/* Airbnb-inspired tokens */
:root {
  --rausch: #ff385c;          /* primary accent */
  --rausch-dark: #e0124a;
  --babu: #00a699;
  --foggy: #767676;
  --hof: #484848;
  --night: #222222;
  --white: #ffffff;
  --offwhite: #f7f7f7;
  --bg: #fafafa;
  --line: #ebebeb;
  --line-strong: #dddddd;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 6px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 14px 40px rgba(0,0,0,0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; color: var(--night); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
a { color: inherit; }

/* Top bar */
.topbar { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 18px; padding: 14px 32px; background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--rausch), #ff7a59); }
.logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.meta { font-size: 13px; color: var(--foggy); text-align: right; line-height: 1.5; }

/* Filter chips */
.filterbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--white); color: var(--hof); font-size: 13px; font-weight: 500; transition: all .15s ease; }
.chip:hover { border-color: var(--night); }
.chip.active { background: var(--night); color: var(--white); border-color: var(--night); }
.chip.select { padding-right: 10px; }
.chip select.select, .chip.select { appearance: none; cursor: pointer; }
.chip.range { padding-right: 6px; }
.chip.range input { width: 70px; height: 24px; border: none; outline: none; background: transparent; font-weight: 500; padding: 0 4px; text-align: right; -moz-appearance: textfield; }
.chip.range input::-webkit-outer-spin-button, .chip.range input::-webkit-inner-spin-button { -webkit-appearance: none; }
.chip.toggle input { margin-right: 4px; accent-color: var(--rausch); }
.chip.toggle:has(input:checked),
.chip.toggle.checked { background: #fff0f3; border-color: var(--rausch); color: var(--rausch); }
.chip.toggle.fav.checked { background: var(--rausch); color: var(--white); border-color: var(--rausch); }

/* Heart / favorite button */
.fav-btn { position: absolute; top: 12px; left: 12px; width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(255,255,255,0.92); color: var(--hof); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: transform .15s ease, color .15s ease; z-index: 1; }
.fav-btn:hover { transform: scale(1.1); }
.fav-btn svg { width: 18px; height: 18px; }
.fav-btn.is-fav { color: var(--rausch); }
.fav-btn.is-fav svg { fill: var(--rausch); }
.card { position: relative; }
.card .addr, .card .hero { padding-left: 36px; }
.card .pills { padding-left: 0; }

.fav-btn-detail { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--white); color: var(--hof); font-weight: 600; font-size: 13px; cursor: pointer; transition: all .15s ease; }
.fav-btn-detail:hover { border-color: var(--rausch); color: var(--rausch); }
.fav-btn-detail.is-fav { background: var(--rausch); color: var(--white); border-color: var(--rausch); }
.fav-btn-detail svg { width: 16px; height: 16px; }
.fav-btn-detail.is-fav svg { fill: currentColor; }
.muted { color: var(--foggy); font-weight: 400; }
.chip.secondary { gap: 8px; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(560px, 1fr) minmax(0, 1.1fr); height: calc(100vh - 65px); }
.results { padding: 24px 32px 32px; overflow-y: auto; }
.results-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.results-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }

