:root {
  color-scheme: light;
  font-family: "Instrument Sans", system-ui, sans-serif;
  color: #142b32;
  background: #f7f8f4;
  --muted: #52666a;
  --border: #dbe3df;
  --accent: #007566;
}
* { box-sizing: border-box; }
body { margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 78px; padding: 13px 26px; background: #102d34; color: #f5fcfa;
}
.identity, .feed { display: flex; align-items: center; gap: 13px; }
.brand {
  background: #d4f2db; color: #123c37; padding: 10px; border-radius: 7px;
  font-weight: 800; letter-spacing: .045em; font-size: 13px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.15; letter-spacing: -.025em; }
.identity p, .feed-time { font-size: 12px; color: #bcd2d3; margin-top: 3px; }
.status { padding: 6px 10px; border-radius: 5px; background: #26464e; font-size: 12px; font-weight: 650; }
.status[data-state="live"] { background: #ccebd7; color: #14533e; }
.status[data-state="stale"], .status[data-state="snapshot"] { background: #ffebc1; color: #69450a; }
.status[data-state="offline"] { background: #f9d9d3; color: #782f29; }
main { display: grid; grid-template-columns: minmax(270px, 325px) minmax(0, 1fr); flex: 1; min-height: 0; }
aside { display: flex; flex-direction: column; min-height: 0; background: #fff; border-right: 1px solid var(--border); }
.filters { padding: 19px 18px 16px; border-bottom: 1px solid var(--border); }
#vehicle-controls { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.route-heading, .results-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
label, h2 { font-size: 13px; font-weight: 700; }
input, select, button { font: inherit; color: inherit; }
.toggle { display: flex; align-items: center; gap: 7px; margin-top: 12px; font-weight: 550; }
input[type="checkbox"] { accent-color: var(--accent); }
#fit { font-size: 12px; font-weight: 700; background: #edf5f0; border: 0; border-radius: 4px; padding: 5px 8px; color: #23544d; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.results-heading { padding: 12px 18px; background: #f4f7f4; }
#count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#vehicle-list { margin: 0; padding: 0 10px 10px; overflow: auto; list-style: none; }
.vehicle {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  text-align: left; width: 100%; padding: 10px 6px; border: 0;
  border-bottom: 1px solid #e9efeb; background: #fff;
}
.vehicle:hover, .vehicle[aria-pressed="true"] { background: #edf5f0; }
.vehicle-id { font-size: 13px; font-weight: 750; }
.age { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #879792; flex: 0 0 auto; }
.dot.fresh { background: var(--route-color, #007566); }
.notice, .empty { padding: 10px 14px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.notice { background: #fff4de; color: #69450a; }
.map-panel { position: relative; min-height: 0; background: #e5ede7; isolation: isolate; }
#map { height: 100%; background: #e5ede7; }
.legend, .map-error {
  position: absolute; z-index: 500; background: #ffffffed; border: 1px solid var(--border);
  border-radius: 7px; box-shadow: 0 2px 10px #102d341a;
}
.legend { bottom: 26px; right: 12px; display: flex; flex-wrap: wrap; gap: 10px 14px; padding: 8px 10px; font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .line { width: 15px; height: 3px; border-radius: 3px; background: #526f8e; }
.map-error { left: 50%; top: 16px; transform: translateX(-50%); padding: 10px; max-width: 75%; font-size: 12px; }
.popup { min-width: 168px; line-height: 1.45; }
.popup strong { font-size: 15px; }
.popup p { margin: 4px 0 0; }
.popup .age { color: #385054; }
#favorites {
  width: 100%; margin-top: 7px; border: 1px solid #c3d1cd; border-radius: 6px;
  padding: 7px 8px; background: #edf5f0; color: #23544d; font-size: 12px; font-weight: 700;
}
#favorites[aria-pressed="true"] { background: #d3eee1; border-color: #007566; }
.layers { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; }
.layers .toggle { margin: 0; font-size: 12px; }
.bus-icon > div { --bus-color: var(--route-color, #526764); }
.bus-icon.is-stale > div { opacity: .55; }
.bus-icon.is-estimated .bus-route { border-style: dashed; outline: 1px solid #372754; }
.bus-icon.is-selected .bus-route { box-shadow: 0 0 0 3px #102d34, 0 2px 5px #102d3460; }
.bus-route {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  min-width: 24px; height: 23px; padding: 0 3px; border: 2px solid white;
  border-radius: 6px; background: var(--bus-color); color: white; box-shadow: 0 1px 4px #102d3470;
  font: 800 11px/19px system-ui, sans-serif; text-align: center; white-space: nowrap;
}
.bus-heading {
  position: absolute; inset: 0; pointer-events: none;
}
.bus-heading::before {
  content: ""; position: absolute; left: 50%; top: 0;
  transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 8px solid var(--bus-color);
  filter: drop-shadow(0 0 1px white);
}
.dot.estimate { background: #64469a; border: 1px dashed white; outline: 1px solid #372754; }
.dot.stop { background: #fff; border: 2px solid #3f6486; }
.route-presets { display: flex; gap: 6px; margin: 8px 0; }
.route-presets button, .route-choice {
  padding: 5px 7px; border: 1px solid #d3deda; border-radius: 5px;
  background: #f1f4f2; color: #425854; font-size: 12px; font-weight: 700;
}
.route-presets #favorites { width: auto; margin: 0; }
.route-presets #all-routes[aria-pressed="true"] { background: #d3eee1; border-color: #007566; }
#route-options {
  display: flex; flex-wrap: wrap; gap: 4px; max-height: 126px; overflow-y: auto;
  padding: 2px; align-content: start;
}
.route-choice { min-width: 31px; padding: 4px 5px; }
.route-choice[aria-pressed="true"] { background: var(--route-color); border-color: var(--route-color); color: #fff; }
.route-choice:hover { box-shadow: inset 0 0 0 1px currentColor; }
.popup h3 { margin: 8px 0 4px; font-size: 12px; }
.stop-times { max-height: 230px; width: min(285px, 62vw); overflow-y: auto; overscroll-behavior: contain; }
.departure-list { list-style: none; margin: 0; padding: 0 5px 0 0; }
.departure-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px;
  padding: 5px 0; border-top: 1px solid #dbe3df;
}
.departure-route, .departure-clock strong { font-size: 12px; font-weight: 750; }
.departure-headsign, .departure-clock span { display: block; font-size: 10px; }
.departure-clock { text-align: right; white-space: nowrap; }
.legend .line.shared { background: #f7faf8; border: 1px solid #526f8e; }
.gps-key { color: #37434a; font-size: 9px; font-weight: 800; font-style: normal; }
.bus-fix .bus-route { background: #e5e9e8; border: 1px solid #56625f; color: #263434; }
.bus-fix .gps-key {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  line-height: 11px; padding: 0 2px; background: white; border-radius: 2px; white-space: nowrap;
}
.mobile-tools, .mobile-close, .sheet-heading, #stop-sheet { display: none; }

@media (max-width: 760px), (max-height: 480px) and (pointer: coarse) {
  .topbar {
    min-height: 54px; gap: 8px;
    padding: calc(6px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      6px max(12px, env(safe-area-inset-left));
  }
  .identity { gap: 8px; }
  .identity p { display: none; }
  .brand { padding: 7px; font-size: 11px; }
  h1 { font-size: 16px; }
  .feed { min-width: 0; flex-direction: column; align-items: flex-end; gap: 0; }
  .feed-time { font-size: 10px; }
  .status { font-size: 11px; padding: 4px 6px; text-align: right; }
  main { position: relative; display: flex; flex-direction: column; isolation: isolate; }
  .map-panel { flex: 1; }
  #map .leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
  .mobile-tools {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
    background: white; border-top: 1px solid var(--border); z-index: 4;
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .mobile-tools button, .mobile-close {
    min-height: 44px; border: 0; border-radius: 8px; background: #eff4f1;
    font-weight: 700; font-size: 13px;
  }
  .mobile-tools button[aria-expanded="true"] { background: #d3eee1; color: #185443; }
  aside, #stop-sheet, .legend {
    position: absolute; left: max(6px, env(safe-area-inset-left)); right: max(6px, env(safe-area-inset-right));
    bottom: calc(58px + env(safe-area-inset-bottom)); max-height: calc(100% - 66px - env(safe-area-inset-bottom));
    background: white; border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 4px 24px #102d3433; z-index: 3; overflow: auto; overscroll-behavior: contain;
  }
  aside, .legend, #route-controls, #vehicle-controls { display: none; }
  #app[data-panel="routes"] aside, #app[data-panel="vehicles"] aside,
  #app[data-panel="routes"] #route-controls, #app[data-panel="vehicles"] #vehicle-controls {
    display: block;
  }
  #app[data-panel="vehicles"] aside { max-height: min(49%, 380px); }
  #app[data-panel="legend"] .legend {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  }
  .legend { bottom: 5px; max-height: calc(100% - 10px); padding: 10px 12px 14px; z-index: 800; }
  .legend .sheet-heading { grid-column: 1 / -1; }
  .sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .mobile-close { display: block; flex: 0 0 44px; width: 44px; font-size: 23px; font-weight: 500; }
  #fit { min-height: 44px; margin-left: auto; padding-inline: 12px; }
  .filters { padding: 8px 12px 10px; border-bottom: 0; }
  .route-presets { margin: 6px 0; flex-wrap: wrap; }
  .route-presets button { min-height: 44px; padding-inline: 10px; }
  #route-options {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 5px; max-height: none; overflow: visible;
  }
  .route-choice { min-height: 44px; }
  .route-choice[data-route-choice=""] { grid-column: span 2; }
  .layers { margin-top: 6px; gap: 4px 14px; }
  .layers .toggle { min-height: 44px; }
  .results-heading { padding: 5px 10px 5px 14px; }
  #count { margin-left: auto; }
  #vehicle-list { overflow: visible; }
  .vehicle { min-height: 48px; }
  #stop-sheet:not([hidden]) { display: block; padding: 8px 12px 12px; max-height: min(51%, 400px); }
  #stop-sheet-title { font-size: 15px; }
  #stop-sheet .stop-times { width: auto; max-height: none; overflow: visible; }
  #stop-sheet .departure-list li { padding: 9px 0; }
  #stop-sheet .departure-headsign, #stop-sheet .departure-clock span { font-size: 11px; }
}
