:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #16191d;
  --muted: #5d6673;
  --accent: #2f6fdf;
  --accent-soft: #e5eefc;
  --fit: #13875a;
  --fit-soft: #e1f4eb;
  --match: #d08a16;
  --warn: #b4452f;
  --warn-soft: #fbe9e5;
  --star: #e2a400;
  --gone: #8b929c;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 10px;
  --top-h: auto;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e8ebef;
    --muted: #9aa3ae;
    --accent: #6b9cf2;
    --accent-soft: #1d2a40;
    --fit: #3cc58a;
    --fit-soft: #15301f;
    --match: #e8a93c;
    --warn: #ef8a74;
    --warn-soft: #3a211b;
    --star: #f2c230;
    --gone: #6f7782;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --border: #2c333d; --text: #e8ebef;
  --muted: #9aa3ae; --accent: #6b9cf2; --accent-soft: #1d2a40; --fit: #3cc58a; --fit-soft: #15301f;
  --match: #e8a93c; --warn: #ef8a74; --warn-soft: #3a211b; --star: #f2c230; --gone: #6f7782;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

/* ---- header ---- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 3;
}
.brand h1 { font-size: 17px; }
.summary { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-left: auto; }
.filters fieldset { border: 0; margin: 0; padding: 0; display: flex; gap: 4px; }
.chips label, .toggle { position: relative; cursor: pointer; }
.chips input, .toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chips span, .toggle span {
  display: inline-block; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted); white-space: nowrap; user-select: none;
}
.chips input:checked + span, .toggle input:checked + span {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600;
}
.chips input:focus-visible + span, .toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.field input, .field select {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
.field input[type="number"] { width: 84px; }

/* ---- panes ---- */
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 0.9fr); }
.map-pane { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.list-pane { overflow-y: auto; padding: 12px; border-left: 1px solid var(--border); scroll-behavior: smooth; }
.panes-switch { display: none; }

.legend {
  position: absolute; left: 10px; bottom: 28px; display: flex; flex-wrap: wrap; gap: 4px 12px; max-width: calc(100% - 20px);
  padding: 6px 10px; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.fit { background: var(--fit); } .sw.match { background: var(--match); }
.sw.other { background: #9aa3ae; } .sw.ring { border: 2px dashed var(--accent); border-radius: 50%; }

.bldg-pin {
  display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 4px; border-radius: 999px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.bldg-pin b { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 11px; }
.bldg-pin.has-fit b { background: var(--fit); color: #fff; }
.bldg-pin.has-match b { background: var(--match); color: #fff; }
.bldg-pin.forma { border-color: var(--accent); }
.bldg-pin.forma::after { content: "♥"; color: var(--accent); }
.bldg-pin.active { outline: 2px solid var(--accent); }

.maplibregl-popup-content { background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { display: none; }

/* ---- building cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; scroll-margin-top: 12px;
}
.card.active { outline: 2px solid var(--accent); }
.card-head { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px 8px; cursor: pointer; }
.card-head h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-sub { color: var(--muted); font-size: 12.5px; }
.card-stats { text-align: right; font-size: 12.5px; color: var(--muted); }
.card-stats .walk { font-weight: 600; color: var(--text); }
.stars { color: var(--star); letter-spacing: -1px; }
.tier { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.tier.best { background: var(--fit-soft); color: var(--fit); }
.tier.good { background: var(--accent-soft); color: var(--accent); }
.tier.mixed { background: var(--surface-2); color: var(--muted); }
.tier.poor { background: var(--warn-soft); color: var(--warn); }
.tier.unknown { background: var(--surface-2); color: var(--muted); }
.you-are-here { font-size: 11px; font-weight: 600; color: var(--accent); }

.sentiment { padding: 0 14px 10px; font-size: 13px; }
.sentiment summary { cursor: pointer; color: var(--muted); list-style: none; }
.sentiment summary::-webkit-details-marker { display: none; }
.sentiment summary::before { content: "▸ "; }
.sentiment[open] summary::before { content: "▾ "; }
.sentiment .verdict { color: var(--text); }
.pc { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.pc h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }
.pc ul { margin: 0; padding-left: 16px; }
.pc li { margin-bottom: 2px; }
.pc .sources { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* ---- unit rows ---- */
.units { border-top: 1px solid var(--border); }
.unit {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
  padding: 9px 14px; border-bottom: 1px solid var(--border); cursor: pointer; background: none; border-left: 0;
  border-right: 0; border-top: 0; width: 100%; text-align: left;
}
.unit:last-child { border-bottom: 0; }
.unit:hover, .unit:focus-visible { background: var(--surface-2); outline: none; }
.unit.selected { background: var(--accent-soft); }
.unit.gone { opacity: .55; }
.unit .thumb { width: 56px; height: 42px; object-fit: contain; background: #fff; border-radius: 4px; border: 1px solid var(--border); grid-row: span 2; }
.unit .l1 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.unit .no { font-weight: 700; }
.unit .plan { color: var(--muted); font-size: 12.5px; }
.unit .l2 { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.unit .price { text-align: right; grid-row: span 2; }
.unit .price b { font-size: 15px; display: block; }
.unit .price small { color: var(--muted); font-size: 11.5px; }
.badge { font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 999px; line-height: 18px; white-space: nowrap; }
.badge.fit { background: var(--fit-soft); color: var(--fit); }
.badge.nofit { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.badge.new { background: var(--accent-soft); color: var(--accent); }
.badge.down { background: var(--fit-soft); color: var(--fit); }
.badge.up { background: var(--warn-soft); color: var(--warn); }
.badge.gone { background: var(--surface-2); color: var(--gone); }
.badge.star { color: var(--star); padding: 0; }
.badge.tour { background: var(--surface-2); color: var(--text); }
.no-match { padding: 10px 14px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }
.more { padding: 8px 14px; border: 0; border-top: 1px solid var(--border); width: 100%; background: none; color: var(--accent); cursor: pointer; text-align: left; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---- drawer ---- */
.drawer { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.drawer-scrim { position: absolute; inset: 0; background: rgb(0 0 0 / 35%); opacity: 0; transition: opacity .15s; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--surface);
  box-shadow: var(--shadow); transform: translateX(100%); transition: transform .18s ease-out; overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.open { pointer-events: auto; }
.drawer.open .drawer-scrim { opacity: 1; }
.drawer.open .drawer-panel { transform: none; }
.d-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.d-head h2 { font-size: 17px; flex: 1; }
.d-head .sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 10px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.starred { color: var(--star); border-color: var(--star); }
.d-body { padding: 14px 16px 40px; display: grid; gap: 18px; }
.d-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.keyfacts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.keyfacts div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.keyfacts b { display: block; font-size: 16px; }
.keyfacts span { font-size: 12px; color: var(--muted); }
.media { display: grid; gap: 10px; }
.media img { width: 100%; background: #fff; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.media figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.media figure { margin: 0; }
.tour-frame { width: 100%; aspect-ratio: 16 / 10; border: 0; border-radius: 8px; background: var(--surface-2); }
.tour-cta { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
table.fees { width: 100%; border-collapse: collapse; font-size: 13px; }
table.fees td { padding: 5px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
table.fees td:last-child { text-align: right; white-space: nowrap; padding-left: 12px; }
table.fees tr.total td { font-weight: 700; border-bottom: 0; }
table.fees .muted, .muted { color: var(--muted); }
.fees-sub { font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.quote { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quote input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.quote-result { margin-top: 8px; font-size: 13px; }
.window-bar { position: relative; height: 26px; margin: 6px 0 2px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.window-bar .span { position: absolute; top: 0; bottom: 0; background: var(--fit-soft); border-left: 2px solid var(--fit); border-right: 2px solid var(--fit); }
.window-bar .target { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--accent); }
.window-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.history { font-size: 13px; }
.history svg { width: 100%; height: 60px; display: block; }
.history ol { margin: 6px 0 0; padding-left: 18px; }
.notes-list { display: grid; gap: 8px; margin-bottom: 8px; }
.note { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.note header { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.note button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.note-form { display: flex; gap: 8px; }
.note-form textarea { flex: 1; min-height: 38px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); resize: vertical; font: inherit; }
.amenities { display: flex; flex-wrap: wrap; gap: 5px; }
.amenities span { font-size: 12px; background: var(--surface-2); padding: 2px 8px; border-radius: 999px; }
.disclaimer { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }

.lightbox { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 85%); display: grid; place-items: center; padding: 20px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }
.lightbox .icon-btn { position: absolute; top: 14px; right: 14px; }

.gate { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.gate[hidden] { display: none; }
.gate-card { max-width: 380px; text-align: center; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 18px; width: min(360px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog h2 { font-size: 16px; margin-bottom: 6px; }
dialog p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
dialog input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
dialog menu button { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
dialog menu .primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- phones: one pane at a time ---- */
@media (max-width: 860px) {
  .top { padding: 10px 16px; }
  .filters { margin-left: 0; overflow-x: auto; flex-wrap: nowrap; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  .filters > * { flex: none; }
  .panes-switch { display: flex; gap: 4px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .panes-switch button { flex: 1; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
  .panes-switch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
  .panes { grid-template-columns: 1fr; }
  .panes[data-pane="list"] .map-pane { display: none; }
  .panes[data-pane="map"] .list-pane { display: none; }
  .list-pane { border-left: 0; padding: 12px 16px; }
  .keyfacts { grid-template-columns: repeat(2, 1fr); }
  .pc { grid-template-columns: 1fr; }
}
.list-note { margin: 0 2px 10px; font-size: 12px; color: var(--muted); }
