:root {
  color-scheme: dark;
  --bg: #07101d;
  --surface: #0d1828;
  --surface-2: #122137;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f7fb;
  --muted: #9fb0c6;
  --accent: #62a8ff;
  /* Risk colors stay identical across themes: risk.js carries its own copy
     of these same hex values for the map's station-dot paint layer, and
     the filter/legend dots use these tokens too, so the dots on the map
     always match the dots in the sidebar regardless of theme. */
  --normal: #35c789;
  --attention: #f5c84c;
  --difficult: #ff8a4c;
  --extreme: #ff4d6d;
  --stale: #7d8999;
  /* ...but a bright saturated color that reads fine as *text* on a dark
     background fails contrast badly on a light one, so status-pill text
     uses these instead. Dark theme just aliases the base color; light
     theme below overrides with darker variants. */
  --normal-fg: var(--normal);
  --attention-fg: var(--attention);
  --difficult-fg: var(--difficult);
  --extreme-fg: var(--extreme);
  --stale-fg: var(--stale);
  /* Subtle "this panel sits slightly above its surroundings" tint. A white
     tint at low alpha only shows up against a dark surface — light theme
     overrides it with a dark tint instead. */
  --surface-raised: rgba(255, 255, 255, 0.035);
  /* "Inset" cards (count tiles, station/incident lists) — a black tint
     reads as recessed against both a dark and a light surface, so unlike
     --surface-raised this one doesn't need a per-theme override. */
  --surface-recessed: rgba(0, 0, 0, 0.1);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  /* Spacing scale — not yet applied throughout; foundation for the upcoming
     hierarchy/density pass. */
  --space-1: 4px;
  --space-2: 7px;
  --space-3: 10px;
  --space-4: 14px;
  --space-5: 20px;
  --space-6: 28px;

  /* Typography scale — mirrors the font sizes already in use. */
  --font-size-xs: 0.65rem;
  --font-size-sm: 0.72rem;
  --font-size-base: 0.84rem;
  --font-size-md: 0.95rem;
  --font-size-lg: 1.2rem;
  --font-size-xl: 1.7rem;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --border: rgba(15, 23, 42, 0.12);
    --text: #101826;
    --muted: #55647a;
    --accent: #2563eb;
    --normal-fg: #15803d;
    --attention-fg: #8a6407;
    --difficult-fg: #b1470f;
    --extreme-fg: #c11f3f;
    --stale-fg: #56637a;
    --surface-raised: rgba(15, 23, 42, 0.04);
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  }
}

