/* ═══════════════════════════════════════════════════════════════
   print.css — @media print styles untuk semua halaman SBS
   Taruh di: static/print.css
   Include di semua template: <link rel="stylesheet" href="{{ url_for('static', filename='print.css') }}">
   ═══════════════════════════════════════════════════════════════ */

@media print {
    /* ── PAGE SETUP ── */
    @page {
        size: A4 landscape;
        margin: 8mm 10mm 12mm 10mm;
    }
    @page :first {
        margin-top: 14mm;
    }

    /* ── HIDE NON-PRINT ELEMENTS ── */
    .topbar,
    .toolbar,
    .tab-bar,
    .ms-wrap,
    .btn-apply,
    .btn-back,
    .btn-reset,
    .nav-link,
    .toggle-btn,
    .detail-row,
    .detail-overlay,
    .edit-modal-overlay,
    .edit-reason-modal-overlay,
    .period-select,
    .prod-pills,
    button,
    #page-loading-bar,
    .dfilter-btn,
    .edit-reason-btn,
    .edit-reason2-btn,
    .mech-item,
    .reloadExcel,
    [onclick],
    .ms-panel {
        display: none !important;
    }

    /* ── RESET BODY ── */
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    html, body {
        height: auto !important;
        overflow: visible !important;
        background: #fff !important;
        font-family: 'DM Sans', Arial, sans-serif;
        font-size: 8pt;
        color: #1e2329;
    }

    /* ── PRINT HEADER (appears on every page) ── */
    .print-header {
        display: block !important;
        position: running(header);
        background: #1a3a5c;
        color: white;
        padding: 5mm 10mm;
        font-size: 9pt;
        font-weight: bold;
    }
    @page { @top-center { content: element(header); } }

    /* ── CONTENT AREAS ── */
    .content-area,
    .su-content-area,
    .cg-content-area,
    .util-content,
    .content-wrap,
    .charts-grid {
        height: auto !important;
        overflow: visible !important;
        padding: 4mm 0 !important;
        min-height: unset !important;
    }

    /* ── TABLE CONTAINERS ── */
    .table-wrap,
    .table-card,
    .cg-table-section,
    .util-content .table-wrap {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    /* ── PAGE TITLE (print only) ── */
    .print-page-title {
        display: block !important;
        font-family: 'Syne', 'DM Sans', Arial, sans-serif;
        font-size: 13pt;
        font-weight: 800;
        color: #1a3a5c;
        margin-bottom: 2mm;
        border-bottom: 2pt solid #1a3a5c;
        padding-bottom: 2mm;
    }
    .print-meta {
        display: block !important;
        font-size: 7pt;
        color: #6b7280;
        margin-bottom: 4mm;
    }

    /* ── KPI SUMMARY TABLE ── */
    .summary-table,
    .kpi-table,
    .su-table,
    .cg-table,
    .util-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 7pt !important;
        page-break-inside: auto;
    }

    .summary-table thead th,
    .kpi-table thead th,
    .su-table thead th,
    .cg-table thead th,
    .util-table thead th {
        background-color: #1a3a5c !important;
        color: white !important;
        font-size: 6.5pt !important;
        padding: 3pt 5pt !important;
        border: 0.5pt solid #2d6a9f !important;
        white-space: nowrap;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    /* KPI group header colours */
    .summary-table thead tr:first-child th:nth-child(4),
    .summary-table thead tr:first-child th:nth-child(5),
    .summary-table thead tr:first-child th:nth-child(6) {
        background-color: #2e8b57 !important;
    }
    .summary-table thead tr:first-child th:nth-child(7),
    .summary-table thead tr:first-child th:nth-child(8),
    .summary-table thead tr:first-child th:nth-child(9) {
        background-color: #1a6ea8 !important;
    }
    .summary-table thead tr:first-child th:nth-child(10),
    .summary-table thead tr:first-child th:nth-child(11),
    .summary-table thead tr:first-child th:nth-child(12) {
        background-color: #c8960c !important;
    }
    .summary-table thead tr:first-child th:nth-child(13),
    .summary-table thead tr:first-child th:nth-child(14),
    .summary-table thead tr:first-child th:nth-child(15) {
        background-color: #c0582a !important;
    }
    .summary-table thead th.avg-th { background-color: #e6b800 !important; color: #1e2329 !important; }
    .summary-table thead th.util-th { background-color: #1a5276 !important; }

    .summary-table td,
    .kpi-table td,
    .su-table td,
    .cg-table td,
    .util-table td {
        padding: 2.5pt 4pt !important;
        border: 0.5pt solid #d1d9e0 !important;
        font-size: 7pt !important;
        vertical-align: middle !important;
    }

    /* Row backgrounds */
    .summary-table tr:nth-child(even) td,
    .kpi-table tr:nth-child(even) td,
    .su-table tr:nth-child(even) td,
    .cg-table tr:nth-child(even) td,
    .util-table tr:nth-child(even) td {
        background-color: #f5f7fa !important;
    }

    /* Region rows */
    .region-sep td,
    .region-row td {
        background-color: #e2eaf4 !important;
        color: #1a3a5c !important;
        font-weight: 700 !important;
        font-size: 7pt !important;
        padding: 3pt 5pt !important;
    }

    /* Grand total */
    .grand-row td,
    .grand-total-row td {
        background-color: #d4edda !important;
        font-weight: 700 !important;
        font-size: 7.5pt !important;
        border-top: 1.5pt solid #2e8b57 !important;
        position: static !important;
    }

    /* KPI colour cells */
    .pct-green  { background-color: #c6efce !important; color: #1a6e35 !important; font-weight: 700 !important; }
    .pct-yellow { background-color: #ffeb9c !important; color: #7a5a00 !important; font-weight: 700 !important; }
    .pct-red    { background-color: #ffc7ce !important; color: #9c0006 !important; font-weight: 700 !important; }
    .pct-x      { color: #9ca3af !important; }

    /* Status update pct bars — replace with text */
    .pct-bar-bg { display: none !important; }
    .pct-num, .prev-num { font-size: 7.5pt !important; font-weight: 700 !important; }
    .pct-num.good, .prev-num.good { color: #1e7e34 !important; }
    .pct-num.warn, .prev-num.warn { color: #b56d00 !important; }
    .pct-num.danger, .prev-num.danger { color: #c0392b !important; }
    .miss-cell { color: #c0392b !important; font-weight: 700 !important; text-decoration: none !important; }
    .ok-num { color: #2e8b57 !important; }
    .trend-badge { font-size: 6pt !important; }

    /* Creator group bars */
    .pct-mini-bar { display: none !important; }
    .pct-cell-wrap { justify-content: center !important; }
    .pct-leader-val { color: #1d4ed8 !important; font-weight: 700 !important; }
    .pct-nl-val { color: #b91c1c !important; font-weight: 700 !important; }
    .val-leader { color: #1d4ed8 !important; font-weight: 700 !important; }
    .val-nonleader { color: #b91c1c !important; font-weight: 700 !important; }
    .cg-badge { display: none !important; }

    /* Utilisasi */
    .achiev-good { color: #1e7e34 !important; font-weight: 700 !important; }
    .achiev-warn { color: #b56d00 !important; font-weight: 700 !important; }
    .achiev-bad  { color: #9c0006 !important; font-weight: 700 !important; background-color: #ffc7ce !important; }

    /* KPI Reason table */
    .reason-table { font-size: 6.5pt !important; }
    .reason-table th { font-size: 6pt !important; }
    .reason-table .reason-group-row td {
        background-color: #fff0f0 !important;
        color: #c0392b !important;
        font-weight: 700 !important;
    }
    .count-cell { color: #c0392b !important; text-decoration: none !important; cursor: default !important; }

    /* Tab content — show active only */
    .tab-content { display: none !important; }
    .tab-content.active { display: block !important; }

    /* KPI page tab content */
    .kr-content { height: auto !important; overflow: visible !important; }
    .split-view {
        display: flex !important;
        gap: 5mm !important;
        page-break-inside: avoid;
    }
    .split-left { flex: 1 !important; }
    .split-right { display: none !important; } /* hide chart on print */
    .kr-table-section {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }
    .kr-info-bar { margin-bottom: 2mm !important; }
    .kr-badge { font-size: 6.5pt !important; }

    /* Dashboard — hide charts, show summary */
    .chart-card { display: none !important; }

    /* Page breaks */
    .region-sep, .region-row { page-break-inside: avoid; }
    tr { page-break-inside: avoid; }
    thead { display: table-header-group; }

    /* CG chart */
    .cg-chart-card { display: none !important; }
    .cg-table-section { flex: 1 !important; }

    /* Util info bar */
    .util-infobar { margin-bottom: 2mm !important; }
    .period-badge, .product-badge {
        font-size: 7pt !important;
        padding: 1pt 5pt !important;
        border-radius: 3pt !important;
    }
}

/* ── PRINT-ONLY ELEMENTS (hidden in screen) ── */
.print-page-title,
.print-meta,
.print-header {
    display: none;
}