:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #6b716c;
  --line: #e2ded4;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --warn: #9a6400;
  --warn-soft: #fbf0d9;
  --bad: #a3312b;
  --bad-soft: #f8e1df;
  --good: #2e6b34;
  --good-soft: #e1f0e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1e2220;
    --text: #e8ebe8;
    --muted: #9aa29c;
    --line: #313733;
    --accent: #7fbfa9;
    --accent-ink: #10201a;
    --accent-soft: #23332d;
    --warn: #e7b65c;
    --warn-soft: #3a301c;
    --bad: #ef8a83;
    --bad-soft: #3d2322;
    --good: #8fd196;
    --good-soft: #213323;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.container { max-width: 1280px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--accent); text-decoration: none; font-size: 1.05rem; }
.brand.big { font-size: 1.35rem; margin-bottom: 0.25rem; }
.topbar nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.topbar nav a { color: var(--text); text-decoration: none; }
.topbar nav a[aria-current] { color: var(--accent); font-weight: 600; }
form.inline { display: inline; margin: 0; }

/* ---------- controls ---------- */
input, select, button, .button { font: inherit; }
input, select {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 0.45rem; font-size: 0.95rem; color: var(--text); }
label.check input { width: auto; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 0.95rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); }
button.link { background: none; border: 0; padding: 0; color: var(--text); }
button:disabled { opacity: 0.5; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.alert { padding: 0.6rem 0.8rem; border-radius: 8px; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--good-soft); color: var(--good); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.85rem; }
.login p { margin: 0; }

