/* ============================================================
   Arrivo Transit Lab — Redesigned Dashboard
   Theme: Dark, amber-accented — matches Arrivo mobile app
   ============================================================ */

/* --- Design Tokens --- */
:root {
  color-scheme: dark;

  /* Core palette — derived from Arrivo mobile app */
  --amber:    #FFC107;
  --amber-d:  #E5AC00;
  --amber-dd: #3D3000;
  --amber-l:  #FFD54F;
  --amber-ll: #FFF8E1;
  --orange:   #FF9800;
  --blue:     #2196F3;
  --blue-d:   #0D47A1;
  --green:    #4CAF50;
  --red:      #F44336;

  /* Surfaces */
  --bg:       #0A0A08;
  --bg-1:     #111110;
  --bg-2:     #18181A;
  --panel:    #141413;
  --panel-2:  #1C1C1A;
  --panel-3:  #222220;
  --surface:  #1A1A18;

  /* Borders & lines */
  --line:     #2A2A26;
  --line-2:   #353530;
  --line-h:   #40403A;

  /* Text */
  --text:     #F0EDE4;
  --text-2:   #C8C5BA;
  --muted:    #8A877C;
  --faint:    #5A5850;

  /* Vehicle / route colors — matching mobile app exactly */
  --tram:     #FFC107;
  --trolley:  #FF9800;
  --bus:      #2196F3;

  /* Semantic */
  --good:     #66BB6A;
  --good-bg:  rgba(102, 187, 106, 0.08);
  --warn:     #FFB74D;
  --bad:      #EF5350;

  /* Radius */
  --r-sm:     6px;
  --r-md:     10px;
  --r-lg:     14px;
  --r-xl:     20px;
  --r-pill:   999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4), 0 4px 10px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(255,193,7,0.12);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast:   120ms;
  --t-normal: 220ms;
  --t-slow:   400ms;

  /* Fonts */
  --f-display: 'Outfit', system-ui, sans-serif;
  --f-body:    'DM Sans', system-ui, sans-serif;
  --f-mono:    'JetBrains Mono', 'SF Mono', monospace;
}

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

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4, p {
  margin: 0;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--line-h);
}

/* --- Shell Layout --- */
.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 370px 1fr;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  right: -1px;
  width: 1px;
  height: 100%;
  background: linear-gradient(
    180deg,
    rgba(255,193,7,0.15) 0%,
    transparent 15%,
    transparent 85%,
    rgba(255,193,7,0.08) 100%
  );
  pointer-events: none;
}

/* --- Brand --- */
.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,193,7,0.03) 0%, transparent 100%);
  position: relative;
}

.brand-icon-wrap {
  position: relative;
  flex-shrink: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: block;
  border-radius: var(--r-md);
  object-fit: cover;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 1;
}

.brand-glow {
  position: absolute;
  inset: -4px;
  border-radius: var(--r-lg);
  background: radial-gradient(circle, rgba(255,193,7,0.25) 0%, transparent 70%);
  filter: blur(8px);
  animation: glow-pulse 3s ease-in-out infinite;
}

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

h1 {
  font-family: var(--f-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-accent {
  color: var(--amber);
  font-weight: 600;
}

.brand p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.01em;
}

/* --- Eyebrow --- */
.eyebrow {
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* --- Controls / Search --- */
.controls {
  padding: 16px 18px;
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--faint);
  pointer-events: none;
  transition: color var(--t-normal) var(--ease-out);
}

.search-wrap:focus-within .search-icon {
  color: var(--amber);
}

input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 11px 14px 11px 36px;
  outline: none;
  font-size: 13px;
  transition: all var(--t-normal) var(--ease-out);
}

input[type="search"]:focus {
  border-color: var(--amber-d);
  box-shadow: 0 0 0 3px rgba(255,193,7,0.1);
  background: var(--bg);
}

input[type="search"]::placeholder {
  color: var(--faint);
}

input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* --- Filter Buttons --- */
.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.filter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  color: var(--text-2);
  background: var(--panel-2);
  border-radius: var(--r-md);
  padding: 8px 3px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: all var(--t-normal) var(--ease-out);
  user-select: none;
}

