/* Delfast Platform — design system v3.
   LIGHT is the default for the office console (dispatch, portal, tracking):
   dispatchers read lists for eight hours in lit rooms, and the map tiles are
   light — the page should match. DARK is an override via [data-theme="dark"]:
   the driver app forces it (night driving), and the console offers a toggle. */
:root {
  --bg: #eef1f8; --surface: #ffffff; --surface2: #ffffff; --raise: #f3f5fb;
  --line: rgba(30,41,90,.12); --line2: rgba(30,41,90,.22);
  --txt: #171c33; --muted: #5b6485; --dim: #8790ad;
  --accent: #6d4aff; --accent2: #c026d3;
  --grad: linear-gradient(135deg, #6d4aff, #a855f7, #c026d3);
  --ok: #047857; --warn: #b45309; --danger: #b91c1c; --info: #0369a1; --stat: #e11d48;
  --neut-bg: #e8ebf5; --neut-tx: #5b6485;
  --info-bg: #e0f2fe; --info-tx: #0369a1;
  --warn-bg: #fef3c7; --warn-tx: #92400e;
  --purp-bg: #ede9fe; --purp-tx: #6d28d9;
  --ok-bg: #d1fae5; --ok-tx: #047857;
  --danger-bg: #fee2e2; --danger-tx: #b91c1c;
  --statban-bg: #ffe4e9; --statban-tx: #9f1239;
  --input-bg: #ffffff; --glass: rgba(255,255,255,.93); --mapbg: #dfe6f0;
  --radius: 14px; --shadow: 0 8px 26px rgba(30,41,90,.10);
  --ghost-bg: rgba(109,74,255,.06); --ghost-hover: rgba(109,74,255,.13);
}
[data-theme="dark"] {
  --bg: #0a0e1c; --surface: #111830; --surface2: #172142; --raise: #1c2750;
  --line: rgba(148,163,216,.14); --line2: rgba(148,163,216,.24);
  --txt: #eef1fb; --muted: #8f9ac0; --dim: #67719c;
  --ok: #34d399; --warn: #f5a623; --danger: #f87171; --info: #38bdf8; --stat: #ff4d6d;
  --neut-bg: rgba(143,154,192,.16); --neut-tx: #aab4d4;
  --info-bg: rgba(56,189,248,.14); --info-tx: #38bdf8;
  --warn-bg: rgba(245,166,35,.15); --warn-tx: #f5a623;
  --purp-bg: rgba(167,139,250,.17); --purp-tx: #c4b5fd;
  --ok-bg: rgba(52,211,153,.14); --ok-tx: #34d399;
  --danger-bg: rgba(248,113,113,.14); --danger-tx: #f87171;
  --statban-bg: rgba(255,77,109,.13); --statban-tx: #ffb3c1;
  --input-bg: #0d1326; --glass: rgba(13,19,38,.92); --mapbg: #1a2036;
  --shadow: 0 10px 34px rgba(3,6,18,.55);
  --ghost-bg: rgba(124,92,255,.08); --ghost-hover: rgba(124,92,255,.17);
}
* { box-sizing: border-box; margin: 0; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body { background: var(--bg); color: var(--txt); font: 14.5px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; color: inherit; }
h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; }
input, select, textarea { font: inherit; background: var(--input-bg); color: var(--txt); border: 1px solid var(--line2); border-radius: 9px; padding: 8px 11px; width: 100%; transition: border-color .12s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,74,255,.15); }
input::placeholder { color: var(--dim); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 11px 0 4px; text-transform: uppercase; letter-spacing: .05em; }
label .lc { text-transform: none; letter-spacing: 0; font-weight: 400; }

.btn { background: var(--grad); color: #fff; border: 0; border-radius: 10px; padding: 9px 17px; font-weight: 700; transition: transform .1s, filter .12s; box-shadow: 0 4px 14px rgba(109,74,255,.3); }
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:disabled { opacity: .5; transform: none; cursor: default; }
.btn-ghost { background: var(--ghost-bg); color: var(--txt); border: 1px solid var(--line2); border-radius: 10px; padding: 8px 15px; font-weight: 600; transition: background .12s, border-color .12s; }
.btn-ghost:hover { background: var(--ghost-hover); border-color: var(--accent); text-decoration: none; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--danger-bg); color: var(--danger-tx); border: 1px solid var(--danger-tx); border-radius: 10px; padding: 8px 15px; font-weight: 600; }
.btn-danger:hover { filter: brightness(.97); }

.topbar { display: flex; align-items: center; gap: 10px; padding: 9px 16px; background: var(--glass); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1100; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 16.5px; white-space: nowrap; }
.brand .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; box-shadow: 0 3px 12px rgba(109,74,255,.35); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; white-space: nowrap; }

