/* Continental color tokens */
:root {
  --conti-yellow: #ffa500;
  --conti-yellow-dim: #cc8400;
  --conti-black: #000000;
  --conti-black-soft: #0d0d0d;
  --conti-ink: #1a1a1a;
  --conti-gray-1: #737373;
  --conti-gray-2: #969696;
  --conti-gray-3: #cdcdcd;
  --conti-gray-4: #f0f0f0;
  --conti-white: #ffffff;
  --conti-blue: #00a5dc;
  --conti-dark-blue: #004eaf;
  --conti-green: #2db928;
  --conti-dark-green: #057855;
  --conti-red: #ff2d37;

  --rail-bg: #0d0d0d;
  --rail-card: #161616;
  --rail-card-2: #1f1f1f;
  --rail-border: #2a2a2a;
  --rail-text-dim: #8a8a8a;

  --font-sans: "Inter", "Helvetica Neue", "Arial", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Menlo", monospace;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  background: var(--conti-black);
  color: var(--conti-white);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: 152px 1fr;
  height: 100vh;
}

/* ---------- Header ---------- */
.header {
  background: var(--conti-black);
  border-bottom: 1px solid #1c1c1c;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
  position: relative;
  z-index: 1000;
}
.header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--conti-yellow) 0%, var(--conti-yellow) 18%, transparent 18%, transparent 100%);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
}
.brand-logo {
  height: 128px;
  width: auto;
  display: block;
}

.event {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-self: center;
}
.event-divider {
  width: 1px;
  height: 22px;
  background: #2a2a2a;
}
.event-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--rail-text-dim);
}
.event-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--conti-white);
}

/* ---- Header navigation tabs (Consumption Test · Braking Tests · Diagnostic · Settings) ---- */
.nav-tabs {
  display: flex;
  gap: 12px;
  align-items: center;
}
.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--rail-text-dim);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.nav-tab .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rail-text-dim);
  display: inline-block;
}
.nav-tab:hover {
  color: var(--conti-white);
}
.nav-tab.active {
  color: var(--conti-yellow);
  border-color: var(--conti-yellow);
  background: rgba(255, 165, 0, 0.08);
}
.nav-tab.active .dot {
  background: var(--conti-yellow);
}

/* ---- Connection-state variants for the live pill ----
   Chained selectors (.live-pill.live-pill-on) so they win against the base
   .live-pill rule below regardless of source order. */
.live-pill.live-pill-on {
  background: rgba(45, 185, 40, 0.14);
  border-color: rgba(45, 185, 40, 0.45);
  color: var(--conti-green);
}
.live-pill.live-pill-busy {
  background: rgba(255, 165, 0, 0.14);
  border-color: rgba(255, 165, 0, 0.45);
  color: var(--conti-yellow);
}
.live-pill.live-pill-off {
  background: rgba(138, 138, 138, 0.12);
  border-color: rgba(138, 138, 138, 0.35);
  color: var(--rail-text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
  justify-self: end;
}
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(255, 45, 55, 0.12);
  border: 1px solid rgba(255, 45, 55, 0.35);
  color: var(--conti-red);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   currentColor; }
  70%  { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0   transparent; }
}
/* Disable the attention-grabbing pulse when offline */
.live-pill-off .live-dot { animation: none; }
.clock {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--conti-white);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.clock .label {
  color: var(--rail-text-dim);
  margin-right: 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ---------- Main split ---------- */
.main {
  display: grid;
  grid-template-columns: 1fr 420px;
  min-height: 0;
}

/* ---------- Map ---------- */
.map-wrap {
  position: relative;
  min-height: 0;
  background: var(--conti-gray-4);
}
#map {
  position: absolute;
  inset: 0;
}
/* dim non-route map a bit, keep route prominent */
.leaflet-container {
  background: #1b1b1b !important;
  font-family: var(--font-sans) !important;
}
/* Subtle darken on satellite for a more "ops dashboard" feel */
.leaflet-tile-pane {
  filter: brightness(0.78) contrast(1.05) saturate(0.9);
}
.leaflet-control-attribution {
  background: rgba(0,0,0,0.6) !important;
  color: var(--rail-text-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--conti-gray-3) !important; }
.leaflet-control-zoom { display: none; }

/* Map overlays */
.map-overlay {
  position: absolute;
  z-index: 500;
  pointer-events: none;
}
.map-overlay > * { pointer-events: auto; }

.route-card {
  top: 16px;
  left: 16px;
  background: rgba(13,13,13,0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--rail-border);
  border-radius: 12px;
  padding: 14px 18px;
  color: var(--conti-white);
  min-width: 280px;
}
.route-card .head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.route-card .head h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rail-text-dim);
  font-weight: 600;
}
.route-card .head .progress-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--conti-yellow);
  font-variant-numeric: tabular-nums;
}
.route-bar {
  position: relative;
  height: 6px;
  background: #232323;
  border-radius: 3px;
  overflow: hidden;
}
.route-bar-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--conti-yellow) 0%, #ffc658 100%);
  width: 0%;
  transition: width 0.3s linear;
  border-radius: 3px;
}
.route-bar-tick {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 12px;
  background: var(--rail-text-dim);
  opacity: 0.5;
}
.route-endpoints {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 11px;
  color: var(--rail-text-dim);
}
.route-endpoints .pt {
  display: flex; align-items: center; gap: 6px;
}
.route-endpoints .pt .dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.route-endpoints .start .dot { background: var(--conti-green); }
.route-endpoints .end .dot { background: var(--conti-red); }
.route-endpoints strong { color: var(--conti-white); font-weight: 600; }