.filter:hover {
  border-color: var(--line-h);
  background: var(--panel-3);
  transform: translateY(-1px);
}

.filter.active {
  border-color: var(--amber-d);
  background: var(--amber-dd);
  color: var(--amber-l);
  box-shadow: 0 0 12px rgba(255,193,7,0.06);
}

.filter-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-dot-all  { background: var(--text-2); }
.filter-dot-tram { background: var(--tram); }
.filter-dot-trolley { background: var(--trolley); }
.filter-dot-bus  { background: var(--bus); }
.filter-dot-minibus { background: var(--green); }

.filter.active .filter-dot-all { background: var(--amber-l); }

/* --- Collector Panel --- */
.collector-panel {
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
  display: grid;
  gap: 12px;
  background: var(--bg-1);
}

.panel-mini-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-mini-header h3 {
  font-family: var(--f-display);
  font-size: 13px;
  font-weight: 600;
  margin-top: 3px;
  color: var(--text-2);
}

/* --- State Pill --- */
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 12px 4px 10px;
  font-size: 11px;
  font-family: var(--f-mono);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  transition: all var(--t-slow) var(--ease-out);
}

.state-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  transition: all var(--t-slow) var(--ease-out);
}

.state-pill.running {
  color: var(--good);
  border-color: rgba(102,187,106,0.3);
  background: rgba(102,187,106,0.06);
}

.state-pill.running::before {
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--good); }
  50%      { opacity: 0.5; box-shadow: 0 0 10px var(--good); }
}

/* --- Collector Controls --- */
.collector-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: end;
}

.collector-controls label {
  display: grid;
  gap: 4px;
}

.collector-controls label span {
  color: var(--muted);
  font-size: 10px;
  font-family: var(--f-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.collector-controls input {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 7px 8px;
  font-family: var(--f-mono);
  font-size: 12px;
  transition: border-color var(--t-normal) var(--ease-out);
}

.collector-controls input:focus {
  outline: none;
  border-color: var(--amber-d);
}

.btn-collector {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--t-normal) var(--ease-out);
}

.btn-collector:hover:not(:disabled) {
  border-color: var(--line-h);
  background: var(--panel-3);
  transform: translateY(-1px);
}

.btn-collector:active:not(:disabled) {
  transform: translateY(0);
}

.btn-collector:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-start:hover:not(:disabled) {
  border-color: rgba(102,187,106,0.4);
  color: var(--good);
}

.btn-stop:hover:not(:disabled) {
  border-color: rgba(239,83,80,0.4);
  color: var(--bad);
}

/* --- Stat Cards --- */
.collector-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.collector-stats div,
.history-summary p {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px;
  background: var(--bg);
}

.history-summary p {
  display: flex;
  flex-direction: column;
  min-height: 64px;
}

.collector-stats strong,
.collector-stats span,
.history-summary span,
.history-summary strong {
  display: block;
}

.collector-stats strong {
  font-family: var(--f-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.history-summary strong {
  font-family: var(--f-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-top: auto;
}

.collector-stats span,
.history-summary span {
  color: var(--muted);
  font-size: 10px;
  font-family: var(--f-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-height: 24px;
}

.collector-stats span {
  margin-top: 2px;
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.summary-card-highlight {
  border-color: rgba(255,193,7,0.2) !important;
  background: rgba(255,193,7,0.04) !important;
}

.summary-card-highlight strong {
  color: var(--amber-l);
}

/* --- Station List --- */
.station-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px;
}

.station-group + .station-group {
  margin-top: 6px;
}

.station-group-header {
  position: sticky;
  top: -8px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 7px 12px 6px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  color: var(--text-2);
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}

.station-group-header::before {
  content: '';
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.station-group-header span {
  flex: 1;
}

.station-group-header strong {
  color: var(--muted);
  font-size: 10px;
}

.station-empty {
  padding: 24px 12px;
  color: var(--muted);
  text-align: center;
}

.station-row {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  padding: 11px 14px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-normal) var(--ease-out);
  position: relative;
}

.station-row::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  border-radius: var(--r-pill);
  background: var(--accent, var(--amber));
  transition: height var(--t-normal) var(--ease-spring);
}

.station-row:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.station-row.active {
  background: color-mix(in srgb, var(--accent, var(--amber)), transparent 90%);
  border-color: color-mix(in srgb, var(--accent, var(--amber)), transparent 72%);
}

.station-row.active::before {
  height: 20px;
}

.station-row strong {
  display: block;
  font-family: var(--f-display);
  font-size: 13px;
  font-weight: 600;
}

.station-row span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--f-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

/* --- Workspace --- */
.workspace {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* --- Topbar --- */
.topbar {
  min-height: 82px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  gap: 20px;
  background: var(--bg-1);
  position: relative;
}

.topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--amber-d) 0%, transparent 40%);
  opacity: 0.3;
}

#stationTitle {
  font-family: var(--f-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 4px;
  --title-glow-x: 88%;
  --title-base: linear-gradient(135deg, var(--text) 60%, var(--amber-l) 100%);
  background:
    radial-gradient(circle at var(--title-glow-x) 52%, var(--amber-l) 0%, var(--text) 23%, transparent 38%),
    var(--title-base);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  cursor: default;
  transition: filter var(--t-normal) var(--ease-out);
}

#stationTitle:hover,
#stationTitle.glow-persisted {
  --title-base: linear-gradient(135deg, var(--text), var(--text));
  filter: drop-shadow(0 0 10px rgba(255,193,7,0.08));
}

/* --- Status Strip --- */
.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 8px;
}

