:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #14213d;
  --ink-2: #3d4a63;
  --muted: #6b7489;
  --line: #e4e1d8;
  --line-2: #efece5;
  --brand: #14213d;
  --accent: #0e9f6e;
  --accent-ink: #046c4e;
  --accent-soft: #def7ec;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #c2410c;
  --s1: #e8f1ec; --s2: #b7dccb; --s3: #6fbd9b; --s4: #2b9b6e; --s5: #0b6e4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 24px rgba(20, 33, 61, .06);
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --top: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  height: var(--top);
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: var(--brand);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; letter-spacing: -.01em; }
.brand svg { width: 30px; height: 30px; color: #22345c; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: 0; color: #c9d1e4; padding: 8px 12px; border-radius: 8px; font-weight: 500;
}
.tab:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.tab.is-active { color: #fff; background: rgba(255, 255, 255, .12); }
.fresh { margin-left: auto; font-size: 13px; color: #aeb8cf; }
.fresh b { color: #fff; font-weight: 500; }

/* Search bar */
.searchbar {
  display: flex; align-items: flex-end; gap: 22px; flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.budget-inputs { display: flex; align-items: center; gap: 8px; }
.budget-inputs span { color: var(--muted); font-size: 13px; }
select {
  appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%236b7489' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center / 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 32px 9px 12px;
  min-height: 40px;
}
select:focus, button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips, .segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 8px 14px; min-height: 40px; font-weight: 500; color: var(--ink-2);
}
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.segmented { background: var(--line-2); padding: 4px; border-radius: 12px; gap: 2px; }
.segmented button { border: 0; background: none; padding: 7px 12px; border-radius: 9px; font-weight: 500; color: var(--ink-2); min-height: 32px; }
.segmented button.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 33, 61, .12); }
.more {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; min-height: 40px; font-weight: 500;
}
.more svg { width: 18px; height: 18px; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; }

.more-panel { background: var(--surface); border-bottom: 1px solid var(--line); padding: 4px 20px 18px; }
.more-grid { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; color: var(--ink-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.weights { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.weights-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.weights-head span { color: var(--muted); font-size: 13px; }
.weights-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 22px; }
.weight { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 14px; }
.weight output { color: var(--muted); font-size: 13px; }
.weight input { grid-column: 1 / -1; accent-color: var(--accent); }

/* Main layout */
.app { height: calc(100vh - var(--top) - var(--bar, 70px)); }
.view { display: none; height: 100%; }
.view.is-active { display: block; }
.view-search.is-active { display: grid; grid-template-columns: minmax(380px, 460px) 1fr; position: relative; }
.results { overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg); }
.results-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 18px 12px; background: var(--bg);
  border-bottom: 1px solid var(--line-2);
}
.results-head h1 { font-family: var(--serif); font-weight: 400; font-size: 28px; line-height: 1.1; margin: 0 0 4px; letter-spacing: -.01em; }
.results-head p { margin: 0; font-size: 13px; }
.mobile-switch { display: none; }
.cards { list-style: none; margin: 0; padding: 12px; display: grid; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
}
.card:hover, .card.is-hover { border-color: #b9c2d6; box-shadow: var(--shadow); }
.card.is-selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.card h2 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.card .where { font-size: 13px; color: var(--muted); }
.card .price { grid-column: 1 / -1; margin-top: 6px; font-size: 15px; }
.card .price strong { font-size: 18px; font-weight: 600; }
.card .tags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 500; padding: 3px 8px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); }
.tag.good { background: var(--accent-soft); color: var(--accent-ink); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.score { grid-row: 1 / span 2; grid-column: 2; display: grid; place-items: center; }
.ring { --p: 50; width: 52px; height: 52px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line-2) 0);
  display: grid; place-items: center; }
.ring span { width: 42px; height: 42px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 16px; }
.score small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bars { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.bars div { display: grid; gap: 3px; font-size: 10.5px; color: var(--muted); text-align: center; }
.bars i { display: block; height: 4px; border-radius: 2px; background: var(--line-2); position: relative; overflow: hidden; }
.bars i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: calc(var(--v) * 1%); background: var(--s4); border-radius: 2px; }
.load-more { display: block; margin: 4px auto 24px; border: 1px solid var(--line); background: var(--surface); padding: 10px 18px; border-radius: 10px; font-weight: 500; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }

