/* ─────────────────────────────────────────────────────────────────
   Deal Underwriting Simulator — visual system v3

   Theme: cool alabaster canvas, deep midnight-cobalt sidebar,
   committed cobalt-blue as the working accent, emerald for gain,
   terracotta for AGH identity, coral for risk. Editorial serif for
   the deal name and headline IRR; everything else stays Inter.

   Color strategy: Committed.
   Cobalt carries the spine (sidebar), the lede, the active tab, the
   slider thumbs, the focus rings — roughly 30-40% of pigmented
   surface. Emerald and terracotta stay localized and earned.

   Scene: BPP fund principal walking an LP through a deal on a 27"
   monitor at 3pm in a south-facing office. Light enough not to glare
   in daylight, saturated enough to feel premium and brand-led, not
   generic SaaS beige.
───────────────────────────────────────────────────────────────── */

:root {
  /* Surfaces — cool alabaster, brand-tinted (no beige, no pure white) */
  --paper:         oklch(98%   0.012 250);  /* main canvas */
  --paper-2:       oklch(96.5% 0.014 250);
  --paper-sunk:    oklch(95%   0.016 250);
  --surface:       oklch(99.4% 0.006 250);  /* cards */
  --surface-warm:  oklch(99%   0.020 250);

  /* Ink — deep midnight-cobalt for the sidebar spine */
  --ink:           oklch(20%   0.060 265);
  --ink-2:         oklch(25%   0.070 265);
  --ink-soft:      oklch(33%   0.060 265);
  --ink-line:      oklch(40%   0.045 265);
  --ink-text:      oklch(98%   0.010 250);
  --ink-muted:     oklch(86%   0.020 250);
  --ink-faint:     oklch(72%   0.022 250);

  /* Borders */
  --border:        oklch(91%   0.012 250);
  --border-strong: oklch(84%   0.018 250);
  --border-soft:   oklch(94%   0.010 250);

  /* Type — darker overall so secondary copy and table values are
     readable in normal office light. */
  --text:          oklch(15%   0.025 260);
  --text-2:        oklch(28%   0.020 260);
  --text-muted:    oklch(40%   0.018 260);
  --text-faint:    oklch(52%   0.014 260);

  /* Accents — committed cobalt (was indigo). More saturated, more
     confident, less dusty. Used for primary actions, focus, lede. */
  --indigo:        oklch(54%   0.22  256);
  --indigo-2:      oklch(46%   0.22  256);
  --indigo-3:      oklch(36%   0.20  256);
  --indigo-soft:   oklch(95%   0.040 256);
  --indigo-mid:    oklch(86%   0.080 256);
  --indigo-line:   oklch(78%   0.110 256);

  /* Sage → emerald. Brighter, more alive. */
  --sage:          oklch(58%   0.16  158);
  --sage-2:        oklch(46%   0.16  158);
  --sage-soft:     oklch(95%   0.045 158);
  --sage-line:     oklch(80%   0.110 158);

  /* Amber → terracotta / sunset. Warmer hue, real personality. */
  --amber:         oklch(68%   0.16  48);
  --amber-2:       oklch(55%   0.16  42);
  --amber-soft:    oklch(96%   0.040 50);
  --amber-line:    oklch(83%   0.120 48);

  /* Rose → coral. Punchier red for cost / loss signals. */
  --rose:          oklch(60%   0.22  22);
  --rose-soft:     oklch(96%   0.032 22);

  /* Shadows — subtly tinted with the brand cobalt so cards feel
     lifted into a colored room, not floating in a grey void. */
  --shadow-xs: 0 1px 2px oklch(28% 0.10 256 / 0.05);
  --shadow-sm: 0 1px 3px oklch(28% 0.10 256 / 0.06), 0 2px 8px oklch(28% 0.10 256 / 0.05);
  --shadow:    0 2px 6px oklch(28% 0.10 256 / 0.08), 0 12px 28px -8px oklch(28% 0.10 256 / 0.10);
  --shadow-lg: 0 6px 18px oklch(28% 0.10 256 / 0.12), 0 28px 56px -16px oklch(28% 0.10 256 / 0.20);

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r:    10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;

  /* Type scale */
  --fs-2xs: 11px;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-md:  15px;
  --fs-lg:  17px;
  --fs-xl:  20px;
  --fs-2xl: 26px;
  --fs-3xl: 34px;
  --fs-display: clamp(40px, 5vw, 64px);

  /* Motion — exponential ease-out */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 140ms;
  --t:      220ms;
  --t-slow: 360ms;

  /* Fonts — Inter for body/UI, Instrument Serif for editorial moments
     (deal name, headline IRR). Real hierarchy via typeface contrast. */
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Instrument Serif", "Iowan Old Style", "Georgia", serif;
  --font-mono:    ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  /* Subtle cobalt-tinted gradient wash so the canvas isn't a flat
     slab. Anchored at the top — feels like daylight from a window. */
  background:
    radial-gradient(ellipse 1200px 600px at 80% -10%, oklch(94% 0.04 256 / 0.6), transparent 60%),
    radial-gradient(ellipse 900px 500px at 0% 100%, oklch(96% 0.03 158 / 0.35), transparent 60%),
    var(--paper);
  background-attachment: fixed;
  color: var(--text);
  font-size: var(--fs-sm);
  font-feature-settings: "tnum", "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── AUTH GATE ─────────────────────────────────────────────────── */
#authGate {
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at top, oklch(28% 0.04 283 / 0.8), transparent 60%),
    oklch(15% 0.025 280);
  color: oklch(95% 0.008 75);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  z-index: 9999; text-align: center; padding: 24px;
}
#authGate.hide { display: none; }
#authGate .card {
  max-width: 440px;
  background: oklch(22% 0.025 280);
  border: 1px solid oklch(30% 0.025 280);
  border-radius: var(--r-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
#authGate .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--sage);
  display: inline-block; margin-right: 10px; vertical-align: middle;
}
#authGate h2 {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
#authGate p { font-size: var(--fs-sm); color: oklch(75% 0.012 280); line-height: 1.6; margin-bottom: 18px; }
#authGate button {
  background: var(--indigo); color: #fff; border: none;
  border-radius: var(--r-sm); padding: 11px 20px;
  font-weight: 600; font-size: var(--fs-md); font-family: inherit;
  cursor: pointer; transition: all var(--t) var(--ease);
}
#authGate button:hover { background: var(--indigo-2); transform: translateY(-1px); }
#authGate .err { color: oklch(72% 0.18 25); font-weight: 600; }
#authGate .small { font-size: var(--fs-2xs); color: oklch(65% 0.012 280); margin-top: 16px; }

/* ── APP SHELL ─────────────────────────────────────────────────── */
.app { display: none; min-height: 100vh; width: 100%; }
.app.on { display: flex; }

/* Sidebar — deep ink, the spine of the design */
.sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--ink);
  color: var(--ink-text);
  border-right: 1px solid var(--ink-line);
  display: flex; flex-direction: column;
  min-height: 100vh;
  align-self: stretch;
  transition: width var(--t) var(--ease);
  position: relative;
}

/* Collapse handle — sits on the right edge of the sidebar */
.sb-collapse {
  position: absolute; top: 18px; right: -12px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink-2);
  border: 1px solid var(--ink-line);
  color: var(--ink-text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 60;
  transition: transform var(--t) var(--ease), background var(--t-fast) var(--ease);
  box-shadow: var(--shadow-sm);
}
.sb-collapse:hover { background: var(--indigo); border-color: var(--indigo); }
.sb-collapse svg { transition: transform var(--t) var(--ease); }

