/* Plow — live ops dashboard */
:root {
  color-scheme: light;
  --page: #eef0f3;
  --surface: #ffffff;
  --sunken: #f4f5f7;
  --ink: #0f1b2d;
  --ink-2: #4a5263;
  --muted: #6b7280;
  --hair: #e3e6ea;
  --ring: rgba(15,27,45,0.10);
  --accent: #1a6ee6;
  --accent-ink: #1a62cc;
  --salt: #f07c1b;
  --salt-ink: #b95000;
  --idle: #9aa1ad;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(15,27,45,0.08), 0 4px 14px rgba(15,27,45,0.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0b0d10; --surface: #16191e; --sunken: #1d2127;
    --ink: #f3f5f8; --ink-2: #c1c6cf; --muted: #8d94a0;
    --hair: #2a2f37; --ring: rgba(255,255,255,0.10);
    --accent: #3d8bf0; --accent-ink: #7fb2f7; --salt: #f28a30; --salt-ink: #f5a55e;
    --idle: #6b7280;
    --shadow: 0 1px 2px rgba(0,0,0,0.5), 0 4px 14px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0d10; --surface: #16191e; --sunken: #1d2127;
  --ink: #f3f5f8; --ink-2: #c1c6cf; --muted: #8d94a0;
  --hair: #2a2f37; --ring: rgba(255,255,255,0.10);
  --accent: #3d8bf0; --accent-ink: #7fb2f7; --salt: #f28a30; --salt-ink: #f5a55e;
  --idle: #6b7280;
  --shadow: 0 1px 2px rgba(0,0,0,0.5), 0 4px 14px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
a { color: var(--accent-ink); }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 32px; background: var(--surface);
  border-bottom: 1px solid var(--hair); z-index: 1001;
}
.brand { display: flex; align-items: baseline; gap: 20px; min-width: 0; }
.word { font-size: 32px; font-weight: 900; letter-spacing: 0.01em; line-height: 1; }
.place { font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.status.err { color: var(--critical); }

/* layout */
.app { flex: 1 1 auto; min-height: 0; display: flex; }
.panel {
  flex: 0 0 468px; overflow-y: auto; background: var(--page);
  display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px;
}
.mapwrap { position: relative; flex: 1 1 auto; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--sunken); }

