/* =====================================================================
   Bay Area Traffic — Graph Intelligence
   style.css  (the ONLY file this module owns)

   Clean, modern, minimalist data-tool styling.
   - Inter type system, accent #2b6cb0, light theme, generous whitespace
   - Fixed left sidebar (~300px) of module-card panels
   - Full-bleed #map filling the rest of the viewport
   - #insightPanel + #legend as small translucent fixed cards (bottom corners)
   - #storyPanel as a clean readable card
   - Congestion gradient legend (green -> amber -> red)
   - SVG node / edge / label legibility helpers
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---------------------------------------------------------------------
   Design tokens
   --------------------------------------------------------------------- */
:root {
  /* Palette */
  --ink:        #1f2933;   /* primary text */
  --ink-2:      #374151;   /* secondary text */
  --ink-3:      #6b7682;   /* tertiary / captions */
  --muted:      #647280;
  --accent:     #2b6cb0;   /* brand accent */
  --accent-ink: #245a94;   /* darker accent (hover / active) */
  --accent-soft:#ebf3fb;   /* tinted wash */

  /* Surfaces */
  --bg:         #f4f6f9;   /* app background behind the map */
  --panel:      #ffffff;
  --surface-1:  #fafbfc;
  --surface-hover: #f0f6ff;
  --line:       #e6e9ee;
  --line-soft:  #eef1f5;

  /* Congestion ramp (matches the JS color scale) */
  --c-free:  #2ca25f;   /* free-flow green   (c -> 1) */
  --c-amber: #f5a623;   /* slowing amber     (c ~ 0.5) */
  --c-jam:   #d7301f;   /* jammed red        (c -> 0) */

  /* Radii — 8px family */
  --r-sm:  6px;
  --r-md:  8px;
  --r-lg:  12px;
  --r-pill: 999px;

  /* Shadows */
  --sh-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --sh-2: 0 4px 14px rgba(16, 24, 40, 0.08);
  --sh-3: 0 12px 32px rgba(16, 24, 40, 0.14);

  /* Type scale */
  --fs-xs:   11px;
  --fs-sm:   12px;
  --fs-base: 13px;
  --fs-md:   14px;
  --fs-lg:   16px;
  --fs-xl:   19px;
  --fs-2xl:  24px;

  /* Spacing rhythm */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 28px;

  --sidebar-w: 300px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ---------------------------------------------------------------------
   Reset / base
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
               Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;                 /* the map owns the viewport */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
  letter-spacing: 0.005em;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--ink); }
p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); }

::selection { background: var(--accent-soft); }

/* Calm, consistent scrollbars in the sidebar */
.sidebar::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-thumb {
  background: #d7dde5;
  border-radius: var(--r-pill);
  border: 2px solid var(--panel);
}
.sidebar::-webkit-scrollbar-thumb:hover { background: #c2cad4; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

/* =====================================================================
   LAYOUT  —  fixed left sidebar + full-bleed map
   ===================================================================== */

.sidebar,
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--sh-1);
  overflow-y: auto;
  overflow-x: hidden;
}

/* The map fills everything to the right of the sidebar. */
#map {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  left: var(--sidebar-w);
  background:
    radial-gradient(1200px 800px at 70% 18%, #ffffff 0%, #eef2f7 55%, #e7ecf3 100%);
  overflow: hidden;
}

/* Leaflet sets its own panes/overlay svg sizing; do NOT force the overlay svg
   to 100% (that breaks the geographic projection). Only ensure the map fills. */
#map { z-index: 1; }
#map .leaflet-overlay-pane svg { overflow: visible; }
/* Keep the basemap muted so the colored road graph dominates. */
#map .leaflet-tile-pane { opacity: 0.92; }

/* =====================================================================
   SIDEBAR  —  brand + module cards
   ===================================================================== */

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line-soft);
}
.brand .brand-title,
.sidebar h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
  line-height: 1.2;
}
.brand .brand-title .accent { color: var(--accent); }
.brand .brand-sub,
.sidebar .subtitle {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  font-weight: 400;
}

/* Live clock chip (rush-hour status surfaces here) */
#clock,
.clock {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  align-self: flex-start;
  margin-top: 2px;
  padding: 5px 11px;
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: var(--r-pill);
  letter-spacing: 0.01em;
}
#clock .rush,
.clock .rush {
  font-weight: 500;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Module-card panels — the building block of the sidebar */
.module-card,
.panel,
.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--space-4);
  box-shadow: var(--sh-1);
}

.module-card + .module-card { margin-top: 0; } /* gap handled by flex */

/* Card title row */
.module-card h2,
.module-card h3,
.panel-title,
.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}
.module-card h2::before,
.panel-title::before,
.card-title::before {
  content: '';
  width: 3px;
  height: 13px;
  border-radius: var(--r-pill);
  background: var(--accent);
  flex: 0 0 auto;
}