.status-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 14px;
  background: var(--panel);
  transition: all var(--t-normal) var(--ease-out);
}

.status-card:hover {
  border-color: var(--line-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.status-card span {
  display: block;
  font-family: var(--f-mono);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.status-card small {
  display: block;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* --- Content Grid --- */
.content-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 1.15fr) minmax(380px, 0.85fr);
  overflow: hidden;
}

/* --- Map --- */
#map {
  height: calc(100vh - 82px);
  min-height: 0;
  background: var(--bg);
}

/* Leaflet dark overrides */
.leaflet-control-zoom a {
  background: var(--panel-2) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
  border-radius: var(--r-sm) !important;
  transition: all var(--t-fast) var(--ease-out);
}

.leaflet-control-zoom a:hover {
  background: var(--panel-3) !important;
  color: var(--amber) !important;
}

.leaflet-control-zoom {
  border: none !important;
  border-radius: var(--r-md) !important;
  overflow: hidden;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-attribution {
  background: rgba(10,10,8,0.85) !important;
  color: var(--faint) !important;
  font-size: 10px !important;
  backdrop-filter: blur(8px);
}

.leaflet-control-attribution a {
  color: var(--muted) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--panel-2) !important;
  color: var(--text) !important;
  border-radius: var(--r-md) !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--line);
}

.leaflet-popup-tip {
  background: var(--panel-2) !important;
}

.leaflet-tooltip {
  background: var(--panel-3) !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--r-sm) !important;
  box-shadow: var(--shadow-md) !important;
  font-family: var(--f-body);
  font-size: 12px;
  padding: 6px 10px !important;
}

.leaflet-tooltip-top::before { border-top-color: var(--panel-3) !important; }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--panel-3) !important; }
.leaflet-tooltip-left::before { border-left-color: var(--panel-3) !important; }
.leaflet-tooltip-right::before { border-right-color: var(--panel-3) !important; }

/* --- Arrivals Panel --- */
.arrivals-panel {
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* --- Panel Header --- */
.panel-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.panel-header.compact {
  padding: 12px 16px;
}

.panel-header h3 {
  font-family: var(--f-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  margin-top: 3px;
}

/* --- Buttons (Refresh, etc) --- */
#refreshButton,
#historyRefresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  color: var(--text-2);
  background: var(--panel-2);
  border-radius: var(--r-md);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--t-normal) var(--ease-out);
}

#refreshButton:hover,
#historyRefresh:hover {
  border-color: var(--amber-d);
  color: var(--amber);
  background: var(--amber-dd);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

#refreshButton:active,
#historyRefresh:active {
  transform: translateY(0) scale(0.98);
}

#refreshButton svg,
#historyRefresh svg {
  transition: transform var(--t-slow) var(--ease-out);
}

