/* =========================================================
   BusPulse — styles.css
   Clean, modern, system-theme-aware with dark + light mode.
   ========================================================= */
:root {
  --bg: #f5f7fb;
  --bg-card: #ffffff;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f2f7;
  --input-bg: #f0f2f7;
  --border: #e2e6ee;
  --text: #1a1f2b;
  --text-dim: #5a6477;
  --accent: #0078d7;
  --accent-2: #5c2d91;
  --ontime: #2ecc71;
  --late: #e81123;
  --early: #f5b800;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}
[data-theme="dark"] {
  --bg: #0e1116;
  --bg-card: #161b22;
  --bg-elev: #161b22;
  --bg-elev-2: #1f2530;
  --input-bg: #1f2530;
  --border: #262d39;
  --text: #e6edf3;
  --text-dim: #8b96a6;
  --accent: #4cc2ff;
  --accent-2: #7c5cff;
  --ontime: #2ecc71;
  --late: #ff5c5c;
  --early: #f5b800;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-card: #ffffff;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f2f7;
  --input-bg: #f0f2f7;
  --border: #e2e6ee;
  --text: #1a1f2b;
  --text-dim: #5a6477;
  --accent: #0078d7;
  --accent-2: #5c2d91;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; min-height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }

#app { display: grid; grid-template-columns: 380px minmax(0, 1fr); height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; min-height: 0; }

/* ===== Minimal front page ===== */
.front-page { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at top, rgba(76,194,255,.13), transparent 34%), var(--bg); transition: opacity .22s ease, visibility .22s ease; }
.front-page--hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.front-card { width: min(560px, 100%); background: color-mix(in srgb, var(--bg-elev) 92%, transparent); border: 1px solid var(--border); border-radius: 28px; padding: 34px; box-shadow: var(--shadow); }
.front-logo { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 18px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: 28px; margin-bottom: 18px; }
.front-card h1 { margin: 0; font-size: clamp(34px, 8vw, 56px); letter-spacing: -.06em; line-height: .95; }
.front-subtitle { margin: 12px 0 26px; color: var(--text-dim); font-size: 16px; }
.front-tabs { display: flex; gap: 4px; margin-bottom: 22px; background: var(--bg-elev-2); border-radius: 14px; padding: 4px; }
.front-tab { flex: 1; border: 0; background: transparent; color: var(--text-dim); font-weight: 600; font-size: 14px; padding: 10px 14px; border-radius: 10px; cursor: pointer; transition: all .15s ease; }
.front-tab--active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.front-tab-panel { display: block; }
.front-tab-panel[hidden] { display: none; }
.bus-search-hint { margin: 8px 0 0; color: var(--text-dim); font-size: 13px; }
.stop-search-form label { display: block; margin-bottom: 8px; color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.stop-search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.stop-search-row input { min-width: 0; background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 15px 16px; font-size: 18px; outline: none; }
.stop-search-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(76,194,255,.16); }
.stop-search-row button, .open-map-btn { border: 0; border-radius: 16px; padding: 0 20px; color: #001520; background: var(--accent); font-weight: 800; cursor: pointer; }
.open-map-btn { width: 100%; margin-top: 14px; height: 44px; background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
.front-error { margin-top: 14px; padding: 12px; border: 1px solid rgba(255,92,92,.35); border-radius: 14px; color: var(--late); background: rgba(255,92,92,.09); font-size: 13px; }
.arrival-results { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; max-height: min(48vh, 420px); overflow: auto; }
.arrival-warning { padding: 10px 12px; border-radius: 14px; border: 1px solid rgba(245,184,0,.28); background: rgba(245,184,0,.09); color: var(--early); font-size: 12px; line-height: 1.35; }
.arrival-card { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 13px; border: 1px solid var(--border); border-radius: 18px; background: var(--bg-elev-2); color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.arrival-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.arrival-route { display: grid; place-items: center; min-height: 42px; border-radius: 13px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #001520; font-weight: 900; }
.arrival-destination { font-weight: 700; }
.arrival-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.arrival-time { text-align: right; font-weight: 900; font-size: 20px; color: var(--accent); }
.arrival-clock { display: block; color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.arrival-suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.arrival-suggestion { width: 100%; text-align: left; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev-2); color: var(--text); padding: 10px 12px; cursor: pointer; font: inherit; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.arrival-suggestion:hover { border-color: var(--accent); transform: translateY(-1px); }

/* ===== Opening split reveal =====
   On first load the screen is covered by two theme-coloured halves. The top
   half slides up and the bottom half slides down, revealing the page. Pure
   CSS animation (JS only removes the overlay afterwards). */
.page-reveal { position: fixed; inset: 0; z-index: 1000; pointer-events: none; overflow: hidden; }
.page-reveal__half { position: absolute; left: 0; width: 100%; height: 50.5%; background: var(--bg); will-change: transform; }
.page-reveal__half--top { top: 0; animation: page-reveal-up .9s cubic-bezier(.76, 0, .24, 1) .35s forwards; }
.page-reveal__half--bottom { bottom: 0; animation: page-reveal-down .9s cubic-bezier(.76, 0, .24, 1) .35s forwards; }
@keyframes page-reveal-up { to { transform: translateY(-101%); } }
@keyframes page-reveal-down { to { transform: translateY(101%); } }
.page-reveal__brand { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 12px; z-index: 1; animation: page-reveal-brand .3s ease .3s forwards; }
@keyframes page-reveal-brand { to { opacity: 0; transform: translate(-50%, -50%) scale(1.08); } }
.page-reveal__logo { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 18px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #001520; box-shadow: var(--shadow); }
.page-reveal__logo svg { width: 30px; height: 30px; }
.page-reveal__wordmark { font-size: 21px; font-weight: 700; letter-spacing: -.03em; color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .page-reveal { display: none; }
}

/* ===== Sidebar ===== */
.sidebar { background: var(--bg-elev); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; min-height: 0; max-height: 100vh; max-height: 100dvh; overflow: hidden; }
.sidebar__header { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand__logo { width: 42px; height: 42px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-radius: 12px; font-size: 22px; box-shadow: var(--shadow); }
.brand__name { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand__tag { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }

.icon-btn { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 16px; display: grid; place-items: center; transition: transform .15s, background .15s; }
.icon-btn:hover { background: var(--border); transform: translateY(-1px); }

.search { padding: 4px 18px 10px; position: relative; }
.search input { width: 100%; background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); padding: 11px 14px; border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,194,255,0.18); }
.search__results { position: absolute; top: 100%; left: 18px; right: 18px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); max-height: 320px; overflow-y: auto; z-index: 10; box-shadow: var(--shadow); }
.search__result { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.search__result { width: 100%; background: transparent; color: var(--text); text-align: left; border-left: 0; border-right: 0; border-top: 0; }
.search__result span { display: block; }
.search__result:last-child { border-bottom: none; }
.search__result:hover { background: var(--bg-elev-2); }
.search__result .muted { color: var(--text-dim); font-size: 11px; }

/* ===== Star / favourites toggle ===== */
.star-btn { background: none; border: none; cursor: pointer; font-size: 18px; padding: 0 4px; color: var(--text-dim); transition: color .15s, transform .15s; line-height: 1; }
.star-btn:hover { transform: scale(1.2); }
.star-btn--active { color: var(--early); }
.star-btn--active:hover { color: var(--early); }

/* ===== Favourites section ===== */
.fav-section { padding: 4px 14px 0; }
.fav-section__header { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--early); margin: 8px 4px 4px; display: flex; align-items: center; gap: 4px; }

/* ===== Nearest stops panel ===== */
.nearest-panel { margin: 6px 18px 4px; padding: 12px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius); animation: pop .2s ease; }
.nearest-panel__header { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 8px; display: flex; align-items: center; gap: 4px; }
.nearest-panel__item { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; cursor: pointer; }
.nearest-panel__item:last-child { border-bottom: none; }
.nearest-panel__item:hover { color: var(--accent); }
.nearest-panel__distance { color: var(--text-dim); font-size: 11px; min-width: 52px; text-align: right; }

.filters { display: flex; gap: 8px; padding: 4px 18px 12px; }
.chip { background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 12px; cursor: pointer; transition: all .15s; }
.chip:hover { color: var(--text); }
.chip--active { background: var(--accent); color: #001520; border-color: transparent; font-weight: 600; }


/* ===== Detail panel ===== */
.detail { position: relative; margin: 0 14px 12px; padding: 16px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius); animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.detail__close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; font-size: 12px; }
.detail h3 { margin: 0 0 4px; font-size: 18px; }
.detail-hero { display: flex; gap: 10px; align-items: center; margin-right: 28px; }
.detail .route-badge { display: inline-block; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #001520; font-weight: 700; padding: 4px 10px; border-radius: 8px; font-size: 14px; margin-right: 8px; }
.detail .meta { color: var(--text-dim); font-size: 12px; margin: 4px 0 12px; }
.prediction-card { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin: 12px 0; padding: 14px; border-radius: 14px; background: linear-gradient(135deg, rgba(76,194,255,.16), rgba(124,92,255,.12)); border: 1px solid rgba(76,194,255,.35); }
.prediction-card--stale { background: rgba(245,184,0,.12); border-color: rgba(245,184,0,.45); }
.prediction-card__label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.prediction-card__eta { font-size: 30px; font-weight: 800; letter-spacing: -.04em; line-height: 1; margin-top: 4px; }
.prediction-card__side { text-align: right; color: var(--text-dim); font-size: 12px; line-height: 1.45; }
.stops { display: flex; flex-direction: column; gap: 0; margin-top: 8px; }
.stop { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); align-items: center; }
.stop:last-child { border-bottom: none; }
.stop__eta { font-weight: 700; font-size: 14px; color: var(--accent); }
.stop__name { font-size: 13px; }
.stop__range { font-size: 10px; color: var(--text-dim); }
.stop--next { background: rgba(76,194,255,0.08); border-radius: 8px; padding: 8px; margin: 0 -4px; }

/* ===== Live list ===== */
.list { flex: 1; overflow-y: auto; padding: 4px 14px 14px; }
.list__title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin: 8px 4px; }
.debug-panel { margin: 0 0 10px; padding: 10px 12px; background: rgba(76,194,255,.08); border: 1px solid rgba(76,194,255,.22); border-radius: var(--radius-sm); color: var(--text-dim); font-size: 12px; line-height: 1.35; }

/* Map sidebar empty state (All buses / no selection) */
.map-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 14px 4px 6px; }
.map-empty__icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: var(--bg-elev-2); color: var(--text-dim); margin-bottom: 2px; }
.map-empty__title { font-size: 15px; letter-spacing: -0.01em; }
.map-empty__text { margin: 0; color: var(--text-dim); font-size: 12.5px; line-height: 1.45; max-width: 44ch; }
.map-empty__actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.map-empty-cta {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: border-color .15s, transform .12s;
}
.map-empty-cta:hover { border-color: var(--accent); transform: translateY(-1px); }
.map-empty-cta:active { transform: translateY(0) scale(0.98); }
.map-empty-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.map-empty-cta--primary { background: var(--accent); color: #fff; border-color: transparent; }
.map-empty-cta--primary:hover { filter: brightness(1.08); }
.list__items { display: flex; flex-direction: column; gap: 6px; }
.vehicle-item { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg-elev-2); color: var(--text); text-align: left; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: transform .15s, border-color .15s; width: 100%; font: inherit; }
.vehicle-item:hover { transform: translateX(2px); border-color: var(--accent); }
.vehicle-item--serving-stop, .arrival-list-item--clickable { border-color: rgba(225,29,29,.62); box-shadow: 0 0 0 1px rgba(225,29,29,.16) inset; }
.vehicle-item--serving-stop .vehicle-item__route, .arrival-list-item--clickable .vehicle-item__route { background: linear-gradient(135deg, #e11d1d, #ff6b6b); color: #fff; }

/* Scheduled (no live bus) variant */
.vehicle-item--scheduled { border-color: var(--border); opacity: .82; }
.vehicle-item--scheduled .vehicle-item__route { background: linear-gradient(135deg, #6b7280, #9ca3af); color: #fff; }
.status-scheduled { color: var(--text-dim); font-size: .82rem; padding: 3px 8px; background: var(--bg-elev-3); border-radius: var(--radius); }

.vehicle-item__route { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #001520; font-weight: 700; text-align: center; padding: 6px 0; border-radius: 8px; font-size: 13px; }
.vehicle-item__dest { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vehicle-item__sub { font-size: 11px; color: var(--text-dim); }
.vehicle-item__status { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.vehicle-item__flag { display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 999px; border: 1px solid rgba(245,184,0,.30); background: rgba(245,184,0,.13); color: var(--early); font-size: 10px; font-weight: 600; white-space: nowrap; }
.status-ontime { background: rgba(46,204,113,0.15); color: var(--ontime); }
.status-late { background: rgba(255,92,92,0.15); color: var(--late); }
.status-early { background: rgba(245,184,0,0.15); color: var(--early); }
.status-stale { background: rgba(139,150,166,0.16); color: var(--text-dim); }
.stop-live-map-note { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid rgba(225,29,29,.32); background: rgba(225,29,29,.1); color: #ff8a8a; font-size: 12px; line-height: 1.35; }
.stop-live-map-note--muted { border-color: rgba(76,194,255,.22); background: rgba(76,194,255,.08); color: var(--text-dim); }

.sidebar__footer { display: flex; align-items: center; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.sidebar__footer .accuracy-link { color: var(--text-dim); text-decoration: underline; text-underline-offset: 3px; }
.spacer { flex: 1; }
.status { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); display: inline-block; }
.status--ok { background: var(--ontime); box-shadow: 0 0 8px var(--ontime); }
.status--connecting { background: var(--early); animation: pulse 1.2s infinite; }
.status--error { background: var(--late); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

#last-updated { font-size: 11px; opacity: 0.65; white-space: nowrap; }
#last-updated.disconnected { color: var(--late); opacity: 0.85; }

/* ===== Map ===== */
#mapContainer { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; }

.legend { position: absolute; top: 16px; right: 16px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); font-size: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 5; min-width: 140px; max-height: calc(100% - 32px); overflow-y: auto; }
.legend__row { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot--ontime { background: var(--ontime); }
.dot--late { background: var(--late); }
.dot--early { background: var(--early); }
.dot--stop { background: #ffd166; border-radius: 3px; border: 1px solid #1b1b1b; }
.legend__btn { background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; }
.legend__btn:hover { border-color: var(--accent); }
.legend__ver { font-size: 10px; opacity: 0.55; margin-top: 2px; user-select: none; }

/* Smooth-motion toggle: floating pill at top-center of the map — always
   visible on desktop and mobile (the legend stack can clip on short maps). */
.smooth-toggle {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: var(--accent);
  border: 2px solid rgba(0, 0, 0, 0.35);
  color: #001520;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.smooth-toggle:hover { filter: brightness(1.1); }
.smooth-toggle[aria-pressed="false"] { opacity: 0.85; border-style: dashed; }

.toast { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg-elev); border: 1px solid var(--border); padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 6; }


/* ===== Bus marker ===== */
.bus-marker { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #001520; font-weight: 700; font-size: 11px; border: 2px solid #fff; box-shadow: 0 4px 10px rgba(0,0,0,0.35); cursor: pointer; transition: transform .2s; background: var(--accent); position: relative; }
.bus-marker:hover { transform: scale(1.15); }
.bus-marker--late { background: var(--late); color: #fff; }
.bus-marker--early { background: var(--early); }
.bus-marker--stale { filter: grayscale(.75); opacity: .72; }
.bus-marker--selected { box-shadow: 0 0 0 4px rgba(76,194,255,0.4), 0 4px 10px rgba(0,0,0,0.35); transform: scale(1.2); }

.setup-screen { min-height: 100vh; padding: 42px; display: grid; place-content: center; background: var(--bg); color: var(--text); font-family: inherit; }
.setup-screen code { background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; }

.stop-marker { width: 12px; height: 12px; border-radius: 50%; background: var(--bg-elev); border: 2px solid var(--accent); cursor: pointer; }
.stop-marker:hover { background: var(--accent); }
.selected-stop-marker {
  width: 48px;
  height: 28px;
  border-radius: 7px;
  background: #ffd166;
  border: 2px solid #1b1b1b;
  color: #1b1b1b;
  box-shadow: 0 0 0 5px rgba(255,209,102,.22), 0 8px 20px rgba(0,0,0,.42);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.selected-stop-marker::before { content: "STOP"; }
.selected-stop-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -15px;
  width: 5px;
  height: 15px;
  border-radius: 0 0 3px 3px;
  background: #fff;
  border: 1px solid #1b1b1b;
  transform: translateX(-50%);
  box-shadow: 0 6px 12px rgba(0,0,0,.28);
}

/* Responsive */
@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  #app.app--panel-expanded {
    grid-template-rows: minmax(0, 42vh) minmax(0, 58vh);
    grid-template-rows: minmax(0, 42dvh) minmax(0, 58dvh);
  }
  .sidebar {
    order: 2;
    height: auto;
    max-height: none;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .app--panel-expanded .sidebar { height: 100%; overflow-y: auto; }
  #mapContainer { order: 1; }
  #app:not(.app--panel-expanded) .sidebar__header,
  #app:not(.app--panel-expanded) .nearest-panel,
  #app:not(.app--panel-expanded) .filters,
  #app:not(.app--panel-expanded) .detail,
  #app:not(.app--panel-expanded) .list,
  #app:not(.app--panel-expanded) .sidebar__footer { display: none; }
  .sidebar__header { padding: 12px 12px 8px; gap: 8px; }
  .brand { flex: 1; min-width: 0; }
  .brand > div:last-child { min-width: 0; }
  .brand .front-logo { width: 42px; height: 42px; margin-bottom: 0; border-radius: 12px; font-size: 22px; flex: none; }
  .brand__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand__tag { display: none; }
  .search { padding: 4px 12px 8px; }
  #app:not(.app--panel-expanded) .search { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .search__results {
    position: fixed;
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(58px + env(safe-area-inset-bottom));
    max-height: min(320px, 52dvh);
  }
  .app--panel-expanded .search__results { position: absolute; top: 100%; bottom: auto; }
  .nearest-panel { margin: 4px 12px; }
  .filters { padding: 2px 12px 8px; gap: 6px; overflow-x: auto; }
  .chip { flex: none; }
  .detail { flex: none; margin: 0 10px 10px; padding: 14px; }
  .list { flex: none; overflow: visible; padding: 2px 10px 10px; }
  .sidebar__footer {
    position: static;
    padding: 9px 12px max(9px, env(safe-area-inset-bottom));
    background: var(--bg-elev);
  }
  #last-updated { display: none; }
  .legend { top: 12px; right: 12px; padding: 8px; min-width: 0; }
  .legend__row { display: none; }
  .toast { max-width: calc(100% - 24px); text-align: center; }
}

@media (max-width: 480px) {
  .front-page { place-items: start center; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
  .front-card { padding: 24px 18px; border-radius: 20px; }
  .stop-search-row button { padding: 0 14px; }
  .arrival-card { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; padding: 10px; }
  .prediction-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 11px; }
  .prediction-card__eta { font-size: 24px; }
  .prediction-card__side { min-width: 0; }
  .stop { grid-template-columns: 62px minmax(0, 1fr) auto; gap: 7px; }
  .stop__name { overflow-wrap: anywhere; }
  .vehicle-item { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 8px; padding: 9px; }
}
