:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #5d636e;
  --line: #dcdfe4;
  --accent: #2b59c3;
  --shadow: 0 2px 10px rgba(0, 0, 0, .12);
  --pin: #1d1f23;
  --neutral: #f2f0eb;
  --cheap: #2166ac;
  --pricey: #b2182b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --surface: #1f2228; --text: #e8eaed; --muted: #9aa1ad; --line: #343843;
    --accent: #7ea2ff; --shadow: 0 2px 12px rgba(0, 0, 0, .5); --pin: #ffffff; --neutral: #3a3d44;
    --cheap: #4393c3; --pricey: #d6604d;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --surface: #1f2228; --text: #e8eaed; --muted: #9aa1ad; --line: #343843;
  --accent: #7ea2ff; --shadow: 0 2px 12px rgba(0, 0, 0, .5); --pin: #ffffff; --neutral: #3a3d44;
  --cheap: #4393c3; --pricey: #d6604d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; }

.bar {
  display: flex; gap: 12px; align-items: center; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); z-index: 1001;
}
.brand { font-weight: 650; white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 460px; }
.search input, .salary input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.search input:focus, .salary input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
#suggest li { padding: 7px 9px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#suggest li small { color: var(--muted); }
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--bg); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--bg); flex-shrink: 0; }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.seg button:focus-visible { outline: 2px solid var(--accent); }
.salary { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.salary .money { position: relative; width: 120px; }
.salary .money::before { content: "$"; position: absolute; left: 9px; top: 8px; color: var(--muted); }
.salary input { padding-left: 20px; }

#map { flex: 1; background: var(--bg); }
.leaflet-container { background: var(--bg); font: inherit; }

.panel {
  position: absolute; left: 16px; bottom: 24px; z-index: 1000; width: 280px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 12px 14px;
}
#status { margin-bottom: 10px; }
#status .origin { font-weight: 650; font-size: 15px; }
#status .sub { color: var(--muted); font-size: 12.5px; }
.ramp { height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--cheap), var(--neutral), var(--pricey)); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.cap { color: var(--muted); font-size: 12px; margin-top: 4px; }
.link { background: none; border: 0; padding: 0; margin-top: 8px; color: var(--accent); cursor: pointer; text-decoration: underline; }

/* map labels */
.lbl { background: none; border: 0; }
.lbl button {
  transform: translate(-50%, -50%); position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap;
  padding: 2px 7px; border-radius: 11px; border: 1px solid rgba(0, 0, 0, .25);
  font-size: 12px; font-weight: 650; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  font-variant-numeric: tabular-nums; line-height: 16px;
}
.lbl button .nm { font-weight: 500; }
.lbl button:hover { outline: 2px solid var(--text); }
.lbl.town button, .lbl.rural button { font-size: 11px; padding: 1px 6px; border: 1px dashed var(--text); }
.lbl.state button, .lbl.rural button { cursor: zoom-in; }
.lbl.origin button { outline: 2px solid var(--text); }
.leader { stroke: var(--muted); }
.pin { background: none; border: 0; }
.pin svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.sheet {
  position: relative; background: var(--surface); color: var(--text); border-radius: 12px;
  box-shadow: var(--shadow); max-width: 640px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 20px 22px;
}
.close { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.sheet h2 { margin: 0 28px 2px 0; font-size: 18px; }
.sheet .basis { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.headline { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { flex: 1; min-width: 170px; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12px; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
table.bd { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.bd th, table.bd td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
table.bd th:first-child, table.bd td:first-child { text-align: left; }
table.bd th { font-size: 11.5px; color: var(--muted); font-weight: 600; }
table.bd td small { display: block; color: var(--muted); font-size: 11.5px; }
.bar2 { position: relative; width: 110px; height: 10px; margin-left: auto; }
.bar2::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; border-left: 1px solid var(--muted); }
.bar2 i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.up { color: var(--pricey); } .down { color: var(--cheap); }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.sources { font-size: 12.5px; padding-left: 18px; margin: 4px 0 0; }
.sources li { margin: 3px 0; }
.sources a { color: var(--accent); }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; padding: 8px 16px; }
  .brand { display: none; }
  .search { max-width: none; flex-basis: 100%; }
  .salary .money { width: 110px; }
  .panel { left: 16px; right: 16px; width: auto; bottom: 16px; padding: 10px 12px; }
  .sheet { padding: 16px; }
  .bar2 { width: 60px; }
}

/* compare */
.bar { align-items: flex-start; }
.bar > .brand, .bar > .seg, .bar > .salary, .bar > .btn { margin-top: 2px; }
.cmprow { position: relative; margin-top: 6px; }
.cmprow[hidden] { display: none; }
.cmprow input { border-color: var(--accent); }
#suggest2 {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; z-index: 5;
  list-style: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
#suggest2 li { padding: 7px 9px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#suggest2 li small { color: var(--muted); }
#suggest2 li[aria-selected="true"], #suggest2 li:hover { background: var(--bg); }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); }
#status .cmp { margin: 4px 0 2px; font-size: 13px; }
#status .cmp .link { margin: 0; }
.rhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 28px 6px 0; }
.eyebrow { color: var(--muted); font-size: 12px; }
.printBtn { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; }

@media print {
  .bar, #map, .panel, .close, .printBtn { display: none !important; }
  body { background: #fff; color: #000; display: block; }
  .modal { position: static; background: none; padding: 0; display: block; }
  .sheet { box-shadow: none; max-height: none; max-width: none; overflow: visible; background: #fff; color: #000; }
  .stat { background: #f3f3f3; }
}
@media (max-width: 640px) {
  .bar { align-items: center; }
  .btn { padding: 6px 10px; }
}
.sheet:focus { outline: none; }

/* right-click menu */
.ctx { position: absolute; z-index: 1100; min-width: 190px; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.ctx[hidden] { display: none; }
.ctx-h { padding: 6px 9px 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 9px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.ctx button:hover, .ctx button:focus-visible { background: var(--bg); outline: none; }