/* Collapsed state — narrow rail, only the toggle remains visible */
.sidebar.collapsed { width: 12px; }
.sidebar.collapsed > :not(.sb-collapse) { opacity: 0; pointer-events: none; visibility: hidden; }
.sidebar.collapsed .sb-collapse { right: -12px; }
.sidebar.collapsed .sb-collapse svg { transform: rotate(180deg); }
.sb-head {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--ink-2);
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700;
  color: var(--ink-text);
  letter-spacing: -0.015em;
  line-height: 1.2;
}
.sb-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sage); flex-shrink: 0; }
.sb-tag {
  font-size: 9px; font-weight: 600; font-family: var(--font-sans);
  padding: 3px 8px; border-radius: 999px;
  background: var(--indigo); color: #fff;
  letter-spacing: 0.06em; margin-left: auto;
  text-transform: uppercase;
}
.sb-user {
  font-size: var(--fs-2xs); color: var(--ink-muted);
  margin-top: 10px; display: flex; justify-content: space-between;
  align-items: center; gap: 8px;
}
.sb-user span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.sb-user .logout {
  font-size: var(--fs-2xs); color: var(--ink-muted); text-decoration: none;
  border: 1px solid var(--ink-line); padding: 3px 9px;
  border-radius: var(--r-sm); flex-shrink: 0;
  transition: all var(--t-fast) var(--ease);
}
.sb-user .logout:hover { background: var(--ink-2); color: var(--ink-text); }

.sb-actions {
  padding: 12px; border-bottom: 1px solid var(--ink-2);
  display: flex; gap: 6px; flex-wrap: wrap;
}
.sb-actions button {
  flex: 1; border: 1px solid var(--ink-line); background: var(--ink-2);
  color: var(--ink-text); border-radius: var(--r-sm);
  padding: 8px 10px; font-size: var(--fs-xs); font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: all var(--t-fast) var(--ease);
}
.sb-actions button.primary {
  background: var(--indigo); color: #fff; border-color: var(--indigo);
}
.sb-actions button.primary:hover { background: var(--indigo-2); border-color: var(--indigo-2); transform: translateY(-1px); }
.sb-actions button:hover:not(.primary) { background: var(--ink-soft); border-color: var(--ink-faint); }
.sb-actions .sb-trash {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px;
}
.sb-actions .sb-trash svg { vertical-align: -1px; opacity: 0.85; }

.sb-list { flex: 1; overflow-y: auto; padding: 8px; scrollbar-width: thin; scrollbar-color: var(--ink-line) transparent; }
.sb-list::-webkit-scrollbar { width: 6px; }
.sb-list::-webkit-scrollbar-thumb { background: var(--ink-line); border-radius: 3px; }
.sb-list .empty {
  font-size: var(--fs-xs); color: var(--ink-faint);
  padding: 22px 8px; text-align: center; line-height: 1.6;
}
.sb-list .group-label {
  font-size: 10px; font-weight: 800; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.12em;
  padding: 14px 8px 6px;
}
.sb-deal {
  padding: 10px 12px; border-radius: var(--r-sm);
  cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
  transition: all var(--t-fast) var(--ease);
}
.sb-deal:hover { background: var(--ink-2); }
.sb-deal.active {
  background: var(--ink-soft);
  border-color: var(--indigo);
  box-shadow: inset 2px 0 0 var(--indigo);
}
.sb-deal .name {
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--ink-text); line-height: 1.3;
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.sb-deal .name .del {
  opacity: 0; border: none; background: transparent;
  color: var(--ink-faint); font-size: 14px;
  cursor: pointer; line-height: 1; padding: 0 4px; flex-shrink: 0;
  transition: color var(--t-fast) var(--ease);
}
.sb-deal:hover .name .del { opacity: 1; }
.sb-deal .name .del:hover { color: var(--rose); }
.sb-deal .meta { font-size: 10px; color: var(--ink-muted); margin-top: 4px; line-height: 1.4; }
.sb-deal .author { font-size: 10px; color: var(--ink-muted); margin-top: 6px; }
.sb-deal-chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px; margin-top: 8px;
}
.sb-deal-chips .chip {
  display: inline-flex; flex-direction: column;
  min-width: 0;
  padding: 4px 4px;
  background: oklch(30% 0.08 265 / 0.45);
  border: 1px solid var(--ink-line);
  border-radius: 5px;
  text-align: center;
  line-height: 1.15;
}
.sb-deal-chips .chip-l {
  font-size: 8px; font-weight: 700;
  color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
.sb-deal-chips .chip-v {
  font-size: 10px; font-weight: 700;
  color: var(--ink-text);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
  white-space: nowrap;
}
.sb-deal-chips .chip-irr[data-tone="good"] {
  background: oklch(35% 0.13 158 / 0.45);
  border-color: oklch(55% 0.16 158 / 0.6);
}
.sb-deal-chips .chip-irr[data-tone="good"] .chip-v { color: oklch(85% 0.16 158); }
.sb-deal-chips .chip-irr[data-tone="warn"] {
  background: oklch(35% 0.10 50 / 0.45);
  border-color: oklch(60% 0.14 50 / 0.6);
}
.sb-deal-chips .chip-irr[data-tone="warn"] .chip-v { color: oklch(85% 0.14 60); }
.sb-deal-chips .chip-irr[data-tone="bad"] {
  background: oklch(35% 0.18 22 / 0.4);
  border-color: oklch(58% 0.20 22 / 0.6);
}
.sb-deal-chips .chip-irr[data-tone="bad"] .chip-v { color: oklch(85% 0.18 22); }
.sb-deal.scratch {
  background: oklch(35% 0.08 65 / 0.25);
  border-color: oklch(50% 0.10 65 / 0.5);
}
.sb-deal.scratch .name { color: oklch(85% 0.10 65); }
.sb-foot {
  padding: 12px 14px; border-top: 1px solid var(--ink-2);
  font-size: 9px; color: var(--ink-faint); line-height: 1.5;
}

/* Main column — full canvas, no max-width */
.main {
  flex: 1; min-width: 0;
  padding: 0;
  display: flex; flex-direction: column;
}

/* ── TOP BAR (editorial) ───────────────────────────────────────── */
.topbar {
  position: relative; z-index: 50;
  background:
    radial-gradient(ellipse 80% 70% at 30% 0%, var(--indigo-soft) 0%, transparent 70%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper) 100%);
  border-bottom: 1px solid var(--border);
  padding: 12px clamp(20px, 3vw, 40px) 0;
}

.topbar-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: clamp(14px, 1.6vw, 24px);
  align-items: center;
  margin-bottom: 8px;
}
.topbar-grid > .topbar-identity { justify-self: start; min-width: 0; }
.topbar-grid > .topbar-lede     { justify-self: center; }
.topbar-grid > .topbar-actions  { justify-self: end; }
@media (max-width: 1300px) { .topbar-grid { gap: 12px; } }
@media (max-width: 1100px) { .topbar-grid { grid-template-columns: 1fr; gap: 16px; } .topbar-grid > * { justify-self: stretch !important; max-width: none !important; } }

/* Left: identity column */
.topbar-identity { min-width: 0; }
.eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-2xs); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: 6px;
}
.eyebrow-sep { color: var(--text-faint); }
.eyebrow-text { font-weight: 500; }

.dirty-badge {
  display: inline-block; font-size: 9px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--amber-soft); color: oklch(40% 0.12 65);
  letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid var(--amber-line);
}
.dirty-badge.saved   { background: var(--sage-soft);  color: oklch(34% 0.10 165); border-color: var(--sage-line); }
.dirty-badge.scratch { background: var(--amber-soft); color: oklch(38% 0.12 65);  border-color: var(--amber-line); }
.dirty-badge.dirty   { background: var(--amber-soft); color: oklch(38% 0.12 65);  border-color: var(--amber-line); }

