:root {
  --paper:#f4f3ee; --panel:#ffffff; --panel2:#faf9f4;
  --ink:#20262c; --muted:#6b7280; --line:#ddd9cf; --row:#efede3;
  --hivis:#e0611c; --green:#2f8f5b; --amber:#c98a12; --red:#c53a2c; --blue:#3e77a8;
  --navy:#28313a; --head-fg:#eef0f2; --head-sub:#9aa5b0; --chipbg:#efede3; --chipfg:#57534a;
  --pillg:#e2efe7; --pillb:#e2ecf4; --pillo:#f8e6da; --pilla:#f5ecd8;
  --flagover:#f7ddd8; --flagok:#e2efe7; --ownerbg:#f3e8df; --ownerfg:#8a4413;
  --svgline:#c9c4b6; --svgtick:#ddd9cf; --svgcity:#a49f92; --dotstroke:#ffffff;
}
html[data-theme="dark"] {
  --paper:#14171c; --panel:#1c2129; --panel2:#222834;
  --ink:#e8ebef; --muted:#8b95a5; --line:#2e3644; --row:#242b37;
  --navy:#10141a; --head-fg:#e8ebef; --head-sub:#7d8899;
  --chipbg:#2a3140; --chipfg:#aeb7c4;
  --pillg:rgba(79,191,114,.12); --pillb:rgba(91,155,213,.12); --pillo:rgba(224,97,28,.15); --pilla:rgba(201,138,18,.15);
  --flagover:rgba(197,58,44,.18); --flagok:rgba(47,143,91,.16); --ownerbg:rgba(224,97,28,.16); --ownerfg:#e59a63;
  --svgline:#39424f; --svgtick:#2e3644; --svgcity:#5a6474; --dotstroke:#14171c;
  --green:#4fbf72; --amber:#e0a832; --red:#e05c4b; --blue:#5b9bd5; --hivis:#e87b3a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Archivo', sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}
.mono { font-family: 'IBM Plex Mono', monospace; }
.hidden { display: none !important; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px; background: var(--navy); color: var(--head-fg);
  flex-wrap: wrap;
}
/* White backdrop is deliberate: the logo's navy wordmark disappears
   against the header's own navy background, same reasoning already
   applied to the white PWA icon backgrounds. */
.brand-logo {
  display: inline-block;
  line-height: 0;
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
}
.brand-logo img { display: block; height: 40px; width: auto; }
.brand small { display: block; margin-top: 4px; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--head-sub); }
@media (max-width: 480px) {
  .brand-logo { padding: 4px 8px; }
  .brand-logo img { height: 28px; }
}
.who { font-size: .74rem; background: rgba(255,255,255,.09); padding: 5px 12px; border-radius: 20px; }
.right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.live { display: flex; align-items: center; gap: 7px; font-size: .74rem; color: var(--head-sub); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.theme-btn {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: var(--head-fg);
  font-family: 'Archivo'; font-size: .74rem; padding: 6px 13px; border-radius: 20px; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
}
.theme-btn:hover { background: rgba(255,255,255,.18); }

.loading-state { padding: 40px 16px; text-align: center; opacity: .7; }
.stale-banner {
  background: #422006; color: #fdba74; padding: 4px 10px; border-radius: 6px; font-size: .8rem;
}

.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px; background: var(--line); border-bottom: 1px solid var(--line);
}
/* #kpi-strip has an odd tile count (9) so auto-fit can leave the last row
   with one dangling empty cell at common widths (audit-fixes brief Part 7).
   Widening the last tile fills that gap at the widths actually seen. */
#kpi-strip > *:last-child { grid-column: span 2; }
.kpi { background: var(--panel); padding: 14px 20px; }
.kpi .n { font-family: 'Barlow Condensed'; font-weight: 600; font-size: 2rem; line-height: 1; }
.kpi .l { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; margin-top: 4px; }
.kpi .sub { font-size: .68rem; color: var(--muted); margin-top: 2px; }
.n.g { color: var(--green); } .n.o { color: var(--hivis); } .n.a { color: var(--amber); } .n.r { color: var(--red); }

