/* ════════════════════════════════════════════════════════════════
   DART Train Tracker v2.0 — Premium Dark UI
   ════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Depth layers */
  --bg-base: #060a10;
  --bg-surface: #0d1219;
  --bg-card: #141c27;
  --bg-elevated: #1a2435;
  --bg-hover: #1f2d3d;

  /* Glass */
  --glass-bg: rgba(14, 20, 30, 0.85);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-highlight: rgba(255, 255, 255, 0.1);
  --glass-blur: blur(20px) saturate(180%);

  /* Text */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --text-accent: #58a6ff;

  /* Line colors */
  --line-red: #e74c3c;
  --line-blue: #2196F3;
  --line-green: #4caf50;
  --line-orange: #ff9800;
  --line-silver: #9e9e9e;
  --line-tre: #00897b;
  --line-texrail: #7b1fa2;

  /* Semantic */
  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.15);
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --info: #58a6ff;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 2px 4px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.4), 0 16px 48px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.1);

  /* Spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-12: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Typography */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Sidebar */
  --sidebar-width: 320px;
  --header-height: 52px;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, button { font-family: inherit; font-size: inherit; }

.hidden { display: none !important; }

/* ── Page System ── */
.page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  animation: pageIn 300ms ease;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── App Container ── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ════════════════════ HEADER ════════════════════ */
.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}
.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.logo h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #58a6ff, #a371f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Navigation links (desktop) */
.nav-links {
  display: flex;
  gap: var(--sp-1);
  margin-left: var(--sp-6);
}
.nav-link {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-elevated); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-glow); }

/* Status pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  font-size: 12px;
  color: var(--text-secondary);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-base);
}
.status-dot.live {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
  animation: pulse 2s infinite;
}
.status-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.last-update {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Buttons ── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--glass-highlight); }

.icon-btn-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  transition: color var(--transition-fast);
}
.icon-btn-sm:hover { color: var(--text-primary); }

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
}
.sidebar-toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #4393e6; }
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.3);
}
.btn-danger:hover { background: rgba(248, 81, 73, 0.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ════════════════════ MAIN CONTENT ════════════════════ */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ════════════════════ SIDEBAR ════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--glass-border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  z-index: 50;
  transition: transform var(--transition-base);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

.sidebar-inner { padding: var(--sp-3); }

.sidebar-section {
  margin-bottom: var(--sp-4);
}

.section-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2);
  margin-bottom: var(--sp-2);
}
.section-accent {
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}
.section-header h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  flex: 1;
}

/* ── Line Filters ── */
.line-filters {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.line-filter {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.line-filter:hover { background: var(--bg-card); }
.line-filter input { display: none; }

.line-badge {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.line-badge.red { background: var(--line-red); }
.line-badge.blue { background: var(--line-blue); }
.line-badge.green { background: var(--line-green); }
.line-badge.orange { background: var(--line-orange); }
.line-badge.silver { background: var(--line-silver); }
.line-badge.tre { background: var(--line-tre); }
.line-badge.texrail { background: var(--line-texrail); }

.line-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}
.train-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 18px;
  text-align: right;
}

/* Unchecked state */
.line-filter input:not(:checked) ~ .line-badge { opacity: 0.3; }
.line-filter input:not(:checked) ~ .line-name { color: var(--text-muted); }

/* ── Toggle ── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
}
.toggle-row.compact { padding: 0; }
.toggle-row input { display: none; }
.toggle-track {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg-hover);
  position: relative;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: all var(--transition-fast);
}
.toggle-row input:checked ~ .toggle-track {
  background: var(--accent);
}
.toggle-row input:checked ~ .toggle-track .toggle-thumb {
  left: 18px;
  background: #fff;
}
.toggle-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Train List ── */
.train-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
}
.train-list::-webkit-scrollbar { width: 4px; }
.train-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.train-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-left: 3px solid transparent;
  animation: slideIn 200ms ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.train-item:hover { background: var(--bg-card); }
.train-item[data-line="RED"] { border-left-color: var(--line-red); }
.train-item[data-line="BLUE"] { border-left-color: var(--line-blue); }
.train-item[data-line="GREEN"] { border-left-color: var(--line-green); }
.train-item[data-line="ORANGE"] { border-left-color: var(--line-orange); }
.train-item[data-line="SILVER"] { border-left-color: var(--line-silver); }
.train-item[data-line="TRE"] { border-left-color: var(--line-tre); }

