/* ─────────────────────────────────────────────────────────────────────────
   VALUA — Vietnam Real-Estate AVM · SPA theme
   ArcGIS-Pro-style dark cartography · deep navy + gold (matches VALUA reports)
   ───────────────────────────────────────────────────────────────────────── */
:root {
  --bg:            #080b14;
  --bg-2:          #0a0e1a;
  --bg-3:          #0d1426;
  --panel:         #111a2e;
  --panel-2:       #15203a;
  --card:          #131d33;
  --border:        #1e2c49;
  --border-soft:   #26365a;

  --text:          #eaf0fb;
  --text-muted:    #9fb0cf;
  --text-dim:      #64769a;

  --gold:          #d8b46a;
  --gold-2:        #f2d79a;
  --gold-deep:     #a8842f;
  --gold-soft:     rgba(216, 180, 106, 0.14);
  --gold-glow:     rgba(216, 180, 106, 0.40);

  --accent:        #6b8cff;   /* periwinkle */
  --accent-2:      #22d3ee;   /* cyan */
  --ok:            #34d399;
  --warn:          #fbbf24;
  --err:           #ff6b6b;

  /* spatial ramps */
  --hot:           #ff5d5d;
  --warm:          #ffa24c;
  --neutral:       #8aa0c8;
  --cool:          #4cc3ff;
  --cold:          #3a7bd5;

  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 6px 28px rgba(0, 0, 0, 0.55);
  --shadow-lg:     0 12px 48px rgba(0, 0, 0, 0.62);
  --header-h:      58px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14.5px; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 0% -5%, rgba(107,140,255,0.10) 0%, transparent 55%),
    radial-gradient(900px 620px at 100% 105%, rgba(216,180,106,0.10) 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1.1rem;
  background: linear-gradient(180deg, rgba(21,32,58,0.96), rgba(13,20,38,0.96));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.header-left { display: flex; align-items: center; gap: 0.65rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.1rem; color: #1a1303;
  background: linear-gradient(135deg, var(--gold-2), var(--gold-deep));
  box-shadow: 0 0 18px var(--gold-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-weight: 800; letter-spacing: 0.06em; font-size: 1.05rem;
  background: linear-gradient(90deg, var(--gold-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 0.64rem; color: var(--text-dim); letter-spacing: 0.14em; text-transform: uppercase; }

.tabs { display: flex; gap: 0.25rem; margin: 0 auto; }
.tab {
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--text-muted); font: inherit; font-weight: 600; font-size: 0.86rem;
  padding: 0.46rem 0.95rem; border-radius: 9px; cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: rgba(107,140,255,0.08); }
.tab.active {
  color: var(--gold-2);
  background: var(--gold-soft);
  border-color: rgba(216,180,106,0.35);
  box-shadow: inset 0 0 0 1px rgba(216,180,106,0.12);
}

.header-right { display: flex; align-items: center; gap: 0.8rem; }
.apikey-box { display: flex; align-items: center; gap: 0.35rem; }

/* currency toggle (VND ⇄ USD) */
.ccy-toggle { display: inline-flex; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 9px; padding: 2px; gap: 2px; }
.ccy-btn { appearance: none; cursor: pointer; font: inherit; font-size: 0.74rem; font-weight: 600;
  border: none; background: transparent; color: var(--text-muted); border-radius: 7px;
  padding: 0.3rem 0.55rem; transition: all 0.15s ease; }
.ccy-btn:hover { color: var(--text); }
.ccy-btn.active { background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #1a1303; box-shadow: 0 0 12px var(--gold-glow); }

.apikey-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
#api-key {
  width: 168px; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.4rem 0.55rem; font: inherit; font-size: 0.8rem;
}
#api-key:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(107,140,255,0.18); }

.conn-status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.74rem; color: var(--text-muted); }
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); box-shadow: 0 0 8px currentColor; }
.conn-ok    .dot { background: var(--ok);  color: var(--ok); }
.conn-ok    .txt { color: var(--ok); }
.conn-down  .dot { background: var(--err); color: var(--err); }
.conn-down  .txt { color: var(--err); }
.conn-unknown .dot { background: var(--warn); color: var(--warn); }

/* ── Buttons / controls ─────────────────────────────────────────────────── */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.82rem;
  border-radius: 9px; padding: 0.5rem 0.9rem; border: 1px solid var(--border-soft);
  background: var(--panel-2); color: var(--text); transition: all 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #1a1303; border-color: transparent; box-shadow: 0 0 16px var(--gold-glow);
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