.wrap { padding: 20px 24px 8px; }
.sec { font-family: 'Barlow Condensed'; font-weight: 600; font-size: 1rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.sec-em { font-style: normal; font-family: 'IBM Plex Mono'; font-size: .72rem; letter-spacing: 0; text-transform: none; }
.sub { font-size: .76rem; color: var(--muted); margin: 2px 0 14px; }
.corridor {
  position: relative; height: 150px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.corridor svg { width: 100%; height: 100%; min-width: 700px; }
.cl { font-family: 'IBM Plex Mono'; font-size: 10px; fill: var(--muted); }
.bl { font-family: 'IBM Plex Mono'; font-size: 9px; fill: var(--amber); }
.rte { stroke: var(--svgline); } .tick { stroke: var(--svgtick); } .citydot { fill: var(--svgcity); }
.td-mv { fill: var(--green); } .td-id { fill: var(--amber); } .td-st { fill: var(--blue); } .td-of { fill: var(--hivis); }
.td { stroke: var(--dotstroke); }

main { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; padding: 14px 24px 30px; }
@media (max-width: 960px) {
  main { grid-template-columns: 1fr; }
  /* Stacked mobile layout: Needs review/Delay reasons would otherwise sit
     below the full Active trips table (65+ rows), making the review count
     easy to miss (audit-fixes brief Part 3). Surface it first instead. */
  main .col:nth-child(2) { order: -1; }
}
.col { display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.card > h2 {
  font-family: 'Barlow Condensed'; font-weight: 600; font-size: .98rem; letter-spacing: .09em;
  text-transform: uppercase; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.card > h2 em { font-style: normal; font-family: 'IBM Plex Mono'; font-size: .72rem; color: var(--muted); }
.card.hot > h2 { background: var(--hivis); color: #fff; border-bottom: 0; }
.card.hot > h2 em { color: rgba(255,255,255,.85); }

.bd { padding: 14px 16px; border-bottom: 1px solid var(--row); display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; }
.bd:last-child { border-bottom: 0; }
.bd .t1 { font-weight: 600; font-size: .9rem; }
.bd .t1 .reg { font-family: 'IBM Plex Mono'; font-weight: 600; }
.bd .meta { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.clock { text-align: right; }
.flag { display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .06em; padding: 3px 8px; border-radius: 4px; margin-top: 5px; }
.f-neutral { background: var(--chipbg); color: var(--chipfg); }

table { width: 100%; border-collapse: collapse; font-size: .8rem; }
th {
  font-family: 'Barlow Condensed'; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  font-size: .7rem; color: var(--muted); text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--line);
}
td { padding: 9px 13px; border-bottom: 1px solid var(--row); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.reg { font-family: 'IBM Plex Mono'; font-weight: 500; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: var(--row); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .7rem; padding: 2px 9px; border-radius: 20px; white-space: nowrap; font-weight: 500; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.p-mv { color: var(--green); background: var(--pillg); }
.p-st { color: var(--blue); background: var(--pillb); }
.p-of { color: var(--hivis); background: var(--pillo); }
.p-id { color: var(--amber); background: var(--pilla); }
.p-ontrack { color: var(--green); background: var(--pillg); }
.p-watch { color: var(--amber); background: var(--pilla); }
.p-overdue { color: var(--red); background: var(--flagover); }
.p-workshop { color: var(--muted); background: var(--chipbg); }
.day { font-family: 'IBM Plex Mono'; }
.day.over { color: var(--red); font-weight: 600; }
.chip { font-size: .68rem; background: var(--chipbg); color: var(--chipfg); padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.chip.need { background: var(--flagover); color: var(--red); font-weight: 600; }

.bar-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: .76rem; }
.bar-row .lbl { width: 118px; color: var(--ink); }
.bar-row .bar { flex: 1; height: 12px; background: var(--chipbg); border-radius: 3px; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--muted); border-radius: 3px; }
.bar-row .v { font-family: 'IBM Plex Mono'; font-size: .7rem; color: var(--muted); width: 58px; text-align: right; }
.note { padding: 10px 16px 14px; font-size: .72rem; color: var(--muted); }

.empty-state { padding: 24px; text-align: center; }
.empty-state-title { font-weight: 600; margin: 0 0 4px; }
.empty-state-subtitle { opacity: .6; margin: 0; font-size: .85rem; }

table[data-scroll], .table-scroll { overflow-x: auto; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: var(--row); }
footer { padding: 8px 24px 26px; font-size: .7rem; color: var(--muted); font-family: 'IBM Plex Mono'; }

/* ---- Map panel ---- */
.map-panel {
  height: 300px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  z-index: 0;             /* keep Leaflet's stacking context below the detail panel */
}
@media (min-width: 768px) { .map-panel { height: 420px; } }

/* Dashboard-embedded map only (layout brief Part 2, design-audit brief
   Part 1) -- roughly half the base .map-panel height, AND a fixed max
   width that does not grow as the browser window is stretched wider --
   this is a small preview map, the full experience lives on the
   dedicated Live Map page (#live-map-canvas, map-panel-full, untouched). */
#map.map-panel { height: 150px; max-width: 640px; }
@media (min-width: 768px) { #map.map-panel { height: 210px; } }
.leaflet-container { font-family: 'Archivo', sans-serif; }
.truck-tooltip { font-family: 'IBM Plex Mono', monospace; font-size: .72rem; }

/* ---- Corridor dot interactivity ---- */
#corridor-trucks circle { cursor: pointer; }
#corridor-trucks circle.selected { stroke: var(--hivis); stroke-width: 3; }

/* ---- Truck detail panel ---- */
.detail-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000;
}
.detail-panel {
  position: fixed; z-index: 1001; background: var(--panel);
  border-left: 1px solid var(--line);
  top: 0; right: 0; bottom: 0; width: min(380px, 92vw);
  display: flex; flex-direction: column;
  box-shadow: -6px 0 24px rgba(0,0,0,.25);
}
@media (max-width: 767px) {
  .detail-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 78vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.25);
  }
}
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.detail-reg { font-size: 1.15rem; font-weight: 600; }
.detail-driver { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.detail-close {
  background: var(--chipbg); color: var(--chipfg); border: 0; border-radius: 8px;
  font-size: 1.3rem; line-height: 1; padding: 4px 11px 7px; cursor: pointer;
}
.detail-close:hover { background: var(--row); }
.detail-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.detail-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: .84rem; border-bottom: 1px solid var(--row); }
.detail-row .k { color: var(--muted); }
.detail-sec {
  font-family: 'Barlow Condensed'; font-weight: 600; font-size: .85rem;
  letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
  margin: 16px 0 6px;
}
.detail-note { font-size: .78rem; color: var(--muted); padding: 8px 0; }
.detail-notes { padding: 4px 0 8px; }
.notes-textarea {
  width: 100%; min-height: 72px; resize: vertical; box-sizing: border-box;
  font-family: 'Archivo'; font-size: .82rem; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--ink);
}
.notes-save-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.notes-save-status { font-size: .72rem; color: var(--muted); }
.detail-bd { padding: 8px 0; border-bottom: 1px solid var(--row); font-size: .8rem; }
.detail-bd .meta { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.spark { width: 100%; height: 44px; margin-top: 4px; }
.spark polyline { fill: none; stroke: var(--green); stroke-width: 2; }
.spark text { font-family: 'IBM Plex Mono'; font-size: 9px; fill: var(--muted); }

/* ---- Trip status board ---- */
.trip-remarks { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; color: var(--muted); }
.location-flag {
  display: inline-flex; align-items: center; gap: 5px; font-size: .68rem; font-weight: 600;
  color: var(--amber); background: var(--pilla); padding: 2px 8px; border-radius: 20px; margin-left: 6px; white-space: nowrap;
}
.unmatched-note {
  padding: 10px 16px 14px; font-size: .74rem; color: var(--muted); border-top: 1px solid var(--line);
}
.unmatched-note b { color: var(--ink); }
.unmatched-note ul { margin: 6px 0 0 18px; }

/* ---- Checkpoint progress (detail panel) ---- */
.checkpoint-leg { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 10px 0 4px; }
.checkpoint-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: .8rem; border-bottom: 1px solid var(--row); }
.checkpoint-row .cp-name { color: var(--ink); }
.checkpoint-row .cp-times { font-family: 'IBM Plex Mono'; font-size: .72rem; color: var(--muted); text-align: right; }
.checkpoint-row.cp-pending .cp-name, .checkpoint-row.cp-pending .cp-times { color: var(--muted); opacity: .55; }

/* ---- Clickable KPI tiles / filtering ---- */
.kpi.clickable { cursor: pointer; transition: box-shadow .15s, background .15s; }
.kpi.clickable:hover { background: var(--row); }
.kpi.active { box-shadow: inset 0 0 0 2px var(--hivis); background: var(--pillo); }
.filter-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; margin-bottom: 12px;
  background: var(--pillo); border: 1px solid var(--hivis); border-radius: 8px; font-size: .8rem;
}
.filter-bar b { color: var(--ink); }
.filter-bar button {
  margin-left: auto; background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-family: 'Archivo'; font-size: .74rem; padding: 4px 12px; border-radius: 14px; cursor: pointer;
}
.filter-bar button:hover { background: var(--row); }

/* ---- Movement digest panel ---- */
.digest-item { padding: 12px 16px; border-bottom: 1px solid var(--row); display: flex; align-items: flex-start; gap: 12px; }
.digest-item:last-child { border-bottom: 0; }
.digest-item .reg { flex-shrink: 0; padding-top: 1px; }
.digest-item .digest-body { flex: 1; font-size: .84rem; }
.digest-item .digest-meta { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.digest-severity-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--line); flex-shrink: 0; }
.digest-item.sev-high .digest-severity-bar { background: var(--red); }
.digest-item.sev-med .digest-severity-bar { background: var(--amber); }
.digest-item.sev-low .digest-severity-bar { background: var(--blue); }
.digest-arrow { color: var(--muted); margin: 0 4px; }
.digest-more-toggle {
  display: block; width: 100%; text-align: center; padding: 10px; background: none; border: 0;
  border-top: 1px solid var(--line); color: var(--blue); font-family: 'Archivo'; font-size: .78rem; cursor: pointer;
}
.digest-more-toggle:hover { background: var(--row); }
.digest-window-note { padding: 10px 16px; font-size: .72rem; color: var(--muted); }

/* ---- Grouped truck view ---- */
.group-region { border-bottom: 1px solid var(--line); }
.group-region:last-child { border-bottom: 0; }
.group-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer;
  font-family: 'Barlow Condensed'; font-weight: 600; font-size: .95rem;
}
.group-header:hover { background: var(--row); }
.group-header .chevron { font-size: .7rem; color: var(--muted); transition: transform .15s; width: 12px; }
.group-header.expanded .chevron { transform: rotate(90deg); }
.group-header .group-count { font-family: 'IBM Plex Mono'; font-weight: 400; font-size: .75rem; color: var(--muted); }
.group-region > .group-header { background: var(--panel2); }
.group-location-list { background: var(--panel); }
.group-location > .group-header {
  padding-left: 32px; font-size: .85rem; font-weight: 500; font-family: 'Archivo';
}
.group-trucks { overflow-x: auto; }
.group-trucks table { font-size: .8rem; }

