:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --text: #1d1d1b;
  --muted: #5f5d57;
  --border: #d9d6cd;
  --accent: #0b6e4f;
  --accent-text: #ffffff;
  --operating: #0072B2;
  --construction: #E69F00;
  --planned: #CC79A7;
  --abandoned: #6B6B6B;
  --loss: #B3401A;
  --gain: #0b6e4f;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #272723; --text: #ecebe6; --muted: #a9a79f;
    --border: #3a3934; --accent: #3fb88a; --accent-text: #0d1a14; --operating: #56B4E9; --abandoned: #9a9a9a;
    --loss: #ef7d55; --gain: #3fb88a; --shadow: 0 1px 3px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1d1a; --surface-2: #272723; --text: #ecebe6; --muted: #a9a79f;
  --border: #3a3934; --accent: #3fb88a; --accent-text: #0d1a14; --operating: #56B4E9; --abandoned: #9a9a9a;
  --loss: #ef7d55; --gain: #3fb88a; --shadow: 0 1px 3px rgba(0,0,0,.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.hint { color: var(--muted); font-size: 12.5px; }
.small { font-size: 12.5px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo { display: inline-grid; gap: 2px; width: 22px; }
.logo i { display: block; height: 5px; border-radius: 1px; }
.logo i:nth-child(1) { background: var(--operating); }
.logo i:nth-child(2) { background: var(--construction); }
.logo i:nth-child(3) { background: var(--accent); }
.tagline { color: var(--muted); font-size: 12.5px; }
.headline { font-variant-numeric: tabular-nums; font-size: 13px; }
.headline b { font-size: 15px; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(320px, 400px) 1fr; min-height: 0; }
.panel { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.tabs button { flex: 1; padding: 10px 8px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; padding: 14px 16px 28px; overflow-y: auto; flex: 1; }
.tabpane.active { display: block; }

.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.mapbar { position: absolute; top: 10px; left: 56px; z-index: 500; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 120px); }
.mapbar button, .swipe-controls { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font: inherit; font-size: 12.5px; box-shadow: var(--shadow); cursor: pointer; }
.mapbar .hint { background: var(--surface); padding: 3px 8px; border-radius: 4px; box-shadow: var(--shadow); }
.mapbar .hint:empty { display: none; }

.legend { position: absolute; bottom: 28px; right: 10px; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); }
.legend div { display: flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,.35); flex-shrink: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; cursor: pointer; background: var(--surface); color: var(--text); font: inherit; font-size: 12.5px; }
.chip[aria-pressed="false"] { opacity: .45; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 10px; }
.kpi .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi.wide { grid-column: 1 / -1; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12.5px; }
th, td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
td.n, th.n { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--surface-2); }

.field { display: block; margin: 10px 0; border: 0; padding: 0; }
.field legend { padding: 0; margin-bottom: 4px; }
select, input[type=search] { width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; margin-top: 4px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 6px; align-items: flex-start; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row select { flex: 1; margin-top: 0; }
button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font: inherit; font-size: 12.5px; cursor: pointer; }
button.ghost:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: progress; }
.presets { display: flex; gap: 6px; }

.calc-out { margin-top: 14px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 4px 0 10px; }
.bar > span { display: block; height: 100%; }

.site-list { list-style: none; padding: 0; margin: 8px 0; }
.site-list li { padding: 8px 6px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: baseline; }
.site-list li:hover { background: var(--surface-2); }
.site-list .meta { color: var(--muted); font-size: 12px; }
.site-list .num { font-variant-numeric: tabular-nums; font-size: 12.5px; text-align: right; }

.detail h2 { font-size: 17px; margin: 0 0 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 12px 0; font-size: 13px; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-word; }
.green-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.green-compare .kpi .v { font-size: 18px; }
.delta-loss { color: var(--loss); }
.delta-gain { color: var(--gain); }
.prose p, .prose li { color: var(--text); }
.prose code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 3px; }

.swipe { position: absolute; inset: 0; z-index: 450; pointer-events: none; }
.swipe-controls { position: absolute; top: 52px; left: 56px; display: flex; gap: 10px; align-items: center; pointer-events: auto; cursor: default; flex-wrap: wrap; }
.swipe-controls select { width: auto; margin: 0 0 0 4px; padding: 3px 4px; }
#swipe-range { position: absolute; left: 0; right: 0; bottom: 34px; width: 100%; pointer-events: auto; }
.swipe-line { position: absolute; top: 0; bottom: 0; width: 3px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); left: 50%; }

.leaflet-container { font: 12px/1.4 var(--font); }
.leaflet-popup-content { margin: 10px 12px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .panel { order: 2; border-right: 0; border-top: 1px solid var(--border); }
  .mapwrap { order: 1; min-height: 55vh; }
  .tabpane { overflow: visible; }
  .mapbar { left: 52px; max-width: calc(100% - 64px); }
  .legend { bottom: 30px; font-size: 11px; padding: 5px 7px; }
  .tagline { display: none; }
}
