:root {
  --bg: #0f1419; --bg-2: #161d24; --panel: #1b232c; --panel-2: #222c37; --line: #2c3845; --line-2: #3a4857;
  --text: #e6edf3; --muted: #9aa8b6; --faint: #6b7a89;
  --red: #ef4444; --red-bg: rgba(239,68,68,.14); --amber: #f59e0b; --amber-bg: rgba(245,158,11,.14);
  --blue: #3b82f6; --blue-bg: rgba(59,130,246,.14); --grey: #8b98a6; --grey-bg: rgba(139,152,166,.12);
  --green: #22c55e; --green-bg: rgba(34,197,94,.14); --accent: #f97316;
  --radius: 8px; --font: "IBM Plex Sans", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: #7cb7ff; text-decoration: none; } a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; } .right { text-align: right; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; } h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

/* top bar */
.topbar { height: 52px; display: flex; align-items: center; gap: 20px; padding: 0 16px; background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand i { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); display: inline-block; transform: rotate(45deg); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--panel-2); color: var(--text); }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 16px 48px; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); font: 500 13px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #536375; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d03; font-weight: 600; }
.btn.danger { border-color: #7f2a2a; color: #fca5a5; }
.btn.ok { border-color: #1f6b3a; color: #86efac; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.link { background: none; border: none; color: #7cb7ff; padding: 0; height: auto; }
input, select, textarea { width: 100%; height: 34px; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: 14px var(--font); }
textarea { height: auto; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(249,115,22,.5); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; height: auto; accent-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; } .row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 0 14px 6px 0; }
.err { color: #fca5a5; font-size: 12px; margin-top: 4px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--green-bg); border-color: #1f6b3a; } .flash.err { background: var(--red-bg); border-color: #7f2a2a; }

/* tables / cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 16px; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:hover td { background: rgba(255,255,255,.015); }
.t .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .02em; border: 1px solid transparent; white-space: nowrap; }
.pill.waiting, .pill.red { background: var(--red-bg); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.pill.active, .pill.amber { background: var(--amber-bg); color: #fcd34d; border-color: rgba(245,158,11,.35); }
.pill.scheduled, .pill.blue { background: var(--blue-bg); color: #93c5fd; border-color: rgba(59,130,246,.35); }
.pill.cleared, .pill.grey { background: var(--grey-bg); color: #cbd5e1; border-color: rgba(139,152,166,.3); }
.pill.green { background: var(--green-bg); color: #86efac; border-color: rgba(34,197,94,.35); }
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 8px; flex-wrap: wrap; } .toolbar form > * { width: auto; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.pager { margin-top: 12px; } .pager nav { display: flex; gap: 6px; flex-wrap: wrap; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

/* ======== DISPATCH BOARD ======== */
body.board-page { overflow: hidden; }
.board { display: grid; grid-template-columns: 360px 1fr 300px; height: calc(100vh - 52px); }
.queue, .fleet { background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; }
.queue { border-right: 1px solid var(--line); } .fleet { border-left: 1px solid var(--line); }
.pane-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tab { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 4px; text-align: center; cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.tab b { display: block; font: 600 18px var(--mono); color: var(--text); }
.tab.waiting { border-top: 3px solid var(--red); } .tab.active { border-top: 3px solid var(--amber); }
.tab.scheduled { border-top: 3px solid var(--blue); } .tab.cleared { border-top: 3px solid var(--grey); }
.tab.on { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.list { overflow-y: auto; flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--faint); text-align: center; padding: 32px 12px; font-size: 13px; }
.tk { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--grey); border-radius: 6px; padding: 9px 10px; cursor: pointer; user-select: none; }
.tk:hover { border-color: var(--line-2); } .tk.sel { outline: 2px solid var(--accent); }
.tk.waiting { border-left-color: var(--red); } .tk.active { border-left-color: var(--amber); } .tk.scheduled { border-left-color: var(--blue); }
.tk.alert { animation: flash 1s steps(2, start) infinite; }
@keyframes flash { to { background: rgba(239,68,68,.22); } }
.tk .l1 { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.tk .l2 { font-weight: 600; margin: 3px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk .l3 { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tk .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.tk[draggable=true] { cursor: grab; }
.mapwrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.map-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); text-align: center; padding: 24px; }
.drv { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; cursor: pointer; }
.drv.drop { outline: 2px dashed var(--accent); background: rgba(249,115,22,.08); }
.drv .l1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.drv .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.available { background: var(--green); } .dot.busy { background: var(--amber); } .dot.off_duty { background: var(--faint); }
.mk-truck { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font: 700 10px var(--mono); color: #0b0f14; border: 2px solid #0b0f14; box-shadow: 0 1px 4px rgba(0,0,0,.6); cursor: pointer; }
.mk-truck.available { background: var(--green); } .mk-truck.busy { background: var(--amber); } .mk-truck.off_duty { background: var(--faint); }
.mk-truck.stale { opacity: .5; } .mk-truck.drop { outline: 3px solid var(--accent); }
.mk-job { width: 18px; height: 18px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #0b0f14; cursor: pointer; }
.mk-job.waiting { background: var(--red); } .mk-job.active { background: var(--amber); } .mk-job.scheduled { background: var(--blue); } .mk-job.cleared { background: var(--grey); }
.mk-drop { width: 12px; height: 12px; background: #fff; border: 3px solid #0b0f14; transform: rotate(45deg); }

/* drawer (ticket detail + intake) */
.drawer { position: fixed; top: 52px; right: 0; bottom: 0; width: 460px; max-width: 100vw; background: var(--bg-2); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0,0,0,.4); transform: translateX(100%); transition: transform .18s ease; z-index: 40; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer .head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.drawer .body { padding: 16px; overflow-y: auto; flex: 1; }
.drawer .foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.section { margin-bottom: 18px; }
.lines { width: 100%; border-collapse: collapse; font-size: 13px; } .lines td { padding: 4px 0; border-bottom: 1px dashed var(--line); } .lines td.num { text-align: right; font-family: var(--mono); }
.lines tr.total td { border: none; font-weight: 700; padding-top: 8px; }
.cand { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; background: var(--panel); }
.cand.no { opacity: .55; } .cand .why { grid-column: 1 / -1; color: #fca5a5; font-size: 12px; }
.ac { position: relative; } .ac-list { position: absolute; z-index: 60; left: 0; right: 0; top: 100%; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; margin-top: 2px; max-height: 240px; overflow-y: auto; display: none; }
.ac-list div { padding: 7px 10px; cursor: pointer; font-size: 13px; } .ac-list div:hover, .ac-list div.hl { background: rgba(249,115,22,.15); }
.picked { font-size: 11px; color: var(--green); margin-top: 3px; }
.estimate-box { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.banner { padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.banner.red { background: var(--red-bg); border: 1px solid rgba(239,68,68,.4); } .banner.amber { background: var(--amber-bg); border: 1px solid rgba(245,158,11,.4); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 90vw; }
.toast.err { border-color: #7f2a2a; background: #2a1414; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12px; } .timeline li { padding: 5px 0 5px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.timeline li.rejected::before { background: var(--red); } .timeline li.ignored::before { background: var(--faint); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos figure { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.photos img { width: 100%; height: 120px; object-fit: cover; display: block; background: #fff; }
.photos figcaption { padding: 6px 8px; font-size: 11px; color: var(--muted); }
.sig img { object-fit: contain; }

@media (min-width: 1101px) { .board-page .drawer { right: 300px; box-shadow: -12px 0 32px rgba(0,0,0,.4), 1px 0 0 var(--line); } }
@media (max-width: 1100px) { .board { grid-template-columns: 320px 1fr; } .fleet { display: none; } }
@media (max-width: 760px) {
  body.board-page { overflow: auto; } .board { grid-template-columns: 1fr; height: auto; }
  .queue { height: 60vh; } .mapwrap { height: 50vh; } .drawer { width: 100vw; }
  .kv { grid-template-columns: 110px 1fr; }
  .topbar { gap: 10px; padding: 0 10px; } .who > a, .who .pill { display: none; }
}

/* print (invoices) */
@media print {
  .topbar, .no-print { display: none !important; }
  body, html { background: #fff; color: #000; } .card { border: none; background: #fff; padding: 0; }
  .t th, .t td { border-color: #ccc; color: #000; } .muted { color: #444; } .wrap { max-width: none; padding: 0; }
}