.train-item-info {
  flex: 1;
  min-width: 0;
}
.train-item-dest {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.train-item-sub {
  font-size: 11px;
  color: var(--text-muted);
}
.train-item-speed {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Delay badges */
.delay-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  white-space: nowrap;
}
.delay-badge.on-time { background: rgba(63,185,80,0.15); color: var(--success); }
.delay-badge.delayed { background: rgba(248,81,73,0.15); color: var(--danger); }
.delay-badge.ahead { background: rgba(88,166,255,0.15); color: var(--info); }

/* ── Stats ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  padding: 0 var(--sp-2);
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  text-align: center;
}
.stat-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Delay Summary ── */
.delay-summary { padding: 0 var(--sp-2); }
.delay-stat-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) 0;
}
.delay-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.delay-indicator.ontime { background: var(--success); }
.delay-indicator.delayed { background: var(--danger); }
.delay-indicator.ahead { background: var(--info); }
.delay-stat-label { flex: 1; font-size: 13px; color: var(--text-secondary); }
.delay-stat-value { font-family: var(--font-mono); font-size: 13px; }

.delay-details {
  margin-top: var(--sp-2);
  padding: 0 var(--sp-2);
}
.delay-detail-item {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 0;
}

/* ════════════════════ MAP ════════════════════ */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#map {
  width: 100%;
  height: 100%;
  background: var(--bg-base);
  position: relative;
  z-index: 0; /* Create stacking context so Leaflet panes stay inside */
}

/* Leaflet overrides */
.leaflet-control-zoom { border: none !important; }
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--glass-border) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-elevated) !important; }

.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  backdrop-filter: var(--glass-blur);
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { margin: var(--sp-3) !important; font-size: 13px; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* Leaflet divIcon override — no default bg/border, keep pointer events */
.dart-icon {
  background: none !important;
  border: none !important;
  pointer-events: auto !important;
}

/* ── Map Controls ── */
.map-controls {
  position: absolute;
  bottom: var(--sp-4);
  right: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 40;
}
.map-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.map-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* ════════════════════ TRAIN DETAIL PANEL ════════════════════ */
.detail-panel {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 320px;
  max-height: calc(100% - var(--sp-8));
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-top: 1px solid var(--glass-highlight);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 45;
  animation: panelSlideIn 250ms ease;
}
@keyframes panelSlideIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
.detail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--glass-border);
}
.detail-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
}
.detail-panel-body {
  padding: var(--sp-3) var(--sp-4);
  overflow-y: auto;
  max-height: 500px;
  font-size: 13px;
}
.detail-panel-body::-webkit-scrollbar { width: 4px; }
.detail-panel-body::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-1) 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.detail-label { color: var(--text-muted); font-size: 12px; }
.detail-value { font-family: var(--font-mono); font-size: 12px; }

.stop-list {
  margin-top: var(--sp-3);
}
.stop-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 0;
  font-size: 12px;
}
.stop-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  flex-shrink: 0;
}
.stop-item.current .stop-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.stop-item.passed { opacity: 0.4; }
.stop-name { flex: 1; }
.stop-time { font-family: var(--font-mono); color: var(--text-muted); }

/* ════════════════════ STATION DETAIL PANEL ════════════════════ */
.station-panel {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 360px;
  max-height: calc(100% - var(--sp-8));
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-top: 1px solid var(--glass-highlight);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 46;
  animation: panelSlideIn 250ms ease;
}
.station-panel-header {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.station-panel-title h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--sp-1);
}
.station-panel-lines {
  display: flex;
  gap: var(--sp-1);
  margin-top: var(--sp-1);
}
.station-panel-body {
  padding: var(--sp-4);
  overflow-y: auto;
  max-height: 500px;
  font-size: 13px;
}
.station-panel-body::-webkit-scrollbar { width: 4px; }
.station-panel-body::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.station-facility {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
}

.station-departures-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}
.station-departure-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.station-departure-line {
  width: 4px;
  height: 24px;
  border-radius: 2px;
}
.station-departure-info { flex: 1; min-width: 0; }
.station-departure-dest {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.station-departure-dir { font-size: 11px; color: var(--text-muted); }
.station-departure-time {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  text-align: right;
}
.station-departure-min {
  font-size: 10px;
  color: var(--text-muted);
}

/* ════════════════════ ARRIVAL BOARDS ════════════════════ */
.arrival-boards {
  position: absolute;
  bottom: var(--sp-4);
  left: var(--sp-4);
  display: flex;
  gap: var(--sp-3);
  z-index: 40;
  max-width: calc(100% - var(--sp-8));
  overflow-x: auto;
  padding-bottom: var(--sp-1);
}
.arrival-boards::-webkit-scrollbar { height: 4px; }
.arrival-boards::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.arrival-board {
  width: 260px;
  min-width: 260px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: boardIn 300ms ease;
}
@keyframes boardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.arrival-board-header {
  padding: var(--sp-2) var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  position: relative;
  overflow: hidden;
}
.arrival-board-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}
.arrival-board-header .board-station-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.arrival-board-header .board-speaker {
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  flex-shrink: 0;
}
.arrival-board-header .board-speaker:hover { color: var(--text-primary); }
.arrival-board-header .board-speaker.active { color: var(--accent); }