.module-card .hint,
.field-hint {
  margin-top: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--ink-3);
  line-height: 1.45;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* =====================================================================
   FORM CONTROLS  —  lens select, inputs, buttons
   ===================================================================== */

/* Lens selector */
#lensSel,
select.lens,
select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 9px 34px 9px 12px;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--ink);
  background-color: var(--panel);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%23647280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
#lensSel:hover,
select:hover { border-color: #cdd5df; }
#lensSel:focus,
select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.16);
}

/* Text input (copilot ask box) */
#askInput,
input[type="text"],
input[type="search"],
textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
#askInput::placeholder,
input::placeholder,
textarea::placeholder { color: #a4adb8; }

/* Buttons — shared */
button,
.btn,
#storyBtn,
#askBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
              box-shadow 0.15s var(--ease), transform 0.05s var(--ease);
}
button:hover,
.btn:hover,
#storyBtn:hover,
#askBtn:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  box-shadow: var(--sh-2);
}
button:active,
.btn:active,
#storyBtn:active,
#askBtn:active { transform: translateY(1px); box-shadow: var(--sh-1); }
button:focus-visible,
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.30);
}

/* Secondary / ghost button variant */
.btn-ghost,
button.secondary,
.btn.secondary {
  color: var(--accent);
  background: var(--panel);
  border-color: var(--line);
}
.btn-ghost:hover,
button.secondary:hover,
.btn.secondary:hover {
  color: var(--accent-ink);
  background: var(--surface-hover);
  border-color: #cdd5df;
}

/* Copilot ask row: input + button side by side */
.ask-row,
.copilot-row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}
.ask-row #askInput { flex: 1 1 auto; }
.ask-row #askBtn   { flex: 0 0 auto; }

/* Copilot answer area */
#askAnswer {
  margin-top: var(--space-3);
  padding: var(--space-3);
  font-size: var(--fs-sm);
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  min-height: 0;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
#askAnswer:empty {
  display: none;
}
#askAnswer strong { color: var(--ink); font-weight: 600; }
#askAnswer ol,
#askAnswer ul { margin: 6px 0 0; padding-left: 18px; }
#askAnswer li { margin: 2px 0; }

/* =====================================================================
   STORY PANEL  —  clean readable narrated card
   ===================================================================== */

#storyPanel {
  position: fixed;
  left: calc(var(--sidebar-w) + 28px);
  top: 28px;
  z-index: 40;
  width: 360px;
  max-width: calc(100vw - var(--sidebar-w) - 56px);
  padding: var(--space-5);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  animation: rise 0.28s var(--ease);
}
#storyPanel[hidden],
#storyPanel.hidden { display: none; }

#storyPanel .story-eyebrow,
#storyPanel .eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--space-3);
}
#storyPanel .story-eyebrow::before,
#storyPanel .eyebrow::before {
  content: '';
  width: 16px; height: 2px;
  background: var(--accent);
  border-radius: var(--r-pill);
}

#storyPanel h2,
#storyPanel .story-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}

#storyPanel .story-body,
#storyPanel p {
  font-size: var(--fs-md);
  line-height: 1.62;
  color: var(--ink-2);
}
#storyPanel .story-body strong,
#storyPanel p strong { color: var(--ink); font-weight: 600; }

/* Story footer: progress dots + Next */
#storyPanel .story-foot,
#storyPanel .story-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
}
#storyPanel .story-progress,
#storyPanel .dots {
  display: flex;
  gap: 6px;
  align-items: center;
}
#storyPanel .dot {
  width: 7px; height: 7px;
  border-radius: var(--r-pill);
  background: #d7dde5;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}
#storyPanel .dot.active {
  background: var(--accent);
  transform: scale(1.25);
}
#storyPanel .story-count {
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* Close affordance for the story card */
#storyPanel .story-close,
#storyClose {
  position: absolute;
  top: 12px; right: 12px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
  color: var(--ink-3);
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
}
#storyPanel .story-close:hover,
#storyClose:hover { color: var(--ink); background: var(--surface-1); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   INSIGHT PANEL  —  translucent fixed card, bottom-right
   ===================================================================== */

#insightPanel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 35;
  width: 280px;
  max-width: calc(100vw - var(--sidebar-w) - 60px);
  padding: var(--space-4);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(214, 221, 229, 0.7);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
#insightPanel[hidden],
#insightPanel.hidden,
#insightPanel:empty { display: none; }

#insightPanel .insight-name,
#insightPanel h3,
#insightPanel .name {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin-bottom: 2px;
}