@media (max-width: 640px) {
  .group-header { padding: 10px 14px; }
  .group-location > .group-header { padding-left: 26px; }
}

/* ---- Alerts (integrated into the digest panel) ---- */
.alert-item {
  padding: 12px 16px; border-bottom: 1px solid var(--row); display: flex; align-items: flex-start; gap: 12px;
  background: var(--flagover);
}
.alert-item .digest-severity-bar { background: var(--red); }
.alert-item .alert-badge {
  flex-shrink: 0; font-size: .62rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; background: var(--red); padding: 3px 7px; border-radius: 4px; margin-top: 1px;
}
.alert-item .digest-body { flex: 1; font-size: .84rem; }
.alert-item .digest-meta { font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* ---- Collapsible section headers (needs-review, digest panel, ...) ---- */
.collapsible-h2 { cursor: pointer; }
.collapsible-h2 .chevron {
  font-size: .7rem; color: var(--muted); margin-left: auto; transition: transform .15s;
}
.collapsible-h2.expanded .chevron { transform: rotate(90deg); }
.needs-review-item {
  padding: 9px 16px; border-bottom: 1px solid var(--row); font-size: .78rem; color: var(--muted);
}
.needs-review-item:last-child { border-bottom: 0; }

/* ---- FCL Workshop panel: deliberately calm, no alert/escalation styling ---- */
.fcl-workshop-card h2 em { color: var(--muted); }
.fcl-workshop-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--row); font-size: .82rem;
}
.fcl-workshop-item:last-child { border-bottom: 0; }
.fcl-workshop-item .reg { color: var(--ink); }
.fcl-workshop-item .fw-issue { color: var(--muted); flex: 1; }
.fcl-workshop-item .fw-since { color: var(--muted); font-size: .74rem; }
.needs-review-item .reg { color: var(--ink); font-size: .8rem; }
.needs-review-item .nr-detail { margin-top: 2px; }
.needs-review-more { padding: 8px 16px; font-size: .72rem; color: var(--muted); text-align: center; }
.needs-review-filter-row { padding: 10px 16px; border-bottom: 1px solid var(--row); }
.needs-review-filter-row .select-input { width: 100%; }
/* Bounded height instead of a hard 15-item cap -- every item stays reachable
   via scroll and filterable, rather than a dead-end "not shown here". */