#refreshButton:hover svg,
#historyRefresh:hover svg {
  transform: rotate(-90deg);
}

/* --- Arrival List --- */
.arrival-list {
  flex: 1 1 58%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.arrival-list.empty {
  color: var(--muted);
  padding: 28px 22px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* --- Arrival Card --- */
.arrival-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-1);
  padding: 14px;
  cursor: pointer;
  outline: none;
  transition: all var(--t-normal) var(--ease-out);
  position: relative;
  overflow: visible;
}

.arrival-card.animate {
  animation: card-in var(--t-slow) var(--ease-out) both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.arrival-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  transition: background var(--t-normal) var(--ease-out);
}

.arrival-card:hover,
.arrival-card:focus-visible {
  border-color: var(--line-h);
  background: var(--bg-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.arrival-card.selected {
  border-color: color-mix(in srgb, var(--accent, var(--amber)), transparent 64%);
  background: color-mix(in srgb, var(--accent, var(--amber)), transparent 92%);
}

.arrival-card:not(.selected) {
  padding: 12px 14px;
}

.arrival-card.selected::before {
  background: var(--accent, var(--amber));
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent, var(--amber)), transparent 65%);
}

/* --- Arrival Content --- */
.arrival-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.arrival-title {
  display: flex;
  align-items: center;
}

.arrival-title strong {
  display: block;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 14px;
}

.arrival-title small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.compact-eta {
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
}

