@media print {
    .no-print { display: none !important; }
    #authModal { display: none !important; }
    .print-only { display: inline !important; }
    .print-only-block { display: block !important; }
    body { background: white !important; margin: 0 !important; padding: 0 !important; }
    header, #viewTabs, main { margin: 0 !important; padding: 0 !important; max-width: 100% !important; }

    .week-report { 
        page-break-inside: avoid; 
        break-inside: avoid; 
        box-sizing: border-box;
        margin: 0 !important;
        padding: 0 !important;
    }
    #weeksView {
        display: block !important;
    }
    #weeksView > .week-report {
        break-after: page;
        page-break-after: always;
    }
    #weeksView > .week-report:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    input.cell-input, input[type="checkbox"].cell-checkbox, input.livres-input, input.books-text-input { display: none !important; }
    .cell-print-text { display: inline !important; }
    .books-print-text { display: inline !important; }
    .bg-gradient-to-r { background: #312e81 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .week-header.bg-gradient-to-r {
        background: linear-gradient(105deg, #3730a3 0%, #1d4ed8 100%) !important;
        color: #ffffff !important;
    }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    .week-header { 
        padding: 5px 10px !important; 
        border-radius: 5px !important; 
        margin: 0 0 3px 0 !important; 
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }
    .week-header h2 { font-size: 11px !important; margin: 0 !important; line-height: 1.1 !important; }
    .week-header .week-subtitle { font-size: 7.5px !important; margin-top: 0px !important; }
    .week-header .week-badge { font-size: 7px !important; padding: 1px 4px !important; }
    .week-header .user-name-print { font-size: 9.5px !important; font-weight: bold; }

    .totals-cards-screen {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 10px !important;
        width: 100% !important;
        margin: 0 0 6px 0 !important;
    }
    .totals-cards-screen > div {
        min-width: 0 !important;
        width: 100% !important;
        padding: 10px !important;
    }
    .totals-bar-print { display: none !important; }

    .analysis-print-box {
        margin: 0 0 3px 0 !important;
        padding: 5px 10px !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 5px !important;
        background: #f8fafc !important;
        font-size: 8.5px !important;
        line-height: 1.15 !important;
    }
    .analysis-print-box h4 {
        font-weight: 800 !important;
        color: #312e81 !important;
        text-transform: uppercase !important;
        font-size: 9px !important;
        margin-bottom: 2px !important;
    }

    .week-table-wrap { 
        margin: 0 0 3px 0 !important; 
        border-radius: 5px !important; 
        box-shadow: none !important; 
        border: 1px solid #cbd5e1 !important; 
        overflow: visible !important; 
    }
    .week-table-wrap .table-title { display: none !important; }
    .week-table { 
        font-size: 7.5px !important; 
        width: 100% !important; 
        border-collapse: collapse !important;
        min-width: 100% !important;
    }
    .week-table th { 
        padding: 2px 3px !important; 
        font-size: 6.5px !important; 
        font-weight: 700 !important;
    }
    .week-table td { 
        padding: 2px 3px !important; 
        font-size: 7.5px !important; 
    }
    .week-table tfoot td {
        padding: 2px 3px !important;
        font-size: 8px !important;
        font-weight: 800 !important;
    }
    .day-badge { 
        font-size: 6.5px !important; 
        padding: 1px 2px !important; 
    }

    .books-bar-print {
        margin: 0 !important;
        padding: 3px 6px !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 5px !important;
        background: #f8fafc !important;
        font-size: 8px !important;
        line-height: 1.1 !important;
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
    .books-bar-print .books-count-tag {
        font-weight: 800 !important;
        white-space: nowrap !important;
    }

    @page { size: A4 portrait; margin: 2mm; }
}

@media screen {
    .print-only, .cell-print-text, .books-bar-print { display: none !important; }
    .books-table-print-row { display: none !important; }
    .totals-bar-print { display: none !important; }
    .analysis-print-box { display: block !important; }
}

body.pdf-exporting .no-print { display: none !important; }
body.pdf-exporting .cell-print-text { display: inline !important; }
body.pdf-exporting .books-bar-print { display: flex !important; }
body.pdf-exporting .totals-bar-print { display: none !important; }
body.pdf-exporting input.cell-input, 
body.pdf-exporting input[type="checkbox"].cell-checkbox,
body.pdf-exporting input.livres-input,
body.pdf-exporting input.books-text-input { display: none !important; }
body.pdf-exporting .totals-cards-screen {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
}

body.print-mode-weeks #monthView,
body.print-mode-weeks #yearView,
body.print-mode-weeks #whatsappView,
body.print-mode-weeks #adminView { display: none !important; }

body.print-mode-month #weeksView,
body.print-mode-month #yearView,
body.print-mode-month #whatsappView,
body.print-mode-month #adminView,
body.print-mode-month header,
body.print-mode-month #viewTabs { display: none !important; }
body.print-mode-month #monthView { display: block !important; }

body.print-mode-year #weeksView,
body.print-mode-year #monthView,
body.print-mode-year #whatsappView,
body.print-mode-year #adminView,
body.print-mode-year header,
body.print-mode-year #viewTabs { display: none !important; }
body.print-mode-year #yearView { display: block !important; }

.day-dimanche { background-color: #fef2f2; border-left: 4px solid #ef4444; }
.day-lundi    { background-color: #fff7ed; border-left: 4px solid #f97316; }
.day-mardi    { background-color: #fefce8; border-left: 4px solid #eab308; }
.day-mercredi { background-color: #f0fdf4; border-left: 4px solid #22c55e; }
.day-jeudi    { background-color: #eff6ff; border-left: 4px solid #3b82f6; }
.day-vendredi { background-color: #eef2ff; border-left: 4px solid #6366f1; }
.day-samedi   { background-color: #faf5ff; border-left: 4px solid #a855f7; }

.day-badge-dimanche { background: #ef4444; color: white; }
.day-badge-lundi    { background: #f97316; color: white; }
.day-badge-mardi    { background: #eab308; color: white; }
.day-badge-mercredi { background: #22c55e; color: white; }
.day-badge-jeudi    { background: #3b82f6; color: white; }
.day-badge-vendredi { background: #6366f1; color: white; }
.day-badge-samedi   { background: #a855f7; color: white; }

input[type="number"].cell-input {
    width: 3.1rem;
    text-align: center;
    border: 1px solid #cbd5e1;
    border-radius: 0.375rem;
    padding: 0.2rem 0.25rem;
    font-size: 0.85rem;
}
input[type="number"].cell-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}
.tab-active { background: #312e81; color: white; }
.tab-inactive { background: white; color: #475569; border: 1px solid #e2e8f0; }

.current-week-highlight {
    box-shadow: 0 0 0 3px #4f46e5, 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important;
    border-radius: 0.75rem !important;
}

@media print {
    body.print-single-week #weeksView .week-report {
        display: none !important;
    }
    body.print-single-week #weeksView .week-report[data-print-target="true"] {
        display: block !important;
        visibility: visible !important;
        break-after: auto !important;
        page-break-after: auto !important;
    }
    body.print-single-week #weeksView .week-report[data-print-target="true"] [id^="reportArea-"] {
        display: block !important;
        visibility: visible !important;
    }
}


/* Correction impression mobile/PC : un seul rapport, sans page blanche supplémentaire */
@media print {
    html, body {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    body.print-single-week #weeksView,
    body.print-single-week #weeksView .week-report,
    body.print-single-week #weeksView .week-report[data-print-target="true"] {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        break-after: auto !important;
        page-break-after: auto !important;
        break-before: auto !important;
        page-break-before: auto !important;
    }
    body.print-single-week #weeksView .week-report:not([data-print-target="true"]) {
        display: none !important;
    }
    body.print-single-week #weeksView .week-report[data-print-target="true"] {
        position: static !important;
        transform: none !important;
        width: 100% !important;
    }
    body.print-single-week #weeksView .week-report[data-print-target="true"] [id^="reportArea-"] {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        break-after: auto !important;
        page-break-after: auto !important;
    }
    @page {
        size: A4 portrait;
        margin: 6mm;
    }
}