/* Type / region meta chips */
#insightPanel .meta,
#insightPanel .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: var(--space-2) 0 var(--space-3);
}
#insightPanel .chip,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: var(--r-pill);
}
#insightPanel .chip .swatch,
.chip .swatch {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

/* Stat rows: betweenness rank, worst incident road, modeled speed */
#insightPanel .stat,
#insightPanel .row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 7px 0;
  font-size: var(--fs-sm);
  border-top: 1px solid var(--line-soft);
}
#insightPanel .stat:first-of-type,
#insightPanel .row:first-of-type { border-top: none; }
#insightPanel .stat .k,
#insightPanel .row .k {
  color: var(--muted);
  font-weight: 500;
  flex: 0 0 auto;
}
#insightPanel .stat .v,
#insightPanel .row .v {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Critical-intersection rank highlight */
#insightPanel .rank,
.rank-badge {
  color: var(--accent-ink);
  font-weight: 700;
}

/* Edge hover readout: road + modeled mph */
#insightPanel .speed,
.speed-readout { font-variant-numeric: tabular-nums; font-weight: 700; }

/* =====================================================================
   LEGEND  —  translucent fixed card, bottom-left of the map
   ===================================================================== */

#legend {
  position: fixed;
  left: calc(var(--sidebar-w) + 22px);
  bottom: 22px;
  z-index: 35;
  width: 248px;
  padding: var(--space-4);
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(214, 221, 229, 0.7);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
}
#legend[hidden],
#legend.hidden { display: none; }

#legend h4,
#legend .legend-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: var(--space-3);
}

#legend .legend-section + .legend-section {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
}
#legend .legend-sub {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}

/* Congestion gradient bar: green -> amber -> red */
#legend .gradient,
.congestion-gradient {
  height: 11px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg,
              var(--c-jam) 0%,
              var(--c-amber) 50%,
              var(--c-free) 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
}
#legend .gradient-labels,
.congestion-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-weight: 500;
}

/* Region swatches list */
#legend .swatches,
.region-swatches {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#legend .swatch-row,
.region-swatches .row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
#legend .swatch-row .dot,
#legend .swatch {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.10);
}

/* Honest data note */
#legend .note,
.data-note {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--ink-3);
  font-style: italic;
}

/* =====================================================================
   SVG  —  node / edge / label legibility helpers
   (the engine sets geometry + per-element fill/stroke; these are the
    presentation defaults that make it read cleanly)
   ===================================================================== */

#map svg text,
.node-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
  pointer-events: none;
  /* halo so labels stay legible over colored edges */
  paint-order: stroke fill;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.node-label.minor { font-size: 10px; font-weight: 500; fill: var(--ink-2); }

/* Edges — width comes from lanes, color from congestion (set in JS). */
.edge,
line.edge,
.link {
  stroke-linecap: round;
  fill: none;
  transition: stroke 0.6s linear, opacity 0.15s var(--ease);
  cursor: pointer;
}
.edge:hover,
.link:hover { opacity: 0.85; }
.edge.highlight,
.link.highlight {
  filter: drop-shadow(0 0 4px rgba(43, 108, 176, 0.55));
}

/* Nodes — now a <g> glyph: main disc (fill=community), articulation ring,
   inner type mark, and a live pulse halo. Geometry + per-channel paint in JS. */
.node { cursor: pointer; }
.node .glyph-disc {
  transition: stroke-width 0.12s var(--ease), filter 0.12s var(--ease);
}
.node:hover .glyph-disc {
  filter: drop-shadow(0 1px 4px rgba(16, 24, 40, 0.28));
}
.node .glyph-mark { pointer-events: none; }
.node .glyph-pulse, .node .glyph-artic-outer { pointer-events: none; }
.node.selected .glyph-disc,
.node.critical .glyph-disc {
  stroke: var(--accent);
  stroke-width: 2.5px;
}

/* Dim everything else when a node/edge is focused (JS toggles .dim) */
.dim { opacity: 0.18; }