/* ── Disclaimer banner ──────────────────────────────────────────────────── */
.basis-banner {
  font-size: 0.78rem; color: var(--gold-2);
  background: linear-gradient(90deg, rgba(216,180,106,0.12), transparent);
  border-bottom: 1px solid rgba(216,180,106,0.22);
  padding: 0.4rem 1.1rem;
}
.basis-banner strong { color: var(--gold); }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  flex: 1; display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0; min-height: 0;
}
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem 1rem 2rem;
  overflow-y: auto;
}
.workspace { display: flex; flex-direction: column; min-width: 0; }
.map-wrap { position: relative; flex: 1; min-height: 340px; }
.map { position: absolute; inset: 0; background: var(--bg-2); }
.result { background: var(--bg-2); border-top: 1px solid var(--border); max-height: 46vh; overflow-y: auto; }
.result:empty { display: none; }

/* ── Panel widgets ──────────────────────────────────────────────────────── */
.panel h2 { font-size: 0.96rem; font-weight: 700; margin-bottom: 0.15rem; letter-spacing: 0.01em; }
.panel .hint { font-size: 0.74rem; color: var(--text-dim); margin-bottom: 0.85rem; }
.section-title {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-dim); margin: 1.1rem 0 0.5rem;
  border-bottom: 1px solid var(--border); padding-bottom: 0.35rem;
}
.field { margin-bottom: 0.7rem; }
.field label { display: block; font-size: 0.74rem; color: var(--text-muted); margin-bottom: 0.22rem; }
.field input, .field select {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.46rem 0.55rem; font: inherit; font-size: 0.82rem;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(107,140,255,0.16);
}
.field input.auto-filled { border-color: rgba(111,207,151,0.5); background: rgba(111,207,151,0.06); }
.field .req { color: var(--gold); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }
.seg {
  display: flex; gap: 0.25rem; background: var(--bg-3); padding: 0.25rem;
  border: 1px solid var(--border); border-radius: 9px; flex-wrap: wrap;
}
.seg button {
  flex: 1; min-width: 56px; appearance: none; border: none; background: transparent;
  color: var(--text-muted); font: inherit; font-size: 0.78rem; font-weight: 600;
  padding: 0.38rem 0.4rem; border-radius: 6px; cursor: pointer; transition: all 0.12s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--gold-soft); color: var(--gold-2); box-shadow: inset 0 0 0 1px rgba(216,180,106,0.3); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.seg button.locked { opacity: 0.32; cursor: not-allowed; }
.seg button.locked::after { content: " 🔒"; font-size: 0.7em; }

/* ── Address search (item 4 · forward geocode) ──────────────────────────── */
.addr-wrap { margin: 0.6rem 0 0.2rem; position: relative; }
.addr-row { display: flex; gap: 0.4rem; }
.addr-search {
  flex: 1; background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.45rem 0.6rem; font: inherit; font-size: 0.82rem;
}
.addr-search:focus { outline: none; border-color: rgba(216,180,106,0.5); }
.addr-results {
  margin-top: 0.3rem; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; max-height: 230px; overflow-y: auto;
}
.addr-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0.6rem; cursor: pointer; border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.addr-item:last-child { border-bottom: none; }
.addr-item:hover { background: var(--gold-soft); }
.addr-name { color: var(--text); }
.addr-meta { font-size: 0.7rem; white-space: nowrap; }
.addr-empty { padding: 0.5rem 0.6rem; font-size: 0.78rem; color: var(--text-dim); }

.check { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; font-size: 0.8rem; color: var(--text-muted); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--gold); }

.note { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.5rem; }
.error-msg { color: var(--err); font-size: 0.8rem; margin-top: 0.6rem; }

