:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #e2e5e0;
  --text: #17201c;
  --muted: #66716b;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #e0f2ef;
  --private: #0f766e;
  --shared: #2563eb;
  --none: #64748b;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --good: #15803d;
  --bad: #b91c1c;
  --star: #f59e0b;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 8px 24px rgba(16, 24, 20, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #161d1a; --surface-2: #1d2622; --border: #2a3530;
    --text: #e8eeeb; --muted: #94a39b; --accent: #2dd4bf; --accent-2: #5eead4; --accent-soft: #123430;
    --private: #14b8a6; --shared: #60a5fa; --none: #94a3b8; --warn: #fbbf24; --warn-soft: #3a2e10;
    --good: #4ade80; --bad: #f87171; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #161d1a; --surface-2: #1d2622; --border: #2a3530;
  --text: #e8eeeb; --muted: #94a39b; --accent: #2dd4bf; --accent-2: #5eead4; --accent-soft: #123430;
  --private: #14b8a6; --shared: #60a5fa; --none: #94a3b8; --warn: #fbbf24; --warn-soft: #3a2e10;
  --good: #4ade80; --bad: #f87171; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); font-weight: 400; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 40px; height: 40px; border-radius: 11px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; }
.logo svg { width: 22px; height: 22px; fill: #fff; stroke: none; }
.brand h1 { font-size: 18px; font-weight: 700; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex: none; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn b { background: rgba(255,255,255,.22); border-radius: 6px; padding: 0 6px; margin-left: 2px; }
.icon-btn { border: 0; background: var(--surface-2); color: var(--text); width: 34px; height: 34px; border-radius: 10px; font-size: 22px; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--border); }

/* ---------- filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 22px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.f-group { display: flex; flex-direction: column; gap: 6px; }
.f-group.grow { flex: 1 1 220px; }
.f-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.range { display: flex; align-items: center; gap: 6px; color: var(--muted); }
input[type=number], input[type=search], select {
  height: 32px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
  padding: 0 10px; font: inherit; font-size: 13px; outline: none;
}
input[type=number] { width: 96px; }
input[type=search] { width: 100%; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- map ---------- */
main { padding: 18px 24px 40px; max-width: 1600px; margin: 0 auto; }
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); background: var(--surface-2); }
#map { height: min(64vh, 680px); min-height: 380px; width: 100%; }
.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 12px; box-shadow: var(--shadow);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.private { background: var(--private); } .dot.shared { background: var(--shared); } .dot.none { background: var(--none); }
.poi-toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; border-left: 1px solid var(--border); padding-left: 12px; }
.map-note { position: absolute; right: 12px; top: 12px; z-index: 500; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 12px; max-width: 320px; }