/* Card */
.card { background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--line); padding: 16px; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; position: relative; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: transparent; }
.card .hero { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card .lot-sf { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
.card .lot-sf small { font-size: 11px; font-weight: 500; color: var(--foggy); margin-left: 4px; }
.card .score { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; font-weight: 700; font-size: 14px; }
.score.tier-call { background: var(--rausch); color: var(--white); }
.score.tier-mail { background: #ffefe6; color: #c2410c; }
.score.tier-watch { background: var(--offwhite); color: var(--hof); }
.score.tier-skip { background: transparent; color: var(--foggy); border: 1px dashed var(--line-strong); }
.card .addr { font-size: 14px; color: var(--hof); margin-bottom: 6px; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.card .city-line { font-size: 12px; color: var(--foggy); margin-bottom: 12px; }
.card .pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 3px 9px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 500; background: var(--offwhite); color: var(--hof); }
.pill.listed { background: #e6f7ee; color: #0a7d3b; }
.pill.investor { background: #f3e8ff; color: #6b21a8; }
.pill.teardown { background: #ffeacc; color: #9a3412; }
.pill.transit { background: #e0f2fe; color: #0369a1; }
.pill.duplex { background: #ede9fe; color: #5b21b6; }
.pill.cottage { background: #fef3c7; color: #92400e; }

/* Map */
.map-wrap { background: var(--white); border-left: 1px solid var(--line); }
#map { width: 100%; height: 100%; }
.maplibregl-popup-content { padding: 14px 16px !important; border-radius: var(--radius-md) !important; box-shadow: var(--shadow-md) !important; font-family: inherit; }

/* Drawer */
.drawer { position: fixed; top: 65px; right: 0; width: 420px; max-width: 92vw; height: calc(100vh - 65px); background: var(--white); box-shadow: var(--shadow-lg); padding: 28px 28px 32px; overflow-y: auto; z-index: 30; transform: translateX(0); transition: transform .25s ease; }
.drawer.hidden { transform: translateX(100%); }
.drawer-close { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--white); font-size: 20px; line-height: 1; color: var(--hof); }
.drawer-close:hover { background: var(--offwhite); }
.detail-h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.detail-sub { color: var(--foggy); font-size: 14px; margin-bottom: 18px; }
.detail-score { display: flex; align-items: center; gap: 14px; margin: 0 0 18px; padding: 14px; background: var(--offwhite); border-radius: var(--radius-md); }
.detail-score .score { width: 56px; height: 56px; font-size: 18px; }
.detail-score .label { font-weight: 600; font-size: 15px; }
.detail-score .label small { display: block; color: var(--foggy); font-weight: 400; font-size: 12px; margin-top: 2px; }

.detail-section { margin-top: 18px; }
.detail-section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--foggy); font-weight: 600; }
.detail-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-row span:first-child { color: var(--foggy); }
.detail-row span:last-child { color: var(--night); font-weight: 500; text-align: right; }
ul.notes { padding-left: 18px; font-size: 12px; color: var(--hof); margin: 6px 0; }
ul.notes li { margin: 4px 0; }

.action-row { display: flex; gap: 10px; margin: 18px 0 0; }
.btn { flex: 1; height: 44px; border-radius: var(--radius-pill); font-weight: 600; font-size: 14px; border: 1px solid var(--line-strong); background: var(--white); color: var(--night); transition: all .15s ease; }
.btn:hover { border-color: var(--night); }
.btn.primary { background: var(--rausch); color: var(--white); border-color: var(--rausch); }
.btn.primary:hover { background: var(--rausch-dark); border-color: var(--rausch-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.contact-block { margin-top: 14px; }
.contact-block .contact-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--foggy); font-weight: 600; margin: 12px 0 6px; }
.contact-block .phone, .contact-block .email { font-size: 14px; padding: 4px 0; font-weight: 500; }
.contact-block .phone .meta { font-size: 11px; color: var(--foggy); font-weight: 400; margin-left: 4px; }

.warn { font-size: 13px; color: #92400e; padding: 10px 12px; background: #fef3c7; border-radius: var(--radius-sm); margin: 8px 0; }
.empty { text-align: center; padding: 60px 20px; color: var(--foggy); }
.empty h2 { font-weight: 600; color: var(--hof); margin: 8px 0; }

/* Admin / refresh panel */
.admin-wrap { position: relative; }
.admin-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--radius-pill); border: 1px solid var(--night); background: var(--night); color: var(--white); font-size: 13px; font-weight: 600; transition: background .15s ease; }
.admin-btn:hover { background: #000; }
.admin-btn svg { display: block; }

.admin-panel { position: absolute; right: 0; top: calc(100% + 12px); width: 360px; max-height: calc(100vh - 110px); overflow-y: auto; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 18px 20px 14px; z-index: 40; }
.admin-panel.hidden { display: none; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.admin-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.admin-close { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--white); font-size: 18px; line-height: 1; color: var(--hof); }
.admin-close:hover { background: var(--offwhite); }
.admin-action { padding: 12px 0; border-bottom: 1px solid var(--line); }
.admin-action:last-child { border-bottom: none; }
.admin-action.diag { padding: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.admin-action.diag .admin-action-h { margin: 0; }
.admin-action.diag .btn { width: auto; padding: 0 16px; height: 36px; flex-shrink: 0; }
.admin-action-h { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; gap: 8px; }
.admin-action-h strong { font-size: 14px; font-weight: 600; color: var(--night); }
.admin-est { font-size: 11px; color: var(--foggy); white-space: nowrap; }
.admin-action p { font-size: 12px; color: var(--foggy); margin: 0 0 10px; line-height: 1.45; }
.last-run { font-size: 11px; color: var(--foggy); margin: 0 0 8px; }
.last-run.fresh { color: #0a7d3b; }
.last-run.stale { color: #c2410c; }
.admin-action .btn { width: 100%; height: 36px; font-size: 13px; }
.admin-row { display: flex; gap: 8px; align-items: center; }
.admin-row .chip.select { flex: 1; height: 36px; }
.admin-row .btn { flex-shrink: 0; width: auto; padding: 0 16px; }
.admin-divider { height: 1px; background: var(--line); margin: 8px 0; }
.admin-status { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12px; line-height: 1.5; min-height: 0; max-height: 160px; overflow-y: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; display: none; }
.admin-status.show { display: block; }
.admin-status.running { background: #fff7ed; color: #92400e; }
.admin-status.ok { background: #ecfdf5; color: #065f46; }
.admin-status.error { background: #fef2f2; color: #991b1b; white-space: pre-wrap; }

/* Map / List toggle (mobile only) */
.view-toggle { display: none; position: sticky; top: 65px; z-index: 15; padding: 10px 16px; background: var(--white); border-bottom: 1px solid var(--line); gap: 6px; justify-content: center; }
.view-toggle .vt-btn { flex: 1; max-width: 200px; height: 40px; border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--white); color: var(--hof); font-weight: 600; font-size: 14px; }
.view-toggle .vt-btn.active { background: var(--night); color: var(--white); border-color: var(--night); }

/* ≤1100px: stack list + map */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 420px; border-left: none; border-top: 1px solid var(--line); position: sticky; top: 65px; }
  .results { height: auto; max-height: none; overflow: visible; }
}

/* ≤900px: smaller padding, tighter cards */
@media (max-width: 900px) {
  .topbar { padding: 12px 18px; gap: 12px; }
  .results { padding: 18px 18px 24px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
  .map-wrap { position: static; height: 380px; }
}

/* ≤768px: stack the topbar to two rows, scroll filters horizontally,
   show the view toggle, and hide the meta count (admin panel surfaces it). */
@media (max-width: 768px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "brand meta admin"
      "filters filters filters";
    padding: 10px 14px 0;
    gap: 10px 12px;
  }
  .brand { grid-area: brand; }
  .meta { grid-area: meta; font-size: 11px; }
  .admin-wrap { grid-area: admin; }
  .filterbar {
    grid-area: filters;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 12px;
    margin: 0 -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .filterbar::-webkit-scrollbar { display: none; }
  .filterbar { scrollbar-width: none; }
  .chip-group { flex-wrap: nowrap; }
  .chip { scroll-snap-align: start; flex-shrink: 0; }
  .chip-group.secondary { gap: 6px; }
  .admin-label { display: none; }
  .admin-btn { padding: 0 12px; height: 38px; }

  .view-toggle { display: flex; }

  .layout { grid-template-rows: auto; }
  .layout[data-view="list"] .map-wrap { display: none; }
  .layout[data-view="map"] .results { display: none; }
  .layout[data-view="map"] .map-wrap { height: calc(100vh - 175px); }

  .results-head h1 { font-size: 18px; }

  .cards { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; }
  .card .lot-sf { font-size: 20px; }
  .card .score { width: 40px; height: 40px; font-size: 13px; }

  /* Drawer: bottom sheet on phones */
  .drawer {
    top: auto; bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%;
    height: auto; max-height: 88vh;
    border-top-left-radius: 18px; border-top-right-radius: 18px;
    transform: translateY(0);
    padding: 18px 20px 28px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .drawer.hidden { transform: translateY(100%); }
  .drawer::before {
    content: ""; display: block; width: 36px; height: 4px;
    background: var(--line-strong); border-radius: 2px;
    margin: -4px auto 12px;
  }
  .drawer-close { top: 10px; right: 10px; }
  .detail-h1 { font-size: 19px; }
  .detail-score .score { width: 48px; height: 48px; font-size: 16px; }

  /* Admin panel: bottom sheet on phones */
  .admin-panel {
    position: fixed; top: auto; bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%; max-height: 80vh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.18);
    padding: 16px 18px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .admin-panel::before {
    content: ""; display: block; width: 36px; height: 4px;
    background: var(--line-strong); border-radius: 2px;
    margin: -4px auto 10px;
  }
}

/* ≤480px: smallest phones */
@media (max-width: 480px) {
  .topbar { padding: 8px 12px 0; }
  .logo-text { font-size: 15px; }
  .meta { display: none; }
  .results { padding: 14px 14px 20px; }
  .results-head { margin-bottom: 12px; }
  .chip { height: 34px; font-size: 12px; padding: 0 12px; }
  .chip.range input { width: 60px; }
  .vt-btn { font-size: 13px; }
  .layout[data-view="map"] .map-wrap { height: calc(100vh - 165px); }
}