.deal-name-input {
  font-size: clamp(28px, 2.8vw, 38px);
  font-weight: 700; line-height: 1.1;
  letter-spacing: -0.025em;
  border: none; background: transparent;
  padding: 2px 4px;
  color: var(--text); outline: none;
  border-radius: var(--r-sm);
  display: block; width: 100%;
  margin-left: -4px;
  border: 1px solid transparent;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.deal-name-input:hover { border-color: var(--border); }
.deal-name-input:focus { background: var(--surface); border-color: var(--indigo-line); }
.deal-name-input::placeholder { color: var(--text-faint); font-weight: 600; }

.identity-meta {
  display: flex; align-items: center; gap: 14px;
  margin-top: 4px;
  font-size: var(--fs-md); color: var(--text-2);
  flex-wrap: wrap;
}
.meta-chunk { display: inline-flex; align-items: baseline; gap: 6px; }
.meta-l {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.meta-v {
  font-size: var(--fs-md); font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.meta-dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--text-faint);
}

/* Middle-left: executive summary (the verdict) */
.topbar-summary {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.verdict-inline {
  margin: 0;
  padding: 10px 14px;
  font-size: var(--fs-sm);
  line-height: 1.45;
}

/* AI insights panel — replaces the static verdict box. Same footprint
   so the topbar grid balance is preserved. */
.ai-panel {
  position: relative;
  background:
    radial-gradient(circle at 100% 0%, oklch(94% 0.06 256 / 0.55), transparent 65%),
    var(--surface);
  border: 1px solid var(--indigo-line);
  border-radius: var(--r-md);
  padding: 10px 14px 12px;
  box-shadow: var(--shadow-xs);
  width: 100%;
  max-height: 220px;
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.ai-panel[data-state="ready"] {
  border-color: oklch(80% 0.14 256);
  box-shadow: var(--shadow-sm);
  max-height: 380px;
}
.ai-panel[data-state="busy"]  { border-color: oklch(80% 0.14 256); }
.ai-panel[data-state="error"] { border-color: var(--rose); }

.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
.ai-title {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-2xs); font-weight: 700;
  color: var(--indigo-2);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.ai-title .ai-spark {
  color: var(--indigo);
  animation: aiSparkSpin 8s linear infinite;
}
.ai-panel[data-state="busy"] .ai-spark { animation-duration: 1.6s; }
@keyframes aiSparkSpin { to { transform: rotate(360deg); } }
.ai-model {
  font-size: 10px; font-weight: 600;
  color: var(--text-faint);
  text-transform: none; letter-spacing: 0.02em;
  padding: 2px 7px;
  background: var(--paper-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}
.ai-btn {
  font-family: inherit; font-size: var(--fs-xs); font-weight: 600;
  padding: 5px 12px;
  background: var(--indigo); color: #fff;
  border: 1px solid var(--indigo-2);
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.ai-btn:hover:not(:disabled) { background: var(--indigo-2); transform: translateY(-1px); }
.ai-btn:disabled { opacity: 0.65; cursor: progress; }

.ai-body {
  margin-top: 8px;
  font-size: var(--fs-xs);
  color: var(--text-2);
  line-height: 1.55;
  overflow-y: auto;
  flex: 1 1 auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.ai-body::-webkit-scrollbar { width: 6px; }
.ai-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.ai-hint { color: var(--text-muted); }
.ai-err  { color: oklch(48% 0.18 22); font-weight: 600; }

.ai-h {
  font-size: var(--fs-2xs); font-weight: 700;
  color: var(--indigo-2);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin: 8px 0 3px; line-height: 1.3;
}
.ai-h:first-child { margin-top: 0; }
.ai-p { margin: 4px 0; color: var(--text); }
.ai-ul { margin: 2px 0 4px 18px; padding: 0; list-style: disc; }
.ai-ul li { margin: 2px 0; }
.ai-body strong { color: var(--text); font-weight: 700; }

/* Full-tab AI insights surface. Same renderer feeds it, but the layout is
   designed for long-form analyst output: wider measure, larger type, no
   height clamp, generous section spacing. */
.ai-full {
  background:
    radial-gradient(circle at 100% 0%, oklch(94% 0.06 256 / 0.4), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px clamp(24px, 3vw, 44px) 36px;
  box-shadow: var(--shadow-sm);
}
.ai-full[data-state="busy"]  { border-color: var(--indigo-line); }
.ai-full[data-state="error"] { border-color: var(--rose); }
.ai-full-body {
  font-size: var(--fs-md);
  color: var(--text);
  line-height: 1.65;
}
.ai-full-body .ai-h {
  font-size: var(--fs-md);
  font-weight: 800;
  color: var(--indigo-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 22px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}
.ai-full-body .ai-h:first-child { margin-top: 0; }
.ai-full-body h3.ai-h { font-size: var(--fs-sm); border-bottom: none; padding-bottom: 0; }
.ai-full-body .ai-p {
  font-size: var(--fs-md);
  margin: 8px 0;
}
.ai-full-body .ai-ul {
  margin: 6px 0 12px 22px;
}
.ai-full-body .ai-ul li { margin: 6px 0; }
.ai-full-body strong { color: var(--text); font-weight: 700; }
.ai-full-body a { color: var(--indigo); text-decoration: underline; text-underline-offset: 2px; }
.ai-full-body a:hover { color: var(--indigo-2); }

.ai-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.ai-empty p { margin-bottom: 8px; }
.ai-empty-note {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  max-width: 60ch;
  margin: 8px auto 0;
}
.ai-stamp {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border-soft);
}

/* Middle-right: lede — the IRR that dominates */
.topbar-lede {
  display: flex; flex-direction: column;
  gap: 4px; align-items: center; justify-content: center;
  padding: 14px 22px;
  background: var(--surface);
  border: 1px solid var(--indigo-line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.topbar-lede::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 100% 0%, var(--indigo-soft) 0%, transparent 60%);
  pointer-events: none;
}
/* Compact variant — removed; default lede styling now applies */
.topbar-lede-compact { padding: 14px 22px; }
.topbar-lede-compact .lede-value { font-size: clamp(36px, 4vw, 56px); }
.topbar-lede-compact .lede-sub   { font-size: var(--fs-xs); }
.lede-label {
  font-size: var(--fs-xs); font-weight: 700;
  color: var(--indigo-2);
  text-transform: uppercase; letter-spacing: 0.1em;
  position: relative;
}
.lede-value {
  font-family: var(--font-display);
  font-size: clamp(44px, 4.6vw, 64px);
  font-weight: 400; line-height: 1;
  letter-spacing: -0.02em;
  color: var(--indigo-3);
  font-variant-numeric: tabular-nums;
  position: relative;
  text-align: center;
}
.lede-value[data-tone="good"] { color: oklch(34% 0.13 165); }
.lede-value[data-tone="warn"] { color: oklch(40% 0.14 65); }
.lede-value[data-tone="bad"]  { color: oklch(40% 0.18 25); }
.lede-sub {
  font-size: var(--fs-sm); color: var(--text-muted);
  margin-top: 2px;
  position: relative;
  text-align: center;
}
.lede-sub span { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* Right: actions */
.topbar-actions {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; justify-self: end;
}
@media (max-width: 1100px) { .topbar-actions { justify-self: start; } }
.topbar-label {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-xs); color: var(--text-2); font-weight: 500;
}
.topbar-label select {
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 10px; font-size: var(--fs-xs);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-weight: 500;
  transition: all var(--t-fast) var(--ease);
}
.topbar-label select:hover { border-color: var(--border-strong); }
.topbar-label select:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-soft); }

.btn-ghost {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--r-sm);
  padding: 7px 14px; font-size: var(--fs-xs); font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: all var(--t-fast) var(--ease);
}
.btn-ghost:hover { background: var(--paper-2); border-color: var(--border-strong); transform: translateY(-1px); }

/* Variant: primary-tinted ghost (used for Save next to Print) */
.btn-ghost.btn-primary {
  background: var(--indigo); color: #fff;
  border-color: var(--indigo-2);
}
.btn-ghost.btn-primary:hover { background: var(--indigo-2); border-color: var(--indigo-2); }

/* Variant: square icon button (Trash) */
.btn-ghost.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 4px;
  padding: 7px 9px;
  position: relative;
}
.btn-ghost.btn-icon svg { color: var(--text-2); }

/* ── USER MENU (top-right) ─────────────────────────────────────── */
.user-menu { position: relative; }
.user-menu-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--t-fast) var(--ease);
  padding: 0;
}
.user-menu-btn:hover { border-color: var(--indigo); transform: translateY(-1px); }
.user-menu-btn[aria-expanded="true"] { border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-soft); }
.user-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; border-radius: 50%;
  font-size: 13px; font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--indigo), oklch(50% 0.18 268));
  letter-spacing: 0;
  text-transform: uppercase;
}
.user-pop {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  overflow: hidden;
  animation: upPop 180ms var(--ease);
}
.user-pop[hidden] { display: none; }
@keyframes upPop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.up-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.up-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), oklch(50% 0.18 268));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  flex-shrink: 0;
}
.up-id { min-width: 0; flex: 1; }
.up-name {
  font-size: var(--fs-sm); font-weight: 700; color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.up-email {
  font-size: var(--fs-xs); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}
.up-sec {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.up-sec-l {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.up-theme {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--paper-sunk);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  padding: 3px;
}
.up-theme-opt {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 5px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.up-theme-opt:hover { color: var(--text); }
.up-theme-opt[aria-checked="true"] {
  background: var(--surface);
  border-color: var(--indigo-line);
  color: var(--indigo-2);
  box-shadow: var(--shadow-xs);
}
.up-theme-opt svg { opacity: 0.85; }
.up-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
  font-family: inherit;
}
.up-item:hover { background: var(--paper-2); }
.up-item svg { color: var(--text-muted); }
.up-signout { color: var(--rose); }
.up-signout svg { color: var(--rose); }
.up-signout:hover { background: oklch(96% 0.025 22); }
.up-badge {
  margin-left: auto;
  background: var(--indigo);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* Trash count pill on the Trash button */
.trash-count {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  font-size: 10px; font-weight: 700;
  color: #fff; background: var(--rose);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* Trash modal */
.trash-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: none;
}
.trash-modal.on { display: block; }
.trash-mask {
  position: absolute; inset: 0;
  background: oklch(20% 0.04 260 / 0.45);
  backdrop-filter: blur(2px);
  animation: trashFadeIn 180ms var(--ease);
}
.trash-card {
  position: relative;
  margin: 7vh auto 0;
  width: min(720px, 92vw);
  max-height: 80vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: trashSlideUp 240ms var(--ease);
}
@keyframes trashFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes trashSlideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.trash-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.trash-head h3 {
  font-size: var(--fs-lg); font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.trash-head p {
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-top: 4px;
}
.trash-x {
  background: none; border: none;
  font-size: 22px; line-height: 1;
  color: var(--text-muted); cursor: pointer;
  padding: 4px 8px; border-radius: var(--r-sm);
  transition: all var(--t-fast) var(--ease);
}
.trash-x:hover { color: var(--text); background: var(--paper-2); }
.trash-list {
  overflow-y: auto;
  padding: 10px 14px 18px;
  flex: 1 1 auto;
}
.trash-empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: var(--fs-sm);
}
.trash-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  margin-bottom: 8px;
  background: var(--paper);
  transition: all var(--t-fast) var(--ease);
}
.trash-row:hover { border-color: var(--border-strong); background: var(--paper-2); }
.trash-row-name { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.trash-row-meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.trash-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.trash-purge { color: var(--rose); border-color: oklch(85% 0.06 22); }
.trash-purge:hover { background: oklch(96% 0.025 22); color: oklch(40% 0.20 22); }

/* KPI chips — supporting numbers (the lede above is the primary) */
.kpis {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
@media (max-width: 1700px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 700px)  { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  display: flex; flex-direction: column;
  padding: 8px 10px;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  transition: all var(--t-fast) var(--ease);
  text-align: center;
}
.kpi:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-xs); }
.kpi-l {
  font-size: 10px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  line-height: 1.2;
  flex: 0 0 auto;
  min-height: 0;
}
.kpi-v {
  font-size: clamp(18px, 1.5vw, 22px); font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  flex: 0 0 auto;
  min-height: 0;
  margin: 2px 0;
}
.kpi-s {
  font-size: 10px; color: var(--text-muted);
  line-height: 1.3;
  flex: 1 1 auto;
  min-height: 0;
}
.kpi-v-pos { color: oklch(38% 0.13 165); }
.kpi-v-neg { color: oklch(45% 0.18 25); }
.kpi-v[data-tone="good"] { color: oklch(38% 0.13 165); }
.kpi-v[data-tone="warn"] { color: oklch(45% 0.14 65); }
.kpi-v[data-tone="bad"]  { color: oklch(45% 0.18 25); }

/* Tab nav */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin: 0 calc(-1 * clamp(20px, 3vw, 40px));
  padding: 0 clamp(20px, 3vw, 40px);
}
.tab-btn {
  border: none; background: transparent;
  color: var(--text-muted); font-family: inherit;
  font-size: var(--fs-md); font-weight: 500;
  padding: 12px 18px;
  cursor: pointer;
  position: relative;
  transition: color var(--t-fast) var(--ease);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--indigo-2);
  font-weight: 600;
}
.tab-btn.active::after {
  content: ""; position: absolute;
  left: 12px; right: 12px; bottom: -1px; height: 2px;
  background: var(--indigo);
  border-radius: 2px 2px 0 0;
}

