/* Schmaps — Canadian-themed PWA styles */

:root {
  /* Navigation design-system tokens */
  --nav-bg: #e2e8f0;
  --nav-card-bg: rgba(255, 255, 255, 0.92);
  --nav-surface: #f1f5f9;
  --nav-primary: #1e3a8a;
  --nav-primary-text: #ffffff;
  --nav-accent: #2563eb;
  --nav-text-main: #0f172a;
  --nav-text-sub: #475569;
  --nav-border: rgba(203, 213, 225, 0.8);
  --nav-route: #2563eb;
  /* Dual-state location cursor (spec §2) */
  --cursor-color: #2563eb;
  --cursor-border: #ffffff;
  /* Compact spatial sizing (spec §3) */
  --right-rail-width: 58px; /* slim: just wide enough for "120" */
  /* The search box's slot at the top: its height plus gaps. Folds to 0
     while navigating (body.topbar-collapsed, Spec §3.4b) and everything
     below — banner, rail, toasts — moves up with it. */
  --top-slot: 64px;
  --top-bar-height: 52px;
  --touch-target-min: 56px;
  --red: #d52b1e;
  --red-dark: #a91f15;
  --ink: #1c1c1e;
  --ink-soft: #5a5a5e;
  --panel: #ffffff;
  /* A touch of transparency — the map stays faintly visible under the
     full-width bottom navigation card. */
  --panel-translucent: rgba(255, 255, 255, 0.90);
  --line: #e6e6e8;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  /* Width reserved at the screen's right edge for the bottom-right map
     controls (zoom, locate, attribution) — bottom overlays never
     stretch into it. */
  --map-ctrl-strip: 48px;
  --info-rail: 96px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win — a display rule on the same
   element (#update-bar's flex, .errands-list's flex column) would
   otherwise override the browser's [hidden] { display: none } and
   leave "hidden" UI visible on screen. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--nav-text-main);
  background: var(--nav-bg);
}

#map {
  position: fixed;
  inset: 0;
}

/* Map popups (drop-pin "Navigate here", stop/incident details) must
   stack ABOVE the HUD chrome — MapLibre leaves them at z-index auto,
   which paints below every positioned panel (route card 20, rail 21,
   status 30). 32 clears the lot. */
.maplibregl-popup {
  z-index: 32;
}

/* ---------- spec §7: transparent status bar safe-area helper ----------
   The map canvas extends edge-to-edge; HUD overlays pad their content
   inside the safe-area insets so notches and Android gesture bars never
   clip a control's touch target. Container positions still use the env()
   offset directly so the dock stays where the spec says. */
.hud-overlay {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ---------- ZONE 1: top navigation search bar ---------- */

#topbar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  /* Full screen width — the ⋮ quick-options button lives inside the
     search box (right of the mic), so nothing needs to be dodged. */
  left: 12px;
  right: 12px;
  z-index: 20;
}

#search-form {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  height: var(--top-bar-height);
  border: 1px solid var(--nav-border);
  border-radius: 12px;
  /* room for TWO docked buttons: the ⋮ quick options (right) and the
     mic (left of it) */
  padding: 0 92px 0 16px;
  font-size: 14px;
  font-weight: 500;
  background: var(--nav-card-bg);
  color: var(--nav-text-main);
  box-shadow: var(--shadow);
  outline: none;
}

#search-input:focus {
  box-shadow: var(--shadow), 0 0 0 2px var(--nav-accent);
}

/* Android-standard mic docked inside the right boundary of the input,
   with the ⋮ quick-options button to its right. */
#mic-btn {
  position: absolute;
  right: 50px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--nav-accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

/* Quick options (⋮) — the top-right focal point, docked inside the
   search box. Opens the quick-options menu, anchored to the box. */
#breadcrumb-btn {
  position: absolute;
  right: 6px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--nav-text-main);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

#breadcrumb-btn:hover { background: var(--nav-surface); }
#breadcrumb-btn:active { transform: scale(0.95); }

#mic-btn:hover { background: var(--nav-surface); }

#mic-btn:active { transform: scale(0.92); }

/* ---------- ZONE 2: right hand rail (control dock) ---------- */

#right-rail {
  position: fixed;
  /* Starts below the full-width search box and runs down the right
     edge to the bottom navigation card. */
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot) + var(--turn-banner-h, 0px));
  right: 12px;
  transition: top 0.18s ease;
  z-index: 21;
  width: var(--right-rail-width);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

#breadcrumb-menu {
  /* Anchored to the search box (the menu's offset parent is
     #search-form), dropping below the input's right edge. */
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 180px;
  background: var(--nav-card-bg);
  border: 1px solid var(--nav-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#breadcrumb-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--nav-text-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#breadcrumb-menu button:hover { background: var(--nav-surface); }

/* §3.6 — the TTS sub-line under the Voice item: which engine is
 * speaking (Azure neural vs the browser's Web Speech). */
.voice-source {
  padding: 2px 12px 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--nav-text-faint, var(--nav-text-main));
  opacity: .75;
}

/* AI understanding toggle — highlighted (aria-pressed) = the LLM
 * backend is active for query understanding. */
