/* ========================================
   STYLES D'IMPRESSION - NOIR ET BLANC
   Pour le Créateur de Livre d'Exercices
   ======================================== */

@media print {
    /* Configuration de la page d'impression */
    @page {
        size: A4;
        margin: 0;
    }
    
    /* Masquer tout sauf le conteneur d'impression */
    body > *:not(#print-container) {
        display: none !important;
    }
    
    /* Mode PDF en couleur - Utiliser les styles visuels au lieu du noir et blanc */
    body:has(.pdf-color-mode) #print-container.pdf-color-mode {
        /* Préserver les couleurs et styles */
    }
    
    body:has(.pdf-color-mode) .exercice-normal {
        border: 3px solid #3b82f6 !important;
        background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(147, 197, 253, 0.05)) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .exercice-dm {
        border: 3px solid #f59e0b !important;
        background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(251, 191, 36, 0.08)) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .exercice-dm .exercice-header {
        background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Exercices avec niveau - Mode couleur */
    body:has(.pdf-color-mode) .exercice-niveau {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-1 {
        border: 3px solid #10b981 !important;
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(52, 211, 153, 0.04)) !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-1 .exercice-header {
        background: linear-gradient(135deg, #10b981, #34d399) !important;
        color: white !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-2 {
        border: 3px solid #3b82f6 !important;
        background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(147, 197, 253, 0.04)) !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-2 .exercice-header {
        background: linear-gradient(135deg, #3b82f6, #93c5fd) !important;
        color: white !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-3 {
        border: 3px solid #f59e0b !important;
        background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(251, 191, 36, 0.04)) !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-3 .exercice-header {
        background: linear-gradient(135deg, #f59e0b, #fbbf24) !important;
        color: white !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-4 {
        border: 3px solid #ef4444 !important;
        background: linear-gradient(135deg, rgba(239, 68, 68, 0.08), rgba(248, 113, 113, 0.04)) !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-4 .exercice-header {
        background: linear-gradient(135deg, #ef4444, #f87171) !important;
        color: white !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-5 {
        border: 3px solid #7c3aed !important;
        background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(167, 139, 250, 0.05)) !important;
    }
    
    body:has(.pdf-color-mode) .exercice-niveau.niveau-5 .exercice-header {
        background: linear-gradient(135deg, #7c3aed, #a78bfa) !important;
        color: white !important;
    }
    
    /* Titres de section - Styles couleur */
    body:has(.pdf-color-mode) .titre-section.style-2 {
        background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(147, 197, 253, 0.05)) !important;
        border-left: 6px solid #3b82f6 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .titre-section.style-2 .element-content {
        color: #3b82f6 !important;
    }
    
    body:has(.pdf-color-mode) .titre-section.style-3 {
        border-bottom: 3px solid #3b82f6 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .titre-section.style-3 .element-content {
        color: #3b82f6 !important;
    }
    
    body:has(.pdf-color-mode) .titre-section.style-4 {
        background: #3b82f6 !important;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .titre-section.style-4 .element-content {
        color: white !important;
    }
    
    body:has(.pdf-color-mode) .exercice-numero {
        background: #3b82f6 !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .titre-section {
        background: linear-gradient(90deg, #3b82f6, #60a5fa) !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .graphique-element {
        border: 2px solid #8b5cf6 !important;
        background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), rgba(167, 139, 250, 0.05)) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    body:has(.pdf-color-mode) .graphique-element canvas,
    body:has(.pdf-color-mode) .attached-graphique canvas {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    /* Force le fond blanc pour tout */
    body, html {
        background: white !important;
        color: black !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Conteneur d'impression */
    #print-container {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
    }
    
    /* Page A4 pour impression - DIMENSIONS EXACTES */
    .page-a4-print,
    .page-a4 {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 20mm 10mm !important; /* Marges réduites : 10mm gauche/droite au lieu de 15mm */
        box-shadow: none !important;
        border: none !important;
        page-break-after: always !important;
        background: white !important;
        display: block !important;
        position: relative !important; /* RELATIF pour permettre le positionnement des enfants */
        top: 0 !important;
        left: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* Masquer les éléments d'interface */
    .element-toolbar,
    .resize-handle,
    .page-welcome {
        display: none !important;
    }
    
    /* Éléments - CONSERVER LES POSITIONS ABSOLUES */
    .page-element {
        position: absolute !important; /* Conserver la disposition exacte */
        page-break-inside: avoid;
        background: white !important;
    }
    
    /* ==========================================
       EXERCICES NORMAUX - Style économique
       ========================================== */
    .exercice-normal {
        border: 1.5px solid #555 !important; /* Bordure fine grise */
        background: white !important;
        padding: 8px !important;
        border-radius: 4px !important;
    }
    
    .exercice-normal .exercice-header {
        border-bottom: 1px solid #ccc;
        padding-bottom: 4px;
        margin-bottom: 6px;
    }
    
    .exercice-normal .exercice-numero {
        background: white !important;
        color: black !important;
        border: 1.5px solid #555 !important;
        padding: 3px 7px !important;
        font-weight: bold;
        border-radius: 50%;
    }
    
    .exercice-normal .exercice-points {
        color: #444 !important;
        font-size: 9pt;
    }
    
    .exercice-normal .exercice-consigne {
        color: #333 !important;
        font-style: italic;
        border-left: 2px solid #888;
        padding-left: 6px;
        margin: 4px 0;
    }
    
    .exercice-normal .exercice-contenu {
        color: black !important;
        line-height: 1.5;
    }
    
    /* ==========================================
       EXERCICES AVEC NIVEAU - Style avec étoiles
       ========================================== */
    .exercice-niveau {
        border: 1.5px solid #555 !important;
        background: white !important;
        padding: 8px !important;
        border-radius: 4px !important;
    }
    
    .exercice-niveau .exercice-header {
        background: #f5f5f5 !important;
        color: black !important;
        padding: 5px 8px !important;
        margin: -8px -8px 6px -8px !important;
        font-weight: bold;
        border: 1px solid #ccc;
        border-radius: 4px 4px 0 0;
        display: flex !important;
        align-items: center;
        gap: 6px;
    }
    
    .exercice-niveau .exercice-numero {
        background: white !important;
        color: black !important;
        border: 1.5px solid #333 !important;
        padding: 3px 7px !important;
        font-weight: bold;
        border-radius: 50%;
    }
    
    .exercice-niveau .niveau-stars {
        background: white !important;
        color: black !important;
        border: 1px solid #666 !important;
        padding: 2px 6px !important;
        font-size: 8pt;
    }
    
    .exercice-niveau .exercice-points {
        color: #333 !important;
        font-size: 9pt;
        font-weight: bold;
    }
    
    .exercice-niveau .exercice-consigne {
        color: #222 !important;
        font-style: italic;
        border-left: 2px solid #555;
        padding-left: 6px;
        margin: 4px 0;
        font-weight: 500;
    }
    
    .exercice-niveau .exercice-contenu {
        color: black !important;
        line-height: 1.5;
    }
    
    /* ==========================================
       DEVOIRS MAISON - Distinction subtile avec icône maison
       ========================================== */
    .exercice-dm {
        border: 2px dashed #333 !important; /* Bordure pointillée pour distinction */
        background: white !important;
        padding: 8px !important;
        border-radius: 6px !important;
    }
    
    /* En-tête léger avec DM et icône maison */
    .exercice-dm .exercice-header {
        background: #f5f5f5 !important; /* Fond gris très clair */
        color: black !important;
        padding: 5px 8px !important;
        margin: -8px -8px 6px -8px !important;
        font-weight: bold;
        border: 1px solid #ccc;
        border-radius: 4px 4px 0 0;
        display: flex !important;
        align-items: center;
        gap: 6px;
    }
    
    /* Afficher "DM" */
    .exercice-dm .exercice-header::before {
        content: 'DM';
        font-size: 9pt;
        font-weight: bold;
        letter-spacing: 0.5px;
        color: black !important;
    }
    
    /* Conserver l'icône maison */
    .exercice-dm .dm-icon {
        font-size: 12pt;
        color: black !important;
        filter: none !important;
    }
    
    .exercice-dm .exercice-numero {
        background: white !important;
        color: black !important;
        border: 1.5px solid #333 !important;
        padding: 3px 7px !important;
        font-weight: bold;
        border-radius: 50%;
    }
    
    .exercice-dm .exercice-points {
        color: #333 !important;
        font-size: 9pt;
        font-weight: bold;
    }
    
    .exercice-dm .exercice-consigne {
        color: #222 !important;
        font-style: italic;
        border-left: 2px solid #555;
        padding-left: 6px;
        margin: 4px 0;
        font-weight: 500;
    }
    
    .exercice-dm .exercice-contenu {
        color: black !important;
        line-height: 1.5;
    }
    
    /* Contenu des exercices */
    .exercice-consigne {
        font-style: italic !important;
        color: #000 !important;
        margin-bottom: 4px;
    }
    
    .exercice-contenu,
    .element-content {
        color: #000 !important;
        line-height: 1.5;
    }
    
    .exercice-points {
        color: #000 !important;
        font-weight: bold;
    }
    
    /* ==========================================
       TITRE DE SECTION - Style sobre
       ========================================== */
    .titre-section,
    .titre-section.style-1 {
        background: white !important;
        color: black !important;
        padding: 6px 10px !important;
        margin: 8px 0 4px 0 !important;
        font-size: 14pt !important;
        font-weight: bold !important;
        border-bottom: 2px solid #333 !important;
        border-left: none !important;
        border-radius: 0 !important;
        page-break-after: avoid;
    }
    
    .titre-section.style-2 {
        background: white !important;
        border-left: 4px solid #333 !important;
        border-bottom: 1px solid #999 !important;
        padding-left: 12px !important;
    }
    
    .titre-section.style-3 {
        background: white !important;
        border-bottom: 3px solid #333 !important;
        border-left: none !important;
    }
    
    .titre-section.style-4 {
        background: #f5f5f5 !important;
        border: 1.5px solid #333 !important;
        border-radius: 15px !important;
        text-align: center !important;
        padding: 8px 20px !important;
    }
    
    .titre-section .element-content {
        color: black !important;
    }
    
    /* ==========================================
       SÉPARATEUR - Ligne fine
       ========================================== */
    .separateur {
        height: 1px !important;
        background: #999 !important;
        border: none !important;
        margin: 6px 0 !important;
    }
    
    /* ==========================================
       ENCADRÉ - Style sobre avec icône
       ========================================== */
    .encadre {
        border: 1.5px solid #555 !important;
        background: #fafafa !important; /* Fond très léger */
        padding: 8px !important;
        margin: 6px 0 !important;
        border-radius: 4px !important;
    }
    
    .encadre .encadre-titre {
        font-weight: bold;
        color: black !important;
        margin-bottom: 4px;
        padding-bottom: 3px;
        border-bottom: 1px solid #ccc;
    }
    
    .encadre .encadre-titre::before {
        content: '💡 ';
        font-size: 10pt;
    }
    
    .encadre-content {
        color: #000 !important;
    }
    
    /* ==========================================
       PARAGRAPHE
       ========================================== */
    .paragraphe {
        border: none !important;
        background: white !important;
        padding: 4px 0 !important;
        margin: 4px 0 !important;
    }
    
    .paragraphe .element-content {
        color: #000 !important;
        line-height: 1.6;
    }
    
    /* ==========================================
       IMAGES
       ========================================== */
    .image-element {
        border: 1px solid #666 !important;
        padding: 0 !important;
        background: white !important;
        page-break-inside: avoid;
    }
    
    .image-element img {
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
    
    /* Graphiques */
    .graphique-element {
        border: 1px solid #666 !important;
        padding: 0.3cm !important;
        background: white !important;
        page-break-inside: avoid;
        display: flex !important;
        flex-direction: column !important;
        min-height: 6cm !important;
        box-sizing: border-box !important;
    }
    
    .graphique-element canvas {
        display: block !important;
        width: 100% !important;
        height: 5cm !important;
        min-height: 5cm !important;
        flex: 1 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: white !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }
    
    .graphique-titre {
        font-weight: 600 !important;
        color: #000 !important;
        margin-bottom: 0.2cm !important;
        text-align: center !important;
        font-size: 11pt !important;
    }
    
    /* ==========================================
       ÉLÉMENTS ATTACHÉS
       ========================================== */
    .attached-elements {
        margin-top: 0.4cm !important;
        padding-top: 0.4cm !important;
        border-top: 1px dashed #999 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.3cm !important;
    }
    
    .attached-graphique,
    .attached-image {
        background: white !important;
        border: 1px solid #ccc !important;
        border-radius: 4px !important;
        padding: 0.3cm !important;
        page-break-inside: avoid !important;
    }
    
    .attached-toolbar {
        display: none !important;
    }
    
    .attached-graphique-titre {
        font-weight: 600 !important;
        color: #000 !important;
        font-size: 10pt !important;
        margin-bottom: 0.2cm !important;
        text-align: center !important;
    }
    
    .attached-graphique canvas {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 4cm !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 1px solid #ddd !important;
        background: white !important;
    }
    
    .attached-image img {
        width: 100% !important;
        height: auto !important;
        display: block !important;
        border: 1px solid #ddd !important;
    }
    
    .attached-image-legende {
        margin-top: 0.2cm !important;
        font-size: 9pt !important;
        font-style: italic !important;
        color: #555 !important;
        text-align: center !important;
    }
    
    /* ==========================================
       FORMULES MATHÉMATIQUES
       ========================================== */
    math-field {
        color: #000 !important;
        background: white !important;
        border: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        display: inline-block !important;
    }
    
    /* ==========================================
       OPTIMISATIONS GÉNÉRALES
       ========================================== */
    
    /* Éviter les coupures de page dans les éléments */
    .page-element {
        page-break-inside: avoid;
    }
    
    /* Typographie optimisée pour l'impression */
    body {
        font-family: 'Times New Roman', Times, serif !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
        color: #000 !important;
    }
    
    /* Liens en noir */
    a {
        color: #000 !important;
        text-decoration: underline !important;
    }
}

/* ==========================================
   MODE APERÇU AVANT IMPRESSION
   ========================================== */
@media screen {
    body.printing-mode #section-livre-exercices {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 99999;
        background: white;
        overflow: auto;
    }
    
    body.printing-mode .livre-header,
    body.printing-mode .livre-toolbar,
    body.printing-mode .livre-sidebar,
    body.printing-mode .livre-elements-panel,
    body.printing-mode .workspace-header {
        display: none !important;
    }
}
