:root { --bg: #fff; --fg: #1d1d1f; --muted: #6b6b70; --border: #e2e2e6; --hover: #f2f2f5; --accent: #0a7cff; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1c1e; --fg: #f2f2f5; --muted: #9a9aa0; --border: #333338; --hover: #2a2a2e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 system-ui, -apple-system, sans-serif; color: var(--fg); background: var(--bg); }
#map { position: absolute; inset: 0; }
#panel {
  position: absolute; z-index: 1000; top: 12px; left: 12px; width: 300px; max-height: calc(100% - 24px);
  overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,.18); padding: 12px 14px; transition: transform .2s;
}
#panel.collapsed { transform: translateX(calc(-100% + 34px)); }
#panel.collapsed > :not(header) { visibility: hidden; }
header { display: flex; justify-content: space-between; align-items: center; }
h1 { font-size: 17px; margin: 0; }
a { color: inherit; }
#collapse { background: none; border: 0; color: var(--fg); font-size: 20px; cursor: pointer; padding: 0 4px; }
#panel.collapsed #collapse { transform: rotate(180deg); }
input[type=search] { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg); font: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
/* Search box in the map's top-right corner, above the zoom buttons. */
/* z-index lifts the search (and its dropdown) above the zoom/view buttons that sit just below it. */
.map-search { position: relative; z-index: 1001; width: 280px; max-width: calc(100vw - 340px); min-width: 180px; }
.map-search input { box-shadow: 0 1px 5px rgba(0,0,0,.4); border-radius: 6px; padding: 8px 10px; font: 14px/1.3 system-ui, -apple-system, sans-serif; }
#results { display: none; position: absolute; right: 0; top: calc(100% + 4px); width: 100%; max-height: 60vh; overflow-y: auto;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  padding: 4px; z-index: 1001; font: 13px/1.35 system-ui, -apple-system, sans-serif; }
#results.open { display: block; }
#results li { padding: 6px 7px; border-radius: 5px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#results li:hover, #results li.active { background: var(--hover); }
#results li.status { cursor: default; color: var(--muted); font-size: 12px; }
#results .kind { color: var(--muted); font-size: 11px; white-space: nowrap; }
#results .place-name { font-weight: 600; }
/* Long names and addresses truncate rather than widening the list (no sideways scrollbar). */
#results { overflow-x: hidden; }
#results li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results li > span:first-child .kind { display: block; overflow: hidden; text-overflow: ellipsis; }
#searchToggle { display: none; }
/* Phones: a 🔍 button, so the bar doesn't cover the panel's header and collapse button. Tapping it
   expands the full-width bar (above the panel); picking a result, Esc, or tapping the map collapses it. */
@media (max-width: 640px) {
  .map-search { width: auto; min-width: 0; max-width: none; }
  .map-search:not(.expanded) input, .map-search:not(.expanded) #results { display: none; }
  .map-search:not(.expanded) #searchToggle { display: block; width: 34px; height: 34px; border-radius: 6px; border: 2px solid rgba(0,0,0,.2);
    background: var(--bg); font-size: 16px; line-height: 1; cursor: pointer; padding: 0; }
  .map-search.expanded { width: calc(100vw - 24px); }
}

.mode { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 8px; }
.mode summary { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; list-style: none; margin-bottom: 6px; font-weight: 600; }
.mode summary::-webkit-details-marker { display: none; }
.mode summary::before { content: '▸'; margin-right: 6px; transition: transform .15s; }
.mode[open] summary::before { transform: rotate(90deg); }
.mode summary .actions { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; }

