/* Book — impression / PDF. Chargée en media="print" APRÈS readtheorg.css.
   Par défaut : noir et blanc. <html class="pdf-couleur"> conserve les couleurs.
   Les numéros de page de la table (.toc-titre/.toc-points/.toc-page) sont injectés par book/pdf.js. */

:root { --nb-fond: transparent; }   /* #eee pour des encadrés en gris clair */

/* ===================== commun (couleur et N&B) ===================== */

#toggle-sidebar, .close-sidebar, #postamble { display: none !important; }

/* rien de souligné (gras et italique conservés) */
*, *::before, *::after { text-decoration: none !important; }

/* --- table des matières --- */
#table-of-contents {
  display: block !important;
  position: static !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  background: none !important;
  margin: 0;
  break-before: page;                 /* après la page de titre */
  break-after: page;
}
#table-of-contents h2 {               /* pas le style des h2 de section */
  font-size: 28px; color: #000;
  padding: 0; margin: 0 0 1em 0;
  border: none; border-radius: 0; background: none;
}
/* readtheorg.js replie les sous-listes (style en ligne) : on force leur affichage */
#text-table-of-contents ul { display: block !important; margin: 0; padding: 0; }
#text-table-of-contents li { display: block !important; margin: 0; list-style: none; max-width: none; break-inside: avoid; }
#text-table-of-contents a {
  display: flex;
  align-items: baseline;
  padding: .15em 0 !important;
  color: #000 !important;
  text-decoration: none !important;
  font-size: 16px;
}
#text-table-of-contents > ul > li { margin-top: .8em; }
#text-table-of-contents > ul > li > a { font-weight: bold; font-size: 18px; }
#text-table-of-contents > ul > li > ul > li > a { padding-left: 2em !important; }

/* points de conduite + numéro de page */
#text-table-of-contents .toc-points {
  flex: 1 1 auto;
  min-width: 1.5em;
  margin: 0 .3em;
  border-bottom: 1px dotted #888;
  transform: translateY(-.25em);
}
#text-table-of-contents .toc-page {
  flex: 0 0 2.2em;                      /* largeur fixe : la mise en page ne bouge pas entre les passes */
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: normal;
}

/* numérotation 1.1, 1.2… (les sections portent déjà « 1. » dans le HTML) */
#text-table-of-contents > ul { counter-reset: toc-s; }
#text-table-of-contents > ul > li { counter-increment: toc-s; counter-reset: toc-b; }
#text-table-of-contents > ul > li > ul > li { counter-increment: toc-b; }
#text-table-of-contents > ul > li > ul > li > a::before {
  content: counter(toc-s) "." counter(toc-b) "\00a0\00a0";
  flex: 0 0 auto;
}
#content { counter-reset: sec; }
#content .outline-2 { counter-increment: sec; counter-reset: sous; }
#content .outline-3 > h3 { counter-increment: sous; }
#content .outline-3 > h3::before { content: counter(sec) "." counter(sous) "\00a0\00a0"; }

/* --- titres --- */
#content .outline-2 { break-before: page; }               /* chaque section en haut d'une page */
#content .outline-2 > h2 {
  font-size: 36px; line-height: 1.2;
  margin: 0 0 .8em 0; padding: 0;
  border: none !important; border-radius: 0;
  background: none !important;
  color: #6c5e55;
}
#content .outline-3 > h3 { font-size: 24px; line-height: 1.25; }

/* --- pagination --- */
/* titre + étiquette restent avec le début du texte ; les encadrés, parfois longs, peuvent se couper */
h3, #aspect, #etq-org-ul, #renvoi-aspect { break-after: avoid; }
#renvoi-aspect-titre-harm, #renvoi-aspect-titre-diss, #renvoi-mmx { break-inside: avoid; break-after: avoid; }
p, li { orphans: 3; widows: 3; }
/* encadré entier sur une page (blanc laissé au besoin) ; un encadré plus haut qu'une page reste coupé */
.note, .warning, .attention, .danger, .seealso, .important, ul.org-ul { break-inside: avoid; }

/* --- renvois sur une ligne : étiquette · titre · lien --- */
.renvoi {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 0 .6em;
  margin: .3em 0 1em 1em; padding-left: .5em;
  break-inside: avoid;
}
.renvoi #renvoi-mmx { display: contents; }
.renvoi :is(#renvoi-aspect, #renvoi-aspect-titre-harm, #renvoi-aspect-titre-diss, #renvoi-mmx-section,
            #renvoi-lien-asp, #lien-maison) {
  margin: 0 !important; padding: 0 !important; border: none !important;
}
.renvoi p { display: inline; margin: 0 !important; padding: 0 !important; font-size: 16px !important; }
.renvoi br { display: none; }
.renvoi #renvoi-aspect, .renvoi #renvoi-mmx-section,
.renvoi #renvoi-mmx-section p { font-size: 13px !important; font-weight: normal; font-style: normal; }
.renvoi:has(#renvoi-aspect-titre-harm) { border-left: 3px solid #C3E324; }
.renvoi:has(#renvoi-aspect-titre-diss) { border-left: 7px double #F2942F; }
.renvoi:has(#renvoi-mmx) { border-left: 3px dotted #CCCCCC; }

/* ===================== noir et blanc ===================== */

html:not(.pdf-couleur) *,
html:not(.pdf-couleur) *::before,
html:not(.pdf-couleur) *::after {
  background-color: transparent !important;
  background-image: none !important;
  color: #000 !important;
  border-color: #666 !important;
  box-shadow: none !important;
}

/* gris secondaires (étiquettes, sous-titre) */
html:not(.pdf-couleur) :is(#aspect, #etq-org-ul, #renvoi-aspect, #renvoi-mmx-section, #intro-pub, .subtitle),
html:not(.pdf-couleur) :is(#aspect, #etq-org-ul, #renvoi-aspect, #renvoi-mmx-section, #intro-pub, .subtitle) * {
  color: #555 !important;
}

html:not(.pdf-couleur) #content img { filter: grayscale(1) !important; }

/* encadrés : la couleur est remplacée par le trait */
html:not(.pdf-couleur) #content :is(.note, .seealso, .danger, .important) {
  background-color: var(--nb-fond) !important;
  border: 1px solid #999 !important;
}
html:not(.pdf-couleur) #content .attention {          /* harmonique */
  background-color: var(--nb-fond) !important;
  border: none !important;
  border-left: 3px solid #000 !important;
}
html:not(.pdf-couleur) #content .warning {            /* dissonant */
  background-color: var(--nb-fond) !important;
  border: none !important;
  border-left: 7px double #000 !important;
}
html:not(.pdf-couleur) #content .outline-2 > h2 { color: #000 !important; }
html:not(.pdf-couleur) .renvoi:has(#renvoi-aspect-titre-harm) { border-left: 3px solid #000 !important; }
html:not(.pdf-couleur) .renvoi:has(#renvoi-aspect-titre-diss) { border-left: 7px double #000 !important; }
html:not(.pdf-couleur) .renvoi:has(#renvoi-mmx) { border-left: 3px dotted #666 !important; }
html:not(.pdf-couleur) ul.org-ul { background-color: var(--nb-fond) !important; }
