:root {
  --bg: var(--tg-theme-bg-color, #f4f5f2);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17231e);
  --muted: var(--tg-theme-hint-color, #718079);
  --accent: var(--tg-theme-button-color, #176b4d);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --shadow: 0 10px 30px rgba(22, 47, 37, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); min-height: 100vh; }
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

#app { max-width: 760px; margin: 0 auto; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(18px + env(safe-area-inset-top)) 18px 12px; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 30px; letter-spacing: -.04em; }
h2 { margin-bottom: 5px; font-size: 23px; letter-spacing: -.025em; }
.muted { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.icon-button, .back-button { border: 0; background: var(--surface); box-shadow: var(--shadow); }
.icon-button { width: 42px; height: 42px; border-radius: 50%; font-size: 23px; }
.view { display: none; padding: 12px 16px 105px; }
.view.active { display: block; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.segmented { display: flex; padding: 3px; border-radius: 12px; background: var(--surface); }
.mode-button { border: 0; border-radius: 9px; padding: 7px 11px; background: transparent; color: var(--muted); font-weight: 700; }
.mode-button.active { color: var(--accent-text); background: var(--accent); }

.listing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.listing-card { overflow: hidden; border: 0; border-radius: 20px; padding: 0; text-align: left; background: var(--surface); box-shadow: var(--shadow); cursor: pointer; }
.card-photo { position: relative; aspect-ratio: 1.24; overflow: hidden; background: #dfe5e1; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-placeholder { display: grid; place-items: center; width: 100%; height: 100%; color: #789087; font-size: 36px; background: linear-gradient(145deg, #dfe9e4, #c9d7d1); }
.score-pill { position: absolute; left: 9px; top: 9px; padding: 6px 8px; border-radius: 999px; background: rgba(12, 37, 28, .82); color: white; font-size: 12px; font-weight: 800; backdrop-filter: blur(7px); }
.favorite-chip { position: absolute; right: 9px; top: 9px; display: grid; place-items: center; width: 31px; height: 31px; border: 0; border-radius: 50%; background: rgba(255,255,255,.9); color: #173a2d; font-size: 20px; }
.favorite-chip.active { color: #d74a67; }
.card-body { padding: 12px; }
.card-price { margin: 0 0 4px; font-size: 20px; font-weight: 850; }
.card-facts { margin: 0 0 8px; font-size: 14px; font-weight: 650; }
.card-address { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty-state { padding: 58px 20px; text-align: center; color: var(--muted); }
.empty-state span { display: block; font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

.filter-form { display: grid; gap: 14px; }
fieldset, .toggle-list { border: 0; border-radius: 19px; padding: 16px; margin: 0; background: var(--surface); box-shadow: var(--shadow); }
legend { padding: 0; margin-bottom: 10px; font-weight: 800; }
.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range-row label, .full-field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
input[type="number"] { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--text); background: var(--bg); outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
.choice-row { display: grid; grid-template-columns: 1fr 1.45fr; gap: 8px; }
.choice-row label { padding: 11px; border-radius: 12px; background: var(--bg); font-size: 13px; }
.toggle-list { display: grid; gap: 16px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row small { color: var(--muted); }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.primary-button { border: 0; border-radius: 15px; padding: 15px; background: var(--accent); color: var(--accent-text); font-weight: 800; box-shadow: var(--shadow); }
.form-message { min-height: 18px; margin: 0; text-align: center; color: var(--accent); font-size: 13px; }

.bottom-nav { position: fixed; z-index: 1000; left: 50%; bottom: 0; transform: translateX(-50%); display: grid; grid-template-columns: repeat(3, 1fr); width: min(760px, 100%); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(16px); }
.nav-button { display: grid; place-items: center; gap: 2px; border: 0; padding: 5px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.nav-button span { font-size: 21px; line-height: 1; }
.nav-button.active { color: var(--accent); }

.detail-view { padding: 4px 0 38px; }
.back-button { position: sticky; z-index: 900; top: 10px; margin: 0 16px 10px; border-radius: 999px; padding: 9px 14px; font-weight: 800; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 10px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.photo-strip::-webkit-scrollbar { display: none; }
.detail-photo { flex: 0 0 calc(100% - 32px); aspect-ratio: 1.35; border-radius: 24px; object-fit: cover; scroll-snap-align: center; background: #dfe5e1; }
.detail-panel { margin: 4px 16px 14px; padding: 19px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.detail-price { font-size: 30px; margin-bottom: 7px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 7px; }
.detail-meta span { padding: 7px 10px; border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: 13px; font-weight: 750; }
.description { white-space: pre-wrap; line-height: 1.5; overflow-wrap: anywhere; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.secondary-button { border: 1px solid var(--line); border-radius: 13px; padding: 12px; background: var(--bg); font-weight: 750; }
.secondary-button.active { color: #d74a67; }
.source-button { display: block; margin-top: 9px; border-radius: 13px; padding: 12px; text-align: center; text-decoration: none; background: var(--accent); color: var(--accent-text); font-weight: 800; }
#detail-map { width: 100%; height: 320px; border-radius: 18px; overflow: hidden; }
.map-missing { display: grid; place-items: center; height: 190px; border-radius: 18px; color: var(--muted); background: var(--bg); text-align: center; }
.toast { position: fixed; z-index: 2000; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 14px; border-radius: 999px; color: white; background: rgba(10, 26, 20, .9); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .listing-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .card-body { padding: 10px; }
  .card-price { font-size: 18px; }
  .card-facts { font-size: 12px; }
}

@media (min-width: 680px) {
  .listing-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