/* panel sections */
.sec { background: var(--surface); padding: 22px 28px 20px; }
.sec h2 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.sec h2 + * { margin-top: 14px; }
.note { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; }
.note[hidden] { display: none; }
.note + .stats { margin-top: 14px; }
.note.err { color: var(--critical); }
.fine { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.muted { color: var(--muted); }

.alert { margin: 0; padding: 14px 28px; font-size: 13px; background: var(--surface); color: var(--ink); }
.alert b { display: block; color: var(--critical); font-size: 14px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); }
.stat { padding: 0 10px; border-left: 1px solid var(--hair); min-width: 0; }
.stat:first-child { padding-left: 0; border-left: 0; }
.sv { font-size: 28px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.sl { font-size: 13px; color: var(--ink); margin-top: 6px; line-height: 1.3; }
.ss { font-size: 12px; color: var(--muted); line-height: 1.3; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--ink); padding: 8px; background: var(--sunken); }
td { padding: 8px; border-bottom: 1px solid var(--hair); color: var(--ink); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.fc th:first-child, .fc td:first-child { padding-left: 8px; }
.fc td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.fc td:first-child { white-space: normal; }
#fcTotals td { font-weight: 500; padding-top: 10px; padding-bottom: 10px; }
#fcTotals tr:last-child td { border-bottom: 2px solid var(--hair); }
.fc .snowy { color: var(--accent-ink); font-weight: 600; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunken); border-radius: 4px; margin: 14px 0 12px; }
.tabs button { border: 0; background: transparent; padding: 8px 10px; border-radius: 4px; cursor: pointer; color: var(--ink); font-size: 13px; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.tt tbody tr { cursor: pointer; }
.tt tbody tr:hover td { background: var(--sunken); }
.tt tbody tr.sel td { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.tt td:first-child { font-variant-numeric: tabular-nums; }
.st { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.st::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--idle); flex: 0 0 auto; }
.st.moving::before { background: var(--accent); }
.st.stsalt::before { background: var(--salt); }
.st.parked { color: var(--muted); }
.st.parked::before { background: transparent; box-shadow: inset 0 0 0 2px var(--idle); }
.empty td { color: var(--muted); cursor: default; }

.source { padding: 16px 28px 8px; font-size: 12px; color: var(--muted); }
.source p { margin: 0 0 6px; }
.source p:last-child { margin: 0; }

/* map overlays */
.chip, .seg, .btn, .zoom, .legend, .loading {
  position: absolute; z-index: 1000; background: var(--surface); box-shadow: var(--shadow); border-radius: 6px;
}
.chip { top: 16px; left: 16px; padding: 8px 16px; font-size: 14px; color: var(--ink); max-width: calc(100% - 32px); }
.chip:empty { display: none; }
.chip b { font-weight: 600; }
.mapctl { position: absolute; top: 16px; right: 16px; z-index: 1000; display: flex; gap: 8px; }
.mapctl .seg, .mapctl .btn { position: static; }
.seg { display: flex; padding: 4px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 4px; min-height: 34px;
  font-size: 14px; cursor: pointer; color: var(--ink);
}
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.btn { border: 0; padding: 0 20px; min-height: 42px; font-size: 14px; font-weight: 500; cursor: pointer; }
.zoom { right: 16px; bottom: 100px; display: flex; flex-direction: column; background: transparent; box-shadow: none; gap: 8px; }
.zoom button {
  width: 42px; height: 42px; border: 0; background: var(--surface); box-shadow: var(--shadow);
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink); display: grid; place-items: center;
}
.zoom #zin { border-radius: 6px 6px 0 0; }
.zoom #zout { border-radius: 0 0 6px 6px; margin-top: -8px; border-top: 1px solid var(--hair); }
.zoom #locate { border-radius: 6px; }
.legend {
  right: 16px; bottom: 30px; padding: 10px 18px; display: flex; flex-wrap: wrap; gap: 6px 22px;
  font-size: 13px; color: var(--ink-2); max-width: calc(100% - 32px);
}
.legend .row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend .sw { width: 34px; height: 4px; border-radius: 2px; }
.legend .dt { width: 12px; height: 12px; border-radius: 50%; background: var(--salt); }
.loading { top: 64px; left: 16px; font-size: 12px; color: var(--ink-2); padding: 4px 10px; }
.loading[hidden] { display: none; }

.leaflet-container { background: var(--sunken); font: inherit; }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 80%, transparent) !important;
  color: var(--muted) !important; font-size: 11px !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-tooltip { background: var(--surface); color: var(--ink); border: 0; box-shadow: var(--shadow); }