#ai-toggle[aria-pressed="true"] {
  background: var(--nav-surface);
  color: var(--blue, #1976d2);
}
#ai-toggle[aria-pressed="true"] .theme-icon { filter: none; }

#voice-toggle .icon-off { display: none; }

#voice-toggle.muted .icon-on { display: none; }
#voice-toggle.muted .icon-off { display: block; }

/* Speedometer module — same width as the breadcrumb button. */
#speed-module {
  width: 100%;
  background: var(--nav-card-bg);
  border: 1px solid var(--nav-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 5px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#speed-module .speed-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--nav-text-sub);
}

#current-speed {
  font-size: 24px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 900;
  line-height: 1.1;
  color: var(--nav-text-main);
  font-variant-numeric: tabular-nums;
}

/* Speed limit sign — classic red-ring badge, docked under the speed.
   The red ring is universal (it has to read as a speed-limit sign at a
   glance regardless of theme), but the interior flips to match the
   theme so the badge doesn't blast a white square into a dark map.
   See #speed-limit-bg in §10.7. */
#speed-limit {
  /* A round sign, the size of the rail — reads as a limit sign, not a pill. */
  width: var(--right-rail-width);
  height: var(--right-rail-width);
  background: var(--speed-limit-bg, #fff);
  border: 4px solid var(--red);
  border-radius: 999px;
  color: var(--speed-limit-fg, var(--ink));
  font-size: 18px;
  font-weight: 900;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
  /* No CSS transition on background: the comparator flips several times per
     second on a noisy GPS, and a 150 ms transition smears the colour
     into a wash that loses the band signal. Snap the colour change
     instantly — the ring colour is the high-signal cue, not a fade. */
}

/* Spec §10.9 — speed-limit comparator: ring color encodes current-vs-limit.
   Asymmetric +5/+15 km/h bands (see public/js/app.js#speedLimitBand for
   the full table) with 2 km/h hysteresis to keep the badge steady on a
   noisy GPS. The interior digits stay theme-driven; only the border +
   a soft interior wash change with the state. The new tokens land in
   both theme blocks (§10.7 dark + §10.7 light). */
#speed-limit[data-state="ok"] {
  /* 12% green wash. The exact hex values land in each theme block as
     `--speed-limit-ok-bg` / `--speed-limit-warn-bg` /
     `--speed-limit-over-bg`. See the comment above the base #speed-limit
     rule for why we don't use color-mix() and skip a CSS transition
     here (the comparator flips multiple times per second on noisy GPS). */
  background: var(--speed-limit-ok-bg);
}
#speed-limit[data-state="warn"] {
  background: var(--speed-limit-warn-bg);
}
#speed-limit[data-state="over"] {
  background: var(--speed-limit-over-bg);
}
#speed-limit[data-state="idle"] {
  /* No comparator (unposted, or no current-speed reading). Stay
     neutral — the universal red ring from the base rule is correct,
     and the interior returns to the plain panel colour. */
  background: var(--speed-limit-bg);
}
/* `ok` and `warn` swap the border to the comparator color. `over` and
   `idle` keep the original red so an over-limit badge still reads
   instantly as a speed-limit sign at a glance (color reinforcement
   rather than replacement). */
#speed-limit[data-state="ok"]   { border-color: var(--speed-limit-ok); }
#speed-limit[data-state="warn"] { border-color: var(--speed-limit-warn); }

/* ---------- ZONE 3: left hand pane ---------- */

#left-pane {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot));
  transition: top 0.18s ease;
  left: 12px;
  right: 12px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  /* The directions banner spans the screen (lane guidance needs the
     room); capped so it doesn't sprawl on a tablet. */
  max-width: 560px;
  pointer-events: none; /* the gap beside Recenter stays map */
}
#left-pane > * { pointer-events: auto; }

/* ---------- did-you-mean suggestions ---------- */

#suggest-bar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot));
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(92vw, 520px);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.suggest-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggest-chip {
  border: 1.5px solid var(--red);
  background: #fff;
  color: var(--red-dark);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  /* No CSS transition on background: the comparator flips several times per
     second on a noisy GPS, and a 150 ms transition smears the colour
     into a wash that loses the band signal. Snap the colour change
     instantly — the ring colour is the high-signal cue, not a fade. */
}

.suggest-chip:hover,
.suggest-chip:focus-visible {
  background: var(--red);
  color: #fff;
  outline: none;
}

.suggest-chip .chip-prov {
  font-weight: 400;
  opacity: 0.75;
}

/* ---------- voice help (mic tap) ---------- */

#voice-help {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot));
  left: 50%;
  transform: translateX(-50%);
  z-index: 27;
  width: min(92vw, 460px);
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.voice-help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.voice-help-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#voice-help-close {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#voice-help-close:hover,
#voice-help-close:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

.voice-help-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-help-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  line-height: 1.35;
}