/* Manual toggle (theme-toggle.js) always wins over the system preference
   above, since an attribute selector on :root is more specific than a
   plain :root selector regardless of source order. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07101d;
  --surface: #0d1828;
  --surface-2: #122137;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f7fb;
  --muted: #9fb0c6;
  --accent: #62a8ff;
  --normal-fg: var(--normal);
  --attention-fg: var(--attention);
  --difficult-fg: var(--difficult);
  --extreme-fg: var(--extreme);
  --stale-fg: var(--stale);
  --surface-raised: rgba(255, 255, 255, 0.035);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: rgba(15, 23, 42, 0.12);
  --text: #101826;
  --muted: #55647a;
  --accent: #2563eb;
  --normal-fg: #15803d;
  --attention-fg: #8a6407;
  --difficult-fg: #b1470f;
  --extreme-fg: #c11f3f;
  --stale-fg: #56637a;
  --surface-raised: rgba(15, 23, 42, 0.04);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 3px;
}

a {
  color: var(--accent);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 104px;
  padding: 20px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--accent) 7%, var(--surface)),
    var(--surface)
  );
  position: relative;
  z-index: 50;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.7rem, 2.5vw, 2.4rem);
  margin-bottom: 5px;
  letter-spacing: -0.03em;
}

h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.subtitle,
.muted {
  color: var(--muted);
}

.subtitle {
  margin: 0;
  font-size: 0.95rem;
}

.small {
  font-size: 0.78rem;
}

.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;
}

.mobile-only,
.sidebar-header,
.sidebar-backdrop {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--surface-raised);
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 16%, transparent);
}

.status-live {
  color: var(--normal-fg);
}

.status-loading {
  color: var(--attention-fg);
}

.status-loading::before {
  animation: pulse 1.2s ease-in-out infinite;
}

.is-loading {
  animation: pulse 1.2s ease-in-out infinite;
}

.status-error {
  color: var(--extreme-fg);
}

.button,
.icon-button,
.text-button,
.map-action-button {
  border: 0;
  color: var(--text);
  transition:
    filter 150ms ease,
    opacity 150ms ease,
    background-color 150ms ease;
}

.button {
  min-height: 40px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-weight: 700;
  text-decoration: none;
}

.button-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.button:hover,
.icon-button:hover,
.text-button:hover,
.map-action-button:hover {
  filter: brightness(1.12);
}

.full-width {
  width: 100%;
}

.text-button {
  background: transparent;
  color: var(--accent);
  padding: 4px 0;
  font-size: 0.8rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 1.5rem;
}

.theme-toggle-button {
  font-size: 1.1rem;
  border: 1px solid var(--border);
}

.main-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
}

.sidebar,
.details-panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 14px;
}

.details-panel {
  border-left: 1px solid var(--border);
  padding: 18px;
}

.panel {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.controls-panel {
  position: relative;
}

.search-label {
  display: block;
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 7px;
}

.search-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 9px 11px;
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}

.search-results {
  margin-top: 8px;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.search-result {
  width: 100%;
  min-height: 48px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: background-color 150ms ease;
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover,
.search-result:focus-visible {
  background: var(--surface-2);
}

.search-result-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-result-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-meta {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.search-empty {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.filter-header,
.panel-heading-row,
.dialog-header,
.detail-header,
.metric-row,
.camera-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.filter-header {
  margin-top: 16px;
}

.filter-header h2,
.panel-heading-row h2 {
  margin-bottom: 0;
}

.risk-filters {
  margin-top: 10px;
  display: grid;
  gap: 7px;
}

.risk-filter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 9px;
  border-radius: 10px;
  background: var(--surface-raised);
}

.risk-filter label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  cursor: pointer;
}

.risk-filter input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.filter-count {
  color: var(--muted);
  font-size: 0.75rem;
}

.control-row {
  margin-top: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.summary-card {
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-raised);
}

.summary-card strong {
  display: block;
  font-size: 1.45rem;
  margin-bottom: 3px;
}

.summary-card span {
  font-size: 0.74rem;
  color: var(--muted);
}

.explainer-panel details {
  font-size: 0.82rem;
  line-height: 1.5;
}

.explainer-panel summary {
  cursor: pointer;
  font-weight: 750;
}

.explainer-panel p {
  margin: 10px 0;
  color: var(--muted);
}

.map-section {
  position: relative;
  min-width: 0;
  min-height: 540px;
  background: #dce5eb;
}

.map {
  position: absolute;
  inset: 0;
}

.map-action-button {
  min-height: 44px;
  padding: 8px 13px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: #172334;
  background: rgba(231, 237, 241, 0.88);
  backdrop-filter: blur(4px);
  font-weight: 800;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid rgba(23, 35, 52, 0.2);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.map-message {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: max-content;
  max-width: min(620px, calc(100% - 36px));
  padding: 12px 15px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--extreme) 45%, transparent);
  background: color-mix(in srgb, var(--extreme) 12%, var(--surface));
  box-shadow: var(--shadow);
  line-height: 1.45;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.hidden {
  display: none !important;
}

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  max-width: calc(100% - 24px);
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  font-size: 0.72rem;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot,
.risk-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  display: inline-block;
}

.risk-normal {
  background: var(--normal);
}

.risk-attention {
  background: var(--attention);
}

.risk-difficult {
  background: var(--difficult);
}

.risk-extreme {
  background: var(--extreme);
}

.risk-stale {
  background: var(--stale);
}

/* Text-color counterparts of the above — use the theme-aware -fg tokens,
   never the base risk colors directly (see :root's comment on why). */
.risk-text-normal {
  color: var(--normal-fg);
}

.risk-text-attention {
  color: var(--attention-fg);
}

.risk-text-difficult {
  color: var(--difficult-fg);
}

