/* ═══════════════════════════════════════════════
   PRINT — Browser print styles
   Vector text, proper A4 pages, sharp charts,
   dark heros preserved, branded header/footer
   ═══════════════════════════════════════════════ */

@media print {
    /* ── Global page setup ── */
    @page {
        size: A4 portrait;
        margin: 18mm 14mm 22mm 14mm;
    }

    /* First page: less top margin (cover hero) */
    @page :first {
        margin-top: 10mm;
    }

    /* ── Force colors & backgrounds to print ── */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* ── Hide UI chrome ── */
    .topbar,
    .tabbar,
    .tabbar-user,
    .progress-strip,
    .empty-state,
    .loading-overlay,
    .premium-lock-overlay,
    .so-overlay,
    .so-panel,
    .save-modal-overlay,
    .no-credits-modal,
    .toast-notification,
    .skip-nav,
    .scroll-cue,
    .rob-hero-scroll-cue,
    .bench-hero-scroll-cue,
    .foot, .footer,
    footer,
    .rob-cta-strip,
    .verdict-hero-actions,
    .repr-upgrade-cta,
    .repr-premium-hint,
    .payment-banner,
    .avatar-dropdown,
    .metricsFab,
    #topbarSaveStrat,
    #newStrategyBtn,
    .topbar-actions {
        display: none !important;
    }

    /* ── Hide user panes (Account, Strategies, Portfolio) ── */
    .user-pane,
    #upane-account,
    #upane-strategies,
    #upane-portfolio,
    #upane-plan {
        display: none !important;
    }

    /* ── Reset body ── */
    html, body {
        overflow: visible !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    body {
        font-size: 9.5pt;
        line-height: 1.5;
        background: #fff !important;
        color: #1a1a1a !important;
    }

    /* ── Header height offset: remove fixed header offsets ── */
    :root {
        --header-h: 0px !important;
        --topbar-h: 0px !important;
    }

    /* ── Force all reveal animations to final state ── */
    .rv, .rv.vis,
    [class*="rd"] {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
        animation: none !important;
    }

    /* ── Remove all animations ── */
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }

    /* ── Show all report tab panes as a continuous flow ── */
    .tab-pane {
        display: block !important;
        opacity: 1 !important;
        transform: none !important;
        position: relative !important;
    }

    /* ═══ BRANDED HEADER — top of every page ═══ */
    main#main-content::before {
        content: 'SigmaGrid';
        display: block;
        font-family: 'Playfair Display', Georgia, serif;
        font-size: 13pt;
        font-weight: 700;
        color: #051C2C;
        padding: 0 0 10px 0;
        margin-bottom: 16px;
        border-bottom: 2px solid #051C2C;
        position: running(header);
    }

    /* ═══ PAGE BREAK — each major tab starts a new page ═══ */
    /* Each tab hero = new page (feels like flipping sections) */
    .hero,
    .dark-hero-section,
    .rob-hero,
    .bench-tab-hero,
    .eff-tab-hero,
    .verdict-hero,
    .trades-hero-section,
    #pane-hypothesis {
        page-break-before: always;
        break-before: page;
    }

    /* First hero: no page break */
    #pane-results .hero {
        page-break-before: auto;
        break-before: auto;
    }

    /* Keep these blocks together — never split mid-card */
    .section,
    .result-card,
    .expect-card,
    .rob-glass-card,
    .bench-col,
    .bp-h-row,
    .verdict-takeaway,
    .hyp-card,
    .bench-conclusion,
    .eff-narrative-card,
    .rob-mini-verdict,
    .resilience-stat,
    .spag-stat,
    .metric-strip,
    .metrics-strip,
    .stress-row,
    .evo-chart-wrap,
    .dist-chart-full,
    .spag-chart-full,
    .trades-chart-full,
    .bench-evo-chart,
    .eff-chart-full {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* ═══ HERO SECTIONS ═══ */
    .hero {
        min-height: auto !important;
        padding: 36px 40px !important;
    }

    .dark-hero-section {
        min-height: auto !important;
        padding: 40px !important;
        background: linear-gradient(170deg, #041828 0%, #051C2C 40%, #0A2E44 100%) !important;
        border-radius: 0 !important;
    }

    .rob-hero,
    .bench-tab-hero,
    .eff-tab-hero,
    .verdict-hero {
        min-height: auto !important;
        padding: 40px !important;
    }

    /* Ambient glows: hide (don't print well) */
    .rob-hero-ambient,
    .bench-tab-hero-ambient,
    .eff-tab-hero-ambient,
    .verdict-hero-ambient,
    .hero-ambient,
    .ambient-glow {
        display: none !important;
    }

    /* ═══ SECTION SPACING ═══ */
    .section {
        padding: 28px 0 !important;
    }

    /* ═══ CARDS — subtle print-friendly borders ═══ */
    .result-card,
    .rob-glass-card,
    .expect-card,
    .bench-conclusion,
    .eff-narrative-card,
    .rob-mini-verdict,
    .spag-stat,
    .resilience-stat,
    .hyp-card,
    .bp-howto,
    .trades-table-wrap {
        box-shadow: none !important;
        border: 1px solid #dde2e8 !important;
        border-radius: 8px !important;
    }

    /* ═══ CHARTS — high-res images from JS beforeprint ═══ */
    .print-chart-img {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        max-height: 320px !important;
        object-fit: contain;
        margin: 8px auto;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Hide original canvas when print image exists */
    .print-has-img canvas {
        display: none !important;
    }

    /* Chart containers: constrain */
    .evo-chart-wrap,
    .dist-chart-full,
    .spag-chart-full,
    .trades-chart-full,
    .bench-evo-chart,
    .eff-chart-full,
    .rob-mini-dist-chart {
        height: auto !important;
        max-height: 320px !important;
        overflow: visible !important;
    }

    /* ═══ TYPOGRAPHY — crisp vector text ═══ */
    .hero-title {
        font-size: 28pt !important;
        line-height: 1.15 !important;
    }
    .section-title {
        font-size: 16pt !important;
        margin-bottom: 12px !important;
    }
    .pnl-number {
        font-size: 32pt !important;
        line-height: 1.1 !important;
    }
    .dark-hero-title,
    .rob-hero-title,
    .bench-tab-hero-title,
    .eff-tab-hero-title {
        font-size: 24pt !important;
        line-height: 1.2 !important;
    }
    .verdict-grade-word {
        font-size: 48pt !important;
        filter: none !important;
        opacity: 1 !important;
    }

    /* Metric values: ensure tabular nums */
    .num, [class*="metric"] {
        font-variant-numeric: tabular-nums !important;
    }

    /* ═══ GAUGES — SVG prints cleanly ═══ */
    .rob-gauge-ring svg,
    .repr-gauge svg {
        filter: none !important;
    }
    .rob-gauge-ring,
    .repr-gauge {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* ═══ ANIMATED ELEMENTS — freeze at final state ═══ */
    .mk-bar-fill,
    .alloc-seg,
    .bp-h-track .bp-h-whisker,
    .bp-h-track .bp-h-box,
    .bp-h-track .bp-h-median,
    .bp-h-point,
    .confidence-marker,
    .expect-range-fill,
    .expect-range-median,
    .expect-range-you,
    .eff-rebal-bar-fill,
    .rob-glass-bar-fill,
    .bench-bar-fill {
        transition: none !important;
    }

    /* ═══ TABLES ═══ */
    .trades-table-wrap {
        overflow: visible !important;
    }
    .trades-table {
        min-width: 0 !important;
        font-size: 8pt !important;
        width: 100% !important;
    }
    .trades-table th,
    .trades-table td {
        padding: 6px 8px !important;
    }
    .trades-table thead {
        display: table-header-group;
    }
    .trades-table tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* ═══ LINKS — no URLs ═══ */
    a[href]::after { content: none !important; }

    /* ═══ GRIDS — fit A4 width ═══ */
    .bench-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 12px !important;
    }
    .rob-glass-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 12px !important;
    }
    .expect-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 12px !important;
    }
    .hero-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 24px !important;
    }
    .resilience-inner {
        grid-template-columns: 240px 1fr !important;
    }

    /* ═══ MISC PRINT FIXES ═══ */

    /* Confidence labels: readable on dark bg */
    .confidence-zone span {
        color: rgba(255,255,255,0.6) !important;
    }

    /* Rob card blur: remove locks */
    .repr-card-blur {
        display: none !important;
    }

    /* Stress table: fit */
    .stress-grid {
        gap: 8px !important;
    }

    /* Metric strips: fit nicely */
    .metric-strip,
    .metrics-strip {
        gap: 8px !important;
        flex-wrap: wrap !important;
    }

    /* Scrollable containers: show all */
    [style*="overflow-x"], [style*="overflow-y"],
    .overflow-auto, .overflow-x-auto {
        overflow: visible !important;
    }

    /* Tab separator lines between sections */
    .tab-pane + .tab-pane {
        border-top: 2px solid #E8ECF0;
        margin-top: 0;
    }
}

/* ═══ Screen: hide print-only elements ═══ */
.print-chart-img { display: none; }
