/* ---------- Design tokens ---------- */

:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-alt: #EBEEF1;
  --border: #DFE3E8;
  --text: #12181F;
  --text-muted: #5B6570;
  --accent: #1E88C7;
  --accent-strong: #146FA3;
  --accent-contrast: #FFFFFF;
  --accent-tint: #E4F1FA;
  --danger: #D64550;
  --success: #1E9E6B;
  --warn: #B9790F;
  --shadow: 0 -4px 24px rgba(15, 23, 32, 0.10);
  --shadow-card: 0 1px 3px rgba(15, 23, 32, 0.08);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1418;
    --surface: #161D22;
    --surface-alt: #1D262C;
    --border: #2A343B;
    --text: #E7EDF1;
    --text-muted: #93A1AB;
    --accent: #4FB3E8;
    --accent-strong: #7BC8EE;
    --accent-contrast: #08131A;
    --accent-tint: #17303D;
    --danger: #F17782;
    --success: #4FD8A0;
    --warn: #F0B429;
    --shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0E1418;
  --surface: #161D22;
  --surface-alt: #1D262C;
  --border: #2A343B;
  --text: #E7EDF1;
  --text-muted: #93A1AB;
  --accent: #4FB3E8;
  --accent-strong: #7BC8EE;
  --accent-contrast: #08131A;
  --accent-tint: #17303D;
  --danger: #F17782;
  --success: #4FD8A0;
  --warn: #F0B429;
  --shadow: 0 -4px 24px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---------- Reset & base ---------- */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 150ms ease, color 150ms ease;
}

a { color: inherit; text-decoration: none; }

ul { list-style: none; margin: 0; padding: 0; }

svg { display: block; width: 20px; height: 20px; }

button { font: inherit; color: inherit; }