.risk-text-extreme {
  color: var(--extreme-fg);
}

.risk-text-stale {
  color: var(--stale-fg);
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  animation: fade-in-up 220ms ease;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--text);
  font-size: 1.2rem;
}

.empty-icon {
  font-size: 3.2rem;
  color: var(--accent);
  margin-bottom: 12px;
}

.detail-header {
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  animation: fade-in-up 220ms ease;
}

.detail-header h2 {
  margin-bottom: 5px;
  font-size: 1.22rem;
}

.detail-close-button {
  display: none;
}

/* Risk level is the thing a user opens this panel to find out — it gets a
   full-width, color-tinted banner instead of a small pill, with the top
   contributing reason shown right there as a teaser. --level-color is set
   per risk-banner-* modifier and consumed generically below. */
.risk-banner {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--level-color) 45%, var(--border));
  background: color-mix(in srgb, var(--level-color) 13%, transparent);
  animation: fade-in-up 260ms ease;
}

.risk-banner-normal {
  --level-color: var(--normal);
}

.risk-banner-attention {
  --level-color: var(--attention);
}

.risk-banner-difficult {
  --level-color: var(--difficult);
}

.risk-banner-extreme {
  --level-color: var(--extreme);
}

.risk-banner-stale {
  --level-color: var(--stale);
}

.risk-banner-level {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.risk-banner-level .risk-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
}

.risk-banner-level strong {
  font-size: var(--font-size-md);
}

.risk-banner-score {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.risk-banner-reason {
  margin: var(--space-2) 0 0;
  font-size: var(--font-size-base);
  line-height: 1.4;
}

.detail-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.detail-section:last-child {
  border-bottom: 0;
}

.detail-section-secondary h3 {
  color: var(--muted);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metrics {
  display: grid;
  gap: 8px;
}

.metric-row {
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--surface-raised);
  font-size: 0.84rem;
}

.metric-row span:first-child {
  color: var(--muted);
}

.metrics-secondary .metric-row {
  padding: 6px 10px;
  background: transparent;
  font-size: var(--font-size-sm);
}

.reason-list {
  padding-left: 20px;
  margin: 0;
  display: grid;
  gap: 7px;
  font-size: 0.84rem;
  line-height: 1.4;
}

.camera-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.camera-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--surface-2);
}

.camera-card-body {
  padding: 10px;
}

.camera-card-body p {
  margin-bottom: 0;
}

.methodology-dialog {
  width: min(620px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.methodology-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.methodology-content {
  line-height: 1.55;
}

.methodology-content h3 {
  margin-top: 18px;
}

.footer {
  min-height: 46px;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
}

.footer p {
  margin: 0;
}

.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--surface) !important;
}

.maplibregl-ctrl-group {
  background: var(--surface) !important;
}

