/* Dispatch CRM — highway-signage palette, Overpass type */
:root {
  --asphalt: #23272b;
  --asphalt-2: #2f3439;
  --asphalt-ink: #c9d0d5;
  --sign: #0b6b4f;
  --sign-deep: #08573f;
  --sign-tint: #e3f0eb;
  --paper: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --ink: #1b1f23;
  --muted: #5b646c;
  --line: #dde2e0;
  --line-strong: #c6ccca;
  --amber: #b97a06;
  --amber-bg: #fdf3dc;
  --red: #b42318;
  --red-bg: #fde8e6;
  --blue: #1f5fad;
  --blue-bg: #e5eefa;
  --slate: #4b5868;
  --slate-bg: #e9edf1;
  --focus: #f2b705;
  --radius: 6px;
  --font: "Overpass", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
    --paper: #16191c;
    --surface: #1e2226;
    --surface-2: #23282c;
    --ink: #e7eaec;
    --muted: #9aa4ab;
    --line: #2f353a;
    --line-strong: #3d444a;
    --sign-tint: #12352a;
    --amber: #f0b43c;
    --amber-bg: #3a2c0c;
    --red: #f2766b;
    --red-bg: #3d1915;
    --blue: #7fb0f0;
    --blue-bg: #172b45;
    --slate: #b3bdc8;
    --slate-bg: #2a3038;
    --asphalt: #101315;
    --asphalt-2: #1b1f22;
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sign); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--asphalt);
  color: var(--asphalt-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  /* lane line */
  background-image: linear-gradient(var(--asphalt), var(--asphalt)),
    repeating-linear-gradient(to bottom, #e9b949 0 18px, transparent 18px 34px);
  background-size: calc(100% - 4px) 100%, 4px 100%;
  background-position: left top, right top;
  background-repeat: no-repeat;
}
.brand { padding: 20px 18px 18px; }
.brand-mark {
  display: inline-block; background: var(--sign); color: #fff;
  border: 2px solid #fff; box-shadow: 0 0 0 2px var(--sign);
  border-radius: 6px; padding: 5px 10px 3px; font-weight: 800; font-size: 15px; letter-spacing: .01em;
}
.brand small { display: block; margin-top: 8px; color: #8d979e; font-size: 12px; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.nav a {
  color: var(--asphalt-ink); padding: 9px 12px; border-radius: var(--radius);
  font-weight: 600; display: flex; align-items: center; gap: 10px;
}
.nav a:hover { background: var(--asphalt-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--asphalt-2); color: #fff; box-shadow: inset 3px 0 0 #e9b949; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-foot { padding: 14px 18px 18px; font-size: 12px; border-top: 1px solid #343a3f; margin-right: 4px; }
.side-foot b { color: #fff; display: block; font-size: 13px; }
.side-foot .row { display: flex; gap: 12px; margin-top: 8px; }
.side-foot button { background: none; border: 0; color: #9fb7ad; padding: 0; font: inherit; cursor: pointer; }
.side-foot button:hover { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 28px 14px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 22px; font-weight: 800; margin-right: auto; }
.topbar .crumb { color: var(--muted); font-weight: 600; font-size: 14px; margin-right: 8px; }
.menu-btn { display: none; }
.content { padding: 22px 28px 60px; max-width: 1500px; width: 100%; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px 7px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--sign); border-color: var(--sign); color: #fff; }
.btn.primary:hover { background: var(--sign-deep); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px 4px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 7px 10px 6px; width: 100%; min-height: 36px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sign); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sign) 25%, transparent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: auto; min-height: 0; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { max-width: 280px; }
.filters select, .filters input[type=date] { width: auto; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  padding: 5px 11px 3px; border-radius: 999px;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.panel > header { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 10px; }
.panel > header h2 { font-size: 15px; font-weight: 800; }
.panel > header .aside { margin-left: auto; font-size: 13px; color: var(--muted); }
.panel .empty { padding: 18px 16px 22px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px 8px; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface-2); white-space: nowrap; border-top: 0; border-bottom: 1px solid var(--line); }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }
td .sub { display: block; color: var(--muted); font-size: 12px; }
tfoot td { font-weight: 800; border-top: 2px solid var(--line-strong); }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }

/* KPI strip — reads like a mileage board, one band not cards */
.board {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 16px;
}
.board > div { padding: 14px 18px 12px; border-left: 1px solid var(--line); }
.board > div:first-child { border-left: 0; }
.board .v { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.board .k { color: var(--muted); font-size: 13px; font-weight: 600; }

.range { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* status pills */
.pill {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px 1px; border-radius: 999px;
  background: var(--slate-bg); color: var(--slate); white-space: nowrap;
}
.pill.booked { background: var(--slate-bg); color: var(--slate); }
.pill.dispatched { background: var(--blue-bg); color: var(--blue); }
.pill.in_transit { background: var(--amber-bg); color: var(--amber); }
.pill.delivered, .pill.paid, .pill.active { background: var(--sign-tint); color: var(--sign); }
.pill.cancelled, .pill.void, .pill.inactive { background: transparent; color: var(--muted); border: 1px solid var(--line-strong); }
.pill.sent { background: var(--blue-bg); color: var(--blue); }
.pill.overdue, .pill.dnu { background: var(--red-bg); color: var(--red); }
.pill.on_hold { background: var(--amber-bg); color: var(--amber); }
:root[data-theme="dark"] .pill.delivered, :root[data-theme="dark"] .pill.paid, :root[data-theme="dark"] .pill.active { color: #6fd3ad; }

.warn { color: var(--amber); font-weight: 700; }
.bad { color: var(--red); font-weight: 700; }

/* ---------- the route sign ---------- */
.sign {
  background: var(--sign); color: #fff; border-radius: 12px; padding: 4px;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.sign-inner {
  border: 2px solid #fff; border-radius: 9px; padding: 18px 22px 16px;
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 18px; align-items: center;
}
.sign .end .lbl { font-size: 13px; font-weight: 600; opacity: .8; }
.sign .city { font-size: 30px; font-weight: 800; line-height: 1.05; letter-spacing: -.01em; }
.sign .city small { font-size: 18px; font-weight: 700; opacity: .85; margin-left: 4px; }
.sign .when { font-size: 14px; font-weight: 600; margin-top: 4px; }
.sign .end.to { text-align: right; }
.sign .mid { text-align: center; }
.sign .mid svg { width: 64px; height: 30px; display: block; margin: 0 auto 2px; }
.sign .miles { font-size: 20px; font-weight: 800; }
.sign .miles small { font-size: 13px; font-weight: 600; opacity: .85; display: block; }

/* status road */
.road { display: flex; margin: 16px 0 4px; }
.road .stop {
  flex: 1; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted);
  padding-top: 18px; position: relative;
}
.road .stop::before {
  content: ""; position: absolute; top: 6px; left: 0; right: 0; height: 4px; background: var(--line);
}
.road .stop::after {
  content: ""; position: absolute; top: 2px; left: calc(50% - 6px); width: 12px; height: 12px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--line-strong);
}
.road .stop.done::before { background: var(--sign); }
.road .stop.done::after { border-color: var(--sign); background: var(--sign); }
.road .stop.now { color: var(--ink); }
.road .stop.now::after { border-color: var(--sign); background: var(--surface); box-shadow: 0 0 0 4px var(--sign-tint); }
.road .stop:first-child::before { left: 50%; }
.road .stop:last-child::before { right: 50%; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0; }
.facts > div { padding: 10px 16px 9px; border-top: 1px solid var(--line); }
.facts dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 700; word-break: break-word; }
.notes { white-space: pre-wrap; padding: 4px 16px 16px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.split { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.split > :last-child { margin-left: auto; }
.stack > * + * { margin-top: 16px; }

.files { list-style: none; margin: 0; padding: 0 16px 8px; }
.files li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.files li:first-child { border-top: 0; }
.files .tag { font-size: 11px; font-weight: 800; background: var(--slate-bg); color: var(--slate); border-radius: 4px; padding: 2px 6px 1px; }
.files a { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop { margin: 0 16px 16px; border: 2px dashed var(--line-strong); border-radius: 8px; padding: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drop.over { border-color: var(--sign); background: var(--sign-tint); }
.drop select { width: auto; }

.log { list-style: none; margin: 0; padding: 0 16px 14px; font-size: 13px; }
.log li { padding: 6px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log time { color: var(--muted); display: block; font-size: 12px; }

/* ---------- modal ---------- */
dialog {
  border: 0; border-radius: 10px; padding: 0; width: min(760px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(20, 24, 27, .55); }
dialog form > header { padding: 18px 22px 6px; display: flex; align-items: center; }
dialog form > header h2 { font-size: 18px; font-weight: 800; margin-right: auto; }
dialog .body { padding: 10px 22px 6px; max-height: calc(100vh - 190px); overflow-y: auto; }
dialog footer { padding: 14px 22px 18px; display: flex; gap: 8px; justify-content: flex-end; align-items: center; border-top: 1px solid var(--line); margin-top: 10px; }
dialog footer .calc { margin-right: auto; color: var(--muted); font-size: 13px; }
dialog footer .calc b { color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px 14px; }
.form-grid .c1 { grid-column: span 1; } .form-grid .c2 { grid-column: span 2; } .form-grid .c3 { grid-column: span 3; }
.form-grid .c4 { grid-column: span 4; } .form-grid .c6 { grid-column: span 6; }
.form-grid .group { grid-column: span 6; font-weight: 800; font-size: 13px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; }
.form-grid .group:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-error { color: var(--red); font-weight: 700; padding: 0 22px; }

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 10px 18px 9px; border-radius: 8px; font-weight: 700;
  z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--asphalt); }
.login form { width: min(380px, 100%); }
.login .sign-inner { display: block; padding: 26px 26px 24px; }
.login h1 { font-size: 30px; font-weight: 800; }
.login p { margin: 4px 0 20px; opacity: .85; }
.login label { display: block; font-weight: 700; margin-bottom: 12px; }
.login input { margin-top: 4px; border-color: transparent; background: #fff; color: #1b1f23; }
.login .btn { width: 100%; margin-top: 6px; background: #fff; color: var(--sign-deep); border-color: #fff; }
.login .err { background: rgba(0,0,0,.25); padding: 8px 10px; border-radius: 6px; margin-bottom: 12px; font-weight: 700; }

/* ---------- invoice (also printable) ---------- */
.invoice { background: #fff; color: #1b1f23; padding: 34px 38px; border: 1px solid var(--line); border-radius: 8px; }
.invoice .head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.invoice h2 { font-size: 26px; font-weight: 800; color: var(--sign); }
.invoice .meta { text-align: right; }
.invoice .meta div { margin-bottom: 2px; }
.invoice table th { background: #f3f5f4; color: #5b646c; }
.invoice table td, .invoice table th { border-color: #dde2e0; }
.invoice .total { text-align: right; font-size: 20px; font-weight: 800; margin-top: 14px; }
.invoice .pay { margin-top: 22px; padding-top: 14px; border-top: 1px solid #dde2e0; white-space: pre-wrap; color: #5b646c; }

@media print {
  .sidebar, .topbar, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  body { background: #fff; }
  .invoice { border: 0; padding: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid.side, .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 18px; }
  .content { padding: 16px 16px 60px; }
  .board { grid-template-columns: 1fr 1fr; }
  .board > div:nth-child(3) { border-left: 0; }
  .board > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .sign-inner { grid-template-columns: 1fr; text-align: left; gap: 10px; }
  .sign .end.to { text-align: left; }
  .sign .mid { text-align: left; display: flex; gap: 10px; align-items: center; }
  .sign .mid svg { margin: 0; transform: rotate(90deg); width: 30px; }
  .sign .city { font-size: 24px; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid > * { grid-column: span 2 !important; }
  .form-grid .c1 { grid-column: span 1 !important; }
  .filters input[type=search] { max-width: none; }
  .invoice { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* utilities (no inline styles: CSP) */
.mb { margin-bottom: 14px; }
.pad { padding: 8px 16px 16px; }
.btn.menu-btn { display: none; }
@media (max-width: 860px) { .btn.menu-btn { display: inline-flex; } }
.range input { width: auto; }
.road .stop.now:not(:last-child)::before { background: linear-gradient(to right, var(--sign) 50%, var(--line) 50%); }
.road .stop.now:first-child::before { background: var(--line); }
.auto-note { font-size: 13px; background: var(--sign-tint); border-radius: var(--radius); padding: 8px 12px 7px; line-height: 1.6; }
.auto-note:empty { display: none; }
.auto-note .btn { margin-left: 6px; vertical-align: middle; }
p.c6 { margin: 0; }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.mt { margin-top: 16px; }
tbody tr.on td { background: var(--sign-tint); }
.secret { display: flex; gap: 10px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 6px 0 10px; }
.secret code { font-size: 18px; font-weight: 700; letter-spacing: .04em; flex: 1; word-break: break-all; }
dialog.wide { width: min(980px, calc(100vw - 24px)); }
.steps { margin: 0; padding-left: 20px; line-height: 1.7; }
.code-wrap { position: relative; }
.code-wrap .btn { position: absolute; top: 8px; right: 8px; }
.code-wrap pre { margin: 0; max-height: 320px; overflow: auto; background: var(--asphalt); color: #e6ebe8; border-radius: 8px; padding: 14px 16px; font-size: 12px; line-height: 1.5; }
