/* ===========================================================================
   TerraLens — "Orbital Observatory" visual layer
   Loaded after app.css. Re-skins tokens and components; adds motion.
   World: a mission-control console under a live night sky. Hairline instruments,
   aurora accent, precise mono telemetry. Light theme = daylight lab console.
   =========================================================================== */

:root {
  color-scheme: dark;
  --bg-canvas: #04070e;
  --bg-sidebar: rgb(7 12 22 / 0.78);
  --bg-surface: rgb(13 21 35 / 0.74);
  --bg-elevated: #111c2f;
  --bg-hover: rgb(120 170 255 / 0.1);
  --border-subtle: rgb(140 175 235 / 0.13);
  --border-strong: rgb(140 175 235 / 0.28);
  --border-control: rgb(150 185 240 / 0.42);
  --text-primary: #eef4ff;
  --text-secondary: #bccae0;
  --text-tertiary: #93a6c2;
  --accent: #4be3f0;
  --accent-text: #8cf1f8;
  --on-accent: #031a22;
  --accent-soft: rgb(75 227 240 / 0.1);
  --accent-border: rgb(75 227 240 / 0.38);
  --accent-2: #9a86ff;
  --accent-3: #ffb86b;
  --status-green: #5cf0ae;
  --status-amber: #ffc176;
  --status-rose: #ff7d9d;
  --status-violet: #b8a4ff;
  --status-green-text: #8af5c4;
  --status-amber-text: #ffd49b;
  --status-rose-text: #ffa5ba;
  --scroll-thumb: rgb(140 175 235 / 0.28);
  --focus-ring: #8cf1f8;
  --surface-shadow: 0 1px 0 rgb(255 255 255 / 0.05) inset, 0 18px 40px -22px rgb(0 4 14 / 0.9);
  --panel-sheen: linear-gradient(180deg, rgb(160 200 255 / 0.05), transparent 38%);
  --chart-text: #a9bad4;
  --chart-grid: rgb(150 185 240 / 0.09);
  --chart-tooltip-bg: rgb(10 17 30 / 0.94);
  --chart-tooltip-text: #eef4ff;
  --series-anomaly: #5fb4ff;
  --series-trend: #5cf0ae;
  --series-ols: #ffc176;
  --series-step: #b8a4ff;
  --series-alert: #ff7d9d;
  --series-muted: #7f94b3;
  --series-oni: #ffc176;
  --star-rgb: 205 225 255;
  --aurora-a: rgb(40 210 235 / 0.16);
  --aurora-b: rgb(120 90 255 / 0.15);
  --aurora-c: rgb(255 150 90 / 0.07);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --radius: 16px;
}

html.light {
  color-scheme: light;
  --bg-canvas: #e9eff8;
  --bg-sidebar: rgb(250 252 255 / 0.82);
  --bg-surface: rgb(255 255 255 / 0.82);
  --bg-elevated: #f1f5fb;
  --bg-hover: rgb(30 90 200 / 0.07);
  --border-subtle: rgb(40 70 130 / 0.12);
  --border-strong: rgb(40 70 130 / 0.26);
  --border-control: rgb(40 70 130 / 0.4);
  --text-primary: #0d1a2e;
  --text-secondary: #33465f;
  --text-tertiary: #556a85;
  --accent: #007f8c;
  --accent-text: #00606b;
  --on-accent: #fff;
  --accent-soft: rgb(0 127 140 / 0.09);
  --accent-border: rgb(0 127 140 / 0.36);
  --accent-2: #5b46d6;
  --accent-3: #b45f12;
  --status-green: #17784f;
  --status-amber: #a35a10;
  --status-rose: #b53a58;
  --status-violet: #6a4fc4;
  --status-green-text: #146543;
  --status-amber-text: #874a09;
  --status-rose-text: #98304c;
  --scroll-thumb: rgb(40 70 130 / 0.3);
  --focus-ring: #00606b;
  --surface-shadow: 0 1px 0 rgb(255 255 255 / 0.9) inset, 0 14px 30px -20px rgb(30 60 120 / 0.35);
  --panel-sheen: linear-gradient(180deg, rgb(255 255 255 / 0.7), transparent 40%);
  --chart-text: #435873;
  --chart-grid: rgb(40 70 130 / 0.1);
  --chart-tooltip-bg: rgb(255 255 255 / 0.96);
  --chart-tooltip-text: #0d1a2e;
  --series-anomaly: #0a66c8;
  --series-trend: #17784f;
  --series-ols: #a35a10;
  --series-step: #6a4fc4;
  --series-alert: #c23a5c;
  --series-muted: #5f7691;
  --series-oni: #a35a10;
  --star-rgb: 60 90 150;
  --aurora-a: rgb(0 150 190 / 0.12);
  --aurora-b: rgb(110 90 230 / 0.09);
  --aurora-c: rgb(255 170 100 / 0.1);
}

