:root {
  --navy: #0B1F33;
  --navy-2: #12293F;
  --navy-line: #22405E;
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --line: #DDD8CF;
  --line-soft: #EEEAE3;
  --text: #0B1F33;
  --muted: #44566A;
  --muted-2: #5B6B7C;
  --on-navy: #F4F2EE;
  --on-navy-muted: #C9D3DD;
  --accent: #C2410C;
  --accent-hover: #9A3412;
  --accent-soft: #FFF6EF;
  --accent-soft-line: #F6CFB2;
  --danger: #B91C1C;
  --radius: 8px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--sans); color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--muted-2); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-dark { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.btn-dark:hover { background: #18324D; color: var(--on-navy); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; }
.input, .field input, .field select, .field textarea { height: 40px; border: 1px solid #A8A193; border-radius: 5px; padding: 0 10px; background: #fff; width: 100%; }
.field textarea { height: auto; min-height: 80px; padding: 10px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-grid .span-all { grid-column: 1 / -1; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: flex; flex-wrap: wrap; }
.auth-side { flex: 1 1 420px; background: var(--navy); color: var(--on-navy); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; background-image: linear-gradient(#13304A 1px, transparent 1px), linear-gradient(90deg, #13304A 1px, transparent 1px); background-size: 48px 48px; }
.auth-side h1 { font-size: clamp(30px, 4vw, 46px); line-height: 1.08; max-width: 520px; }
.auth-side p { color: var(--on-navy-muted); font-size: 17px; max-width: 480px; }
.auth-points { display: flex; flex-direction: column; gap: 10px; color: var(--on-navy-muted); }
.auth-points span { display: flex; gap: 10px; align-items: center; }
.auth-main { flex: 1 1 420px; display: flex; align-items: center; justify-content: center; padding: 40px 20px; }
.auth-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }
.auth-card h2 { font-size: 28px; }
.auth-switch { display: flex; gap: 6px; background: #E9E5DE; padding: 4px; border-radius: 7px; }
.auth-switch button { flex: 1; min-height: 38px; border: 0; border-radius: 5px; background: transparent; font-weight: 600; cursor: pointer; color: #2B3D50; }
.auth-switch button[aria-pressed="true"] { background: var(--navy); color: var(--on-navy); }
.notice { padding: 12px 14px; border-radius: 6px; font-size: 14px; line-height: 1.5; }
.notice-error { background: #FDECEC; border: 1px solid #F5C2C2; color: #7F1D1D; }
.notice-info { background: var(--accent-soft); border: 1px solid var(--accent-soft-line); color: #5A2A0A; }

.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; color: inherit; text-decoration: none; }
.logo small { font-family: var(--mono); font-weight: 500; font-size: 11px; letter-spacing: 0.08em; color: #F59E62; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { flex: 0 0 232px; width: 232px; min-width: 0;background: var(--navy); color: var(--on-navy-muted); display: flex; flex-direction: column; padding: 20px 14px; gap: 24px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { color: var(--on-navy); padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 6px; color: var(--on-navy-muted); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav a:hover { background: #15304A; color: var(--on-navy); }
.nav a[aria-current="page"] { background: #1C3550; color: var(--on-navy); }
.nav svg { flex: 0 0 18px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--navy-line); padding: 14px 8px 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.sidebar-foot strong { color: var(--on-navy); font-size: 14px; }
.sidebar-foot button { margin-top: 8px; align-self: flex-start; background: none; border: 1px solid var(--navy-line); color: var(--on-navy-muted); border-radius: 5px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.sidebar-foot button:hover { color: var(--on-navy); border-color: #3A5571; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.page { padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head h1 { font-size: 28px; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.card-head h2 { font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .sub { font-size: 12px; color: var(--muted-2); }
.kpi.alert .value { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 18px; align-items: start; }

.statusbar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.statusbar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: inherit; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: #FAF8F5; color: inherit; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

/* ---------- Table ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .input { width: auto; min-width: 220px; flex: 1 1 240px; }
.toolbar select.input { flex: 0 1 180px; min-width: 150px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 820px; }
table.data th { text-align: left; font-weight: 500; color: var(--muted-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #FBFAF8; white-space: nowrap; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: #FAF8F5; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.s-booked { background: #E3EAF2; color: #1E3A5F; }
.s-dispatched { background: #E6E4F7; color: #3730A3; }
.s-picked_up { background: #DDF1F0; color: #115E59; }
.s-in_transit { background: #DCEBFB; color: #1E40AF; }
.s-at_customs { background: #FDF0D5; color: #854D0E; }
.s-out_for_delivery { background: #EFE3F8; color: #6B21A8; }
.s-delivered { background: #DCF2E7; color: #14653F; }
.s-exception { background: #FDE2E2; color: #991B1B; }
.s-cancelled { background: #ECEAE6; color: #57534E; }
.r-high { background: #FDE8D7; color: #9A3412; }
.r-medium { background: #FDF0D5; color: #854D0E; }
.r-low { background: #EEF2F6; color: #44566A; }
.r-none { background: transparent; color: var(--muted-2); padding-left: 0; }
.r-none::before { display: none; }

/* ---------- Board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: #E9E5DE; border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 2px; font-weight: 600; font-size: 14px; }
.col-head .count { font-family: var(--mono); font-size: 12px; color: var(--muted-2); background: #fff; border-radius: 999px; padding: 2px 8px; }
.tcard { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.tcard.risk-high { border-left: 3px solid var(--accent); }
.tcard-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tcard-top a { font-family: var(--mono); font-weight: 600; font-size: 13px; color: var(--text); text-decoration: none; }
.tcard-top a:hover { color: var(--accent); }
.tcard .lane { font-weight: 600; font-size: 14px; }
.tcard-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- Detail ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 18px 20px; padding: 20px; }
.fact .k { font-size: 12px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.04em; }
.fact .v { font-weight: 600; margin-top: 3px; overflow-wrap: anywhere; }
.lane-big { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-size: 22px; font-weight: 700; }
.lane-big svg { color: var(--accent); }
.timeline { list-style: none; margin: 0; padding: 20px; display: flex; flex-direction: column; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--navy); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::after { display: none; }
.timeline li.latest::before { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.timeline .t-title { font-weight: 600; }
.timeline .t-meta { font-size: 13px; color: var(--muted); }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11, 31, 51, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 720px; box-shadow: 0 30px 80px rgba(0,0,0,0.3); }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; border-radius: 5px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--line-soft); color: var(--text); }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 40px); }
.toast { background: var(--navy); color: var(--on-navy); padding: 12px 16px; border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); font-size: 14px; max-width: 380px; }
.toast.error { background: #7F1D1D; }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.demo-banner { background: var(--accent-soft); border-bottom: 1px solid var(--accent-soft-line); color: #5A2A0A; font-size: 13px; padding: 8px 32px; }

/* ---------- Utilities ---------- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.org-switch { width: 100%; max-width: 100%; height: 34px;border-radius: 5px; border: 1px solid var(--navy-line); background: var(--navy-2); color: var(--on-navy); padding: 0 8px; font-size: 13px; }

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo { position: relative; display: block; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--line-soft); border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(11,31,51,0.8); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }

/* ---------- Driver app (mobile first) ---------- */
.driver-app { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.d-head { background: var(--navy); color: var(--on-navy); padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; }
.d-head .logo { color: var(--on-navy); font-size: 17px; }
.d-who { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--on-navy-muted); text-align: right; min-width: 0; }
.d-who strong { color: var(--on-navy); font-size: 14px; }
.d-main { flex: 1; width: 100%; max-width: 620px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.d-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.d-title h1 { font-size: 24px; }
.d-sub { font-size: 15px; color: var(--muted); margin-top: 12px; }
.d-job { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; text-decoration: none; color: inherit; }
.d-job:hover { border-color: var(--muted-2); color: inherit; }
.d-job-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.d-lane { font-size: 18px; font-weight: 700; line-height: 1.25; }
.d-lane.big { font-size: 24px; }
.d-meta { font-size: 14px; color: var(--muted); }
.d-empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 28px 20px; text-align: center; color: var(--muted); }
.d-back { font-size: 15px; font-weight: 600; text-decoration: none; padding: 4px 0; }
.d-job-head { display: flex; flex-direction: column; gap: 8px; }
.d-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.d-card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-2); font-weight: 600; }
.d-actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.d-actions-row .btn { flex: 1 1 110px; min-height: 46px; }
.d-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.d-facts span { display: block; font-size: 12px; color: var(--muted-2); }
.d-actions { display: flex; flex-direction: column; gap: 10px; }
.d-big { min-height: 56px; font-size: 17px; width: 100%; }
.d-gps { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); padding: 4px 2px; }
.d-gps input { width: 20px; height: 20px; }
.d-foot { display: flex; gap: 8px; justify-content: center; padding: 16px; flex-wrap: wrap; }
.d-foot .input { width: auto; max-width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; flex: none; padding: 12px 16px; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .sidebar-foot { display: none; }
  .page { padding: 20px 16px 40px; }
  .detail { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .demo-banner { padding: 8px 16px; }
  .auth-side { padding: 32px 20px; }
}