.compact-eta span {
  color: var(--text);
  font-family: var(--f-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.compact-eta small {
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --- Route Pill --- */
.route-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 30px;
  border-radius: var(--r-sm);
  color: var(--bg);
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 13px;
  margin-right: 10px;
  letter-spacing: -0.01em;
  box-shadow: var(--shadow-sm);
}

.route-pill.tram       { background: var(--tram); }
.route-pill.trolleybus { background: var(--trolley); }
.route-pill.bus,
.route-pill.minibus    { background: var(--bus); }

/* --- ETA Comparison Boxes --- */
.eta-pair {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 14px;
}

.eta-box {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  padding: 10px 12px;
  transition: all var(--t-normal) var(--ease-out);
}

.eta-box:hover {
  border-color: var(--line-2);
}

.eta-box span {
  display: block;
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 9px;
  font-weight: 500;
  min-height: 28px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.eta-box strong {
  display: block;
  margin-top: 10px;
  font-family: var(--f-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.eta-box-v2 {
  border-color: rgba(102,187,106,0.25);
  background: rgba(102,187,106,0.06);
}

.eta-box-v2 span {
  color: var(--good);
}

.eta-box-v2 strong {
  color: var(--good);
}

.eta-box-v32 {
  border-color: rgba(33,150,243,0.32);
  background: rgba(33,150,243,0.07);
}

.eta-box-v32 span,
.eta-box-v32 strong {
  color: #64B5F6;
}

.eta-box-timer {
  border-color: rgba(255,193,7,0.25);
  background: rgba(255,193,7,0.045);
}

.eta-box-timer span,
.eta-box-timer strong {
  color: var(--amber-l);
}

/* --- Comparison Detail Sections --- */
.comparison-sections {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.comparison-section {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.015);
  padding: 12px;
}

.section-label {
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.meta-grid {
  display: grid;
  gap: 10px;
}

.meta-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.meta-grid-drift {
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
}

.meta-grid-ops {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.meta-grid div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  min-width: 0;
}

.meta-grid .meta-reason {
  grid-column: 1 / -1;
}

.meta-grid span {
  display: block;
  color: var(--faint);
  font-family: var(--f-mono);
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta-grid strong {
  display: block;
  margin-top: 4px;
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
  color: var(--text-2);
}

/* --- Confidence Colors --- */
.confidence-high     { color: var(--good); font-family: var(--f-mono); font-size: 11px; font-weight: 600; }
.confidence-medium   { color: var(--warn); font-family: var(--f-mono); font-size: 11px; font-weight: 600; }
.confidence-low,
.confidence-fallback,
.confidence-no-gps   { color: var(--bad); font-family: var(--f-mono); font-size: 11px; font-weight: 600; }

/* --- Map Markers --- */
.station-marker {
  position: relative;
  width: 28px;
  height: 34px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
  transition: transform var(--t-normal) var(--ease-spring);
}

.station-marker:hover {
  transform: scale(1.15);
}

.station-marker::before {
  content: '';
  position: absolute;
  inset: 0 0 6px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--marker-color);
  border: 2.5px solid var(--bg);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2);
}

.station-marker span {
  position: absolute;
  left: 9px;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg);
}

/* --- Vehicle Icons --- */
.vehicle-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--r-md);
  background: var(--bg);
  border: 2px solid var(--text);
  box-shadow: var(--shadow-lg);
  transition: transform var(--t-normal) var(--ease-spring);
}

.vehicle-icon:hover {
  transform: scale(1.1);
}

.vehicle-icon svg {
  display: block;
  width: 42px;
  height: 42px;
}

.vehicle-body    { fill: var(--vehicle-color); }
.vehicle-stroke  { stroke: var(--bg); stroke-width: 2; stroke-linecap: round; }
.vehicle-stroke.thin { stroke-width: 1.7; }
.vehicle-wheel   { fill: var(--bg); }

.vehicle-label {
  fill: var(--bg);
  font-size: 6px;
  font-weight: 800;
  letter-spacing: 0;
  dominant-baseline: middle;
}

/* --- History Table --- */
.history-table-panel {
  flex: 0 0 270px;
  min-height: 190px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-table {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 10px 16px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) repeat(5, 48px) 94px;
  gap: 8px;
  min-width: 540px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
  font-size: 12px;
  transition: background var(--t-fast) var(--ease-out);
}

.history-panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.history-search-wrap {
  width: min(220px, 28vw);
  min-width: 150px;
}

.history-search-wrap input[type="search"] {
  padding-top: 7px;
  padding-bottom: 7px;
  font-size: 11px;
}

.history-group-header {
  position: sticky;
  top: -8px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 540px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--text-2);
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.history-group-header::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.history-group-header strong {
  margin-left: auto;
  color: var(--muted);
}

.history-vehicle-group + .history-vehicle-group {
  margin-top: 12px;
}

.history-v32 {
  color: #64B5F6 !important;
}

.history-empty {
  padding: 24px 12px;
  color: var(--muted);
  text-align: center;
}

.history-row:hover:not(.header) {
  background: rgba(255,193,7,0.03);
}

.history-row.header {
  color: var(--muted);
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom-color: var(--line-2);
}

.history-row strong {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row span {
  font-family: var(--f-mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
}

/* --- Responsive --- */
@media (max-width: 1000px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
  }

  .sidebar {
    height: auto;
    min-height: 0;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar::after {
    display: none;
  }

  .collector-panel {
    display: none;
  }

  .workspace {
    height: auto;
  }

  .topbar {
    min-height: auto;
    padding: 14px 18px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .topbar::after {
    display: none;
  }

  #stationTitle {
    font-size: 20px;
  }

  .status-strip {
    width: 100%;
  }

  .content-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 220px minmax(0, 1fr);
  }

  #map {
    height: 220px;
    min-height: 0;
  }

  .arrivals-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .history-table-panel {
    flex-basis: 210px;
  }
}

/* --- Animation delay for staggered cards --- */
.arrival-card.animate:nth-child(1) { animation-delay: 0ms; }
.arrival-card.animate:nth-child(2) { animation-delay: 40ms; }
.arrival-card.animate:nth-child(3) { animation-delay: 80ms; }
.arrival-card.animate:nth-child(4) { animation-delay: 120ms; }
.arrival-card.animate:nth-child(5) { animation-delay: 160ms; }
.arrival-card.animate:nth-child(6) { animation-delay: 200ms; }
.arrival-card.animate:nth-child(7) { animation-delay: 240ms; }
.arrival-card.animate:nth-child(8) { animation-delay: 280ms; }
.arrival-card.animate:nth-child(9) { animation-delay: 320ms; }
.arrival-card.animate:nth-child(10) { animation-delay: 360ms; }

/* --- Station row stagger --- */
.station-row {
  animation: row-in var(--t-slow) var(--ease-out) both;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
}

.station-row:nth-child(1)  { animation-delay: 0ms; }
.station-row:nth-child(2)  { animation-delay: 20ms; }
.station-row:nth-child(3)  { animation-delay: 40ms; }
.station-row:nth-child(4)  { animation-delay: 60ms; }
.station-row:nth-child(5)  { animation-delay: 80ms; }
.station-row:nth-child(6)  { animation-delay: 100ms; }
.station-row:nth-child(7)  { animation-delay: 120ms; }
.station-row:nth-child(8)  { animation-delay: 140ms; }
.station-row:nth-child(9)  { animation-delay: 160ms; }
.station-row:nth-child(10) { animation-delay: 180ms; }

/* --- History row stagger --- */
.history-row.animate {
  animation: row-in var(--t-slow) var(--ease-out) both;
}

.history-row.animate:nth-child(2)  { animation-delay: 30ms; }
.history-row.animate:nth-child(3)  { animation-delay: 60ms; }
.history-row.animate:nth-child(4)  { animation-delay: 90ms; }
.history-row.animate:nth-child(5)  { animation-delay: 120ms; }
.history-row.animate:nth-child(6)  { animation-delay: 150ms; }
.history-row.animate:nth-child(7)  { animation-delay: 180ms; }
.history-row.animate:nth-child(8)  { animation-delay: 210ms; }
.history-row.animate:nth-child(9)  { animation-delay: 240ms; }
.history-row.animate:nth-child(10) { animation-delay: 270ms; }
.history-row.animate:nth-child(11) { animation-delay: 300ms; }
.history-row.animate:nth-child(12) { animation-delay: 330ms; }
.history-row.animate:nth-child(13) { animation-delay: 360ms; }

/* --- Confirmation Modal --- */
.modal-backdrop {
  align-items: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(244,67,54,0.18), transparent 36%),
    rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 22px;
  position: fixed;
  z-index: 10000;
}

.modal-backdrop.open {
  display: flex;
  animation: modal-fade var(--t-normal) var(--ease-out) both;
}

.confirm-modal {
  background: linear-gradient(145deg, var(--panel-2), var(--bg-1));
  border: 1px solid rgba(244,67,54,0.42);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55), 0 0 0 1px rgba(244,67,54,0.08) inset, 0 0 34px rgba(244,67,54,0.08);
  display: grid;
  gap: 18px;
  max-width: 430px;
  padding: 24px;
  position: relative;
  width: min(100%, 430px);
}

