:root {
  --ink: #14213d;
  --ink-2: #4a5568;
  --muted: #718096;
  --bg: #ffffff;
  --surface: #ffffff;
  --line: #e2e8f0;
  --accent: #e4572e;
  --nd: #cbd5e0;
  --shadow: 0 6px 24px rgba(20, 33, 61, .14);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }

/* Top bar */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line); z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; white-space: nowrap; }
.brand svg { width: 28px; height: 28px; }
.brand b { color: var(--accent); }
#city, #search input, .budget input {
  font: inherit; font-size: 15px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: #f7fafc;
  padding: 9px 10px; min-width: 0;
}
#city { flex: 0 0 auto; }
#search { display: flex; flex: 1; min-width: 0; max-width: 480px; }
#search input { flex: 1; border-radius: 10px 0 0 10px; }
#search button {
  border: 0; background: var(--ink); color: #fff; padding: 0 14px;
  border-radius: 0 10px 10px 0; cursor: pointer;
}
.pill {
  margin-left: auto; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.ghost { width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; font-weight: 700; color: var(--ink-2); cursor: pointer;
}

#map { flex: 1; }
.leaflet-container { font: inherit; background: #eef1f4; }
.leaflet-tile-pane { filter: grayscale(1) contrast(.9) brightness(1.06); }

.card {
  position: absolute; z-index: 900; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px;
}

/* Budget filter */
.budget { top: 72px; left: 16px; width: 270px; }
.budget-row { display: flex; gap: 10px; }
.budget label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; flex: 1; }
.budget input { width: 100%; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; margin: 6px 0 0; }

/* Legend */
.legend { bottom: 24px; left: 16px; font-size: 12px; }
.legend h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend i { width: 18px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.08); }

/* Zone panel */
.panel {
  position: absolute; z-index: 1001; top: 72px; right: 16px; width: 360px;
  max-height: calc(100% - 96px); overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 18px 14px;
}
.panel .close {
  position: absolute; top: 8px; right: 10px; border: 0; background: none;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.chip {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; background: #edf2f7; color: var(--ink-2); margin-right: 6px;
}
.panel h2 { font-size: 18px; margin: 10px 0 4px; line-height: 1.3; padding-right: 20px; }
.panel .descr-more { border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; font: inherit; font-size: 13px; }
.big { font-size: 30px; font-weight: 750; letter-spacing: -.02em; margin: 14px 0 0; }
.big small { font-size: 14px; font-weight: 500; color: var(--muted); }
.sub { color: var(--ink-2); margin: 2px 0 0; font-size: 14px; }
.trend { display: inline-block; margin: 8px 0 0; font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.trend.up { color: #9b2c2c; background: #fff5f5; }
.trend.down { color: #22543d; background: #f0fff4; }
.trend.flat { color: var(--ink-2); background: #edf2f7; }
.estimate { margin-top: 14px; padding: 12px; border-radius: 12px; background: #fff7f2; border: 1px solid #fde3d4; }
.estimate .lbl { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.estimate input { width: 64px; font: inherit; font-size: 14px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 8px; }
.estimate .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.community { margin-top: 12px; padding: 12px; border-radius: 12px; background: #f0f7ff; border: 1px solid #cfe3fb; }
.community .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.community .cval { font-size: 20px; font-weight: 700; margin-top: 2px; }
.community .cval small { font-size: 12px; font-weight: 500; color: var(--muted); }
.report { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.report label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.report input, .report select { font: inherit; font-size: 14px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #f7fafc; min-width: 0; }
.report .primary, .report .hint { grid-column: 1 / -1; }
.report .hp { position: absolute; left: -9999px; width: 1px; height: 1px; }
.thanks { margin-top: 12px; font-size: 14px; color: #22543d; background: #f0fff4; border: 1px solid #c6f6d5; border-radius: 10px; padding: 10px 12px; }
.listings { margin-top: 14px; }
.listings .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.lks { display: flex; flex-wrap: wrap; gap: 6px; }
.lk {
  flex: 1 1 auto; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  color: var(--ink); text-decoration: none; font-size: 13.5px; font-weight: 600; background: #fff;
}
.lk:hover { border-color: var(--ink); }
.lk small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.5; }
.warn { font-size: 12.5px; color: #744210; background: #fffbea; border: 1px solid #f6e05e; border-radius: 10px; padding: 8px 10px; margin-top: 12px; line-height: 1.45; }
.share { margin-top: 12px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.list { margin: 10px 0 0; padding: 0; list-style: none; }
.list li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13.5px; }

.toast {
  position: absolute; z-index: 1100; left: 50%; top: 76px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

dialog {
  border: 0; border-radius: var(--radius); box-shadow: var(--shadow); max-width: 520px; width: calc(100% - 32px);
  padding: 22px; color: var(--ink); line-height: 1.5; font-size: 15px;
}
dialog::backdrop { background: rgba(20, 33, 61, .45); }
dialog h2 { margin-top: 0; }
dialog h3 { margin-bottom: 4px; font-size: 15px; }
dialog ul { padding-left: 18px; margin-top: 4px; }
dialog .src { font-size: 13px; color: var(--ink-2); }
dialog a { color: var(--accent); }
.primary { background: var(--ink); color: #fff; border: 0; border-radius: 10px; padding: 10px 18px; font: inherit; cursor: pointer; }

.zone-tip { font-size: 12.5px; }

.zlist { list-style: none; margin: 12px 0 0; padding: 0; }
.zrow button {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; width: 100%;
  border: 0; border-top: 1px solid var(--line); background: none; padding: 9px 2px; text-align: left;
  font: inherit; font-size: 13.5px; color: var(--ink); cursor: pointer;
}
.zrow button:hover { background: #f7fafc; }
.zrow i { width: 12px; height: 12px; border-radius: 3px; }
.zname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zval { text-align: right; font-weight: 600; white-space: nowrap; }
.zval small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.zrow.out { opacity: .4; }

/* Phone: budget collapses under the bar, panel becomes a bottom sheet */
@media (max-width: 767px) {
  .bar { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .brand { font-size: 16px; }
  #search { order: 3; flex: 1 1 calc(100% - 44px); max-width: none; }
  #infoBtn { order: 4; }
  .ghost { width: 32px; height: 32px; margin-left: 0; }
  .pill { padding: 6px 10px; font-size: 13px; }
  .budget { top: auto; left: 16px; right: 16px; width: auto; bottom: 16px; padding: 10px 12px; }
  .budget .hint#budgetMsg:empty { display: none; }
  /* Compact horizontal legend strip under the bar */
  .legend { bottom: auto; top: 116px; left: 16px; right: 16px; padding: 6px 8px; display: flex; gap: 2px; font-size: 10px; }
  .legend h4 { display: none; }
  .legend .row { flex: 1; flex-direction: column; gap: 2px; margin: 0; text-align: center; white-space: nowrap; }
  .legend i { width: 100%; height: 8px; }
  .panel-open .legend, .panel-open .budget { display: none; }
  .panel {
    top: auto; right: 0; left: 0; bottom: 0; width: auto;
    max-height: 48%; border-radius: 18px 18px 0 0; padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  .toast { top: 160px; }
}