/* ── Result card ────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; margin: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.price-big {
  font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--gold-2), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.price-sub { font-size: 0.82rem; color: var(--text-muted); }
.tag { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.2rem 0.5rem; border-radius: 999px; border: 1px solid var(--border-soft); color: var(--text-muted); }
.tag.gold { color: var(--gold-2); border-color: rgba(216,180,106,0.4); background: var(--gold-soft); }
.head-tags { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }.tag.conf { cursor: help; }
.tag.conf-high { color: #6fcf97; border-color: rgba(111,207,151,0.45); background: rgba(111,207,151,0.08); }
.tag.conf-medium { color: #e0b65a; border-color: rgba(224,182,90,0.45); background: rgba(224,182,90,0.08); }
.tag.conf-low { color: #eb8f8f; border-color: rgba(235,143,143,0.45); background: rgba(235,143,143,0.08); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; margin: 0.9rem 0; }
.kpi { background: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.55rem 0.7rem; }
.kpi .k { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.kpi .v { font-size: 1.05rem; font-weight: 700; color: var(--gold-2); }
.kpi .u { font-size: 0.7rem; color: var(--text-muted); }

/* conformal band */
.band-wrap { margin: 0.9rem 0 0.4rem; }
.band-label { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.band-track { position: relative; }
.band-track svg { width: 100%; height: auto; display: block; max-height: 84px; }
.band-disclaimer { font-size: 0.72rem; color: var(--gold); margin-top: 0.7rem; padding: 0.5rem 0.65rem; background: var(--gold-soft); border-left: 3px solid var(--gold); border-radius: 0 6px 6px 0; clear: both; }

/* insights stack (estimate-vs-median + accessibility), full-width, no overlap */
.insights { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.7rem; }
.chart-box { min-width: 0; }
.chart-box h4 { font-size: 0.74rem; color: var(--text-muted); font-weight: 600; margin-bottom: 0.4rem; }
.chart-box svg { width: 100%; height: auto; display: block; max-height: 96px; }

/* compact accessibility chips */
.prox-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.prox-chip {
  display: inline-flex; align-items: center; gap: 0.34rem;
  padding: 0.26rem 0.5rem 0.26rem 0.4rem;
  background: var(--bg-3); border: 1px solid var(--border);
  border-left: 3px solid var(--c, var(--gold)); border-radius: 999px;
  font-size: 0.74rem; line-height: 1; white-space: nowrap;
}
.prox-chip .pc-ic { font-size: 0.92rem; filter: saturate(0.9); }
.prox-chip .pc-lb { color: var(--text-muted); }
.prox-chip .pc-km { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

/* legacy 2-col chart row (still used by batch summaries) */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-top: 0.6rem; }
@media (max-width: 900px) { .chart-row { grid-template-columns: 1fr; } }

/* ── Tables (batch) ─────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.tbl th, .tbl td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--text-dim); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; position: sticky; top: 0; background: var(--bg-3); }
.tbl tbody tr:hover { background: rgba(107,140,255,0.06); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.tbl-wrap { max-height: 440px; overflow: auto; margin-top: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tbl-wrap .tbl th { box-shadow: inset 0 -1px 0 var(--border); z-index: 1; }
.row-err td { color: var(--err); }

.progress { height: 9px; background: var(--bg-3); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); transition: width 0.3s ease; }

.statusline { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.badge { font-size: 0.68rem; padding: 0.16rem 0.5rem; border-radius: 999px; font-weight: 600; }
.badge.queued  { background: rgba(251,191,36,0.16); color: var(--warn); }
.badge.running { background: rgba(107,140,255,0.16); color: var(--accent); }
.badge.done    { background: rgba(52,211,153,0.16); color: var(--ok); }
.badge.error   { background: rgba(255,107,107,0.16); color: var(--err); }

/* ── Map controls + legend ──────────────────────────────────────────────── */
.map-legend {
  position: absolute; right: 12px; bottom: 18px; z-index: 600;
  background: rgba(13,20,38,0.92); border: 1px solid var(--border-soft);
  border-radius: 10px; padding: 0.6rem 0.75rem; font-size: 0.72rem; color: var(--text-muted);
  box-shadow: var(--shadow); max-width: 220px;
}
.map-legend h5 { font-size: 0.68rem; color: var(--gold-2); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.4rem; }
.legend-row { display: flex; align-items: center; gap: 0.45rem; margin: 0.18rem 0; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.legend-bar { height: 10px; border-radius: 4px; margin: 0.3rem 0; }

.lf-mouse-pos { background: rgba(13,20,38,0.85); color: var(--text-muted); padding: 2px 8px; font-size: 11px; font-variant-numeric: tabular-nums; border-radius: 6px 0 0 0; }
.leaflet-control-attribution { background: rgba(13,20,38,0.78) !important; color: var(--text-dim) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-bar a, .leaflet-control-layers-toggle { background-color: var(--panel) !important; }
.lf-fs-btn { width: 30px; height: 30px; line-height: 28px; text-align: center; font-weight: 700; color: var(--text); background: var(--panel); cursor: pointer; }

.layer-toolbar {
  display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.6rem;
}
.layer-toolbar button {
  flex: 1 1 auto; font-size: 0.75rem; padding: 0.4rem 0.5rem;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-muted); cursor: pointer; font-weight: 600;
}
.layer-toolbar button.active { color: var(--gold-2); border-color: rgba(216,180,106,0.45); background: var(--gold-soft); }

/* ── misc ───────────────────────────────────────────────────────────────── */
.app-footer {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.5rem 1.1rem; font-size: 0.72rem; color: var(--text-dim);
  border-top: 1px solid var(--border); background: var(--bg-2);
}
.app-footer .sep { opacity: 0.5; }
.foot-link { color: var(--text-muted); }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border-soft);
  border-top-color: var(--gold); border-radius: 50%; display: inline-block;
  animation: spin 0.7s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); max-height: none; }
  .tabs { order: 3; width: 100%; margin: 0; justify-content: center; }
  .app-header { flex-wrap: wrap; height: auto; padding: 0.5rem 1rem; }
}
