:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1d2321;
  --muted: #5d6662;
  --line: #ded9cf;
  --brand: #0f5f5c;
  --brand-ink: #ffffff;
  --accent: #d9622b;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --closed: #8a8f8c;
  --exact: #0f5f5c;
  --approx: #d9622b;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(20, 30, 28, 0.12);
  --topbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615;
    --surface: #1a201e;
    --surface-2: #232a28;
    --text: #e8ecea;
    --muted: #9aa5a0;
    --line: #2f3835;
    --brand: #3fb0a8;
    --brand-ink: #08201e;
    --accent: #f08a57;
    --ok: #5cc38a;
    --warn: #e0a440;
    --closed: #7b8380;
    --exact: #3fb0a8;
    --approx: #f08a57;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121615; --surface: #1a201e; --surface-2: #232a28; --text: #e8ecea; --muted: #9aa5a0;
  --line: #2f3835; --brand: #3fb0a8; --brand-ink: #08201e; --accent: #f08a57; --ok: #5cc38a;
  --warn: #e0a440; --closed: #7b8380; --exact: #3fb0a8; --approx: #f08a57; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 18px; }
.brand .sub { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--brand); color: var(--brand-ink); }

/* Layout: desktop = list | map, calculator as its own view */
.layout { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.panel { background: var(--surface); overflow: auto; }
.list-panel { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.calc-panel { display: none; padding: 20px; grid-column: 1 / -1; }
.layout[data-view="calc"] .list-panel,
.layout[data-view="calc"] .map-wrap { display: none; }
.layout[data-view="calc"] .calc-panel { display: block; }
.layout[data-view="calc"] { grid-template-columns: 1fr; }
.calc-panel > * { max-width: 880px; margin-left: auto; margin-right: auto; }

/* Filters */
.filters { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
input[type="search"], input[type="number"], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
.row { display: flex; gap: 8px; align-items: center; }
.loc { display: grid; gap: 8px; }
select:disabled { opacity: .55; cursor: not-allowed; }
.row > * { flex: 1; min-width: 0; }
.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.inline select { flex: 1; }
.inline.check { gap: 6px; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); cursor: pointer;
}
.count { text-align: right; font-size: 13px; color: var(--muted); flex: 0 0 auto; }

/* Results */
.results { list-style: none; margin: 0; padding: 0; }
.results li { border-bottom: 1px solid var(--line); }
.card { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; padding: 12px 14px; cursor: pointer; }
.card:hover, .card:focus-visible { background: var(--surface-2); outline: none; }
.card .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.price { font-weight: 700; font-size: 17px; }
.price small { font-weight: 500; font-size: 12px; color: var(--muted); }
.card .addr { font-size: 13px; color: var(--muted); margin-top: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.tag.open { color: var(--ok); border-color: currentColor; }
.tag.soon { color: var(--warn); border-color: currentColor; }
.tag.closed { color: var(--closed); }
.more { padding: 12px; text-align: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* Map */
.legend {
  position: absolute; left: 10px; bottom: 34px; z-index: 500; background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); display: flex; gap: 12px;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; }
.dot.exact { background: var(--exact); }
.dot.approx { background: var(--approx); border: 2px dashed var(--surface); }
.pin {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.pin.exact { background: var(--exact); }
.pin.approx { background: var(--approx); opacity: .85; }
.leaflet-popup-content { margin: 10px 12px; font: 14px/1.4 system-ui, sans-serif; }
.popup b { font-size: 16px; }
.popup .btn { min-height: 32px; padding: 4px 10px; margin-top: 8px; font-size: 13px; }

.report-bar {
  position: absolute; top: 10px; left: 56px; right: 10px; z-index: 600; display: flex; flex-wrap: wrap;
  gap: 8px 12px; align-items: center; justify-content: space-between; background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); font-size: 14px;
}
.report-bar[hidden] { display: none; }
.report-msg { flex: 1 1 220px; }
.report-whole { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.report-bar .hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
#reportCheck:empty { display: none; }
.report-actions { display: flex; gap: 8px; }
.report-actions .btn { min-height: 36px; padding: 6px 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
#map.picking { cursor: crosshair; }
.note .actions { margin-top: 8px; }

/* Bottom sheet / dialog */
.sheet { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet[hidden] { display: none; }
.sheet-card {
  position: relative; width: min(560px, 100%); max-height: 88vh; overflow: auto; background: var(--surface);
  border-radius: 16px; padding: 20px; box-shadow: var(--shadow);
}
.close { position: absolute; top: 8px; right: 10px; border: 0; background: none; color: var(--muted); font-size: 28px; cursor: pointer; line-height: 1; padding: 6px; }
.detail h2 { font-size: 20px; padding-right: 30px; }
.detail .big { font-size: 26px; font-weight: 800; margin: 8px 0 0; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 12px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1 1 160px; }

/* Calculator */
.calc-panel h2 { margin-bottom: 4px; }
.calc-panel h3 { margin: 24px auto 8px; }
.calc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin-top: 16px; }
.calc-grid label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.calc-grid output { font-weight: 700; color: var(--brand); margin-left: 6px; }
input[type="range"] { width: 100%; accent-color: var(--brand); min-height: 28px; }
.assumptions { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.assumptions summary { cursor: pointer; font-weight: 600; }
.assumptions label { margin-top: 10px; }
.calc-out { margin-top: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.hero { background: var(--brand); color: var(--brand-ink); }
.stat.hero .k, .stat.hero .s { color: inherit; opacity: .85; }
.limits { grid-column: 1 / -1; font-size: 14px; }
.limits ul { margin: 6px 0 0; padding-left: 18px; }
.limits li.bind { font-weight: 700; }
.warn { color: var(--warn); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.compare { width: 100%; border-collapse: collapse; font-size: 14px; }
.compare th, .compare td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.compare th:first-child, .compare td:first-child { text-align: left; }
.compare tr.sel td { background: var(--surface-2); font-weight: 700; }

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

/* Phone */
@media (max-width: 760px) {
  :root { --topbar-h: auto; }
  .topbar { flex-direction: column; align-items: stretch; padding: 10px 16px 8px; gap: 8px; }
  .tabs { justify-content: space-between; }
  .tabs button { flex: 1; padding: 8px 6px; }
  .layout { grid-template-columns: 1fr; }
  .layout[data-view="map"] .list-panel { display: none; }
  .layout[data-view="list"] .map-wrap { display: none; }
  .layout[data-view="list"] .list-panel { border-right: 0; }
  .map-wrap { min-height: 60vh; }
  .calc-panel { padding: 16px; }
  .calc-grid { grid-template-columns: 1fr; }
  .calc-out { grid-template-columns: 1fr 1fr; }
  .calc-out .stat.hero { grid-column: 1 / -1; }
  .legend { flex-direction: column; gap: 2px; bottom: 46px; }
  .report-bar { left: 10px; top: 92px; }
  .sheet { align-items: flex-end; padding: 0; }
  .sheet-card { border-radius: 16px 16px 0 0; max-height: 85vh; }
  .foot { font-size: 11px; padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); }
  .foot .long { display: none; }
}
@media (min-width: 761px) {
  .tabs button[data-view="list"] { display: none; }
  .layout[data-view="list"] { grid-template-columns: 380px 1fr; }
}
