:root {
  --bg: #F5F2EC;
  --bg-2: #F2EFE8;
  --surface: #FFFFFF;
  --ink: #1A1F4D;
  --ink-2: #3B4068;
  --muted: #7B7868;
  --border: #E2DDD2;
  --border-2: #C9C2B2;
  --red: #D1232A;
  --blue: #0072BC;
  --green: #009A44;
  --warn: #C24A2C;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; letter-spacing: 0.01em; }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.app { display: flex; flex-direction: column; min-height: 100vh; max-width: 1480px; margin: 0 auto; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 24px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center;
}
.brand-title { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

/* Filter input */
.filter-bar { position: relative; flex: 1; min-width: 0; max-width: 560px; }
.filter-input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--border-2); border-radius: 12px;
  padding: 0 12px; height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
.filter-input-wrap:focus-within { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(26,31,77,0.08); }
.filter-input-wrap.err { border-color: var(--warn); }
.filter-input-wrap.lim { background: var(--bg-2); opacity: 0.7; }
.filter-prefix {
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px; font-weight: 700;
  color: var(--muted); letter-spacing: 0.12em;
  padding: 3px 7px; background: var(--bg-2); border-radius: 5px;
}
.filter-input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px; font-weight: 600; color: var(--ink); letter-spacing: 0.04em;
}
.filter-input::placeholder { color: #B4AE9E; font-weight: 500; letter-spacing: 0.02em; }
.filter-input:disabled { color: var(--muted); }
.filter-clear { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 8px; }
.filter-clear:hover { color: var(--ink); }
.filter-error { font-size: 12px; color: var(--warn); margin-top: 6px; padding-left: 4px; }

.filter-pop {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
  box-shadow: 0 12px 32px rgba(26,31,77,0.08); z-index: 40;
}
.filter-section + .filter-section { margin-top: 14px; }
.filter-section-title { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 8px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-2); background: var(--bg-2); border-radius: 6px; padding: 5px 9px; font-size: 12px; font-weight: 600; color: var(--ink); }
.chip:hover { border-color: var(--ink); }
.filter-suggestions { display: flex; flex-direction: column; gap: 2px; }
.suggestion { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: transparent; border: 0; text-align: left; width: 100%; }
.suggestion:hover { background: var(--bg-2); }
.suggestion-code { display: inline-block; min-width: 56px; padding: 3px 7px; background: var(--ink); color: #fff; border-radius: 5px; font-size: 12px; font-weight: 700; }
.suggestion-label { font-size: 13px; color: var(--ink-2); }

/* ── Selection bar ───────────────────────────────────── */
.sel-empty {
  margin: 0 28px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px dashed var(--border-2); border-radius: 12px;
  color: var(--muted); font-size: 13px;
}
.sel-empty-glyph { font-size: 16px; }

.sel-chips-row {
  margin: 0 28px; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 1px 0 rgba(26,31,77,0.02);
}
.sel-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sel-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--ink); color: #fff;
  padding: 6px 6px 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
}
.sel-chip.metro { background: #2A4264; }
.sel-chip-x {
  background: rgba(255,255,255,0.18); border: 0; color: #fff;
  width: 22px; height: 22px; border-radius: 999px;
  font-size: 16px; line-height: 1; display: grid; place-items: center;
  padding: 0;
}
.sel-chip-x:hover { background: rgba(255,255,255,0.32); }
.sel-limit {
  font-size: 12px; font-weight: 700; color: var(--warn);
  padding: 5px 9px; background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-radius: 999px;
}
.sel-counter {
  font-size: 11px; font-weight: 700; color: var(--muted);
  padding: 5px 10px; background: var(--bg-2); border-radius: 999px;
  letter-spacing: 0.02em;
}
.sel-actions { display: flex; gap: 6px; flex-shrink: 0; }
.sel-action {
  background: var(--ink); color: #fff; border: 0;
  padding: 8px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  transition: opacity .15s;
}
.sel-action:hover { opacity: 0.88; }
.sel-action.ghost { background: transparent; color: var(--ink-2); }
.sel-action.ghost:hover { color: var(--ink); }

/* ── Main layout ─────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) 380px;
  gap: 24px; padding: 18px 28px 28px;
  align-items: start;
}
@media (max-width: 1100px) {
  .main { grid-template-columns: 1fr; }
  .sel-chips-row, .sel-empty { margin: 0 16px; }
}
@media (max-width: 640px) {
  .filter-bar { flex-basis: 100%; max-width: none; order: 3; }
  .main { padding: 12px 10px 20px; gap: 16px; }
  .map-pane { padding: 10px; }
}

/* ── Map pane ────────────────────────────────────────── */
.map-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  overflow: hidden;
}
.map-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.map-title { font-weight: 700; font-size: 14px; }
.map-tools { display: flex; gap: 6px; }
.tool {
  border: 1px solid var(--border-2); background: transparent;
  border-radius: 8px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  color: var(--ink-2);
}
.tool:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.tool.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.map-canvas { position: relative; border-radius: 12px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--border); touch-action: none; }
.map-canvas-zoom { will-change: transform; }
.kyiv-svg { width: 100%; height: auto; display: block; }

