/* Investment Property Area Finder — offline, no external assets */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-deep: #1c5cab;
  --bar-track: #f0efec;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --chip-a-bg: #e2f3e2; --chip-a-fg: #075c07;
  --chip-b-bg: #dcebfb; --chip-b-fg: #16497f;
  --chip-c-bg: #faf0d2; --chip-c-fg: #6d4e04;
  --chip-d-bg: #fbe5da; --chip-d-fg: #8a3c1b;
  --chip-f-bg: #f9dcdc; --chip-f-fg: #8f2323;
  --chip-na-bg: #eeedea; --chip-na-fg: #6b6a66;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-deep: #86b6ef;
    --bar-track: #262624;
    --chip-a-bg: #123c12; --chip-a-fg: #7fe07f;
    --chip-b-bg: #142f4d; --chip-b-fg: #8fc1f5;
    --chip-c-bg: #423408; --chip-c-fg: #f4cf6a;
    --chip-d-bg: #46220f; --chip-d-fg: #f3a983;
    --chip-f-bg: #471616; --chip-f-fg: #f19c9c;
    --chip-na-bg: #262624; --chip-na-fg: #9c9a94;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.wrap { max-width: 1500px; margin: 0 auto; padding: 20px 24px 60px; }

header.app { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
header.app h1 { font-size: 21px; margin: 0; }
header.app .vintage { color: var(--muted); font-size: 12.5px; }

#loading {
  margin: 40px auto; text-align: center; color: var(--ink-2);
}
#loading .bar {
  width: 300px; height: 6px; border-radius: 4px; background: var(--bar-track);
  margin: 14px auto 0; overflow: hidden;
}
#loading .bar > div {
  width: 40%; height: 100%; border-radius: 4px; background: var(--accent);
  animation: slide 1.1s ease-in-out infinite alternate;
}
@keyframes slide { from { margin-left: 0; } to { margin-left: 60%; } }
#loading.error { color: var(--critical); }
#loading.error .bar { display: none; }
#loading code { background: var(--bar-track); padding: 1px 6px; border-radius: 4px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; margin-top: 14px;
}

/* ----- filters ----- */
.filters { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.filters .f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.filters input, .filters select {
  font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--baseline); border-radius: 6px; padding: 5px 8px; min-width: 110px;
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.filters .grow { flex: 1 1 180px; }

/* filter-label tooltips */
.filters .f { position: relative; }
.tip { border-bottom: 1px dotted var(--muted); cursor: help; width: fit-content; }
.tip:hover::after, .tip:focus-visible::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
  width: max-content; max-width: 260px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--baseline); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 8px 10px; font-size: 12px; line-height: 1.45; white-space: normal;
}
.filters .f:nth-last-child(-n+3) .tip:hover::after,
.filters .f:nth-last-child(-n+3) .tip:focus-visible::after { left: auto; right: 0; }

/* multi-select dropdown (state filter) */
.msel { position: relative; }
.msel-btn {
  min-width: 130px; max-width: 210px; text-align: left;
  background: var(--page); border: 1px solid var(--baseline); border-radius: 6px;
  padding: 5px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msel-btn::after { content: " ▾"; color: var(--muted); }
.msel-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--baseline); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2); padding: 10px;
  display: grid; grid-template-columns: repeat(4, auto); gap: 2px 10px;
  max-height: 320px; overflow: auto; width: max-content;
}
.msel-menu[hidden] { display: none; }
.msel-clear { grid-column: 1 / -1; margin-bottom: 6px; font-size: 12px; padding: 4px 8px; }
.msel-item {
  display: flex; gap: 6px; align-items: center; font-size: 12.5px;
  color: var(--ink); cursor: pointer; padding: 2px 4px; border-radius: 4px;
  white-space: nowrap;
}
.msel-item:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.msel-item input { accent-color: var(--accent); margin: 0; }

/* table-header tooltips: the sticky th is the positioned anchor; tooltips on
   the right half open leftwards so the scroll container doesn't clip them */