.needs-review-scroll { max-height: 420px; overflow-y: auto; }

/* ==================================================================
   Multi-page shell: sidebar nav, page sections, mobile bottom nav
   ================================================================== */
#app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0; background: var(--navy); color: var(--head-fg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar-brand { padding: 18px 18px 14px; }
.sidebar-brand .brand-logo { background: #fff; border-radius: 8px; padding: 6px 10px; }
.sidebar-brand .brand-logo img { display: block; height: 34px; width: auto; }
.sidebar-brand small { display: block; margin-top: 8px; font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--head-sub); }

.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px; color: var(--head-sub);
  text-decoration: none; font-size: .86rem; font-weight: 500; border-left: 3px solid transparent;
  position: relative;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: var(--head-fg); }
.nav-link.active { background: rgba(255,255,255,.08); color: var(--head-fg); border-left-color: var(--hivis); }
.nav-icon { display: inline-block; width: 18px; text-align: center; font-size: 1.05rem; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: .66rem; font-weight: 700;
  padding: 1px 7px; border-radius: 10px; font-family: 'IBM Plex Mono';
}

.sidebar-footer {
  margin-top: auto; padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 10px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-footer .who { font-size: .72rem; background: rgba(255,255,255,.09); padding: 5px 12px; border-radius: 20px; width: fit-content; }
.sidebar-footer .live { display: flex; align-items: center; gap: 7px; font-size: .74rem; color: var(--head-sub); }
.sidebar-footer .live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
.sidebar-footer .theme-btn {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: var(--head-fg);
  font-family: 'Archivo'; font-size: .74rem; padding: 6px 13px; border-radius: 20px; cursor: pointer;
  display: flex; align-items: center; gap: 7px; width: fit-content;
}
.sidebar-footer .theme-btn:hover { background: rgba(255,255,255,.18); }

#main-content { flex: 1; min-width: 0; }
.page { display: block; }
.page.hidden { display: none !important; }

.map-panel-full { height: 70vh; min-height: 420px; }

.mobile-nav { display: none; }

.select-input {
  font-family: 'Archivo'; font-size: .82rem; padding: 7px 11px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--ink);
}
.csv-btn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
  font-family: 'Archivo'; font-size: .72rem; padding: 5px 12px; border-radius: 14px; cursor: pointer;
}
.csv-btn:hover { background: var(--row); }
.csv-btn:disabled { opacity: .5; cursor: default; }
.playback-label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

