:root {
  color-scheme: light dark; /* native scrollbars and form controls follow the theme */
  --bg: #ffffff;
  --fg: #1b1f24;
  --muted: #5b6470;
  --border: #d8dde3;
  --panel: #ffffff;
  --accent: #1f6feb;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --fg: #e8ebef;
    --muted: #9aa4b1;
    --border: #2c323a;
    --panel: #1c2027;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* Slim, rounded scrollbars that follow the theme, everywhere in the app */
:root { --scroll-thumb: rgba(110, 118, 129, 0.45); --scroll-thumb-hover: rgba(110, 118, 129, 0.7); }
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
::-webkit-scrollbar-corner, ::-webkit-scrollbar-button { display: none; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
}

/* Top-right panel: title and live status, filters, search, stops switch and the trip planner button.
   The vehicle/stop cards stack below it (see .side). */
.topbar {
  position: absolute; top: 12px; right: 12px; z-index: 1100;
  width: min(360px, calc(100vw - 24px));
  display: flex; flex-direction: column;
  padding: 0;
}
.tb-head { min-width: 0; }
.tri { display: inline-block; font: 12px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; transition: transform 0.15s; }
.tb-body { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 0; border-top: 1px solid var(--border); }
.tb-plan { padding: 12px 14px 14px; }
.topbar.collapsed .tb-plan { border-top: 1px solid var(--border); }
.topbar.collapsed .rc-toggle { transform: rotate(-90deg); }
/* Collapsed: just the title, live status and the Plan My Trip button */
.topbar.collapsed .tb-body { display: none; }
@media (prefers-reduced-motion: reduce) { .tri { transition: none; } }
.tb-logo { color: var(--accent); flex: 0 0 auto; }
.topbar h1 { margin: 0; white-space: nowrap; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.controls select {
  grid-column: span 2; width: 100%; min-width: 0;
  font: inherit; font-size: 13px; padding: 7px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg); cursor: pointer;
}
.controls select:hover { border-color: var(--accent); }
/* City and vehicle type share a row when the type filter is shown */
.controls:has(#modeFilter:not([hidden])) #citySelect,
.controls #modeFilter { grid-column: span 1; }
.tb-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; width: 34px; height: 20px; border-radius: 999px; flex: 0 0 auto;
  background: var(--border); transition: background 0.15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .switch .track, .switch .track::after { transition: none; } }
.status {
  /* padding leaves room for the live dot's glow, which overflow:hidden would otherwise clip */
  min-width: 0; overflow: hidden; padding: 3px 0 3px 3px; margin: -3px 0 -3px -3px; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 6px;
}
.status.live::before { content: ''; flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: #2da44e; box-shadow: 0 0 0 3px rgba(45, 164, 78, 0.2); }
.status.error { color: #d1242f; }

#map { flex: 1; min-height: 0; }
@media (prefers-color-scheme: dark) {
  .leaflet-container { background: #1d2126; }
}
/* Darken raster tiles in dark mode */
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) saturate(0.6); }

/* Vehicles are drawn on a canvas (see VehicleMarker in app.js), so they need no CSS. */

/* Side panel: the route card (when a vehicle is open) stacked above the main panel */
.side {
  position: absolute; top: calc(var(--topbar-h, 260px) + 22px); right: 12px; /* below the top-right panel */
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100% - var(--topbar-h, 260px) - 34px);
  display: flex; flex-direction: column; gap: 10px;
  z-index: 1000;
  pointer-events: none; /* the gap between cards lets clicks through to the map */
}
.panel, .card {
  pointer-events: auto;
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.panel {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  overflow: auto;
  padding: 0;
}
/* Vehicle/stop card: the title bar (same design as the route card) stays put while the body scrolls */
.panel > .rc-head { position: sticky; top: 0; z-index: 2; background: var(--panel); border-radius: 10px 10px 0 0; }
.card-body { padding: 12px 14px 14px; border-top: 1px solid var(--border); }
.panel.collapsed .card-body { display: none; }
.panel.collapsed .rc-toggle { transform: rotate(-90deg); }
.stop-badge {
  flex: 0 0 auto; width: 30px; height: 26px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(31, 111, 235, 0.14); color: var(--accent);
}
@media (max-width: 600px) {
  /* Phones: the panel spans the top, compacted */
  .topbar { top: 8px; left: 8px; right: 8px; width: auto; }
  /* Phones: the cards span the screen width at the bottom, like the top panel */
  .side { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; max-height: 55%; gap: 8px; }
  .card-body { padding: 10px 12px 12px; }
  .stoplist { max-height: 110px; }
}
.close {
  position: absolute; top: 6px; right: 8px;
  border: 0; background: none; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.panel h2 { margin: 0 56px 4px 0; font-size: 17px; display: flex; gap: 8px; align-items: center; }
.panel .sub { color: var(--muted); margin: 0 0 10px; }
.chip {
  display: inline-block; min-width: 26px; padding: 2px 7px;
  border-radius: 999px; font-weight: 700; font-size: 12px; text-align: center;
  background: var(--c); color: var(--t);
  border: 0; cursor: pointer; font-family: inherit;
  flex-shrink: 0; white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
/* A vehicle's stops: a timeline in a scrolling box. Travelled part in the route colour (--c). */
.stops-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 14px 0 6px; }
.stops-head .sp-label { margin: 0; }
.stops-count { font-size: 12px; color: var(--muted); }
.stoplist {
  --c: var(--accent);
  list-style: none; margin: 0; padding: 6px 4px; max-height: 300px; overflow: auto; position: relative;
  border: 1px solid var(--border); border-radius: 10px; background: rgba(127, 127, 127, 0.04);
}
.stoplist li {
  position: relative; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 5px 8px 5px 30px; border-radius: 7px; line-height: 1.3; font-size: 13px;
}
/* rail */
.stoplist li::before {
  content: ''; position: absolute; left: 14px; top: 0; bottom: 0; width: 2px; background: var(--border);
}
.stoplist li:first-child::before { top: 50%; }
.stoplist li:last-child::before { bottom: 50%; }
/* dot */
.stoplist li::after {
  content: ''; position: absolute; left: 10px; top: calc(5px + 0.65em - 5px); width: 10px; height: 10px; border-radius: 50%;
  box-sizing: border-box; background: var(--panel); border: 2px solid var(--c);
}
.stoplist li.past { color: var(--muted); }
.stoplist li.past::before { background: var(--c); opacity: 0.6; }
.stoplist li.past::after { background: var(--c); border-color: var(--c); opacity: 0.6; width: 8px; height: 8px; left: 11px; top: calc(5px + 0.65em - 4px); }
.stoplist li.current { font-weight: 650; background: rgba(127, 127, 127, 0.12); }
.stoplist li.current::before { background: linear-gradient(var(--c) 50%, var(--border) 50%); }
.stoplist li.current:first-child::before { background: var(--border); }
.stoplist li.current::after {
  width: 14px; height: 14px; left: 8px; top: calc(5px + 0.65em - 7px); background: var(--c); border-color: var(--panel);
  box-shadow: 0 0 0 2px var(--c), 0 0 0 6px color-mix(in srgb, var(--c) 25%, transparent);
}
.attribution-note { color: var(--muted); font-size: 11px; margin-top: 10px; }

/* Popups follow the light/dark theme */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--fg); box-shadow: var(--shadow);
}
.leaflet-popup-content-wrapper { border-radius: 12px; border: 1px solid var(--border); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.35; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); top: 6px; right: 6px; font-size: 20px; }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--fg); }
.leaflet-popup-content .sub { color: var(--muted); margin: 0 0 6px; font-size: 12px; }