.modal-backdrop.open .confirm-modal {
  animation: modal-in var(--t-slow) var(--ease-out) both;
}

.modal-icon {
  align-items: center;
  background: rgba(244,67,54,0.14);
  border: 1px solid rgba(244,67,54,0.42);
  border-radius: var(--r-lg);
  color: #ffb4ad;
  display: flex;
  height: 52px;
  justify-content: center;
  width: 52px;
}

.modal-icon svg {
  height: 28px;
  width: 28px;
}

.modal-copy h2 {
  color: #ffdad6;
  font-family: var(--f-display);
  font-size: 25px;
  letter-spacing: -0.03em;
  margin-top: 6px;
}

.modal-copy > p:last-child {
  color: var(--text-2);
  font-size: 14px;
  margin-top: 8px;
}

.modal-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.modal-button {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 700;
  padding: 11px 14px;
  transition: all var(--t-normal) var(--ease-out);
}

.modal-button-secondary {
  background: rgba(244,67,54,0.06);
  border-color: rgba(244,67,54,0.22);
  color: #f1c6c2;
}

.modal-button-danger {
  background: rgba(244,67,54,0.22);
  border-color: rgba(244,67,54,0.58);
  color: #ffdad6;
}

.modal-button:hover:not(:disabled),
.modal-button:focus-visible:not(:disabled) {
  transform: translateY(-1px);
  outline: none;
}

.modal-button-secondary:hover,
.modal-button-secondary:focus-visible {
  background: rgba(244,67,54,0.1);
  border-color: rgba(244,67,54,0.34);
  color: #ffdad6;
}

.modal-button-danger:hover,
.modal-button-danger:focus-visible {
  background: rgba(244,67,54,0.32);
  border-color: rgba(244,67,54,0.72);
}

.modal-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