/* ---- Trip timeline ---- */
.timeline { display: flex; flex-direction: column; padding: 6px 16px 16px; }
.timeline-node { display: flex; gap: 14px; }
.timeline-node .tl-marker { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.timeline-node .tl-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--green); border: 2px solid var(--panel); box-shadow: 0 0 0 2px var(--green); margin-top: 3px; }
.timeline-node .tl-line { width: 2px; flex: 1; background: var(--line); min-height: 28px; }
.timeline-node:last-child .tl-line { display: none; }
.timeline-node.pending .tl-dot { background: var(--panel); box-shadow: 0 0 0 2px var(--line); }
.timeline-node.current .tl-dot { background: var(--amber); box-shadow: 0 0 0 2px var(--amber); }
.timeline-node.current .tl-title { color: var(--amber); }
.timeline-node .tl-body { padding-bottom: 22px; flex: 1; }
.timeline-node .tl-title { font-weight: 600; font-size: .88rem; }
.timeline-node.pending .tl-title { color: var(--muted); font-weight: 500; }
.timeline-node .tl-times { font-family: 'IBM Plex Mono'; font-size: .74rem; color: var(--muted); margin-top: 2px; }
.timeline-node .tl-pill { display: inline-block; font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--chipbg); padding: 1px 7px; border-radius: 10px; margin-left: 6px; }