table.z thead th .tip::after { text-align: left; font-weight: 400; text-transform: none; letter-spacing: normal; color: var(--ink); }
table.z thead th:nth-last-child(-n+9) .tip:hover::after,
table.z thead th:nth-last-child(-n+9) .tip:focus-visible::after { left: auto; right: 0; }
button {
  font: inherit; border-radius: 7px; border: 1px solid var(--baseline);
  background: var(--surface); color: var(--ink); padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-deep); color: #fff; }

/* ----- stat tiles ----- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 650; margin-top: 2px; }
.tile .s { font-size: 12px; color: var(--ink-2); }
.tile .delta { font-size: 12px; font-weight: 600; margin-left: 6px; }
.tile .delta.good { color: #006300; }
.tile .delta.bad { color: var(--critical); }
@media (prefers-color-scheme: dark) {
  .tile .delta.good { color: var(--good); }
  .tile .delta.bad { color: #e66767; }
}

/* ----- weights ----- */
details.weights summary {
  cursor: pointer; font-weight: 600; color: var(--ink);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.weights summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.weights[open] summary::before { transform: rotate(90deg); }
.presets { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }
.presets button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.sliders { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px 26px; margin-top: 10px; }
.slider { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 2px 10px; }
.slider .lbl { font-size: 12.5px; color: var(--ink-2); grid-column: 1 / 3; display: flex; justify-content: space-between; }
.slider .lbl .hint { color: var(--muted); font-size: 11.5px; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.slider .val { font-size: 12.5px; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }

/* ----- table ----- */
/* The wrapper is the scroll container (both axes) so the sticky header pins
   to it while rows scroll underneath. Zero padding so rows can't peek
   through a gap above the pinned header. */
.tablewrap { overflow: auto; margin-top: 8px; padding: 0; max-height: calc(100vh - 24px); }
table.z { border-collapse: collapse; width: 100%; font-size: 13px; }
table.z th, table.z td { padding: 7px 10px; text-align: right; white-space: nowrap; }
table.z th:nth-child(-n+6), table.z td:nth-child(-n+6) { text-align: left; }
table.z thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--muted);
  font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--baseline);
  cursor: pointer; user-select: none;
}
table.z th:first-child, table.z td:first-child { padding-left: 16px; }
table.z th:last-child, table.z td:last-child { padding-right: 16px; }
table.z thead th:hover { color: var(--accent); }
table.z thead th .arrow { color: var(--accent); }
table.z tbody td { border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
table.z tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); cursor: pointer; }
td.num-strong { font-weight: 600; }
td.muted, .muted { color: var(--muted); }

.chip {
  display: inline-block; min-width: 34px; text-align: center; padding: 2px 7px;
  border-radius: 999px; font-weight: 700; font-size: 12px;
}
.chip.gA { background: var(--chip-a-bg); color: var(--chip-a-fg); }
.chip.gB { background: var(--chip-b-bg); color: var(--chip-b-fg); }
.chip.gC { background: var(--chip-c-bg); color: var(--chip-c-fg); }
.chip.gD { background: var(--chip-d-bg); color: var(--chip-d-fg); }
.chip.gF { background: var(--chip-f-bg); color: var(--chip-f-fg); }
.chip.gN { background: var(--chip-na-bg); color: var(--chip-na-fg); }

