:root {
  --ground: #F4F6F8;
  --surface: #FFFFFF;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #556274;
  --line: #DFE5EC;
  --line-2: #EDF1F5;
  --control: #C5CED9;
  --link: #1D4ED8;
  --link-hover: #1E3A8A;
  --r1: #E5F5EF;
  --r2: #A8DDC9;
  --r3: #52B69A;
  --r4: #1F7F86;
  --r5: #163E5C;
  --gain: #A21CAF;
  --gain-text: #86198F;
  --loss: #0891B2;
  --none: #E8ECEF;
  --dense: #D97706;
  --dense-text: #B45309;
  --select: #E5F5EF;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--ground);
  display: flex;
  flex-direction: column;
}
a { color: var(--link); }
a:hover { color: var(--link-hover); }
h1 { font-size: 18px; margin: 0; }
button, select { font: inherit; color: inherit; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px 16px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.title p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.datalink { font-size: 14px; font-weight: 500; }
.linkbtn {
  border: 0; background: none; padding: 0; cursor: pointer; color: var(--link);
  text-decoration: underline; font-size: inherit;
}
.linkbtn:hover { color: var(--link-hover); }
.top .linkbtn { font-size: 14px; font-weight: 500; }

dialog#downloads {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto;
  border: 0; border-radius: 12px; padding: 20px 24px; color: var(--ink);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
}
dialog#downloads::backdrop { background: rgba(15, 23, 42, 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg-head h2 { font-size: 18px; margin: 0; }
.dlg-close {
  border: 0; background: var(--line-2); border-radius: 8px; width: 40px; height: 40px;
  font-size: 22px; line-height: 1; cursor: pointer;
}
dialog h3 { font-size: 14px; margin: 18px 0 8px; }
.dl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.dl li { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.dl span { font-size: 12px; color: var(--muted); }

.seg {
  display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--line-2);
}
.seg3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg button {
  border: 0; border-radius: 8px; min-height: 44px; padding: 10px 18px;
  background: transparent; color: #475569; font-size: 14px; cursor: pointer;
}
.seg3 button { padding: 10px 6px; font-size: 13px; }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.seg button:disabled { opacity: 0.45; cursor: not-allowed; }
.seg button:focus-visible, select:focus-visible, tr:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 400px; flex-shrink: 0; overflow-y: auto; background: var(--surface);
  border-right: 1px solid var(--line); padding: 20px 24px; display: flex; flex-direction: column; gap: 20px;
}
.pane { display: flex; flex-direction: column; gap: 18px; }
.pane[hidden] { display: none; }
.mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

.status { font-size: 13px; color: var(--muted); }
.status:empty { display: none; }
.status.error { color: #B91C1C; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; }
select {
  min-height: 44px; padding: 0 12px; font-size: 15px; border: 1px solid var(--control);
  border-radius: 8px; background: var(--surface);
}

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card-label { font-size: 12px; color: var(--muted); }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.gain { color: var(--gain-text); }

.chart { margin: 0; }
.chart figcaption, .subhead, .legend-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
#chart { width: 100%; height: 150px; display: block; }
#chart .dot { cursor: pointer; }
.note { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 6px 0 0; }
.body { font-size: 13px; color: var(--ink-2); line-height: 1.45; margin: 4px 0 0; }

.ramp { display: grid; grid-template-columns: repeat(5, 1fr); height: 12px; border-radius: 3px; overflow: hidden; }
.ramp-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

.big-value { font-size: 30px; font-weight: 700; }
.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.keys li { display: flex; align-items: center; gap: 10px; }
.sw { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
.sw-gain { background: var(--gain); }
.sw-loss { background: var(--loss); }
.sw-dense { background: var(--dense); }
.sw-none { background: var(--none); border: 1px solid var(--control); }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--line); }
td { padding: 9px 6px; border-bottom: 1px solid var(--line-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--ground); }
tbody tr.selected { background: var(--select); font-weight: 600; }
td.gain { color: var(--gain-text); }
.sort {
  border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px;
}
th.num .sort { flex-direction: row-reverse; }
.sort:hover { color: var(--ink); }
.sort:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.arrow::after { content: "\2195"; opacity: 0.45; font-size: 12px; }
th[aria-sort="ascending"] .arrow::after { content: "\25B2"; opacity: 1; font-size: 9px; }
th[aria-sort="descending"] .arrow::after { content: "\25BC"; opacity: 1; font-size: 9px; }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--ink); }
td.dense { color: var(--dense-text); }

.foot {
  display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 12px 24px; background: var(--surface);
  border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
}

.maplibregl-popup-content { font-family: Inter, system-ui, sans-serif; border-radius: 10px; padding: 12px 14px; }
.pop-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.pop-line { font-size: 13px; color: var(--ink-2); }

@media (max-width: 800px) {
  body { height: auto; }
  .top { padding: 12px 16px; }
  .title p { display: none; }
  .top .datalink { order: -1; margin-left: auto; font-size: 13px; }
  #cities { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout { flex-direction: column; }
  .mapwrap { order: 1; flex: none; height: 55vh; }
  .panel { order: 2; width: 100%; border-right: 0; padding: 16px; overflow: visible; }
  .foot { padding: 12px 16px; }
}
