/* ===================== DESIGN TOKENS ===================== */
:root, [data-theme='light'] {
  /* Surfaces — cool slate, precision-first (finance dashboard) */
  --color-bg: #eef1f5;
  --color-surface: #ffffff;
  --color-surface-2: #f7f9fb;
  --color-surface-offset: #e4e9ef;
  --color-border: #d3dae2;
  --color-divider: #dde3ea;

  /* Text */
  --color-text: #16202e;
  --color-text-muted: #5b6675;
  --color-text-faint: #93a0af;
  --color-text-inverse: #f7f9fb;

  /* Primary accent — deep navy (trust/legacy) */
  --color-primary: #17385f;
  --color-primary-hover: #0f2a49;
  --color-primary-active: #0a1f38;
  --color-primary-highlight: #dbe3ee;

  /* Secondary accent — muted bronze/gold (wealth, legacy) */
  --color-accent: #a9803f;
  --color-accent-hover: #8a692f;
  --color-accent-highlight: #ecdfc8;

  --color-success: #2f7a4f;
  --color-success-highlight: #d9ece0;
  --color-warning: #9a5b1e;
  --color-warning-highlight: #f0e0c8;
  --color-error: #a1352f;
  --color-error-highlight: #f1d9d7;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.9rem;
  --radius-full: 9999px;

  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 2px rgba(20, 30, 45, 0.06);
  --shadow-md: 0 6px 16px rgba(20, 30, 45, 0.08);
  --shadow-lg: 0 16px 40px rgba(20, 30, 45, 0.14);

  --font-display: 'Marcellus', Georgia, serif;
  --font-body: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

[data-theme='dark'] {
  --color-bg: #0d1420;
  --color-surface: #131c2b;
  --color-surface-2: #16202f;
  --color-surface-offset: #1a2536;
  --color-border: #263349;
  --color-divider: #202c3f;

  --color-text: #dde5ee;
  --color-text-muted: #8b98ab;
  --color-text-faint: #5b6675;
  --color-text-inverse: #0d1420;

  --color-primary: #6f9bc9;
  --color-primary-hover: #8bb0d8;
  --color-primary-active: #a6c2e2;
  --color-primary-highlight: #22334a;

  --color-accent: #cdab6c;
  --color-accent-hover: #ddc086;
  --color-accent-highlight: #3a2f1c;

  --color-success: #6bc590;
  --color-success-highlight: #16301f;
  --color-warning: #d9a15a;
  --color-warning-highlight: #372a15;
  --color-error: #d97a72;
  --color-error-highlight: #3a1e1c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* Type scale (fluid, 12px floor) */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.2vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.25vw, 0.9375rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.9vw, 1.75rem);
  --text-kpi: clamp(2.25rem, 1.6rem + 2.5vw, 3.75rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --space-12: 3rem; --space-16: 4rem;
}

/* ===================== BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
img, canvas, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }
.hidden { display: none !important; }

/* ===================== RIBBON ===================== */
.demo-ribbon {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  padding: var(--space-2) var(--space-4);
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--color-border);
}

/* ===================== HEADER ===================== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.logo { color: var(--color-primary); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-size: var(--text-xl); color: var(--color-text); }
.brand-tag { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.audience-toggle { display: flex; gap: var(--space-1); background: var(--color-surface-offset); border-radius: var(--radius-full); padding: var(--space-1); }
.tab {
  border: none; background: none; cursor: pointer;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); font-weight: 600;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.tab.active { background: var(--color-primary); color: var(--color-text-inverse); }
.tab:hover:not(.active) { color: var(--color-text); }

.theme-toggle {
  border: 1px solid var(--color-border); background: var(--color-surface-2);
  border-radius: var(--radius-full); width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center; color: var(--color-text-muted);
}
.theme-toggle:hover { color: var(--color-primary); border-color: var(--color-primary); }

/* ===================== LAYOUT ===================== */
main#app { max-width: 1240px; margin: 0 auto; padding: var(--space-8); }
.view#view-advisor { display: grid; grid-template-columns: 300px 1fr; gap: var(--space-8); align-items: start; }
@media (max-width: 900px) { .view#view-advisor { grid-template-columns: 1fr; } .input-card { position: static !important; top: auto !important; } }

/* ===================== INPUT CARD ===================== */
.input-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  position: sticky;
  top: 96px;
  box-shadow: var(--shadow-sm);
}
.panel-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-1); }
.panel-sub { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-5); }
.field-grid { display: flex; flex-direction: column; gap: var(--space-4); }
.field { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-xs); font-weight: 600; color: var(--color-text-muted); }
.field input, .field select {
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
  font-family: var(--font-mono);
}
.field input:focus, .field select:focus { border-color: var(--color-primary); }
.assumption-note {
  margin-top: var(--space-6);
  padding: var(--space-3);
  background: var(--color-accent-highlight);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--color-text);
  line-height: 1.5;
}
.assumption-note a { color: var(--color-primary); font-weight: 600; }