.vh-phrase {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vh-mode {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.vh-drive { background: #e3ecf9; color: #1a4c8b; }
.vh-walk  { background: #e3efe1; color: #1f7a3a; }
.vh-bike  { background: #fdeee0; color: #a05a1a; }
.vh-auto  { background: #f0f0f2; color: var(--ink-soft); }

[data-theme="dark"] .vh-drive { background: #1c2a44; color: #8ab4f8; }
[data-theme="dark"] .vh-walk  { background: #1a3829; color: #34d27a; }
[data-theme="dark"] .vh-bike  { background: #3a2a17; color: #f0b46a; }
[data-theme="dark"] .vh-auto  { background: rgba(255, 255, 255, 0.08); color: #8b949e; }

.voice-help-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
}

.voice-help-got-it {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--blue, #1976d2);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.voice-help-got-it:hover,
.voice-help-got-it:focus-visible {
  outline: none;
  filter: brightness(1.08);
}

.voice-help-got-it:active { transform: scale(0.98); }

/* ---------- typeahead autocomplete ---------- */

#autocomplete {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot));
  left: 12px;
  right: 12px;
  z-index: 26;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  max-height: min(50vh, 420px);
  overflow-y: auto;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.ac-item.active,
.ac-item:hover {
  background: #f7f7f8;
}

.ac-icon {
  flex: none;
  font-size: 15px;
}

.ac-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ac-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac-sub {
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#mic-btn.listening {
  background: var(--red-dark);
  animation: pulse 1.1s ease-in-out infinite;
}

#mic-btn:disabled {
  background: #9a9a9e;
  cursor: not-allowed;
}

@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(213, 43, 30, 0.55); }
  50%      { box-shadow: var(--shadow), 0 0 0 14px rgba(213, 43, 30, 0); }
}

/* ---------- status toast ---------- */

#status {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot) + var(--turn-banner-h, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(92vw, 480px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  text-align: center;
}

/* ---------- the box folds into the banner while driving (§3.4b) ---------- */

body.topbar-collapsed { --top-slot: 0px; }
body.topbar-collapsed #topbar { display: none; }

/* 🔍 / 🎤 on the rail, under the speed-limit sign — only while the box
   is folded, so the banner keeps the full width (Spec §3.4b). */
.rail-actions {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
body.topbar-collapsed .rail-actions { display: flex; }

.rail-actions button {
  width: var(--right-rail-width);
  height: var(--right-rail-width);
  border: 1px solid var(--nav-border);
  border-radius: 50%;
  background: var(--nav-card-bg);
  color: var(--nav-text-main);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
}
#nav-mic-btn { color: var(--blue, #1976d2); }
.rail-actions button:active { transform: scale(0.94); }

/* ---------- quick chips under the box (§3.4a) ---------- */

.quick-chips {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot));
  left: 12px;
  right: 12px;
  max-width: 560px;
  z-index: 26;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--nav-border);
  border-radius: 999px;
  background: var(--nav-card-bg);
  color: var(--nav-text-main);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quick-chip.cat { color: var(--blue, #1976d2); }

/* ---------- answers under the box (§3.6) ---------- */

.answer-card {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px + var(--top-slot) + var(--turn-banner-h, 0px));
  left: 12px;
  right: 12px;
  max-width: 560px;
  z-index: 29;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--nav-card-bg);
  color: var(--nav-text-main);
  border: 1px solid var(--nav-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 52px 14px 16px;
}

.answer-q {
  font-size: 13px;
  color: var(--nav-text-sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.answer-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

#answer-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--nav-text-sub);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- ZONE 3 / Slot 1: turn-by-turn maneuver dialog ---------- */

#turn-banner {
  display: flex;
  flex-wrap: wrap; /* lanes drop to a full-width row of their own */
  align-items: center;
  gap: 10px 14px;
  width: 100%;
  background: var(--nav-card-bg);
  color: var(--nav-text-main);
  border: 1px solid var(--nav-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.turn-icon {
  flex: none;
  width: 60px;
  height: 60px;
  font-size: 36px;
  line-height: 1;
  border-radius: 12px;
  background: var(--nav-primary);
  color: var(--nav-primary-text);
  display: grid;
  place-items: center;
  text-align: center;
}

.turn-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: center;
}

#turn-instruction {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  /* Two lines before it truncates — street names are long. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--nav-text-main);
}

.turn-distance {
  font-size: 32px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 800;
  color: var(--nav-accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* Lane guidance — its own full-width row under the instruction, lanes
   centred, valid lanes lit. Sized to read at a glance. */
.turn-lanes {
  flex: 1 0 100%;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--nav-border);
}

.lane {
  width: 36px;
  height: 44px;
  border-radius: 8px;
  background: #3f3f46;
  display: grid;
  place-items: center;
  font-size: 24px;
  color: #71717a;
}

.lane.valid {
  background: #0e7490;
  color: #fff;
}

/* ---------- route HUD (compact, bottom-left) ---------- */

#route-panel {
  position: fixed;
  /* Full screen width — the bottom navigation card spans edge to edge. */
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 20;
  /* Translucent — the map peeks through the full-width card. */
  background: var(--panel-translucent, var(--panel));
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 6px 16px 12px;
  /* The card owns its gestures (Spec §3.2b) — no browser panning. */
  touch-action: none;
}

#route-panel.swiping,
.errands-list li.swiping { transition: none; }
#route-panel:not(.swiping) { transition: transform 0.2s ease, opacity 0.2s ease; }

/* Grab handle — the bottom-sheet cue that the card swipes. */
.card-handle {
  width: 40px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--ink-soft) 45%, transparent);
}

.swipe-hint {
  margin: -2px 0 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Visually hidden, still reachable by keyboard and screen readers. */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

#close-route-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink-soft) 14%, transparent);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#close-route-btn:hover,
#close-route-btn:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

.route-stats {
  /* One row, three columns sized to their content, spread across the
     FULL card width under the ＋ / ✕ strip (Spec §5.1) — never beside
     the buttons, where the big numbers collide at phone width. */
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: space-between;
  column-gap: 12px;
}

.route-stats .stat { min-width: 0; }

/* Spec §3.1 — Selection mode: a clear "Start" CTA sits below the
 * route stats so the user has a one-tap path to commit to the current
 * primary. Becomes the same navigation gesture as tapping the primary
 * badge on the map. Hidden once navigation begins.
 *
 * Auto-start countdown: the button starts as a LIGHT blue wash and
 * fills left→right with the solid blue over START_TIMEOUT.ms — the
 * fill IS the countdown. When it completes, navigation auto-starts on
 * the current primary (the suggested route). The fill is a ::before
 * overlay so the label stays crisp above it. */
.start-route-btn {
  position: relative;
  display: block;
  width: 100%;
  margin: 12px 0 4px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(25, 118, 210, 0.28); /* light blue — the unfilled state */
  border: none;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(25, 118, 210, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  overflow: hidden; /* clip the fill to the button's rounded box */
  isolation: isolate; /* stacking context: the fill paints above the
                         background but below the label text */
}
/* The countdown fill — solid blue sweeping left→right. Width is
 * driven by JS (a CSS custom property) so the timer can be cancelled
 * or restarted without animation juggling; linear so it matches the
 * wall-clock timeout exactly. */
.start-route-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  width: var(--fill, 0%);
  background: var(--blue, #1976d2);
  border-radius: inherit;
  transition: width 0.15s linear;
  pointer-events: none;
  z-index: -1; /* above the light-blue background, below the label */
}
.start-route-btn:hover,
.start-route-btn:focus-visible {
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(25, 118, 210, 0.45);
}
.start-route-btn:active { transform: translateY(0); }
.start-route-btn[hidden] { display: none; }
/* Reduced motion: the fill still tracks the timeout (it's information,
 * not decoration) but stops animating between ticks. */
@media (prefers-reduced-motion: reduce) {
  .start-route-btn::before { transition: none; }
}

.label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat strong {
  display: block;
  /* 24px on a roomy screen, easing down on a narrow phone so
     "47 h 33 min" still fits beside its neighbours. */
  font-size: clamp(18px, 5.4vw, 24px);
  font-weight: 800;
  margin-top: 2px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Units ride small beside their numbers — "23 km", "4:05 pm" — the
   number is the glance (Spec §5.1). */
.unit {
  font-size: 0.55em;
  font-weight: 700;
  margin: 0 0.3em 0 0.12em;
  letter-spacing: 0.01em;
}
.unit:last-child { margin-right: 0; }

/* Arrival is the hero number on a one-stop card too. */
.route-stats .stat:last-child strong { color: var(--trip-accent); }

/* "Add a stop" — visually hidden now (swipe up, Spec §3.2b); these
   rules only matter if .sr-only is ever dropped. Formerly a circular ＋
   docked in the card's top-right
   corner beside the ✕. The big pill is gone: screen real estate is for
   the map, and the affordance only needs to be discoverable, not loud.
   Opens the same detour sheet (§3.3). */
.options-btn {
  position: absolute;
  top: 8px;
  right: 56px;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  font-weight: 600;
  color: var(--blue, #1976d2);
  background: color-mix(in srgb, var(--blue, #1976d2) 12%, transparent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.12s ease;
}

.options-btn:hover,
.options-btn:focus-visible {
  background: color-mix(in srgb, var(--blue, #1976d2) 14%, transparent);
  outline: none;
}

.options-btn:active { transform: scale(0.92); }

/* ---------- USA-crossing banner + alternative-route chips ---------- */

.usa-banner {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: #8a4b00;
  background: #fff4e0;
  border: 1px solid #ffd9a0;
  border-radius: 10px;
  padding: 7px 10px;
}

.alt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.alt-chip {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  /* No CSS transition on background: the comparator flips several times per
     second on a noisy GPS, and a 150 ms transition smears the colour
     into a wash that loses the band signal. Snap the colour change
     instantly — the ring colour is the high-signal cue, not a fade. */
}

.alt-chip.stays-canada {
  border-color: #2e8b57;
  color: #1f6b42;
}

.alt-chip.via-usa {
  border-color: #b0b0b4;
  color: var(--ink-soft);
}

.alt-chip:hover,
.alt-chip:focus-visible {
  background: #f0f0f2;
  outline: none;
}

.alt-chip.stays-canada:hover,
.alt-chip.stays-canada:focus-visible {
  background: #e7f4ec;
}

.alt-chip.via-usa:hover,
.alt-chip.via-usa:focus-visible {
  background: #f4f4f5;
}

/* ---------- OBD gauge strip (live car data) ---------- */

#obd-strip {
  position: fixed;
  left: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 19; /* under the route panel — app.js lifts it above */
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  max-width: calc(100vw - 24px - var(--map-ctrl-strip));
  overflow-x: auto;
  scrollbar-width: none;
}

#obd-strip::-webkit-scrollbar { display: none; }

.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
  padding: 0 4px;
}

.gauge-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.gauge-value {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1.2;
}

/* Stale feed — the bridge stopped or Bluetooth dropped. Dim rather
   than hide: the driver sees the gauges are paused, not vanished. */
#obd-strip.stale .gauge-value {
  color: var(--ink-soft);
  opacity: 0.55;
}

/* Oil countdown urgency — amber under 1000 km, red at/below 0. */
.gauge.warn .gauge-value { color: #b45309; }
.gauge.overdue .gauge-value { color: var(--red-dark); }

#obd-settings-btn {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#obd-settings-btn:hover,
#obd-settings-btn:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

/* ---------- OBD car settings ---------- */

#obd-settings {
  position: fixed;
  left: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 28;
  width: min(320px, calc(100vw - 24px));
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.obd-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}

.obd-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
}

.obd-field input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  font-size: 15px;
  outline: none;
  background: #fafafa;
}

.obd-field input:focus {
  border-color: var(--red);
}

.obd-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

#obd-save {
  border: none;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 18px;
  cursor: pointer;
}

#obd-save:active { transform: scale(0.96); }

#obd-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#obd-close:hover,
#obd-close:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

/* ---------- quicker-route card (mid-drive offer) ---------- */

.quicker-card {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  background: #eaf3ff;
  border: 1px solid #b9d4f5;
  border-radius: 10px;
  padding: 7px 8px 7px 12px;
}

.quicker-text {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: #1c4f8a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#quicker-accept {
  flex: none;
  border: none;
  border-radius: 999px;
  background: #1e88e5;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  cursor: pointer;
}

#quicker-accept:hover { background: #166bb8; }
#quicker-accept:active { transform: scale(0.96); }

#quicker-dismiss {
  flex: none;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#quicker-dismiss:hover,
#quicker-dismiss:focus-visible {
  background: #d8e6f5;
  color: var(--ink);
  outline: none;
}

/* ---------- save-as-place form (🏷️) ---------- */

.save-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  width: min(300px, 70vw);
}

.save-heading {
  flex: 1 1 100%;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.save-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  background: #fafafa;
}

.save-row input:focus {
  border-color: var(--red);
}

#save-name {
  flex: 1 1 100%;
}

#save-tags {
  flex: 1 1 140px;
}

#save-btn {
  flex: none;
  border: none;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 0 14px;
  cursor: pointer;
}

#save-btn:active {
  transform: scale(0.96);
}

/* ---------- "Add a stop" detour sheet ---------- */

.options-sheet {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.options-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.options-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#options-close {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#options-close:hover,
#options-close:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

.options-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.options-chip {
  border: 1.5px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.options-chip:hover,
.options-chip:focus-visible {
  border-color: var(--blue, #1976d2);
  outline: none;
}

.options-chip.active {
  background: var(--blue, #1976d2);
  border-color: var(--blue, #1976d2);
  color: #fff;
}

.options-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.options-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.options-row:hover,
.options-row:focus-visible {
  background: #f7f7f8;
  outline: none;
}

[data-theme="dark"] .options-row:hover,
[data-theme="dark"] .options-row:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.options-icon {
  flex: none;
  font-size: 15px;
}

.options-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.options-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.options-sub {
  font-size: 11px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.options-cost {
  flex: none;
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue, #1976d2);
  white-space: nowrap;
}

.options-cost.na {
  color: var(--ink-soft);
  font-weight: 600;
}

/* ---------- trip list (Spec §3.2, §5 glanceable sizing) ---------- */

/* Glance rules for a driver (≈ 2 s per look): one hero number per row
   (the arrival clock), names large enough to read at arm's length,
   secondary figures muted, tabular digits so times don't jitter as
   they re-time on every GPS fix, and ≥ 48 px touch targets. */
:root {
  --trip-accent: #1565c0; /* next-stop arrival — 6.1:1 on the light card */
  --trip-divider: rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] {
  --trip-accent: #8ab4f8; /* 8:1 on the dark card */
  --trip-divider: rgba(255, 255, 255, 0.1);
}

.errands-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.errands-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px; /* a full thumb, even with gloves on */
  padding: 6px 0;
  line-height: 1.2;
}

.errands-list li + li {
  border-top: 1px solid var(--trip-divider);
}

.stop-num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--red); /* matches the numbered map markers */
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

.stop-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.errands-list .stop-name {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.errands-list .stop-sub {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.errands-list .stop-arrive {
  flex: none;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The next stop leads: bigger name, the arrival in the accent colour —
   "where am I going and when do I get there" in one glance. */
.errands-list li.next .stop-name {
  font-size: 18px;
  font-weight: 700;
}

.errands-list li.next .stop-sub {
  font-size: 14px;
}

.errands-list li.next .stop-arrive {
  font-size: 22px;
  font-weight: 800;
  color: var(--trip-accent);
}

/* Two-bar drag grip (Spec §3.2) — the reorder handle. A 44 px hit area
   (bigger than it looks) that claims the gesture outright
   (touch-action: none) so the page never scrolls mid-drag. */
.stop-grip {
  flex: none;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  margin: 0 -10px 0 -14px;
  cursor: grab;
  color: var(--ink-soft);
  touch-action: none;
}

.stop-grip i {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}

.stop-grip:hover { color: var(--ink); }
.stop-grip:active { cursor: grabbing; }

/* Rows take vertical pans (page scroll) but leave horizontal motion to
   the swipe-to-remove handler. The lifted row rides above its
   neighbours; the others slide to show the drop slot. */
.errands-list li {
  touch-action: pan-y;
  transition: transform 0.15s ease;
  border-radius: 8px;
}
.errands-list li.dragging,
.errands-list li.swiping {
  transition: none;
  position: relative;
  z-index: 1;
  background: var(--panel, #fff);
  box-shadow: var(--shadow);
}

/* ---------- undo toast (Spec §3.2) ---------- */

.trip-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--toast-lift, 12px));
  z-index: 23;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 24px);
  min-height: 48px;
  padding: 0 8px 0 18px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 600;
}

.trip-toast span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#trip-toast-undo {
  flex: none;
  min-height: 40px;
  border: none;
  background: transparent;
  color: #8ab4f8; /* the toast is always dark */
  font-size: 15px;
  font-weight: 800;
  padding: 0 10px;
  cursor: pointer;
}

/* ---------- AI offer card (Spec §3.6) — docked above the bottom card ---------- */

.ai-offer {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--ai-offer-lift, 12px));
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel, #fff);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px 10px 16px;
}

#ai-offer-text {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
}

#ai-offer-yes,
#ai-offer-no {
  flex: none;
  border: none;
  border-radius: 999px;
  min-height: 48px;
  font-size: 16px;
  font-weight: 800;
  padding: 0 20px;
  cursor: pointer;
}

