/* =============================================================================
   stage-memo.css — page styles for the Investment Memo (IM) stage.
   Loaded after controls.css + pages.css. Ported from mockup/html/styles.css,
   adapted to design tokens. Square corners, no drop shadows, colour only via
   custom properties.
   ========================================================================== */

/* ── hero grid ────────────────────────────────────────────────────────────── */

.memo-hero {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: var(--space-5);
}

.memo-hero__summary .panel__body {
  display: flex;
  flex-direction: column;
}

/* The "uploaded by …" label sits directly on the source DocChip otherwise. */
.memo-hero__summary .kicker {
  margin-bottom: var(--space-3);
}

.memo-hero__quote {
  margin-top: var(--space-4);
  font-size: 0.875rem;
  font-style: italic;
  line-height: 1.55;
  color: var(--text-primary);
}

/* ── toolbar / tabs ───────────────────────────────────────────────────────── */

.memo-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  /* Gap to the tab content below so the card isn't flush with the tabs --
   * matches .cmp-tabbar. Shared by the memo tabs + diligence readiness tabs. */
  margin-bottom: var(--space-4);
}
/* Inside a .subst readiness/substantiation wrapper the flex column-gap already
 * separates the toolbar from its content, so the margin would stack (48px).
 * Drop it there and let the wrapper's own rhythm (space-6) carry the gap. */
.subst .memo-toolbar { margin-bottom: 0; }

/* ── tab body ─────────────────────────────────────────────────────────────── */

.memo-tab {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.memo-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ── panels ───────────────────────────────────────────────────────────────── */

.memo-panel--flush > .panel__body { padding: 0; }
.memo-panel--mb { margin-bottom: var(--space-2); }
.memo-panel--mt { margin-top: var(--space-4); }

.memo-panel .panel__body > div {
  display: flex;
  flex-direction: column;
}

/* ── type ─────────────────────────────────────────────────────────────────── */

.memo-h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1.25;
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}

.memo-h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.3;
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}
.memo-h4--mt { margin-top: var(--space-2); }

/* Residual-risk card title row — title on the left, severity Badge pinned
 * to the right. The h4 keeps the margin-bottom; the row's own gap handles
 * the badge spacing. */
.memo-risk-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}
.memo-risk-head .memo-h4 { margin-bottom: var(--space-3); flex: 1; min-width: 0; }

.memo-body {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.memo-body--lg { font-size: 0.9375rem; }
.memo-body--sm { font-size: 0.8125rem; }
.memo-body--xs { font-size: 0.75rem; color: var(--text-muted); }
.memo-body--strong { color: var(--text-primary); }
.memo-body--mb { margin-bottom: var(--space-4); }
.memo-body--mt { margin-top: var(--space-2); }

.memo-caption--mt { margin-top: var(--space-1); }

.memo-note {
  margin-top: var(--space-3);
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.55;
}

.memo-context {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px dashed var(--hairline);
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.55;
}

.memo-sumline {
  margin-top: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  overflow-wrap: anywhere; /* long mono reconciliation strings must wrap, not overflow */
}

/* Capital-structure reconciliation header: basis caption, then the all-in
   amount as a stat with a status badge beside it, then the (often long)
   description as body prose — see composites MemoReconHead. */
.memo-recon { margin-bottom: var(--space-4); }
.memo-recon .caption { margin-bottom: var(--space-1); }
.memo-recon__figure {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.memo-stat {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  line-height: 1.2;
  margin-top: var(--space-1);
  color: var(--text-primary);
}
.memo-stat--lg { font-size: 1.125rem; margin-top: var(--space-2); }

.memo-inline-tag {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.memo-empty-line {
  padding: var(--space-5);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── grids ────────────────────────────────────────────────────────────────── */

.memo-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}
.memo-grid-2--gap { gap: var(--space-4); }
.memo-grid-2--wide { gap: var(--space-6); }

.memo-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

/* ── investment-summary metric grid ───────────────────────────────────────── */

.memo-metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
}
.memo-metric {
  border-top: 1px solid var(--hairline);
  padding: var(--space-3) var(--space-4) var(--space-3) 0;
}
/* Rules between rows only — strip the top edge of the first row (3 columns). */
.memo-metric:nth-child(-n + 3) {
  border-top: none;
}
.memo-metric__value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  margin-top: var(--space-2);
  color: var(--text-primary);
}

/* ── chip rows ────────────────────────────────────────────────────────────── */

.memo-chiprow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
/* A chip can carry a long prose "amount" from the platform (e.g. a full
   all-in-cost sentence) — let it wrap within the row instead of overflowing the
   panel as a giant non-wrapping pill. */
.memo-chiprow .badge { white-space: normal; max-width: 100%; }
/* The DD-IM hero carries a single prominent recommendation chip (not a dense
   metadata row) — the default badge padding (0.2em) reads as cramped there, so
   give it real breathing room. */
.memo-hero__summary .memo-chiprow .badge { padding: var(--space-2) var(--space-3); }

/* ── KV list ──────────────────────────────────────────────────────────────── */

.memo-kv-list {
  display: flex;
  flex-direction: column;
}
.memo-kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--hairline);
}
/* Dividers between rows only — not above the first row. */
.memo-kv:first-child {
  border-top: none;
}
/* In a two-column grid the :first-child guard only clears the left cell — the
   top-right cell is the first row too, so clear it as well. Restored at ≤960px
   (below), where the grid collapses to one column and it becomes a real row 2. */