/* ---- Reports: bar rows, sample-size notes ---- */
.report-row { padding: 10px 16px; border-bottom: 1px solid var(--row); font-size: .84rem; display: flex; justify-content: space-between; gap: 10px; }
.report-row:last-child { border-bottom: 0; }
.report-row .rr-meta { color: var(--muted); font-size: .72rem; }
.sample-flag { color: var(--amber); font-size: .68rem; font-weight: 600; }

/* ---- Data-age indicator (ops-feedback brief Part 7) ---- */
.report-as-of {
  font-family: 'IBM Plex Mono'; font-size: .7rem; letter-spacing: 0;
  text-transform: none; color: var(--muted); margin-left: 8px;
}
.report-as-of.stale {
  color: var(--hivis); font-weight: 600;
  background: var(--pillo); padding: 1px 8px; border-radius: 10px;
}

/* ---- Aged trips (Part 4): flagged group, no action controls ---- */
.aged-trips-card { border-left: 3px solid var(--red); }
.aged-trips-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 16px 14px; }
.aged-trip-row {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 11px; font-family: 'Archivo'; font-size: .8rem; color: var(--ink);
}
.aged-trip-row:hover { background: var(--row); }
.aged-trip-row .aged-days {
  font-family: 'IBM Plex Mono'; font-weight: 600; color: var(--red);
}
.aged-trip-row .aged-loc { color: var(--muted); font-size: .74rem; }

/* ---- Ops mapping controls on unclassified locations (Part 2) ---- */
.map-controls { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 8px; }
.map-controls .select-input { font-size: .78rem; padding: 5px 8px; }
.map-controls .map-note { min-width: 160px; flex: 1; }
.map-status { font-size: .74rem; color: var(--muted); }

/* ---- Insurance page ---- */
.ins-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 11px 16px; border-top: 1px solid var(--row);
}
.ins-row:first-child { border-top: 0; }
.ins-reg { font-family: 'IBM Plex Mono'; font-size: .86rem; font-weight: 600; }
.ins-type {
  font-family: inherit; font-size: .66rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); margin-left: 6px;
}
.ins-owner { font-size: .68rem; color: var(--muted); margin-left: 6px; }
.ins-dates, .ins-insurer { font-size: .74rem; color: var(--muted); margin-top: 2px; }
.ins-err { font-size: .72rem; color: var(--amber); margin-top: 2px; }
.ins-right { text-align: right; white-space: nowrap; }
.ins-days { font-size: .74rem; color: var(--muted); }
.ins-days.warn { color: var(--amber); }
.chip-unconfirmed {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .05em;
  background: var(--chipbg); color: var(--chipfg);
  padding: 1px 6px; border-radius: 3px; margin-left: 4px; white-space: nowrap;
}
.ins-days.bad { color: var(--red); font-weight: 600; }
.ins-premium { font-family: 'IBM Plex Mono'; font-size: .74rem; color: var(--muted); margin-top: 2px; }
.ins-oos { font-size: .74rem; color: var(--amber); margin-top: 2px; }
.pk-bill { display: flex; gap: 8px; align-items: baseline; font-size: .74rem; margin-top: 3px; flex-wrap: wrap; }
.pk-ctl { font-family: 'IBM Plex Mono'; color: var(--muted); }
.pk-desc { color: var(--muted); }
.pk-amt { font-family: 'IBM Plex Mono'; }
.pk-total { font-family: 'IBM Plex Mono'; font-size: .82rem; font-weight: 600; color: var(--hivis); }

/* ---- In-flight button + confirmation toast ---- */
.is-busy { position: relative; padding-left: 26px !important; opacity: .8; cursor: progress; }
.is-busy::before {
  content: ""; position: absolute; left: 9px; top: 50%; width: 11px; height: 11px;
  margin-top: -6px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .is-busy::before { animation-duration: 2.4s; }
}

