/* ─────────────────────────────────────────────────────────────────────────
   VALUA — Uzbekistan Real-Estate AVM · SPA theme  (P7 · Variant C)
   Aistera dark-blue + dark-green design system (methodology §13).
   Emerald is reserved for the single most important figure; azure carries
   links/actions; gold is used at most once per view. No decorative emoji,
   no national-flag glyphs (enforced by ci/check-no-flags.mjs).
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* ── §13 palette tokens (verbatim) ─────────────────────────────────────── */
  --bg-0:        #0A1626;   /* Midnight Navy  — primary background */
  --bg-1:        #0E2038;   /* Deep Navy      — panels / surfaces */
  --bg-2:        #0B2E22;   /* Forest Ink     — alternate surface (green) */
  --green-1:     #12463A;   /* Pine           — secondary surface / borders */
  --accent-green:#2FBF8F;   /* Emerald        — key figures, primary series */
  --accent-green-2:#5FE0B0; /* Mint           — highlights, hover, 2nd series */
  --accent-blue: #3B82F6;   /* Azure          — links, primary actions */
  --accent-blue-2:#5FB0E6;  /* Sky            — tertiary series, info */
  --text:        #E8EEF4;
  --muted:       #9FB3C8;
  --line:        #22364D;
  --gold:        #C9A24B;   /* sparing — one key number/rule per view */
  --warn:        #E0A458;
  --crit:        #D9695F;

  /* derived surfaces */
  --bg-elev:     #122745;
  --line-soft:   #2C4366;
  --green-soft:  rgba(47, 191, 143, 0.14);
  --green-glow:  rgba(47, 191, 143, 0.40);
  --blue-soft:   rgba(59, 130, 246, 0.14);

  /* spatial sequential ramp (low → high), all within the §13 family:
     azure → sky → emerald → mint → gold → warn (hottest). No neon/pure RGB. */
  --ramp-0:      #2B5AA6;
  --ramp-1:      #3B82F6;
  --ramp-2:      #5FB0E6;
  --ramp-3:      #2FBF8F;
  --ramp-4:      #5FE0B0;
  --ramp-5:      #C9A24B;
  --ramp-6:      #E0A458;

  --radius:      12px;
  --radius-sm:   8px;
  --pad:         20px;
  --shadow:      0 6px 28px rgba(0, 0, 0, 0.50);
  --shadow-lg:   0 12px 48px rgba(0, 0, 0, 0.58);
  --header-h:    58px;

  --font-head:   "EB Garamond", Georgia, "Times New Roman", serif;
  --font-body:   "Inter", "Helvetica Neue", Arial, system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14.5px; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, #103a30 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-0), #08111d);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
h1, h2, h3, h4, .brand-name, .kpi-value, .panel-title {
  font-family: var(--font-head);
  font-weight: 600;
  letter-spacing: 0.01em;
}
a { color: var(--accent-blue); text-decoration: none; }
a:hover { color: var(--accent-blue-2); text-decoration: underline; }

@media (prefers-reduced-motion: no-preference) {
  .count-up, .kpi-value, .tab, .btn { transition: all 280ms cubic-bezier(.2,.7,.2,1); }
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1.1rem;
  background: linear-gradient(180deg, rgba(14,32,56,0.96), rgba(10,22,38,0.96));
  border-bottom: 1px solid var(--line);
  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-family: var(--font-head); font-weight: 700; font-size: 1.15rem;
  color: var(--bg-0);
  background: linear-gradient(135deg, var(--accent-green-2), var(--accent-green));
  box-shadow: 0 0 14px var(--green-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 1.12rem; color: var(--text); }
.brand-sub { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.04em; }

.tabs { display: flex; gap: 0.25rem; margin-left: 0.5rem; }
.tab {
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--muted); font-family: var(--font-body); font-size: 0.86rem;
  padding: 0.42rem 0.85rem; border-radius: var(--radius-sm); cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--blue-soft); }
.tab.active {
  color: var(--text); background: var(--bg-1);
  border-color: var(--line); box-shadow: inset 0 -2px 0 var(--accent-green);
}

.header-right { margin-left: auto; display: flex; align-items: center; gap: 0.8rem; }

.ccy-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.ccy-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font-size: 0.78rem; padding: 0.34rem 0.6rem; cursor: pointer;
}
.ccy-btn.active { background: var(--green-soft); color: var(--accent-green-2); }

.apikey-box { display: flex; align-items: center; gap: 0.35rem; }
.apikey-label { font-size: 0.72rem; color: var(--muted); }
#api-key {
  width: 150px; background: var(--bg-0); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-sm); padding: 0.34rem 0.5rem;
  font-size: 0.78rem; font-family: var(--font-body);
}
#api-key:focus { outline: none; border-color: var(--accent-blue); }