#ai-offer-yes { background: #1e88e5; color: #fff; }
#ai-offer-no { background: transparent; color: var(--ink-soft); }

/* ---------- map chrome tweaks ---------- */

/* Required attribution for OpenStreetMap data + OpenFreeMap tiles (and
   the Nominatim/Photon geocoding that shares the data). MapLibre's own
   attribution control is disabled in app.js, so this static chip carries
   it instead — see the .map-attribution div inside #map in index.html. */
.map-attribution {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  margin: 0;
  padding: 2px 8px;
  font-size: 10px;
  line-height: 1.5;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  border-radius: 8px;
  pointer-events: none;
}

.map-attribution a {
  pointer-events: auto;
  color: inherit;
}

.maplibregl-ctrl-attrib {
  font-size: 10px;
}

.maplibregl-ctrl-top-right,
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-top-left {
  display: none !important;
}

.maplibregl-ctrl-attrib.maplibregl-compact {
  max-width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  overflow: hidden;
}

.maplibregl-ctrl-attrib-button {
  font-size: 12px;
}

.dest-marker {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  background: var(--red);
  border: 3px solid #fff;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* Numbered errands stop — the number is the visiting order. */
.stop-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--red);
  border: 2.5px solid #fff;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.incident-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ff9500;
  border: 2px solid #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.incident-marker.closure { background: var(--red); }

