:root {
  --bg: #ffffff;
  --fg: #1c1f24;
  --muted: #646b75;
  --line: #e2e5ea;
  --surface: #f5f6f8;
  --accent: #16a34a;
  --busy: #ea8a0c;
  --off: #8b929c;
  --shadow: 0 2px 12px rgba(0, 0, 0, .15);
  --series-1: #2563eb;
  --series-2: #db2777;
  --series-3: #0d9488;
  --series-4: #9333ea;
  --series-5: #ca8a04;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1e23;
    --fg: #e7e9ec;
    --muted: #9aa1ab;
    --line: #333841;
    --surface: #24282e;
    --accent: #22c55e;
    --busy: #f59e0b;
    --off: #7b828c;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5);
    --series-1: #60a5fa;
    --series-2: #f472b6;
    --series-3: #2dd4bf;
    --series-4: #c084fc;
    --series-5: #facc15;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--series-1); }
.muted { color: var(--muted); }
#map { position: absolute; inset: 0; }

.card { position: absolute; z-index: 1000; background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); }

#toolbar { top: 12px; left: 56px; width: min(380px, calc(100vw - 72px)); padding: 10px; }
#search { width: 100%; padding: 8px 10px; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; align-items: center; }
.filters label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.filters select { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px; }
#count { margin-top: 6px; font-size: 12px; }
#search-results { margin-top: 6px; max-height: 40vh; overflow: auto; border-top: 1px solid var(--line); }
#search-results button { display: block; width: 100%; text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 6px 4px; cursor: pointer; border-bottom: 1px solid var(--line); }
#search-results button:hover, #search-results button:focus-visible { background: var(--surface); }

#panel { top: 12px; right: 12px; bottom: 34px; width: min(440px, calc(100vw - 24px)); overflow: auto; padding: 16px 16px 20px; }
#close { position: sticky; top: 0; float: right; margin: -6px -6px 0 0; }
button.icon { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--surface); color: var(--fg); font-size: 20px; line-height: 1; cursor: pointer; }
#detail h2 { margin: 0 32px 2px 0; font-size: 17px; line-height: 1.3; }
#detail h4 { margin: 14px 0 6px; font-size: 13px; }
#detail h3 { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.evse { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.evse:last-child { border-bottom: 0; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; color: #fff; background: var(--off); white-space: nowrap; }
.badge.AVAILABLE { background: var(--accent); }
.badge.CHARGING, .badge.BLOCKED, .badge.RESERVED { background: var(--busy); }

table.prices { width: 100%; border-collapse: collapse; font-size: 13px; }
table.prices th, table.prices td { text-align: left; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.prices th { color: var(--muted); font-weight: 500; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.ranges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ranges button, .ranges select { font: inherit; font-size: 12px; padding: 4px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; }
.ranges button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.custom { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; font-size: 12px; }
.custom input { font: inherit; font-size: 12px; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 10px; }
.chart .grid line { stroke: var(--line); }
.chart .tip { position: absolute; pointer-events: none; background: var(--fg); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; z-index: 1; }
.note { font-size: 12px; margin-top: 8px; }
details { margin-top: 12px; font-size: 12px; }
details pre { max-height: 300px; overflow: auto; background: var(--surface); padding: 8px; border-radius: 6px; }

#source { position: absolute; z-index: 1000; left: 12px; bottom: 6px; font-size: 11px; background: var(--bg); padding: 2px 8px; border-radius: 6px; opacity: .9; }

.cluster { display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 600; font-size: 12px; border: 2px solid rgba(255, 255, 255, .8); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }

/* Phone: panel becomes a bottom sheet */
@media (max-width: 640px) {
  #toolbar { left: 50px; right: 10px; top: 10px; width: auto; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 70vh; border-radius: 14px 14px 0 0; }
  #source { display: none; }
}
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: brightness(.75) contrast(1.1) saturate(.8); }
  .leaflet-control-zoom a, .leaflet-control-attribution { background: var(--bg) !important; color: var(--fg) !important; }
}