/* ---------- filters ---------- */
.filters-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters-toggle { display: none; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; padding: 0.9rem; align-items: end; }
.filters .grow { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.field-label { font-size: 0.8rem; color: var(--muted); }
.field.reset { justify-content: center; font-size: 0.9rem; padding-bottom: 0.45rem; }
.area-toggle label.check { padding: 0.4rem 0; }

/* Multi-select dropdown built from <details> + checkboxes */
.multi { position: relative; }
.multi summary {
  list-style: none; cursor: pointer; padding: 0.45rem 1.8rem 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.multi summary::-webkit-details-marker { display: none; }
.multi summary::after { content: "▾"; position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.multi[open] summary { outline: 2px solid var(--accent); outline-offset: -1px; }
.multi-menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  padding: 0.4rem 0.6rem; display: flex; flex-direction: column; gap: 0.15rem;
}
.multi-menu label.check { padding: 0.3rem 0.1rem; }

@media (max-width: 700px) {
  .filters-toggle {
    display: flex; gap: 0.5rem; align-items: baseline; padding: 0.75rem 0.9rem; cursor: pointer; list-style: none; font-weight: 600;
  }
  .filters-toggle::-webkit-details-marker { display: none; }
  .filters-toggle .muted { font-weight: 400; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
  .filters-toggle::after { content: "▾"; color: var(--muted); }
  .filters-panel[open] .filters-toggle::after { content: "▴"; }
  .filters-panel[open] .filters { border-top: 1px solid var(--line); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .grow { grid-column: 1 / -1; }
}
.count { color: var(--muted); margin: 1rem 0 0.6rem; }

/* ---------- phones ---------- */
.tabbar { display: none; }
@media (max-width: 700px) {
  /* A larger root size scales everything set in rem; small text gets a floor below. */
  html { font-size: 17px; }
  body { font-size: 1rem; padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .container { padding: 0.75rem 14px 1.5rem; }
  .topbar { padding: 0.55rem 14px; gap: 0.5rem; }
  .topbar nav .nav-main, .topbar nav .muted { display: none; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 2000;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgb(0 0 0 / 0.06);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; font-size: 0.78rem; color: var(--muted); text-decoration: none; }
  .tabbar a[aria-current] { color: var(--accent); font-weight: 600; }
  .tabbar svg { width: 25px; height: 25px; fill: currentColor; }
  .src { font-size: 0.8rem; padding: 0.15rem 0.5rem; }
  .seen, .small, .price-note, .travel, .fans, .interest-label { font-size: 0.86rem; }
  .badge, .photo-count { font-size: 0.78rem; }
  label, .field-label, .filters-toggle .muted { font-size: 0.86rem; }
  input, select, .multi summary { min-height: 46px; }
  label.check { min-height: 40px; }
  .interest .choice { min-height: 44px; min-width: 4.4rem; font-size: 0.95rem; }
  .links .button, .more button { min-height: 46px; }
  .minimap { width: 112px; }
  .minimap-off { font-size: 0.72rem; }
  dl { font-size: 0.95rem; }
  .grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .card { padding: 0.9rem; }
  .listing { padding: 0; }
  h1 { font-size: 1.3rem; }
  .price.big { font-size: 1.45rem; }
  .stage { aspect-ratio: 4 / 3; border-radius: 8px; }
  .stage .nav { width: 42px; height: 42px; font-size: 1.5rem; }
  .strip img { width: 72px; height: 54px; }
  .links { flex-direction: row; flex-wrap: wrap; }
  .links .button { flex: 1 1 auto; }
  .admin-grid { grid-template-columns: 1fr; }
  .run-now, .area-actions { flex-wrap: wrap; }
  .area-actions .spacer { display: none; }
  .area-map { height: 320px; }
  .table th, .table td { padding: 0.4rem 0.35rem; }
  .map-page { height: calc(100dvh - 3.2rem - 62px - env(safe-area-inset-bottom)); padding-bottom: 0.5rem; }
}
.htmx-request #results, #results.htmx-request { opacity: 0.55; transition: opacity 0.2s; }

/* ---------- listing grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; }
.listing { padding: 0; overflow: hidden; display: flex; flex-direction: column; transition: transform 0.12s, box-shadow 0.12s, opacity 0.25s; }
.listing:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgb(0 0 0 / 0.08); }
.listing.leaving { opacity: 0; transform: scale(0.97); }
.card-link { text-decoration: none; color: inherit; display: flex; flex-direction: column; flex: 1; }
.listing > .interest { padding: 0.55rem 0.95rem 0.8rem; border-top: 1px solid var(--line); }
.interest { display: flex; align-items: center; gap: 0.45rem; }
.interest-label { color: var(--muted); font-size: 0.85rem; margin-right: auto; }
.interest .choice { padding: 0.3rem 0.9rem; border-radius: 999px; font-size: 0.85rem; min-width: 3.6rem; }
.interest .choice-yes.on { background: var(--good); border-color: var(--good); color: #fff; font-weight: 600; }
.interest .choice-no.on { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.interest.htmx-request { opacity: 0.6; }
.summary .interest { margin: 0.6rem 0 0.2rem; }
.fans { color: var(--good); font-size: 0.85rem; font-weight: 500; }
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--line); overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 0.9rem; }
.badges { position: absolute; top: 0.6rem; left: 0.6rem; display: flex; gap: 0.35rem; }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; }
.badge.new { background: var(--accent); color: var(--accent-ink); }
.badge.status-under_offer { background: var(--warn-soft); color: var(--warn); }
.badge.status-sold_stc, .badge.status-removed, .badge.err { background: var(--bad-soft); color: var(--bad); }
.badge.ok { background: var(--good-soft); color: var(--good); }
.photo-count { position: absolute; right: 0.6rem; bottom: 0.6rem; background: rgb(0 0 0 / 0.6); color: #fff; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; }
.listing .body { padding: 0.8rem 0.95rem 0.95rem; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.price { font-size: 1.25rem; font-weight: 700; }
.price.big { font-size: 1.7rem; }
.price .qual { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.facts { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; color: var(--muted); font-size: 0.9rem; }
.address { font-weight: 500; }
.badge.closing-upcoming { background: var(--warn-soft); color: var(--warn); }
.badge.closing-soon { background: var(--bad); color: #fff; }
.badge.closing-passed { background: var(--line); color: var(--muted); }
.price.varies { color: var(--warn); }
.price.varies::after { content: " ▲"; font-size: 0.6em; vertical-align: 0.35em; }
.price-note { background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 0.3rem 0.55rem; font-size: 0.8rem; line-height: 1.35; }
.price-note ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }
.body-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; align-items: start; }
.body-text { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.minimap { position: relative; width: 92px; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--line); flex: none; }
.minimap img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.minimap-dot { position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; background: #1f6feb; border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35); }
.minimap-stop { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; background: #c0392b; border: 1px solid #fff; }
.minimap-large { width: 100%; max-width: 320px; margin: 0.75rem auto 0; border-radius: 10px; }
.minimap-large .minimap-dot { width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px; }
.minimap-large .minimap-stop { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
.minimap-off { position: absolute; inset: auto 0 0 0; text-align: center; font-size: 0.65rem; background: rgb(255 255 255 / 0.85); color: #333; padding: 1px 0; }
.travel { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; font-size: 0.85rem; }
.stop-pin { display: inline-flex; align-items: center; justify-content: center; transform: translate(-50%, -50%); background: #c0392b; color: #fff; font: 700 0.75rem/1 system-ui, sans-serif; padding: 0.3rem 0.4rem; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); }
.sources { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; margin-top: auto; padding-top: 0.35rem; }
.src { font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.seen { margin-left: auto; font-size: 0.8rem; }
.more { grid-column: 1 / -1; display: flex; justify-content: center; padding: 0.5rem; }
.empty { text-align: center; padding: 2.5rem 1rem; }

/* ---------- detail ---------- */
.back { text-decoration: none; }
.detail { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .detail { grid-template-columns: minmax(0, 1fr); } }
.detail > *, .detail-lower > * { min-width: 0; }
.stage { position: relative; aspect-ratio: 3 / 2; background: #000; border-radius: var(--radius); overflow: hidden; }
.stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage.noimg { background: var(--line); }
.stage .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgb(255 255 255 / 0.85); color: #111; font-size: 1.6rem; line-height: 1; padding: 0; box-shadow: 0 1px 6px rgb(0 0 0 / 0.35); }
.stage .prev { left: 0.6rem; }
.stage .next { right: 0.6rem; }
.strip { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.5rem 0; }
.strip button { padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; flex: 0 0 auto; background: none; }
.strip button.active { border-color: var(--accent); }
.strip img { width: 88px; height: 64px; object-fit: cover; display: block; }
.summary { display: flex; flex-direction: column; gap: 0.6rem; position: sticky; top: 4.2rem; }
.summary h1 { font-size: 1.2rem; margin: 0; }
.summary .badge { align-self: flex-start; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.9rem; margin: 0.25rem 0; font-size: 0.92rem; }
dt { color: var(--muted); }
dd { margin: 0; }
.links { display: flex; flex-direction: column; gap: 0.45rem; }
.detail-lower { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
@media (max-width: 860px) { .detail-lower { grid-template-columns: minmax(0, 1fr); } .summary { position: static; } }
.prose { white-space: pre-line; max-width: 75ch; }
.lower-main { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.lower-main > section.card + section.card { margin-top: 0; }
.gallery-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.5rem; }
.gallery-tabs button, .gallery-tabs a { border-radius: 999px; padding: 0.35rem 0.95rem; font-size: 0.9rem; }
.gallery-tabs .on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.stage.is-plan { background: #fff; border: 1px solid var(--line); }
.stage .plan-open { position: absolute; left: 0.6rem; bottom: 0.6rem; background: rgb(0 0 0 / 0.65); color: #fff; font-size: 0.8rem; padding: 0.25rem 0.65rem; border-radius: 999px; text-decoration: none; }
.strip .plan-thumb { position: relative; background: #fff; }
.strip .plan-thumb img { object-fit: contain; }
.strip .plan-thumb span { position: absolute; left: 0; right: 0; bottom: 0; background: rgb(0 0 0 / 0.6); color: #fff; font-size: 0.68rem; text-align: center; }

/* ---------- tables / admin ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.table-scroll { overflow-x: auto; }
.table pre { white-space: pre-wrap; font-size: 0.78rem; max-width: 60ch; }
details summary { cursor: pointer; list-style: none; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
section.card + section.card { margin-top: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.8rem; display: flex; flex-direction: column; gap: 0.35rem; }
legend { font-size: 0.8rem; color: var(--muted); padding: 0 0.3rem; }
.run-now { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.inline-form { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input:not([type=checkbox]) { width: auto; flex: 1 1 160px; }
.add-user { margin-top: 1rem; }

/* ---------- map ---------- */
.map-page { display: flex; flex-direction: column; height: calc(100vh - 3.2rem); padding-bottom: 1rem; }
.map-page .count { margin: 0.6rem 0; }
#map { flex: 1; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.price-pin {
  display: inline-block; transform: translate(-50%, -100%); white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); font: 700 12px/1 system-ui, sans-serif;
  padding: 5px 7px; border-radius: 999px; border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.35); cursor: pointer;
}
.price-pin.pin-under_offer { background: #b07a12; color: #fff; }
.price-pin.pin-sold_stc, .price-pin.pin-removed { background: #8a8f8b; color: #fff; }
.price-pin.pin-new { outline: 2px solid #f2c94c; }
.price-pin.pin-varies::after { content: " ▲"; font-size: 9px; }
.leaflet-marker-icon:hover .price-pin { transform: translate(-50%, -100%) scale(1.08); }
.leaflet-popup-content { margin: 0; width: 240px !important; }
.leaflet-popup-content-wrapper { padding: 0; overflow: hidden; border-radius: var(--radius); }
.leaflet-container a.map-popup { display: block; color: #1f2421; text-decoration: none; }
.map-popup img { display: block; width: 100%; height: 150px; object-fit: cover; }
.map-popup-body { padding: 0.6rem 0.75rem 0.75rem; display: flex; flex-direction: column; gap: 0.2rem; font: 14px/1.4 system-ui, sans-serif; }
.map-popup .price { font-size: 1.1rem; }
.map-popup .badge { align-self: flex-start; }
.small { font-size: 0.8rem; }
.container.wide { max-width: none; }
.area-map { height: 420px; border-radius: 8px; border: 1px solid var(--line); margin: 0.75rem 0; z-index: 0; }
.area-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.area-actions .spacer { flex: 1; }
.vertex { display: block; width: 14px; height: 14px; transform: translate(-50%, -50%); border-radius: 50%; background: #fff; border: 3px solid #2f5d50; cursor: move; }
.cluster-pin {
  display: grid; place-items: center; width: 38px; height: 38px; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 700 13px/1 system-ui, sans-serif;
  border: 3px solid #fff; box-shadow: 0 0 0 4px rgb(47 93 80 / 0.25), 0 1px 4px rgb(0 0 0 / 0.3); cursor: pointer;
}

/* ---------- interested ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 0.25rem; background: var(--line); padding: 0.2rem; border-radius: 999px; }
.tabs a { padding: 0.3rem 0.9rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 0.9rem; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 600; }