/* Tab panels */
.tab-panel { display: none; padding: 14px clamp(20px, 3vw, 40px) 40px; flex: 1; }
.tab-panel.active { display: block; animation: fadeUp 280ms var(--ease); }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-intro {
  font-size: var(--fs-sm); color: var(--text-muted);
  margin-bottom: 22px; line-height: 1.6;
  max-width: 70ch;
}

/* Section labels */
.sec {
  font-size: var(--fs-2xs); font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin: 14px 0 8px;
  display: flex; align-items: center; gap: 10px;
  /* Lock the row height so the heading baseline never jumps when a
     section header carries an extra control (button, select, spotlight
     dropdown). Every tab now opens with the heading at the same Y. */
  min-height: 32px;
}
.sec:first-child { margin-top: 0; }
.sec.sec-with-spot { gap: 16px; }
.sec.sec-with-spot .sec-text { display: inline-flex; align-items: center; gap: 10px; }
.sec.sec-with-spot .sec-spot { margin-left: auto; }
.partners-toolbar {
  display: none;
}
.sec-spot { font-size: var(--fs-2xs); color: var(--text-muted); display: inline-flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.sec-spot select { font-family: inherit; font-size: var(--fs-xs); padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 500; }
/* Partners tab: spot-panel sits before the first .sec but is display:none
   until activated, so use this rule to zero the top margin when it's idle. */
.spot-panel:not(.on) + .sec { margin-top: 0; }
.sec::before {
  content: ""; width: 16px; height: 1px; background: var(--border-strong);
}
.sec .hint {
  font-weight: 400; letter-spacing: 0; text-transform: none;
  color: var(--text-faint); font-size: var(--fs-2xs);
}

/* ── INPUT CARDS ───────────────────────────────────────────────── */
.inputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  /* Cap to 4 columns at extreme widths so cards don't get lost */
  max-width: 1800px;
}
@media (min-width: 1400px) { .inputs-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Compact variant: tighter rows so all 4 cards fit without scrolling
   on a typical laptop (1366-1600px) viewport. */
.inputs-grid.compact { gap: 12px; }
.inputs-grid.compact .input-group { padding: 14px 16px 14px; }
.inputs-grid.compact .ig-title { margin-bottom: 10px; padding-bottom: 8px; font-size: var(--fs-sm); }
.inputs-grid.compact .ig-sub { margin: 10px 0 6px; padding-top: 8px; }
.inputs-grid.compact .ig-sub:first-of-type { margin-top: 2px; }
.inputs-grid.compact .sl-row { margin-bottom: 6px; min-height: 22px; gap: 8px; }
.inputs-grid.compact .sl-row label { font-size: var(--fs-xs); line-height: 1.25; }
.inputs-grid.compact .sl-row input[type=range] { width: 86px; }
.inputs-grid.compact .sl-row input[type=number] { width: 92px; padding: 4px 7px; }
.inputs-grid.compact .sl-row input[type=text] { padding: 4px 8px; }
.inputs-grid.compact .sl-row span { min-width: 50px; padding: 2px 5px; }

.input-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t) var(--ease), border-color var(--t) var(--ease);
}
.input-group:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.ig-title {
  font-size: var(--fs-md); font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.ig-sub {
  font-size: 9px; font-weight: 700;
  color: var(--indigo-2);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin: 16px 0 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-soft);
}
.ig-sub:first-of-type { padding-top: 0; border-top: 0; margin-top: 4px; }