/* Map controls — top-right (Auto-center toggle + Recenter button) */
.map-controls {
  top: 18px;
  right: 16px;
  background: rgba(13,13,13,0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--rail-border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  color: var(--rail-text-dim);
}
.map-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.map-toggle input { accent-color: var(--conti-yellow); }
.map-toggle-label {
  letter-spacing: 1px;
  color: var(--conti-white);
}
.map-mini-btn {
  background: var(--rail-card);
  color: var(--conti-yellow);
  border: 1px solid var(--conti-yellow);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
}
.map-mini-btn:hover { background: rgba(255,165,0,0.12); }

/* Map legend bottom-right */
.map-legend {
  bottom: 18px;
  left: 16px;
  background: rgba(13,13,13,0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--rail-border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--rail-text-dim);
}
.map-legend .leg {
  display: flex; align-items: center; gap: 8px;
}
.map-legend .swatch {
  width: 18px; height: 3px; border-radius: 2px;
}
.map-legend .swatch.route { background: var(--conti-yellow); }
.map-legend .swatch.trail { background: linear-gradient(90deg, transparent, var(--conti-yellow)); height: 3px; }
.map-legend .truck-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--conti-yellow);
  box-shadow: 0 0 0 3px rgba(255,165,0,0.25);
}

/* Truck marker */
.truck-marker {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}
.truck-marker .pulse {
  position: absolute;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,165,0,0.25);
  animation: truckpulse 1.8s infinite;
}
@keyframes truckpulse {
  0%   { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(2.0); opacity: 0; }
}
.truck-marker .core {
  position: relative;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--conti-yellow);
  border: 3px solid var(--conti-black);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  display: grid; place-items: center;
}
.truck-marker .core svg {
  width: 16px; height: 16px;
}

/* ---------- Right rail ---------- */
.rail {
  background: var(--rail-bg);
  border-left: 1px solid #1c1c1c;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
.rail::-webkit-scrollbar { width: 6px; }
.rail::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }

/* Truck hero */
.truck-hero {
  padding: 20px 24px 8px;
  border-bottom: 1px solid #1c1c1c;
  position: relative;
}
.truck-hero .label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--rail-text-dim); font-weight: 600;
}
.truck-hero .vin {
  font-family: var(--font-mono);
  color: var(--conti-yellow);
  letter-spacing: 0.05em;
}
.truck-hero h2 {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.truck-hero .sub {
  color: var(--rail-text-dim);
  font-size: 13px;
  margin-top: 2px;
}
.truck-illustration {
  width: 100%;
  height: 110px;
  margin: 4px 0 -10px;
  display: block;
}

/* Speed gauge */
.gauge-section {
  padding: 20px 24px 24px;
  border-bottom: 1px solid #1c1c1c;
  text-align: center;
}
.gauge-section .label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--rail-text-dim); font-weight: 600;
  margin-bottom: 12px;
}
.gauge-wrap {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}
.gauge-svg { display: block; }
.gauge-readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.gauge-readout .v {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 700;
  color: var(--conti-white);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 24px;
}
.gauge-readout .u {
  font-size: 12px;
  color: var(--rail-text-dim);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-top: 4px;
}

.tag-row {
  display: flex; justify-content: center; gap: 8px;
  margin-top: 8px;
}
.tag {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.tag.gear { background: #1f1f1f; color: var(--conti-white); border: 1px solid #2a2a2a; }
.tag.cruise { background: rgba(45,185,40,0.12); color: var(--conti-green); border: 1px solid rgba(45,185,40,0.35); }
.tag.cruise.off { background: #1f1f1f; color: var(--rail-text-dim); border-color: #2a2a2a; }

/* Stat cards */
.stats {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-card {
  background: var(--rail-card);
  border: 1px solid var(--rail-border);
  border-radius: 10px;
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.stat-card.wide { grid-column: span 2; }
.stat-card .label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rail-text-dim);
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.stat-card .label .icon {
  width: 14px; height: 14px; color: var(--conti-yellow);
}
.stat-card .v {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--conti-white);
  line-height: 1;
}
.stat-card .u {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--rail-text-dim);
  margin-left: 4px;
}
.stat-card .delta {
  font-size: 11px;
  margin-top: 8px;
  color: var(--rail-text-dim);
  display: flex; align-items: center; gap: 4px;
}
.stat-card .delta.good { color: var(--conti-green); }
.stat-card .delta.bad { color: var(--conti-red); }

/* Sparkline */
.spark-card {
  background: var(--rail-card);
  border: 1px solid var(--rail-border);
  border-radius: 10px;
  padding: 14px 14px 4px;
  margin: 0 16px 16px;
}
.spark-card .head {
  display: flex; justify-content: space-between; align-items: center;
}
.spark-card .head .label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rail-text-dim);
  font-weight: 600;
}
.spark-card .head .now {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--conti-yellow);
  font-variant-numeric: tabular-nums;
}
.spark-card svg {
  display: block;
  width: 100%;
  height: 60px;
  margin-top: 4px;
}

/* Footer status */
.rail-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid #1c1c1c;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--rail-text-dim);
  background: #0a0a0a;
}
.rail-footer .ok {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--conti-green);
}
.rail-footer .ok::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--conti-green);
  box-shadow: 0 0 0 3px rgba(45,185,40,0.18);
}

/* Loading veil while map loads */
.loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: #1b1b1b;
  z-index: 600;
  color: var(--rail-text-dim);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transition: opacity 0.4s;
}
.loading.gone { opacity: 0; pointer-events: none; }
.loading .spinner {
  width: 28px; height: 28px;
  border: 3px solid #333;
  border-top-color: var(--conti-yellow);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-right: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
