:root {
  --paper: #f6efe2;
  --paper-2: #fffaf0;
  --paper-3: #efe5d2;
  --ink: #17211f;
  --ink-2: #2a3532;
  --muted: #6b746f;
  --line: rgba(23, 33, 31, 0.13);
  --line-2: rgba(23, 33, 31, 0.22);
  --sale: #14756d;
  --sale-2: #0d5d57;
  --rent: #e2572b;
  --rent-2: #b9401c;
  --gold: #d9a441;
  --shadow: 0 18px 50px rgba(23, 33, 31, 0.16), 0 2px 8px rgba(23, 33, 31, 0.08);
  --radius: 18px;
  --header-h: 76px;
  --font-ui: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", ui-serif, Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; }
button { cursor: pointer; }
a { color: inherit; }

#app { height: 100%; }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  background: rgba(246, 239, 226, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  flex: 0 0 auto;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(23, 33, 31, 0.22);
}
.brand-mark svg { width: 30px; height: 30px; }

.brand-copy { display: flex; flex-direction: column; line-height: 1; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 27px;
  letter-spacing: -0.03em;
}
.brand-sub {
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 5px;
}

.top-stats {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding-left: 22px;
  border-left: 1px solid var(--line);
}
.stat { display: flex; flex-direction: column; padding: 0 16px; line-height: 1; }
.stat strong {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stat span {
  margin-top: 5px;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-sale strong { color: var(--sale); }
.stat-rent strong { color: var(--rent); }

.top-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.city-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  width: 250px;
  padding: 0 13px;
  background: var(--paper-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.city-picker:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(23, 33, 31, 0.08);
}
.city-picker svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  flex: 0 0 auto;
}
.city-picker input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 13px;
  color: var(--ink);
}
.city-picker input::placeholder { color: #8d958f; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--paper-2);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: #fff; transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.map-shell {
  position: fixed;
  top: var(--header-h);
  inset-inline: 0;
  bottom: 0;
}

#map { position: absolute; inset: 0; background: var(--paper-3); }

.maplibregl-ctrl-attrib {
  font-family: var(--font-ui);
  font-size: 10px;
  background: rgba(246, 239, 226, 0.86) !important;
  border-radius: 8px 0 0 0;
}
.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-group {
  background: var(--paper-2) !important;
  border: 1px solid var(--line) !important;
  box-shadow: 0 6px 18px rgba(23, 33, 31, 0.12) !important;
  border-radius: 12px !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button { width: 34px !important; height: 34px !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }

.panel {
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
}

.filters {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 286px;
  padding: 15px;
  z-index: 10;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: var(--paper-3);
  border-radius: 11px;
  margin-bottom: 14px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.segmented button.active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 3px 8px rgba(23, 33, 31, 0.22);
}

.field { display: block; margin-bottom: 13px; }
.field > span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.field select,
.field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: #fff;
  padding: 0 10px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}
.field select:focus,
.field input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 33, 31, 0.07); }