.map-wrap { position: relative; }
#map { position: absolute; inset: 0; background: #e9e6df; }
.legend {
  position: absolute; left: 12px; bottom: 22px; z-index: 500;
  background: rgba(255, 255, 255, .94); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px; display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted);
}
.legend i { width: 14px; height: 10px; border-radius: 3px; display: block; }
.l1 { background: #e3ece7; } .l2 { background: #b7dccb; } .l3 { background: #6fbd9b; } .l4 { background: #2b9b6e; } .l5 { background: #0b6e4f; }
.leaflet-container { font-family: var(--font); }
.leaflet-tile-pane { filter: grayscale(1) contrast(.92) brightness(1.06); opacity: .75; }
.legend em { font-style: normal; margin-left: 8px; padding-left: 8px; border-left: 1px solid var(--line); }
.legend em:empty { display: none; }
.leaflet-tooltip.street-tip { font-family: var(--font); font-size: 13px; border-radius: 8px; border: 1px solid var(--line); box-shadow: var(--shadow); }

/* Street detail */
.detail {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(500px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(20, 33, 61, .10);
  overflow-y: auto; z-index: 900; padding: 22px 22px 40px;
}
.close { position: absolute; top: 12px; right: 14px; border: 0; background: var(--line-2); width: 34px; height: 34px; border-radius: 50%; font-size: 22px; line-height: 1; }
.detail h2 { font-family: var(--serif); font-weight: 400; font-size: 32px; line-height: 1.05; margin: 0 40px 4px 0; letter-spacing: -.01em; }
.detail .where { color: var(--muted); margin: 0 0 16px; }
.d-hero { display: flex; gap: 16px; align-items: center; padding: 14px; border-radius: var(--radius); background: var(--bg); margin-bottom: 18px; }
.d-hero .ring { width: 64px; height: 64px; }
.d-hero .ring span { width: 52px; height: 52px; font-size: 20px; }
.d-hero p { margin: 0; font-size: 14px; color: var(--ink-2); }
.d-section { margin: 22px 0 0; }
.d-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kpi b { display: block; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.kpi span { font-size: 12.5px; color: var(--muted); }
.scorelist { display: grid; gap: 9px; }
.srow { display: grid; grid-template-columns: 110px 1fr 34px; align-items: center; gap: 10px; font-size: 14px; }
.srow .track { height: 8px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.srow .track i { display: block; height: 100%; background: var(--s4); border-radius: 4px; }
.srow em { font-style: normal; text-align: right; font-weight: 600; }
.srow small { grid-column: 2 / -1; margin-top: -5px; color: var(--muted); font-size: 12.5px; }
.near { display: grid; gap: 8px; }
.near div { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.near svg { width: 20px; height: 20px; color: var(--ink-2); }
.near span.muted { font-size: 13px; }
.types { width: 100%; border-collapse: collapse; font-size: 14px; }
.types th, .types td { padding: 7px 4px; border-bottom: 1px solid var(--line-2); text-align: right; }
.types th:first-child, .types td:first-child { text-align: left; }
.types th { font-size: 12px; color: var(--muted); font-weight: 600; }
.portals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.portal { display: block; text-align: center; padding: 11px 6px; border-radius: 10px; background: var(--ink); color: #fff; text-decoration: none; font-weight: 600; font-size: 14px; }
.portal:hover { background: #22345c; }
.portal.alt { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.sales { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.sales td { padding: 8px 4px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.sales td:last-child { text-align: right; white-space: nowrap; }
.sales small { color: var(--muted); display: block; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line-2); }

/* Pages */
.view-areas, .view-method { overflow-y: auto; }
.page { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }
.page h1 { font-family: var(--serif); font-weight: 400; font-size: 42px; letter-spacing: -.01em; margin: 0 0 8px; line-height: 1.05; }
.lead { color: var(--ink-2); font-size: 17px; margin: 0 0 24px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
.table th.sorted { color: var(--ink); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--bg); }
.prose { font-size: 16px; line-height: 1.6; }
.prose h2 { font-size: 20px; margin: 32px 0 8px; }
.prose p, .prose li { color: var(--ink-2); }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0 16px; }
.prose td, .prose th { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.callout { background: var(--warn-soft); color: #78350f; padding: 14px 16px; border-radius: 12px; font-size: 14.5px; }
.prose a { color: var(--accent-ink); }

/* Tablet and phone */
@media (max-width: 1100px) {
  .searchbar { gap: 14px; }
  .fresh { display: none; }
}
@media (max-width: 820px) {
  :root { --top: 54px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  .tabs { margin-left: auto; }
  .tab { padding: 7px 9px; font-size: 14px; }
  .searchbar { padding: 12px 16px; gap: 12px; }
  .searchbar .field { width: 100%; }
  .budget-inputs select { flex: 1; min-width: 0; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 7px 4px; font-size: 14px; }
  .more { width: 100%; justify-content: center; }
  .more-panel { padding: 4px 16px 16px; }
  .more-grid .field { width: 100%; }
  .more-grid select { width: 100%; }
  .app { height: auto; }
  .view-search.is-active { display: block; }
  .results { border-right: 0; overflow: visible; }
  .results-head { position: static; padding: 14px 16px 8px; flex-direction: column; }
  .results-head .sort, .results-head select { width: 100%; }
  .mobile-switch { display: flex; gap: 6px; padding: 8px 16px 0; }
  .mobile-switch button { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px; font-weight: 600; }
  .mobile-switch button.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }
  .cards { padding: 10px 16px; }
  .map-wrap { display: none; height: 70vh; margin: 10px 16px 24px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
  .show-map .map-wrap { display: block; }
  .show-map .cards, .show-map .load-more { display: none; }
  .detail { position: fixed; inset: 0; width: 100%; padding: 20px 16px 40px; }
  .bars { grid-template-columns: repeat(4, 1fr); row-gap: 8px; }
  .page h1 { font-size: 34px; }
  .page { padding: 24px 16px 48px; }
}
