/* ── Variables & Reset ───────────────────────────────────────── */
:root {
  --accent:        #ff3434;
  --accent-dark:   #702305;
  --accent-bg:     #e6f7ef;
  --sidebar-width: 400px;
  --gap:           12px;
  --header-h:      40px;
  --nav-h:         48px;
  --bottom-nav-h:  62px;
  --radius:        8px;
  --shadow:        0 2px 8px rgba(0,0,0,0.10);
  --font:         'Segoe UI', Arial, sans-serif;
}

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

body, html {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  background: #f0f4f8;
  color: #1a1a2e;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,100,40,0.25);
  position: relative;
  z-index: 200;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ── Top Navigation (desktop) ───────────────────────────────── */
.top-tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e0e8e4;
  padding: 0 8px;
  gap: 2px;
  position: sticky;
  top: 0;
  z-index: 150;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.top-tabs .tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  height: var(--nav-h);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #555;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
}

.top-tabs .tab svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.18s;
}

.top-tabs .tab:hover           { color: var(--accent); background: var(--accent-bg); }
.top-tabs .tab:hover svg       { opacity: 1; }
.top-tabs .tab.active          { color: var(--accent-dark); font-weight: 700; border-bottom-color: var(--accent); }
.top-tabs .tab.active svg      { opacity: 1; }

/* ── Bottom nav placeholder (unused on desktop) ─────────────── */
.bottom-nav { display: none; }
/* top-tabs stays in flow on desktop */

/* ── Drawer toggle button (hidden on desktop) ───────────────── */
.drawer-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s;
}
.drawer-toggle-btn svg { width: 22px; height: 22px; }
.drawer-toggle-btn:hover { background: rgba(255,255,255,0.3); }

/* ── Drawer overlay backdrop (used on mobile only) ───────────── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.42);
  z-index: 499;
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}

/* ── Drawer close button (added by JS) ───────────────────────── */
.drawer-close-btn {
  display: none;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}
.drawer-close-btn svg { width: 18px; height: 18px; }
.drawer-close-btn:hover { color: var(--accent-dark); }

/* ── Main ───────────────────────────────────────────────────── */
main {
  display: block;
  height: calc(100% - var(--header-h) - var(--nav-h));
  overflow-y: auto;
  padding: 14px;
}

/* ── Section cards ───────────────────────────────────────────── */
section > h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #555;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Split layout ────────────────────────────────────────────── */
/* Panels live in <body> (moved by JS), so split-layout only contains map-wrap */
.split-layout { display: block; }

/* ── Left panel ─────────────────────────────────────────────── */
/* Desktop: fixed right sidebar, hidden until panel-active is added by JS */
.left-panel {
  position: fixed;
  top: calc(var(--header-h) + var(--nav-h));
  right: 0;
  height: calc(100vh - var(--header-h) - var(--nav-h));
  width: var(--sidebar-width);
  z-index: 100;
  background: #fff;
  overflow-y: auto;
  padding: 12px;
  box-shadow: -2px 0 10px rgba(0,0,0,0.09);
  border-left: 1px solid #e8edf2;
  border-radius: var(--radius) 0 0 var(--radius);
  display: none;
}

.left-panel.panel-active { display: block; }

.left-panel h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}

/* ── Map canvas ─────────────────────────────────────────────── */
/* Offset map to the left of the fixed panel */
.map-wrap { margin-right: calc(var(--sidebar-width) + var(--gap)); }

#map-live, #map-stop, #map-route-by {
  width: 100%;
  height: 680px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Search inputs ───────────────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #dde3e9;
  border-radius: 6px;
  font-size: 13px;
  background: #f9fbfd;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,84,0.15);
  background: #fff;
}

.stop-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.stop-search-row .search-input {
  flex: 1 1 auto;
}

.stop-geolocate-btn {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid #dde3e9;
  background: #fff;
  color: #444;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.stop-geolocate-btn:hover {
  background: #f0faf4;
  color: var(--accent-dark);
  border-color: var(--accent);
}

.stop-geolocate-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* ── Tables ─────────────────────────────────────────────────── */
#live-table, #stops-table, #stop-bus-table,
#route-by-bus-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#live-table th,           #live-table td,
#stops-table th,          #stops-table td,
#stop-bus-table th,       #stop-bus-table td,
#route-by-bus-table th,   #route-by-bus-table td,
#live-left table th,      #live-left table td {
  padding: 7px 8px;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
}

