/* ════════════════════════════════════════════════════════════════════
   Report tab — builder sidecar + dual-pane preview (visual + .tex source)
   ════════════════════════════════════════════════════════════════════ */

/* ── Newsletter — fund "cover sheet" above the valuation doc builder ──
   The cover itself is `.liveov-summary` (styled in live-overview.css) —
   a portrait fact sheet, so cap its width rather than letting the
   stacked label/value tables span the full card. */
.report-newsletter {
  margin-bottom: 16px;
}
.report-newsletter-sub {
  margin-bottom: 12px;
}
/* Cover-date strip (Live + EOM snapshots) — box + button styles come from
   .liveov-pb-tabs / .report-cover-tab in live-overview.css; here we just
   pin its width to the cover column beneath so the two read as one unit.
   Overflow-x scrolls once the month list outgrows the cap. */
.report-newsletter .report-cover-tabs {
  max-width: 380px;
  margin: 10px 0 12px;
}
.report-newsletter-cover {
  max-width: 380px;
}

/* Two covers side by side — USD fund cover + BTC share class cover.
   Each keeps the single-cover width; the pair wraps to stacked cards
   when the viewport can't fit both. */
.report-cover-pair {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.report-cover-pair > .report-newsletter-cover {
  flex: 1 1 320px;
}

/* Covers on the left, the overview's Monthly Performance Net tables on the
   right (every cover figure is computed from those cells). The tables keep
   the overview's own .liveov-mp-block markup, so they size and stack exactly
   as the strip does; the column drops below the covers when the card can't
   hold both. */
.report-cover-row {
  display: flex;
  gap: 16px 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.report-cover-row > .report-cover-pair {
  flex: 0 1 776px;
  min-width: 0;
}
.report-cover-tables {
  flex: 1 1 560px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.report-cover-tables > .liveov-mp-block + .liveov-mp-block {
  border-top: 0;
}

/* BTC share class cover — bitcoin-orange tint over the shared summary
   chrome. Accents only (titles, rules, card wash): the value cells keep
   the standard mono/pos/neg colors so the two covers read as siblings. */
.liveov-summary--btc {
  background: color-mix(in srgb, #f7931a 8%, var(--surface-tinted));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #f7931a 32%, transparent);
}
.liveov-summary--btc .liveov-sum-title {
  color: #f7931a;
}
.liveov-summary--btc .liveov-sum-head {
  border-bottom-color: color-mix(in srgb, #f7931a 38%, transparent);
}
.liveov-summary--btc .liveov-sum-copy:hover {
  border-color: #e8820c;
  color: #e8820c;
}
/* Light theme needs the deeper orange for contrast on the pale wash. */
:root[data-theme="light"] .liveov-summary--btc .liveov-sum-title {
  color: #e8820c;
}

.report-shell {
  display: grid;
  /* Builder is wide enough that the preview pane shrinks to roughly an
     A4-page width on common laptop screens. */
  grid-template-columns: 460px 1fr;
  gap: 16px;
  align-items: stretch;
  /* Definite height (not min-height) so the inner preview panes can
     constrain their overflow. .main is the page-level scroll container,
     so if we let the shell grow with content the WHOLE page scrolls and
     the preview wraps never trigger their own scrollbars. */
  height: calc(100vh - 180px);
  min-height: 560px;
}
/* Grid items must opt out of the default min-width:auto so the 1fr
   preview track can shrink (and the inner iframe + table-scroll wraps
   actually engage their overflow) rather than letting wide preview
   content push the whole shell past the viewport. */
.report-shell > * { min-width: 0; min-height: 0; }
@media (max-width: 1200px) {
  .report-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    /* At portrait widths, drop the fixed shell height. With
       `height: calc(100vh - 180px)` the preview row got `1fr` of whatever
       remained after the builder card's content height — on short
       viewports that was ~0px and the preview vanished entirely. */
    height: auto;
    min-height: 0;
  }
}

.report-sidecar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Shell locks height to viewport so the preview pane can constrain
     its own scroll. The builder column has more vertical content than
     fits at 720p and below — without overflow handling here, fields and
     buttons spill out the bottom of the card. Confine the scroll to the
     sidebar so the bento boundary is always honored. */
  min-height: 0;
  overflow-y: auto;
}
/* Drop the in-card scrollbar once the shell stops height-locking
   (≤1200px the shell goes auto-height, so the page itself scrolls and
   a nested scrollbar is just visual noise). */
@media (max-width: 1200px) {
  .report-sidecar { overflow-y: visible; }
}
.report-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.report-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 500;
}
.report-fields input[type="text"],
.report-fields textarea {
  background: var(--input);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  text-transform: none;
  letter-spacing: 0;
}
.report-fields input[type="text"]:focus,
.report-fields textarea:focus { outline: none; border-color: var(--ring); }
.report-fields textarea { resize: vertical; min-height: 64px; }

.report-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
/* Toggle pills. The .cb-chip pattern is reused from the deal-card form,
   but here we override the .report-fields label parent so the chips
   render as proper inline pills with the indicator beside the text. */
.report-toggles .cb-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 10px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  text-transform: none;
  letter-spacing: 0;
  flex-direction: row;        /* override parent flex-column */
  transition: background .15s, border-color .15s, color .15s;
}
.report-toggles .cb-chip:hover {
  border-color: var(--border-strong);
  color: var(--foreground);
}
.report-toggles .cb-chip input[type="checkbox"] {
  /* Hide native control, keep it focusable for keyboard accessibility. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  pointer-events: none;
}
.report-toggles .cb-chip::before {
  content: '';
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  background: transparent;
  background-position: center;
  background-size: 70% 70%;
  background-repeat: no-repeat;
  transition: background-color .15s, border-color .15s, background-image .15s;
}
.report-toggles .cb-chip:has(input:checked) {
  background: var(--accent);
  border-color: var(--border-strong);
  color: var(--foreground);
}
.report-toggles .cb-chip:has(input:checked)::before {
  background-color: var(--foreground);
  border-color: var(--foreground);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%230d0d0d' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 8 7 12 13 4'/></svg>");
}
.report-toggles .cb-chip:focus-within {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
/* Light theme: --foreground flips dark, so the box flips too. The check
   stroke must flip to white to stay readable on the dark fill. */
:root[data-theme="light"] .report-toggles .cb-chip:has(input:checked)::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 8 7 12 13 4'/></svg>");
}

.report-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.report-actions .primary { grid-column: 1 / -1; }
.report-actions button[disabled] { opacity: .45; cursor: not-allowed; }

/* External-link affordance on the Overleaf button. */
#rep-overleaf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
#rep-overleaf .ico-external {
  width: 13px;
  height: 13px;
  opacity: 0.75;
  transition: opacity .15s, transform .15s;
}
#rep-overleaf:hover .ico-external {
  opacity: 1;
  transform: translate(1px, -1px);
}