.tableheadrow { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.tableheadrow h2 { font-size: 16px; margin: 0; }
.tableheadrow .spacer { flex: 1; }
.pager { display: flex; gap: 6px; align-items: center; color: var(--ink-2); font-size: 13px; }

/* ----- detail drawer ----- */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); display: none; z-index: 40;
}
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 94vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(102%); transition: transform .18s ease-out;
  overflow-y: auto; padding: 20px 22px;
}
#drawer.open { transform: none; }
#drawer h2 { margin: 0 0 2px; font-size: 20px; display: flex; gap: 10px; align-items: center; }
#drawer .sub { color: var(--ink-2); margin-bottom: 14px; }
#drawer .close { position: absolute; top: 14px; right: 14px; }
.dsection { margin-top: 18px; }
.dsection h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 13.5px; }
.kv .k { color: var(--ink-2); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }
.pctrow { display: grid; grid-template-columns: 150px 1fr 34px; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 12.5px; }
.pctrow .k { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pctrow .track { height: 8px; border-radius: 4px; background: var(--bar-track); overflow: hidden; }
.pctrow .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.pctrow .n { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.extlinks { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.extlinks a {
  color: var(--accent); text-decoration: none; border: 1px solid var(--baseline);
  padding: 5px 10px; border-radius: 7px; font-size: 12.5px;
}
.extlinks a:hover { border-color: var(--accent); }

footer.app { margin-top: 26px; color: var(--muted); font-size: 12px; }
footer.app a { color: var(--accent); }

/* ----- map view ----- */
:root {
  --dot-a: #0f9d0f; --dot-b: #2a78d6; --dot-c: #d99400;
  --dot-d: #e06a30; --dot-f: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --dot-a: #35c135; --dot-b: #4d95ea; --dot-c: #eda100;
    --dot-d: #ee7c42; --dot-f: #e35d5d;
  }
}
.viewtoggle { display: flex; }
.viewtoggle button { border-radius: 0; }
.viewtoggle button:first-child { border-radius: 7px 0 0 7px; }
.viewtoggle button:last-child { border-radius: 0 7px 7px 0; border-left: none; }
.viewtoggle button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.mapbox { position: relative; }
#map { display: block; width: 100%; border-radius: 8px; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#maptip {
  position: absolute; z-index: 10; pointer-events: none;
  background: var(--surface); border: 1px solid var(--baseline); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2); padding: 8px 10px; font-size: 12.5px;
  max-width: 240px; line-height: 1.4;
}
.maplegend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.maplegend .li { display: flex; gap: 6px; align-items: center; }
.maplegend .sw { width: 10px; height: 10px; border-radius: 50%; }
.maplegend .gradbar { width: 180px; height: 10px; border-radius: 5px; border: 1px solid var(--border); }

/* ----- property analyzer ----- */
.navlink { color: var(--accent); text-decoration: none; font-size: 13.5px; }
.navlink:hover { text-decoration: underline; }
.ptitle { margin: 0 0 12px; font-size: 14px; color: var(--ink); }
.small { font-size: 12px; }

.verdict { border-width: 2px; }
.verdict .vtitle { font-size: 18px; font-weight: 700; }
.verdict .vwhy { margin-top: 6px; color: var(--ink-2); max-width: 75ch; }
.verdict.v-good { border-color: var(--good); }
.verdict.v-warn { border-color: var(--warning); }
.verdict.v-bad { border-color: var(--critical); }
.verdict.v-good .vtitle { color: #006300; }
.verdict.v-bad .vtitle { color: var(--critical); }
@media (prefers-color-scheme: dark) {
  .verdict.v-good .vtitle { color: var(--good); }
  .verdict.v-bad .vtitle { color: #e66767; }
}

.flags { margin-top: 12px; display: grid; gap: 8px; }
.flagrow {
  display: grid; grid-template-columns: 20px 64px 1fr; gap: 8px; align-items: start;
  font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--bar-track);
}
.flagrow .ficon { font-weight: 700; text-align: center; }
.flagrow .flabel { font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; margin-top: 1px; }
.flagrow.good .ficon, .flagrow.good .flabel { color: #006300; }
.flagrow.info .ficon, .flagrow.info .flabel { color: var(--accent); }
.flagrow.serious .ficon, .flagrow.serious .flabel { color: #a04a1d; }
.flagrow.critical .ficon, .flagrow.critical .flabel { color: var(--critical); }
@media (prefers-color-scheme: dark) {
  .flagrow.good .ficon, .flagrow.good .flabel { color: var(--good); }
  .flagrow.serious .ficon, .flagrow.serious .flabel { color: var(--serious); }
  .flagrow.critical .ficon, .flagrow.critical .flabel { color: #e66767; }
}
code { background: var(--bar-track); padding: 2px 6px; border-radius: 5px; font-size: 12.5px; }