@keyframes modal-fade {
  from { opacity: 0; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

/* --- Mobile Dashboard Layout --- */
@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow: auto;
    overflow-x: hidden;
  }

  .shell {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    width: 100%;
    max-width: 100vw;
  }

  .sidebar,
  .workspace {
    height: auto;
    min-height: 0;
    overflow: visible;
    width: 100%;
    max-width: 100vw;
  }

  .sidebar {
    border-bottom: 1px solid var(--line);
    border-right: 0;
  }

  .brand {
    padding: 14px 16px;
  }

  .brand-mark {
    height: 34px;
    width: 34px;
  }

  h1 {
    font-size: 17px;
  }

  .brand p {
    font-size: 10px;
  }

  .controls {
    background: var(--panel);
    padding: 12px 14px;
    position: sticky;
    top: 0;
    z-index: 30;
  }

  input[type="search"] {
    min-height: 44px;
  }

  .filters {
    gap: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .filter {
    min-height: 38px;
    padding: 8px 4px;
  }

  .collector-panel {
    display: grid;
    padding: 12px 14px;
    min-width: 0;
  }

  .collector-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }

  .collector-controls label,
  .collector-controls button,
  .collector-controls input {
    min-width: 0;
  }

  .btn-collector {
    justify-content: center;
    min-height: 40px;
  }

  .collector-stats,
  .history-summary {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }

  .collector-stats div,
  .history-summary p,
  .status-card {
    min-width: 0;
  }

  .collector-stats strong,
  .history-summary strong,
  .status-card span {
    overflow-wrap: anywhere;
  }

  .collector-stats strong {
    font-size: clamp(18px, 5vw, 27px);
  }

  .history-summary strong {
    font-size: 16px;
  }

  .station-list {
    display: grid;
    gap: 8px;
    max-height: 34vh;
    overflow-y: auto;
    padding: 10px 14px 14px;
  }

  .station-row {
    background: var(--bg-1);
    border-color: var(--line);
    min-height: 56px;
    padding: 10px 12px;
  }

  .topbar {
    align-items: stretch;
    background: var(--bg);
    flex-direction: column;
    gap: 12px;
    min-height: auto;
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .topbar::after {
    display: none;
  }

  #stationTitle {
    font-size: 21px;
    line-height: 1.1;
  }

  .status-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .status-card {
    padding: 9px 10px;
  }

  .status-card span {
    font-size: 13px;
  }

  .status-card small {
    font-size: 8px;
  }

  .content-grid {
    display: block;
    overflow: visible;
  }

  #map {
    border-bottom: 1px solid var(--line);
    height: 260px;
    min-height: 260px;
  }

  .arrivals-panel {
    border-left: 0;
    border-top: 0;
    min-height: auto;
    overflow: visible;
  }

  .panel-header {
    align-items: center;
    padding: 14px 16px;
  }

  .panel-header h3 {
    font-size: 15px;
  }

  #refreshButton,
  #historyRefresh {
    min-height: 40px;
    padding: 9px 12px;
  }

  .arrival-list {
    display: grid;
    gap: 12px;
    max-height: none;
    min-height: auto;
    overflow: visible;
    padding: 12px 14px 16px;
  }

  .arrival-list.empty {
    min-height: 150px;
  }

  .arrival-card,
  .arrival-card:not(.selected) {
    padding: 14px;
  }

  .arrival-main {
    gap: 10px;
  }

  .arrival-title strong {
    font-size: 15px;
  }

  .arrival-title small {
    font-size: 11px;
  }

  .route-pill {
    height: 34px;
    margin-right: 10px;
    min-width: 44px;
  }

  .compact-eta span {
    font-size: 18px;
  }

  .eta-pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .eta-box {
    padding: 10px;
  }

  .eta-box span {
    min-height: 26px;
  }

  .eta-box strong {
    font-size: 23px;
  }

  .comparison-section {
    padding: 10px;
  }

  .meta-grid-drift,
  .meta-grid-ops {
    grid-template-columns: 1fr;
  }

  .meta-grid .meta-reason {
    grid-column: auto;
  }

  .meta-grid strong {
    font-size: 13px;
  }

  .history-table-panel {
    border-top: 1px solid var(--line);
    flex: none;
    min-height: auto;
    overflow: visible;
  }

  .history-table {
    overflow: auto;
    padding: 8px 14px 18px;
  }

  .history-row {
    gap: 7px;
    grid-template-columns: minmax(110px, 1fr) repeat(5, 44px) 88px;
    min-width: 510px;
  }

  .history-row.header {
    font-size: 8px;
    letter-spacing: 0.04em;
  }

  .history-row strong,
  .history-row span {
    font-size: 10px;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .brand {
    gap: 10px;
  }

  .filter {
    font-size: 11px;
  }

  .filter-dot {
    display: none;
  }

  .collector-panel {
    display: none;
  }

  .station-list {
    max-height: 38vh;
  }

  .status-strip {
    gap: 6px;
  }

  .status-card {
    padding: 8px;
  }

  #map {
    height: 230px;
    min-height: 230px;
  }

  .eta-pair {
    grid-template-columns: 1fr;
  }

  .history-row {
    grid-template-columns: minmax(100px, 1fr) repeat(5, 42px) 82px;
    min-width: 490px;
  }
}