/* price pill marker (shared by Leaflet & Google) */
.pill {
  --c: var(--none);
  position: relative; display: inline-flex; align-items: center; gap: 5px; transform: translate(-50%, calc(-100% - 7px));
  background: var(--surface); color: var(--text); border: 2px solid var(--c); border-radius: 999px;
  padding: 3px 9px 3px 4px; font: 600 12.5px/1.2 Inter, system-ui, sans-serif; white-space: nowrap; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .12s, box-shadow .12s;
  user-select: none;
}
.pill::after { content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--c); border-bottom: 0; }
.pill .beds { background: var(--c); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 11.5px; }
.pill.private { --c: var(--private); } .pill.shared { --c: var(--shared); } .pill.none { --c: var(--none); }
.pill.fav { box-shadow: 0 0 0 3px var(--star), 0 2px 6px rgba(0,0,0,.2); }
.pill.dim { opacity: .3; }
.pill:hover, .pill.active { transform: translate(-50%, calc(-100% - 7px)) scale(1.1); z-index: 10; box-shadow: 0 4px 14px rgba(0,0,0,.3); background: var(--c); color: #fff; }
.pill:hover .beds, .pill.active .beds { background: rgba(255,255,255,.25); }
.pill.new { border-style: dashed; }
.poi { transform: translate(-50%, -50%); display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 2px 6px; font: 600 11px/1.3 Inter, system-ui, sans-serif; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.12); pointer-events: auto; }
.poi i { font-style: normal; }
.leaflet-div-icon { background: none; border: 0; }
.leaflet-container { font-family: inherit; background: var(--surface-2); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-head h2 { font-size: 16px; }
.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; cursor: pointer; user-select: none; }
th.nosort { cursor: default; }
th .arr { opacity: .35; margin-left: 3px; }
th.sorted .arr { opacity: 1; color: var(--accent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.active { background: var(--accent-soft); }
tbody tr.dup td { opacity: .6; }
.thumb { width: 64px; height: 46px; border-radius: 8px; object-fit: cover; display: block; background: var(--surface-2); }
.t-title { font-weight: 600; max-width: 260px; }
.t-sub { color: var(--muted); font-size: 12px; }
.price { font-weight: 700; }
.price-alt { color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.private { background: color-mix(in srgb, var(--private) 15%, transparent); color: var(--private); }
.badge.shared { background: color-mix(in srgb, var(--shared) 15%, transparent); color: var(--shared); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.badge.new { background: var(--accent-soft); color: var(--accent); }
.ficons { display: flex; flex-wrap: wrap; gap: 3px; max-width: 170px; }
.ficons span { font-size: 15px; line-height: 1; }
.comment { max-width: 200px; font-size: 12.5px; color: var(--text); font-style: italic; }
.star { background: none; border: 0; cursor: pointer; font-size: 18px; color: var(--border); padding: 0; line-height: 1; }
.star.on { color: var(--star); }
.cmp-check { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.open-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.open-link svg { width: 14px; height: 14px; }
.foot { padding: 12px 16px; margin: 0; font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 15, 12, .35); z-index: 1500; }
@media (min-width: 861px) { .drawer-backdrop { display: none !important; } }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(560px, 100%); background: var(--surface); z-index: 1600;
  box-shadow: -8px 0 40px rgba(0,0,0,.2); transform: translateX(105%); transition: transform .25s ease; overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.open { transform: none; }
.d-close { position: absolute; top: 12px; right: 12px; z-index: 5; background: rgba(0,0,0,.55); color: #fff; }
.d-close:hover { background: rgba(0,0,0,.75); }

.carousel { position: relative; background: #0b0f0d; aspect-ratio: 4 / 3; overflow: hidden; }
.track { display: flex; height: 100%; transition: transform .3s ease; }
.track img { width: 100%; height: 100%; flex: none; object-fit: cover; cursor: zoom-in; }
.c-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.88); color: #111; font-size: 24px; cursor: pointer; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.c-btn.prev { left: 12px; } .c-btn.next { right: 12px; }
.c-count { position: absolute; left: 12px; bottom: 12px; background: rgba(0,0,0,.6); color: #fff; border-radius: 8px; padding: 3px 9px; font-size: 12px; font-weight: 600; }
.thumbs { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; background: var(--surface-2); scrollbar-width: thin; }
.thumbs img { width: 62px; height: 46px; object-fit: cover; border-radius: 6px; cursor: pointer; opacity: .55; flex: none; border: 2px solid transparent; }
.thumbs img.on { opacity: 1; border-color: var(--accent); }
.no-photo { aspect-ratio: 4/3; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); }

.d-body { padding: 18px 20px 28px; }
.d-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.d-title { font-size: 19px; font-weight: 700; line-height: 1.25; }
.d-loc { color: var(--muted); margin-top: 4px; font-size: 13px; }
.d-price { text-align: right; flex: none; }
.d-price .big { font-size: 22px; font-weight: 700; white-space: nowrap; }
.d-price .small { color: var(--muted); font-size: 12px; }
.d-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.d-summary { margin: 12px 0; font-size: 14px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: 14px 0; }
.fact { background: var(--surface); padding: 9px 11px; }
.fact .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.fact .v { font-weight: 600; margin-top: 1px; }
.sec { margin-top: 18px; }
.sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; gap: 5px; align-items: center; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; font-weight: 500; }
.pc { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pc ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.pc li { position: relative; padding-left: 20px; font-size: 13px; }
.pc .pros li::before { content: "+"; position: absolute; left: 0; color: var(--good); font-weight: 700; }
.pc .cons li::before { content: "–"; position: absolute; left: 2px; color: var(--bad); font-weight: 700; }
.pc .box { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.pc h4 { margin: 0 0 8px; font-size: 12.5px; }
.terms { width: 100%; border: 1px solid var(--border); border-radius: 10px; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.terms td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.terms tr:last-child td { border-bottom: 0; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.commentbox { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.dist { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 14px; font-size: 13px; }
.dist div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 3px 0; }
details.orig { margin-top: 18px; border: 1px solid var(--border); border-radius: 10px; }
details.orig summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 13px; }
details.orig pre { white-space: pre-wrap; word-wrap: break-word; font: 12.5px/1.5 Inter, system-ui, sans-serif; margin: 0; padding: 0 12px 12px; color: var(--muted); max-height: 420px; overflow: auto; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.92); display: grid; place-items: center; }
.lightbox img { max-width: 94vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox button { position: absolute; background: rgba(255,255,255,.12); border: 0; color: #fff; width: 48px; height: 48px; border-radius: 50%; font-size: 30px; cursor: pointer; }
.lightbox button:hover { background: rgba(255,255,255,.25); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-count { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; }

/* ---------- compare modal ---------- */
.modal { position: fixed; inset: 0; z-index: 2500; background: rgba(10,15,12,.5); display: grid; place-items: center; padding: 20px; }
.modal-box { background: var(--surface); border-radius: 16px; width: min(1200px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { overflow: auto; }
.cmp { border-collapse: collapse; width: 100%; font-size: 13px; }
.cmp th, .cmp td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; text-align: left; cursor: default; }
.cmp th { position: sticky; left: 0; background: var(--surface-2); width: 150px; text-transform: none; letter-spacing: 0; font-size: 12.5px; z-index: 1; }
.cmp thead td { position: sticky; top: 0; background: var(--surface); z-index: 2; }
.cmp img { width: 100%; max-width: 240px; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; display: block; }
.cmp .best { color: var(--good); font-weight: 700; }
.cmp ul { margin: 0; padding-left: 16px; }

[hidden] { display: none !important; }

@media (max-width: 860px) {
  .topbar { padding: 10px 16px; }
  .top-actions .btn span { display: none; }
  .filters { padding: 12px 16px; gap: 10px 14px; }
  main { padding: 12px 16px 30px; }
  #map { height: 56vh; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .pc { grid-template-columns: 1fr; }
  .d-top { flex-direction: column; }
  .d-price { text-align: left; }
  .legend { font-size: 11px; gap: 4px 10px; right: 12px; }
}
@media (max-width: 520px) {
  .brand h1 { font-size: 16px; }
  .sub { max-width: 52vw; }
  .chips { flex-wrap: nowrap; overflow-x: auto; max-width: calc(100vw - 32px); padding-bottom: 2px; }
}
#table td:nth-child(4) { min-width: 240px; }
#table td:nth-child(12) { min-width: 120px; }

.only-mobile { display: none; }
.map-note { cursor: pointer; }
.map-note::after { content: " ×"; font-weight: 700; }
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .filters.collapsed { display: none; }
  .map-note { left: 56px; right: 12px; top: 10px; max-width: none; font-size: 11.5px; padding: 6px 10px; }
  .top-actions { gap: 6px; }
  .top-actions .btn { padding: 0 10px; }
}
@media (max-width: 520px) {
  .cmp-label { display: none; }
  .brand { gap: 10px; }
  .logo { width: 34px; height: 34px; }
  .sub { max-width: 46vw; }
}

.brand > div { min-width: 0; }
.brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .sub { max-width: none; } .stat .v { font-size: 17px; } .stat .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } }
