:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --line: #dbe2ea;
  --line-strong: #cbd5e1;
  --text: #111827;
  --muted: #64748b;
  --blue: #145bd6;
  --blue-dark: #0e46ad;
  --green: #0f8a43;
  --green-bg: #e9f7ee;
  --amber: #d97706;
  --amber-bg: #fff4df;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  color: var(--blue-dark);
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  height: 96px;
  padding: 0 28px;
  color: var(--text);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: 0;
}

.nav-stack,
.quick-upload {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
}

.nav-stack a,
.quick-upload a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 6px;
  color: #253044;
  font-weight: 600;
}

.nav-stack a:hover,
.quick-upload a:hover {
  background: #eef5ff;
  color: var(--blue);
}

.quick-upload {
  margin-top: 24px;
  border-top: 1px solid var(--line);
}

.quick-upload p {
  margin: 10px 4px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-foot {
  display: grid;
  gap: 2px;
  margin-top: auto;
  padding: 18px 24px;
  color: var(--muted);
  font-size: 12px;
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 80px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.top-field {
  display: grid;
  min-width: 240px;
  gap: 4px;
}

.top-field span {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.top-field strong {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.content {
  padding: 22px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn {
  padding: 8px 14px;
}

.icon-btn {
  width: 38px;
  padding: 0;
}

.btn-primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
  color: #fff;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 18px;
}

.dashboard-main,
.dashboard-rail {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.kpi {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  min-height: 104px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi svg {
  width: 28px;
  height: 28px;
  color: var(--blue);
}

.kpi span {
  min-height: 32px;
  font-weight: 700;
  line-height: 1.2;
}

.kpi strong {
  font-size: 24px;
  line-height: 1.1;
}

.kpi small {
  color: var(--muted);
}

.kpi-warning svg {
  color: var(--amber);
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.narrow-panel {
  max-width: 760px;
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
}

.tabs {
  display: flex;
  gap: 22px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.tabs a {
  display: flex;
  align-items: center;
  min-height: 54px;
  border-bottom: 2px solid transparent;
  color: #253044;
  font-weight: 700;
}

.tabs a.active {
  border-color: var(--blue);
  color: var(--blue);
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}

.search {
  position: relative;
  flex: 1;
}

.search svg {
  position: absolute;
  top: 10px;
  left: 12px;
  color: var(--muted);
}

.search input {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px 9px 40px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: inherit;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: var(--surface-2);
  color: #0f172a;
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-left: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.status.matched,
.status.in_transit,
.status.delivered {
  background: var(--green-bg);
  color: var(--green);
}

.status.loaded,
.status.at_depot,
.status.partial {
  background: var(--amber-bg);
  color: var(--amber);
}

.status.failed,
.status.delayed,
.status.exception {
  background: var(--red-bg);
  color: var(--red);
}

.rail-panel {
  overflow: hidden;
}

.upload-list,
.status-list {
  display: grid;
}

.upload-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--text);
}

.upload-row:first-child {
  border-top: 0;
}

.upload-row svg {
  color: var(--green);
}

.upload-row span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.upload-row strong,
.upload-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-row small {
  color: var(--muted);
}

.status-list {
  padding: 10px 14px 14px;
}

.status-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.mini-table th,
.mini-table td {
  padding: 9px 10px;
  font-size: 12px;
}

.positive {
  color: var(--green);
  font-weight: 800;
}

.negative {
  color: var(--red);
  font-weight: 800;
}

.exception-panel {
  padding-bottom: 10px;
}

.exception-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 16px;
}

.exception-grid div {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 0 10px;
  padding: 0 14px;
  border-left: 1px solid var(--line);
}

.exception-grid div:first-child {
  border-left: 0;
}

.exception-grid svg {
  grid-row: span 3;
  width: 28px;
  height: 28px;
  color: var(--amber);
}

.exception-grid strong {
  font-size: 20px;
}

.exception-grid span {
  font-weight: 800;
}

.exception-grid small {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-style: normal;
  text-align: center;
}

.form-grid,
.form-stack {
  display: grid;
  gap: 14px;
}

.form-grid label,
.form-stack label {
  display: grid;
  gap: 6px;
  color: #1f2937;
  font-weight: 700;
}

input,
select,
textarea {
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.field-error {
  color: var(--red);
  font-weight: 700;
}

.detail-list {
  padding: 18px;
}

.detail-list dl {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px 18px;
  margin: 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.message {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  font-weight: 700;
}

.message.success {
  border-color: #b7e4c7;
  background: var(--green-bg);
  color: var(--green);
}

.message.error {
  border-color: #fecaca;
  background: var(--red-bg);
  color: var(--red);
}

code {
  display: inline-block;
  max-width: 480px;
  overflow: hidden;
  color: #334155;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(180deg, #f8fafc 0%, #eef4f8 100%);
}

.login-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card.wide {
  width: min(100%, 560px);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.landing-page {
  min-height: 100vh;
  background: #0b1118;
  color: #fff;
}

.landing-hero {
  position: relative;
  display: grid;
  min-height: 74vh;
  padding: 24px clamp(18px, 4vw, 64px) 72px;
  background:
    linear-gradient(90deg, rgba(6, 13, 22, 0.92) 0%, rgba(6, 13, 22, 0.72) 38%, rgba(6, 13, 22, 0.15) 100%),
    var(--hero-image) center / cover no-repeat;
}

.landing-nav {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  height: 54px;
}

.landing-brand {
  color: #fff;
  font-size: 26px;
  font-weight: 850;
  letter-spacing: 0;
}

.landing-brand:hover {
  color: #fff;
}

.btn-light {
  border-color: rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  backdrop-filter: blur(8px);
}

.btn-light:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.btn-large {
  min-height: 46px;
  padding: 11px 18px;
}

.landing-copy {
  position: relative;
  z-index: 1;
  align-self: center;
  max-width: 720px;
  padding: 54px 0 12px;
}

.landing-copy h1 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(40px, 5vw, 74px);
  line-height: 0.98;
  letter-spacing: 0;
}

.landing-copy p {
  max-width: 610px;
  margin: 22px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 18px;
  line-height: 1.65;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}

.landing-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: #263241;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.landing-feature {
  min-height: 210px;
  padding: 34px clamp(20px, 4vw, 46px);
  background: #101923;
}

.landing-feature svg {
  width: 28px;
  height: 28px;
  color: #4f8cff;
}

.landing-feature h2 {
  margin: 18px 0 8px;
  font-size: 18px;
}

.landing-feature p {
  margin: 0;
  max-width: 420px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  line-height: 1.65;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .brand {
    padding: 0 12px;
    font-size: 0;
  }

  .brand::before {
    content: "mA";
    font-size: 21px;
  }

  .nav-stack a,
  .quick-upload a {
    justify-content: center;
    padding: 10px;
    font-size: 0;
  }

  .quick-upload p,
  .sidebar-foot {
    display: none;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .brand {
    height: 58px;
    font-size: 22px;
  }

  .brand::before {
    content: none;
  }

  .nav-stack {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 12px 12px;
  }

  .nav-stack a {
    flex: 0 0 86px;
    min-height: 58px;
    font-size: 12px;
    flex-direction: column;
    gap: 4px;
  }

  .quick-upload,
  .sidebar-foot {
    display: none;
  }

  .topbar {
    position: static;
    flex-wrap: wrap;
  }

  .top-field {
    min-width: min(100%, 220px);
  }

  .top-actions {
    width: 100%;
    margin-left: 0;
  }

  .content {
    padding: 14px;
  }

  .kpi-grid,
  .exception-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .landing-hero {
    min-height: 68vh;
    padding-bottom: 52px;
    background:
      linear-gradient(180deg, rgba(6, 13, 22, 0.94) 0%, rgba(6, 13, 22, 0.76) 55%, rgba(6, 13, 22, 0.34) 100%),
      var(--hero-image) center / cover no-repeat;
  }

  .landing-copy h1 {
    font-size: 42px;
  }

  .landing-band {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .kpi-grid,
  .exception-grid {
    grid-template-columns: 1fr;
  }

  .table-tools,
  .tabs {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .detail-list dl {
    grid-template-columns: 1fr;
  }
}