.conn-status { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.74rem; color: var(--muted); }
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn-ok .dot { background: var(--accent-green); box-shadow: 0 0 8px var(--green-glow); }
.conn-down .dot { background: var(--crit); }
.conn-unknown .dot { background: var(--warn); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  appearance: none; cursor: pointer; font-family: var(--font-body);
  border-radius: var(--radius-sm); padding: 0.5rem 0.95rem; font-size: 0.86rem;
  border: 1px solid var(--line); background: var(--bg-1); color: var(--text);
}
.btn:hover { border-color: var(--accent-blue); }
.btn-primary {
  border-color: transparent; color: var(--bg-0); font-weight: 600;
  background: linear-gradient(135deg, var(--accent-green-2), var(--accent-green));
  box-shadow: 0 0 14px var(--green-glow);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Disclaimer banner (Integrity Rule #3 — always visible) ─────────────── */
.basis-banner {
  background: linear-gradient(180deg, var(--bg-2), rgba(11,46,34,0.6));
  border-bottom: 1px solid var(--green-1);
  color: var(--text); font-size: 0.8rem;
  padding: 0.5rem 1.1rem;
}
.basis-banner strong { color: var(--accent-green-2); }

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

/* full-width dashboard layout (Trust view hides the map) */
.layout.full .panel { display: none; }
.layout.full .map-wrap { display: none; }
.layout.full .result { max-height: none; }

.panel-title { font-size: 1.0rem; color: var(--text); margin-bottom: 0.2rem; }
.panel-sub { font-size: 0.76rem; color: var(--muted); margin-bottom: 0.9rem; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem 0.8rem; }
.field { display: flex; flex-direction: column; gap: 0.22rem; }
.field.col-span { grid-column: 1 / -1; }
.field label { font-size: 0.74rem; color: var(--muted); }
.field input, .field select {
  background: var(--bg-0); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 0.42rem 0.55rem; font-size: 0.84rem;
  font-family: var(--font-body);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent-blue); }
.field .hint { font-size: 0.66rem; color: var(--muted); opacity: 0.8; }
.field-group-label {
  grid-column: 1 / -1; font-size: 0.7rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent-green-2); margin-top: 0.5rem;
  border-bottom: 1px solid var(--line); padding-bottom: 0.25rem;
}
.form-actions { display: flex; gap: 0.6rem; margin-top: 1rem; }

/* ── KPI / result card ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--pad); box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.kpi-row { display: flex; flex-wrap: wrap; gap: 1.4rem; align-items: flex-end; }
.kpi { display: flex; flex-direction: column; gap: 0.15rem; }
.kpi-label { font-size: 0.72rem; color: var(--muted); }
.kpi-value { font-size: 1.7rem; color: var(--accent-green); line-height: 1; }
.kpi-value.secondary { font-size: 1.15rem; color: var(--text); }
.kpi-value .unit { font-size: 0.8rem; color: var(--muted); margin-left: 0.2rem; }
.kpi-sub { font-size: 0.72rem; color: var(--muted); }

.chart-block { margin-top: 1rem; }
.chart-title { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.4rem; }
.chart-block svg { width: 100%; height: auto; }

/* ── Proximity chips (icon = inline SVG, NOT emoji) ──────────────────────── */
.prox-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.prox-chip {
  display: inline-flex; align-items: center; gap: 0.32rem;
  border: 1px solid var(--line); border-left: 3px solid var(--c, var(--accent-blue));
  background: var(--bg-0); border-radius: 999px; padding: 0.2rem 0.6rem; font-size: 0.74rem;
}
.prox-chip .pc-ic { width: 13px; height: 13px; color: var(--c, var(--accent-blue)); display: inline-flex; }
.prox-chip .pc-ic svg { width: 13px; height: 13px; }
.prox-chip .pc-lb { color: var(--muted); }
.prox-chip .pc-km { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem;
  padding: 0.16rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); }