::selection { background: var(--accent); color: var(--on-accent); }
* { caret-color: var(--accent); scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-border); }

html, body { background: var(--bg-canvas); }
body { font-feature-settings: 'ss01', 'cv11'; text-rendering: optimizeLegibility; }

/* ----------------------------------------------------------------------------
   Living backdrop: star canvas + drifting aurora
   ---------------------------------------------------------------------------- */
#fxStars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 600ms var(--ease-out);
}
html.light #fxStars { opacity: 0.35; }

.aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(38% 34% at 78% 12%, var(--aurora-a), transparent 70%),
    radial-gradient(34% 38% at 12% 88%, var(--aurora-b), transparent 70%),
    radial-gradient(30% 26% at 92% 82%, var(--aurora-c), transparent 70%);
  animation: aurora-drift 38s var(--ease-io) infinite alternate;
  will-change: transform;
}

@keyframes aurora-drift {
  0% { transform: translate3d(-2%, -1%, 0) scale(1); }
  50% { transform: translate3d(3%, 2%, 0) scale(1.08); }
  100% { transform: translate3d(-1%, 3%, 0) scale(1.03); }
}

.app-shell { position: relative; z-index: 1; }
.main-area { background: transparent; }

/* ----------------------------------------------------------------------------
   Sidebar
   ---------------------------------------------------------------------------- */
.sidebar {
  background: var(--bg-sidebar);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border-right: 1px solid var(--border-subtle);
  box-shadow: 1px 0 0 rgb(255 255 255 / 0.02);
}

.brand-block {
  position: relative;
  border-bottom-color: transparent;
  padding-bottom: 18px;
  flex-wrap: wrap;
}
.brand-block::after {
  content: '';
  position: absolute;
  inset: auto 8px 0;
  height: 1px;
  background: linear-gradient(90deg, var(--accent-border), var(--border-subtle) 40%, transparent);
}

.brand-mark {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--accent-border), 0 8px 22px -8px var(--accent);
}

.brand-title { font-size: 20px; letter-spacing: -0.03em; }
.brand-sub { font-size: 11.5px; letter-spacing: 0.01em; }

.mission-chip {
  flex-basis: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pulse-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-green);
  flex: none;
}
.pulse-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--status-green);
  animation: ping 2.4s var(--ease-out) infinite;
}
@keyframes ping {
  0% { transform: scale(1); opacity: 0.7; }
  80%, 100% { transform: scale(3.2); opacity: 0; }
}

.nav-group-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.nav-list { position: relative; gap: 2px; }
.nav-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 0;
  border-radius: 10px;
  background: linear-gradient(100deg, var(--accent-soft), transparent 90%), var(--bg-hover);
  border: 1px solid var(--accent-border);
  box-shadow: 0 10px 24px -14px var(--accent);
  pointer-events: none;
  opacity: 0;
  transition: transform 480ms var(--ease-out), opacity 300ms ease;
}
.nav-indicator::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.nav-btn {
  position: relative;
  border-radius: 10px;
  transition: color 200ms var(--ease-out), background 200ms ease, transform 300ms var(--ease-out);
}
.nav-btn:hover { background: var(--bg-hover); transform: translateX(2px); }
.nav-btn.active,
.js-fx .nav-btn.active {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--accent-text);
}
html:not(.js-fx) .nav-btn.active { background: var(--accent-soft); border-color: var(--accent-border); }
.nav-btn.active:hover { transform: none; }
.nav-icon { transition: transform 400ms var(--ease-out), opacity 200ms; }
.nav-btn:hover .nav-icon { transform: scale(1.12) rotate(-4deg); opacity: 1; }
.nav-btn.active .nav-icon { opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); }

.nav-tag {
  background: transparent;
  border-color: var(--border-strong);
  letter-spacing: 0.04em;
}