.memo-grid-2 > .memo-kv:nth-child(2) {
  border-top: none;
}
.memo-kv__label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.memo-kv__value {
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ── tables ───────────────────────────────────────────────────────────────── */

.memo-table { margin-top: var(--space-3); }
.memo-table .table { width: 100%; }
/* Prose-heavy tables (sensitivities): cells hold paragraph-length text, so
   top-align every column and open the leading — middle-aligned prose reads as
   floating and the rows are tall enough that centring looks broken. */
.memo-table--prose .table__td { vertical-align: top; line-height: 1.55; }

/* ── closing-timeline sub-cards ───────────────────────────────────────────── */

.memo-subcard {
  background: var(--card-bg);
  border: 1px solid var(--hairline);
  padding: var(--space-4);
}
.memo-subcard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Reserve the status-badge height so a head with a badge (Signing) and one
     without (Closing) are the same height — otherwise the date row below sits
     a few px lower on the card that carries the badge. */
  min-height: 1.5rem;
  margin-bottom: var(--space-3);
}
.memo-subcard__val {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  margin-top: var(--space-1);
  color: var(--text-primary);
}

/* ── recommendation ───────────────────────────────────────────────────────── */

.memo-rec__head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

/* Stylized ordered list — a mono accent "01 02 03" marker. */
.memo-list {
  margin: var(--space-3) 0 0;
  padding-left: 0;
  list-style: none;
  counter-reset: memo-item;
  color: var(--text-secondary);
}
.memo-list__item {
  counter-increment: memo-item;
  position: relative;
  padding-left: var(--space-7);
  margin-bottom: var(--space-3);
  line-height: 1.5;
  font-size: 0.875rem;
}
.memo-list__item::before {
  content: counter(memo-item, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.1em;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent-emphasis);
}

/* ── card stacks ──────────────────────────────────────────────────────────── */

.memo-card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ── scenario table (Key numbers) ─────────────────────────────────────────── */

.memo-scenario-wrap { overflow-x: auto; }

.memo-scenario-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.875rem;
}
.memo-scenario-table th {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  text-align: center;
}
.memo-scenario-table__dim {
  width: 220px;
  text-align: left !important;
}
.memo-scenario-table__col.is-primary {
  background: color-mix(in srgb, var(--accent-emphasis) 6%, transparent);
}
.memo-scenario-table__tag { margin-left: var(--space-2); }
.memo-scenario-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
  text-align: center;
  color: var(--text-primary);
}
.memo-scenario-table tr:last-child td { border-bottom: 0; }
.memo-scenario-table__rowhead {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left !important;
}
.memo-scenario-table__cell.is-primary {
  background: color-mix(in srgb, var(--accent-emphasis) 4%, transparent);
}
.memo-scenario-table__cell.is-irr {
  font-family: var(--font-display);
  font-weight: 700;
}
.memo-scenario-table__cell.is-irr-primary { color: var(--accent-emphasis); }

