/* ════════════════════════════════════════════════════════════════════
   Charts — generic chart-grid layout, watermark, timeline header legend
   Per-chart logic (Chart.js styling, SVG drawing) lives in the JS modules.
   ════════════════════════════════════════════════════════════════════ */

.chart-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px;
  margin-bottom: 24px;
}
.chart-grid .span-2   { grid-column: span 2; }
.chart-grid .span-all { grid-column: 1 / -1; }
/* Pair two cards side-by-side at 50/50, taking the full grid width
   regardless of the parent column count. Matches gap with the parent
   so the visual rhythm stays consistent. */
.chart-grid .chart-pair {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
/* CSS-grid items default to `min-width: auto`, which means "at least as
   wide as the content's min-content size". With Chart.js canvases that
   resolves to whatever Chart.js last sized the bitmap to — so on the
   first paint at a narrower viewport the grid track refuses to shrink
   below the previous canvas width and the entire grid (and the page)
   overflow horizontally. Forcing min-width:0 lets 1fr actually do its
   job; Chart.js' responsive observer then reflows the canvas to fit.
   min-height:0 is the same fix for vertical flex/grid layouts that
   embed canvases. Apply at every level so a `.span-all` card or a
   `.chart-pair` nested grid get the same treatment. */
.chart-grid > *,
.chart-grid .chart-pair > * { min-width: 0; min-height: 0; }
/* Canvas heights live on .chart-wrap (inline style="height: …"). All charts
   set responsive:true + maintainAspectRatio:false in JS so Chart.js picks up
   the wrapper's pixel height as the canvas size. */
.chart-container, .chart-container * { cursor: crosshair !important; }

/* Spartan text watermark — one per chart, centered on the chart's bounding
   box. Mirrors AumChart/PnlChart in spartan-dashboard: an absolute pseudo-
   element inside the chart container, opacity .03 dark / .05 light. */
.chart-wrap, .svg-host, .tdd-donut-wrap { position: relative; min-width: 0; }
.chart-wrap > canvas, .svg-host > svg, .tdd-donut-wrap > canvas { position: relative; z-index: 1; }
.chart-wrap::before, .svg-host::before, .tdd-donut-wrap::before, .aum-hero::before {
  content: "";
  position: absolute; inset: 0;
  background: var(--watermark-svg) center center / min(450px, 70%) no-repeat;
  opacity: .03;
  pointer-events: none;
  z-index: 0;
}
:root[data-theme="light"] .chart-wrap::before,
:root[data-theme="light"] .svg-host::before,
:root[data-theme="light"] .tdd-donut-wrap::before,
:root[data-theme="light"] .aum-hero::before { opacity: .05; }

/* ── Timeline header legend ────────────────────────────────────────── */
.timeline-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px 12px;
  font-size: 11px; color: var(--muted-foreground);
}
.timeline-header .marker { display: inline-flex; align-items: center; gap: 6px; }
.timeline-header .marker-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.timeline-header .marker.today .marker-dot { background: var(--foreground); }
.timeline-header .marker.mtm   .marker-dot { background: var(--chart-3); }
.timeline-header .legend-row { display: inline-flex; align-items: center; gap: 14px; }
.legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--foreground); margin-right: 4px;
}
/* Unified with backtest sweep palette:
   cliff / pre-discount = OTC cyan, vest-with-discount = chart-3 amber. */
.legend-cliff     { background: var(--otc-cyan); }
.legend-vest-mtm  { background: var(--otc-cyan); opacity: .65; }
.legend-vest-disc { background: var(--chart-3); }
.legend-vest-past { background: var(--muted-foreground); }

/* Responsive: collapse to single column on narrow viewports. */
@media (max-width: 1280px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-grid .span-2,
  .chart-grid .span-all { grid-column: span 1; }
  .chart-grid .chart-pair { grid-template-columns: 1fr; }
}