/* ===================== STORY COLUMN ===================== */
.story-column { display: flex; flex-direction: column; gap: var(--space-6); }
.story-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.story-kicker {
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--color-primary); margin-bottom: var(--space-4);
}
.cap-note { color: var(--color-text-faint); text-transform: none; font-weight: 500; letter-spacing: 0; }
.story-copy { color: var(--color-text-muted); font-size: var(--text-sm); margin-top: var(--space-3); max-width: 68ch; }

.hero-number-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.hero-number { display: flex; flex-direction: column; }
.hero-value { font-family: var(--font-display); font-size: var(--text-kpi); line-height: 1; color: var(--color-primary); }
.hero-label { font-size: var(--text-sm); color: var(--color-text-muted); max-width: 32ch; margin-top: var(--space-2); }
.hero-chip {
  font-size: var(--text-xs); font-weight: 700; padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full); background: var(--color-success-highlight); color: var(--color-success);
  white-space: nowrap;
}
.hero-chip.warn { background: var(--color-warning-highlight); color: var(--color-warning); }
.hero-chip.bad { background: var(--color-error-highlight); color: var(--color-error); }

.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }
@media (max-width: 700px) { .chart-row { grid-template-columns: 1fr; } }
.chart-block h3 { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-3); }
.chart-canvas-wrap { position: relative; width: 100%; height: 220px; }
.chart-canvas-wrap canvas { position: absolute; top: 0; left: 0; width: 100% !important; height: 100% !important; }
.chart-canvas-wrap--client { height: 200px; }
.chart-caption { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-2); }

.before-after { display: flex; align-items: center; gap: var(--space-6); flex-wrap: wrap; }
.ba-col { flex: 1; min-width: 180px; padding: var(--space-4); border-radius: var(--radius-md); background: var(--color-surface-2); border: 1px solid var(--color-border); }
.ba-col h4 { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); margin-bottom: var(--space-2); }
.ba-metric { font-family: var(--font-mono); font-size: var(--text-xl); font-weight: 600; }
.ba-sub { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); }
.ba-recommended { background: var(--color-primary-highlight); border-color: var(--color-primary); }
.ba-recommended .ba-metric { color: var(--color-primary); }
.ba-arrow { font-size: var(--text-xl); color: var(--color-text-faint); }

.opportunity-card .flags { display: flex; flex-direction: column; gap: var(--space-3); }
.flag-item {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
}
.flag-badge {
  flex-shrink: 0; font-size: var(--text-xs); font-weight: 700; padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full); background: var(--color-accent-highlight); color: var(--color-accent);
  white-space: nowrap;
}
.flag-text { font-size: var(--text-sm); }
.flag-text strong { color: var(--color-text); }
.flag-text span { color: var(--color-text-muted); }

.disclosure-block {
  background: var(--color-surface-offset);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.disclosure-block h4 { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); margin-bottom: var(--space-2); }
.disclosure-block p { font-size: var(--text-xs); color: var(--color-text-faint); line-height: 1.6; }

/* ===================== CLIENT VIEW ===================== */
.client-sheet { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-8); }
.client-header h2 { font-family: var(--font-display); font-size: var(--text-xl); }
.client-sub { color: var(--color-text-muted); font-size: var(--text-sm); margin-top: var(--space-1); }
.client-block {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-6); box-shadow: var(--shadow-sm);
}
.client-kicker { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-primary); margin-bottom: var(--space-4); }
.client-hero { display: flex; flex-direction: column; margin-bottom: var(--space-3); }
.client-hero .hero-value { font-family: var(--font-display); font-size: var(--text-kpi); color: var(--color-primary); }
.client-hero .hero-label { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: var(--space-2); }

/* ===================== TRADER VIEW ===================== */
.trader-banner {
  background: var(--color-error-highlight); color: var(--color-error);
  border: 1px solid var(--color-error); border-radius: var(--radius-md);
  padding: var(--space-4); font-size: var(--text-sm); margin-bottom: var(--space-6);
}
.trader-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }
@media (max-width: 900px) { .trader-grid { grid-template-columns: 1fr; } }
.trader-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm); grid-column: span 1; }
.trader-card:first-child, .trader-card:last-child { grid-column: 1 / -1; }
.trader-card h3 { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-4); }
.trader-kpis { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; gap: var(--space-1); }
.kpi-value { font-family: var(--font-mono); font-size: var(--text-xl); font-weight: 700; color: var(--color-primary); }
.kpi-label { font-size: var(--text-xs); color: var(--color-text-muted); max-width: 20ch; }
.trader-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.trader-table th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; color: var(--color-text-muted); padding: var(--space-2) var(--space-2); border-bottom: 1px solid var(--color-border); }
.trader-table td { padding: var(--space-2) var(--space-2); border-bottom: 1px solid var(--color-divider); font-family: var(--font-mono); }
.trader-questions { list-style: disc; padding-left: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }

/* ===================== FOOTER ===================== */
.site-footer {
  text-align: center; padding: var(--space-8); font-size: var(--text-xs); color: var(--color-text-faint);
}
