/* --- 1. STYLES ÉCRAN (BASE) --- */
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f4f4; margin: 0; line-height: 1.4; color: #333; }
.main-content { padding: 20px; margin: 0 auto; max-width: 1200px; }

.arrimage-container { margin: auto; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.arrimage-header-section { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid #0056b3; padding-bottom: 15px; margin-bottom: 25px; }
.main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
.panel { border: 1px solid #ddd; padding: 20px; border-radius: 8px; background: #fff; margin-bottom: 20px; }
h3 { margin-top: 0; color: #0056b3; border-bottom: 1px solid #eee; padding-bottom: 10px; font-size: 1.1em; }

.status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 15px; }
.status-box { padding: 15px; border-radius: 8px; background-color: #eee; text-align: center; border: 2px solid #ccc; }
.valeur { font-size: 1.1em; font-weight: bold; display: block; margin: 5px 0; }
.pourcentage { font-size: 0.9em; font-weight: bold; }

table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 0.85em; }
th, td { border: 1px solid #ddd; padding: 10px; text-align: center; }
th { background-color: #0056b3; color: white; }

label { display: block; margin-top: 10px; font-weight: bold; font-size: 0.85em; }
select, input { width: 100%; padding: 8px; margin-top: 5px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
.row-inputs { display: flex; gap: 10px; }
.btn-add { background-color: #28a745; color: white; width: 100%; padding: 12px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; margin-top: 15px; }
.btn-print { background-color: #0056b3; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }

.disclaimer { margin-top: 30px; padding: 20px; background-color: #fff3cd; border: 1px solid #ffeeba; border-radius: 8px; color: #856404; font-size: 0.85em; text-align: justify; }
.note-technique { margin-top: 30px; padding: 20px; border: 1px solid #ccc; background: #fff; font-size: 0.9em; }
.note-technique h2 { color: #0056b3; border-bottom: 2px solid #0056b3; padding-bottom: 5px; }
.math-box { background: #f9f9f9; padding: 10px; border-left: 3px solid #28a745; font-family: monospace; margin: 10px 0; }

.print-only { display: none; font-weight: bold; font-size: 1.2em; }
.footer-print { display: none; }
.img-schema {
    max-width: 100%;  /* L'image ne peut pas être plus large que son parent */
    height: auto;     /* Conserve les proportions pour éviter de l'écraser */
    display: block;   /* Supprime l'espace vide sous l'image */
    margin: 10px auto; /* Centre l'image si elle est plus petite que le parent */
}
/* Conteneur des boîtes de statut */
.status-grid {
    display: flex;
    flex-wrap: wrap; /* Permet de passer à la ligne si pas assez de place */
    gap: 10px;       /* Espace entre les boîtes */
    width: 100%;
}

/* Les boîtes individuelles (ex: #bilan_avant) */
.status-box {
    flex: 1 1 calc(25% - 10px); /* 4 colonnes sur PC, soustrait le gap */
    min-width: 150px;           /* Se mettra à la ligne si < 150px */
    max-width: 100%;            /* Ne déborde jamais du parent */
    box-sizing: border-box;     /* Inclut le padding dans la largeur */
    word-wrap: break-word;      /* Coupe les mots trop longs */
}

/* Responsive pour tablettes/mobiles */
@media (max-width: 768px) {
    .status-box {
        flex: 1 1 calc(50% - 10px); /* 2 colonnes sur tablette */
    }
}
@media (max-width: 480px) {
    .status-box {
        flex: 1 1 100%;             /* 1 seule colonne sur petit mobile */
    }
}
/* On s'assure que le panel qui contient le tableau ne déborde pas */
.panel {
    max-width: 100%;
    overflow-x: hidden; /* Empêche le débordement global */
}

/* Conteneur spécifique pour le tableau (à ajouter autour de <table> si possible) 
   ou cibler directement le tableau avec cette technique : */
#tableau_arrimage {
    width: 100%;
    border-collapse: collapse;
    display: block;        /* Permet le scroll sur le tableau lui-même */
    overflow-x: auto;      /* Apparition d'une barre de défilement si trop large */
    -webkit-overflow-scrolling: touch;
}

#tableau_arrimage thead th {
    white-space: nowrap;   /* Évite que les titres ne se cassent bizarrement */
    font-size: 0.9em;      /* Un peu plus petit pour gagner de la place */
}
/* Sécurité maximale pour tout le conteneur principal */
.arrimage-container, .panel, .status-box, table {
    box-sizing: border-box !important;
    max-width: 100% !important;
}

/* Gestion du tableau en responsive */
@media (max-width: 600px) {
    #tableau_arrimage {
        font-size: 12px; /* Réduction de la police sur mobile */
    }
    
    /* Optionnel : cacher certaines colonnes non critiques sur mobile */
    #tableau_arrimage th:nth-child(2), 
    #tableau_arrimage td:nth-child(2) {
        display: none; 
    }
}
/* --- 2. STYLES IMPRESSION (MÉTIER) --- */
@media print {
    /* Nettoyage global */
    .btn-add, .no-print, button, select, input, #menu-toggle, .sidebar, header, footer { display: none !important; }
    body { background: white; margin: 0; padding: 0; counter-reset: page; }
    .main-content { width: 100%; max-width: 100%; margin: 0; padding: 0; }
    .arrimage-container { box-shadow: none; border: none; width: 100%; padding: 0; }
    
    /* Correction du saut de page (Crucial) */
    .main-grid { 
        display: block !important; /* Casse la grille pour éviter que le navigateur ne la pousse en page 2 */
        width: 100%; 
    }
    
    .panel { 
        page-break-inside: avoid; /* Empêche de couper un bloc au milieu */
        break-inside: avoid;
        border: 1px solid #ddd !important;
        margin-bottom: 15px !important;
    }

    .arrimage-header-section { 
        margin-bottom: 10px !important; 
        page-break-after: avoid; 
    }

    .print-only { display: block !important; margin-bottom: 10px; }

    /* Forcer le saut de page pour les sections de fin */
    .page-break { page-break-before: always !important; break-before: always !important; margin-top: 20px; }
    .note-technique { page-break-before: always !important; break-before: always !important; }

    /* Pied de page dynamique */
    .footer-print {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        text-align: center;
        font-size: 9pt;
        color: #555;
        border-top: 1px solid #ccc;
        padding: 5px 0;
        background: white;
    }
    .page-number:after {
        counter-increment: page;
        content: " - Page " counter(page);
    }
    
    /* Ajustement tableaux */
    table { page-break-inside: auto; }
    tr { page-break-inside: avoid; break-inside: avoid; }
}