/* ════════════════════════════════════════════════════════════════════════
   ATLAS AGROALIMENTAIRE — Impression (v22.1)
   Une fiche ouverte s'imprime SEULE et EN ENTIER : avant, la fenêtre de la fiche
   (position fixe, défilement interne) répétait le même premier écran sur chaque
   page et les sections repliées n'étaient pas imprimées. Ici : noir sur blanc
   (lisible même sans « arrière-plans »), sections dépliées par impression.js,
   boutons masqués, liens des sources écrits en clair, coupures de page propres.
   ════════════════════════════════════════════════════════════════════════ */
.a22-print-head, .a22-print-foot { display: none; }

@page { size: A4; margin: 13mm 12mm 15mm; }

@media print {
  :root, html, html.theme-is-dark, html.theme-is-light, html[data-theme] {
    --bg: #fff; --surface: #fff; --card: #fff; --ink: #161616; --text: #111; --parch: #111; --dim: #444;
    --border: #bdbdbd; --gold: #5a3a00; color-scheme: light;
  }
  html, body { background: #fff !important; color: #111 !important; }
  body { font-size: 10.5pt; line-height: 1.42; }
  *, *::before, *::after { box-shadow: none !important; text-shadow: none !important; animation: none !important; transition: none !important; }

  /* Habillage de l'application : jamais imprimé */
  #navbar, .a20-header, footer.atlas-footer, .atlas-footer, #a20-cmp-tray, .a20-cmp-tray, .v22-set-nav, #a21-hub,
  .a20-toast, #a20-toast, .a20-skip, #loader, .a20-palette, .a20-fab, .a22-no-print, #quiz-modal-backdrop { display: none !important; }

  /* ── Fiche ouverte : elle seule, en entier ───────────────────────────── */
  html.a22-print-fiche body > :not(#modal-bg) { display: none !important; }
  html.a22-print-fiche #modal-bg {
    position: static !important; display: block !important; inset: auto !important; overflow: visible !important;
    background: none !important; padding: 0 !important; margin: 0 !important; width: auto !important; height: auto !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
  }
  html.a22-print-fiche #modal-bg .modal {
    position: static !important; width: auto !important; max-width: none !important; min-height: 0 !important; max-height: none !important;
    height: auto !important; margin: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important;
    overflow: visible !important; background: #fff !important; color: #111 !important; transform: none !important;
  }
  /* aucun bloc à défilement interne ni hauteur bornée sur papier */
  html.a22-print #modal-bg .modal *:not(svg):not(svg *), html.a22-print-page #app-main *:not(svg):not(svg *) {
    max-height: none !important; overflow: visible !important;
  }
  html.a22-print #modal-bg .modal .modal-header, html.a22-print #modal-bg .modal [class*="sticky"] { position: static !important; top: auto !important; }
  #modal-bg .modal-header, #modal-bg .modal-body, #modal-bg .p21-grp-body, #modal-bg .modal-section { padding-left: 0 !important; padding-right: 0 !important; background: none !important; }
  #modal-bg .modal-body > div[style*="padding"] { padding: 0 !important; }

  /* Commandes et navigation internes : inutiles sur papier (les notes .p21-help — source Ciqual, aliment de référence — restent imprimées) */
  .modal-close, .a20-fiche-tools, .a20-toc, [data-a20-print], .p21-actions, .a20-btn, button.a20-btn,
  .leaflet-container, .a20-alpha, .alpha-bar, input, select, textarea, .a20-tabs, [role="tablist"], .v22-filters, .a20-filters { display: none !important; }

  /* Relevé brut des champs (« données structurées complémentaires ») : imprimé seulement s'il a été ouvert */
  #modal-bg details.structured-complements:not([open]) { display: none !important; }
  /* Repères de dépliage (▸) et lettres espacées des titres : inutiles sur papier, gênent la recherche dans le PDF */
  .p21-grp > summary::before, .p21-grp > summary::after, .p21-chev, .p21-caret { display: none !important; content: none !important; }
  .ms-ttl, .p21-grp-t, #modal-bg h3, #modal-bg h4 { letter-spacing: .02em !important; }

  /* Titres et sections */
  #modal-bg .m-title, .a22-print-page h1 { font-size: 20pt !important; color: #111 !important; margin: 0 0 2mm !important; }
  #modal-bg .m-subtitle, #modal-bg .m-eyebrow { color: #333 !important; }
  details > summary { list-style: none !important; cursor: default; }
  details > summary::-webkit-details-marker, details > summary::marker { display: none !important; content: '' !important; }
  .p21-grp { border: 0 !important; margin: 0 0 3mm !important; padding: 0 !important; background: none !important; }
  .p21-grp > summary { padding: 0 !important; margin: 4mm 0 2mm !important; border-bottom: 1.2pt solid #555 !important; }
  .p21-grp > summary h3, .p21-grp-t { font-size: 13pt !important; color: #111 !important; margin: 0 0 1mm !important; }
  .p21-n, .structured-count { display: none !important; }
  h1, h2, h3, h4, h5, summary, .ms-ttl, .p21-grp-t { break-after: avoid; page-break-after: avoid; break-inside: avoid; color: #111 !important; }
  .ms-ttl { font-size: 11pt !important; margin: 3mm 0 1mm !important; }
  p, li { orphans: 3; widows: 3; }

  /* Blocs à ne pas couper */
  .zref, figure, .fiche-img, .tl-item, .micro-item, .structured-row, tr, .param, .a20-related-grp, .p21-gen-note, blockquote { break-inside: avoid; page-break-inside: avoid; }

  /* Couleurs et pastilles : texte foncé, contours au lieu des aplats */
  #modal-bg .modal, #modal-bg .modal * { color: #111 !important; border-color: #bdbdbd !important; }
  #modal-bg .modal [class*="badge"]:not([class*="badges"]), #modal-bg .modal [class*="tag"]:not([class*="tags"]):not([class*="tagline"]),
  #modal-bg .modal [class*="chip"]:not([class*="chips"]), #modal-bg .modal .hv-bc,
  .a22-print-page [class*="badge"]:not([class*="badges"]), .a22-print-page [class*="chip"]:not([class*="chips"]) {
    background: none !important; border: 0.6pt solid #888 !important; color: #111 !important; padding: 0 1.5mm !important;
  }
  #modal-bg .modal .a20-chip { display: inline-block !important; margin: 0 1mm 1mm 0 !important; font-size: 8.5pt !important; }
  .a20-related { margin: 2mm 0 !important; }

  /* Images : dans la page, sans déformation */
  img, svg, canvas, video { max-width: 100% !important; height: auto; }
  #modal-bg .fiche-img img, #modal-bg figure img { max-height: 70mm !important; width: auto !important; object-fit: contain; }
  #modal-bg .fiche-gallery { display: flex !important; flex-wrap: wrap !important; gap: 2mm !important; }
  #modal-bg .fiche-gallery img, #modal-bg .modal a > img, #modal-bg .modal [class*="gallery"] img, #modal-bg .modal [class*="galerie"] img {
    max-height: 30mm !important; width: auto !important; height: auto !important; object-fit: contain;
  }
  #modal-bg .fiche-gallery figure img.fiche-img, #modal-bg figure > img.fiche-img { max-height: 70mm !important; }
  #modal-bg .fiche-gallery > :nth-child(n+7) { display: none !important; }

  /* Tableaux : pleine largeur, retour à la ligne, en-têtes répétés */
  table { width: 100% !important; max-width: 100% !important; border-collapse: collapse !important; table-layout: auto !important; font-size: 9pt !important; }
  thead { display: table-header-group; }
  th, td { border: 0.5pt solid #aaa !important; padding: 0.8mm 1.5mm !important; background: none !important; overflow-wrap: anywhere; word-break: normal; }

  /* Textes longs (DOI, URL, noms chimiques) : jamais hors de la page */
  #modal-bg .modal, .a22-print-page #app-main { overflow-wrap: anywhere; word-wrap: break-word; }
  pre, code { white-space: pre-wrap !important; overflow-wrap: anywhere; }

  /* Liens : soulignés ; adresse écrite en clair pour les sources (le DOI est déjà écrit) */
  a { color: #111 !important; text-decoration: underline; }
  .zref-ids a[href^="http"]:not([href*="doi.org"])::after, .a22-print-url[href^="http"]::after {
    content: " — " attr(href); font-size: 8pt; text-decoration: none; overflow-wrap: anywhere; word-break: break-all;
  }

  /* En-tête et pied ajoutés par impression.js */
  .a22-print-head { display: block !important; font-size: 8.5pt; color: #333 !important; border-bottom: 0.6pt solid #888; padding: 0 0 1.5mm; margin: 0 0 3mm; }
  .a22-print-head strong { color: #111 !important; }
  .a22-print-foot { display: block !important; font-size: 8pt; color: #333 !important; border-top: 0.6pt solid #888; padding: 1.5mm 0 0; margin: 4mm 0 0; break-inside: avoid; }
  .a22-print-head a, .a22-print-foot a { overflow-wrap: anywhere; word-break: break-all; }

  /* ── Pages (plats, collections, documents) : le contenu principal seul ── */
  html.a22-print-page #app-main { margin: 0 !important; padding: 0 !important; max-width: none !important; width: auto !important; }
}