.arrival-board-body {
  padding: var(--sp-1) var(--sp-3) var(--sp-2);
}
.arrival-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.arrival-row:last-child { border-bottom: none; }
.arrival-line-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.arrival-dest {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}
.arrival-time {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.arrival-time.arriving {
  color: var(--success);
  font-weight: 600;
  animation: pulse 1.5s infinite;
}
.arrival-row.now { background: rgba(63,185,80,0.08); border-radius: var(--radius-sm); }

.no-arrivals {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: var(--sp-2) 0;
}

/* ════════════════════ SERVICE ALERT BANNER ════════════════════ */
.alert-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  background: rgba(210, 153, 34, 0.1);
  border-bottom: 1px solid rgba(210, 153, 34, 0.2);
  font-size: 13px;
  color: var(--warning);
  cursor: pointer;
  flex-shrink: 0;
}
.alert-banner:hover { background: rgba(210, 153, 34, 0.15); }
.alert-banner-icon { flex-shrink: 0; }
.alert-banner-text { flex: 1; }
.alert-banner-dismiss {
  background: none;
  border: none;
  color: var(--warning);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  opacity: 0.6;
}
.alert-banner-dismiss:hover { opacity: 1; }

/* ════════════════════ TOAST ════════════════════ */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--sp-3));
  right: var(--sp-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.toast {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: toastIn 250ms ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ════════════════════ SHORTCUTS OVERLAY ════════════════════ */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.shortcuts-panel {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}
.shortcuts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-4);
}
.shortcuts-header h3 { font-size: 16px; font-weight: 600; }
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.shortcut-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 13px;
  color: var(--text-secondary);
}
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
}

/* ════════════════════ SETTINGS PAGE ════════════════════ */
.settings-container {
  height: 100%;
  overflow-y: auto;
  background: var(--bg-base);
}
.settings-container::-webkit-scrollbar { width: 8px; }
.settings-container::-webkit-scrollbar-track { background: transparent; }
.settings-container::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }

.settings-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--glass-border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.settings-header h1 {
  font-size: 18px;
  font-weight: 600;
}
.back-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition-fast);
}
.back-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.settings-body {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-top: 1px solid var(--glass-highlight);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}
.settings-card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  color: var(--text-primary);
}
.settings-card-header h2 { font-size: 15px; font-weight: 600; }
.settings-card-header svg { color: var(--accent); flex-shrink: 0; }

.settings-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-4);
  line-height: 1.6;
}

.settings-subsection {
  margin-top: var(--sp-4);
}
.settings-subsection h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  gap: var(--sp-4);
}
.setting-info { flex: 1; }
.setting-info label {
  display: block;
  font-size: 13px;
  font-weight: 500;
}
.setting-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Form Elements ── */
.input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color var(--transition-fast);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input.mono { font-family: var(--font-mono); font-size: 12px; }

select.input {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.range-input {
  width: 120px;
  accent-color: var(--accent);
}

.form-group {
  margin-top: var(--sp-3);
}
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}
.form-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.status-msg {
  font-size: 12px;
  margin-top: var(--sp-2);
  min-height: 18px;
}
.status-msg.success { color: var(--success); }
.status-msg.error { color: var(--danger); }

/* Tracked stations */
.tracked-stations-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.tracked-station-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
}
.tracked-station-name { font-size: 13px; }
.tracked-station-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.tracked-station-remove:hover { color: var(--danger); }

.station-search-wrap { position: relative; }
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}
.search-results.open { display: block; }
.search-result-item {
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.search-result-item:hover { background: var(--bg-hover); }

/* GTFS info */
.gtfs-info { margin-bottom: var(--sp-3); }
.gtfs-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-1) 0;
  font-size: 13px;
}
.gtfs-label { color: var(--text-secondary); }
.gtfs-value { font-family: var(--font-mono); font-size: 12px; }

/* ════════════════════ TRIP PLANNER PAGE ════════════════════ */
.planner-container {
  height: 100%;
  overflow-y: auto;
  background: var(--bg-base);
}

.planner-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--glass-border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.planner-header h1 { font-size: 18px; font-weight: 600; }

.planner-body {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-6);
}

.planner-form {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}
.planner-field {
  margin-bottom: var(--sp-3);
  position: relative;
}
.planner-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.planner-swap {
  display: flex;
  justify-content: center;
  margin: var(--sp-1) 0;
}
.planner-swap button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.planner-swap button:hover { background: var(--bg-hover); color: var(--text-primary); }

.planner-results {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.planner-no-results {
  text-align: center;
  padding: var(--sp-8);
  color: var(--text-muted);
  font-size: 14px;
}

.journey-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: boardIn 300ms ease;
}
.journey-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.journey-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-glow);
  color: var(--accent);
}
.journey-type.transfer { background: rgba(210,153,34,0.15); color: var(--warning); }
.journey-duration {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}
.journey-times {
  font-family: var(--font-mono);
  font-size: 14px;
}

