/* ==================== css/lab-stats-print.css ====================
 * Print-only styles for Embryology Lab Statistics (Tab 113).
 * Active only when the user prints (window.print()) — controls page
 * breaks, hides UI chrome, renders cover & footer.
 * Linked via <link ... media="print">, so these rules never apply on screen.
 */

@page {
    size: A4 portrait;
    margin: 16mm 14mm 18mm 14mm;
}

@media print {
    /* ===== Hide the rest of the app =====
     * Scoped to .lab-stats-printing so this only fires during a Lab-Stats
     * export. Without the scope it would also hide #mainContent during the
     * medical-cert / consultation prints (and style.css's own
     * `body > *:not(#mainContent)` rule would likewise blank Lab Stats —
     * the two global print rules collide). #labStatsView is lifted to <body>
     * top by _doPdfExport so this rule reveals it. */
    body.lab-stats-printing > *:not(#labStatsView):not(.lab-stats-export-overlay) {
        display: none !important;
    }
    body, html {
        background: #fff !important;
        margin: 0;
        padding: 0;
    }
    /* Sidebar / topbar / nav — hide hard */
    .sidebar, #sidebar, .topBar, #topBar, .no-print, .lab-stats-topbar {
        display: none !important;
    }

    #labStatsView {
        background: #fff !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .lab-stats-root {
        max-width: 100% !important;
        padding: 0 !important;
        font-size: 11pt;
        color: #0f172a;
    }

    /* ===== Cover page ===== */
    .lab-stats-print-cover {
        display: flex !important;
        align-items: center;
        justify-content: center;
        height: 250mm;
        page-break-after: always;
        break-after: page;
    }
    /* Two-column cover: text on the left, Vita brand on the right. */
    .lab-stats-cover-inner {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 16mm;
        width: 100%;
        max-width: 170mm;
    }
    .lab-stats-cover-text {
        flex: 1 1 auto;
        max-width: 110mm;
    }
    .lab-stats-cover-brand {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .lab-stats-cover-logo {
        height: 40mm;
        width: auto;
    }
    .lab-stats-cover-title {
        font-family: 'Inter', -apple-system, sans-serif;
        font-size: 28pt;
        font-weight: 600;
        color: #1e3a5f;
        margin: 0 0 4mm;
        letter-spacing: -0.01em;
        line-height: 1.15;
    }
    .lab-stats-cover-subtitle {
        font-size: 11pt;
        color: #475569;
        margin-bottom: 10mm;
        letter-spacing: 0.04em;
    }
    .lab-stats-cover-meta {
        font-size: 10pt;
        color: #1e3a5f;
        line-height: 1.9;
        padding: 6mm 0;
        border-top: 1px solid #c4985e;
        border-bottom: 1px solid #c4985e;
    }
    .lab-stats-cover-meta-key {
        color: #94a3b8;
        font-size: 8.5pt;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        margin-right: 4mm;
    }

    /* ===== Header on every page (after cover) ===== */
    .lab-stats-header {
        margin: 0 0 8mm;
        padding: 0 0 4mm;
        border-bottom: 1px solid #c4985e;
    }
    .lab-stats-title {
        font-size: 18pt;
        color: #1e3a5f;
        margin: 0 0 1mm;
    }
    .lab-stats-subtitle {
        font-size: 9pt;
        color: #475569;
    }
    .lab-stats-logo {
        height: 14mm;
    }

    /* ===== Sections ===== */
    .lab-stats-section {
        margin-bottom: 6mm;
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .lab-stats-section-title {
        font-size: 14pt;
        color: #1e3a5f;
        margin: 0 0 3mm;
    }

    /* Force page break before key sections */
    .lab-stats-section[data-section="charts"]      { page-break-before: always; break-before: page; }
    .lab-stats-section[data-section="outcome"]     { page-break-before: always; break-before: page; }
    .lab-stats-section[data-section="agency-perf"] { page-break-before: always; break-before: page; }
    .lab-stats-section[data-section="audit-list"]  { page-break-before: always; break-before: page; }
    .lab-stats-section[data-section="methodology"] { page-break-before: always; break-before: page; }

    /* Audit-only print mode: hide cover, hide all other sections, audit becomes the lead. */
    body.lab-stats-printing-audit .lab-stats-print-cover { display: none !important; }
    body.lab-stats-printing-audit .lab-stats-section[data-section="audit-list"] {
        page-break-before: auto !important;
        break-before: auto !important;
    }
    body.lab-stats-printing-audit .lab-stats-audit-toolbar { display: none !important; }
    body.lab-stats-printing-audit .lab-stats-case-audit-table {
        font-size: 8.5pt;
    }
    body.lab-stats-printing-audit .lab-stats-case-audit-table th,
    body.lab-stats-printing-audit .lab-stats-case-audit-table td {
        padding: 1.5mm 2mm !important;
        /* Allow wrapping (vs the screen's nowrap) so a long patient name can
           never push the 11-col table past the landscape page edge. */
        white-space: normal !important;
        word-break: break-word;
    }
    body.lab-stats-printing-audit .lab-stats-case-audit-table tr {
        page-break-inside: avoid;
    }

    /* ===== KPI grid ===== */
    .lab-stats-kpi-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 4mm !important;
    }
    .lab-stats-kpi-card {
        padding: 5mm 4mm !important;
        border-color: #e2e8f0 !important;
        box-shadow: none !important;
        page-break-inside: avoid;
    }
    .lab-stats-kpi-label {
        font-size: 8pt;
        margin-bottom: 2mm;
    }
    .lab-stats-kpi-value {
        font-size: 22pt;
    }
    .lab-stats-kpi-denom {
        font-size: 8pt;
    }

    /* ===== Totals ===== */
    .lab-stats-totals-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        border-color: #e2e8f0 !important;
    }
    .lab-stats-total-cell {
        padding: 3mm 3mm !important;
        border-color: #e2e8f0 !important;
    }
    .lab-stats-total-cell:nth-child(4n) { border-right: none !important; }
    .lab-stats-total-cell:nth-child(8n) { border-right: 1px solid #e2e8f0 !important; }
    .lab-stats-total-label {
        font-size: 7.5pt;
    }
    .lab-stats-total-value {
        font-size: 14pt;
    }
    .lab-stats-total-hint {
        font-size: 7pt;
    }

    /* ===== Charts ===== */
    .lab-stats-charts-grid {
        grid-template-columns: 1fr !important;
        gap: 4mm !important;
    }
    .lab-stats-chart-card {
        page-break-inside: avoid;
        padding: 4mm !important;
        box-shadow: none !important;
    }
    .lab-stats-chart-title {
        font-size: 10pt;
        margin-bottom: 2mm;
    }
    .lab-stats-chart-wrap {
        height: 65mm !important;
    }

    /* ===== Agency table ===== */
    .lab-stats-agency-table-wrap {
        overflow: visible !important;
        box-shadow: none !important;
    }
    .lab-stats-agency-table {
        font-size: 8.5pt;
    }
    .lab-stats-agency-table th,
    .lab-stats-agency-table td {
        padding: 2mm 2mm !important;
    }
    .lab-stats-agency-table th {
        background: #f1f5f9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .lab-stats-agency-table tr {
        page-break-inside: avoid;
    }

    /* When printing, force-expand all agency detail rows */
    .lab-stats-agency-detail-row {
        display: table-row !important;
    }
    .lab-stats-expand-icon {
        display: none !important;
    }
    .lab-stats-expand-btn {
        cursor: default !important;
        pointer-events: none !important;
    }

    .lab-stats-detail-table {
        font-size: 8pt;
    }
    .lab-stats-detail-table th,
    .lab-stats-detail-table td {
        padding: 1.5mm 2mm !important;
    }

    /* ===== Audit ===== */
    .lab-stats-audit-block {
        page-break-inside: avoid;
        padding: 3mm 4mm !important;
        margin-bottom: 3mm !important;
        box-shadow: none !important;
    }
    .lab-stats-audit-list {
        font-size: 9pt;
    }
    .lab-stats-audit-list li {
        padding: 1mm 0 !important;
    }

    /* ===== Methodology ===== */
    .lab-stats-method-list {
        font-size: 9pt;
    }

    /* ===== Footer fixed on every page ===== */
    .lab-stats-print-footer {
        display: flex !important;
        justify-content: space-between;
        position: fixed;
        bottom: 4mm;
        left: 14mm;
        right: 14mm;
        font-size: 8pt;
        color: #94a3b8;
        letter-spacing: 0.06em;
        border-top: 1px solid #e2e8f0;
        padding-top: 2mm;
    }
    .lab-stats-print-footer-left {
        font-weight: 600;
        color: #c4985e;
        letter-spacing: 0.1em;
        text-transform: lowercase;
    }
    .lab-stats-print-footer-right {
        font-size: 7.5pt;
        text-transform: uppercase;
    }

    /* Hide export modal if it slipped through */
    .lab-stats-export-overlay {
        display: none !important;
    }

    /* Force colour-accurate printing of decorative bits */
    .lab-stats-supplement-badge,
    .lab-stats-audit-clean,
    .lab-stats-audit-block,
    .lab-stats-totals-row {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