.memo-scenario-foot {
  padding: var(--space-5);
  border-top: 1px solid var(--hairline);
  background: var(--menu-bg);
}
.memo-scenario-driver {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--hairline);
}
.memo-scenario-driver .memo-note { margin-top: 0; }

/* ── operating snapshot ───────────────────────────────────────────────────── */

/* ── key assumptions ──────────────────────────────────────────────────────── */

.memo-assumptions {
  display: flex;
  flex-direction: column;
}
.memo-assumption {
  padding: var(--space-5);
  border-top: 1px solid var(--hairline);
}
.memo-assumptions .memo-assumption:first-child { border-top: 0; }
.memo-assumption__head { margin-bottom: var(--space-3); }
/* The basis renders as a MemoBlock; give it breathing room from the
 * assumption text above so the two don't collide. */
.memo-assumption .memo-block { margin-top: var(--space-3); }

/* Counterparty concerns now render through the shared MemoLabeledItem
 * (memo-item-list / memo-item) -- same as workstreams + contractual. */

/* ── IC checklist ─────────────────────────────────────────────────────────── */

.memo-checklist__head,
.memo-checklist__row {
  display: grid;
  grid-template-columns: 120px 1fr 140px;
  /* Item text and the status badge sit in adjacent columns; without a gap
   * the badge butts right up against the item prose. space-4 matches the
   * row's vertical padding so the table reads consistently spaced. */
  gap: var(--space-4);
}
.memo-checklist__head {
  padding: var(--space-3) var(--space-5);
  background: var(--menu-bg);
  border-bottom: 1px solid var(--hairline);
}
.memo-checklist__col {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.memo-checklist__col--right { text-align: right; }
.memo-checklist__row {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--hairline);
  align-items: start;
}
.memo-checklist__row:first-of-type { border-top: 0; }
.memo-checklist__status { text-align: right; }
.memo-checklist__block {
  padding: var(--space-5);
  border-top: 1px solid var(--hairline);
}
.memo-checklist__block--alt { background: var(--menu-bg); }

/* ── labelled item list (workstreams · contractual execution) ─────────────────
   A bold label with a status/priority badge pinned to the top-right -- whatever
   the label length -- then body lines. Shared via MemoLabeledItem (composites).
   The badge no longer wraps below long labels the way the old space-between
   header did. */
.memo-item-list {
  display: flex;
  flex-direction: column;
  margin-top: var(--space-2);
}
.memo-item {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--hairline);
}
.memo-item:first-child { border-top: 0; }
.memo-item__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.memo-item__label { flex: 1; min-width: 0; color: var(--text-primary); font-size: 0.875rem; }
.memo-item__head > .badge { flex: none; }

/* MemoBlock -- a labelled prose block. The kicker heads its text as a block
 * (never an inline tag), so long prose reads cleanly. Shared by the assumption
 * Basis and the contractual-execution Risk line. */
.memo-block .kicker { display: block; margin-bottom: var(--space-1); }

/* ── key counterparties ───────────────────────────────────────────────────── */

.memo-counterparty-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-6);
  row-gap: var(--space-5);
}
/* memo-panel flexes its direct div children (.panel__body > div); the
   counterparty directory must stay a grid, so out-specify that. */
.memo-panel .panel__body > .memo-counterparty-grid { display: grid; }

/* ── responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .memo-hero { grid-template-columns: 1fr; }
  .memo-grid-3,
  .memo-grid-2,
  .memo-counterparty-grid { grid-template-columns: 1fr; }
  .memo-checklist__head,
  .memo-checklist__row { grid-template-columns: 90px 1fr; }
  .memo-checklist__col--right,
  .memo-checklist__status { display: none; }
  .memo-kv { grid-template-columns: 1fr; gap: var(--space-1); }
  /* single column — the top-right cell is a real second row again. */
  .memo-grid-2 > .memo-kv:nth-child(2) { border-top: 1px solid var(--hairline); }
}

/* "Generate from diligence" — Flow B option below the memo upload card. */
.memo-gendd { margin-top: var(--space-4); }
.memo-gendd__body { display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-start; }
.memo-gendd__blocked { display: flex; flex-direction: column; gap: var(--space-2); }
.memo-gendd__link { color: var(--accent); text-decoration: none; }
.memo-gendd__link:hover { text-decoration: underline; }