/* ── Legend ──────────────────────────────────────────── */
.legend {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 0.9fr;
  gap: 18px;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px dashed var(--border-2);
}
@media (max-width: 760px) { .legend { grid-template-columns: 1fr; } }
.legend-h { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 10px; }
.legend-hint { font-weight: 500; text-transform: none; letter-spacing: 0; opacity: 0.75; margin-left: 4px; }
.legend-districts { display: flex; flex-direction: column; gap: 6px; }
.d-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 5px; border-radius: 999px;
  background: var(--c); border: 1px solid var(--border-2);
  font-size: 12px; font-weight: 600; color: var(--ink);
}
.d-pill:hover { border-color: var(--ink); }
.d-pill.on { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(26,31,77,0.12); }
.d-pill-num { display: inline-grid; place-items: center; min-width: 22px; height: 22px; background: rgba(255,255,255,0.7); border-radius: 999px; font-size: 11px; font-weight: 800; }
.d-pill-name { font-size: 12px; }
.d-pill-count { font-size: 10.5px; font-weight: 700; color: var(--ink); opacity: 0.6; padding-left: 4px; border-left: 1px solid rgba(26,31,77,0.18); }

.legend-metro { display: flex; flex-direction: column; gap: 12px; }
.m-row { display: flex; flex-direction: column; gap: 6px; }
.m-row-head { display: flex; align-items: center; gap: 8px; }
.m-dot { width: 10px; height: 10px; border-radius: 999px; flex-shrink: 0; }
.m-name { font-size: 12px; font-weight: 600; flex: 1; min-width: 0; }
.m-segs { display: flex; flex-direction: column; gap: 4px; }
.m-seg { display: flex; align-items: baseline; gap: 8px; border: 1px solid var(--c); background: transparent; color: var(--c); border-radius: 6px; padding: 5px 9px; font-size: 11px; font-weight: 700; text-align: left; width: 100%; }
.m-seg:hover { background: color-mix(in srgb, var(--c) 12%, transparent); }
.m-seg.on { background: var(--c); color: #fff; }
.m-seg-range { font-size: 10.5px; font-weight: 500; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-seg-static { cursor: default; opacity: 0.9; }
.m-seg-static:hover { background: transparent; }
.legend-foot { font-size: 11px; color: var(--muted); margin-top: 8px; }
.legend-sub { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.legend-sub .mono { display: inline-block; min-width: 18px; padding: 1px 5px; background: var(--bg-2); border-radius: 4px; font-weight: 700; margin-right: 6px; }

/* ── Listings ────────────────────────────────────────── */
.side-pane { position: sticky; top: 96px; }
.listings { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px; max-height: calc(100vh - 120px); display: flex; flex-direction: column; }
.listings-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.listings-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.listings-count { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.listings-noun { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.sel-count { font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 8px; background: var(--bg-2); border-radius: 999px; }

.tag { display: inline-block; padding: 3px 8px; background: var(--bg-2); border-radius: 5px; font-size: 11.5px; font-weight: 700; color: var(--ink); }
.tag.metro-tag { background: var(--ink); color: #fff; }

.listings-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding-right: 4px; }
.listings-list::-webkit-scrollbar { width: 6px; }
.listings-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface); transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--ink); transform: translateY(-1px); }
.card-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-title { font-weight: 700; font-size: 13.5px; }
.card-price { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 13px; }
.card-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; margin-top: 3px; }
.card-tags { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-glyph { font-size: 36px; margin-bottom: 8px; }
.empty-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty-sub { font-size: 12px; }