#lines li, .rail-lines li { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; user-select: none; }
#lines li.off, .rail-lines li.off { opacity: .4; }
/* Commuter-rail line with no train running right now. */
.rail-lines li.idle > span:nth-child(2) { color: var(--muted); }
.rail-lines li.idle .swatch { filter: grayscale(1); opacity: .55; }
.rail-lines li.idle .status { font-style: italic; }
/* Group header in a railroad's line list (Amtrak: "Serving Chicago", "Rest of the US"). */
.rail-lines li.sep { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 0 2px; font-weight: 600; }
.rail-lines li.sep:hover { color: var(--fg); }
.swatch { width: 26px; height: 6px; border-radius: 3px; flex: none; }
.dots { display: inline-flex; gap: 2px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.check { display: block; padding: 3px 0; cursor: pointer; }
.status { color: var(--muted); font-size: 12px; }

#busFilter { margin-bottom: 6px; }
#busRoutes { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 4px; margin-bottom: 6px; }
#busRoutes li label { display: flex; align-items: center; gap: 7px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
#busRoutes li label:hover { background: var(--hover); }
#busRoutes li { display: flex; align-items: center; }
#busRoutes li > label:first-child { flex: 1; min-width: 0; }
/* ⏺ record-for-replay toggle on each bus route: faint when off, red when on. */
#busRoutes li label.rec { flex: none; padding: 2px 5px; font-size: 12px; }
#busRoutes .rec input { display: none; }
#busRoutes .rec span { opacity: .25; filter: grayscale(1); }
#busRoutes .rec:hover span { opacity: .6; }
#busRoutes .rec input:checked + span { opacity: 1; filter: none; color: #e0245e; }
#busRoutes .rt { font-weight: 700; min-width: 30px; }
#busRoutes .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#busRoutes .sep { font-size: 11px; color: var(--muted); padding: 4px 4px 2px; text-transform: uppercase; letter-spacing: .04em; }
footer { margin-top: 12px; font-size: 11px; color: var(--muted); }

.leaflet-popup-content { margin: 10px 12px; min-width: 220px; }
.popup h3 { margin: 0 0 4px; font-size: 15px; }
.popup .meta { color: #666; font-size: 12px; margin-bottom: 6px; }
.popup table { border-collapse: collapse; width: 100%; font-size: 12px; }
.popup td { padding: 2px 4px 2px 0; vertical-align: top; }
.popup td.min { text-align: right; white-space: nowrap; font-weight: 600; }
.pill { display: inline-block; padding: 1px 6px; border-radius: 8px; color: #fff; font-size: 11px; font-weight: 600; margin: 0 3px 3px 0; }
.basemap { filter: grayscale(1) contrast(.9) brightness(1.05); opacity: .75; }
@media (prefers-color-scheme: dark) {
  .basemap { filter: grayscale(1) invert(1) brightness(.9) contrast(.85); opacity: .9; }
  #map { background: #111; }
}
.train-marker { background: none; border: 0; }
.train-arrow { display: block; overflow: visible; transition: transform 1.2s ease-in-out; filter: drop-shadow(0 0 1.5px rgba(0,0,0,.7)); }
.swatch.metra { height: 7px; border-radius: 1px; box-shadow: 0 0 0 1.5px #1a1a1a; }
.bus-dot { width: 8px; height: 8px; border-radius: 2px; border: 1px solid #fff; box-shadow: 0 0 2px rgba(0,0,0,.7); }
.train-wrap { position: relative; width: 100%; height: 100%; }
.express-badge { position: absolute; right: -10px; top: -10px; width: 19px; height: 19px; border-radius: 50%;
  background: #111; color: #ffd400; font-size: 12px; line-height: 19px; text-align: center; border: 2px solid #ffd400;
  box-shadow: 0 0 3px rgba(0,0,0,.8); pointer-events: none; }
.express-tag { display: inline-block; padding: 0 5px; border-radius: 7px; background: #111; color: #ffd400; font-size: 10px; font-weight: 700; vertical-align: 1px; }
.express-badge.limited { background: #fff; color: #111; border-color: #111; font: 900 15px/17px system-ui, sans-serif; }
.express-tag.limited { background: #e8e8ec; color: #111; }
/* Route labels along commuter-rail lines. */
.route-labels { display: flex; gap: 2px; transform: translate(-50%, -50%); white-space: nowrap; pointer-events: none; }
.route-label { font: 700 9px/1 system-ui, sans-serif; letter-spacing: .02em; padding: 2px 4px; border-radius: 3px;
  border: 1px solid rgba(255,255,255,.85); box-shadow: 0 0 2px rgba(0,0,0,.7); }
.route-label.idle { opacity: .75; }
.train-popup { min-width: 200px; }
.train-popup .next-arrival { margin-top: 6px; padding-top: 6px; border-top: 1px solid #e2e2e6; }
/* Same block inside a hover tooltip: tooltips don't wrap by default, and their text is smaller. */
/* Tooltips sit in a zero-width box, so with wrapping on they'd collapse to the narrowest word. Size to the
   content instead (max-content), capped at 300px; only text longer than that wraps. */
.leaflet-tooltip .train-popup { min-width: 0; width: max-content; max-width: 300px; white-space: normal; }
.leaflet-tooltip .train-popup .next-arrival { margin-top: 4px; padding-top: 4px; }
.train-popup .next-arrival .meta { display: inline; margin-left: 2px; }

/* ---- Replay ---- */
/* Map control under the search bar: a button that opens the replay card (same width as the search bar). */
.map-replay { clear: both; display: flex; flex-direction: column; align-items: flex-end; }
#rpToggle { font: 13px/1 system-ui, -apple-system, sans-serif; padding: 7px 10px; border-radius: 6px; border: 2px solid rgba(0,0,0,.2);
  background: var(--bg); color: var(--fg); cursor: pointer; background-clip: padding-box; }
#rpToggle:hover { background: var(--hover); }
body.replaying #rpToggle { background: #b3261e; color: #fff; }
.rp-card { display: none; width: 280px; max-width: calc(100vw - 340px); min-width: 230px; margin-top: 6px; padding: 8px 10px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  font: 13px/1.35 system-ui, -apple-system, sans-serif; }
.map-replay.open .rp-card { display: block; }
.map-replay.open #rpToggle { display: none; }
.rp-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.rp-head .status { flex: 1; text-align: right; }
#rpClose { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
#rpClose:hover { color: var(--fg); }
#rpSlider { width: 100%; margin: 2px 0 6px; }
.replay-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.replay-row button, .replay-row select, .replay-row input, .replay-banner button {
  font: inherit; font-size: 13px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer; }
.replay-row input[type=datetime-local] { flex: 1; min-width: 0; padding: 3px 4px; }
.replay-row button:disabled { opacity: .45; cursor: default; }
#rpPlay { min-width: 34px; }
/* Banner across the top of the map while replaying, so it's never mistaken for live. */
.replay-banner { display: none; position: absolute; z-index: 1000; top: 12px; left: 50%; transform: translateX(-50%);
  background: #b3261e; color: #fff; border-radius: 8px; padding: 5px 8px 5px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.4);
  font-size: 13px; white-space: nowrap; align-items: center; gap: 8px; }
.replay-banner button { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.5); padding: 2px 8px; }
body.replaying .replay-banner { display: flex; }

@media (max-width: 640px) {
  /* Phones: below the search button row, full width. */
  .replay-banner { top: auto; bottom: 28px; max-width: calc(100vw - 24px); font-size: 12px; }
  /* Phones: just ⏪ (like the 🔍 button); the open card spans the screen. */
  #rpToggle { width: 34px; height: 34px; padding: 0; font-size: 15px; }
  #rpToggle .rp-label { display: none; }
  .rp-card { width: calc(100vw - 24px); max-width: none; min-width: 0; }
}

/* ---- Bus markers: CTA Bus Tracker icon on the route color, arrow for direction of travel ---- */
.bus-marker { background: none; border: 0; }
.bus-box { position: relative; border-radius: 4px; box-shadow: 0 0 0 1.5px #fff, 0 0 4px rgba(0,0,0,.7); overflow: hidden; }
.bus-icon { display: block; width: 100%; height: 100%; }
/* The arrow sits just outside the box and orbits its center as it turns. */
.bus-box { width: 100%; height: 100%; }
.bus-dir { position: absolute; inset: 0; pointer-events: none; }
/* Centered ~20 px (14 px when small) from the box's center: clear of its edges, and of its corners at diagonals. */
.bus-arrow { position: absolute; left: 50%; top: -17px; width: 16px; height: 16px; margin-left: -8px; filter: drop-shadow(0 0 1.5px rgba(0,0,0,.7)); }
.bus-square .bus-arrow { top: -13px; width: 13px; height: 13px; margin-left: -6.5px; }
/* Route number beside the icon (right, or left for eastbound buses: see tagLeft in app.js). */
.bus-route { position: absolute; left: calc(100% + 4px); top: 50%; transform: translateY(-50%); color: #fff;
  font: 700 9px/1 system-ui, sans-serif; padding: 2px 3px; border-radius: 3px; white-space: nowrap;
  box-shadow: 0 0 0 1px #fff, 0 0 3px rgba(0,0,0,.6); }
.bus-marker.tag-left .bus-route { left: auto; right: calc(100% + 4px); }

/* Bus hover: next stops and minutes away. */
.bus-next { border-collapse: collapse; margin-top: 2px; }
.bus-next td { padding: 1px 0; vertical-align: top; }
.bus-next td.min { padding-left: 10px; text-align: right; white-space: nowrap; font-weight: 600; }