/* ---------- Layout shell ---------- */

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) max(16px, var(--safe-right)) 10px max(16px, var(--safe-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand__mark { width: 26px; height: 26px; flex: none; }

/* A domain-name brand ("BUS.justinex.net") is longer than a short word --
   shrink/truncate it first on a narrow phone rather than letting it push
   the language/viewtime/theme controls (which must all stay reachable)
   off the edge of the screen. */
.brand__name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .brand { font-size: 13px; gap: 6px; }
  .brand__mark { width: 24px; height: 24px; }
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.switcher {
  display: flex;
  align-items: center;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.switcher__opt {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: calc(var(--radius-sm) - 3px);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.switcher__opt.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-card);
}

.theme-switcher .switcher__opt svg { width: 16px; height: 16px; }

/* ---------- Viewing-time picker: browse a schedule instead of live data ---------- */

.viewtime {
  position: relative;
  display: flex;
  align-items: center;
}

.viewtime__button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: pointer;
}

.viewtime__button svg { width: 16px; height: 16px; }

.viewtime__button.is-active {
  background: var(--accent-tint);
  color: var(--accent);
}

.viewtime__badge {
  margin-left: 6px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.viewtime__panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: 260px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* The [hidden] attribute's default display:none is a UA-stylesheet rule,
   which this class's own `display: flex` above silently outranks (author
   CSS always wins over UA CSS, regardless of specificity) -- without this,
   setting .hidden = true in JS never actually hides the panel. */
.viewtime__panel[hidden] {
  display: none;
}

.viewtime__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.viewtime__title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.viewtime__close {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: -4px -4px -4px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.viewtime__close svg { width: 14px; height: 14px; }
.viewtime__close:hover, .viewtime__close:focus-visible { background: var(--surface-alt); color: var(--text); }

.viewtime__live {
  padding: 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.viewtime__quick {
  display: flex;
  gap: 6px;
}

.viewtime__quick button {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.viewtime__quick button:hover, .viewtime__quick button:focus-visible {
  background: var(--accent-tint);
  color: var(--accent);
}

.viewtime__fields {
  display: flex;
  gap: 8px;
}

.viewtime__field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.viewtime__field input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  color-scheme: light dark;
}

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Generic padded page wrapper, for anything that isn't full-bleed like the map. */
.page {
  padding: 24px max(16px, var(--safe-right)) calc(32px + var(--safe-bottom)) max(16px, var(--safe-left));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Home page: full-bleed map + overlay bottom sheet ---------- */

.map-page {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* ID selector: must outrank maplibre-gl.css's own ".maplibregl-map {
   position: relative }" rule, which loads after app.css and would otherwise
   win on equal class specificity and collapse this to height 0. */
#map {
  position: absolute;
  inset: 0;
  background: var(--surface-alt);
}

.maplibregl-ctrl-bottom-right { margin-bottom: calc(var(--safe-bottom) + 12px) !important; }

.vehicle-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.vehicle-marker svg { width: 16px; height: 16px; }

/* Two-class selectors: must outrank maplibre-gl.css's own single-class
   ".maplibregl-popup-content { background: #fff }" etc., which loads after
   app.css and would otherwise win these properties on tied specificity
   (the same issue as the #map rule above). */
.maplibregl-popup .maplibregl-popup-content {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-card);
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
}

/* The tip's visible border side depends on which of 8 anchor classes
   MapLibre assigns at runtime (each a same-specificity 2-class selector
   in maplibre-gl.css); !important sidesteps matching all 8 rather than
   fighting each one on specificity. */
.maplibregl-popup-tip {
  border-top-color: var(--surface) !important;
  border-bottom-color: var(--surface) !important;
  border-left-color: var(--surface) !important;
  border-right-color: var(--surface) !important;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  height: 132px;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  border-top: 1px solid var(--border);
  overflow: hidden;
  transition: height 280ms cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet__handle {
  flex: none;
  display: block;
  width: 100%;
  padding: 10px 0 12px;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.sheet__handle:active { cursor: grabbing; }

.sheet__handle-bar {
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto;
}

.sheet__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px calc(16px + var(--safe-bottom));
}

.sheet__banner {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

.sheet__banner--degraded {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.sheet__banner--viewtime {
  background: var(--accent-tint);
  color: var(--accent);
}

/* Same reason as .tracking-badge[hidden] etc. above: this class's own
   `background`/`color` don't conflict with [hidden]'s `display:none`, but
   the shared .sheet__banner rule below sets no `display` of its own either
   -- kept here anyway since every other toggled element in this app gets
   this guard, and a future edit to .sheet__banner adding `display` would
   otherwise silently reopen the bug. */
.sheet__banner--viewtime[hidden] { display: none; }

.sheet__search input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.sheet__search input::placeholder { color: var(--text-muted); }

.sheet__section-title {
  margin: 18px 2px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.sheet__results {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet__empty {
  margin: 4px 2px;
  font-size: 14px;
  color: var(--text-muted);
}

.stop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.stop-row:hover, .stop-row:focus-visible { background: var(--surface-alt); }

.stop-row__icon {
  flex: none;
  display: flex;
  color: var(--accent);
}

.stop-row__icon svg { width: 18px; height: 18px; }

.stop-row__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-row__meta {
  flex: none;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Stop detail: back nav + live arrivals ---------- */

.stop-detail__back {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 2px 0 6px -6px;
  padding: 8px 8px 8px 6px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.stop-detail__back svg { width: 18px; height: 18px; }

.stop-detail__title {
  margin: 4px 2px 14px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.stop-detail__arrivals {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.arrival-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 2px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.arrival-row:last-child { border-bottom: 0; }
.arrival-row:hover, .arrival-row:focus-visible { background: var(--surface-alt); }

.arrival-row__badge {
  flex: none;
  min-width: 40px;
  padding: 4px 7px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

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

.arrival-row__headsign {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

/* Operator + platform -- always shown, greyed out (never omitted) when
   upstream doesn't have that particular piece of data for this bus. */
.arrival-row__meta {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-muted);
}

.arrival-row__meta-sep { flex: none; }

.arrival-row__meta-item--empty {
  font-style: italic;
  opacity: 0.75;
}

.arrival-row__time {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.arrival-row__countdown {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
}

.arrival-row__countdown--live { color: var(--success); }

.arrival-row__delay {
  font-size: 11px;
  font-weight: 600;
}

.arrival-row__delay--late { color: var(--warn); }
.arrival-row__delay--early { color: var(--success); }

.arrival-row__alert-icon {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--warn);
}

/* ---------- Search result groups + route rows ---------- */

.sheet__group-title {
  margin: 16px 2px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.sheet__group-title:first-child { margin-top: 2px; }

.route-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.route-row:hover, .route-row:focus-visible { background: var(--surface-alt); }

.route-row__badge {
  flex: none;
  min-width: 40px;
  padding: 4px 7px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.route-row__headsign {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Route detail: line + ordered stop list ---------- */

/* Back button, badge/title, and tracking status stay pinned to the top of
   the scrolling sheet, since the stop list below auto-scrolls to the bus's
   current position -- without this, scrolling down would carry the only way
   back (and the tracking indicator) out of view. */
.route-detail__sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.route-detail__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.route-detail__share {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 2px -4px 6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.route-detail__share svg { width: 20px; height: 20px; }
.route-detail__share:hover, .route-detail__share:focus-visible { background: var(--surface-alt); }
.route-detail__share--done { color: var(--success); }

/* Same reason as .tracking-badge[hidden] above: this class's own `display`
   would otherwise outrank the [hidden] attribute's default. */
.route-detail__share[hidden] {
  display: none;
}

.route-detail__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 2px 10px;
}

.route-detail__badge {
  flex: none;
  min-width: 44px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.route-detail__title {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

/* How this specific bus is being tracked: real GPS position, a schedule-
   derived time estimate with no position, or nothing live at all. */
.tracking-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px 14px;
  padding: 4px 9px 4px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

/* This class's own `display` would otherwise outrank the [hidden]
   attribute's UA-stylesheet display:none (author CSS always wins). */
.tracking-badge[hidden] {
  display: none;
}

.tracking-badge__dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.tracking-badge--gps { color: var(--success); }
.tracking-badge--eta { color: var(--warn); }
.tracking-badge--none { color: var(--text-muted); }

/* Service alerts affecting the trip/route currently open -- deduped and
   aggregated server-side, one banner per distinct alert. */
.route-detail__alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 2px 14px;
  /* Real alerts can run long (some are several sentences, in whichever
     language upstream actually published), and this sits in the sticky
     header -- cap it and scroll internally instead of letting it grow
     until it covers the whole sheet (and the map above it). */
  max-height: 180px;
  overflow-y: auto;
}

.route-detail__alerts:empty {
  display: none;
}

.alert-banner {
  position: relative;
  padding: 10px 30px 10px 12px;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
}

.alert-banner__close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.alert-banner__close:hover, .alert-banner__close:focus-visible {
  background: color-mix(in srgb, currentColor 15%, transparent);
  color: var(--text);
}

.alert-banner--severe {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.alert-banner--info, .alert-banner--unknown {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.alert-banner__header {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
}

.alert-banner__description {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.alert-banner__link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

/* Vehicle/trip metadata for whichever bus is being tracked. Every field is
   always shown -- upstream leaves most of them null in practice (model,
   low_floor, photo), so those render as a muted "no data" placeholder
   rather than disappearing, per the point of this panel: what we know
   about this specific vehicle, and just as importantly what we don't. */
/* A 2-column grid of compact label/value cells -- this lives in the sticky
   header (so it can't be scrolled out of view the moment the stop list
   auto-scrolls), so it stays dense rather than a tall single-column list. */
.vehicle-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin: 0 2px 14px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  flex: none;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}

.tabbar__tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.tabbar__tab svg { width: 22px; height: 22px; }

.tabbar__tab.is-active { color: var(--accent); }

/* ---------- Favorite (star) toggle buttons ---------- */

.stop-detail__topbar, .route-detail__topbar-actions {
  display: flex;
  align-items: center;
}

.stop-detail__topbar { justify-content: space-between; }
.route-detail__topbar-actions { gap: 2px; }

.stop-detail__favorite, .route-detail__favorite {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 2px -4px 6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.stop-detail__favorite svg, .route-detail__favorite svg { width: 20px; height: 20px; }
.stop-detail__favorite:hover, .stop-detail__favorite:focus-visible,
.route-detail__favorite:hover, .route-detail__favorite:focus-visible { background: var(--surface-alt); }

.stop-detail__favorite--active, .route-detail__favorite--active { color: var(--warn); }

/* Same reason as .tracking-badge[hidden] etc. above: this class's own
   `display` would otherwise outrank the [hidden] attribute's default. */
.route-detail__favorite[hidden] { display: none; }

/* ---------- Journey planner (Plan tab) ---------- */

.plan__fields {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.plan__field-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.plan__field {
  position: relative;
  display: flex;
  align-items: center;
}

.plan__field-dot {
  position: absolute;
  left: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
}

.plan__field-dot--from { background: var(--accent); }
.plan__field-dot--to { background: var(--danger); }

.plan__field input {
  width: 100%;
  padding: 11px 40px 11px 30px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.plan__field input::placeholder { color: var(--text-muted); }

.plan__locate {
  position: absolute;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.plan__locate svg { width: 17px; height: 17px; }
.plan__locate:hover, .plan__locate:focus-visible { background: var(--border); color: var(--accent); }

.plan__swap {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--accent);
  cursor: pointer;
}

.plan__swap svg { width: 18px; height: 18px; }
.plan__swap:hover, .plan__swap:focus-visible { background: var(--border); }

/* Same reason as .tracking-badge[hidden] etc. above: this class's own
   `display` would otherwise outrank the [hidden] attribute's default. */
.plan__suggestions[hidden] { display: none; }

.plan__suggestions {
  display: flex;
  flex-direction: column;
  margin: -4px 0 10px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  overflow: hidden;
}

.plan__suggestion {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.plan__suggestion:last-child { border-bottom: 0; }
.plan__suggestion:hover, .plan__suggestion:focus-visible { background: var(--border); }

.plan__suggestion-label { font-size: 14px; }

.plan__suggestion-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.plan__filters { margin: 2px 0 10px; }

.plan__filters-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.plan__filters-toggle svg { width: 16px; height: 16px; color: var(--text-muted); }
.plan__filters-toggle[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.plan__filters-toggle[aria-expanded="true"] svg { color: var(--accent); }

/* Same reason as .tracking-badge[hidden] etc. above: this class's own
   `display` would otherwise outrank the [hidden] attribute's default. */
.plan__filters-count[hidden] { display: none; }

.plan__filters-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 11px;
  font-weight: 700;
}

/* Same reason as .tracking-badge[hidden] etc. above: this class's own
   `display` would otherwise outrank the [hidden] attribute's default. */
.plan__filters-panel[hidden] { display: none; }

.plan__filters-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.plan__filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.plan__filter-row-label {
  font-size: 13px;
  color: var(--text-muted);
}

.plan__filter-group {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.plan__filter-btn {
  border: 0;
  border-radius: calc(var(--radius-sm) - 3px);
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.plan__filter-btn.is-active {
  background: var(--accent-tint);
  color: var(--accent);
}

.plan__filter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.plan__filter-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.plan__search-btn {
  width: 100%;
  padding: 12px;
  margin-bottom: 14px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.plan__search-btn:hover, .plan__search-btn:focus-visible { background: var(--accent-strong); }

.plan__later-btn {
  width: 100%;
  margin-top: 4px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.plan__later-btn:hover, .plan__later-btn:focus-visible { background: var(--surface-alt); }
.plan__later-btn:disabled { color: var(--text-muted); cursor: default; }

.plan__results { display: flex; flex-direction: column; gap: 8px; }

.plan-itin {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.plan-itin:hover, .plan-itin:focus-visible { background: var(--surface-alt); }

.plan-itin__times {
  flex: none;
  font-size: 13px;
  font-weight: 700;
}

.plan-itin__duration {
  flex: none;
  font-size: 12px;
  color: var(--text-muted);
}

.plan-itin__chips {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.plan-itin__arrow {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

.plan-leg__icon, .plan-leg__badge {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.plan-leg__icon {
  width: 22px;
  height: 22px;
  color: var(--text-muted);
}

.plan-leg__icon svg { width: 16px; height: 16px; }

.plan-leg__badge {
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
}

.plan-detail__subtitle {
  margin: -8px 2px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.plan-detail__legs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.plan-leg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  cursor: default;
}

.plan-leg[data-trip-id]:not([data-trip-id=""]) { cursor: pointer; }
.plan-leg[data-trip-id]:not([data-trip-id=""]):hover { background: var(--border); }

.plan-leg__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

.plan-leg__route {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-leg__time {
  flex: none;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.plan-detail__stops {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.plan-detail__stop {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.plan-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.plan-row:hover, .plan-row:focus-visible { background: var(--surface-alt); }

.plan-row__icon {
  flex: none;
  display: flex;
  color: var(--accent);
}

.plan-row__icon svg { width: 18px; height: 18px; }

.plan-row__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vehicle-meta[hidden] { display: none; }

.vehicle-meta__title {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

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

.vehicle-meta__row--wide { grid-column: 1 / -1; }

.vehicle-meta__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.vehicle-meta__value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

.vehicle-meta__value--empty {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

.vehicle-meta__photo {
  grid-column: 1 / -1;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.route-detail__stops {
  display: flex;
  flex-direction: column;
}

.route-stop-row {
  /* Kept in sync with the sticky header's actual current height (it grows
     with alerts/vehicle info) via JS, so no scroll -- ours, the browser's,
     or Playwright's own pre-click "scroll into view" -- can ever land a row
     underneath it, visible but unclickable. */
  scroll-margin-top: var(--route-sticky-height, 0px);
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.route-stop-row:hover, .route-stop-row:focus-visible { background: var(--surface-alt); }

.route-stop-row__seq {
  flex: none;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.route-stop-row__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Already-covered part of a tracked route: dimmed so the remaining stops
   read clearly against it. */
.route-stop-row--passed { opacity: 0.45; }

/* The stop the bus is currently heading to. */
.route-stop-row--next .route-stop-row__seq {
  background: var(--success);
  color: #fff;
}

.route-stop-row--next .route-stop-row__name { font-weight: 700; }

.route-stop-row__eta {
  flex: none;
  margin-left: auto;
  padding-left: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.route-stop-row__time {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.route-stop-row--next .route-stop-row__time { color: var(--text); }

.route-stop-row__delay {
  font-size: 11px;
  font-weight: 600;
}

.route-stop-row__delay--late { color: var(--warn); }
.route-stop-row__delay--early { color: var(--success); }
