/* Damha Watch. A land-survey instrument for interior São Paulo at night:
   deep cerrado-night blue, ipê-yellow for the instrument, survey-laser cyan for good deals,
   terra-roxa coral for warnings. Chamfered panels instead of rounded cards. */

:root {
  --night: #081423;
  --deep: #0e2036;
  --deeper: #0b1a2d;
  --rule: #1f3a5c;
  --rule-soft: #16304d;
  --ipe: #ffc94d;
  --laser: #2fd3a8;
  --terra: #ff7a59;
  --neutral: #8a9bb3;
  --mist: #d9e4f2;
  --haze: #8ea3c0;
  --c-I: #e24d8b;
  --c-II: #338ced;
  --c-III: #e76624;
  --c-IV: #00a888;
  --c-GOLF: #d28e05;
  --c-UNSURE: #8a9bb3;
  --display: 'Unbounded', 'Segoe UI', sans-serif;
  --body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --chamfer: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--night); color: var(--mist); }
body {
  font: 15px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--ipe); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ipe); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.9rem; }
.muted { color: var(--haze); }
.small { font-size: 0.82rem; }
.good { color: var(--laser); }
.bad { color: var(--terra); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 88px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--rule-soft);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 0;
  background: linear-gradient(180deg, var(--deeper), var(--night));
}
.mark { width: 44px; height: 44px; margin-bottom: 18px; }
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 72px; padding: 10px 0; text-decoration: none; color: var(--haze);
  font-size: 0.72rem; border-left: 2px solid transparent;
}
.nav a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.nav a:hover { color: var(--mist); }
.nav a[aria-current='page'] { color: var(--ipe); border-left-color: var(--ipe); background: linear-gradient(90deg, rgba(255, 201, 77, 0.08), transparent); }
.rail .nav { display: flex; flex-direction: column; gap: 2px; }

main { min-width: 0; padding: 22px clamp(14px, 3vw, 36px) 90px; max-width: 1400px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.15rem; }
.ticker {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 14px;
  border: 1px solid var(--rule); background: var(--deeper);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}
.ticker b { font-family: var(--display); font-weight: 500; font-size: 1.05rem; color: var(--ipe); }