.story-btn { border-radius: 10px; transition: background 200ms ease, border-color 200ms ease, transform 300ms var(--ease-out); }
.story-btn:hover { transform: translateX(2px); }

.sidebar-footer { border-top-color: transparent; position: relative; }
.sidebar-footer::before {
  content: '';
  position: absolute;
  inset: 0 8px auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}
.sidebar-footer-row { font-size: 11px; }
.sidebar-footer-row .tabular { color: var(--accent-text); }

/* ----------------------------------------------------------------------------
   Header bar
   ---------------------------------------------------------------------------- */
.view-bar {
  position: relative;
  background: var(--bg-sidebar);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border-bottom-color: var(--border-subtle);
}
.view-bar::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 250ms ease;
}
body.is-loading .view-bar::after {
  opacity: 1;
  animation: scan-bar 1.2s var(--ease-io) infinite;
}
@keyframes scan-bar {
  from { background-position: -60% 0; }
  to { background-position: 160% 0; }
}

.view-title {
  font-size: clamp(20px, 2.3vw, 32px);
  letter-spacing: -0.035em;
  font-weight: 650;
  text-wrap: balance;
}

.utility-group {
  background: rgb(0 0 0 / 0.18);
  border-color: var(--border-subtle);
  border-radius: 12px;
}
html.light .utility-group { background: rgb(255 255 255 / 0.6); }
.util-btn { border-radius: 9px; transition: background 200ms ease, color 200ms ease, transform 200ms var(--ease-out); }
.util-btn:active { transform: scale(0.96); }
.util-btn.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-border); }

/* ----------------------------------------------------------------------------
   Surfaces: instrument modules with spotlight + HUD corner ticks
   ---------------------------------------------------------------------------- */
.panel,
.command-bar,
.kpi-card,
.answer-card,
.case-panel {
  --mx: 50%;
  --my: 0%;
  position: relative;
  isolation: isolate;
}

.panel,
.command-bar {
  background: var(--panel-sheen), var(--bg-surface);
  border-color: var(--border-subtle);
  box-shadow: var(--surface-shadow);
  transition: border-color 350ms var(--ease-out), box-shadow 350ms var(--ease-out), transform 450ms var(--ease-out);
}

.panel::before,
.kpi-card::before,
.answer-card::before,
.command-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(380px circle at var(--mx) var(--my), var(--accent-soft), transparent 70%);
  transition: opacity 400ms ease;
}
.panel:hover::before,
.kpi-card:hover::before,
.answer-card:hover::before,
.command-bar:hover::before { opacity: 1; }
.panel:hover { border-color: var(--accent-border); }

/* HUD brackets */
.panel::after,
.answer-card::after {
  --t: var(--accent);
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(var(--t), var(--t)) top left / 14px 1.5px no-repeat,
    linear-gradient(var(--t), var(--t)) top left / 1.5px 14px no-repeat,
    linear-gradient(var(--t), var(--t)) top right / 14px 1.5px no-repeat,
    linear-gradient(var(--t), var(--t)) top right / 1.5px 14px no-repeat,
    linear-gradient(var(--t), var(--t)) bottom left / 14px 1.5px no-repeat,
    linear-gradient(var(--t), var(--t)) bottom left / 1.5px 14px no-repeat,
    linear-gradient(var(--t), var(--t)) bottom right / 14px 1.5px no-repeat,
    linear-gradient(var(--t), var(--t)) bottom right / 1.5px 14px no-repeat;
  transition: opacity 400ms ease, inset 500ms var(--ease-out);
}
.panel:hover::after,
.answer-card:hover::after { opacity: 0.9; inset: 5px; }

.panel-title { letter-spacing: -0.02em; font-weight: 650; text-wrap: balance; }
.panel-subtitle { font-size: 13.5px; }

/* Entrance choreography: panels rise in once per view change */
@keyframes rise {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.992); }
  to { opacity: 1; transform: none; }
}
.workspace-view.active > .panel,
.workspace-view.active .grid-12 > *,
.workspace-view.active > .prose-block,
.workspace-view.active > .grid-12 {
  animation: rise 700ms var(--ease-out) both;
}
.workspace-view.active .grid-12 > :nth-child(2) { animation-delay: 70ms; }
.workspace-view.active .grid-12 > :nth-child(3) { animation-delay: 140ms; }
.workspace-view.active .grid-12 > :nth-child(4) { animation-delay: 210ms; }
.workspace-view.active .grid-12 > :nth-child(5) { animation-delay: 280ms; }
.workspace-view.active .grid-12 > :nth-child(n + 6) { animation-delay: 340ms; }
.workspace-view.active > .grid-12 { animation: none; }