.maplibregl-ctrl-group button span {
  filter: invert(1);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

/* Plays automatically whenever a matching element is freshly inserted —
   every renderX() function in this app replaces content via innerHTML,
   which creates new nodes each time, so this replays on every update
   without needing any JS to trigger it. */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1120px) {
  .main-layout {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .details-panel {
    position: fixed;
    z-index: 30;
    right: 12px;
    bottom: 12px;
    width: min(390px, calc(100vw - 24px));
    max-height: min(72vh, 680px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
  }

  .details-panel:not(.has-content) {
    display: none;
  }

  .detail-close-button {
    display: inline-grid;
  }
}

@media (max-width: 760px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .topbar {
    min-height: auto;
    align-items: flex-start;
    padding: 13px 14px;
    gap: 10px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .subtitle {
    display: none;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .status-pill {
    min-height: 34px;
    font-size: 0.7rem;
    padding: 6px 9px;
  }

  .topbar-actions .button {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .main-layout {
    display: block;
  }

  .mobile-only {
    display: inline-flex;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .sidebar-backdrop.visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    left: 0;
    width: min(340px, calc(100vw - 30px));
    height: 100dvh;
    max-height: none;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
    border: 0;
    border-right: 1px solid var(--border);
    border-radius: 0 18px 18px 0;
    box-shadow: var(--shadow);
    transform: translateX(calc(-100% - 20px));
    transition: transform 180ms ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 0 12px;
  }

  .sidebar-header h2 {
    margin-bottom: 0;
    font-size: 1.15rem;
  }

  .map-section {
    height: calc(100dvh - 106px);
    min-height: 500px;
  }

  .map-action-button {
    position: absolute;
    z-index: 10;
    top: 12px;
    left: 12px;
  }

  .map-message {
    top: 66px;
    max-width: calc(100% - 20px);
  }

  .details-panel {
    z-index: 30;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(64dvh, 620px);
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    border-radius: 18px 18px 14px 14px;
  }

  .detail-header {
    gap: 8px;
  }

  .footer {
    display: none;
  }

  .map-legend {
    right: 8px;
    left: 8px;
    bottom: 8px;
    max-width: none;
    gap: 6px 10px;
    font-size: 0.64rem;
  }

  .button,
  .icon-button,
  .map-action-button {
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .eyebrow {
    font-size: 0.66rem;
  }

  .status-pill {
    max-width: 132px;
  }

  .map-legend span:nth-child(5) {
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   route-feature.js — route search and route summary panel
   ========================================================================== */

.route-panel {
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.16), transparent 43%),
    var(--surface-raised);
}

.route-heading-row,
.route-summary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  animation: fade-in-up 220ms ease;
}

.route-heading-row h2 {
  margin-bottom: 0;
}

.route-beta {
  padding: 3px 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.route-field {
  position: relative;
  margin-top: 13px;
}

.route-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.route-input-row .button {
  min-width: 58px;
  padding-inline: 10px;
}

.route-selected {
  border-color: rgba(53, 199, 137, 0.72) !important;
  box-shadow: 0 0 0 3px rgba(53, 199, 137, 0.1) !important;
}

.route-swap {
  display: block;
  margin: 10px auto -3px;
}

.route-actions {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.route-primary {
  /* Fixed accent background regardless of theme, so it needs a fixed
     light label too — var(--text) flips polarity between themes and
     would go dark-on-blue in light mode otherwise. */
  background: #2563eb;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.route-status {
  margin: 10px 0 0;
  line-height: 1.45;
}

.route-status.route-error {
  color: var(--extreme-fg);
}

.route-status.route-success {
  color: var(--normal-fg);
}

.route-place-results {
  margin-top: 8px;
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.route-place-result,
.route-station-button,
.route-highlight-button {
  width: 100%;
  min-height: 48px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: background-color 150ms ease;
}

.route-place-result:last-child,
.route-station-button:last-child,
.route-highlight-button:last-child {
  border-bottom: 0;
}

.route-place-result:hover,
.route-place-result:focus-visible,
.route-station-button:hover,
.route-station-button:focus-visible,
.route-highlight-button:hover,
.route-highlight-button:focus-visible {
  background: var(--surface-2);
}

.route-place-result strong,
.route-place-result span {
  display: block;
}

.route-place-result span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.route-no-results {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.route-summary {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.route-summary-header h3 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

.route-summary-meta {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.route-summary-section {
  margin-top: 14px;
  animation: fade-in-up 220ms ease;
}

.route-summary-section h3 {
  margin-bottom: 8px;
}

.route-highlight-list,
.route-station-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-recessed);
}

.route-highlight-button {
  display: block;
  min-height: 0;
}

.route-highlight-button strong,
.route-highlight-button span {
  display: block;
}

.route-highlight-button span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.route-station-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.route-station-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-station-meta {
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.route-disclaimer {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.route-map-legend {
  width: 18px;
  height: 4px;
  display: inline-block;
  border-radius: 999px;
  background: #2563eb;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.82);
}

@media (min-width: 1181px) {
  .main-layout {
    grid-template-columns: 310px minmax(0, 1fr) 340px;
  }
}

@media (max-width: 420px) {
  .route-input-row {
    grid-template-columns: minmax(0, 1fr) 54px;
  }

  .route-input-row .button {
    min-width: 54px;
    padding-inline: 7px;
  }
}

/* ==========================================================================
   traffic-feature.js — traffic incidents (roadworks & announcements)
   ========================================================================== */

.traffic-data-status {
  margin: 10px 0 0;
  padding: 9px 10px;
  border: 1px solid rgba(245, 200, 76, 0.32);
  border-radius: 10px;
  color: var(--attention-fg);
  background: rgba(245, 200, 76, 0.08);
  line-height: 1.45;
}

.traffic-summary-section {
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.traffic-summary-heading,
.traffic-summary-counts,
.traffic-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.traffic-summary-heading h3 {
  margin-bottom: 0;
}

.traffic-summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
  font-size: 0.7rem;
  font-weight: 800;
  white-space: nowrap;
}

.traffic-summary-counts {
  margin: 9px 0;
  align-items: stretch;
}

.traffic-count-card {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-recessed);
  text-align: center;
}

.traffic-count-card strong,
.traffic-count-card span {
  display: block;
}

.traffic-count-card strong {
  font-size: 1rem;
}

.traffic-count-card span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.65rem;
}

.traffic-incident-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-recessed);
}

.traffic-incident-button {
  width: 100%;
  min-height: 0;
  padding: 10px;
  display: block;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: background-color 150ms ease;
}

.traffic-incident-button:last-child {
  border-bottom: 0;
}

.traffic-incident-button:hover,
.traffic-incident-button:focus-visible {
  background: var(--surface-2);
}

.traffic-item-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.79rem;
}

.traffic-kind {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
}

.traffic-kind-roadwork {
  color: var(--difficult-fg);
  background: rgba(255, 138, 76, 0.16);
}

.traffic-kind-traffic {
  color: var(--extreme-fg);
  background: rgba(255, 77, 109, 0.16);
}

.traffic-item-description,
.traffic-item-meta,
.traffic-summary-note {
  display: block;
  color: var(--muted);
  line-height: 1.4;
}

.traffic-item-description {
  margin-top: 5px;
  font-size: 0.7rem;
}

.traffic-item-meta {
  margin-top: 4px;
  font-size: 0.65rem;
}

.traffic-summary-note {
  margin: 9px 0 0;
  font-size: 0.68rem;
}

.traffic-map-roadwork,
.traffic-map-announcement {
  width: 17px;
  height: 5px;
  display: inline-block;
  border-radius: 999px;
}

.traffic-map-roadwork {
  background: #ff8a4c;
}

.traffic-map-announcement {
  background: #ff4d6d;
}

.traffic-popup {
  min-width: min(280px, 70vw);
  max-width: 340px;
}

.traffic-popup h3 {
  margin-bottom: 5px;
  font-size: 0.95rem;
}

.traffic-popup p {
  margin: 5px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
}

.traffic-popup-meta {
  color: var(--muted);
}

.traffic-popup-severity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
}

@media (max-width: 420px) {
  .traffic-summary-counts {
    gap: 6px;
  }

  .traffic-count-card {
    padding-inline: 5px;
  }
}

/* ==========================================================================
   forecast-feature.js — route weather forecast & departure comparison
   ========================================================================== */

.forecast-data-status {
  margin: 10px 0 0;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  border-radius: 10px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  line-height: 1.45;
}

.forecast-summary-section {
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.forecast-summary-heading,
.forecast-control-row,
.forecast-counts,
.forecast-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.forecast-summary-heading {
  align-items: flex-start;
}

.forecast-summary-heading h3 {
  margin-bottom: 3px;
}

.forecast-summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-raised);
  font-size: 0.7rem;
  font-weight: 800;
  white-space: nowrap;
}

.forecast-control-row {
  margin-top: 10px;
  align-items: flex-end;
}

.forecast-control-row label {
  flex: 1 1 auto;
  font-size: 0.76rem;
  font-weight: 750;
}

.forecast-select {
  width: 100%;
  min-height: 42px;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--bg);
  font: inherit;
}

.forecast-comparison {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.forecast-option {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface-recessed);
  text-align: left;
  transition:
    background-color 150ms ease,
    border-color 150ms ease;
}

.forecast-option:hover,
.forecast-option:focus-visible,
.forecast-option.is-selected {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.forecast-option strong,
.forecast-option span {
  display: block;
}

.forecast-option strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
}

.forecast-option span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.65rem;
}

.forecast-recommendation {
  margin: 10px 0 0;
  padding: 9px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  font-size: 0.72rem;
  line-height: 1.45;
}

.forecast-counts {
  margin: 10px 0;
  align-items: stretch;
}

.forecast-count-card {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-recessed);
  text-align: center;
}

.forecast-count-card strong,
.forecast-count-card span {
  display: block;
}

.forecast-count-card strong {
  font-size: 0.95rem;
}

.forecast-count-card span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.6rem;
}

