:root {
  color-scheme: light;
  --bg: #fcfcfb;
  --panel: #ffffff;
  --line: #e4e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --accent: #2a78d6;
  --hover: #f3f2ef;
  --s1: #2a78d6;  /* municipal */
  --s2: #eb6834;  /* upper tier */
  --s3: #1baf7a;  /* education */
  --nodata: #e9e8e4;
  --outline: rgba(255,255,255,.85);
  --sel: #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1a1a19;
    --panel: #222220;
    --line: #383835;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --hover: #2c2c2a;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --nodata: #3a3a37;
    --outline: rgba(20,20,19,.8);
    --sel: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); }
code { font-size: 12px; background: var(--hover); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; }
#side {
  width: 380px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 18px 18px 12px;
  display: flex; flex-direction: column; gap: 16px;
}
#main { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }

h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--text-2); font-size: 13px; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.controls .row { display: flex; gap: 10px; }
.controls .row label { flex: 1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
select, input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select:disabled { opacity: .6; cursor: not-allowed; }
.note { margin: -4px 0 0; font-size: 11px; color: var(--muted); }
table.kv tr.pick { cursor: pointer; }
table.kv tr.pick:hover td { background: var(--hover); }
table.kv tr.pick.on td { font-weight: 650; }
table.kv tr.pick.on td:first-child { box-shadow: inset 3px 0 0 var(--accent); padding-left: 7px; }
.money { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.money span { padding-left: 9px; color: var(--muted); }
.money input { border: 0; background: transparent; }
.money:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.money input:focus { outline: none; }

/* legend */
#legend .ltitle { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
#legend .bar { display: flex; gap: 2px; }
#legend .bar div { flex: 1; height: 12px; }
#legend .bar div:first-child { border-radius: 4px 0 0 4px; }
#legend .bar div:last-child { border-radius: 0 4px 4px 0; }
#legend .ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
#legend .ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#legend .nd { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 6px; }
#legend .nd i { width: 14px; height: 10px; border-radius: 3px; background: var(--nodata); display: inline-block; }

/* detail */
#detail { flex: 1; }
.hint { color: var(--muted); font-size: 13px; border: 1px dashed var(--line); border-radius: 10px; padding: 14px; }
.dhead h2 { font-size: 17px; margin: 0; }
.dhead .meta { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.hero { display: flex; gap: 18px; margin: 14px 0 10px; }
.hero .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hero .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.hero .s { font-size: 12px; color: var(--text-2); }
.stack { display: flex; gap: 2px; height: 14px; margin: 8px 0 6px; }
.stack div { height: 100%; }
.stack div:first-child { border-radius: 4px 0 0 4px; }
.stack div:last-child { border-radius: 0 4px 4px 0; }
table.kv { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.kv td { padding: 3px 0; border-bottom: 1px solid var(--line); }
table.kv td:nth-child(n+2) { text-align: right; padding-left: 12px; white-space: nowrap; }
table.kv tr.tot td { font-weight: 650; border-bottom: 0; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
h4 { font-size: 12px; margin: 18px 0 6px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.small { font-size: 12px; color: var(--text-2); }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.on { color: var(--text); border-color: var(--text-2); }
ul.refs { padding-left: 18px; margin: 6px 0; font-size: 13px; }
ul.refs li { margin: 3px 0; }

.trend svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend .ax { stroke: var(--line); }
.trend text { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.trend .lbl { fill: var(--text-2); font-size: 11px; }
.tlegend { display: flex; gap: 14px; font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.tlegend i { display: inline-block; width: 14px; height: 2px; vertical-align: 3px; margin-right: 5px; }

footer { border-top: 1px solid var(--line); padding-top: 10px; }
button { font: inherit; cursor: pointer; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }

/* view toggle */
.viewtoggle {
  position: absolute; top: 12px; right: 12px; z-index: 1002; display: flex;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.viewtoggle button { border: 0; background: none; color: var(--text-2); padding: 5px 12px; border-radius: 6px; }
.viewtoggle button.on { background: var(--hover); color: var(--text); font-weight: 600; }

/* table */
#tableView { position: absolute; inset: 0; z-index: 1001; background: var(--bg); display: flex; flex-direction: column; padding: 56px 16px 16px; }
.tablebar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.tablebar input { max-width: 280px; }
.tablebar span { color: var(--muted); font-size: 12px; flex: 1; }
.tablebar button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 6px 12px; }
.tablewrap { overflow: auto; flex: 1; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
#tbl { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
#tbl th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; font-size: 12px; color: var(--text-2); user-select: none; }
#tbl th.num, #tbl td.num { text-align: right; }
#tbl th.sorted { color: var(--text); }
#tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#tbl tbody tr { cursor: pointer; }
#tbl tbody tr:hover { background: var(--hover); }
#tbl tbody tr.sel { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
#tbl td .chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* tooltip */
#tip {
  position: absolute; z-index: 1100; pointer-events: none; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12); max-width: 260px;
}
#tip b { display: block; font-size: 13px; }
#tip .v { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 650; }
#tip .r { color: var(--muted); }

/* dialog */
dialog { max-width: 680px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px 24px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-top: 0; }
dialog h3 { font-size: 14px; margin: 16px 0 4px; }
dialog ul { padding-left: 18px; }
dialog li { margin: 5px 0; }
dialog .close { position: absolute; right: 14px; top: 10px; font-size: 22px; border: 0; background: none; color: var(--muted); }

.leaflet-container { font: inherit; background: var(--bg); }
.leaflet-control-attribution { font-size: 10px; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; height: auto; }
  #side { width: 100%; border-right: 0; border-top: 1px solid var(--line); }
  #main { height: 62vh; flex: none; }
}
