/* ============================================================
   Trame — personnalisation des documents (js/personnalisation.js)
   Chargée après atelier.css. Aussi chargée, avec les jetons, dans le document
   d'impression (js/impression.js) : tout ce qui met en forme un document vit ici
   une seule fois, pour l'écran et pour le papier.

   Sty.perso pose sur la racine :
     --perso-*                 les valeurs choisies (elles pointent vers les jetons)
     data-perso="clé clé…"     ce qui est réglé (rien d'autre n'est touché)
     data-perso-tableau        grille | lignes | zebre | entete
     data-perso-frise          horizontale | tableau        (absent : frise verticale)
     data-perso-justifie       texte justifié à l'écran

   1. Le corps du texte et la hiérarchie des titres
   2. Les tableaux
   3. Les frises chronologiques
   4. Les encadrés et les objets insérés
   5. Le surligneur : légende
   6. L'écran Réglages → Personnalisation
   ============================================================ */

/* ----------------------------------------------------------
   0. Atlas (12/11/2026) : les valeurs par défaut d'un document
      Alegreya pour le texte et les titres, interligne de lecture, texte justifié sur une colonne large et aligné
      à gauche sur une colonne étroite (téléphone), titre de point en italique, tableaux et frises d'Atlas.
      Tout ce qui est réglé dans Réglages → Personnalisation (data-perso*, --perso-*) passe toujours devant.
      À l'écran seulement : le PDF (js/impression.js) garde sa propre mise en page.
   ---------------------------------------------------------- */
@media screen {
  .texte-cours, .texte-cours :is(h2, h3, h4) { font-family: var(--font-titre); }
  .texte-cours :is(p, li, blockquote, dd) { hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; }
  .texte-cours h4 { font-style: italic; }
}
@media screen and (min-width: 768px) { .texte-cours :is(p, blockquote > p) { text-align: justify; } }

/* ----------------------------------------------------------
   1. Le corps du texte et la hiérarchie des titres
   ---------------------------------------------------------- */
:root[data-perso~="texte-police"] :is(.texte-cours, .texte-cours :is(p, ul, ol, li, h2, h3, h4, blockquote, dl)) { font-family: var(--perso-texte-police); }
:root[data-perso~="texte-couleur"] :is(.texte-cours, .texte-cours :is(p, ul, ol, h2, h3, h4)):not(.meta, .surligne) { color: var(--perso-texte-couleur); }
/* Titre de sous-partie, sous-section, point : même échelle à l'écran et sur le papier (jetons --doc-echelle-*). */
.texte-cours :is(h2, h3, h4) { font-weight: 600; line-height: var(--doc-interligne-titre); letter-spacing: var(--tr-heading); text-align: start; hyphens: manual; text-wrap: balance; }
.texte-cours h2 { font-size: calc(1em * var(--doc-echelle-h2)); }
.texte-cours h3 { font-size: calc(1em * var(--doc-echelle-h3)); }
.texte-cours h4 { font-size: calc(1em * var(--doc-echelle-h4)); }
:root[data-perso-justifie] .texte-cours :is(p, li):not(.surligne) { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }

/* ----------------------------------------------------------
   2. Les tableaux (dans un document, et les tableaux générés)
      Une frise (table.frise) n'est pas un tableau : elle a ses propres réglages, section 3.
   ---------------------------------------------------------- */
:root[data-perso~="tableau-police"] :is(.texte-cours table:not(.frise), .tableau-objet),
:root[data-perso~="tableau-police"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { font-family: var(--perso-tableau-police); }
:root[data-perso~="tableau-couleur"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { color: var(--perso-tableau-couleur); }
:root[data-perso~="tableau-bordure"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { border-color: var(--perso-tableau-bordure); }
:root[data-perso~="tableau-cases"] :is(.texte-cours table:not(.frise), .tableau-objet) td { background: var(--perso-tableau-cases); }
:root[data-perso~="tableau-colonne"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(td:first-child, th[scope="row"]) { background: var(--perso-tableau-colonne); }
:root[data-perso~="tableau-entete"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(thead th, tr:first-child > th:not([scope="row"])) { background: var(--perso-tableau-entete); }

/* 2a. Par défaut (structure « Trame ») : le tableau d'Atlas. Des filets entre les lignes, l'en-tête sur la feuille en
       retrait, la colonne des intitulés en encre 2, du texte qui passe à la ligne plutôt que de déborder. */
@media screen {
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) { width: 100%; border-collapse: collapse; font-family: var(--font-texte); font-size: var(--t-s); line-height: var(--lh-ui); }
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { padding: var(--s-3); border: 0; border-top: var(--w-trait) solid var(--c-line); text-align: left; vertical-align: top; overflow-wrap: anywhere; hyphens: auto; color: var(--c-ink); }
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) tr:first-child > :is(th, td) { border-top: 0; }
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) :is(thead th, tr:first-child > th:not([scope="row"])) { background: var(--c-surface-2); font-weight: var(--fw-fort); }
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) tbody th { font-weight: var(--fw-fort); color: var(--c-ink-2); background: transparent; }
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) td + td,
  :root:not([data-perso-tableau]) :is(.texte-cours table:not(.frise), .tableau-objet) th + th { border-left: 0; }
}
@media screen and (min-width: 1100px) { :root:not([data-perso-tableau]) .texte-cours table:not(.frise) { font-size: var(--t-m); } :root:not([data-perso-tableau]) .texte-cours table:not(.frise) :is(th, td) { padding: var(--s-3) var(--s-4); } }