.price-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 7px;
}
.price-row span { color: var(--muted); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button {
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11.5px;
  font-weight: 700;
}
.chips button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.hint { font-size: 10.5px; line-height: 1.45; color: var(--muted); margin: 6px 0 0; }
.filter-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-btn:hover { color: var(--ink); }
.filter-count {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--sale);
  background: rgba(20, 117, 109, 0.1);
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.map-toggles {
  position: absolute;
  right: 18px;
  bottom: 96px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.94);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 5px 16px rgba(23, 33, 31, 0.1);
}
.toggle.active { color: var(--ink); border-color: var(--ink); }
.toggle .dot { width: 9px; height: 9px; border-radius: 50%; opacity: 0.38; }
.toggle.active .dot { opacity: 1; }
.heat-dot { background: linear-gradient(135deg, #ffd166, #e2572b 60%, #8e123c); }
.sale-dot { background: var(--sale); }

.legend {
  position: absolute;
  left: 20px;
  bottom: 20px;
  z-index: 10;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 11.5px;
  font-weight: 700;
}
.legend-row { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-dot.sale { background: var(--sale); }
.legend-dot.rent { background: var(--rent); }
.heat-scale { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; }
.heat-scale i {
  width: 74px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.3), #ffd166 25%, #f08a3c 55%, #e2572b 75%, #8e123c);
  display: block;
}

.map-credit {
  position: absolute;
  left: 20px;
  bottom: 68px;
  z-index: 9;
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(246, 239, 226, 0.78);
  padding: 5px 9px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}
.map-credit a { color: var(--ink-2); font-weight: 700; text-decoration: none; }
.map-credit a:hover { text-decoration: underline; }

.loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(246, 239, 226, 0.72);
  backdrop-filter: blur(8px);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.loading.hidden { opacity: 0; visibility: hidden; }
.loading-card {
  text-align: center;
  padding: 30px 38px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  max-width: 380px;
}
.loading-card h2 { font-family: var(--font-display); font-size: 27px; margin: 14px 0 6px; }
.loading-card p { color: var(--muted); font-size: 13px; margin: 0; }
.spinner {
  display: inline-block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(23, 33, 31, 0.14);
  border-top-color: var(--rent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 94vw);
  z-index: 50;
  background: var(--paper-2);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(23, 33, 31, 0.2);
  transform: translateX(102%);
  transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.26, 1);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(23, 33, 31, 0.72);
  color: #fff;
  backdrop-filter: blur(6px);
}
.drawer-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.drawer-close:hover { background: var(--ink); }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(23, 33, 31, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.drawer-backdrop.open { opacity: 1; visibility: visible; }

.drawer-body { min-height: 100%; }
.d-hero {
  position: relative;
  height: 260px;
  background: var(--paper-3) center/cover no-repeat;
}
.d-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(23, 33, 31, 0.05), transparent 45%, rgba(23, 33, 31, 0.28));
}
.d-hero-empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.d-body { padding: 20px 22px 34px; }
.d-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--paper-3);
  color: var(--ink-2);
}
.badge.sale { background: rgba(20, 117, 109, 0.13); color: var(--sale-2); }
.badge.rent { background: rgba(226, 87, 43, 0.13); color: var(--rent-2); }
.d-title {
  font-family: var(--font-display);
  font-size: 29px;
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.d-location { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.d-price {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.d-price small { font-family: var(--font-ui); font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.d-price-rent { color: var(--rent-2); }
.d-price-sale { color: var(--sale-2); }
.d-perm2 { color: var(--muted); font-size: 12px; margin-top: 5px; }

.d-specs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}
.d-spec {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
}
.d-spec b { display: block; font-size: 16px; letter-spacing: -0.02em; }
.d-spec span { display: block; margin-top: 2px; font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.d-section { margin-top: 20px; }
.d-section h3 {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}
.d-desc { font-size: 13px; line-height: 1.62; color: var(--ink-2); white-space: pre-line; }
.d-attrs { display: flex; flex-wrap: wrap; gap: 6px; }
.d-attr {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 11.5px;
}
.d-attr b { font-weight: 800; }
.d-attr span { color: var(--muted); }

.d-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
  height: 48px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  font-weight: 800;
  font-size: 13.5px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.d-cta:hover { background: #0c1513; transform: translateY(-1px); }
.d-cta svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; }

.d-gallery { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.d-gallery img {
  width: 100%;
  aspect-ratio: 1.25;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.d-gallery img:hover { opacity: 0.8; }

.d-source { margin-top: 16px; font-size: 11px; color: var(--muted); line-height: 1.5; }

.skeleton { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.45; } to { opacity: 0.9; } }
.sk-hero { height: 260px; background: var(--paper-3); }
.sk-line { height: 14px; border-radius: 6px; background: var(--paper-3); margin: 10px 22px; }
.sk-line.w60 { width: 60%; }
.sk-line.w40 { width: 40%; }
.sk-price { height: 32px; width: 45%; border-radius: 8px; background: var(--paper-3); margin: 18px 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  z-index: 80;
  background: var(--ink);
  color: var(--paper);
  font-size: 12.5px;
  font-weight: 700;
  padding: 11px 17px;
  border-radius: 999px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@media (min-width: 761px) {
  body.drawer-open .map-toggles { right: 462px; }
  body.drawer-open .maplibregl-ctrl-bottom-right { right: 452px !important; }
  body.drawer-open .map-credit { left: 20px; }
}

@media (max-width: 1080px) {
  .top-stats { display: none; }
  .city-picker { width: 210px; }
}

@media (max-width: 760px) {
  :root { --header-h: 64px; }
  .topbar { gap: 12px; padding: 0 13px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-mark svg { width: 26px; height: 26px; }
  .brand-name { font-size: 23px; }
  .brand-sub { display: none; }
  .city-picker { width: 170px; height: 38px; }
  .icon-btn { display: none; }
  .filters {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    padding: 12px;
    max-height: 42vh;
    overflow-y: auto;
  }
  .legend { display: none; }
  .map-toggles { right: 10px; bottom: 50%; flex-direction: row; }
  .map-credit { bottom: auto; top: 10px; left: 10px; right: auto; }
  .drawer { width: 100%; top: auto; height: 86vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; transform: translateY(102%); }
  .drawer.open { transform: translateY(0); }
  .drawer-backdrop.open { pointer-events: auto; }
}

/* Geo / parcel controls */
.segmented-3 { grid-template-columns: repeat(3, 1fr); }
.segmented-3 button { font-size: 11px; }
.bldg-dot { background: #e2572b; }
.geo-status {
  position: absolute;
  left: 20px;
  bottom: 118px;
  z-index: 10;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  box-shadow: 0 5px 16px rgba(23, 33, 31, 0.1);
}
.geo-status.loading { color: var(--rent-2); }
.geo-status b { color: var(--sale-2); }

.d-geo { display: grid; gap: 8px; }
.d-geo-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  background: #fff;
}
.d-geo-card .geo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.d-geo-card .geo-src {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.d-geo-card.dgt .geo-src { color: var(--sale-2); }
.d-geo-card.ifap .geo-src { color: #5f7f3b; }
.d-geo-card.osm .geo-src { color: var(--rent-2); }
.d-geo-card.approx .geo-src { color: var(--muted); }
.d-geo-card .geo-main { font-size: 13px; font-weight: 700; }
.d-geo-card .geo-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.conf {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--paper-3);
  color: var(--ink-2);
}
.conf.high { background: rgba(20, 117, 109, 0.14); color: var(--sale-2); }
.conf.medium { background: rgba(217, 164, 65, 0.18); color: #7a5a13; }
.conf.low, .conf.approximate { background: rgba(226, 87, 43, 0.12); color: var(--rent-2); }
.geo-actions { display: flex; gap: 7px; margin-top: 12px; flex-wrap: wrap; }
.geo-actions button {
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink-2);
}
.geo-actions button:hover { border-color: var(--ink); }
.geo-actions button.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.price-tip {
  background: var(--ink);
  color: var(--paper);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 11.5px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(23, 33, 31, 0.25);
}
.price-tip span { opacity: 0.7; font-weight: 600; }