#live-table thead th, #stops-table thead th,
#stop-bus-table thead th, #route-by-bus-table thead th,
#live-left table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #999;
  font-weight: 600;
  border-bottom: 2px solid #eee;
  background: #fafafa;
}

#live-table tbody tr:hover,
#stops-table tbody tr:hover,     #stop-bus-table tbody tr:hover,
#route-by-bus-table tbody tr:hover,
#live-left table tbody tr:hover  { background: #f0faf4; cursor: pointer; }

#stops-table tbody tr.selected   { background: #daf2e7; font-weight: 600; }

/* ── Live controls ───────────────────────────────────────────── */
.live-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  margin-right: calc(var(--sidebar-width) + var(--gap));
  flex-wrap: wrap;
}

.live-controls input {
  flex: 1 1 200px;
  padding: 8px 12px;
  border: 1px solid #dde3e9;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  font-family: var(--font);
}
.live-controls input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,84,0.15);
}

.live-controls button,
.controls-row button {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid #dde3e9;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #444;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: var(--font);
}
.live-controls button:hover,
.controls-row button:hover {
  background: var(--accent-bg);
  color: var(--accent-dark);
  border-color: var(--accent);
}

.live-geolocate-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.live-geolocate-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* ── Legacy helpers ──────────────────────────────────────────── */
#live-map-wrap { height: 100%; }
#stop-map-wrap { height: 100%; }
#live-section  { grid-column: 1 / -1; }

/* ── Stop section ────────────────────────────────────────────── */
#stop-section { width: 100%; box-sizing: border-box; }
#stop-left    { flex: 0 0 360px; }