/* Structures types. Le filet : la couleur choisie, sinon celui de Trame. */
:root[data-perso-tableau] :is(.texte-cours table:not(.frise), .tableau-objet) { border-collapse: collapse; }
:root[data-perso-tableau] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { border: 0 solid var(--perso-tableau-bordure, var(--c-line-strong)); }
:root[data-perso-tableau="grille"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { border-width: var(--size-filet); }
:root[data-perso-tableau="lignes"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td),
:root[data-perso-tableau="zebre"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td),
:root[data-perso-tableau="entete"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(th, td) { border-bottom-width: var(--size-filet); }
:root[data-perso-tableau="lignes"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(thead th, tr:first-child > th:not([scope="row"])),
:root[data-perso-tableau="zebre"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(thead th, tr:first-child > th:not([scope="row"])) { border-bottom-width: var(--size-filet-epais); }
:root[data-perso-tableau="lignes"]:not([data-perso~="tableau-entete"]) :is(.texte-cours table:not(.frise), .tableau-objet) th,
:root[data-perso-tableau="zebre"]:not([data-perso~="tableau-entete"]) :is(.texte-cours table:not(.frise), .tableau-objet) th { background: none; }
:root[data-perso-tableau="zebre"] :is(.texte-cours table:not(.frise), .tableau-objet) tbody tr:nth-child(even) > :is(td, th) { background: var(--perso-tableau-cases, var(--c-perso-fond-doux)); }
:root[data-perso-tableau="zebre"][data-perso~="tableau-cases"] :is(.texte-cours table:not(.frise), .tableau-objet) tbody tr:nth-child(odd) > td { background: none; }
:root[data-perso-tableau="entete"] :is(.texte-cours table:not(.frise), .tableau-objet) :is(thead th, tr:first-child > th:not([scope="row"])) {
  background: var(--perso-tableau-entete-plein, var(--c-perso-encre)); color: var(--c-perso-papier); border-bottom-width: 0; }

/* ----------------------------------------------------------
   3. Les frises chronologiques
      Deux écritures, un seul dessin : <table class="frise"> dans un document enregistré
      (une ligne = date, fait) et <ol class="chrono"> pour une chronologie générée.
   ---------------------------------------------------------- */
table.frise, .chrono, table.frise td { font-family: var(--perso-frise-police, inherit); }
:root[data-perso~="frise-couleur"] :is(table.frise td, .chrono, .chrono__titre, .chrono__detail) { color: var(--perso-frise-couleur); }
table.frise td:first-child, .chrono__date { color: var(--perso-frise-date, var(--c-accent-text)); font-weight: 600; }
/* Atlas : la date en Alegreya, en encre ; le fait en encre 2, plus petit. */
@media screen {
  table.frise td:first-child, .chrono__date { font-family: var(--perso-frise-police, var(--font-titre)); font-size: var(--t-l); font-weight: var(--fw-titre); line-height: var(--lh-titre); color: var(--perso-frise-date, var(--c-ink)); font-variant-numeric: lining-nums tabular-nums; }
  table.frise td:not(:first-child), .chrono__detail { font-family: var(--perso-frise-police, var(--font-texte)); font-size: var(--t-s); line-height: var(--lh-ui); color: var(--perso-frise-couleur, var(--c-ink-2)); }
}

/* 3a. Frise verticale (par défaut) et frise horizontale : le tableau cesse d'être un tableau. */
:root:not([data-perso-frise="tableau"]) table.frise { display: block; width: 100%; border: 0; }
:root:not([data-perso-frise="tableau"]) table.frise thead { position: absolute; width: var(--size-filet); height: var(--size-filet); overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:root:not([data-perso-frise="tableau"]) table.frise tbody { display: block; }
:root:not([data-perso-frise="tableau"]) table.frise :is(td, th) { display: block; border: 0; padding: 0; background: none; min-width: 0; }
:root:not([data-perso-frise="tableau"]) :is(table.frise tr, .chrono > li) { position: relative; }
:root:not([data-perso-frise="tableau"]) :is(table.frise tr, .chrono > li)::before { content: ''; position: absolute; background: var(--perso-frise-ligne, var(--c-line-strong)); }
:root:not([data-perso-frise="tableau"]) :is(table.frise tr, .chrono > li)::after { content: ''; position: absolute; width: var(--size-frise-repere); height: var(--size-frise-repere); border-radius: 50%;
  background: var(--perso-frise-repere, var(--c-accent)); }
/* Atlas : le repère est un anneau ocre posé sur la feuille (la couleur choisie, s'il y en a une). */
@media screen { :root:not([data-perso-frise="tableau"]) :is(table.frise tr, .chrono > li)::after { background: var(--c-surface); box-shadow: inset 0 0 0 var(--w-trait-fort) var(--perso-frise-repere, var(--c-ocre-fill)); } }

/* verticale */
:root:not([data-perso-frise]) .chrono { gap: 0; }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li) { display: grid; grid-template-columns: var(--size-frise-date) minmax(0, 1fr); column-gap: var(--s-8); padding: var(--s-2) 0; }
:root:not([data-perso-frise]) :is(table.frise td:first-child, .chrono__date) { text-align: right; }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li)::before { left: calc(var(--size-frise-date) + var(--s-4) - var(--size-frise-ligne) / 2); top: 0; bottom: 0; width: var(--size-frise-ligne); }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li)::after { left: calc(var(--size-frise-date) + var(--s-4) - var(--size-frise-repere) / 2); top: var(--s-4); top: calc(var(--s-2) + 0.5lh - var(--size-frise-repere) / 2); }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li):first-child::before { top: var(--s-4); }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li):last-child::before { bottom: auto; height: var(--s-4); }
:root:not([data-perso-frise]) :is(table.frise tr, .chrono > li):only-child::before { display: none; }

