:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1d2330;
  --muted: #5f6878;
  --line: #d9dde4;
  --accent: #1f6feb;
  --good: #1a7f37;
  --bad: #c62828;
  --hot: #8b3dff;
  --hotring: #ffffff;
  --nodata: #d6d9de;
  --stateline: #ffffff;
  --countyline: rgba(255, 255, 255, 0.35);
  --sel: #111111;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b2029;
    --ink: #e7eaf0;
    --muted: #9aa3b2;
    --line: #2e3542;
    --accent: #58a6ff;
    --good: #3fb950;
    --bad: #ff6b6b;
    --hot: #b583ff;
    --hotring: #12151b;
    --nodata: #3a404b;
    --stateline: #12151b;
    --countyline: rgba(18, 21, 27, 0.35);
    --sel: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.2rem; margin: 0; white-space: nowrap; }
h2 { font-size: 1rem; margin: 0 0 .4rem; }
h3 { font-size: .9rem; margin: .8rem 0 .25rem; }
a { color: var(--accent); }
.ver { font-size: .72rem; font-weight: 500; color: var(--muted); }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .82rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.hot { color: var(--hot); }

/* ---------- header ---------- */
.top {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: flex-end; justify-content: space-between;
  padding: 8px 12px 6px;
}
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.controls label { display: flex; flex-direction: column; font-size: .72rem; color: var(--muted); gap: 1px; }
select, input, button {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
a.hdrlink { font-size: .78rem; text-decoration: none; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color: var(--ink); background: var(--card); white-space: nowrap; }
a.hdrlink:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- main grid ---------- */
.layout {
  flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 10px;
  padding: 0 12px 6px;
}
.mapcard, .side { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 0; }
.mapcard { display: flex; flex-direction: column; padding: 6px; }
#mapwrap { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#map path, #map circle { vector-effect: non-scaling-stroke; }
.county { stroke: var(--countyline); stroke-width: .4; cursor: pointer; }
.statefill { stroke: none; cursor: pointer; }
.statelines { fill: none; stroke: var(--stateline); stroke-width: 1.3; pointer-events: none; }
.selected { fill: none; stroke: var(--sel); stroke-width: 2.6; pointer-events: none; }
.hoverline { fill: none; stroke: var(--sel); stroke-width: 1.2; pointer-events: none; }
.hotdot { fill: var(--hot); fill-opacity: .9; stroke: var(--hotring); stroke-width: 1.5; cursor: pointer; }
.status { position: absolute; left: 8px; top: 4px; margin: 0; font-size: .85rem; color: var(--muted); }
.status.err { color: var(--bad); }

/* ---------- legend ---------- */
.legendbox { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 5px 4px 0; font-size: .76rem; color: var(--muted); }
.legrow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-bottom: 3px; }
.legtitle { color: var(--ink); font-weight: 600; }
.legend { display: inline-flex; flex-wrap: wrap; align-items: flex-start; gap: 0; }
.legend .end { margin: 0 8px; line-height: 11px; }
.sw { display: inline-block; width: 30px; height: 11px; border-radius: 2px; vertical-align: middle; }
.sw.nodata { width: 14px; background: var(--nodata); }
.legend .sw { width: 44px; border-radius: 0; }
.legend .cell { display: inline-flex; flex-direction: column; gap: 1px; }
.legend .cell:first-of-type .sw { border-radius: 2px 0 0 2px; }
.legend .end ~ .cell:last-of-type .sw { border-radius: 0 2px 2px 0; }
.legend .lab { text-align: right; transform: translateX(50%); white-space: nowrap; font-variant-numeric: tabular-nums; font-size: .72rem; }
.key { display: inline-flex; align-items: center; gap: 5px; }
.key b { color: var(--ink); }
.keyline { stroke: var(--muted); stroke-width: 2; }
.keysel { fill: none; stroke: var(--sel); stroke-width: 2; }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tabs button {
  flex: 1; border: none; border-radius: 0; background: none; padding: 8px 2px; color: var(--muted); font-size: .84rem;
  border-bottom: 2px solid transparent; font-weight: 600;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.panel { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 10px 12px; }
.panel[hidden] { display: none; }

.stats { width: 100%; border-collapse: collapse; font-size: .84rem; margin: .2rem 0 .4rem; }
.stats td { padding: 2px 0; border-bottom: 1px solid var(--line); }
.stats td:nth-child(2), .stats td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; padding-left: 6px; }
.stats th { text-align: right; font-weight: 500; font-size: .72rem; color: var(--muted); }
.stats .strong td { font-weight: 600; }
.badge { display: inline-block; background: var(--hot); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: .75rem; font-weight: 600; margin: 0 0 .3rem; }
.scorebox { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin: .3rem 0 .5rem; font-size: .84rem; }
.scorebox b { font-size: .95rem; }
.roigrid .wide { grid-column: 1 / -1; margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: .84rem; }
.linkhead { font-size: .74rem; color: var(--muted); margin: .45rem 0 .1rem; }
.btnrow { margin-top: .5rem; }