#summarySection .answer-card { animation: rise 800ms var(--ease-out) both; }
#summarySection .kpi-card { animation: rise 800ms var(--ease-out) both; }
#summarySection .kpi-card:nth-child(1) { animation-delay: 80ms; }
#summarySection .kpi-card:nth-child(2) { animation-delay: 150ms; }
#summarySection .kpi-card:nth-child(3) { animation-delay: 220ms; }
#summarySection .kpi-card:nth-child(4) { animation-delay: 290ms; }

/* ----------------------------------------------------------------------------
   Answer card: the one hero moment of each series
   ---------------------------------------------------------------------------- */
.answer-card {
  overflow: hidden;
  border: 1px solid var(--accent-border);
  border-inline-start: 1px solid var(--accent-border);
  background:
    radial-gradient(60% 140% at 100% 0%, var(--accent-soft), transparent 60%),
    radial-gradient(40% 120% at 0% 100%, rgb(154 134 255 / 0.07), transparent 60%),
    var(--bg-surface);
  gap: 18px 32px;
}
.answer-card > .answer-scan {
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  z-index: 1;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 30% 100%;
  background-repeat: no-repeat;
  animation: scan-top 6s var(--ease-io) infinite;
  pointer-events: none;
}
@keyframes scan-top {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}

.answer-kicker {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 10px;
  line-height: 1.4;
  border: 1px solid var(--border-strong);
  background: rgb(0 0 0 / 0.16);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.05em;
}
html.light .answer-kicker { background: rgb(255 255 255 / 0.6); }
.answer-kicker::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-green);
  box-shadow: 0 0 8px var(--status-green);
  animation: blink 2.6s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.answer-text {
  font-size: clamp(18px, 2vw, 25px);
  letter-spacing: -0.02em;
  font-weight: 600;
  text-wrap: pretty;
}
.answer-side { gap: 14px; }
#heroSparkline { width: 190px; height: 56px; overflow: visible; }
.spark-line {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 1.6s var(--ease-out) 0.25s forwards;
}
.spark-area { opacity: 0; animation: fade-in 1s ease 0.9s forwards; }
.spark-dot { opacity: 0; transform-box: fill-box; transform-origin: center; animation: dot-in 600ms var(--ease-out) 1.6s forwards, dot-pulse 2.6s ease-in-out 2.2s infinite; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { to { opacity: 1; } }
@keyframes dot-in { from { opacity: 0; transform: scale(0.2); } to { opacity: 1; transform: scale(1); } }
@keyframes dot-pulse { 50% { transform: scale(1.5); opacity: 0.7; } }

.badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  padding: 3px 10px;
}

/* ----------------------------------------------------------------------------
   KPI strip: telemetry readouts
   ---------------------------------------------------------------------------- */
.kpi-grid {
  gap: 0;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: var(--surface-shadow);
  border-radius: var(--radius);
}
.kpi-card {
  background: transparent;
  padding: 18px clamp(14px, 1.5vw, 22px) 16px;
  border-inline-start: 1px solid var(--border-subtle);
  transition: background 300ms ease;
}
.kpi-card:first-child { border-inline-start: 0; }
.kpi-card:hover { background: rgb(120 170 255 / 0.04); }
.kpi-card.hero {
  background: linear-gradient(180deg, var(--accent-soft), transparent 70%);
}
.kpi-card.hero::after {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  animation: grow-x 1.2s var(--ease-out) 0.3s both;
}
@keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.kpi-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.kpi-value-hero {
  font-size: clamp(30px, 3.2vw, 44px);
  font-weight: 500;
  letter-spacing: -0.04em;
  color: var(--accent-text);
}
.kpi-value { font-size: clamp(21px, 2vw, 27px); font-weight: 500; letter-spacing: -0.03em; }
.kpi-unit { font-size: 11.5px; }
.kpi-sub { font-size: 11.5px; font-family: var(--font-mono); letter-spacing: -0.01em; }

/* ----------------------------------------------------------------------------
   Controls
   ---------------------------------------------------------------------------- */
.command-bar { gap: 16px; }
.cmd-field-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