/* horizontale : les étapes se suivent ; trop nombreuses, elles défilent (à l'écran) ou passent à la ligne (papier) */
:root[data-perso-frise="horizontale"] :is(table.frise tbody, .chrono) { display: flex; flex-direction: row; align-items: flex-start; gap: 0; overflow-x: auto; padding-bottom: var(--s-2); }
:root[data-perso-frise="horizontale"] :is(table.frise tr, .chrono > li) { display: flex; flex-direction: column; gap: var(--s-1); flex: 1 0 var(--size-frise-etape); max-width: calc(2 * var(--size-frise-etape));
  padding: calc(var(--size-frise-repere) + var(--s-3)) var(--s-4) 0 0; }
:root[data-perso-frise="horizontale"] :is(table.frise tr, .chrono > li)::before { left: 0; right: 0; top: calc(var(--size-frise-repere) / 2 - var(--size-frise-ligne) / 2); height: var(--size-frise-ligne); }
:root[data-perso-frise="horizontale"] :is(table.frise tr, .chrono > li)::after { left: 0; top: 0; }
@media print { :root[data-perso-frise="horizontale"] :is(table.frise tbody, .chrono) { flex-wrap: wrap; overflow: visible; row-gap: var(--s-4); } }
table.frise, .chrono, :is(table.frise tr, .chrono > li) { break-inside: avoid; }

/* 3b. En tableau : la chronologie générée prend, elle aussi, des lignes. */
:root[data-perso-frise="tableau"] .chrono { gap: 0; }
:root[data-perso-frise="tableau"] .chrono > li { padding: var(--s-2) 0; border-bottom: var(--size-filet) solid var(--perso-frise-ligne, var(--c-line)); }
:root[data-perso-frise="tableau"] table.frise :is(th, td) { border-color: var(--perso-frise-ligne, var(--c-line)); }

/* ----------------------------------------------------------
   4. Les encadrés et les objets insérés (citations, compléments, fiches, cartes d'objet)
      Les couleurs de statut (« À vérifier ») ne changent pas : elles portent un sens.
   ---------------------------------------------------------- */