/* Stale-preview indicators — same amber as .deal-card.dirty */
button#rep-render.stale {
  background: var(--status-dev);
  color: #1a1a1a;
  box-shadow: 0 0 0 1px rgba(248, 168, 0, 0.5), 0 0 12px rgba(248, 168, 0, 0.25);
}
button#rep-render.stale::before {
  content: "● ";
  letter-spacing: 0;
}

.report-engine {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  line-height: 1.45;
}
.report-engine.warn {
  border-color: rgba(255, 170, 60, .55);
  background: rgba(255, 170, 60, .08);
  color: var(--foreground);
}
.report-engine code {
  background: var(--input);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.report-error {
  background: rgba(255, 80, 80, 0.10);
  border: 1px solid rgba(255, 80, 80, 0.40);
  color: #ff8080;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 240px;
  overflow: auto;
}

.report-preview-card {
  display: flex;
  flex-direction: column;
  /* Allow the card to shrink below its content size so the inner wraps'
     overflow actually engages instead of stretching the whole shell taller. */
  min-height: 0;
  position: relative;
  transition: border-color .15s, box-shadow .15s;
}
.report-preview-card.stale {
  border-color: var(--status-dev);
  box-shadow: 0 0 0 1px var(--status-dev), 0 0 24px rgba(248, 168, 0, 0.25);
}
.report-preview-card.stale::after {
  content: "● Inputs changed — click Render Preview to refresh";
  position: absolute;
  top: 14px;
  right: 18px;
  background: var(--status-dev);
  color: #1a1a1a;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* Two-pane preview: visual render on the left, .tex source on the right. */
.report-preview-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1;
  margin-top: 12px;
  min-height: 0;
}
.report-preview-split > * { min-width: 0; min-height: 0; }
@media (max-width: 1400px) {
  .report-preview-split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}
@media (max-width: 1200px) {
  .report-preview-split {
    grid-template-rows: 70vh 70vh;
  }
}

/* Source pane: positioned frame holds the pre + floating copy button. */
.report-source-frame {
  position: relative;
  width: 100%;
  max-width: 720px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.report-copy-btn {
  position: absolute;
  top: 10px;
  right: 22px;
  z-index: 3;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--muted-foreground);
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: color .15s, background .15s, border-color .15s, transform .1s;
}
.report-copy-btn:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--border-strong);
  color: var(--foreground);
}
.report-copy-btn:active { transform: scale(0.94); }
.report-copy-btn svg { width: 15px; height: 15px; }
.report-copy-btn .ico-check { display: none; }
.report-copy-btn.copied {
  color: var(--profit);
  border-color: rgba(81, 193, 72, 0.35);
  background: rgba(81, 193, 72, 0.10);
}
.report-copy-btn.copied .ico-copy  { display: none; }
.report-copy-btn.copied .ico-check { display: block; }
:root[data-theme="light"] .report-copy-btn {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.10);
}
:root[data-theme="light"] .report-copy-btn:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(0, 0, 0, 0.20);
}