/* ---------- panels ---------- */
.panel {
  position: relative; background: var(--deep); border: 1px solid var(--rule-soft);
  padding: 18px; clip-path: polygon(0 0, calc(100% - var(--chamfer)) 0, 100% var(--chamfer), 100% 100%, 0 100%);
}
.panel::after { /* the chamfer edge, drawn as a line */
  content: ''; position: absolute; top: 0; right: 0; width: calc(var(--chamfer) * 1.414); height: 1px;
  background: var(--rule); transform-origin: right top; transform: rotate(45deg) translate(-1px, 0);
}
.panel > header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- radar hero ---------- */
.radar { position: relative; margin: 0 0 16px; border: 1px solid var(--rule-soft); background: radial-gradient(ellipse at 50% 55%, #10284a 0%, var(--deeper) 60%, var(--night) 100%); overflow: hidden; }
.radar > svg { display: block; width: 100%; height: auto; }
.radar .contour { fill: none; stroke: #2a4a72; stroke-width: 0.8; opacity: 0.55; }
.radar .contour.index { stroke: #3f6796; stroke-width: 1.3; opacity: 0.8; }
.radar .elev { fill: #4d73a0; font: 9px var(--body); }
.radar > svg .zone-shape { fill-opacity: 0.07; stroke-width: 1.4; stroke-dasharray: 5 5; cursor: pointer; transition: fill-opacity 0.2s; }
.radar > svg .zone:hover .zone-shape, .radar > svg .zone:focus .zone-shape { fill-opacity: 0.16; }
.radar .zone { outline: none; }
.radar .zone-name { font: 500 17px var(--display); fill: var(--mist); }
.radar .zone-name, .radar .zone-stat, .radar .readout { paint-order: stroke; stroke: #0b1a2d; stroke-width: 4px; stroke-linejoin: round; }
.radar .zone-stat { font: 12px var(--body); fill: var(--haze); }
.radar .zone-stat b { fill: var(--mist); font-weight: 600; }
.radar .blip { cursor: pointer; stroke: var(--night); stroke-width: 2; }
.radar .blip:hover { stroke: var(--mist); }
.radar .pulse { fill: none; stroke-width: 1.5; animation: pulse 2.4s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.radar .star-ring { fill: none; stroke: var(--ipe); stroke-width: 1.5; }
.radar .readout { font: 11px var(--body); fill: var(--haze); }
.radar .sweep { transform-origin: 500px 270px; animation: sweep 2.6s cubic-bezier(0.5, 0.05, 0.3, 1) 0.2s 1 both; }
@keyframes sweep { from { transform: rotate(-90deg); opacity: 1; } 85% { opacity: 0.9; } to { transform: rotate(270deg); opacity: 0; } }
@keyframes pulse { from { transform: scale(1); opacity: 0.9; } to { transform: scale(3.2); opacity: 0; } }
.radar-caption { position: absolute; left: 16px; bottom: 12px; display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--haze); }
.radar-caption i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* real streets, water and survey furniture on the radar */
.radar .road { fill: none; stroke: #3a5f8c; stroke-linecap: round; stroke-linejoin: round; }
.radar .road.main { stroke-width: 2.2; stroke: #4f7cb0; opacity: 0.75; }
.radar .road.minor { stroke-width: 0.9; opacity: 0.45; }
.radar .course { fill: rgba(47, 211, 168, 0.06); stroke: #2b7f6c; stroke-width: 1; stroke-dasharray: 2 3; }
.radar .water { fill: #12365c; stroke: #2a5d8f; stroke-width: 0.8; opacity: 0.7; }
.radar .zone-name .approx { fill: var(--ipe); }
.radar .leader { fill: none; stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.8; }
.radar .has-roads .contour { opacity: 0.28; }
.radar .has-roads .contour.index { opacity: 0.45; }
.radar .scalebar path { fill: none; stroke: var(--haze); stroke-width: 1.5; }
.radar .scalebar text, .radar .north text { font: 11px var(--body); fill: var(--haze); }
.radar .north path { fill: var(--ipe); }

/* condo strip under the radar */
.condos { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px; background: var(--rule-soft); border: 1px solid var(--rule-soft); margin-bottom: 16px; }
.condo { background: var(--deep); padding: 14px 16px; cursor: pointer; border-top: 3px solid var(--c); text-align: left; border-left: 0; border-right: 0; border-bottom: 0; }
.condo:hover { background: #12294a; }
.condo h3 { margin-bottom: 8px; }
.condo dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 0.84rem; }
.condo dt { color: var(--haze); }
.condo dd { margin: 0; text-align: right; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--rule-soft); cursor: pointer; }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; transform: translateY(-1px); }
.feed .when { color: var(--haze); font-size: 0.8rem; white-space: nowrap; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer;
  background: transparent; border: 1px solid var(--rule); color: var(--mist);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 0 100%);
}
.btn:hover { border-color: var(--haze); }
.btn.primary { background: var(--ipe); color: #1a1405; border-color: var(--ipe); font-weight: 600; }
.btn.primary:hover { background: #ffd673; }
.btn.small { padding: 4px 10px; font-size: 0.82rem; }
.btn[disabled] { opacity: 0.5; cursor: progress; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border: 1px solid var(--rule); background: transparent; cursor: pointer; font-size: 0.85rem;
  border-radius: 999px; color: var(--haze);
}
.chip[aria-pressed='true'] { color: var(--night); background: var(--mist); border-color: var(--mist); }
.chip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--haze); }
label.field.inline { flex-direction: row; align-items: center; gap: 8px; }
input[type='text'], input[type='number'], input[type='url'], input[type='search'], select, textarea {
  background: var(--deeper); border: 1px solid var(--rule); padding: 8px 10px; color: var(--mist); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--ipe); outline: none; }
textarea { min-height: 90px; resize: vertical; }
input[type='range'] { accent-color: var(--ipe); width: 100%; }
input[type='checkbox'] { accent-color: var(--ipe); width: 16px; height: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: end; margin-bottom: 16px; }
.filters .grow { flex: 1 1 200px; }

/* ---------- listings ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.tile { background: var(--deep); border: 1px solid var(--rule-soft); cursor: pointer; display: flex; flex-direction: column; position: relative; text-align: left; padding: 0; }
.tile:hover { border-color: var(--rule); }
.tile.gone { opacity: 0.55; }
.tile .img { aspect-ratio: 16 / 9; background: var(--deeper) center / cover no-repeat; position: relative; border-bottom: 2px solid var(--c); }
.tile .img svg { width: 100%; height: 100%; display: block; }
.tile .tags { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; }
.tag { font-size: 0.72rem; padding: 2px 8px; background: rgba(8, 20, 35, 0.85); border: 1px solid var(--rule); color: var(--mist); white-space: nowrap; }
.tag.condo { border-color: var(--c); }
.tile .star { position: absolute; right: 8px; top: 8px; width: 34px; height: 34px; background: rgba(8, 20, 35, 0.8); border: 1px solid var(--rule); cursor: pointer; display: grid; place-items: center; }
.star svg { width: 18px; height: 18px; stroke: var(--mist); fill: none; stroke-width: 1.6; }
.star[aria-pressed='true'] svg { fill: var(--ipe); stroke: var(--ipe); }
.tile .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.price { font-family: var(--display); font-weight: 500; font-size: 1.25rem; color: var(--mist); }
.usd { color: var(--haze); font-size: 0.85rem; }
.facts { font-size: 0.86rem; color: var(--mist); }
.deal { font-size: 0.8rem; display: inline-flex; align-items: center; gap: 6px; }
.deal::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--dc, var(--neutral)); }
.tile .foot { display: flex; justify-content: space-between; align-items: end; gap: 8px; margin-top: auto; font-size: 0.78rem; color: var(--haze); }
.empty { padding: 40px 20px; text-align: center; color: var(--haze); border: 1px dashed var(--rule); }
.empty h2 { color: var(--mist); margin-bottom: 8px; }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(4, 10, 18, 0.6); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 41; overflow-y: auto;
  background: var(--deeper); border-left: 1px solid var(--rule); padding: 20px 22px 60px;
  animation: slidein 0.22s ease-out;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer .close { position: sticky; top: 0; float: right; }
.drawer .hero-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-bottom: 2px solid var(--c); margin: 10px 0 14px; background: var(--deep); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--rule-soft); border: 1px solid var(--rule-soft); margin: 14px 0; }
.kv div { background: var(--deep); padding: 10px 12px; }
.kv span { display: block; font-size: 0.75rem; color: var(--haze); }
.kv b { font-weight: 500; }
.scorecard { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.pips { display: flex; gap: 4px; }
.pip { width: 26px; height: 26px; border: 1px solid var(--rule); background: transparent; cursor: pointer; font-size: 0.75rem; color: var(--haze); }
.pip[aria-pressed='true'] { background: var(--ipe); color: var(--night); border-color: var(--ipe); }

/* ---------- numbers ---------- */
.calc-layout { display: grid; grid-template-columns: 210px 1fr; gap: 20px; }
.calc-nav { display: flex; flex-direction: column; gap: 2px; }
.calc-nav a { padding: 9px 12px; text-decoration: none; color: var(--haze); border-left: 2px solid var(--rule-soft); }
.calc-nav a[aria-current='page'] { color: var(--ipe); border-left-color: var(--ipe); background: rgba(255, 201, 77, 0.06); }
.calc { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 20px; align-items: start; }
.inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inputs .full { grid-column: 1 / -1; }
.result-big { font-family: var(--display); font-weight: 500; font-size: clamp(1.6rem, 3.4vw, 2.4rem); color: var(--ipe); line-height: 1.15; }
.result-sub { color: var(--haze); margin-top: 4px; }
table.break { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 0.9rem; }
table.break td, table.break th { padding: 7px 0; border-bottom: 1px solid var(--rule-soft); text-align: left; font-weight: 400; }
table.break td:last-child, table.break th:last-child { text-align: right; }
table.break tr.total td { border-top: 1px solid var(--haze); border-bottom: 0; font-weight: 600; }
.bar { display: flex; height: 12px; margin-top: 14px; gap: 2px; }
.bar span { background: var(--c); display: block; min-width: 2px; }
.note { font-size: 0.8rem; color: var(--haze); margin-top: 12px; border-left: 2px solid var(--rule); padding-left: 10px; }
.vs { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--rule-soft); border: 1px solid var(--rule-soft); margin-top: 14px; }
.vs > div { background: var(--deep); padding: 14px; }
.vs .win { box-shadow: inset 0 2px 0 var(--laser); }

/* ---------- shortlist ---------- */
.compare { overflow-x: auto; }
.compare table { border-collapse: collapse; min-width: 100%; font-size: 0.88rem; }
.compare th, .compare td { padding: 8px 12px; border-bottom: 1px solid var(--rule-soft); text-align: left; vertical-align: top; min-width: 170px; }
.compare th:first-child, .compare td:first-child { position: sticky; left: 0; background: var(--night); min-width: 120px; color: var(--haze); font-weight: 400; z-index: 1; }
.compare img { width: 100%; aspect-ratio: 16/10; object-fit: cover; display: block; margin-bottom: 6px; }
.meter { height: 6px; background: var(--rule-soft); position: relative; margin-top: 6px; }
.meter span { position: absolute; inset: 0 auto 0 0; background: var(--ipe); }

/* ---------- charts ---------- */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--rule-soft); }
.chart .axis text { fill: var(--haze); font: 11px var(--body); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .endlabel { font: 11px var(--body); fill: var(--mist); }
.chart .hit { fill: transparent; }
.chart .cross { stroke: var(--haze); stroke-dasharray: 3 3; }
.chart-tip { position: fixed; pointer-events: none; z-index: 60; background: var(--deeper); border: 1px solid var(--rule); padding: 8px 10px; font-size: 0.8rem; min-width: 120px; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--haze); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 3px; margin-right: 6px; vertical-align: middle; background: var(--c); }
.tiles-macro { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--rule-soft); border: 1px solid var(--rule-soft); }
.tiles-macro > div { background: var(--deep); padding: 14px; }
.tiles-macro b { display: block; font-family: var(--display); font-weight: 500; font-size: 1.3rem; margin: 2px 0 6px; }

/* ---------- setup ---------- */
.src { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--rule-soft); }
.src .st { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--neutral); }
.src .st.ok { background: var(--laser); }
.src .st.error, .src .st.empty { background: var(--terra); }
.src .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: end; }
.src a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.src > div { min-width: 0; }
code, pre { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.82rem; background: var(--deeper); border: 1px solid var(--rule-soft); }
code { padding: 1px 5px; }
pre { padding: 12px; overflow-x: auto; white-space: pre; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 80; background: var(--mist); color: var(--night); padding: 10px 18px; font-weight: 500; animation: slidein 0.2s; max-width: 90vw; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30; flex-direction: row; padding: 0 4px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--rule); background: var(--deeper); }
  .rail .mark { display: none; }
  .rail .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { width: auto; flex: 1; padding: 8px 0 7px; border-left: 0; border-top: 2px solid transparent; font-size: 0.66rem; }
  .nav a[aria-current='page'] { border-top-color: var(--ipe); background: none; }
  main { padding-bottom: 96px; }
  .calc-layout, .calc { grid-template-columns: 1fr; }
  .calc-nav { flex-direction: row; overflow-x: auto; gap: 6px; }
  .calc-nav a { white-space: nowrap; border-left: 0; border-bottom: 2px solid var(--rule-soft); }
  .calc-nav a[aria-current='page'] { border-bottom-color: var(--ipe); }
  .radar .zone-name { font-size: 23px; }
  .radar .zone-stat { font-size: 16px; }
  .radar .readout { font-size: 17px; }
  .radar .elev { font-size: 13px; }
  .condos { grid-template-columns: 1fr 1fr; }
  .src { grid-template-columns: 14px 1fr; }
  .src .acts { grid-column: 2; justify-content: start; }
  .condo { padding: 12px; }
  .condo dl { font-size: 0.78rem; }
  .radar-caption { position: static; padding: 8px 12px 10px; }
  .radar .scalebar text, .radar .north text { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .radar .sweep { display: none; }
}