:root[data-perso~="encadre-police"] :is(.texte-cours blockquote, .texte-cours blockquote :is(p, li), .objet__corps, .objet__corps :is(p, li, dt, dd, .fiche__texte), .direct-objet figcaption) { font-family: var(--perso-encadre-police); }
:root[data-perso~="encadre-couleur"] :is(.texte-cours blockquote, .objet__corps, .objet__corps :is(p, li, dt, dd, .fiche__texte), .direct-objet figcaption) { color: var(--perso-encadre-couleur); }
:root[data-perso~="encadre-fond"] :is(.texte-cours blockquote, .objet__corps, .direct-objet, .fiche) { background: var(--perso-encadre-fond); }
:root[data-perso~="encadre-bord"] :is(.texte-cours blockquote, .objet, .direct-objet, .fiche) { border-color: var(--perso-encadre-bord); }

/* ----------------------------------------------------------
   5. Le surligneur : la palette de l'éditeur dit à quoi sert chaque couleur
   ---------------------------------------------------------- */
.palette-surlignage--code { min-width: var(--size-ia-modes); }
.palette-surlignage--code .palette-surlignage__pastilles { flex-direction: column; gap: 0; }
.palette-surlignage__ligne { display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: var(--size-touch); padding: var(--s-1) var(--s-2); border: var(--size-filet-epais) solid transparent;
  border-radius: var(--r-md); background: none; color: var(--c-ink); font: var(--t-ui); text-align: left; cursor: pointer; }
.palette-surlignage__ligne > span:first-child { flex: none; width: var(--s-6); height: var(--s-6); border-radius: 50%; box-shadow: inset 0 0 0 var(--size-filet) var(--c-line-strong); }
.palette-surlignage__ligne b { font-weight: 600; }
.palette-surlignage__ligne small { display: block; font: var(--t-small); color: var(--c-ink-2); }
.palette-surlignage__ligne[aria-checked="true"] { border-color: var(--c-accent); }
.palette-surlignage__ligne:hover { background: var(--c-tile); }
.palette-surlignage__ligne:focus-visible { outline: var(--size-filet-epais) solid var(--c-accent); outline-offset: var(--size-filet); }
.palette-surlignage__regler { display: block; padding: var(--s-2); font: var(--t-small); color: var(--c-accent-text); text-decoration: underline; }
.palette-surlignage__regler:focus-visible { outline: var(--size-filet-epais) solid var(--c-accent); outline-offset: var(--size-filet); border-radius: var(--r-sm); }

.perso-legende { display: inline-flex; flex-wrap: wrap; gap: var(--s-1) var(--s-2); vertical-align: middle; }
.perso-legende__item { padding: 0 var(--s-2); border-radius: var(--r-xs); color: var(--c-ink); font: var(--t-small); }
.perso-code-rappel { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); font: var(--t-small); color: var(--c-ink-2); }
.perso-code-rappel a { color: var(--c-accent-text); text-decoration: underline; }

/* ----------------------------------------------------------
   6. Réglages → Personnalisation
   ---------------------------------------------------------- */
