/* ================================
   STYLES D'IMPRESSION
   Solution au problème de pagination
   ================================ */

@media print {
  
  /* ================================
     RESET POUR L'IMPRESSION
     ================================ */
  
  body {
    background-color: white !important;
    padding: 0 !important;
    margin: 0 !important;
    color: black !important;
    font-size: 12pt;
    line-height: 1.4;
  }
  
  /* ================================
     MASQUER LES ÉLÉMENTS NON IMPRIMABLES
     ================================ */
  
  .toolbar,
  .section-actions,
  .resize-handle-col,
  .resize-handle-row,
  .delete-photo-btn,
  .photo-drop-zone p,
  .export-help {
    display: none !important;
  }
  
  /* ================================
     PAGINATION INTELLIGENTE DES SECTIONS
     (SOLUTION PRINCIPALE AU PROBLÈME)
     ================================ */
  
  .section {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 20px !important;
    border: 1px solid #ddd !important;
    border-radius: 0 !important;
  }
  
  /* Force un saut de page avant certaines sections si nécessaire */
  .section.page-break-before {
    page-break-before: always !important;
  }
  
  /* ================================
     PAGINATION DES TABLEAUX
     ================================ */
  
  table {
    page-break-inside: auto !important;
    width: 100% !important;
    border-collapse: collapse !important;
  }
  
  /* Éviter la coupure des lignes de tableau */
  tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  
  /* Répéter l'en-tête de tableau sur chaque page */
  thead {
    display: table-header-group !important;
  }
  
  tbody {
    display: table-row-group !important;
  }
  
  /* ================================
     SECTIONS PHOTO
     ================================ */
  
  .photo-container {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    display: inline-block !important;
    margin: 5px !important;
  }
  
  .photo-preview {
    page-break-inside: avoid !important;
  }
  
  .photo-preview img {
    max-width: 150px !important;
    max-height: 150px !important;
    border: 1px solid #ddd !important;
  }
  
  /* Masquer les champs de saisie des noms de photos */
  .photo-container input[type="text"] {
    display: none !important;
  }
  
  /* ================================
     SECTIONS LAYOUT (MISE EN PAGE)
     ================================ */
  
  .layout-section .section-header {
    display: none !important;
  }
  
  .layout-section {
    border: none !important;
    margin-bottom: 0 !important;
    background: transparent !important;
  }
  
  .layout-section .section-content {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
  }
  
  /* ================================
     OPTIMISATIONS GÉNÉRALES
     ================================ */
  
  #report-container {
    width: 100% !important;
    max-width: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
  }
  
  .container {
    margin: 0 !important;
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
  }
  
  /* ================================
     EN-TÊTES ET TITRES
     ================================ */
  
  .report-header {
    margin-bottom: 20px !important;
  }
  
  .report-header h1 {
    font-size: 20pt !important;
    margin: 0 0 10px 0 !important;
    padding: 0 !important;
    border: none !important;
    text-align: center !important;
  }
  
  .report-author {
    font-size: 12pt !important;
    margin-bottom: 15px !important;
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
  }
  
  .section-title {
    font-size: 14pt !important;
    font-weight: bold !important;
    border: none !important;
    padding: 5px !important;
  }
  
  /* ================================
     STYLES DES SECTIONS
     ================================ */
  
  .section-header {
    background-color: #f8f9fa !important;
    border-bottom: 1px solid #ddd !important;
    padding: 8px !important;
    -webkit-print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  .section-content {
    padding: 10px !important;
  }
  
  /* ================================
     TABLEAUX OPTIMISÉS
     ================================ */
  
  th, td {
    border: 1px solid #ddd !important;
    padding: 6px !important;
    vertical-align: top !important;
    text-align: left !important;
  }
  
  th {
    background-color: #f8f9fa !important;
    font-weight: bold !important;
  }
  
  th span, td span {
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  /* ================================
     MASQUER LES ÉLÉMENTS D'ÉDITION
     ================================ */
  
  [contenteditable="true"]:hover {
    border: none !important;
    cursor: default !important;
  }
  
  /* ================================
     GESTION DES SAUTS DE PAGE MANUELS
     ================================ */
  
  /* Classe utilitaire pour forcer un saut de page */
  .page-break {
    page-break-before: always !important;
  }
  
  /* Éviter les sauts de page orphelins */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid !important;
  }
  
  /* ================================
     LIENS ET URLs
     ================================ */
  
  a {
    color: black !important;
    text-decoration: none !important;
  }
  
  /* Afficher les URLs après les liens si nécessaire */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 10pt;
    color: #666;
  }
  
  /* ================================
     MARGES DE PAGE
     ================================ */
  
  @page {
    margin: 2cm;
    size: A4 portrait;
  }
  
  @page :first {
    margin-top: 3cm;
  }
  
  /* ================================
     OPTIMISATIONS SPÉCIFIQUES
     ================================ */
  
  /* Améliorer la qualité d'impression des images */
  img {
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
  }
  
  /* Optimiser les polices pour l'impression */
  body, th, td, div, span {
    font-family: "Times New Roman", Times, serif !important;
  }
  
  /* Améliorer la lisibilité */
  p, div, span {
    text-rendering: optimizeLegibility !important;
  }
}

/* ================================
   STYLES POUR APERÇU AVANT IMPRESSION
   ================================ */

@media screen {
  .print-preview {
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    background: white;
    max-width: 21cm;
    margin: 0 auto;
    padding: 2cm;
  }
  
  .print-preview .section {
    page-break-inside: avoid;
    break-inside: avoid;
  }
}

/* ================================
   CLASSE UTILITAIRE POUR TEST
   ================================ */

.force-page-break {
  page-break-before: always !important;
}