:root {
  --bg: #ffffff;
  --fill: #f5f5f7;
  --fill2: #ebebf0;
  --line: #e5e5ea;
  --text: #1d1d1f;
  --text2: #6e6e73;
  --text3: #8e8e93;
  --accent: #0066cc;
  --accent-soft: #e8f1fc;
  --good: #188038;
  --good-mid: #5bb974;
  --good-soft: #e6f4ea;
  --mid: #8e8e93;
  --weak: #c7c7cc;
  --bad: #d70015;
  --bad-soft: #fdecee;
  --r: 10px;
  --side: 448px;
  --top: 56px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.top {
  height: var(--top); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 0 24px; border-bottom: 1px solid var(--line); background: var(--bg);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 16px; min-width: 0; }
.brand .name { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand .meta { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; }
.pill {
  height: 32px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font-size: 13px; white-space: nowrap;
}
.pill b { font-weight: 600; font-variant-numeric: tabular-nums; }
.pill:hover { background: var(--fill); }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#newBtn b { color: var(--accent); }
#newBtn[aria-pressed="true"] b { color: #fff; }
.only-phone { display: none; }

/* ---- layout ---- */
.layout { display: flex; height: calc(100% - var(--top)); }
.side {
  width: var(--side); flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line);
  min-height: 0; position: relative; background: var(--bg);
}
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #f2f3f0; }

/* ---- tick rows: type + price ---- */
.ticks { padding: 16px 16px 4px 24px; display: flex; flex-direction: column; gap: 12px; }
.tlbl { font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.tset { display: grid; gap: 6px; }
.tset.t4 { grid-template-columns: repeat(4, 1fr); }
.tset.t5 { grid-template-columns: repeat(5, 1fr); }
.tick { position: relative; cursor: pointer; }
.tick input { position: absolute; opacity: 0; pointer-events: none; }
.tick span {
  height: 32px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 999px; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tick:hover span { background: var(--fill); }
.tick input:checked + span { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.tick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- filters ---- */
.filters { padding: 12px 16px 8px 24px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font-size: 13px; white-space: nowrap;
}
.chip:hover { background: var(--fill); }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip .caret { width: 8px; height: 8px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); opacity: 0.6; margin-left: 2px; }

.pop {
  position: fixed; z-index: 20; width: 320px; background: var(--bg); border-radius: 16px; padding: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.04); overflow-y: auto; overscroll-behavior: contain;
}
.pop.wide { width: 360px; padding-bottom: 0; }
.msec + .msec { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.opts.sep { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.pop-foot {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between;
  margin: 16px -16px 0; padding: 12px 16px; background: var(--bg); border-top: 1px solid var(--line);
}
.linkbtn:disabled { color: var(--text3); cursor: default; }
.chip:focus-visible, .pill:focus-visible, .btn:focus-visible, .back:focus-visible, .linkbtn:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.pop h4 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text2); }
.pop .opts { display: flex; flex-direction: column; gap: 2px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; font-size: 15px; cursor: pointer; }
.opt:hover { background: var(--fill); }
.opt input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.opt .n { margin-left: auto; color: var(--text3); font-size: 13px; font-variant-numeric: tabular-nums; }
.range { display: flex; align-items: center; gap: 8px; }
.range input {
  width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font-size: 15px;
  font-variant-numeric: tabular-nums; background: var(--bg);
}
.range input:focus, .sort select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.range span { color: var(--text3); }
.hint { margin-top: 8px; font-size: 13px; color: var(--text3); }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 4px 0; font-size: 13px; }

/* ---- results ---- */
.results-bar {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 8px 24px;
  border-bottom: 1px solid var(--line); font-size: 13px; color: var(--text2);
}
.count { font-variant-numeric: tabular-nums; }
.sort { display: flex; align-items: center; gap: 8px; }
.sort select { border: 0; background: var(--fill); border-radius: 8px; height: 28px; padding: 0 8px; font-size: 13px; color: var(--text); }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.empty { padding: 48px 24px; text-align: center; color: var(--text2); font-size: 15px; }
.empty b { display: block; color: var(--text); font-size: 17px; font-weight: 600; margin-bottom: 4px; }

.card {
  display: grid; grid-template-columns: 120px 1fr; gap: 16px; padding: 16px 16px 16px 24px;
  border-bottom: 1px solid var(--line); cursor: pointer; position: relative;
}
.card:hover, .card.hl { background: var(--fill); }
.card.faded .ph, .card.faded .info { opacity: 0.55; }
.ph { width: 120px; height: 90px; border-radius: 8px; background: var(--fill2) center / cover no-repeat; }
.info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.line1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.price { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.price.none { color: var(--text3); font-weight: 400; font-size: 15px; }
.sub { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place, .facts { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: var(--fill); color: var(--text2); }
.tag.new { background: var(--accent-soft); color: var(--accent); }
.tag.drop { background: var(--good-soft); color: var(--good); }
.tag.risk3 { background: var(--bad-soft); color: var(--bad); }
.heart { position: absolute; top: 12px; left: 112px; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.92); display: grid; place-items: center; }
.heart svg { width: 14px; height: 14px; fill: var(--bad); }

.score {
  flex: none; min-width: 40px; height: 24px; border-radius: 999px; display: inline-grid; place-items: center;
  padding: 0 8px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.s4 { background: var(--good); color: #fff; }
.s3 { background: var(--good-soft); color: #137333; }
.s2 { background: var(--fill); color: var(--text); }
.s1 { background: var(--fill); color: var(--text3); font-weight: 600; }

/* ---- detail ---- */
.detail { position: absolute; inset: 0; background: var(--bg); overflow-y: auto; z-index: 3; }
.d-top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 12px 16px; background: rgba(255,255,255,.94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.back { border: 0; background: none; color: var(--accent); font-size: 15px; padding: 4px 8px; display: inline-flex; align-items: center; gap: 4px; }
.back::before { content: ""; width: 9px; height: 9px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); margin-right: 2px; }
.d-actions { display: flex; gap: 8px; }
.gal { position: relative; aspect-ratio: 3 / 2; background: var(--fill2); }
.gal img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.9); display: grid; place-items: center; }
.gal .nav::before { content: ""; width: 9px; height: 9px; border: solid var(--text); border-width: 0 0 2px 2px; }
.gal .prev { left: 12px; } .gal .prev::before { transform: translateX(2px) rotate(45deg); }
.gal .next { right: 12px; } .gal .next::before { transform: translateX(-2px) rotate(-135deg); }
.gal .ctr { position: absolute; right: 12px; bottom: 12px; font-size: 11px; font-weight: 600; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.gal .nophoto { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text3); font-size: 13px; }
.d-body { padding: 24px 24px 48px; }
.d-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.d-price { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.d-ppm { font-size: 13px; color: var(--text2); margin-top: 4px; }
.d-score { text-align: center; flex: none; }
.d-score .big { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.d-score .lbl { font-size: 11px; font-weight: 600; color: var(--text2); margin-top: 4px; }
.d-sub { margin-top: 16px; font-size: 15px; }
.d-place { margin-top: 4px; font-size: 13px; color: var(--text2); }
.d-btns { display: flex; gap: 8px; margin-top: 16px; }
.btn { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--fill); font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none; }
.btn:hover { background: var(--fill2); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #0058b0; }
.btn svg { width: 14px; height: 14px; }
.btn.on { color: var(--bad); }
.btn.on svg { fill: var(--bad); }
.sec { margin-top: 32px; }
.sec h3 { margin: 0 0 12px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.srow { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.srow:first-of-type { border-top: 0; padding-top: 0; }
.srow .k { font-size: 15px; font-weight: 600; }
.srow .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.srow .why { grid-column: 1 / -1; font-size: 13px; color: var(--text2); }
.bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--fill2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 2px; background: var(--good); }
.subrows { grid-column: 1 / -1; margin-top: 8px; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.subrows .k { font-size: 13px; font-weight: 400; color: var(--text); }
.subrows .why { font-size: 13px; color: var(--text2); grid-column: 1 / -1; margin-top: -6px; }
.subrows .v { font-size: 13px; font-weight: 600; }
.risk { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.risk:first-of-type { border-top: 0; padding-top: 0; }
.risk .lv { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--weak); }
.risk .lv.l3 { background: var(--bad); }
.risk .lv.l2 { background: #f29900; }
.risk small { display: block; font-size: 13px; color: var(--text2); }
.ok { font-size: 15px; color: var(--text2); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 15px; }
.kv dt { color: var(--text2); }
.kv dd { margin: 0; }
.txt { font-size: 15px; white-space: pre-line; overflow-wrap: anywhere; }
.txt.clip { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.note { margin-top: 32px; font-size: 13px; color: var(--text3); }

/* ---- map extras ---- */
.inview { position: absolute; top: 16px; left: 16px; z-index: 2; display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; background: rgba(255,255,255,.94); border-radius: 999px; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.12); cursor: pointer; }
.inview input { margin: 0; accent-color: var(--accent); }
.legend { position: absolute; left: 16px; bottom: 24px; z-index: 2; display: flex; gap: 12px; padding: 8px 12px; background: rgba(255,255,255,.94); border-radius: 10px; font-size: 11px; color: var(--text2); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1.5px solid #fff; box-shadow: 0 0 0 0.5px rgba(0,0,0,.15); }
.dot.c4 { background: var(--good); } .dot.c3 { background: var(--good-mid); } .dot.c2 { background: var(--mid); } .dot.c1 { background: var(--weak); }
.dot.cn { background: #fff; border: 2.5px solid var(--accent); box-shadow: none; }
.maplibregl-popup-content { border-radius: 10px; padding: 8px 12px; font: 13px/1.35 inherit; box-shadow: 0 4px 16px rgba(0,0,0,.16); }
.maplibregl-popup-content b { font-size: 15px; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---- login / setup ---- */
.gate { min-height: 100%; display: grid; place-items: center; background: var(--fill); padding: 24px 16px; }
.gate form { width: 100%; max-width: 360px; background: var(--bg); border-radius: 16px; padding: 32px; }
.gate h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.gate p { margin: 0 0 24px; color: var(--text2); font-size: 15px; }
.gate input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 17px; margin-bottom: 12px; }
.gate input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.gate button { width: 100%; height: 44px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; }
.gate .err { color: var(--bad); font-size: 13px; margin: -4px 0 12px; }

/* ---- phone ---- */
@media (max-width: 760px) {
  :root { --side: 100%; }
  .top { padding: 0 12px 0 16px; }
  .brand .meta { display: none; }
  .only-phone { display: inline-flex; }
  #favBtn span { display: none; }
  .top #favBtn .ico { display: block; }
  #newBtn .long { display: none; }
  .top-actions { flex: none; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .layout { position: relative; }
  .side { width: 100%; border-right: 0; }
  .map-wrap { position: absolute; inset: 0; z-index: 4; visibility: hidden; }
  body.show-map .map-wrap { visibility: visible; }
  .ticks { padding: 12px 16px 4px; }
  .filters { padding: 12px 16px 8px; }
  body:not(.show-map) .maplibregl-control-container { display: none; }
  .results-bar, .card { padding-left: 16px; }
  .card { grid-template-columns: 96px 1fr; gap: 12px; }
  .ph { width: 96px; height: 72px; }
  .heart { left: 88px; }
  .pop, .pop.wide { left: 16px !important; right: 16px; width: auto; }
  .legend { display: none; }
  .kv { grid-template-columns: 120px 1fr; }
}

/* ---- map controls in the app's own font + colours ---- */
.maplibregl-map, .maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib-inner { font-family: inherit !important; }
.maplibregl-ctrl-group:not(:empty) { box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }

/* ---- small states ---- */
.chip.open { background: var(--fill); }
.chip.on.open { background: var(--accent-soft); }
.chip.open .caret { transform: translateY(2px) rotate(-135deg); }
.rb-left { display: flex; align-items: center; gap: 12px; }
#favBtn .ico { display: none; width: 14px; height: 14px; fill: var(--bad); }
#favBtn[aria-pressed="true"] .ico { fill: #fff; }