/* La page s'élargit pour loger l'aperçu à côté des réglages ; sous 1280 px, l'aperçu passe au-dessus et reste visible en défilant. */
.reglages__page:has(> .perso) { max-width: calc(var(--size-read) + var(--size-perso-apercu) + 2 * var(--s-12)); }
.perso { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.perso__apercu { order: -1; }
@media (min-width: 1280px) { .perso { grid-template-columns: minmax(0, 1fr) minmax(0, var(--size-perso-apercu)); } .perso__apercu { order: 0; position: sticky; top: var(--s-6); max-height: calc(100vh - 2 * var(--s-6)); overflow-y: auto; } }
.perso__reglages { display: flex; flex-direction: column; gap: var(--s-6); min-width: 0; container-type: inline-size; }
.perso__reglages .reglages-carte { margin: 0; }
.perso-champ { display: grid; grid-template-columns: minmax(0, var(--size-perso-libelle)) minmax(0, 1fr); gap: var(--s-2) var(--s-4); align-items: center; padding: var(--s-3) 0; border: 0; margin: 0; min-width: 0; }
.perso-champ + .perso-champ { border-top: var(--size-filet) solid var(--c-line); }
.perso-champ__nom { font: var(--t-ui); font-weight: 500; color: var(--c-ink); padding: 0; }
.perso-champ .sty-select { width: 100%; min-height: var(--size-touch); }
@container (max-width: 460px) { .perso-champ { grid-template-columns: minmax(0, 1fr); } }

/* Les pastilles de couleur : de vrais boutons radio, le nom de la couleur en infobulle et pour les lecteurs d'écran. */
.perso-couleurs { display: flex; flex-wrap: wrap; gap: var(--s-1); min-width: 0; }
.perso-couleur { position: relative; display: inline-grid; place-items: center; width: var(--size-touch); height: var(--size-touch); border-radius: var(--r-md); cursor: pointer; }
.perso-couleur input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.perso-couleur__rond { display: grid; place-items: center; width: var(--size-perso-pastille); height: var(--size-perso-pastille); border-radius: 50%; background: var(--pastille, transparent);
  box-shadow: inset 0 0 0 var(--size-filet) var(--c-line-strong); color: var(--c-ink-2); font: var(--t-micro); }
.perso-couleur__rond--origine { background: none; box-shadow: inset 0 0 0 var(--size-filet-epais) var(--c-control); }
.perso-couleur input:checked + .perso-couleur__rond { outline: var(--size-filet-epais) solid var(--c-accent); outline-offset: var(--size-filet-epais); }
.perso-couleur input:focus-visible + .perso-couleur__rond { outline: var(--size-filet-epais) solid var(--c-ink); outline-offset: var(--size-filet-epais); }
.perso-couleur:hover { background: var(--c-tile); }

/* Les structures types : des cartes à choisir, avec un petit dessin. */
.perso-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--size-perso-libelle), 1fr)); gap: var(--s-2); grid-column: 1 / -1; }
.perso-type { position: relative; display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-3); min-height: var(--size-touch); border: var(--size-filet) solid var(--c-line-strong); border-radius: var(--r-lg);
  background: var(--c-card); cursor: pointer; }
.perso-type input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.perso-type b { font: var(--t-ui); font-weight: 600; color: var(--c-ink); }
.perso-type small { font: var(--t-small); color: var(--c-ink-2); }
.perso-type:has(input:checked) { border-color: var(--c-accent); box-shadow: inset 0 0 0 var(--size-filet) var(--c-accent); background: var(--c-accent-soft); }
.perso-type:has(input:focus-visible) { outline: var(--size-filet-epais) solid var(--c-accent); outline-offset: var(--size-filet-epais); }

/* Le code couleur du surligneur : une ligne par couleur. */
.perso-code { display: flex; flex-direction: column; }
.perso-code__ligne { display: grid; grid-template-columns: minmax(0, var(--size-perso-libelle)) minmax(0, 1fr); gap: var(--s-2) var(--s-4); align-items: center; padding: var(--s-3) 0; }
.perso-code__ligne + .perso-code__ligne { border-top: var(--size-filet) solid var(--c-line); }
.perso-code__couleur { display: flex; align-items: center; gap: var(--s-3); font: var(--t-ui); font-weight: 500; color: var(--c-ink); }
.perso-code__couleur > span { padding: var(--s-1) var(--s-3); border-radius: var(--r-sm); color: var(--c-ink); }
.perso-code__ligne .sty-select { width: 100%; min-height: var(--size-touch); }
.perso-code__aide { grid-column: 2; font: var(--t-small); color: var(--c-ink-2); }
@container (max-width: 460px) { .perso-code__ligne { grid-template-columns: minmax(0, 1fr); } .perso-code__aide { grid-column: 1; } }

/* L'aperçu : une vraie page de cours, mise en forme par les mêmes règles que partout. */
.perso__apercu { min-width: 0; display: flex; flex-direction: column; gap: var(--s-3); }
.perso-page { padding: var(--s-6); border: var(--size-filet) solid var(--c-line); border-radius: var(--r-xl); background: var(--c-page); box-shadow: var(--shadow-default); overflow: hidden; }
.perso-page.texte-cours { font: var(--t-body); font-family: var(--perso-texte-police, var(--font-titre)); }
.perso-page .perso-page__titre { font-size: calc(1em * var(--doc-echelle-h1)); font-weight: 700; line-height: var(--doc-interligne-titre); margin: 0; color: var(--perso-texte-couleur, var(--c-ink)); }
.perso-page > * + * { margin-top: var(--s-3); }
.perso-page table { font: inherit; }
.perso-page .objet { margin: var(--s-3) 0 0; }
.perso-alertes { display: flex; flex-direction: column; gap: var(--s-2); }
.perso-alertes:empty { display: none; }
.perso__pied { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