.statchip { display: flex; flex-direction: column; align-items: center; padding: 2px 13px; border-left: 1px solid var(--line); line-height: 1.2; }
.statchip b { font-size: 15.5px; }
.statchip span { font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.statchip.hot b { color: var(--stat); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sect { font-size: 11.5px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .09em; margin: 16px 0 2px; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2.5px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.st-created { background: var(--neut-bg); color: var(--neut-tx); }
.st-assigned, .st-accepted { background: var(--info-bg); color: var(--info-tx); }
.st-picked_up { background: var(--warn-bg); color: var(--warn-tx); }
.st-in_transit { background: var(--purp-bg); color: var(--purp-tx); }
.st-delivered { background: var(--ok-bg); color: var(--ok-tx); }
.st-failed, .st-canceled { background: var(--danger-bg); color: var(--danger-tx); }
.st-returned { background: var(--neut-bg); color: var(--neut-tx); }
.pr-stat { background: var(--stat); color: #fff; box-shadow: 0 0 10px rgba(225,29,72,.35); }
.pr-rush { background: var(--warn-bg); color: var(--warn-tx); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 480px at 75% -5%, rgba(109,74,255,.14), transparent 62%),
              radial-gradient(700px 420px at 10% 105%, rgba(192,38,211,.09), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; box-shadow: var(--shadow); padding: 26px; }
.login-card h1 { font-size: 22px; margin: 12px 0 3px; }

/* ---------------- app shell: sidebar + sections ---------------- */
.shell { display: grid; grid-template-columns: 192px 1fr; min-height: calc(100vh - 49px); }
.sidebar { border-right: 1px solid var(--line); background: var(--surface); padding: 12px 8px; position: sticky; top: 49px; height: calc(100vh - 49px); overflow-y: auto; }
.navitem { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 9px; padding: 9px 12px; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.navitem:hover { background: var(--ghost-bg); color: var(--txt); }
.navitem.active { background: var(--ghost-hover); color: var(--accent); }
.navitem .n { margin-left: auto; font-size: 11.5px; background: var(--neut-bg); color: var(--neut-tx); border-radius: 999px; padding: 1px 8px; }
.navitem.active .n { background: var(--accent); color: #fff; }
.main { min-width: 0; }
.sec { display: none; }
.sec.active { display: block; }
.pagewrap { padding: 16px; max-width: 1060px; }
.pagewrap h1 { font-size: 20px; margin-bottom: 12px; }

/* dispatch section */
.dispatch-main { display: grid; grid-template-columns: 462px 1fr; height: calc(100vh - 49px); }
.board { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 12px 60px; scrollbar-width: thin; }
.tabs { display: flex; gap: 5px; flex-wrap: wrap; margin: 10px 0; }
.tab { border: 1px solid var(--line2); background: transparent; color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 600; transition: all .12s; }
.tab:hover { border-color: var(--accent); color: var(--txt); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab .n { opacity: .8; font-weight: 700; margin-left: 3px; }

.statbanner { background: var(--statban-bg); border: 1px solid var(--stat); border-radius: 11px; padding: 9px 13px; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--statban-tx); animation: statpulse 2s infinite; }
@keyframes statpulse { 50% { box-shadow: 0 0 0 4px rgba(225,29,72,.12); } }

.drvstrip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.drvpill { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; font-weight: 600; }
.drvpill .d { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.drvpill .d.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.drvpill .load { color: var(--dim); font-weight: 700; }

.routebar { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 12px; }
.routebar .title { font-size: 11.5px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 7px; }

.dcard { position: relative; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line2); border-radius: 11px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: border-color .12s, transform .1s, box-shadow .12s; }
.dcard:hover, .dcard.hl { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.dcard.prio-stat { border-left-color: var(--stat); }
.dcard.prio-rush { border-left-color: var(--warn); }
.dcard.done { opacity: .72; }
.dcard .code { font-weight: 800; letter-spacing: .4px; font-size: 14px; }
.dcard .route-line { font-size: 12.8px; color: var(--muted); margin-top: 3px; display: flex; align-items: baseline; gap: 6px; }
.dcard .route-line .arr { color: var(--accent); }
.dcard .meta { font-size: 12px; color: var(--dim); margin-top: 4px; display: flex; gap: 9px; flex-wrap: wrap; }
.dcard .qa { display: flex; gap: 6px; margin-top: 8px; }
.dcard .qa select { padding: 4px 8px; font-size: 12.5px; flex: 1; }
.drvchip { display: inline-flex; align-items: center; gap: 4px; background: var(--purp-bg); color: var(--purp-tx); border-radius: 999px; padding: 1px 9px; font-size: 11.5px; font-weight: 600; }

#map { height: 100%; background: var(--mapbg); position: relative; }
.leaflet-container { background: var(--mapbg); font: inherit; }
.map-tools { position: absolute; bottom: 22px; left: 12px; z-index: 1050; display: flex; gap: 8px; }
.map-tools .btn-ghost, .maplegend { background: var(--glass); backdrop-filter: blur(6px); }
.maplegend { position: absolute; bottom: 22px; right: 12px; z-index: 1050; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 11.5px; color: var(--muted); }
.maplegend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

.routepanel { position: absolute; top: 12px; right: 12px; z-index: 1060; width: 290px; max-height: calc(100% - 60px); overflow-y: auto; background: var(--glass); border: 1px solid var(--line2); border-radius: 13px; padding: 13px; backdrop-filter: blur(8px); box-shadow: var(--shadow); }
.routepanel .stop { display: flex; gap: 9px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.routepanel .stop:last-child { border-bottom: 0; }
.stopnum { flex: 0 0 22px; height: 22px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 11.5px; font-weight: 800; }

/* overlays — Leaflet panes/controls live at z 400-1000, stay above them */
.overlay { position: fixed; inset: 0; background: rgba(15,20,45,.45); z-index: 1200; display: none; backdrop-filter: blur(2px); }
[data-theme="dark"] .overlay { background: rgba(4,7,18,.7); }
.overlay.open { display: block; }
.drawer { position: fixed; top: 0; right: -560px; width: 100%; max-width: 560px; height: 100vh; background: var(--surface2); border-left: 1px solid var(--line2); z-index: 1300; transition: right .18s ease-out; overflow-y: auto; padding: 20px; }
.drawer.open { right: 0; }
.modal { position: fixed; z-index: 1300; top: 50%; left: 50%; transform: translate(-50%,-50%); background: var(--surface2); border: 1px solid var(--line2); border-radius: 16px; width: min(700px, 94vw); max-height: 92vh; overflow-y: auto; padding: 20px; display: none; box-shadow: var(--shadow); }
.modal.open { display: block; }
.modal h2, .drawer h2 { font-size: 17px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }

/* address autocomplete */
.ac-wrap { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 1350; background: var(--surface); border: 1px solid var(--line2); border-radius: 10px; margin-top: 4px; overflow: hidden; box-shadow: var(--shadow); }
.ac-item { padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover { background: var(--ghost-bg); }
.ac-ok { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 13px; pointer-events: none; }

/* custody timeline */
.timeline { border-left: 2px solid var(--line2); margin: 12px 0 0 8px; padding-left: 16px; }
.timeline .ev { position: relative; padding-bottom: 12px; }
.timeline .ev::before { content: ""; position: absolute; left: -22.5px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface2); }
.timeline .ev.ok::before { background: var(--ok); }
.timeline .ev.bad::before { background: var(--danger); }
.podthumb { max-width: 150px; border-radius: 10px; border: 1px solid var(--line2); display: block; }

/* orders table */
.filterbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filterbar select, .filterbar input { width: auto; min-width: 130px; }
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl th { color: var(--dim); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; position: sticky; top: 0; background: var(--surface); }
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--accent); }
table.tbl tr:hover td { background: var(--ghost-bg); }
table.tbl tr.rowsel td { background: var(--ghost-hover); }
.bulkbar { display: flex; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--accent); border-radius: 11px; padding: 8px 12px; margin-bottom: 10px; }

/* ---------------- driver app (always dark via data-theme) ---------------- */
.driver-wrap { max-width: 560px; margin: 0 auto; padding: 12px 12px 90px; }
.jobcard { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line2); border-radius: 13px; padding: 14px; margin-bottom: 11px; }
.jobcard.prio-stat { border-left-color: var(--stat); }
.jobcard.prio-rush { border-left-color: var(--warn); }
.steps { display: flex; gap: 4px; margin: 9px 0 3px; }
.step { flex: 1; text-align: center; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); padding-top: 5px; border-top: 3px solid var(--line); }
.step.done { color: var(--ok); border-top-color: var(--ok); }
.step.now { color: var(--accent); border-top-color: var(--accent); }
.bigbtn { width: 100%; padding: 14px; font-size: 15.5px; border-radius: 12px; margin-top: 10px; }
.duty { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 11px 14px; margin-bottom: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
#sigpad { background: #fff; border-radius: 10px; width: 100%; touch-action: none; }
.addr { font-size: 13.8px; }
.addr b { font-size: 14.5px; }
.addr .who { color: var(--muted); }
.navbtn { font-size: 12.5px; padding: 3px 10px; }
.scanline { display: flex; gap: 8px; margin-bottom: 12px; }
#scan-video { width: 100%; border-radius: 12px; background: #000; }

/* track page */
.track-wrap { max-width: 470px; margin: 0 auto; padding: 26px 16px; }
.track-status { font-size: 25px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.02em; }
.tsteps { display: flex; gap: 5px; margin: 16px 0 6px; }
.tstep { flex: 1; height: 5px; border-radius: 4px; background: var(--line2); }
.tstep.done { background: var(--grad); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--accent); color: var(--txt); border-radius: 11px; padding: 11px 20px; z-index: 1400; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: toastin .18s ease-out; max-width: 92vw; display: flex; gap: 12px; align-items: center; }
.toast.err { border-color: var(--danger); }
.toast button { background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 3px 12px; font-weight: 700; font-size: 13px; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

.empty { text-align: center; color: var(--dim); padding: 34px 10px; font-size: 13.5px; }
.empty .big { font-size: 30px; margin-bottom: 8px; }

@media (max-width: 940px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; overflow-x: auto; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .navitem { white-space: nowrap; margin: 0 2px 0 0; }
  .dispatch-main { grid-template-columns: 1fr; height: auto; }
  #map { height: 46vh; }
  .board { order: 2; border-right: 0; }
  .statchip { display: none; }
  .routepanel { width: 240px; }
  .grid3 { grid-template-columns: 1fr; }
}