.sl-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 9px;
  min-height: 26px;
}
.sl-row label {
  font-size: var(--fs-xs); color: var(--text-2);
  min-width: 0; flex: 1;
  font-weight: 500;
  line-height: 1.35;
}

/* Sliders */
.sl-row input[type=range] {
  width: 110px; flex-shrink: 0;
  -webkit-appearance: none; appearance: none;
  background: transparent; cursor: pointer;
  height: 20px;
}
.sl-row input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--indigo-mid), var(--border));
}
.sl-row input[type=range]::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--indigo-mid), var(--border));
}
.sl-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--indigo);
  margin-top: -6px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.sl-row input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--indigo);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
}
.sl-row input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.15); }
.sl-row input[type=range]:focus { outline: none; }
.sl-row input[type=range]:focus::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--indigo-soft); }

/* Text/number inputs */
.sl-row input[type=number] {
  width: 110px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 9px; font-size: var(--fs-xs);
  text-align: right; background: var(--surface);
  font-family: inherit; color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: all var(--t-fast) var(--ease);
}
.sl-row input[type=text] {
  flex: 1; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 10px; font-size: var(--fs-xs);
  min-width: 0; background: var(--surface);
  font-family: inherit; color: var(--text);
}
.sl-row input[type=number]:hover,
.sl-row input[type=text]:hover { border-color: var(--border-strong); }
.sl-row input[type=number]:focus,
.sl-row input[type=text]:focus {
  outline: none; border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-soft);
}

