/* ════════════════════════════════════════════════════════════════════
   Analysis tab — picker + structured derivation panel.
   Sections (in DOM order): hero, .an-grid (Deal Terms / Schedule /
   Time Decay), derivation steps, tranche table.
   ════════════════════════════════════════════════════════════════════ */

.analysis-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.analysis-toolbar select {
  background: var(--input); color: var(--foreground);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px;
  min-width: 320px; font-family: var(--font-mono); font-size: 13px;
}
.analysis-toolbar select:focus { outline: none; border-color: var(--ring); }

#analysis-body .dot { color: var(--muted-foreground); margin: 0 4px; }

/* ── Hero ──────────────────────────────────────────────────────────── */
.an-hero {
  display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 24px;
  align-items: stretch;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.an-hero > * { min-width: 0; }
.an-hero-id { display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.an-hero-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Identity block — ONE big circular token icon on the left, ticker +
 * deal name stacked vertically to its right. The icon reads as the
 * dominant visual cue; the two text lines align to a shared baseline
 * of the icon. Inherits the .ticker-icon contract (circle frame, theme
 * backfill, obfuscation behaviour); only the size is overridden. */
.an-hero-idblock {
  display: flex; align-items: center; gap: 14px;
}
.an-hero-idtext {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.an-hero-ticker-icon {
  width: 56px; height: 56px;
  margin-right: 0;
}
.an-hero-ticker {
  font-family: var(--font-mono);
  font-size: 24px; font-weight: 700; letter-spacing: .04em;
  line-height: 1.05; text-transform: uppercase;
}

.an-hero-title {
  margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .02em;
  line-height: 1.2;
  color: var(--foreground);
}
.an-hero-meta {
  font-size: 11px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .08em;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
}
.an-hero-meta strong { color: var(--foreground); font-weight: 600; }
.an-hero-tags { display: flex; gap: 6px; flex-wrap: wrap; }
/* Hero actions row — sits below the tag row. Houses the "↗ Backtest"
   hand-off button (gated by run_calc). Reuses the .bt-link styling from
   the Positions table so the button reads as the same affordance. */
.an-hero-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.an-hero-kpis {
  display: grid;
  /* Auto-fit so adding/removing KPIs doesn't require breakpoint surgery —
     each tile claims ~170px and lines wrap when the container narrows. */
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.an-kpi {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.an-kpi-label {
  color: var(--muted-foreground); font-size: 10px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .1em;
}
.an-kpi-value {
  font-family: var(--font-mono); font-size: 18px; font-weight: 600;
  color: var(--foreground); font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.an-kpi-value.pos { color: var(--profit); }
.an-kpi-value.neg { color: var(--loss); }
/* Inline secondary stat next to the headline value (e.g. "+$X (+12% APR)").
   Matches the Overview's `.kpi-value .kpi-aux` rule so APR suffixes read
   the same on both surfaces. The `.an-kpi-value` rule gives 18px to the
   headline; without this scoped override the inline aux span would
   inherit the same size and overpower the dollar figure. */
.an-kpi-value .kpi-aux {
  display: inline-block; margin-left: 8px;
  font-size: 12px; font-weight: 500;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
/* `?` glyph nested inside the .kpi-aux parenthesised APR text on both
   the Analysis and Overview bentos — sized down a hair so it doesn't
   crowd the rate text it sits next to. */
.kpi-aux .hint {
  width: 12px; height: 12px;
  font-size: 8px;
  margin-left: 4px;
  vertical-align: 1px;
}
.an-kpi-sub {
  color: var(--muted-foreground); font-family: var(--font-mono);
  font-size: 11px; font-variant-numeric: tabular-nums;
}

/* Multi-row bentos (Deal Summary, Cumulative P&L) — rows live below the
   headline value and break down the components. The grid auto-fit on
   `.an-hero-kpis` lets a richer bento naturally claim 2 columns of width
   when the surrounding tiles are simpler — no manual span needed. */
.an-kpi-summary, .an-kpi-pnl {
  /* Span 2 grid tracks so the multi-row body doesn't squeeze. Falls back
     to 1 track at narrow widths via the auto-fit minmax above. */
  grid-column: span 2;
  min-width: 240px;
}
.an-kpi-summary-rows {
  margin-top: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.an-kpi-summary-row {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono); font-size: 12px;
  font-variant-numeric: tabular-nums;
  /* Lock row height so an inline OVR tag on the Effective-discount row
     doesn't make that row taller than the text-only Schedule row above
     it, and so the bento has identical height between override and
     non-override deals when flicking through /analysis. */
  min-height: 20px;
}
.an-kpi-summary-k {
  color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .06em; font-size: 10px;
}
.an-kpi-summary-v {
  color: var(--foreground);
  /* Inline-flex so an OVR badge can sit next to the numeric value without
     wrapping or distorting the row baseline. */
  display: inline-flex; align-items: center; gap: 6px;
}
.an-kpi-summary-v.warn { color: var(--warning, var(--foreground)); }

/* ── Section grid (Deal Terms / Schedule / Time Decay) ─────────────── */
.an-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; margin-bottom: 16px;
}
/* Grid items default to min-width:auto — without this, a section whose
   contents (e.g. a wide table or a Chart.js canvas) have a min-content
   width larger than 1fr will push the whole grid past the viewport. */
.an-grid > * { min-width: 0; min-height: 0; }
.an-section {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}
.an-section-full { margin-bottom: 16px; }
.an-section-title {
  margin: 0 0 14px;
  font-size: 11px; font-weight: 600;
  color: var(--foreground);
  text-transform: uppercase; letter-spacing: .12em;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.an-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.an-section-head .an-section-title {
  margin: 0; padding: 0; border: 0;
}
.an-section-meta {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--foreground); display: flex; align-items: center; gap: 4px;
  flex-wrap: wrap;
}

/* ── Definition list inside section cards ─────────────────────────── */
.an-dl {
  margin: 0; display: grid; grid-template-columns: 1fr; gap: 8px;
}
.an-dl > div {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.an-dl > div:last-child { border-bottom: 0; }
.an-dl dt {
  color: var(--muted-foreground); font-size: 11px;
  text-transform: uppercase; letter-spacing: .08em;
}
.an-dl dd {
  margin: 0; font-family: var(--font-mono);
  font-size: 13px; color: var(--foreground);
  font-variant-numeric: tabular-nums;
}

/* ── Time-decay progress bar ──────────────────────────────────────── */
/* The cliff marker needs to be readable on top of the warm-toned fill,
   so it's drawn as a high-contrast foreground bar with a thin contrasting
   inner line — works in both light and dark themes regardless of where
   along the gradient it falls. */
.an-progress { margin-bottom: 14px; }
.an-progress-track {
  position: relative; height: 10px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: visible;  /* let the cliff marker poke above/below the track */
}
.an-progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--otc-token), var(--chart-3));
  border-radius: 999px;
  transition: width .4s ease;
}
.an-progress-cliff {
  position: absolute; top: -4px; bottom: -4px;
  width: 4px;
  background: var(--foreground);
  border-radius: 1px;
  transform: translateX(-2px);
  box-shadow: 0 0 0 1px var(--background);
}
/* Vest tranche markers — dashed, narrower than the cliff bar so the cliff
   stays the dominant punctuation. The dashed style is implemented via a
   repeating gradient (border-style:dashed on a 1-2px wide element renders
   inconsistently across browsers). Track is 10px + 6px overhang = 16px
   tall; a 4px repeat (2px dash + 2px gap) yields 4 visible dashes. */
.an-progress-vest {
  position: absolute; top: -3px; bottom: -3px;
  width: 2px;
  transform: translateX(-1px);
  background-image: linear-gradient(
    to bottom,
    var(--foreground) 0 2px,
    transparent 2px 4px
  );
  background-size: 2px 4px;
  background-repeat: repeat-y;
  opacity: .6;
}
.an-progress-legend {
  margin-top: 10px; display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted-foreground);
}
.an-progress-legend span { display: inline-flex; align-items: center; gap: 6px; }
.an-progress-legend .sw {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  border: 1px solid var(--border-strong);
}
.an-progress-legend .sw.fill   {
  background: linear-gradient(90deg, var(--otc-token), var(--chart-3));
  border-color: transparent;
}
.an-progress-legend .sw.cliff  {
  background: var(--foreground);
  border-color: transparent;
}
.an-progress-legend .sw.vest {
  background-image: linear-gradient(
    to bottom,
    var(--foreground) 0 2px,
    transparent 2px 4px
  );
  background-size: 100% 4px;
  background-color: transparent;
  border-color: transparent;
  opacity: .6;
}
.an-progress-legend .sw.remain { background: var(--surface-elevated); }

/* ── Derivation steps ──────────────────────────────────────────────── */
.an-steps { display: flex; flex-direction: column; gap: 10px; }
.an-step {
  display: grid; grid-template-columns: 56px 1fr; gap: 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color .2s ease;
}
.an-step:hover { border-color: var(--border-strong); }
.an-step-num {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 600;
  color: var(--muted-foreground);
  letter-spacing: .04em;
  display: flex; align-items: flex-start; justify-content: center;
  border-right: 1px solid var(--border);
  padding-right: 12px;
}
.an-step-body { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.an-step-title {
  font-size: 11px; font-weight: 600;
  color: var(--foreground);
  text-transform: uppercase; letter-spacing: .12em;
}
.an-step-math {
  font-size: 14px;
  color: var(--foreground);
  overflow-x: auto; overflow-y: hidden;
  padding: 4px 0;
}
/* KaTeX inherits color via currentColor by default — make sure it follows
   the theme-aware --foreground rather than the browser default. The 1.31em
   bump (1.05em × 1.25) makes the rendered display math noticeably larger
   than the surrounding labels — the formula is the focus of each step. */
.an-step-math .katex { color: var(--foreground); font-size: 1.31em; }
.an-step-math .katex-display { margin: 0; }
.an-step-formula {
  font-family: var(--font-mono); font-size: 13px;
  color: var(--foreground); white-space: pre-wrap;
}
.an-step-note {
  color: var(--muted-foreground);
  font-size: 11px; font-style: italic;
  border-top: 1px dashed var(--border); padding-top: 6px;
}

.an-tranche-table { margin-top: 4px; }

/* ── Responsive ───────────────────────────────────────────────────── */
/* Hero KPI grid is auto-fit/minmax so it self-wraps; only the section
   grids and step layout need explicit breakpoint overrides. */
@media (max-width: 1280px) {
  .an-hero { grid-template-columns: 1fr; }
  .an-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .an-step { grid-template-columns: 1fr; }
  .an-step-num { border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 8px; justify-content: flex-start; }
}