/* SVG tooltip-ish floating chip the engine may inject for edge hover */
.svg-tip,
.map-tooltip {
  position: fixed;
  z-index: 60;
  padding: 6px 10px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #fff;
  background: rgba(31, 41, 51, 0.94);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-2);
  pointer-events: none;
  white-space: nowrap;
}
.svg-tip .mph,
.map-tooltip .mph { color: #9ad9b4; font-variant-numeric: tabular-nums; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

@media (max-width: 920px) {
  :root { --sidebar-w: 264px; }
  #storyPanel { width: 320px; }
  #insightPanel { width: 248px; }
  #legend { width: 224px; }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .sidebar, #sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  #map {
    position: static;
    left: 0;
    width: 100%;
    height: 62vh;
  }
  #storyPanel {
    left: 50%;
    top: auto;
    bottom: 16px;
    transform: translateX(-50%);
    width: calc(100vw - 32px);
    max-width: 420px;
  }
  #storyPanel.hidden { display: none; }
  #insightPanel { right: 14px; bottom: 14px; max-width: calc(100vw - 28px); }
  #legend { left: 14px; bottom: 14px; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* =====================================================================
   TIME-OF-DAY SCRUBBER  (#timeControl)
   ===================================================================== */
#timeControl label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.time-readout {
  font-size: var(--fs-sm);
  color: var(--ink-2);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.time-readout b { color: var(--ink); font-weight: 600; }
#timeSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg,
    #1f3a5f 0%, #FF851B 33%, #2ECC40 50%, #FFDC00 71%, #1f3a5f 100%);
  outline: none;
  cursor: pointer;
}
#timeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--accent);
  box-shadow: var(--sh-1);
  cursor: pointer;
}
#timeSlider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--accent);
  cursor: pointer;
}
.time-btns {
  display: flex;
  gap: var(--space-2);
  margin-top: 10px;
}
.time-btns .btn { flex: 1 1 auto; padding: 7px 10px; }
.time-btns .btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ti-clock-sim {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--accent);
  border-radius: var(--r-pill);
  vertical-align: middle;
}

/* =====================================================================
   INSIGHT / REROUTE CARD INNER MARKUP  (ti-* classes the engine injects)
   ===================================================================== */
.ti-card { font-size: var(--fs-sm); }
.ti-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin-bottom: var(--space-2);
  color: var(--ink);
}
.ti-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 6px 0;
  border-top: 1px solid var(--line-soft);
}
.ti-row:first-of-type { border-top: none; }
.ti-row > span { color: var(--muted); font-weight: 500; flex: 0 0 auto; }
.ti-row > b {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ti-hint {
  margin-top: 8px;
  font-size: var(--fs-xs);
  line-height: 1.45;
  color: var(--ink-3);
}
.ti-hint b { color: var(--ink-2); font-weight: 600; }

/* Small inline buttons inside cards / story (Prev / Next / Done / Clear) */
.ti-btn {
  padding: 6px 12px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
}
.ti-btn:hover { background: var(--surface-hover); border-color: #cdd5df; }
.ti-btn.ti-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.ti-btn.ti-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

/* =====================================================================
   STORY CARD INNER MARKUP  (ti-story-* classes the engine injects)
   ===================================================================== */
.ti-story-empty { font-size: var(--fs-sm); color: var(--ink-3); }
.ti-story-step {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--space-2);
}
.ti-story-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
  color: var(--ink);
}
.ti-story-body { font-size: var(--fs-md); line-height: 1.6; color: var(--ink-2); }
.ti-story-body b { color: var(--ink); font-weight: 600; }
.ti-story-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
}

/* Copilot answer inner markup */
.ti-ans { font-size: var(--fs-sm); line-height: 1.55; color: var(--ink-2); }
.ti-ans b, .ti-ans strong { color: var(--ink); font-weight: 600; }
.ti-ol, .ti-ul { margin: 6px 0 0; padding-left: 18px; }
.ti-ol li, .ti-ul li { margin: 2px 0; }

/* =====================================================================
   LEGEND INNER MARKUP  (ti-leg-* classes the engine injects)
   ===================================================================== */
.ti-leg-block + .ti-leg-block {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
}
.ti-leg-h {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}
.ti-leg-grad {
  height: 11px;
  border-radius: var(--r-pill);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.ti-leg-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.ti-leg-widths { display: flex; gap: var(--space-4); align-items: flex-end; }
.ti-leg-w {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.ti-leg-w i {
  display: block;
  width: 34px;
  background: #475569;
  border-radius: var(--r-pill);
}
.ti-leg-regs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ti-leg-reg {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.ti-leg-reg i {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.10);
}
.ti-leg-note {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-soft);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--ink-3);
  font-style: italic;
}

/* =====================================================================
   DETOUR / CLOSURE OVERLAY on the Leaflet svg
   ===================================================================== */
.detour {
  filter: drop-shadow(0 0 5px rgba(43, 108, 176, 0.6));
}
.leaflet-container .edge { transition: stroke 0.6s linear, opacity 0.15s var(--ease); }

/* =====================================================================
   "WHAT CHANGED" community toast (under the stats bar)
   ===================================================================== */
.what-changed {
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.4;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid rgba(43, 108, 176, 0.18);
  border-radius: var(--r-md);
  padding: 6px 10px;
  opacity: 0;
  transition: opacity 0.4s var(--ease);
}
.what-changed:empty { display: none; }

/* =====================================================================
   LEGEND GLYPH SWATCHES (ti-leg-glyphs — node size / ring / type marks)
   ===================================================================== */
.ti-leg-glyphs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}
.ti-leg-g {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}
.ti-leg-g svg { display: block; overflow: visible; }