.forecast-highlight-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-recessed);
}

.forecast-highlight-button {
  width: 100%;
  min-height: 0;
  padding: 10px;
  display: block;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: background-color 150ms ease;
}

.forecast-highlight-button:last-child {
  border-bottom: 0;
}

.forecast-highlight-button:hover,
.forecast-highlight-button:focus-visible {
  background: var(--surface-2);
}

.forecast-item-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

.forecast-item-level {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 800;
}

.forecast-item-description,
.forecast-item-meta,
.forecast-summary-note {
  display: block;
  color: var(--muted);
  line-height: 1.4;
}

.forecast-item-description {
  margin-top: 5px;
  font-size: 0.7rem;
}

.forecast-item-meta {
  margin-top: 4px;
  font-size: 0.65rem;
}

.forecast-summary-note {
  margin: 9px 0 0;
  font-size: 0.68rem;
}

.forecast-map-legend {
  width: 18px;
  height: 5px;
  display: inline-block;
  border-radius: 999px;
  background: linear-gradient(90deg, #35c789, #ff8a4c, #ff4d6d);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.82);
}

.forecast-popup {
  min-width: min(270px, 70vw);
  max-width: 340px;
}

.forecast-popup h3 {
  margin-bottom: 5px;
  font-size: 0.95rem;
}

.forecast-popup p {
  margin: 5px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
}

.forecast-popup-meta {
  color: var(--muted);
}

@media (max-width: 420px) {
  .forecast-comparison {
    grid-template-columns: 1fr;
  }

  .forecast-counts {
    gap: 5px;
  }
}

/* ==========================================================================
   beta-feature.js — beta badge, share controls, route overview summary
   ========================================================================== */

.beta-badge {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  padding: 4px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.shared-route-prompt {
  margin: 0 0 13px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.shared-route-prompt strong,
.shared-route-prompt span {
  display: block;
}

.shared-route-prompt span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
}

.shared-route-prompt .button {
  width: 100%;
  margin-top: 9px;
}

.beta-overview {
  margin-top: 13px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: 12px;
  background:
    radial-gradient(
      circle at top right,
      color-mix(in srgb, var(--accent) 12%, transparent),
      transparent 52%
    ),
    rgba(0, 0, 0, 0.11);
  animation: fade-in-up 220ms ease;
}

.beta-overview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.beta-overview-heading h3 {
  margin: 0;
  font-size: 0.86rem;
}

.beta-route-meta,
.beta-updated {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.beta-status-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.beta-status-card {
  min-width: 0;
  padding: 9px 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-raised);
}

.beta-status-card span,
.beta-status-card strong {
  display: block;
}

.beta-status-card span {
  color: var(--muted);
  font-size: 0.62rem;
}

.beta-status-card strong {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.76rem;
  line-height: 1.3;
}

.beta-details-toggle {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
}

#route-summary.beta-details-collapsed > .route-summary-section,
#route-summary.beta-details-collapsed > .route-disclaimer {
  display: none;
}

.beta-footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  font-size: 0.72rem;
}

.beta-footer-links a {
  color: var(--accent);
}

.beta-network-note {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(245, 200, 76, 0.4);
  border-radius: 10px;
  color: #ffe39a;
  background: rgba(11, 18, 32, 0.96);
  box-shadow: var(--shadow);
  font-size: 0.72rem;
  line-height: 1.4;
}

@media (max-width: 540px) {
  .beta-status-grid {
    grid-template-columns: 1fr;
  }

  .beta-status-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .beta-status-card strong {
    margin-top: 0;
    text-align: right;
  }
}