.toast-host {
  position: fixed; z-index: 9999; left: 50%; bottom: 24px;
  transform: translateX(-50%); display: flex; flex-direction: column;
  gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 6px; font-size: .84rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
  opacity: 1; transition: opacity .3s ease, transform .3s ease;
  max-width: min(92vw, 420px); text-align: center;
}
.toast-err { background: var(--red); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); }
/* Mobile nav sits at the bottom -- lift the toast clear of it. */
@media (max-width: 900px) { .toast-host { bottom: 78px; } }

/* ---- Collapsible covered-by-type groups ---- */
.ins-group { border-top: 1px solid var(--row); }
.ins-group:first-child { border-top: 0; }
.ins-group > summary {
  cursor: pointer; padding: 11px 16px; display: flex; align-items: center;
  gap: 8px; font-family: 'Barlow Condensed'; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; font-size: .84rem;
  color: var(--muted); list-style: none;
}
.ins-group > summary::-webkit-details-marker { display: none; }
.ins-group > summary::before {
  content: "\25B8"; display: inline-block; transition: transform .12s ease;
  font-size: .8em; color: var(--muted);
}
.ins-group[open] > summary::before { transform: rotate(90deg); }
.ins-group > summary:hover { color: var(--ink); }
.ins-group > summary em { font-style: normal; color: var(--muted); font-size: .78rem; }
.ins-group > div { border-top: 1px solid var(--row); }

/* ---- Non-fleet reference sections ---- */
.nonfleet-card { opacity: .92; }
.nonfleet-card > h2 { color: var(--muted); }

/* ---- Finance page (top/bottom trucks by profit) ---- */
.fin-topbottom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 4px 16px 16px; }
.fin-topbottom-grid table { width: 100%; }

@media (max-width: 640px) {
  .ins-row { flex-direction: column; gap: 4px; }
  .ins-right { text-align: left; }
  .fin-topbottom-grid { grid-template-columns: 1fr; }
}

/* ---- Append-only truck note log ---- */
.note-log { margin-top: 12px; display: flex; flex-direction: column; }
.note-entry { padding: 9px 0; border-top: 1px solid var(--row); }
.note-entry:first-child { border-top: 0; }
.note-meta {
  font-family: 'IBM Plex Mono'; font-size: .68rem; color: var(--muted); margin-bottom: 3px;
}
.note-body { font-size: .84rem; white-space: pre-wrap; word-break: break-word; }

/* ---- Breakdown resolve control + close provenance ---- */
.bd-resolve { margin-top: 6px; white-space: nowrap; }
.bd-closed-by {
  display: block; margin-top: 5px; font-size: .66rem; color: var(--muted);
  font-family: 'IBM Plex Mono'; text-align: right;
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  #main-content { padding-bottom: 62px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 58px;
    background: var(--navy); z-index: 900; border-top: 1px solid rgba(255,255,255,.1);
  }
  .mobile-nav .nav-link {
    flex: 1; flex-direction: column; justify-content: center; align-items: center; gap: 2px;
    padding: 6px 2px; border-left: 0; font-size: .6rem;
    position: relative; background: none; border: 0; border-top: 3px solid transparent;
    color: var(--head-sub); font-family: 'Archivo'; cursor: pointer;
  }
  .mobile-nav .nav-link.active { border-top-color: var(--hivis); border-left-color: transparent; color: var(--head-fg); }
  .mobile-nav .nav-icon { font-size: 1.2rem; }
  .mobile-nav .nav-label { font-size: .6rem; line-height: 1.1; white-space: nowrap; }
  .mobile-nav .nav-badge {
    position: absolute; top: 2px; left: 50%; margin-left: 6px;
    font-size: .58rem; padding: 0 5px; border-radius: 8px; line-height: 1.3;
  }

  /* ---- "More" bottom sheet: same slide-up language as the detail panel ---- */
  .more-sheet {
    position: fixed; z-index: 1001; background: var(--panel);
    left: 0; right: 0; bottom: 0; width: 100%; max-height: 60vh;
    border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.25);
    display: flex; flex-direction: column;
  }
  .more-links { padding: 6px 0 12px; overflow-y: auto; }
  .more-link {
    display: flex; align-items: center; gap: 12px; padding: 13px 20px;
    color: var(--ink); text-decoration: none; font-size: .88rem; font-weight: 500;
    position: relative;
  }
  .more-link:hover, .more-link:active { background: var(--row); }
  .more-link .nav-icon { width: 20px; text-align: center; font-size: 1.05rem; color: var(--muted); }
  .more-link .nav-badge {
    margin-left: auto; background: var(--red); color: #fff; font-size: .66rem; font-weight: 700;
    padding: 1px 7px; border-radius: 10px; font-family: 'IBM Plex Mono';
  }
}