.mobile-tabbar {
  display: none;
}

@media (max-width: 760px) {
  body {
    padding-bottom: 82px;
  }

  .controls,
  .topbar {
    position: static;
  }

  .collector-panel {
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    margin: 12px 10px;
    max-width: calc(100vw - 20px);
    padding: 12px;
  }

  .mobile-tabbar {
    align-items: center;
    background: rgba(10, 10, 8, 0.88);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    bottom: 12px;
    box-shadow: 0 14px 40px rgba(0,0,0,0.46);
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    left: 12px;
    max-width: calc(100vw - 24px);
    padding: 6px;
    position: fixed;
    right: 12px;
    z-index: 9000;
  }

  .mobile-tab {
    background: transparent;
    border: 0;
    border-radius: 18px;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--f-display);
    font-size: 13px;
    font-weight: 700;
    min-height: 46px;
    transition: all var(--t-normal) var(--ease-out);
  }

  .mobile-tab.active {
    background: rgba(255,193,7,0.14);
    box-shadow: inset 0 0 0 1px rgba(255,193,7,0.2);
    color: var(--amber-l);
  }

  body[data-mobile-tab="collector"] .controls,
  body[data-mobile-tab="collector"] .station-list,
  body[data-mobile-tab="collector"] .topbar-title,
  body[data-mobile-tab="collector"] .status-strip,
  body[data-mobile-tab="collector"] .content-grid,
  body[data-mobile-tab="live"] .collector-panel,
  body[data-mobile-tab="live"] .status-strip,
  body[data-mobile-tab="live"] .history-table-panel,
  body[data-mobile-tab="history"] .sidebar,
  body[data-mobile-tab="history"] .topbar,
  body[data-mobile-tab="history"] #map,
  body[data-mobile-tab="history"] .panel-header:not(.compact),
  body[data-mobile-tab="history"] .arrival-list {
    display: none;
  }

  body[data-mobile-tab="collector"] .workspace {
    display: block;
  }

  body[data-mobile-tab="collector"] .topbar {
    background: transparent;
    border-bottom: 0;
    padding: 0;
  }

  body[data-mobile-tab="live"] .topbar {
    border-bottom: 1px solid var(--line);
  }

  body[data-mobile-tab="history"] .workspace,
  body[data-mobile-tab="history"] .content-grid,
  body[data-mobile-tab="history"] .arrivals-panel,
  body[data-mobile-tab="history"] .history-table-panel {
    display: block;
  }

  body[data-mobile-tab="history"] .history-table-panel {
    border-top: 0;
  }

  body[data-mobile-tab="history"] .panel-header.compact {
    border-bottom: 1px solid var(--line);
    padding: 18px 16px;
  }

  body[data-mobile-tab="history"] .history-table {
    max-height: calc(100vh - 158px);
    overflow: auto;
  }

  .history-panel-actions {
    flex: 1;
  }

  .history-search-wrap {
    flex: 1;
    width: auto;
  }
}

@media (max-width: 420px) {
  body[data-mobile-tab="collector"] .collector-panel {
    display: grid;
  }
}