/* ── Stop status boxes ───────────────────────────────────────── */
#stop-status { max-height: 220px; overflow: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; margin-top: 8px; margin-right: calc(var(--sidebar-width) + var(--gap)); }
.stop-status-box, .stop-status-box * { box-sizing: border-box; }
.stop-status-box {
  width: 150px; min-height: 60px; background: #fff; border: 1px solid #ddd;
  border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.stop-status-box .box-route { font-weight: 700; font-size: 1rem; color: var(--accent-dark); }
.stop-status-box .box-name  { font-size: 0.9rem; color: #555; }
.stop-status-box .box-times { font-size: 0.85rem; color: #222; }

/* ── Stop ETA bottom bar ─────────────────────────────────────── */
/* Fixed strip showing next arrivals; sits above the mobile nav bar.
   Controlled by .show class added/removed by JS.                   */
.stop-eta-bar {
  display: none;           /* flex when .show is present */
  position: fixed;
  bottom: 0;               /* overridden to var(--bottom-nav-h) on mobile */
  left: 0;
  right: calc(var(--sidebar-width) + var(--gap));
  min-height: 62px;
  z-index: 148;
  background: rgba(12,18,28,0.95);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: 0 -3px 18px rgba(0,0,0,0.4);
  border-top: 1px solid rgba(255,255,255,0.12);
  scrollbar-width: none;
}
.stop-eta-bar::-webkit-scrollbar { display: none; }
.stop-eta-bar.show { display: flex; }

.stop-eta-bar-label {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.7);
  padding-right: 10px;
  border-right: 1px solid rgba(255,255,255,0.2);
  margin-right: 4px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stop-eta-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 22px;
  padding: 7px 14px;
  cursor: default;
  white-space: nowrap;
  transition: background 0.15s;
}
.stop-eta-chip:hover { background: rgba(255,255,255,0.18); }
.stop-eta-chip .chip-route { font-weight: 800; color: var(--accent); font-size: 15px; }
.stop-eta-chip .chip-min   { font-size: 15px; color: #e2f7ee; font-weight: 600; }
.stop-eta-chip .chip-due   { font-size: 14px; color: #f9c74f; font-weight: 700; }

/* ── Leaflet icon overflow (allow arrow SVGs to extend beyond bubble) ── */
.leaflet-div-icon {
  background: none !important;
  border: none !important;
  overflow: visible !important;
}

/* ── Stop info left-side tab (mobile only) ────────────────── */
.stop-info-tab {
  display: none;
  position: fixed;
  left: 0;
  top: calc(48px + (100vh - 48px - var(--bottom-nav-h)) / 2);
  transform: translateY(-50%);
  z-index: 499;
  background: var(--accent-dark);
  color: #fff;
  border: none;
  border-radius: 0 12px 12px 0;
  padding: 12px 8px 12px 4px;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 2px 2px 12px rgba(0,0,0,0.3);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.stop-info-tab:active { background: var(--accent); }
.stop-info-tab svg { display: block; }
.stop-info-tab span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
body.dark-mode .stop-info-tab {
  background: #2a2a2a;
  box-shadow: 2px 2px 12px rgba(0,0,0,0.5);
}
body.dark-mode .stop-info-tab:active { background: #444; }

/* ── Stop info slide-in panel (mobile) ────────────────── */
.stop-info-slide {
  display: none;
  position: fixed;
  left: 0;
  top: 48px;
  bottom: var(--bottom-nav-h);
  width: min(310px, 84vw);
  z-index: 500;
  background: #fff;
  border-radius: 0 16px 16px 0;
  box-shadow: 4px 0 24px rgba(0,0,0,0.22);
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
}
.stop-info-slide.open {
  display: flex;
  transform: translateX(0);
}
.stop-info-slide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #e8ede9;
}
.stop-info-slide-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stop-info-slide-header button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #888;
  padding: 0 4px;
  line-height: 1;
}
.stop-info-slide-header button:hover { color: #333; }
.stop-info-slide-section {
  padding: 10px 16px;
}
.stop-info-slide-section:empty { display: none; }
.stop-info-routes-label {
  font-size: 11px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.stop-info-route-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.stop-info-route-chip {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.stop-info-eta-label {
  font-size: 11px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.stop-info-eta-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: #f5f8f6;
  border-radius: 10px;
  border: 1px solid #e8ede9;
}
.stop-info-eta-item .eta-route {
  font-weight: 800;
  font-size: 16px;
  color: var(--accent-dark);
  min-width: 40px;
}
.stop-info-eta-item .eta-dest {
  flex: 1;
  font-size: 12px;
  color: #666;
  margin: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stop-info-eta-item .eta-time {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  text-align: right;
}
.stop-info-eta-item .eta-min {
  font-size: 12px;
  opacity: 0.6;
}
.stop-info-eta-item .eta-due {
  font-size: 15px;
  font-weight: 700;
  color: #e67e22;
}
.stop-info-no-data {
  font-size: 13px;
  color: #999;
  text-align: center;
  padding: 20px 0;
}
body.dark-mode .stop-info-slide {
  background: #1e1e1e;
  box-shadow: 4px 0 24px rgba(0,0,0,0.55);
}
body.dark-mode .stop-info-slide-header {
  border-bottom-color: #333;
}
body.dark-mode .stop-info-slide-header h3 { color: var(--accent); }
body.dark-mode .stop-info-slide-header button { color: #777; }
body.dark-mode .stop-info-slide-header button:hover { color: #ccc; }
body.dark-mode .stop-info-route-chip {
  background: #2a2a2a;
  color: var(--accent);
}
body.dark-mode .stop-info-eta-item {
  background: #2a2a2a;
  border-color: #3a3a3a;
}
body.dark-mode .stop-info-eta-item .eta-route { color: var(--accent); }
body.dark-mode .stop-info-eta-item .eta-dest { color: #999; }
body.dark-mode .stop-info-eta-item .eta-time { color: #ccc; }
body.dark-mode .stop-info-eta-item .eta-due { color: #f9c74f; }
body.dark-mode .stop-info-no-data { color: #666; }
body.dark-mode .stop-info-routes-label,
body.dark-mode .stop-info-eta-label { color: #666; }

/* ── Stop ETA panel (inside drawer) ───────────────────── */
.stop-eta-panel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: #f5f8f6;
  border-radius: 8px;
  border: 1px solid #e8ede9;
}
.stop-eta-panel-item .eta-route {
  font-weight: 800;
  font-size: 15px;
  color: var(--accent-dark);
  min-width: 36px;
}
.stop-eta-panel-item .eta-time {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}
.stop-eta-panel-item .eta-due {
  font-size: 14px;
  font-weight: 700;
  color: #e67e22;
}
body.dark-mode .stop-eta-panel-item {
  background: #2a2a2a;
  border-color: #3a3a3a;
}
body.dark-mode .stop-eta-panel-item .eta-route { color: var(--accent); }
body.dark-mode .stop-eta-panel-item .eta-time { color: #ccc; }
body.dark-mode .stop-eta-panel-item .eta-due  { color: #f9c74f; }

/* Live/Schedule source tags */
.eta-src-live {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  background: #27ae60;
  color: #fff;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}
.eta-src-sched {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  background: #7f8c8d;
  color: #fff;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}
.eta-stops-away {
  display: block;
  font-size: 10px;
  color: #27ae60;
  font-weight: 600;
  margin-top: 1px;
}
body.dark-mode .eta-stops-away { color: #2ecc71; }

/* ── Map arrival popup ───────────────────────────────────────── */
.stop-arrival-icon   { background: transparent; border: none; }
.stop-arrival-popup  { width: 150px; padding: 6px; background: #ffffffcc; border: 1px solid rgba(0,0,0,0.08); border-radius: 6px; }
.stop-arrival-popup .box-route { font-weight: 700; margin-bottom: 4px; }
.stop-arrival-popup .box-times { font-size: 0.85rem; }

/* ── Highlight & Nearby ──────────────────────────────────────── */
.stop-highlight { box-shadow: 0 0 8px 4px rgba(255,200,0,0.9); transform: scale(1.12); }
.nearby-route   { padding: 8px; border: 1px solid #e8f0ea; border-radius: 8px; margin: 6px 0; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.nearby-route .title { font-weight: 600; color: var(--accent-dark); }

/* ── By-route list ───────────────────────────────────────────── */
#route-by-list { overflow-y: auto; max-height: 380px; }
.route-by-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  border-bottom: 1px solid #f0f0f0; transition: background 0.14s;
}
.route-by-item:hover   { background: #f0faf4; }
.route-by-item.selected { background: #daf2e7; font-weight: 600; }
.rb-short { flex: 0 0 44px; font-weight: 700; font-size: 14px; color: #c0392b; }
.rb-long  { flex: 1; font-size: 12px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Sub-panel vehicle wraps ─────────────────────────────────── */
#live-buses-wrap, #route-by-vehicles-wrap {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid #f0f0f0;
}

/* ── Status colors ───────────────────────────────────────────── */
.status-0 { color: gray; }
.status-1 { color: orange; }
.status-2 { color: var(--accent); }
.small-note { font-size: 12px; color: #666; }

#live-status { margin-top: 8px; font-size: 0.88rem; color: #777; }

/* ── Timetable tab ───────────────────────────────────────────── */
#timetable-section .split-layout {
  display: flex; gap: 0; height: calc(100vh - 120px);
}
#timetable-section .left-panel { flex: 0 0 280px; }

.tt-stop-list {
  overflow-y: auto; max-height: calc(100vh - 240px);
}
.tt-stop-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  border-bottom: 1px solid #f0f0f0; transition: background 0.14s;
}
.tt-stop-item:hover    { background: #f0faf4; }
.tt-stop-item.selected { background: #daf2e7; font-weight: 600; }
.tt-code { flex: 0 0 44px; font-weight: 700; font-size: 13px; color: #2c3e50; }
.tt-name { flex: 1; font-size: 12px; color: #555; word-break: break-word; line-height: 1.4; }

.tt-results {
  flex: 1; padding: 16px 20px; overflow-y: auto;
  background: #fff; border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.tt-header {
  font-size: 16px; font-weight: 700; color: #2c3e50;
  margin-bottom: 14px; padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
}
.tt-empty {
  color: #999; font-size: 14px; text-align: center; padding: 60px 20px;
}

.tt-grid {
  display: flex; flex-direction: column; gap: 16px;
}
.tt-route-card {
  border: 1px solid #e8e8e8; border-radius: 10px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.tt-route-card-header {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #fafafa, #f3f3f3);
  border-bottom: 1px solid #eee;
}
.tt-route-card-header .tt-route-badge {
  margin-top: 2px; flex-shrink: 0;
}
.tt-route-card-header-text {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow: hidden;
}
.tt-route-badge {
  background: #c0392b; color: #fff;
  font-weight: 800; font-size: 14px;
  padding: 3px 10px; border-radius: 6px;
  min-width: 36px; text-align: center;
}
.tt-route-name {
  font-size: 12px; color: #555;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tt-route-headsign {
  font-size: 14px; font-weight: 700; color: #2c3e50;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tt-times-wrap {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 14px;
}
.tt-time-chip {
  font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 6px;
  background: #f0f7f3; color: #2c3e50;
  border: 1px solid #dff0e5;
  white-space: nowrap;
  cursor: default;
}
.tt-time-chip.next {
  background: var(--accent); color: #fff;
  border-color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(39,174,96,0.3);
  animation: tt-pulse 1.5s ease-in-out infinite;
}
@keyframes tt-pulse {
  0%, 100% { box-shadow: 0 1px 4px rgba(39,174,96,0.3); }
  50% { box-shadow: 0 1px 10px rgba(39,174,96,0.6); }
}

/* Direction picker bar */
.tt-direction-bar {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px;
}
.tt-dir-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  border: 2px solid #e0e0e0; background: #fafafa;
  cursor: pointer; font-size: 13px; color: #555;
  transition: all 0.15s;
}
.tt-dir-btn:hover { border-color: var(--accent); background: var(--accent-bg); }
.tt-dir-btn.active {
  border-color: var(--accent); background: var(--accent-bg);
  color: var(--accent-dark); font-weight: 700;
}
.tt-dir-btn .tt-dir-arrow { color: var(--accent); font-weight: 700; }
.tt-dir-btn .tt-dir-label {
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1; min-width: 0;
}

/* Departure chips list */
.tt-departures {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 12px 14px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
}
.tt-eta {
  font-size: 10px; font-weight: 400;
  opacity: 0.85; margin-left: 4px;
}
.tt-time-chip.past {
  opacity: 0.4;
}
.tt-hour-sep {
  width: 100%; height: 0;
  border-top: 1px dashed #e0e0e0;
  margin: 2px 0;
}

/* ── Favourite Stars ─────────────────────────────────────────── */
.fav-star {
  cursor: pointer;
  font-size: 16px;
  color: #ccc;
  transition: color 0.15s, transform 0.15s;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
}
.fav-star:hover { color: #f0c040; transform: scale(1.2); }
.fav-star.active { color: #f0c040; }
.fav-cell { width: 28px; text-align: center; padding: 2px !important; }

/* Stars inside route-by items and timetable items */
.route-by-item .fav-star,
.tt-stop-item .fav-star {
  margin-left: auto;
  padding: 0 4px;
}

/* ── Favourites Tab ──────────────────────────────────────────── */
.favs-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}
.favs-group {
  margin-bottom: 24px;
}
.favs-group-title {
  font-size: 15px; font-weight: 700; color: #2c3e50;
  margin: 0 0 10px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid #eee;
}
.favs-list {
  display: flex; flex-direction: column; gap: 6px;
}
.favs-empty {
  font-size: 13px; color: #999;
  padding: 16px 0;
  text-align: center;
}
.fav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}
.fav-item:hover {
  background: #f8faf9;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.fav-item-badge {
  background: #c0392b; color: #fff;
  font-weight: 800; font-size: 13px;
  padding: 3px 10px; border-radius: 6px;
  min-width: 36px; text-align: center;
  flex-shrink: 0;
}
.fav-item-badge--stop {
  background: #2980b9;
}
.fav-item-name {
  font-size: 13px; color: #555;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1;
}
.fav-item .fav-star {
  margin-left: auto;
}

/* ── Fav Action Bar (By Stop / By Route panels) ──────────────── */
.fav-action-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  margin-bottom: 10px;
  background: #fffbe6;
  border: 1px solid #f0e4a0;
  border-radius: 8px;
}
.fav-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px;
  border: 1.5px solid #e0d080;
  border-radius: 6px;
  background: #fff;
  color: #555;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.fav-action-btn:hover {
  background: #fff8d0;
  border-color: #d4b830;
}
.fav-action-btn.active {
  background: #fff3b0;
  border-color: #d4b830;
  color: #8a6d00;
}
.fav-action-star {
  font-size: 16px;
  color: #f0c040;
  line-height: 1;
}
.fav-action-label {
  font-size: 12px; color: #888;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Dark Mode Toggle Button ─────────────────────────────────── */
.dark-mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s;
  margin-right: 6px;
}
.dark-mode-btn svg { width: 20px; height: 20px; }
.dark-mode-btn:hover { background: rgba(255,255,255,0.3); }

/* ═══════════════════════════════════════════════════════════════
   DARK MODE
   ═══════════════════════════════════════════════════════════════ */
body.dark-mode {
  background: #121418;
  color: #d8dce2;
}

body.dark-mode header {
  background: linear-gradient(135deg, #1a1c22 0%, #2a2c34 100%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

body.dark-mode .top-tabs {
  background: #1a1c22;
  border-bottom-color: #2a2d35;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
body.dark-mode .top-tabs .tab { color: #888; }
body.dark-mode .top-tabs .tab:hover { background: #252830; color: var(--accent); }
body.dark-mode .top-tabs .tab.active { color: #eee; border-bottom-color: var(--accent); }

body.dark-mode .left-panel {
  background: #1e2028;
  border-left-color: #2a2d35;
  box-shadow: -2px 0 10px rgba(0,0,0,0.4);
}
body.dark-mode .left-panel h3 { color: #777; }

body.dark-mode .search-input {
  background: #262830;
  border-color: #3a3d48;
  color: #d8dce2;
}
body.dark-mode .search-input:focus {
  background: #2c2e38;
  border-color: var(--accent);
}

body.dark-mode .live-controls input {
  background: #262830;
  border-color: #3a3d48;
  color: #d8dce2;
}
body.dark-mode .live-controls input:focus {
  background: #2c2e38;
  border-color: var(--accent);
}
body.dark-mode .live-controls button,
body.dark-mode .controls-row button {
  background: #262830;
  border-color: #3a3d48;
  color: #aaa;
}
body.dark-mode .live-controls button:hover,
body.dark-mode .controls-row button:hover {
  background: #2e3040;
  border-color: var(--accent);
  color: #eee;
}
body.dark-mode .live-controls {
  background: #1a1c22;
  border-bottom-color: #2a2d35;
}

/* Tables */
body.dark-mode #live-table th, body.dark-mode #live-table td,
body.dark-mode #stops-table th, body.dark-mode #stops-table td,
body.dark-mode #stop-bus-table th, body.dark-mode #stop-bus-table td,
body.dark-mode #route-by-bus-table th, body.dark-mode #route-by-bus-table td,
body.dark-mode #live-left table th, body.dark-mode #live-left table td {
  border-bottom-color: #2a2d35;
}
body.dark-mode #live-table thead th, body.dark-mode #stops-table thead th,
body.dark-mode #stop-bus-table thead th, body.dark-mode #route-by-bus-table thead th,
body.dark-mode #live-left table thead th {
  background: #22242c;
  color: #777;
  border-bottom-color: #3a3d48;
}
body.dark-mode #live-table tbody tr:hover,
body.dark-mode #stops-table tbody tr:hover,
body.dark-mode #stop-bus-table tbody tr:hover,
body.dark-mode #route-by-bus-table tbody tr:hover,
body.dark-mode #live-left table tbody tr:hover { background: #262830; }
body.dark-mode #stops-table tbody tr.selected { background: #2a3530; }

/* Route-by list */
body.dark-mode .route-by-item { border-bottom-color: #2a2d35; }
body.dark-mode .route-by-item:hover { background: #262830; }
body.dark-mode .route-by-item.selected { background: #2a3530; }
body.dark-mode .rb-long { color: #999; }

/* Stop status boxes */
body.dark-mode .stop-status-box {
  background: #1e2028; border-color: #2a2d35;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
body.dark-mode .stop-status-box .box-name { color: #999; }

/* Timetable */
body.dark-mode .tt-stop-item { border-bottom-color: #2a2d35; }
body.dark-mode .tt-stop-item:hover { background: #262830; }
body.dark-mode .tt-stop-item.selected { background: #2a3530; }
body.dark-mode .tt-code { color: #bbb; }
body.dark-mode .tt-name { color: #999; }

body.dark-mode .tt-results {
  background: #1e2028;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
body.dark-mode .tt-header { color: #ddd; }
body.dark-mode .tt-empty { color: #666; }

body.dark-mode .tt-route-card { border-color: #2a2d35; }
body.dark-mode .tt-route-card-header {
  background: linear-gradient(135deg, #22242c, #282a34);
  border-bottom-color: #2a2d35;
}
body.dark-mode .tt-route-name { color: #999; }
body.dark-mode .tt-route-headsign { color: #ddd; }

body.dark-mode .tt-time-chip {
  background: #262830; color: #ccc;
  border-color: #3a3d48;
}
body.dark-mode .tt-hour-sep {
  border-top-color: #3a3d48;
}
body.dark-mode .tt-dir-btn {
  border-color: #3a3d48; background: #22242c; color: #999;
}
body.dark-mode .tt-dir-btn:hover { border-color: var(--accent); background: #2a2c34; }
body.dark-mode .tt-dir-btn.active { background: #2a3530; color: #ccc; }

/* Favourites */
body.dark-mode .favs-container { color: #d8dce2; }
body.dark-mode .favs-group-title { color: #ccc; border-bottom-color: #2a2d35; }
body.dark-mode .favs-empty { color: #666; }
body.dark-mode .fav-item {
  background: #1e2028; border-color: #2a2d35;
}
body.dark-mode .fav-item:hover {
  background: #262830;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
body.dark-mode .fav-item-name { color: #999; }
body.dark-mode .fav-star { color: #555; }
body.dark-mode .fav-star:hover { color: #f0c040; }
body.dark-mode .fav-star.active { color: #f0c040; }

body.dark-mode .fav-action-bar {
  background: #2a2820; border-color: #3d3820;
}
body.dark-mode .fav-action-btn {
  background: #262830; border-color: #3d3820; color: #bbb;
}
body.dark-mode .fav-action-btn:hover { background: #302e20; border-color: #5a5020; }
body.dark-mode .fav-action-btn.active { background: #35321e; color: #d4b830; }
body.dark-mode .fav-action-label { color: #666; }

/* Misc */
body.dark-mode .small-note { color: #888; }
body.dark-mode #live-status { color: #777; }
body.dark-mode #stop-status { color: #999; }
body.dark-mode section > h2 { color: #888; }

body.dark-mode .drawer-overlay { background: rgba(0,0,0,0.6); }
body.dark-mode .drawer-close-btn { color: #999; border-bottom-color: #2a2d35; }
body.dark-mode .drawer-close-btn:hover { color: var(--accent); }


/* ═══════════════════════════════════════════════════════════════
   MOBILE  (≤ 768 px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Show hamburger, hide on desktop ──────────────────────── */
  .drawer-toggle-btn { display: flex; }
  .drawer-close-btn  { display: flex; }

  /* ── Move top-nav to a fixed bottom bar ───────────────────── */
  .top-tabs {
    position: fixed;
    bottom: 0; left: 0; right: 0; top: auto;
    height: var(--bottom-nav-h);
    padding: 0;
    gap: 0;
    flex-direction: row;
    justify-content: stretch;
    border-bottom: none;
    border-top: 1px solid #e0e8e4;
    box-shadow: 0 -3px 14px rgba(0,0,0,0.10);
    z-index: 1000;
    background: #fff;
  }

  .top-tabs .tab {
    flex: 1;
    height: auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px 10px;
    font-size: 10px;
    font-weight: 500;
    color: #bbb;
    border-bottom: none;
    border-top: 3px solid transparent;
    border-radius: 0;
    margin-bottom: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .top-tabs .tab svg    { width: 22px; height: 22px; opacity: 0.7; }
  .top-tabs .tab:hover  { background: var(--accent-bg); color: var(--accent); border-top-color: transparent; }
  .top-tabs .tab.active { color: var(--accent-dark); font-weight: 700; border-top-color: var(--accent); background: transparent; }
  .top-tabs .tab.active svg { opacity: 1; }

  /* ── Header ───────────────────────────────────────────────── */
  header { height: 48px; padding: 0 12px; }
  header h1 { font-size: 0.98rem; }

  /* ── Main: fills below header, maps flush edge-to-edge ────── */
  main {
    height: calc(100% - 48px);
    padding: 0;
    overflow: hidden;
  }

  /* ── Hide section headings & status bar to maximise map ───── */
  section > h2 { display: none; }
  #live-status  { display: none; }

  /* ── Live controls: thin bar above the map ────────────────── */
  .live-controls {
    flex-wrap: nowrap;
    gap: 6px;
    padding: 6px 8px;
    margin: 0;
    background: #fff;
    border-bottom: 1px solid #eee;
  }
  .live-controls input  { font-size: 13px; padding: 7px 10px; }
  .live-controls button { padding: 7px 10px; font-size: 13px; }
  .live-controls .live-geolocate-btn { width: 36px; height: 36px; padding: 0; }

  /* ── Split layout: panel removed from flow entirely ───────── */
  .split-layout { display: block; }

  /* ── Left panels: slide-in drawer ──────────────────────────── */
  /* Use class selector ONLY — ID selectors have higher specificity and
     would prevent the slide-in rule from overriding the transform. */
  .left-panel {
    /* Override desktop fixed sidebar */
    position: fixed !important;
    top: 48px !important;
    right: 0 !important;
    left: auto !important;
    bottom: var(--bottom-nav-h) !important;
    height: auto !important;
    width: min(320px, 86vw) !important;
    max-height: none !important;
    border-left: none !important;
    border-right: none !important;
    border-radius: 14px 0 0 14px !important;
    box-shadow: -4px 0 28px rgba(0, 0, 0, 0.22) !important;
    z-index: 500 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px !important;
    /* display:block always — transform slides it off-screen instead */
    display: block !important;
    transform: translateX(105%) !important;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  /* Slide in the active panel when drawer is open */
  body.drawer-open .left-panel.panel-active { transform: translateX(0) !important; }

  /* Overlay: covers map area only */
  .drawer-overlay {
    top: 48px;
    bottom: var(--bottom-nav-h);
    z-index: 498;
  }
  body.drawer-open .drawer-overlay { display: block; }

  /* ── Maps: full-bleed edge to edge ──────────────────────────── */
  .map-wrap { margin-left: 0; margin-right: 0; width: 100%; display: block; }

  #map-stop, #map-route-by {
    height: calc(100vh - 48px - var(--bottom-nav-h)) !important;
    min-height: unset !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* Live map is slightly shorter to leave room for search bar */
  #map-live {
    height: calc(100vh - 48px - var(--bottom-nav-h) - 50px) !important;
    min-height: unset !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  /* ── Tables inside drawer ─────────────────────────────────── */
  #live-table th,     #live-table td,
  #stops-table th,    #stops-table td,
  #stop-bus-table th, #stop-bus-table td,
  #route-by-bus-table th, #route-by-bus-table td,
  #live-left table th,    #live-left table td {
    padding: 7px 5px;
    font-size: 12px;
  }

  #route-by-list { max-height: none; }
  #stop-status   { max-height: 160px; margin-right: 0; }
  /* ETA bar rises above the mobile nav bar */
  .stop-eta-bar {
    bottom: var(--bottom-nav-h);
    right: 0;
    padding: 8px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .stop-eta-bar-label {
    font-size: 11px;
    max-width: 100px;
  }
  .stop-eta-chip {
    padding: 6px 10px;
    gap: 6px;
  }
  .stop-eta-chip .chip-route { font-size: 13px; }
  .stop-eta-chip .chip-min   { font-size: 13px; }
  .stop-eta-chip .chip-due   { font-size: 12px; }

  /* ── Dark-mode mobile overrides ─────────────────────────── */
  body.dark-mode .top-tabs {
    background: #1e1e1e;
    border-top-color: #333;
    box-shadow: 0 -3px 14px rgba(0,0,0,0.35);
  }
  body.dark-mode .top-tabs .tab        { color: #888; }
  body.dark-mode .top-tabs .tab:hover  { background: #2a2a2a; color: var(--accent); }
  body.dark-mode .top-tabs .tab.active { color: var(--accent); background: transparent; }

  body.dark-mode .left-panel {
    background: #1e1e1e !important;
    box-shadow: -4px 0 28px rgba(0,0,0,0.55) !important;
  }

  body.dark-mode .live-controls {
    background: #1e1e1e;
    border-bottom-color: #333;
  }

  body.dark-mode .drawer-overlay {
    background: rgba(0,0,0,0.55);
  }
}

/* ═══════════════════════════════════════════════════════════════
   VERY SMALL  (≤ 380 px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .top-tabs .tab     { font-size: 9px; }
  .top-tabs .tab svg { width: 20px; height: 20px; }
  header h1          { font-size: 0.88rem; }
  .left-panel {
    width: min(290px, 90vw) !important;
  }
}