/* ---- Alerts page ---- */
.alert-card { border-bottom: 1px solid var(--line); padding: 12px 16px; }
.alert-card:last-child { border-bottom: 0; }
.alert-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.alert-card-top .alert-badge {
  font-size: .62rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; padding: 3px 8px; border-radius: 4px;
}
.alert-card-red .alert-card-top .alert-badge { background: var(--red); }
.alert-card-amber .alert-card-top .alert-badge { background: var(--amber); }
.alert-card-top .digest-meta { margin-left: auto; font-size: .72rem; color: var(--muted); }
.alert-card-body { font-size: .86rem; margin-bottom: 8px; }
.alert-card-status { display: flex; gap: 8px; margin-bottom: 8px; }
.alert-card-actions { display: flex; gap: 8px; }
.alert-card-evidence {
  margin-top: 10px; padding: 12px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px;
}
.alert-card-evidence .detail-sec:first-child { margin-top: 0; }
.alert-badge-inline {
  font-size: .6rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: #fff; padding: 2px 6px; border-radius: 3px; margin-right: 2px;
}
.alert-badge-red { background: var(--red); }
.alert-badge-amber { background: var(--amber); }

/* ---- Region pills (Dashboard, replaces the old corridor strip) ---- */
.region-pill-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px;
  padding: 12px 0;
}
.region-pill { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.region-pill-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.region-pill-name { font-family: 'Barlow Condensed'; font-weight: 600; font-size: .92rem; }
.region-pill-count { font-family: 'IBM Plex Mono'; font-size: .72rem; color: var(--muted); }
.region-pill-alerts-link {
  font-family: 'IBM Plex Mono'; font-size: .72rem; color: var(--hivis);
  background: none; border: none; cursor: pointer; padding: 0;
}
.region-pill-alerts-link:hover { text-decoration: underline; }
.region-pill-alerts-link:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.region-pill-directions { display: flex; flex-direction: column; gap: 6px; }
.region-pill-direction {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 8px; border-radius: 8px; background: var(--row);
}
.region-pill-direction-label { font-size: .74rem; color: var(--muted); min-width: 96px; }
.region-pill-direction.clickable { cursor: pointer; transition: box-shadow .15s, background .15s; }
.region-pill-direction.clickable:hover { background: var(--panel); }
.region-pill-direction.active { box-shadow: inset 0 0 0 2px var(--hivis); background: var(--pillo); }

/* Director-only nav items (layout brief Part 5) -- hidden by default, only
   revealed by JS once /auth/me confirms the "director" role. This is UX
   only; the real access control is nginx auth_request on the server. */
.director-only { display: none; }
.director-only.nav-link-visible { display: flex; }

/* ---- Breakdowns page (one card per truck) ---- */
.truck-card-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px;
  padding: 12px 0 24px;
}
.truck-breakdown-card .bd:last-child { border-bottom: 0; }
.bd-count-badge { background: var(--chipbg); color: var(--chipfg); padding: 2px 8px; border-radius: 10px; }
.bd-tag {
  font-size: .64rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 3px;
}
.bd-headline .t1 { font-size: 1rem; }
.bd-secondary { background: var(--panel2); border-top: 1px solid var(--line); }
.bd-secondary-label {
  padding: 8px 16px 0; font-size: .66rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.bd-secondary .bd { padding: 8px 16px; }
.bd-secondary .bd .t1 { font-size: .82rem; font-weight: 500; }

/* ---- Fine detail table (Fines page) ---- */
.fine-detail-table { margin-top: 6px; font-size: .78rem; }
.fine-detail-table th { font-size: .64rem; padding: 6px 10px; }
.fine-detail-table td { padding: 7px 10px; }
/* Control number: plain selectable text, monospace for easy reading and
   clean copy-paste -- staff need to copy this exact value to pay the fine. */
.fine-detail-table td.fine-ref {
  font-family: 'IBM Plex Mono', monospace; white-space: nowrap; user-select: all;
}