.sl-row span {
  font-size: var(--fs-xs); font-weight: 600;
  min-width: 56px; text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  cursor: text; border-radius: var(--r-sm);
  padding: 3px 7px;
  border: 1px solid transparent;
  transition: all var(--t-fast) var(--ease);
}
.sl-row span:hover { background: var(--paper-2); border-color: var(--border); }
.sl-row span.editing { background: var(--surface); border-color: var(--indigo); }
.sl-row input.inline-num {
  width: 64px; flex-shrink: 0;
  border: 1px solid var(--indigo); border-radius: var(--r-sm);
  padding: 3px 7px; font-size: var(--fs-xs); font-weight: 600;
  text-align: right; color: var(--text); outline: none;
  background: var(--surface); font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.split-check {
  font-size: var(--fs-2xs); padding: 6px 12px;
  border-radius: var(--r-sm); display: inline-block;
  margin-top: 4px; font-weight: 600;
}
.sc-ok { background: var(--sage-soft); color: oklch(34% 0.10 165); border: 1px solid var(--sage-line); }

/* ── RESIDUAL ALLOC BAR ────────────────────────────────────────── */
.alloc-bar {
  height: 64px; border-radius: var(--r);
  overflow: hidden; display: flex;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.seg {
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 600;
  overflow: hidden; white-space: nowrap; padding: 0 14px;
  transition: width var(--t-slow) var(--ease);
  letter-spacing: -0.005em;
}
.seg-lp  { background: linear-gradient(135deg, var(--sage), var(--sage-2));   color: #fff; }
.seg-bpp { background: linear-gradient(135deg, var(--indigo), var(--indigo-2)); color: #fff; }
.seg-agh { background: linear-gradient(135deg, var(--amber), var(--amber-2));  color: oklch(22% 0.04 65); }

.alloc-legend {
  display: flex; gap: 18px;
  font-size: var(--fs-xs); color: var(--text-2);
  margin-bottom: 22px; flex-wrap: wrap; align-items: center;
}
.leg { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.leg-sq { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.leg-sq.leg-lp  { background: var(--sage); }
.leg-sq.leg-bpp { background: var(--indigo); }
.leg-sq.leg-agh { background: var(--amber); }
.leg-summary {
  margin-left: auto; font-size: var(--fs-2xs); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── FACT GRID ─────────────────────────────────────────────────── */
.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.fact {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  transition: all var(--t-fast) var(--ease);
}
.fact:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-xs); }
.fact-l {
  font-size: 9px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.fact-v {
  font-size: var(--fs-xl); font-weight: 600; color: var(--text);
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}
.fact-v-pos { color: oklch(38% 0.13 165); }
.fact-v-neg { color: oklch(45% 0.18 25); }
.fact-s { font-size: 9px; color: var(--text-faint); margin-top: 3px; line-height: 1.4; }

.verdict {
  border-radius: var(--r);
  padding: 14px 18px; font-size: var(--fs-sm);
  border: 1px solid; margin-bottom: 22px; line-height: 1.65;
}
.v-green { background: var(--sage-soft);  color: oklch(28% 0.10 165); border-color: var(--sage-line); }
.v-warn  { background: var(--amber-soft); color: oklch(34% 0.10 65);  border-color: var(--amber-line); }
.v-red   { background: var(--rose-soft);  color: oklch(35% 0.15 25);  border-color: oklch(78% 0.12 25); }

/* ── COST BREAKDOWN ────────────────────────────────────────────── */
.cost-box {
  background: transparent; border: 0; padding: 0; margin: 0 0 22px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
@media (max-width: 1400px) { .cost-box { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 800px)  { .cost-box { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cost-group {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--paper-sunk);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  padding: 10px;
}
.cg-label {
  font-size: 12px; font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 6px;
}
.cg-items {
  display: flex; flex-direction: column; gap: 6px;
}
.cost-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
  transition: all var(--t-fast) var(--ease);
}
.cost-card:hover { border-color: var(--border-strong); }
.cost-card .cc-l {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  line-height: 1.25;
}
.cost-card .cc-v {
  font-size: var(--fs-md); color: var(--text); font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  line-height: 1.15;
}
.cost-card .cc-s { font-size: 9px; color: var(--text-faint); line-height: 1.3; }
.cost-card.muted { background: var(--surface); }
.cost-card.muted .cc-v { color: var(--text-faint); font-weight: 500; }

/* ── CONTRACT CARDS ────────────────────────────────────────────── */
.contract-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 18px; margin-bottom: 22px;
}
@media (max-width: 1000px) { .contract-grid { grid-template-columns: 1fr; } }
.cc {
  background: var(--surface); border: 1px solid;
  border-radius: var(--r-md); overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.cc:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cc-oa  { border-color: var(--amber-line); }
.cc-lpa { border-color: var(--indigo-line); }
.cc-head {
  padding: 16px 20px; border-bottom: 1px solid;
}
.cc-oa  .cc-head {
  background: linear-gradient(180deg, var(--amber-soft), oklch(98% 0.020 68));
  border-color: var(--amber-line);
}
.cc-lpa .cc-head {
  background: linear-gradient(180deg, var(--indigo-soft), oklch(98% 0.020 283));
  border-color: var(--indigo-line);
}
.cc-badge {
  font-size: 9px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  display: inline-block; margin-bottom: 8px;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.cc-oa  .cc-badge { background: var(--amber);  color: oklch(22% 0.04 65); }
.cc-lpa .cc-badge { background: var(--indigo); color: #fff; }
.cc-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl); font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.2;
}
.cc-oa  .cc-title { color: oklch(30% 0.10 65); }
.cc-lpa .cc-title { color: var(--indigo-3); }
.cc-sub {
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-top: 6px; line-height: 1.55;
}
.crow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 20px; font-size: var(--fs-xs);
  border-bottom: 1px solid var(--border-soft);
  transition: background var(--t-fast) var(--ease);
}
.crow:hover { background: var(--paper-2); }
.crow:last-child { border-bottom: none; }
.crow-l { color: var(--text-2); }
.crow-v {
  font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.crow-key  { background: var(--sage-soft); }
.crow-key:hover  { background: oklch(94% 0.04 165); }
.crow-key  .crow-l { color: oklch(34% 0.10 165); font-weight: 600; }
.crow-key  .crow-v { color: oklch(34% 0.10 165); font-size: var(--fs-md); }
.crow-key2 { background: var(--indigo-soft); }
.crow-key2:hover { background: oklch(93% 0.04 283); }
.crow-key2 .crow-l { color: var(--indigo-3); font-weight: 600; }
.crow-key2 .crow-v { color: var(--indigo-3); font-size: var(--fs-md); }
.crow-key3 { background: var(--amber-soft); }
.crow-key3:hover { background: oklch(94% 0.04 65); }
.crow-key3 .crow-l { color: oklch(34% 0.10 65); font-weight: 600; }
.crow-key3 .crow-v { color: oklch(34% 0.10 65); font-size: var(--fs-md); }
.cdiv {
  padding: 7px 20px; font-size: 9px; font-weight: 700;
  background: var(--paper-sunk); border-bottom: 1px solid var(--border-soft);
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em;
}

/* ── TABLES ────────────────────────────────────────────────────── */
.wf, .ptable, .sens {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden; margin-bottom: 22px;
  box-shadow: var(--shadow-xs);
}
.wf thead tr, .ptable thead tr, .sens thead tr {
  background: var(--paper-sunk);
}
.wf th, .ptable th, .sens th {
  padding: 10px 14px; font-size: 9px; font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-align: right;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.wf th:first-child, .ptable th:first-child, .ptable th:nth-child(2), .sens th:first-child {
  text-align: left;
}
.wf td, .ptable td {
  padding: 9px 14px; text-align: right;
  border-bottom: 1px solid var(--border-soft);
  font-size: var(--fs-xs); color: var(--text);
  font-variant-numeric: tabular-nums;
}
.wf td:first-child { text-align: left; color: var(--text-2); }
.wf tfoot td, .ptable tfoot td {
  font-weight: 700; background: var(--paper-sunk);
  border-top: 1px solid var(--border); border-bottom: none;
  text-align: right;
}
.wf tfoot td:first-child, .ptable tfoot td:first-child { text-align: left; color: var(--text); }
.wf .divrow td {
  background: var(--paper-2); font-size: 9px; font-weight: 700;
  color: var(--text-muted); padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.wf tr:last-child td, .ptable tr:last-child td { border-bottom: none; }
.wf tbody tr, .ptable tbody tr {
  transition: background var(--t-fast) var(--ease);
}
.wf tbody tr:hover, .ptable tbody tr:hover { background: var(--paper-2); }

/* ── WATERFALL: equal-width numeric columns, centered, tinted ──
   The waterfall has 6 columns: Step (label) + 5 numeric (Pool, LP,
   BPP, AGH, 3rd Party). table-layout:fixed plus an explicit colgroup
   isn't possible without changing the markup, so we use percentage
   widths via :nth-child to give the 5 numeric columns identical width
   and let the first column take the remaining space.

   Column tinting mirrors the partners-tab convention: green = LP,
   indigo = BPP, amber = AGH, slate = 3rd party. The Pool column gets
   a faint neutral tint so it reads as a "subtotal" lane. */
.wf { table-layout: fixed; }
.wf th, .wf td { overflow: hidden; text-overflow: ellipsis; }

/* Step column gets remaining width; numeric columns share equally. */
.wf th:nth-child(1), .wf td:nth-child(1) { width: auto; }
.wf th:nth-child(n+2), .wf td:nth-child(n+2) { width: 13%; }

/* Header: bigger, darker, centered for the numeric columns. */
.wf th {
  font-size: 11px;
  color: var(--text);
  text-align: center;
}
.wf th:first-child { text-align: left; }

/* Body cells: center the numbers, use one uniform dark color so the
   coloring comes from the column tint rather than the text. */
.wf td { text-align: center; color: var(--text); font-weight: 500; }
.wf td:first-child { text-align: left; color: var(--text-2); font-weight: 500; }
.wf tbody td.c-lp,
.wf tbody td.c-bpp,
.wf tbody td.c-agh,
.wf tfoot td.c-lp,
.wf tfoot td.c-bpp,
.wf tfoot td.c-agh { color: var(--text); font-weight: 600; }

/* Column tint backgrounds. Applied to th + td of the same nth-child so
   the tint runs the full height of the table including thead, tbody,
   and tfoot. Kept very subtle so the data still reads first. */
.wf th:nth-child(2), .wf td:nth-child(2) { background: oklch(97.5% 0.008 260 / 0.6); }   /* Pool — neutral */
.wf th:nth-child(3), .wf td:nth-child(3) { background: oklch(96% 0.030 165 / 0.45); }    /* LP — green */
.wf th:nth-child(4), .wf td:nth-child(4) { background: oklch(95% 0.040 268 / 0.40); }    /* BPP — indigo */
.wf th:nth-child(5), .wf td:nth-child(5) { background: oklch(96% 0.040 70  / 0.50); }    /* AGH — amber */
.wf th:nth-child(6), .wf td:nth-child(6) { background: oklch(96% 0.012 250 / 0.55); }    /* 3rd party — slate */

/* Footer total row keeps the tint but slightly darker to anchor it. */
.wf tfoot td:nth-child(2) { background: oklch(94% 0.010 260 / 0.7); }
.wf tfoot td:nth-child(3) { background: oklch(92% 0.040 165 / 0.55); }
.wf tfoot td:nth-child(4) { background: oklch(91% 0.050 268 / 0.50); }
.wf tfoot td:nth-child(5) { background: oklch(92% 0.050 70  / 0.55); }
.wf tfoot td:nth-child(6) { background: oklch(92% 0.014 250 / 0.65); }
.wf tfoot td { color: var(--text); }

/* Section divider rows span all 6 columns, so suppress the column
   tint and ellipsis so they read as a single banded heading. */
.wf .divrow td { background: var(--paper-2); text-align: left; }

.c-lp  { color: oklch(38% 0.13 165); font-weight: 600; }
.c-bpp { color: var(--indigo-2); font-weight: 600; }
.c-agh { color: oklch(34% 0.10 65); font-weight: 600; }

.ptable td:first-child { text-align: left; font-weight: 600; }
.ptable td:nth-child(2) { text-align: left; font-size: var(--fs-2xs); color: var(--text-muted); font-weight: 400; }
.ptable .sec-row td {
  background: var(--paper-2); font-size: 9px; font-weight: 700;
  color: var(--text-muted); padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.ptable tr.spotlight td {
  background: var(--amber-soft) !important;
  box-shadow: inset 3px 0 0 var(--amber);
}
.th-sub { font-size: 9px; font-weight: 400; color: var(--text-faint); text-transform: none; letter-spacing: 0; }

/* Partner cards */
.p-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px; margin-bottom: 22px;
}
.p-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden;
  transition: all var(--t) var(--ease);
}
.p-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.p-card.spotlight {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px -10px oklch(60% 0.14 65 / 0.45);
  border-color: var(--amber);
}
.p-card.dim { opacity: 0.4; }
.p-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.p-name {
  font-family: var(--font-display);
  font-size: var(--fs-md); font-weight: 700;
  letter-spacing: -0.015em;
}
.p-row {
  display: flex; justify-content: space-between;
  padding: 6px 16px; font-size: var(--fs-2xs);
  border-bottom: 1px solid var(--border-soft);
  font-variant-numeric: tabular-nums;
}
.p-row:last-child { border-bottom: none; }
.p-l { color: var(--text-muted); }
.p-v { font-weight: 600; }
.p-total-row { background: var(--paper-sunk); }
.p-total-row .p-l { font-weight: 600; color: var(--text); font-size: var(--fs-xs); }
.p-total-v {
  font-size: var(--fs-xl); font-weight: 600;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}
.p-sub {
  padding: 7px 16px; font-size: 9px; color: var(--text-faint);
  background: var(--paper-sunk);
}

/* Spotlight panel */
.spot-panel {
  background: var(--surface);
  border: 1px solid var(--amber);
  border-radius: var(--r-lg);
  padding: 20px 24px; margin-bottom: 22px;
  display: none;
  box-shadow: var(--shadow);
  background: linear-gradient(135deg, var(--surface), var(--amber-soft));
}
.spot-panel.on { display: block; animation: fadeUp 280ms var(--ease); }
.spot-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
.spot-name {
  font-family: var(--font-display);
  font-size: var(--fs-2xl); font-weight: 700;
  letter-spacing: -0.025em; line-height: 1.1;
}
.spot-role { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }
.spot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.spot-fact {
  background: var(--surface);
  border: 1px solid var(--amber-line);
  border-radius: var(--r);
  padding: 12px 14px;
}
.spot-fact .l {
  font-size: 9px; color: oklch(36% 0.10 65);
  text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; margin-bottom: 4px;
}
.spot-fact .v {
  font-size: var(--fs-xl); font-weight: 600; color: var(--text);
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}
.spot-fact .s { font-size: 9px; color: var(--text-muted); margin-top: 2px; }

/* Entity income pools — stacked vertically inside the partners split */
.entity-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 0;
}
.entity-grid > div { width: 100%; }

/* Partners tab — left rail (ownership totals) + main table */
.partners-split {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 22px;
  align-items: start;
}
@media (max-width: 1100px) {
  .partners-split { grid-template-columns: 1fr; }
}
.entity-stack { display: flex; flex-direction: column; gap: 6px; }
.partners-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

/* Tight section header for the split layout */
.sec-tight { margin-top: 0; margin-bottom: 6px; }

/* Partner table column tinting */
.ptable-cols th.col-aghf,
.ptable-cols td.col-aghf { background: oklch(96% 0.04 70 / 0.55); color: oklch(40% 0.10 65); }
.ptable-cols th.col-aghs,
.ptable-cols td.col-aghs { background: oklch(94% 0.06 65 / 0.55); color: oklch(38% 0.13 65); font-weight: 600; }
.ptable-cols th.col-bppf,
.ptable-cols td.col-bppf { background: oklch(96% 0.03 280 / 0.55); color: oklch(42% 0.11 280); }
.ptable-cols th.col-bppc,
.ptable-cols td.col-bppc { background: oklch(94% 0.05 280 / 0.55); color: oklch(40% 0.14 280); font-weight: 600; }

/* Sensitivity */
.sens { font-size: var(--fs-2xs); }
.sens-legend {
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-bottom: 10px;
}
.sens td {
  padding: 7px 11px; text-align: center;
  border-bottom: 1px solid var(--border-soft);
  font-variant-numeric: tabular-nums;
}
.sens td:first-child { text-align: left; font-weight: 600; color: var(--text-2); }
.sens tr:last-child td { border-bottom: none; }
.s-strong { color: oklch(28% 0.16 158); font-weight: 800; background: oklch(86% 0.16 158 / 0.55); }
.s-hit    { color: oklch(32% 0.14 158); font-weight: 700; background: oklch(94% 0.085 158 / 0.7); }
.s-close  { color: oklch(38% 0.13 50);  font-weight: 600; background: var(--amber-soft); }
.s-miss   { color: oklch(45% 0.20 22);  background: var(--rose-soft); }

/* Current-deal cell: keep the IRR-tier color, add a strong cobalt outline
   + corner dot so the user can find "where am I" at a glance without
   recoloring the whole row/column. */
.s-current {
  position: relative;
  outline: 2px solid var(--indigo);
  outline-offset: -2px;
  box-shadow: 0 0 0 1px #fff inset;
  z-index: 1;
}
.s-current .s-dot {
  position: absolute; top: 4px; right: 4px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--indigo);
  box-shadow: 0 0 0 2px #fff;
}

.bar-wrap {
  position: relative; width: 100%; height: 300px;
  margin-bottom: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

/* Side-by-side residual pie + GP bar */
.charts-split {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 22px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .charts-split { grid-template-columns: 1fr; }
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column;
}
.pie-wrap {
  position: relative; width: 100%; height: 240px;
  margin: 4px 0 8px;
}
.alloc-legend-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.alloc-legend-stack .leg { font-size: var(--fs-xs); }
.alloc-legend-stack .leg-summary {
  margin-left: 0; margin-top: 4px;
  padding-top: 6px; border-top: 1px solid var(--border-soft);
  font-size: 10px;
}

.note {
  font-size: var(--fs-2xs); color: var(--text-muted);
  line-height: 1.7; margin-top: 22px;
  padding: 16px 20px;
  background: var(--paper-sunk);
  border-radius: var(--r);
  border: 1px solid var(--border-soft);
}

/* Toast */
.toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--ink); color: var(--ink-text);
  padding: 12px 20px; border-radius: var(--r);
  font-size: var(--fs-xs); font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000; opacity: 0; transform: translateY(8px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
  pointer-events: none;
  max-width: 380px;
}
.toast.on { opacity: 1; transform: translateY(0); }
.toast.err { background: oklch(35% 0.18 25); }

/* ── TYPOGRAPHY NORMALIZATION ──────────────────────────────────────
   Single typeface (Inter) across the whole interface. Any element
   that historically asked for --font-display falls back to Inter so
   weights 600/700 render properly and nothing inherits the editorial
   serif. */
.deal-name-input, .sb-brand, .cc-title, .p-name, .dash-v, .spot-name,
.lede-value, #authGate h2 {
  font-family: var(--font-sans);
}
.lede-value {
  font-weight: 700;
  letter-spacing: -0.025em;
}
#authGate h2 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Print */
@media print {
  .sidebar, .topbar, .tabs, .bar-wrap, .sb-actions, .toast { display: none !important; }
  .app { display: block !important; }
  .main { padding: 0; }
  .tab-panel { display: block !important; padding: 12px 0; page-break-inside: avoid; }
}

/* Mobile */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; min-height: 0; }
  .sb-list { max-height: 240px; }
  .topbar { padding: 12px 14px 0; }
  .tab-panel { padding: 16px 14px 32px; }
}

/* ── PHONE (< 640px) ────────────────────────────────────────────
   Collapsible sidebar, scrollable tab strip, single-column lede,
   right-sized auth gate, and tighter cost / sensitivity grids so
   nothing horizontally overflows on a phone in portrait. */
@media (max-width: 640px) {
  /* Auth gate: fill the screen properly, no fixed-width card overflow */
  #authGate { padding: 16px; gap: 10px; }
  #authGate .card { max-width: 100%; padding: 22px 18px; }
  #authGate h2 { font-size: 18px; }
  #authGate p  { font-size: 13px; }
  #authGate button { width: 100%; padding: 13px 18px; font-size: 15px; }

  /* Sidebar becomes a top sheet that the user can collapse to a thin rail
     so the simulator content gets actual screen real estate */
  .sidebar { border-right: none; border-bottom: 1px solid var(--ink-line); }
  .sidebar.collapsed { width: 100%; height: auto; }
  .sidebar.collapsed > :not(.sb-collapse) { display: none; }
  .sb-collapse {
    position: absolute; top: 10px; right: 10px;
    width: 32px; height: 32px;
    border-radius: var(--r-sm);
  }
  .sidebar.collapsed .sb-collapse svg { transform: rotate(90deg); }
  .sb-collapse svg { transform: rotate(-90deg); }
  .sb-list { max-height: 180px; }
  .sb-foot { display: none; }

  /* Topbar: drop heavy padding, single column, smaller LP IRR */
  .topbar { padding: 12px 12px 0; }
  .topbar-grid { gap: 12px; }
  .topbar-lede, .topbar-lede-compact {
    padding: 10px 14px;
    width: 100%;
  }
  .lede-value { font-size: clamp(28px, 9vw, 38px); }
  .deal-name-input { font-size: clamp(22px, 6vw, 28px); }
  .meta-strip { gap: 10px 14px; flex-wrap: wrap; }

  /* Tabs become a horizontally scrollable strip */
  .tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -14px;
    padding: 0 14px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex-shrink: 0;
    padding: 10px 12px;
    font-size: var(--fs-sm);
  }
  .tab-panel { padding: 14px 12px 28px; }

  /* KPI strip: 2 columns max on phones */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-v { font-size: clamp(16px, 5vw, 20px); }

  /* Cost grid: 2 cols max, tighter padding */
  .cost-box { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .cost-group { padding: 8px; }
  .cg-label { font-size: 11px; letter-spacing: 0.06em; }

  /* Dashboard cards stack */
  .dash-grid { grid-template-columns: 1fr; }

  /* Contract / partner grids stack */
  .contract-grid, .inputs-grid { grid-template-columns: 1fr !important; }

  /* Sensitivity table — let it scroll horizontally instead of squishing */
  .sens-wrap, .tab-panel:has(.sens) { overflow-x: auto; }
  .sens { min-width: 720px; font-size: 11px; }
  .sens th, .sens td { padding: 6px 8px; }
  .sens-legend { flex-wrap: wrap; gap: 6px; }

  /* AI insights tab full panel: tighter chrome */
  .ai-full { padding: 18px 14px 24px; border-radius: var(--r-md); }
  .ai-full-body { font-size: var(--fs-sm); line-height: 1.55; }
  .ai-full-body .ai-h { font-size: var(--fs-sm); margin: 16px 0 6px; }

  /* AI topbar panel: don't clamp height as aggressively */
  .ai-panel { max-height: 280px; padding: 10px 12px 12px; }

  /* Trash modal: fit tightly */
  .trash-card { width: 96vw; margin: 4vh auto 0; max-height: 88vh; }
  .trash-head { padding: 14px 16px 12px; }
  .trash-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .trash-row-actions { justify-content: flex-end; }

  /* Slider value-edit boxes don't overflow */
  .partner-row { flex-wrap: wrap; }

  /* Print / Save / New deal buttons stay full-width and tappable */
  .sb-actions button { padding: 12px 14px; font-size: var(--fs-sm); min-height: 44px; }
  .btn-ghost { padding: 9px 14px; min-height: 40px; }
}

/* Tablet sweep (641-900) — relax some rules introduced for phones */
@media (min-width: 641px) and (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  .cost-box { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}

/* ── DASHBOARD HEADLINE STATS ──────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.dash-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow-xs);
  transition: all var(--t) var(--ease);
}
.dash-stat:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.dash-l {
  font-size: var(--fs-2xs); font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.dash-v {
  font-family: var(--font-display);
  font-size: clamp(22px, 2.0vw, 30px);
  font-weight: 700; line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.dash-v.c-lp  { color: oklch(34% 0.13 165); }
.dash-v.c-bpp { color: var(--indigo-3); }
.dash-v.c-agh { color: oklch(32% 0.10 65); }
.dash-s {
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-top: 6px; line-height: 1.4;
}
.dash-s span { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── SENSITIVITY LEGEND CHIPS ──────────────────────────────────── */
.sens-legend {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-bottom: 14px;
}
.sens-key {
  display: inline-flex; align-items: center;
  font-size: var(--fs-2xs); font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid;
}
.sens-key-strong { background: oklch(86% 0.16 158 / 0.6); color: oklch(26% 0.16 158); border-color: oklch(70% 0.16 158); }
.sens-key-hit   { background: oklch(94% 0.085 158 / 0.8); color: oklch(32% 0.14 158); border-color: oklch(78% 0.12 158); }
.sens-key-close { background: var(--amber-soft); color: oklch(38% 0.12 50); border-color: var(--amber-line); }
.sens-key-miss  { background: var(--rose-soft);  color: oklch(40% 0.18 22); border-color: oklch(82% 0.10 22); }
.sens-key-note  { color: var(--text-faint); margin-left: auto; font-style: italic; }

/* Waterfall row helpers */
.wf-sub {
  font-size: 9px; color: var(--text-faint);
  margin-top: 2px; line-height: 1.3;
}
.wf tr.info td { background: var(--paper-2); color: var(--text-2); }
.wf tr.info td:first-child { font-style: italic; }

.wf-balance {
  margin-top: -12px; margin-bottom: 22px;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: var(--fs-xs); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.wf-balance .bc-ok {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  background: var(--sage-soft); color: oklch(34% 0.10 165);
  border: 1px solid var(--sage-line);
}
.wf-balance .bc-bad {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  background: var(--rose-soft); color: oklch(40% 0.15 25);
  border: 1px solid oklch(78% 0.12 25);
}

/* ── PARTNER OWNERSHIP EDITOR ──────────────────────────────────── */
.own-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
  gap: 10px;
  margin-bottom: 14px;
  justify-content: start;
}
.own-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast) var(--ease);
}
.own-card[data-state="bad"] { border-color: oklch(78% 0.12 25); }
.own-card[data-state="ok"]  { border-color: var(--sage-line); }

.own-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px;
  background: var(--paper-sunk);
  border-bottom: 1px solid var(--border-soft);
}
.own-title {
  font-size: var(--fs-sm); font-weight: 700;
  color: var(--text); letter-spacing: -0.005em;
}
.own-reset {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); border-radius: var(--r-sm);
  padding: 2px 8px; font-size: 10px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: all var(--t-fast) var(--ease);
}
.own-reset:hover { background: var(--paper-2); color: var(--text); border-color: var(--border-strong); }

.own-body { padding: 4px 10px; }
.own-row {
  display: grid;
  grid-template-columns: 9px 1fr 60px 14px;
  align-items: center; gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border-soft);
}
.own-row:last-child { border-bottom: none; }
.own-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dot, var(--text-faint));
}
.own-name-input {
  font-family: inherit;
  font-size: var(--fs-xs); font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 3px 6px;
  width: 100%;
  min-width: 0;
  transition: all var(--t-fast) var(--ease);
}
.own-name-input:hover {
  background: var(--paper-sunk);
  border-color: var(--border-soft);
}
.own-name-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--indigo);
  box-shadow: 0 0 0 2px var(--indigo-soft);
}
.own-name {
  font-size: var(--fs-xs); font-weight: 500;
  color: var(--text); display: flex; align-items: center; gap: 6px;
}
.own-name::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--dot, var(--text-faint)); flex-shrink: 0;
}
.own-input {
  width: 100%;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 3px 6px; font-size: 11px; font-weight: 600;
  text-align: right; background: var(--surface);
  font-family: inherit; color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: all var(--t-fast) var(--ease);
}
.own-input:hover { border-color: var(--border-strong); }
.own-input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-soft); }
.own-unit { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }

.own-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  background: var(--paper-sunk);
  border-top: 1px solid var(--border-soft);
}
.own-sum-l {
  font-size: 9px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.own-sum-v {
  font-size: var(--fs-sm); font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid;
}
.own-sum-v[data-state="ok"]  { background: var(--sage-soft);  color: oklch(34% 0.10 165); border-color: var(--sage-line); }
.own-sum-v[data-state="bad"] { background: var(--rose-soft);  color: oklch(40% 0.15 25);  border-color: oklch(78% 0.12 25); }




/* ── 1x3 sidebar action grid ──────────────────────────────────── */
.sb-actions-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.sb-actions-3 button { flex: none; min-width: 0; padding: 9px 6px; font-size: 12px; }
.sb-actions-3 button.primary { white-space: nowrap; }

/* ── DARK THEME ───────────────────────────────────────────────────
   Triggered when <html data-theme="dark"> is set. The sidebar already
   uses ink-* tokens so it stays the same; we only invert the paper
   surfaces and text tokens used by the main content. */
:root[data-theme="dark"] {
  --paper:         oklch(18%   0.025 260);
  --paper-2:       oklch(22%   0.028 260);
  --paper-sunk:    oklch(15%   0.022 260);
  --surface:       oklch(23%   0.026 260);
  --surface-warm:  oklch(24%   0.030 260);
  --border:        oklch(34%   0.025 260);
  --border-strong: oklch(45%   0.028 260);
  --border-soft:   oklch(28%   0.022 260);
  --text:          oklch(96%   0.012 250);
  --text-2:        oklch(86%   0.018 250);
  --text-muted:    oklch(72%   0.020 250);
  --text-faint:    oklch(58%   0.018 250);
  --indigo-soft:   oklch(28%   0.10  268 / 0.45);
  --indigo-line:   oklch(45%   0.12  268);
  --sage-soft:     oklch(28%   0.10  158 / 0.55);
  --sage-line:     oklch(45%   0.13  158);
  --amber-soft:    oklch(30%   0.10  60  / 0.45);
  --amber-line:    oklch(50%   0.14  60);
  --rose-soft:     oklch(30%   0.10  22  / 0.45);
}
:root[data-theme="dark"] .topbar {
  background:
    radial-gradient(ellipse 80% 70% at 30% 0%, oklch(28% 0.12 268 / 0.5) 0%, transparent 70%),
    var(--paper);
}
:root[data-theme="dark"] body { background: var(--paper); }