/* "+min" slowdown pill on the coloured route line — tap for details. */
.slowdown-badge {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 2px solid #fff;
  cursor: pointer;
  white-space: nowrap;
}

.slowdown-badge.moderate { background: #f9a825; }
.slowdown-badge.heavy { background: var(--red); }

/*
 * On-map route-choice badge — one per displayed route, anchored at
 * the geometric midpoint. Replaces the old bottom-card chip row.
 *
 * Light theme (default):
 *   .selected    -> blue band (matches the active route line)
 *   .alt         -> white pill with the line's gray color as accent
 *   .badge-fastest, .badge-eco, .badge-usa, .badge-canada-via
 *                   -> appended modifier modifiers that paint the icon
 *                      chips inside the badge.
 *
 * The badge is *always* visible — alternatives stay tappable across
 * the whole drive. Selected/alt distinction is the primary z-index cue.
 */
.route-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 56px;
  padding: 4px 8px 5px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  border: 2px solid #fff;
  background: #fff;
  color: var(--text, #111);
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.route-badge.alt {
  background: #fff;
  color: #555;
  border-color: #fff;
  /* Subtle ring so the alt badge doesn't disappear against the
     gray alt-route line on a light map. */
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.06),
    0 2px 8px rgba(0, 0, 0, 0.2);
}

.route-badge.selected {
  background: var(--blue, #1976d2);
  color: #fff;
  border-color: #fff;
  /* Lift the selected route so it sits visually on top of the
     alternatives on the line. */
  z-index: 2;
}

.route-badge:hover,
.route-badge:focus-visible {
  transform: translateY(-1px) scale(1.04);
  outline: none;
  box-shadow:
    0 0 0 3px rgba(25, 118, 210, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

.route-badge.alt:hover,
.route-badge.alt:focus-visible {
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, 0.1),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

.route-badge-icons {
  display: flex;
  gap: 2px;
  font-size: 13px;
  line-height: 1;
  margin-bottom: 1px;
}

.route-badge-icon { display: inline-block; }
.route-badge-icon.icon-fastest { color: #f9a825; }
.route-badge-icon.icon-eco     { color: #2e8b57; }
.route-badge-icon.icon-usa     { color: var(--red, #c62828); }
.route-badge-icon.badge-canada-via { color: #c62828; }

.route-badge.selected .route-badge-icon.icon-fastest { color: #ffe082; }
.route-badge.selected .route-badge-icon.icon-eco     { color: #c8e6c9; }

.route-badge-time { font-size: 12px; }
.route-badge-dist {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.85;
}
.route-badge.selected .route-badge-dist { opacity: 0.9; }

/* Dark theme — the badge surface flips to the panel-dark tone and the
   icons lean on the existing accent tokens to stay glanceable. */
[data-theme="dark"] .route-badge.alt {
  background: #1f2330;
  color: #e0e3eb;
  border-color: #1f2330;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.06),
    0 2px 10px rgba(0, 0, 0, 0.55);
}
[data-theme="dark"] .route-badge.selected {
  background: var(--blue, #1976d2);
  color: #fff;
  border-color: #1f2330;
}
[data-theme="dark"] .route-badge-icon.icon-fastest { color: #ffd54f; }
[data-theme="dark"] .route-badge-icon.icon-eco     { color: #81c784; }
[data-theme="dark"] .route-badge-icon.icon-usa     { color: #ef9a9a; }

@media (min-width: 720px) {
  #topbar { left: 20px; right: calc(20px + var(--right-rail-width) + 12px); width: auto; }
  #right-rail { right: 20px; }
  #autocomplete { left: 20px; right: auto; width: min(560px, 60vw); }
  #route-panel { left: 20px; bottom: 20px; }
  #left-pane { left: 20px; }
}

/* ---------- self-update prompt ---------- */

#update-bar {
  position: fixed;
  /* centered in the space left of the bottom-right map controls */
  left: calc(50% - var(--map-ctrl-strip) / 2);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  transform: translateX(-50%);
  z-index: 28;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 8px 8px 16px;
  max-width: calc(100vw - 24px - var(--map-ctrl-strip));
}

#update-text {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#update-btn {
  flex: none;
  height: 34px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}

#update-btn:hover { background: var(--red-dark); }
#update-btn:active { transform: scale(0.96); }

#update-dismiss {
  flex: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#update-dismiss:hover,
#update-dismiss:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

/* ---------- ZONE 2: contextual recenter (auto-follow paused) ----------
   The classic round GPS button on the right rail. Hidden by default;
   surfaces only when the driver pans away (Spec §1, §6). */

#back-to-loc {
  width: var(--right-rail-width);
  height: var(--right-rail-width);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--nav-primary);
  color: var(--nav-primary-text);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
}

#back-to-loc:active { transform: scale(0.94); }

/* ---------- save-form cancel (✕) ---------- */

#save-cancel {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#save-cancel:hover,
#save-cancel:focus-visible {
  background: #f0f0f2;
  color: var(--ink);
  outline: none;
}

/* ---------- tap-to-navigate pin ---------- */

.drop-pin {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  background: var(--ink);
  border: 3px solid #fff;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  animation: pin-drop 0.25s ease-out;
}

@keyframes pin-drop {
  from { transform: rotate(-45deg) translateY(-14px); opacity: 0; }
  to   { transform: rotate(-45deg) translateY(0);    opacity: 1; }
}

/* ---------- recenter: slide/fade entrance (spec §3) ----------
   Slides in from the screen edge rather than a hard display toggle. */

#back-to-loc {
  animation: recenter-in 0.22s ease-out;
}

@keyframes recenter-in {
  from { transform: translateX(12px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ---------- dual-state location cursor (spec §2) ---------- */

/* State A: stationary — solid blue dot + pulsing accuracy halo. */
.location-cursor {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cursor-color);
  border: 3px solid var(--cursor-border);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  animation: location-pulse 2s ease-out infinite;
}

@keyframes location-pulse {
  0%   { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35), 0 0 0 0 color-mix(in srgb, var(--cursor-color) 55%, transparent); }
  70%  { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35), 0 0 0 14px color-mix(in srgb, var(--cursor-color) 0%, transparent); }
  100% { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35), 0 0 0 0 color-mix(in srgb, var(--cursor-color) 0%, transparent); }
}

/* State B: motion — directional navigation arrow rotated to the GPS
   bearing via a CSS custom property set from JS. */
.location-cursor.is-moving {
  width: 42px;
  height: 42px;
  background: transparent;
  border: none;
  box-shadow: none;
  animation: none;
  display: grid;
  place-items: center;
}

.location-cursor.is-moving::before {
  content: "";
  width: 42px;
  height: 42px;
  /* The icon URL is set from JS (js/cursor-icon.js) — beaver for
     walking, moose for cycling, manic GT for city driving, Avro arrow
     for the highway. --cursor-icon carries the url(). */
  background: var(--cursor-icon, url('/icons/cursor-highway.png')) center / contain no-repeat;
  /* PNG transparency lets the drop-shadow isolate the marker from the map. */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  transform: rotate(var(--cursor-heading, 0deg));
}

/* ---------- spec §10.7 dark theme tokens ----------
   The attribute selector (not a `.dark` class) is what the spec mandates;
   the inline FOUC script in <head> sets `html[data-theme]` before paint.
   Two themes are explicitly pinned so a future 'auto' or `system` mode can
   land on either side deterministically. */

html[data-theme="dark"] {
  --nav-bg: #0e1116;
  --nav-card-bg: rgba(22, 30, 46, 0.92);
  --nav-surface: #1f293d;
  --nav-primary: #3b82f6;
  --nav-primary-text: #ffffff;
  --nav-accent: #60a5fa;
  --nav-text-main: #e6edf3;
  --nav-text-sub: #8b949e;
  --nav-border: rgba(255, 255, 255, 0.10);
  --nav-route: #38bdf8;
  --cursor-color: #38bdf8;
  --cursor-border: #0b0f17;
  --panel: #161b22;
  --panel-translucent: rgba(13, 17, 23, 0.90);
  --line: rgba(255, 255, 255, 0.10);
  --ink: #e6edf3;
  --ink-soft: #8b949e;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.50);
  /* Speed-limit badge: dark interior so the red ring stands out
     against the dark map canvas without blasting a white square. */
  --speed-limit-bg: #161b22;
  --speed-limit-fg: #e6edf3;
  /* Spec §10.9 comparator tokens — brighter hues for the dark theme so
     green/yellow pass contrast on the dark panel background. */
  --speed-limit-ok: #34d27a;     /* green — at or under the limit */
  --speed-limit-warn: #f9c74f;   /* amber — edging over (+5..+15) */
  --speed-limit-over: var(--red); /* over — keep the existing brand red */
  /* Per-state interior washes (12% / 18% mixes pre-baked to plain hex
     so embedded browsers don't trip over color-mix()'s caching). */
  --speed-limit-ok-bg:   #1a3829;
  --speed-limit-warn-bg: #2e2719;
  --speed-limit-over-bg: #2e1c19;
}

html[data-theme="light"] {
  /* Explicit pin — matches :root but lets a `system`/sensor resolver
     re-assert without re-parsing the root cascade. */
  --nav-bg: #e2e8f0;
  --nav-card-bg: rgba(255, 255, 255, 0.92);
  --nav-surface: #f1f5f9;
  --nav-text-main: #0f172a;
  --nav-text-sub: #475569;
  --panel: #ffffff;
  --panel-translucent: rgba(255, 255, 255, 0.90);
  --line: #e6e6e8;
  --ink: #1c1c1e;
  --ink-soft: #5a5a5e;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  /* Speed-limit badge: classic white interior + black digits — the
     standard road-sign look. */
  --speed-limit-bg: #ffffff;
  --speed-limit-fg: #1c1c1e;
  /* Spec §10.9 comparator tokens — darker hues for the light theme so
     green/yellow are legible on a white interior. */
  --speed-limit-ok: #1f7a3a;      /* forest green — at or under the limit */
  --speed-limit-warn: #b8860b;    /* dark amber — edging over (+5..+15) */
  --speed-limit-over: var(--red);  /* over — keep the existing brand red */
  /* Per-state interior washes (12% / 18% mixes pre-baked to plain hex). */
  --speed-limit-ok-bg:   #e3efe1;
  --speed-limit-warn-bg: #e9d9b2;
  --speed-limit-over-bg: #f1cfc9;
}

.nav-here-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.nav-here-btn:hover { background: var(--red-dark); }
.nav-here-btn:active { transform: scale(0.96); }

/* ---------- status-coloured pins (detour sheet popups) ---------- */

/* Status-coloured pins: green open, amber closing-soon (pulsing),
   orange opens-later, dark grey closed today, neutral grey unknown. */
.poi-marker {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.poi-marker.open { background: #2e8b57; }
.poi-marker.closing-soon { background: #f9a825; animation: poi-pulse 1.6s ease-in-out infinite; }
.poi-marker.opens-later { background: #e65100; }
.poi-marker.closed-today { background: #3f3f44; opacity: 0.88; }
.poi-marker.unknown { background: #5a5a5e; }

@keyframes poi-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249, 168, 37, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(249, 168, 37, 0); }
}

/* Popup contents: name, status line, address/distance, Navigate. */
.poi-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  font-size: 13px;
}

.poi-info strong { font-size: 14px; }

.poi-status { font-weight: 600; }
.poi-status.open { color: #2e8b57; }
.poi-status.closing-soon { color: #c07f00; }
.poi-status.opens-later { color: #e65100; }
.poi-status.closed-today { color: #5a5a5e; }
.poi-status.unknown { color: var(--ink-soft); }

.poi-extra { color: var(--ink-soft); font-size: 12px; }

.poi-info .nav-here-btn {
  margin-top: 4px;
  align-self: flex-start;
}