.ctrl-select,
.ctrl-input,
.year-select {
  background-color: rgb(0 0 0 / 0.22);
  border-color: var(--border-strong);
  border-radius: 10px;
  transition: border-color 200ms ease, box-shadow 300ms var(--ease-out), background-color 200ms ease;
}
html.light .ctrl-select, html.light .ctrl-input, html.light .year-select { background-color: rgb(255 255 255 / 0.8); }
.ctrl-select:hover, .ctrl-input:hover, .year-select:hover { border-color: var(--accent); }
.ctrl-select:focus-visible, .ctrl-input:focus-visible, .year-select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}

.cmd-switch {
  border-radius: 12px;
  background: rgb(0 0 0 / 0.16);
  transition: border-color 250ms ease, background 250ms ease, transform 250ms var(--ease-out);
}
html.light .cmd-switch { background: rgb(255 255 255 / 0.6); }
.cmd-switch:active { transform: scale(0.98); }
.cmd-switch.active { border-color: var(--accent-border); background: var(--accent-soft); }
.switch-pill { width: 32px; height: 18px; transition: background 250ms ease, border-color 250ms ease, box-shadow 300ms ease; }
.switch-thumb { width: 12px; height: 12px; transition: transform 350ms var(--ease-out), background 200ms ease; }
.cmd-switch.active .switch-thumb { transform: translateX(14px); box-shadow: 0 0 10px var(--accent); }

.btn {
  border-radius: 10px;
  font-weight: 600;
  transition: background 200ms ease, transform 200ms var(--ease-out), border-color 200ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:hover { border-color: var(--accent-border); }
.btn-primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2))); color: var(--on-accent); }
.icon-btn { border-radius: 10px; }

/* ----------------------------------------------------------------------------
   Tables
   ---------------------------------------------------------------------------- */
table.data-table thead th {
  background: transparent;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-strong);
  position: sticky;
  top: 0;
}
table.data-table tbody tr { transition: background 200ms ease; border-bottom-color: var(--border-subtle); }
table.data-table tbody tr:hover { background: linear-gradient(90deg, var(--accent-soft), transparent 80%); }
.workspace-view.active table.data-table tbody tr { animation: row-in 600ms var(--ease-out) both; }
.workspace-view.active table.data-table tbody tr:nth-child(2) { animation-delay: 40ms; }
.workspace-view.active table.data-table tbody tr:nth-child(3) { animation-delay: 80ms; }
.workspace-view.active table.data-table tbody tr:nth-child(4) { animation-delay: 120ms; }
.workspace-view.active table.data-table tbody tr:nth-child(5) { animation-delay: 160ms; }
.workspace-view.active table.data-table tbody tr:nth-child(6) { animation-delay: 200ms; }
.workspace-view.active table.data-table tbody tr:nth-child(n + 7) { animation-delay: 240ms; }
@keyframes row-in { from { opacity: 0; transform: translate3d(-8px, 0, 0); } to { opacity: 1; transform: none; } }

.prop-track { background: var(--border-subtle); height: 6px; border-radius: 99px; }
.prop-fill {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
  transform-origin: left;
  animation: grow-x 1.1s var(--ease-out) both;
}

.dot { box-shadow: 0 0 8px currentColor; }
.dot.tone-sig { color: var(--accent); }
.dot.tone-marginal { color: var(--status-amber); }
.dot.tone-none { box-shadow: none; }

/* ----------------------------------------------------------------------------
   Charts
   ---------------------------------------------------------------------------- */