.journey-legs {
  padding: var(--sp-3) var(--sp-4);
}
.journey-leg {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}
.journey-leg-timeline {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 24px;
  flex-shrink: 0;
}
.journey-leg-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid;
  flex-shrink: 0;
}
.journey-leg-line {
  width: 3px;
  flex: 1;
  border-radius: 2px;
  min-height: 30px;
}
.journey-leg-info { flex: 1; }
.journey-leg-from, .journey-leg-to {
  font-size: 13px;
  font-weight: 500;
}
.journey-leg-details {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0;
}
.journey-leg-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.journey-transfer {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-size: 12px;
  color: var(--warning);
}

/* ════════════════════ TIMETABLE PAGE ════════════════════ */
.timetable-container {
  height: 100%;
  overflow-y: auto;
  background: var(--bg-base);
}
.timetable-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--glass-border);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.timetable-header h1 { font-size: 18px; font-weight: 600; }

.timetable-body {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--sp-6);
}
.timetable-controls {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: flex-end;
}
.timetable-controls .planner-field { margin-bottom: 0; flex: 1; min-width: 200px; }

.day-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 2px;
}
.day-tab {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.day-tab:hover { color: var(--text-primary); }
.day-tab.active {
  background: var(--accent);
  color: #fff;
}

.timetable-results {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.timetable-group {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.timetable-group-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--glass-border);
  position: relative;
}
.timetable-group-header::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}
.timetable-group-header h3 {
  font-size: 14px;
  font-weight: 600;
}
.timetable-group-dir {
  font-size: 12px;
  color: var(--text-muted);
}

.timetable-times {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--sp-3) var(--sp-4);
}
.timetable-time {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.timetable-time:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.timetable-time.past { opacity: 0.3; }

/* ════════════════════ BOTTOM NAV (MOBILE) ════════════════════ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface);
  border-top: 1px solid var(--glass-border);
  z-index: 100;
  padding: 0 var(--sp-4);
  justify-content: space-around;
  align-items: center;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-1);
  color: var(--text-muted);
  font-size: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition-fast);
}
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item:hover { color: var(--text-primary); text-decoration: none; }

/* ════════════════════ PLACEHOLDER ════════════════════ */
.placeholder-text {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: var(--sp-4);
}

/* ════════════════════ RESPONSIVE ════════════════════ */
@media (max-width: 1024px) {
  .sidebar-toggle { display: flex; }
  .nav-links { display: none; }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.open {
    display: block;
  }

  .arrival-boards {
    left: var(--sp-2);
    right: var(--sp-2);
    bottom: var(--sp-2);
  }
  .arrival-board {
    width: 220px;
    min-width: 220px;
  }

  .detail-panel, .station-panel {
    width: calc(100% - var(--sp-4));
    right: var(--sp-2);
    top: var(--sp-2);
  }
}

@media (max-width: 768px) {
  .bottom-nav { display: flex; }
  .header .nav-links { display: none; }

  .main-content { padding-bottom: 56px; }

  .arrival-boards {
    flex-direction: column;
    bottom: 62px;
    left: var(--sp-2);
    right: var(--sp-2);
    max-height: 200px;
    overflow-y: auto;
  }
  .arrival-board {
    width: 100%;
    min-width: unset;
  }

  .settings-body, .planner-body, .timetable-body {
    padding: var(--sp-4);
  }

  .detail-panel, .station-panel {
    width: calc(100% - var(--sp-4));
    right: var(--sp-2);
    left: var(--sp-2);
  }
}

/* ════════════════════ UTILITY ════════════════════ */
.line-color-red { color: var(--line-red); }
.line-color-blue { color: var(--line-blue); }
.line-color-green { color: var(--line-green); }
.line-color-orange { color: var(--line-orange); }
.line-color-silver { color: var(--line-silver); }
.line-color-tre { color: var(--line-tre); }
.line-color-texrail { color: var(--line-texrail); }

.line-bg-red { background: var(--line-red); }
.line-bg-blue { background: var(--line-blue); }
.line-bg-green { background: var(--line-green); }
.line-bg-orange { background: var(--line-orange); }
.line-bg-silver { background: var(--line-silver); }
.line-bg-tre { background: var(--line-tre); }
.line-bg-texrail { background: var(--line-texrail); }

.line-border-red { border-color: var(--line-red); }
.line-border-blue { border-color: var(--line-blue); }
.line-border-green { border-color: var(--line-green); }
.line-border-orange { border-color: var(--line-orange); }
.line-border-silver { border-color: var(--line-silver); }
.line-border-tre { border-color: var(--line-tre); }
.line-border-texrail { border-color: var(--line-texrail); }