.report-source-page {
  margin: 0;
  width: 100%;
  flex: 1;
  /* As a flex item the pre defaults to min-height:auto, which means
     "at least content tall". With ~28KB of LaTeX, that defeats the
     height clamp and overflow:auto never engages. min-height:0 lets the
     explicit flex sizing win. */
  min-height: 0;
  overflow: auto;
  padding: 22px 26px;
  background: #161618;
  color: var(--foreground);
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.report-source-page::-webkit-scrollbar { width: 10px; }
.report-source-page::-webkit-scrollbar-track { background: transparent; }
.report-source-page::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 2px solid #161618;
}
.report-source-page::-webkit-scrollbar-thumb:hover { background: var(--muted-foreground); }
:root[data-theme="light"] .report-source-page::-webkit-scrollbar-thumb { border-color: #fafafa; }
:root[data-theme="light"] .report-source-page {
  background: #fafafa;
  color: #1a1a1a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.12);
}
/* Lightweight LaTeX syntax tinting — applied by JS via <span> wrappers. */
.report-source-page .tex-cmd     { color: #6cb1ff; }
.report-source-page .tex-arg     { color: #b29bff; }
.report-source-page .tex-comment { color: var(--muted-foreground); font-style: italic; }
.report-source-page .tex-math    { color: #ffc07a; }
:root[data-theme="light"] .report-source-page .tex-cmd  { color: #1a4fb0; }
:root[data-theme="light"] .report-source-page .tex-arg  { color: #6c3eb5; }
:root[data-theme="light"] .report-source-page .tex-math { color: #b8651e; }

/* Themed canvas — the surface the "page" sits on. */
.report-iframe-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 20px;
  background: var(--muted);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
  transition: border-color .15s, box-shadow .15s;
}
.report-iframe-wrap[data-pane="visual"] {
  align-items: stretch;
  overflow: hidden;
}
.report-iframe-wrap[data-pane="source"] {
  align-items: stretch;
  overflow: hidden;
}
:root[data-theme="light"] .report-iframe-wrap {
  background: #e6e6ea;
}

.report-iframe {
  width: 100%;
  max-width: 720px;
  height: 100%;
  border: 0;
  border-radius: 4px;
  /* Match the rendered preview's --page-bg per theme. The iframe element's
     own background shows through the (transparent) scrollbar track, so a
     hardcoded #fff would reveal a white sliver in the gutters in dark mode. */
  background: #0d0d0d;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  /* Hidden until a PDF is loaded; the empty state takes the spotlight. */
  display: none;
}
:root[data-theme="light"] .report-iframe {
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.12);
}
.report-iframe.loaded { display: block; }

.report-iframe-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  color: var(--muted-foreground);
  padding: 24px;
}
.report-iframe.loaded ~ .report-iframe-empty { display: none; }
.report-empty-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--foreground);
}