.toplist { margin: 0; padding-left: 1.7rem; }
.toplist li { padding: 2px 0; font-size: .86rem; }
.toplist button { background: none; border: none; padding: 0; color: var(--accent); text-align: left; }
.toplist button:hover { text-decoration: underline; }
.toplist .v { float: right; color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 8px; }
.toplist .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--hot); margin-right: 5px; vertical-align: middle; }

.roigrid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.roigrid h3 { grid-column: 1 / -1; margin: .45rem 0 0; font-size: .8rem; }
.roigrid label { display: flex; flex-direction: column; font-size: .72rem; color: var(--muted); gap: 1px; }
.roigrid input { width: 100%; text-align: right; padding: 3px 6px; }
.roigrid label.wide { grid-column: 1 / -1; }
.roigrid [hidden] { display: none !important; }
.results h3 { font-size: .84rem; margin: .6rem 0 .2rem; }
.results table.proj { margin-bottom: .4rem; }
.results table.proj th { font-size: .7rem; color: var(--muted); font-weight: 500; text-align: right; }
.results table.proj th:first-child, .results table.proj td:first-child { text-align: left; }
.results table.proj td { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- printable deal report ---------- */
.report[hidden] { display: none; }
@media print {
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; color: #000 !important; }
  body > *:not(#report) { display: none !important; }
  #report { display: block !important; font: 11pt/1.35 system-ui, "Segoe UI", sans-serif; color: #000; }
  #report h1 { font-size: 18pt; margin: 0 0 4pt; }
  #report h2 { font-size: 12.5pt; margin: 12pt 0 4pt; border-bottom: 1px solid #999; }
  #report table { width: 100%; border-collapse: collapse; margin-bottom: 6pt; }
  #report td, #report th { padding: 2pt 4pt; border-bottom: 1px solid #ddd; text-align: left; }
  #report td:last-child { text-align: right; }
  #report table.proj td, #report table.proj th { text-align: right; }
  #report table.proj td:first-child, #report table.proj th:first-child { text-align: left; }
  #report .good { color: #11632a; }
  #report .bad { color: #a11; }
  #report .small { font-size: 8.5pt; color: #444; margin-top: 10pt; }
}
.roigrid select { width: 100%; padding: 3px 6px; }
.results { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.results table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.results td { padding: 1px 0; }
.results td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.results .sep td { border-top: 1px solid var(--line); padding-top: 3px; }
.verdict { margin: .35rem 0 0; font-size: .84rem; }

.foot { flex: 0 0 auto; padding: 0 12px 6px; color: var(--muted); font-size: .72rem; }

/* ---------- listings ---------- */
button.usage { font-size: .78rem; padding: 5px 9px; }
button.usage.low { border-color: var(--bad); color: var(--bad); }
.pin { stroke: #111; stroke-width: 1; cursor: pointer; }
.pin.on { stroke: var(--sel); stroke-width: 2.5; }
.keypin { fill: #4caf50; }
.zipdot { stroke: #fff; stroke-width: 1; cursor: default; }
.keyzip { fill: #d9ef8b; stroke: #333; }
.key input { margin: 0; }
.ziptable .stats td:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.ziptable .stats td:nth-child(n+2) { text-align: right; padding-left: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ziptable .stats th:first-child { text-align: left; }
.area { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: 5 4; pointer-events: none; }
.area.saved { stroke: var(--muted); stroke-width: .8; stroke-dasharray: 2 3; opacity: .7; }
.fetchbox { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.fetchbox h3 { margin: 0 0 .3rem; font-size: .88rem; }
.fetchbox .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; font-size: .8rem; }
.fetchbox input[type=password], .fetchbox input[type=text] { width: 120px; padding: 3px 6px; }
.fetchbox .msg { font-size: .8rem; margin: .3rem 0 0; }
.fetchbox .msg.err { color: var(--bad); }
.fetchbox .msg.okmsg { color: var(--good); }
.filters { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; font-size: .82rem; }
.filters summary { cursor: pointer; font-weight: 600; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 6px 0; }
.fgrid label { display: flex; flex-direction: column; font-size: .72rem; color: var(--muted); gap: 1px; }
.fgrid input, .fgrid select { width: 100%; padding: 3px 6px; }
button.small { font-size: .76rem; padding: 2px 8px; }
.repairbox, .afford { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin: 4px 0; font-size: .82rem; }
#repairbox:empty { display: none; }
.rpitems { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; margin: 4px 0; font-size: .78rem; }
.roigrid .rpitems label.cmp { display: flex; flex-direction: row; align-items: center; gap: 5px; color: var(--ink); font-size: .78rem; }
.roigrid .rpitems input[type=checkbox] { width: auto; margin: 0; }
.roigrid .repairbox select, .roigrid .repairbox input[type=number] { width: 100%; }
.afford table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.afford td:last-child { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 8px; }
.watchbox { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; }
.watchbox h3 { margin: 0 0 .2rem; font-size: .88rem; }
.watchbox input[type=email] { flex: 1; min-width: 0; padding: 3px 6px; }
.watchlist { margin: 4px 0; padding-left: 1.1rem; font-size: .82rem; }
.watchlist li { margin: 2px 0; }
button.star { padding: 1px 8px; font-size: .78rem; }
button.star.on { color: #e3a008; border-color: #e3a008; }
#savedbox .row { display: flex; gap: 6px; margin: 6px 0; }
#savedbox input[type=password] { width: 140px; }
textarea.note { width: 100%; margin-top: 3px; font: inherit; font-size: .8rem; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; resize: vertical; }
label.cmp { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
table.compare { font-size: .76rem; }
table.compare th { text-align: right; font-size: .7rem; }
table.compare td:nth-child(n+2) { text-align: right; padding-left: 6px; }
.listhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.listhead label { display: flex; flex-direction: column; font-size: .72rem; color: var(--muted); }
.listings { list-style: none; margin: 4px 0 0; padding: 0; }
.listings li { border-bottom: 1px solid var(--line); padding: 5px 2px; font-size: .8rem; }
.listings li.on { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.listings .l1 { display: flex; justify-content: space-between; gap: 6px; font-weight: 600; font-size: .84rem; }
.listings .l2 { color: var(--muted); }
.listings .l3 { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; margin-top: 2px; }
.listings .l3 button { padding: 1px 7px; font-size: .76rem; }
.listings .addr { cursor: pointer; }
.listings .addr:hover { text-decoration: underline; }

/* ---------- tooltip & guide ---------- */
.tip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: .8rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18); max-width: 260px;
}
.tip b { display: block; }
.tip .hot { font-weight: 600; }
.guide {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
}
.guide::backdrop { background: rgba(0, 0, 0, .55); }
.guidehead {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; margin: 0;
}
.guidehead h2 { margin: 0; font-size: 1.1rem; }
.costdlg { width: min(460px, calc(100vw - 32px)); background: var(--card); color: var(--ink);
  border: 2px solid #e3a008; border-radius: 12px; padding: 14px 18px; }
.costdlg.low { border-color: var(--bad); }
.costdlg::backdrop { background: rgba(0, 0, 0, .55); }
.costdlg h2 { margin: 0 0 .4rem; font-size: 1.05rem; color: #e3a008; }
.costdlg.low h2 { color: var(--bad); }
.costdlg p { font-size: .88rem; margin: .4rem 0; }
.costdlg .stats td:first-child { color: var(--muted); width: 60px; vertical-align: top; }
.costdlg .stats td:nth-child(2) { text-align: left; }
.costbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.gtabs { display: flex; gap: 4px; }
.gtabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; font-weight: 600; padding: 4px 8px; color: var(--muted); }
.gtabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.guidebody[hidden] { display: none; }
.notes h3 { border-bottom: 1px solid var(--line); padding-bottom: 2px; }
button.ver { background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline dotted; }
.guidebody { padding: 4px 18px 16px; }
.guidebody section { margin-top: .6rem; }
.guidebody h3 { font-size: .98rem; margin: .8rem 0 .3rem; }
.guidebody p, .guidebody li, .guidebody dd { font-size: .9rem; }
.guidebody dt { font-weight: 600; font-size: .88rem; margin-top: .35rem; }
.guidebody dd { margin: 0 0 0 1rem; color: var(--muted); }

/* ---------- small screens: allow scrolling ---------- */
@media (max-width: 900px), (max-height: 560px) {
  body { overflow: auto; height: auto; }
  html, body { height: auto; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  #mapwrap { height: 62vw; min-height: 260px; }
  .side { max-height: none; }
  .panel { overflow: visible; }
}
