/* ============================================================
   Ativos/print.css  —  Impressão isolada dos painéis analíticos
   ============================================================ */

@media print {

    /* ── 1. Folha em paisagem ── */
    @page {
        size: landscape;
        margin: 1.2cm 1.5cm;
    }

    /* ── 2. Esconde TUDO ── */
    body * {
        visibility: hidden !important;
    }

    /* ── 3a. CAP ── */
    #painel-cap-analitico,
    #painel-cap-analitico * {
        visibility: visible !important;
    }
    #painel-cap-analitico {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3b. CAR ── */
    #painel-car-analitico,
    #painel-car-analitico * {
        visibility: visible !important;
    }
    #painel-car-analitico {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3c. Sumiram — só aparece quando body tem classe print-sumiram ── */
    body.print-sumiram #painel-insights-sumiram,
    body.print-sumiram #painel-insights-sumiram * {
        visibility: visible !important;
    }
    body.print-sumiram #painel-insights-sumiram {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3d. Queda — só aparece quando body tem classe print-queda ── */
    body.print-queda #painel-insights-queda,
    body.print-queda #painel-insights-queda * {
        visibility: visible !important;
    }
    body.print-queda #painel-insights-queda {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3e. ABC — só aparece quando body tem classe print-abc ── */
    body.print-abc #painel-insights-abc,
    body.print-abc #painel-insights-abc * {
        visibility: visible !important;
    }
    body.print-abc #painel-insights-abc {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 4. Esconde botões e elementos de UI ── */
    .btn-pdf,
    .btn-imprimir,
    #busca-fornecedor-cap,
    #resultados-busca-cap,
    #busca-cliente-car,
    #resultados-busca-car,
    .faixa-btn,
    .faixa-btn-ativo,
    .faixa-btn-car,
    .faixa-btn-car-ativo,
    .paginacao,
    .info-tabela-header,
    #btn-imprimir-sumiram,
    #btn-imprimir-queda,
    #btn-imprimir-abc,
    #btn-reset-print-sumiram,
    #btn-reset-print-queda,
    #btn-reset-print-abc {
        display: none !important;
        visibility: hidden !important;
    }

    /* ── 5. Tabela ocupa toda a largura ── */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 10px !important;
        table-layout: fixed !important;
    }

    /* ── 6. Larguras das colunas CAP (5 colunas) ── */
    #painel-cap-analitico table th:nth-child(1),
    #painel-cap-analitico table td:nth-child(1) { width: 12% !important; }
    #painel-cap-analitico table th:nth-child(2),
    #painel-cap-analitico table td:nth-child(2) { width: 42% !important; }
    #painel-cap-analitico table th:nth-child(3),
    #painel-cap-analitico table td:nth-child(3) { width: 13% !important; }
    #painel-cap-analitico table th:nth-child(4),
    #painel-cap-analitico table td:nth-child(4) { width: 13% !important; }
    #painel-cap-analitico table th:nth-child(5),
    #painel-cap-analitico table td:nth-child(5) { width: 20% !important; }

    /* ── 7. Larguras das colunas CAR (7 colunas) ── */
    #painel-car-analitico table th:nth-child(1),
    #painel-car-analitico table td:nth-child(1) { width: 11% !important; }
    #painel-car-analitico table th:nth-child(2),
    #painel-car-analitico table td:nth-child(2) { width: 30% !important; }
    #painel-car-analitico table th:nth-child(3),
    #painel-car-analitico table td:nth-child(3) { width: 10% !important; }
    #painel-car-analitico table th:nth-child(4),
    #painel-car-analitico table td:nth-child(4) { width: 8%  !important; }
    #painel-car-analitico table th:nth-child(5),
    #painel-car-analitico table td:nth-child(5) { width: 10% !important; }
    #painel-car-analitico table th:nth-child(6),
    #painel-car-analitico table td:nth-child(6) { width: 15% !important; }
    #painel-car-analitico table th:nth-child(7),
    #painel-car-analitico table td:nth-child(7) { width: 16% !important; }

    /* ── 8. Larguras Sumiram (9 colunas) ── */
    #painel-insights-sumiram table th:nth-child(1),
    #painel-insights-sumiram table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-sumiram table th:nth-child(2),
    #painel-insights-sumiram table td:nth-child(2) { width: 6%  !important; }
    #painel-insights-sumiram table th:nth-child(3),
    #painel-insights-sumiram table td:nth-child(3) { width: 24% !important; }
    #painel-insights-sumiram table th:nth-child(4),
    #painel-insights-sumiram table td:nth-child(4) { width: 14% !important; }
    #painel-insights-sumiram table th:nth-child(5),
    #painel-insights-sumiram table td:nth-child(5) { width: 14% !important; }
    #painel-insights-sumiram table th:nth-child(6),
    #painel-insights-sumiram table td:nth-child(6) { width: 10% !important; }
    #painel-insights-sumiram table th:nth-child(7),
    #painel-insights-sumiram table td:nth-child(7) { width: 9%  !important; }
    #painel-insights-sumiram table th:nth-child(8),
    #painel-insights-sumiram table td:nth-child(8) { width: 12% !important; }
    #painel-insights-sumiram table th:nth-child(9),
    #painel-insights-sumiram table td:nth-child(9) { width: 8%  !important; }

    /* ── 9. Larguras Queda (9 colunas) ── */
    #painel-insights-queda table th:nth-child(1),
    #painel-insights-queda table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-queda table th:nth-child(2),
    #painel-insights-queda table td:nth-child(2) { width: 5%  !important; }
    #painel-insights-queda table th:nth-child(3),
    #painel-insights-queda table td:nth-child(3) { width: 22% !important; }
    #painel-insights-queda table th:nth-child(4),
    #painel-insights-queda table td:nth-child(4) { width: 12% !important; }
    #painel-insights-queda table th:nth-child(5),
    #painel-insights-queda table td:nth-child(5) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(6),
    #painel-insights-queda table td:nth-child(6) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(7),
    #painel-insights-queda table td:nth-child(7) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(8),
    #painel-insights-queda table td:nth-child(8) { width: 11% !important; }
    #painel-insights-queda table th:nth-child(9),
    #painel-insights-queda table td:nth-child(9) { width: 8%  !important; }

    /* ── 10. Larguras ABC (9 colunas) ── */
    #painel-insights-abc table th:nth-child(1),
    #painel-insights-abc table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-abc table th:nth-child(2),
    #painel-insights-abc table td:nth-child(2) { width: 6%  !important; }
    #painel-insights-abc table th:nth-child(3),
    #painel-insights-abc table td:nth-child(3) { width: 28% !important; }
    #painel-insights-abc table th:nth-child(4),
    #painel-insights-abc table td:nth-child(4) { width: 17% !important; }
    #painel-insights-abc table th:nth-child(5),
    #painel-insights-abc table td:nth-child(5) { width: 17% !important; }
    #painel-insights-abc table th:nth-child(6),
    #painel-insights-abc table td:nth-child(6) { width: 13% !important; }
    #painel-insights-abc table th:nth-child(7),
    #painel-insights-abc table td:nth-child(7) { width: 7%  !important; }
    #painel-insights-abc table th:nth-child(8),
    #painel-insights-abc table td:nth-child(8) { width: 7%  !important; }
    #painel-insights-abc table th:nth-child(9),
    #painel-insights-abc table td:nth-child(9) { width: 5%  !important; }

    /* ── 11. Cabeçalhos coloridos ── */
    #painel-cap-analitico thead tr {
        background-color: #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-car-analitico thead tr {
        background-color: #1565C0 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-sumiram thead tr {
        background-color: #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-queda thead tr {
        background-color: #DD6B20 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-abc thead tr {
        background-color: #1D9E75 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    thead th {
        color: white !important;
        padding: 7px 10px !important;
        font-size: 9px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* ── 12. Linhas de grupo ── */
    .tr-grupo-print {
        background-color: #edf0ed !important;
        border-left: 3px solid #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .tr-grupo-print-car {
        background-color: #edf0ed !important;
        border-left: 3px solid #1565C0 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* ── 13. Não quebrar linhas no meio da página ── */
    tr { page-break-inside: avoid !important; }

    /* ── 14. Texto não cortado ── */
    td, th {
        overflow: visible !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    /* ── 15. Badges ── */
    .badge-aviso-print {
        background-color: #FAEEDA !important; color: #854F0B !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
        border-radius: 99px; padding: 1px 6px; font-size: 9px; font-weight: 700;
    }
    .badge-critico-print {
        background-color: #FDECEA !important; color: #A32D2D !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
        border-radius: 99px; padding: 1px 6px; font-size: 9px; font-weight: 700;
    }
}


@media print {

    /* ── 1. Folha em paisagem ── */
    @page {
        size: landscape;
        margin: 1.2cm 1.5cm;
    }

    /* ── 2. Esconde TUDO ── */
    body * {
        visibility: hidden !important;
    }

    /* ── 3a. CAP ── */
    #painel-cap-analitico,
    #painel-cap-analitico * {
        visibility: visible !important;
    }
    #painel-cap-analitico {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3b. CAR ── */
    #painel-car-analitico,
    #painel-car-analitico * {
        visibility: visible !important;
    }
    #painel-car-analitico {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3c. Clientes que Sumiram ── */
    #painel-insights-sumiram,
    #painel-insights-sumiram * {
        visibility: visible !important;
    }
    #painel-insights-sumiram {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3d. Clientes em Queda ── */
    #painel-insights-queda,
    #painel-insights-queda * {
        visibility: visible !important;
    }
    #painel-insights-queda {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 3e. Curva ABC ── */
    #painel-insights-abc,
    #painel-insights-abc * {
        visibility: visible !important;
    }
    #painel-insights-abc {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        width: 100% !important;
        padding: 0 !important; margin: 0 !important;
        background: white !important;
    }

    /* ── 4. Esconde botões e elementos de UI ── */
    .btn-pdf,
    .btn-imprimir,
    #busca-fornecedor-cap,
    #resultados-busca-cap,
    #busca-cliente-car,
    #resultados-busca-car,
    .faixa-btn,
    .faixa-btn-ativo,
    .faixa-btn-car,
    .faixa-btn-car-ativo,
    .paginacao,
    .info-tabela-header,
    #btn-imprimir-sumiram,
    #btn-imprimir-queda,
    #btn-imprimir-abc,
    #btn-reset-print-sumiram,
    #btn-reset-print-queda,
    #btn-reset-print-abc {
        display: none !important;
        visibility: hidden !important;
    }

    /* ── 5. Tabela ocupa toda a largura ── */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 10px !important;
        table-layout: fixed !important;
    }

    /* ── 6. Larguras das colunas CAP (5 colunas) ── */
    #painel-cap-analitico table th:nth-child(1),
    #painel-cap-analitico table td:nth-child(1) { width: 12% !important; }
    #painel-cap-analitico table th:nth-child(2),
    #painel-cap-analitico table td:nth-child(2) { width: 42% !important; }
    #painel-cap-analitico table th:nth-child(3),
    #painel-cap-analitico table td:nth-child(3) { width: 13% !important; }
    #painel-cap-analitico table th:nth-child(4),
    #painel-cap-analitico table td:nth-child(4) { width: 13% !important; }
    #painel-cap-analitico table th:nth-child(5),
    #painel-cap-analitico table td:nth-child(5) { width: 20% !important; }

    /* ── 7. Larguras das colunas CAR (7 colunas) ── */
    #painel-car-analitico table th:nth-child(1),
    #painel-car-analitico table td:nth-child(1) { width: 11% !important; }
    #painel-car-analitico table th:nth-child(2),
    #painel-car-analitico table td:nth-child(2) { width: 30% !important; }
    #painel-car-analitico table th:nth-child(3),
    #painel-car-analitico table td:nth-child(3) { width: 10% !important; }
    #painel-car-analitico table th:nth-child(4),
    #painel-car-analitico table td:nth-child(4) { width: 8%  !important; }
    #painel-car-analitico table th:nth-child(5),
    #painel-car-analitico table td:nth-child(5) { width: 10% !important; }
    #painel-car-analitico table th:nth-child(6),
    #painel-car-analitico table td:nth-child(6) { width: 15% !important; }
    #painel-car-analitico table th:nth-child(7),
    #painel-car-analitico table td:nth-child(7) { width: 16% !important; }

    /* ── 8. Larguras Sumiram (9 colunas) ── */
    #painel-insights-sumiram table th:nth-child(1),
    #painel-insights-sumiram table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-sumiram table th:nth-child(2),
    #painel-insights-sumiram table td:nth-child(2) { width: 6%  !important; }
    #painel-insights-sumiram table th:nth-child(3),
    #painel-insights-sumiram table td:nth-child(3) { width: 24% !important; }
    #painel-insights-sumiram table th:nth-child(4),
    #painel-insights-sumiram table td:nth-child(4) { width: 14% !important; }
    #painel-insights-sumiram table th:nth-child(5),
    #painel-insights-sumiram table td:nth-child(5) { width: 14% !important; }
    #painel-insights-sumiram table th:nth-child(6),
    #painel-insights-sumiram table td:nth-child(6) { width: 10% !important; }
    #painel-insights-sumiram table th:nth-child(7),
    #painel-insights-sumiram table td:nth-child(7) { width: 9%  !important; }
    #painel-insights-sumiram table th:nth-child(8),
    #painel-insights-sumiram table td:nth-child(8) { width: 12% !important; }
    #painel-insights-sumiram table th:nth-child(9),
    #painel-insights-sumiram table td:nth-child(9) { width: 8%  !important; }

    /* ── 9. Larguras Queda (9 colunas) ── */
    #painel-insights-queda table th:nth-child(1),
    #painel-insights-queda table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-queda table th:nth-child(2),
    #painel-insights-queda table td:nth-child(2) { width: 5%  !important; }
    #painel-insights-queda table th:nth-child(3),
    #painel-insights-queda table td:nth-child(3) { width: 22% !important; }
    #painel-insights-queda table th:nth-child(4),
    #painel-insights-queda table td:nth-child(4) { width: 12% !important; }
    #painel-insights-queda table th:nth-child(5),
    #painel-insights-queda table td:nth-child(5) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(6),
    #painel-insights-queda table td:nth-child(6) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(7),
    #painel-insights-queda table td:nth-child(7) { width: 13% !important; }
    #painel-insights-queda table th:nth-child(8),
    #painel-insights-queda table td:nth-child(8) { width: 11% !important; }
    #painel-insights-queda table th:nth-child(9),
    #painel-insights-queda table td:nth-child(9) { width: 8%  !important; }

    /* ── 10. Larguras ABC (9 colunas) ── */
    #painel-insights-abc table th:nth-child(1),
    #painel-insights-abc table td:nth-child(1) { width: 3%  !important; }
    #painel-insights-abc table th:nth-child(2),
    #painel-insights-abc table td:nth-child(2) { width: 6%  !important; }
    #painel-insights-abc table th:nth-child(3),
    #painel-insights-abc table td:nth-child(3) { width: 28% !important; }
    #painel-insights-abc table th:nth-child(4),
    #painel-insights-abc table td:nth-child(4) { width: 17% !important; }
    #painel-insights-abc table th:nth-child(5),
    #painel-insights-abc table td:nth-child(5) { width: 17% !important; }
    #painel-insights-abc table th:nth-child(6),
    #painel-insights-abc table td:nth-child(6) { width: 13% !important; }
    #painel-insights-abc table th:nth-child(7),
    #painel-insights-abc table td:nth-child(7) { width: 7%  !important; }
    #painel-insights-abc table th:nth-child(8),
    #painel-insights-abc table td:nth-child(8) { width: 7%  !important; }
    #painel-insights-abc table th:nth-child(9),
    #painel-insights-abc table td:nth-child(9) { width: 5%  !important; }

    /* ── 11. Cabeçalhos coloridos ── */
    #painel-cap-analitico thead tr {
        background-color: #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-car-analitico thead tr {
        background-color: #1565C0 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-sumiram thead tr {
        background-color: #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-queda thead tr {
        background-color: #DD6B20 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    #painel-insights-abc thead tr {
        background-color: #1D9E75 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    thead th {
        color: white !important;
        padding: 7px 10px !important;
        font-size: 9px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* ── 12. Linhas de grupo ── */
    .tr-grupo-print {
        background-color: #edf0ed !important;
        border-left: 3px solid #E53E3E !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .tr-grupo-print-car {
        background-color: #edf0ed !important;
        border-left: 3px solid #1565C0 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* ── 13. Não quebrar linhas no meio da página ── */
    tr { page-break-inside: avoid !important; }

    /* ── 14. Texto não cortado ── */
    td, th {
        overflow: visible !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    /* ── 15. Badges ── */
    .badge-aviso-print {
        background-color: #FAEEDA !important; color: #854F0B !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
        border-radius: 99px; padding: 1px 6px; font-size: 9px; font-weight: 700;
    }
    .badge-critico-print {
        background-color: #FDECEA !important; color: #A32D2D !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
        border-radius: 99px; padding: 1px 6px; font-size: 9px; font-weight: 700;
    }
}