.chart-box, .chart-box-sm { position: relative; }
.chart-box::before, .chart-box-sm::before {
  /* faint instrument grid behind every plot */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(var(--border-subtle) 1px, transparent 1.2px);
  background-size: 22px 22px;
  mask-image: radial-gradient(80% 80% at 50% 50%, #000, transparent);
  -webkit-mask-image: radial-gradient(80% 80% at 50% 50%, #000, transparent);
  opacity: 0.55;
}
.chart-box canvas, .chart-box-sm canvas { position: relative; }

.legend-swatch { border-top-width: 2.5px; border-radius: 2px; }
.legend-item { transition: color 200ms ease; font-family: var(--font-mono); font-size: 11px; }
.legend-item:hover { color: var(--text-primary); }
.legend-extreme { box-shadow: 0 0 10px var(--series-alert); width: 8px; height: 8px; }

.is-loading .chart-box,
.is-loading .chart-box-sm,
.is-loading .kpi-card,
.is-loading .answer-card { opacity: 1; }
.is-loading .chart-box canvas,
.is-loading .chart-box-sm canvas { opacity: 0.45; transition: opacity 250ms ease; }
.is-loading .chart-box::after,
.is-loading .chart-box-sm::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgb(120 180 255 / 0.1) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

/* ----------------------------------------------------------------------------
   Guided cases, guide cards, notes
   ---------------------------------------------------------------------------- */
.case-panel {
  background: radial-gradient(60% 120% at 0% 0%, var(--accent-soft), transparent 60%), var(--bg-surface);
  border-color: var(--accent-border);
  animation: rise 700ms var(--ease-out) both;
}
.case-finding {
  border-left: 1px solid var(--accent-border);
  background: var(--accent-soft);
  border-radius: 10px;
}
.case-dock { background: var(--bg-sidebar); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.case-highlight { outline-color: var(--accent); }

.guide-card {
  background: var(--panel-sheen), rgb(0 0 0 / 0.14);
  border-radius: 14px;
  transition: border-color 300ms ease, transform 450ms var(--ease-out);
}
html.light .guide-card { background: var(--panel-sheen), rgb(255 255 255 / 0.6); }
.guide-card:hover { border-color: var(--accent-border); transform: translateY(-2px); }
.guide-step-num { box-shadow: 0 0 0 1px var(--accent-border); }

.panel-note, .cluster-card { border-radius: 10px; background: rgb(0 0 0 / 0.14); }
html.light .panel-note, html.light .cluster-card { background: rgb(255 255 255 / 0.6); }
.app-alert { border-radius: 12px; backdrop-filter: blur(10px); }

/* ----------------------------------------------------------------------------
   Map
   ---------------------------------------------------------------------------- */
#ecuadorMap { border-radius: 12px; border-color: var(--border-strong); box-shadow: inset 0 0 40px rgb(0 0 0 / 0.25); }
.leaflet-bar { border: 1px solid var(--border-strong) !important; border-radius: 10px !important; overflow: hidden; box-shadow: none !important; }
.leaflet-bar a {
  background: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-subtle) !important;
  transition: background 200ms ease;
}
.leaflet-bar a:hover { background: var(--bg-hover) !important; }
.leaflet-control-attribution { background: var(--bg-sidebar) !important; color: var(--text-tertiary) !important; backdrop-filter: blur(8px); }
.leaflet-control-attribution a { color: var(--accent-text) !important; }
.leaflet-popup-content-wrapper, .leaflet-tooltip {
  background: var(--chart-tooltip-bg) !important;
  color: var(--chart-tooltip-text) !important;
  border: 1px solid var(--border-strong);
  border-radius: 12px !important;
  box-shadow: 0 16px 40px -16px rgb(0 0 0 / 0.7) !important;
  backdrop-filter: blur(12px);
}
.leaflet-popup-tip { background: var(--chart-tooltip-bg) !important; }
.leaflet-interactive { transition: fill-opacity 250ms ease, stroke-width 250ms ease; }
.map-legend-bar { border-radius: 99px; }

/* ----------------------------------------------------------------------------
   Responsive & reduced motion
   ---------------------------------------------------------------------------- */
@media (max-width: 960px) {
  .sidebar { backdrop-filter: blur(26px) saturate(1.3); background: color-mix(in srgb, var(--bg-canvas) 92%, transparent); }
  #heroSparkline { width: 150px; }
}

@container workspace (max-width: 810px) {
  .kpi-card { border-inline-start: 0; border-top: 1px solid var(--border-subtle); }
  .kpi-card:nth-child(-n + 2) { border-top: 0; }
  .kpi-card:nth-child(even) { border-inline-start: 1px solid var(--border-subtle); }
}

@media (hover: none) {
  .panel::before, .panel::after { display: none; }
  .nav-btn:hover, .story-btn:hover, .guide-card:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .aurora, .answer-scan, .pulse-dot::after, .answer-kicker::before, .spark-dot { animation: none !important; }
  .spark-line { stroke-dashoffset: 0; animation: none !important; }
  .spark-area, .spark-dot { opacity: 1; }
  .workspace-view.active > *, .workspace-view.active .grid-12 > *, #summarySection > *,
  .workspace-view.active table.data-table tbody tr, .case-panel { animation: none !important; }
}