.badge-ok { color: var(--accent-green); border-color: var(--green-1); background: var(--green-soft); }
.badge-warn { color: var(--warn); border-color: rgba(224,164,88,0.4); }
.badge-crit { color: var(--crit); border-color: rgba(217,105,95,0.4); }
.badge-info { color: var(--accent-blue-2); border-color: rgba(59,130,246,0.4); background: var(--blue-soft); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.tbl th, .tbl td { text-align: left; padding: 0.42rem 0.6rem; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tbl td { color: var(--text); font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: var(--blue-soft); }
.tbl .num { text-align: right; }

/* ── Dashboard grid (Trust view) ────────────────────────────────────────── */
.dash { padding: var(--pad); display: grid; gap: 1rem; max-width: 1180px; margin: 0 auto; }
.dash-head { display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap; }
.dash-head h2 { font-size: 1.35rem; }
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.dash-grid.two { grid-template-columns: repeat(2, 1fr); }
.regime-card { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.regime-card.hard { border-color: rgba(224,164,88,0.35); }
.regime-name { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.regime-mape { font-family: var(--font-head); font-size: 2.0rem; color: var(--accent-green); line-height: 1.1; }
.regime-card.hard .regime-mape { color: var(--warn); }
.regime-ci { font-size: 0.72rem; color: var(--muted); }
.metric-line { display: flex; justify-content: space-between; font-size: 0.78rem; padding: 0.2rem 0; border-bottom: 1px dashed var(--line); }
.metric-line .mv { color: var(--text); font-variant-numeric: tabular-nums; }
.note { font-size: 0.74rem; color: var(--muted); }
.note.measured { color: var(--accent-green-2); }

/* ── KPI grid + cards (Explorer summary, Trust headline) ────────────────── */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.7rem; margin: 0.8rem 0;
}
.kpi-card {
  background: var(--bg-0); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.6rem 0.7rem;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.kpi-card .kpi-value { font-size: 1.18rem; }

/* ── Layer toolbar + chip buttons (Explorer) ────────────────────────────── */
.layer-toolbar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.8rem; }
.btn.chip { padding: 0.32rem 0.7rem; font-size: 0.78rem; border-radius: 999px; }
.btn.chip.active {
  border-color: transparent; color: var(--bg-0); font-weight: 600;
  background: linear-gradient(135deg, var(--accent-green-2), var(--accent-green));
}

/* ── Getis-Ord hot-spot list (Explorer) ─────────────────────────────────── */
.hot-wrap { margin-top: 0.8rem; }
.panel-title.sm { font-size: 0.85rem; margin-top: 0.6rem; }
.hot-list { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.5rem; }
.hot-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem; align-items: center;
  padding: 0.28rem 0; border-bottom: 1px dashed var(--line);
}
.hot-name { color: var(--text); font-size: 0.82rem; }
.hot-val { font-size: 0.76rem; font-variant-numeric: tabular-nums; }

/* ── Trust dashboard sections + key/value grid ──────────────────────────── */
.dash-section { background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; }
.dash-section > h3 { font-size: 0.96rem; margin-bottom: 0.2rem; }
.dash-section .sec-sub { font-size: 0.74rem; color: var(--muted); margin-bottom: 0.8rem; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.5rem 1rem; }
.kv { display: flex; justify-content: space-between; gap: 0.6rem;
  padding: 0.3rem 0; border-bottom: 1px dashed var(--line); font-size: 0.8rem; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.kv .v.ok { color: var(--accent-green); }
.kv .v.warn { color: var(--warn); }
.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; color: var(--muted); word-break: break-all; }
/* scaffold-honesty variant of the basis banner (synthetic cold-start) */
.basis-banner.scaffold { background: linear-gradient(180deg, rgba(43,34,11,0.7), rgba(46,34,11,0.45));
  border-color: rgba(224,164,88,0.4); }
.basis-banner.scaffold strong { color: var(--warn); }

/* ── Map controls / legend (text only, no flags) ────────────────────────── */
.map-legend {
  position: absolute; right: 12px; bottom: 22px; z-index: 600;
  background: rgba(10,22,38,0.92); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.6rem 0.7rem; font-size: 0.72rem;
  color: var(--text); max-width: 220px; box-shadow: var(--shadow);
}
.map-legend .lg-title { color: var(--muted); margin-bottom: 0.35rem; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; }
.map-legend .lg-row { display: flex; align-items: center; gap: 0.4rem; margin: 0.12rem 0; }
.map-legend .lg-swatch { width: 14px; height: 10px; border-radius: 2px; }
.lf-mouse-pos { background: rgba(10,22,38,0.82); color: var(--muted); padding: 2px 7px;
  font-size: 0.68rem; border-radius: 4px; font-variant-numeric: tabular-nums; }
.lf-fs-btn { background: var(--bg-1); color: var(--text); border: 1px solid var(--line);
  width: 30px; height: 30px; font-size: 1rem; cursor: pointer; }
.leaflet-popup-content-wrapper { background: var(--bg-1); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-tip { background: var(--bg-1); }

/* ── Messages ───────────────────────────────────────────────────────────── */
.error-msg { color: var(--crit); background: rgba(217,105,95,0.08);
  border: 1px solid rgba(217,105,95,0.3); border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; font-size: 0.82rem; }
.empty-msg { color: var(--muted); font-size: 0.84rem; padding: 1rem 0; text-align: center; }
.loading { color: var(--muted); font-size: 0.82rem; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
.app-footer {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.55rem 1.1rem; border-top: 1px solid var(--line);
  font-size: 0.72rem; color: var(--muted); background: rgba(10,22,38,0.6);
}
.app-footer .sep { opacity: 0.5; }
.foot-link { color: var(--accent-blue); }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .dash-grid, .dash-grid.two { grid-template-columns: 1fr; }
}