/* Stop popup */
.stop-pop { min-width: 230px; max-width: 280px; }
.sp-head { padding-right: 18px; margin-bottom: 10px; }
.sp-name { font-size: 15px; font-weight: 700; line-height: 1.25; }
.sp-code {
  display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
  color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px;
}
.sp-section { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.sp-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px; }
.sp-hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.sp-muted { color: var(--muted); font-size: 12px; list-style: none; }
.sp-next { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sp-next li[data-route], .sp-next li[data-vehicle] { display: flex; align-items: center; gap: 8px; cursor: pointer; border-radius: 6px; padding: 2px 4px; margin: 0 -4px; }
.sp-next li[data-route]:hover, .sp-next li[data-vehicle]:hover { background: rgba(127, 127, 127, 0.12); }
.sp-next .chip { flex-shrink: 0; }
.sp-dest { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.sp-when { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; line-height: 1.15; }
.sp-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.sp-time.ontime { color: #1a7f37; } .sp-time.early { color: #1f6feb; } .sp-time.late { color: #d1242f; }
.sp-time.muted { color: var(--fg); }
.sp-status { font-size: 10px; color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .sp-time.ontime { color: #3fb950; } .sp-time.early { color: #58a6ff; } .sp-time.late { color: #f85149; }
}
.stop-pop .chips { gap: 6px; }
.stop-pop .chips .chip { padding: 3px 9px; font-size: 12px; }
.sp-all {
  display: block; width: 100%; margin-top: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; text-align: center;
  background: var(--accent); color: #fff; border: 0;
}
.sp-all:hover { filter: brightness(1.08); }

.empty-state {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; box-shadow: var(--shadow); z-index: 1000; max-width: min(360px, calc(100vw - 32px));
  text-align: center;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Timetable in the info panel */
.stoplist .sname { min-width: 0; }
.stoplist .stime { flex-shrink: 0; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.stoplist li.current .stime, .stoplist li:not(.past) .stime { color: var(--fg); }
.stoplist li.past .stime { color: var(--muted); }
.stoplist .due.was { text-decoration: line-through; opacity: 0.6; }
.stoplist .est { font-weight: 600; }
.delay { display: inline-block; font-size: 12px; font-weight: 650; padding: 1px 8px; border-radius: 999px; margin-right: 4px; }
.delay.ontime { background: rgba(26, 127, 55, 0.15); color: #1a7f37; }
.delay.early { background: rgba(31, 111, 235, 0.15); color: #1f6feb; }
.delay.late { background: rgba(209, 36, 47, 0.13); color: #d1242f; }
.est.ontime { color: #1a7f37; }
.est.early { color: #1f6feb; }
.est.late { color: #d1242f; }
@media (prefers-color-scheme: dark) {
  .delay.ontime, .est.ontime { color: #3fb950; }
  .delay.early, .est.early { color: #58a6ff; }
  .delay.late, .est.late { color: #f85149; }
}

/* Stop departures */
.stop-tabs { margin: 4px 0 10px; }
.chip.all-chip { --c: var(--border); --t: var(--fg); background: var(--c); color: var(--t); }
.chip[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.stop-tabs .chip:not([aria-pressed="true"]) { opacity: 0.75; }
.next-dep { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.next-dep .sub { margin: 0; display: flex; align-items: center; gap: 6px; }
.next-time { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.next-time .due.was { font-size: 14px; font-weight: 400; }
.deplist { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.deplist li.dep { display: flex; gap: 10px; padding: 6px 2px; border-top: 1px solid var(--border); }
.deplist li.dep.clickable { cursor: pointer; }
.deplist li.dep.clickable:hover { background: rgba(127, 127, 127, 0.1); }
.deplist li.past { opacity: 0.55; }
.dep-time { flex: 0 0 66px; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; font-weight: 600; }
.dep-time .due.was { font-weight: 400; font-size: 12px; }
.dep-main { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.dep-head { overflow-wrap: anywhere; }
.dep-status { font-size: 12px; color: var(--muted); }
.delay.muted { background: rgba(127, 127, 127, 0.15); color: var(--muted); }
.btn.small { font-size: 12px; padding: 4px 10px; margin-top: 10px; }
.due.was { text-decoration: line-through; opacity: 0.6; }

/* Buttons and link-style buttons (stop popup, departures panel) */
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; }
.btn {
  font: inherit; padding: 6px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
}

/* Stops in a vehicle's timetable open that stop's departures */
.stoplist li.stop-link { cursor: pointer; }
.stoplist li.stop-link:hover { background: rgba(127, 127, 127, 0.16); }
.stoplist li.stop-link:hover .sname { text-decoration: underline; }
.back-link { display: block; margin: 0 0 8px; font-size: 13px; }

/* Placeholder rows while the popup's times load (keeps its size steady) */
.sp-skel { height: 26px; border-radius: 6px; list-style: none;
  background: linear-gradient(90deg, rgba(127,127,127,.10), rgba(127,127,127,.22), rgba(127,127,127,.10));
  background-size: 200% 100%; animation: sp-shimmer 1.2s linear infinite; }
@keyframes sp-shimmer { from { background-position: 200% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sp-skel { animation: none; } }

/* Route card */
.route-card { flex: 0 0 auto; padding: 0; overflow: hidden; }
.rc-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.rc-head .chip { font-size: 13px; padding: 3px 9px; }
.rc-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rc-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 10px; }
.rc-head .chip { pointer-events: none; }
.rc-title { font-weight: 700; font-size: 14px; line-height: 1.25; }
.rc-sub { color: var(--muted); font-size: 12px; }
.rc-toggle { color: var(--muted); font-size: 12px; transition: transform 0.15s; }
.route-card.collapsed .rc-toggle { transform: rotate(-90deg); }
.route-card.collapsed .rc-body { display: none; }
.rc-body { padding: 0 14px 12px; border-top: 1px solid var(--border); }
.rc-body dl { margin-top: 10px; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; }
.rc-body dd { overflow-wrap: anywhere; }
.rc-muted { color: var(--muted); }
.rc-live .ok { color: #1a7f37; } .rc-live .late { color: #d1242f; } .rc-live .early { color: #1f6feb; }
@media (prefers-color-scheme: dark) {
  .rc-live .ok { color: #3fb950; } .rc-live .late { color: #f85149; } .rc-live .early { color: #58a6ff; }
}
.next-later { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.next-later .next-time { font-size: 20px; }

/* The route card sits below the main card (vehicle or stop departures) */
.side .panel { order: 1; }
.side .route-card { order: 2; }
/* The main card keeps at least half the column; the route card shrinks and scrolls if needed */
.side .panel { min-height: min(260px, 50%); }
.side .route-card { flex: 0 1 auto; min-height: 44px; overflow: auto; }

/* Search box (top of the right-hand column; top of the map on phones) */
.search { position: relative; }
.search input {
  width: 100%; font: inherit; font-size: 14px; color: var(--fg);
  padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel) no-repeat 11px center / 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 10; /* drops over the cards below */
  list-style: none; margin: 0; padding: 4px;
  background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: min(60vh, 480px); overflow: auto;
}
.sr-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 8px 8px 4px; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.sr-item[aria-selected="true"], .sr-item:hover { background: rgba(127, 127, 127, 0.15); }
.sr-item .chip { flex-shrink: 0; pointer-events: none; }
.sr-icon { flex: 0 0 26px; height: 22px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.sr-text { min-width: 0; flex: 1; }
.sr-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-empty { padding: 10px 8px; color: var(--muted); font-size: 13px; }
.sr-title, .sr-sub { display: block; }
.search-results mark { background: none; color: var(--accent); font-weight: 700; }
@media (max-width: 600px) {
  .search-results { max-height: 50vh; }
}

/* ---------- Trip planner ---------- */
.plan-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  font: inherit; font-size: 15px; font-weight: 650; letter-spacing: 0.1px;
  padding: 11px 14px; border-radius: 10px; cursor: pointer;
  border: 0; background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(31, 111, 235, 0.35);
  transition: filter 0.15s, transform 0.05s;
}
.plan-btn:hover { filter: brightness(1.08); }
.plan-btn:active { transform: translateY(1px); }
.plan-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
/* While the planner is open the button reads as "on" */
.plan-btn.active { background: var(--panel); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
#map.picking { cursor: crosshair; }
#map.picking .leaflet-interactive { cursor: crosshair; }

.planner {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  width: min(460px, calc(100vw - 24px)); max-height: calc(100% - 24px);
  overflow: auto; padding: 0;
}
/* Same title bar as the route card; ↻ and × sit before the ▼ */
.planner > .rc-head { position: sticky; top: 0; z-index: 2; background: var(--panel); border-radius: 10px 10px 0 0; }
.planner .rc-title { margin: 0; }
.planner.collapsed .card-body { display: none; }
.planner.collapsed .rc-toggle { transform: rotate(-90deg); }
.pl-close {
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 7px; background: none; cursor: pointer;
  color: var(--muted); font-size: 20px; line-height: 1;
}
.pl-close:hover { color: var(--fg); background: rgba(127, 127, 127, 0.14); }
.pl-points { display: flex; align-items: center; gap: 8px; margin: 10px 0 8px; }
.pl-rows { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pl-point {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--fg); background: rgba(127, 127, 127, 0.08);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.pl-pt { display: flex; gap: 6px; min-width: 0; }
.pl-pt .pl-point { flex: 1; min-width: 0; }
.pl-loc {
  flex: 0 0 34px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: rgba(127, 127, 127, 0.08); color: var(--accent);
}
.pl-loc:hover { border-color: var(--accent); }
.pl-loc.busy svg { animation: pl-loc-pulse 0.9s ease-in-out infinite alternate; }
.pl-loc.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@keyframes pl-loc-pulse { from { opacity: 1; } to { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pl-loc.busy svg { animation: none; opacity: 0.5; } }
.pl-locmsg { margin: 0 0 8px; font-size: 12px; color: #bf8700; }
@media (prefers-color-scheme: dark) { .pl-locmsg { color: #d29922; } }
.pl-point.picking { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.25); }
.pl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pin {
  flex: 0 0 22px; height: 22px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.pin.a, .plan-pin.a { background: #1a7f37; }
.pin.b, .plan-pin.b { background: #d1242f; }
.pl-swap {
  flex: 0 0 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
}
.pl-when { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pl-when select, .pl-when input {
  font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
}
.pl-body { margin-top: 10px; }
.pl-hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

/* map pins */
.plan-pin-icon { background: none; border: none; }
.plan-pin {
  width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); color: #fff; font-weight: 800; font-size: 13px;
}
.plan-pin { line-height: 1; }
.plan-pin::after { content: none; }
.plan-pin > * { transform: rotate(45deg); }
.leaflet-tooltip.pl-tip { font-weight: 600; font-size: 12px; }

/* options */
.pl-options { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pl-option { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.pl-option:hover { border-color: var(--muted); }
.pl-option.selected { border-color: var(--accent); cursor: default; }
.pl-sum { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pl-times { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.pl-dur { font-weight: 700; color: var(--muted); font-size: 13px; }
.pl-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.pl-chips { display: inline-flex; align-items: center; gap: 2px; }
.pl-chips .chip { cursor: pointer; }
.pl-arrow { color: var(--muted); padding: 0 1px; }
.pl-tag { font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 0 6px; }

/* legs */
.pl-legs { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.pl-leg.walk, .pl-leg.change, .pl-leg.arrive { display: flex; align-items: baseline; gap: 6px; color: var(--muted); padding-left: 2px; }
.pl-leg.arrive { color: var(--fg); }
.pl-icon { flex: 0 0 18px; text-align: center; }
.pl-leg.ride { border-left: 4px solid var(--c, var(--accent)); padding: 4px 0 4px 10px; margin-left: 6px; display: flex; flex-direction: column; gap: 3px; }
.pl-leg-head { display: flex; align-items: center; gap: 6px; }
.pl-leg-head .chip { cursor: pointer; }
.pl-towards { color: var(--muted); font-size: 12px; }
.pl-step { display: flex; gap: 8px; align-items: baseline; }
.pl-time { flex: 0 0 62px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pl-meta { padding-left: 70px; font-size: 12px; color: var(--muted); }
.pl-stop { font-size: 13px; font-weight: 600; color: var(--fg); text-align: left; }
.pl-stop:hover { color: var(--accent); text-decoration: underline; }
.sp-plan { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }

@media (max-width: 600px) {
  .plan-btn { padding: 9px 12px; font-size: 14px; }
  /* Phones: the planner sits at the bottom so the map above stays free for tapping the A/B points */
  .planner { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; max-height: 46%; padding: 0; }
  .pl-points { margin: 6px 0; }
  .pl-hint { font-size: 12px; }
  .side { z-index: 1050; } /* a vehicle/stop opened from the planner shows over it */
}

/* Trip planner: refresh button and "your bus has left" banner */
.pl-actions { display: inline-flex; align-items: center; gap: 6px; }
.pl-refresh {
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg);
}
.pl-refresh:hover { border-color: var(--accent); color: var(--accent); }
/* Only the arrow spins, not the button */
.pl-refresh.spin .pl-refresh-ico { animation: pl-spin 0.7s ease-in-out; }
@keyframes pl-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pl-refresh.spin .pl-refresh-ico { animation: none; } }
.pl-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px;
}
.pl-banner.warn { color: #d1242f; border-color: rgba(209, 36, 47, 0.45); background: rgba(209, 36, 47, 0.08); }
.pl-banner .btn.small { margin-top: 0; }
@media (prefers-color-scheme: dark) { .pl-banner.warn { color: #f85149; } }

.pl-only { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--fg); cursor: pointer; }
.pl-only input { width: 16px; height: 16px; accent-color: var(--accent); }

.pl-every { color: var(--muted); font-weight: 400; white-space: nowrap; }
.pl-wait { color: var(--muted); white-space: nowrap; }
.pl-wait.long { color: #bf8700; font-weight: 600; }
@media (prefers-color-scheme: dark) { .pl-wait.long { color: #d29922; } }
.pl-buffer { margin-top: 8px; }
#plBody [data-plan-route]:hover { filter: brightness(1.1); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--c); }

/* Stop schedule: day buttons (today + the next six days) and hour headings */
.day-tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 0 0 10px; }
.day-tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 0; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--fg);
  background: rgba(127, 127, 127, 0.08); border: 1px solid var(--border); border-radius: 8px;
}
.day-tab span { font-size: 11px; font-weight: 500; color: var(--muted); }
.day-tab:hover { border-color: var(--accent); }
.day-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.day-tab[aria-selected="true"] span { color: rgba(255, 255, 255, 0.85); }
.dep-count { margin: 0 0 4px; font-size: 12px; }
#panelBody .deplist { max-height: none; }
.deplist li.dep-hour {
  position: sticky; top: -14px; z-index: 1; padding: 6px 2px 3px; background: var(--panel);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
}
.stop-name-link { text-align: left; font-size: inherit; font-weight: 600; }
.stop-name-link:hover { text-decoration: underline; }

/* Main card (vehicle or stop) collapses to its title row */
.panel-collapse {
  position: absolute; top: 7px; right: 34px; width: 26px; height: 26px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px; background: none; color: var(--muted);
}
.panel-collapse:hover { color: var(--fg); background: rgba(127, 127, 127, 0.14); }
.side .panel.collapsed { min-height: 0; flex: 0 0 auto; }

/* Trip planner collapses to its header and a one-line summary of the chosen trip */
.pl-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-width: 0; }
.pl-summary b { color: var(--fg); font-weight: 600; }
.pl-summary .chip { pointer-events: none; font-size: 10px; padding: 1px 6px; min-width: 0; }
.pl-summary .pl-arrow { font-size: 10px; }

@media (max-width: 600px) {
  /* Phones: the planner, vehicle/stop card and route card stack in one column at the bottom */
  .side { max-height: calc(100% - var(--topbar-h, 200px) - 24px); }
  .side .planner {
    position: static; order: 0; width: auto; max-height: none; flex: 0 1 auto; min-height: 0;
    overflow: auto; padding: 0;
  }
  .side .planner:not(.collapsed) { min-height: min(180px, 40%); }
}

/* 110% interface: the cards, popups and map buttons are drawn 10% larger (map tiles stay sharp at 100%). */
.topbar, .side, .planner, .leaflet-popup-content, .leaflet-control-zoom, .empty-state { zoom: 1.1; }
/* (Popups: only the content is zoomed, so Leaflet measures the larger size and keeps the tip on the stop.) */

/* A collapsed card is just its title bar: never squeeze it (that made it scroll on short screens) */
.side .collapsed, .side .route-card.collapsed { flex: 0 0 auto; min-height: 0; overflow: hidden; }
