:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --surface-3: #f2f1ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --route-line: #2a78d6;
  --charger-dot: #898781;
  --charger-dot-ring: #fcfcfb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --good: #0ca30c;
    --warning: #fab219;
    --critical: #e66767;
    --route-line: #3987e5;
    --charger-dot: #898781;
    --charger-dot-ring: #1a1a19;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-3: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #e66767;
  --route-line: #3987e5;
  --charger-dot: #898781;
  --charger-dot-ring: #1a1a19;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
body { -webkit-font-smoothing: antialiased; }

a { color: var(--accent); }

header.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-wrap: wrap;
}
header.site h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 650;
}
header.site .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}
header.site .title-block { display: flex; flex-direction: column; gap: 2px; }

button.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
button.theme-toggle:hover { background: var(--surface-3); }

main.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 420px);
  gap: 0;
  min-height: 60vh;
}
@media (max-width: 900px) {
  main.layout { grid-template-columns: 1fr; }
}

#map {
  height: 62vh;
  min-height: 420px;
  background: var(--surface-3);
}
@media (max-width: 900px) { #map { height: 46vh; min-height: 320px; } }

aside.panel {
  border-left: 1px solid var(--border);
  background: var(--surface-1);
  padding: 16px;
  overflow-y: auto;
  max-height: 62vh;
}
@media (max-width: 900px) {
  aside.panel { border-left: none; border-top: 1px solid var(--border); max-height: none; }
}

section.controls fieldset {
  border: none;
  padding: 0;
  margin: 0 0 14px 0;
}
section.controls legend {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0 0 6px 0;
  font-weight: 650;
}
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
}
.field-row label {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
}
.field-row .hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}
.field-row input[type="number"] {
  width: 84px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.field-row input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

details.advanced {
  margin: 4px 0 14px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
details.advanced summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}
details.advanced .field-row { padding: 6px 0; }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0 16px 0;
}
.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat-tile .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-tile .value {
  font-size: 20px;
  font-weight: 650;
  margin-top: 2px;
}
.stat-tile .value small { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

.banner {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.banner.error {
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  border-color: color-mix(in srgb, var(--critical) 40%, var(--border));
  color: var(--text-primary);
}

.stops-list { list-style: none; margin: 0; padding: 0; }
.stop-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
}
.stop-item:last-child { border-bottom: none; }
.stop-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.stop-badge.start { background: var(--good); }
.stop-badge.end { background: var(--text-muted); }
.stop-title { font-size: 13.5px; font-weight: 600; }
.stop-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.stop-meta .soc-arrow { color: var(--text-muted); padding: 0 2px; }
.stop-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.stop-maps-link {
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  margin-top: 3px;
  display: inline-block;
}
.stop-maps-link:hover { text-decoration: underline; }

.leg-row {
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 4px 0 4px 34px;
  border-bottom: 1px solid var(--gridline);
}

footer.site {
  padding: 22px 20px 40px 20px;
  max-width: 900px;
  margin: 0 auto;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.55;
}
footer.site h2 { font-size: 15px; color: var(--text-primary); margin: 22px 0 8px 0; }
footer.site h2:first-child { margin-top: 0; }
footer.site code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
footer.site .version {
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.leaflet-container { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--surface-3); }
.divicon-stop {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid var(--surface-1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.divicon-endpoint {
  background: var(--good);
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface-1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.divicon-endpoint.end { background: var(--text-muted); }

.leaflet-popup-content { font-size: 12.5px; }
.leaflet-popup-content b { display: block; margin-bottom: 2px; }

.compute-note {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: -4px 0 12px 0;
}
