:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7a;
  --line: #dde2e7;
  --accent: #0b5cab;
  --accent-ink: #ffffff;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --radius: 8px;
  --side-w: 300px;
  --panel-w: 420px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171d; --surface: #1a2129; --ink: #e8edf2; --muted: #9aa8b6; --line: #2b3640;
    --accent: #5aa9ff; --accent-ink: #0a1118; --warn-bg: #3a2f10; --warn-ink: #f2d98a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex; flex-direction: column;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; font-weight: 650; letter-spacing: .1px; }
h2 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 8px; }
h3 { font-size: 14px; font-weight: 650; margin-top: 18px; }
.muted { color: var(--muted); }
.cap { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; display: block; }
.sub { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.updated { font-size: 12px; color: var(--muted); }

.btn {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn.icon { padding: 6px 10px; font-size: 16px; line-height: 1; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); margin-top: 16px; }
.btn:focus-visible, select:focus-visible, .seg button:focus-visible, .close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }
.seg button { font: inherit; background: var(--surface); color: var(--ink); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.demo { background: var(--warn-bg); color: var(--warn-ink); padding: 6px 16px; font-size: 13px; border-bottom: 1px solid var(--line); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--side-w) 1fr; position: relative; }
.layout.with-panel { grid-template-columns: var(--side-w) 1fr var(--panel-w); }

.side { background: var(--surface); border-right: 1px solid var(--line); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field[hidden] { display: none; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; min-width: 0; }
.period { display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 6px; }
.period select[hidden] { display: none; }
.period.annual { grid-template-columns: auto 1fr auto; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }

.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rank li button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; align-items: center;
  font: inherit; color: var(--ink); background: none; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; cursor: pointer; text-align: left;
}
.rank li button:hover, .rank li button[aria-current="true"] { background: var(--bg); border-color: var(--line); }
.rank .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; border: 1px solid rgba(0,0,0,.2); }
.rank .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .vl { font-variant-numeric: tabular-nums; font-weight: 600; }
.note { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }

.mapwrap { position: relative; min-width: 0; min-height: 360px; }
#map { position: absolute; inset: 0; }
.legend {
  position: absolute; left: 12px; bottom: 28px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; min-width: 190px; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.legend .bar { height: 10px; border-radius: 3px; margin: 6px 0 4px; border: 1px solid rgba(0,0,0,.15); }
.legend .ticks { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.legend .nodata { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--muted); }
.legend .nodata i { width: 12px; height: 10px; background: #8a949e; opacity: .55; display: inline-block; border-radius: 2px; }

.panel { background: var(--surface); border-left: 1px solid var(--line); padding: 16px 18px 24px; overflow-y: auto; position: relative; }
.panel[hidden] { display: none; }
.close { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.panel h2 { text-transform: none; font-size: 18px; letter-spacing: 0; color: var(--ink); margin: 0 24px 2px 0; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.kpis div { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; }
.kpis b { font-size: 20px; font-variant-numeric: tabular-nums; }
.kpis span { font-size: 11px; color: var(--muted); }
.chart { width: 100%; height: 220px; }
.chart.small { height: 180px; }
#levelsSection .cap { margin: 2px 0; }
#levelsSection .btn { margin-top: 8px; font-size: 13px; padding: 5px 10px; }
#levelsSection .field { margin-bottom: 6px; }

dialog { max-width: 560px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 20px 22px; }
dialog::backdrop { background: rgba(10, 17, 24, .5); }
dialog h2 { text-transform: none; font-size: 18px; letter-spacing: 0; color: var(--ink); }
dialog p { margin: 10px 0; }
dialog table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
dialog td, dialog th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }

@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  .layout, .layout.with-panel { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .side { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  .mapwrap { order: 1; height: 55vh; min-height: 320px; }
  .panel { order: 3; border-left: 0; border-top: 1px solid var(--line); }
  .topbar { padding: 8px 12px; }
  .updated { display: none; }
}

[hidden] { display: none !important; }
.lakelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lakelist button {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 9px 12px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 2px;
}
.lakelist button:hover { border-color: var(--accent); }
.lakelist button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lakelist .ln { font-weight: 600; }
.lakelist .ls { font-size: 12px; color: var(--muted); }
.pin {
  font: 600 12px/1 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--accent-ink); background: var(--accent);
  border: 2px solid #fff; border-radius: 999px; padding: 6px 11px 6px 9px; cursor: pointer; white-space: nowrap;
  box-shadow: 0 1px 5px rgba(0,0,0,.4); display: inline-flex; align-items: center; gap: 6px;
}
.pin::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; flex: none; }
.pin:hover, .pin:focus-visible { background: #0a4a8c; outline: 2px solid #ffd54a; outline-offset: 1px; }
.allbtn { position: absolute; top: 10px; left: 10px; z-index: 2; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.basesel { position: absolute; top: 10px; right: 52px; z-index: 2; box-shadow: 0 1px 4px rgba(0,0,0,.25); padding: 5px 8px; font-size: 13px; }
.attrib { position: absolute; right: 0; bottom: 0; z-index: 2; max-width: 70%; background: rgba(255,255,255,.82); color: #333; font-size: 11px; line-height: 1.3; padding: 2px 6px; }
.attrib a { color: #0b5cab; }
.brand { color: inherit; text-decoration: none; border-radius: var(--radius); }
.brand:hover h1 { color: var(--accent); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