/* truck markers */
.tk { position: relative; width: 32px; height: 32px; }
.tk .body {
  position: absolute; inset: 0; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(0,0,0,0.35);
  display: grid; place-items: center;
}
.tk .body svg { width: 18px; height: 18px; }
.tk.idle .body { background: var(--idle); }
.tk.parked .body { background: var(--idle); opacity: 0.75; }
.tk.stsalt .body { background: var(--salt); }
.tk.msalt .body::after {
  content: ""; position: absolute; right: -3px; top: -3px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--salt); box-shadow: 0 0 0 2px #fff;
}
.tk.sel .body { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink), 0 2px 6px rgba(0,0,0,0.35); }
.tk .lab {
  position: absolute; left: 40px; top: 7px; font-size: 14px; font-weight: 700; white-space: nowrap;
  color: #0f1b2d; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 4px #fff, 0 0 6px #fff;
}
.me { width: 16px; height: 16px; border-radius: 50%; background: #1a6ee6; box-shadow: 0 0 0 3px #fff, 0 0 0 9px rgba(26,110,230,0.2); }

/* tablet */
@media (max-width: 1100px) {
  .panel { flex-basis: 400px; }
  .sec { padding: 18px 20px; }
  .alert, .source { padding-left: 20px; padding-right: 20px; }
  .top { padding: 10px 20px; }
  .legend { left: 16px; right: 70px; bottom: 26px; }
}

/* phones: map on top, panel scrolls below */
@media (max-width: 760px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .app { flex-direction: column; }
  .mapwrap { flex: 0 0 auto; height: 60vh; min-height: 360px; order: -1; }
  .panel { flex: 1 1 auto; overflow: visible; }
  .top { padding: 10px 16px; }
  .word { font-size: 22px; }
  .brand { gap: 10px; }
  .place { font-size: 12px; }
  .sec { padding: 16px; }
  .alert, .source { padding-left: 16px; padding-right: 16px; }
  .chip { top: 64px; left: 12px; font-size: 13px; padding: 6px 12px; }
  .mapctl { top: 12px; left: 12px; right: 12px; justify-content: space-between; }
  .seg button { padding: 6px 12px; }
  .btn { min-height: 42px; padding: 0 16px; }
  .zoom { right: 12px; bottom: 96px; }
  .zoom button { width: 38px; height: 38px; }
  .legend { left: 12px; right: 12px; bottom: 22px; padding: 8px 12px; gap: 4px 14px; font-size: 12px; }
  .legend .sw { width: 22px; }
  .sv { font-size: 22px; }
  .stat { padding: 0 8px; }
  .sl { font-size: 12px; }
  .fc td, .fc th, .tt td, .tt th { padding: 7px 5px; }
  table { font-size: 12px; }
  .st { gap: 6px; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; row-gap: 14px; }
  .stat:nth-child(3) { padding-left: 0; border-left: 0; }
  .place { display: none; }
}


/* soften the street basemap so trails and trucks carry the color */
:root:not([data-theme="dark"]) .leaflet-tile-pane { filter: saturate(0.45) brightness(1.08) contrast(0.92); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .leaflet-tile-pane { filter: none; } }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tk .lab { color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 5px #000; }
}
:root[data-theme="dark"] .tk .lab { color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 5px #000; }
@media (max-width: 760px) { .legend { bottom: 44px; } .zoom { bottom: 118px; } }

/* ---------- motion touches ---------- */
/* rolling stat digits */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sv > span:not(.sr) { -webkit-user-select: none; user-select: none; }
.sv .dg { display: inline-block; height: 1.15em; overflow: hidden; vertical-align: top; }
.sv .strip { display: flex; flex-direction: column; transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sv .strip > span { height: 1.15em; line-height: 1.15em; text-align: center; }
.sv .dg:nth-child(2) .strip { transition-delay: 0.04s; }
.sv .dg:nth-child(3) .strip { transition-delay: 0.08s; }
.sv .dg:nth-child(4) .strip { transition-delay: 0.12s; }

/* sliding highlight behind the pressed toggle */
.mapctl .seg, .tabs { position: relative; }
.has-slide .slide {
  position: absolute; left: 0; top: 0; z-index: 0; border-radius: 4px; background: var(--accent);
  box-shadow: 0 1px 2px rgba(15,27,45,0.18);
  transition: transform 0.38s cubic-bezier(0.3, 0.9, 0.2, 1), width 0.38s cubic-bezier(0.3, 0.9, 0.2, 1);
}
.has-slide button { position: relative; z-index: 1; transition: color 0.2s ease; }
.has-slide button[aria-pressed="true"] { background: transparent; }
.seg button:not([aria-pressed="true"]):hover, .tabs button:not([aria-pressed="true"]):hover { color: var(--accent-ink); }

/* soft entrances */
.enter tr { animation: rowIn 0.18s ease-out both; }
@keyframes rowIn { from { opacity: 0; } }
.tt td { transition: background-color 0.25s ease; }

@media (prefers-reduced-motion: reduce) {
  .sv .strip, .has-slide .slide, .has-slide button, .tt td { transition: none; }
  .enter tr { animation: none; }
}
/* idle trucks bunch up at the garage; label them once zoomed in */
#map.far .tk.idle:not(.sel) .lab, #map.far .tk.parked:not(.sel) .lab { display: none; }
