/*
 * fiches.css — Fiches de révision (SPECS §9).
 *
 * Trois contextes pour UN même modèle de fiche (.fiche) :
 *   1. l'écran de configuration (#/fiches) : sélection, filtres, format ;
 *   2. le DECK consultable : fil vertical plein écran à défilement par fiche
 *      (scroll-snap, façon Shorts) ;
 *   3. l'IMPRESSION (@media print) : une fiche par page (ou N par page), couleurs
 *      d'encre, masquage du reste de l'app.
 *
 * Tout dérive des tokens de styles/main.css (clair/sombre + palettes), sauf le
 * bloc d'impression qui force des couleurs lisibles à l'encre.
 */

/* ===================== Écran de configuration ============================== */

.fiches-count { margin: 0; }
.small { font-size: 0.85rem; }

/* Sélection des caractéristiques + valeurs de filtre : cases à cocher en ligne. */
.fiches-cols { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.fiches-format { align-items: flex-end; gap: 16px; }

/* Carte « Filtrer » repliable (repliée par défaut) : le titre vit dans le <summary>,
   avec un chevron explicite qui pivote à l'ouverture (le marqueur natif est masqué). */
.fiches-filter-card > summary {
  cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none;
}
.fiches-filter-card > summary::-webkit-details-marker { display: none; }
.fiches-filter-card .chevron { color: var(--muted); transition: transform var(--speed); }
.fiches-filter-card[open] > summary .chevron { transform: rotate(90deg); }
h2.inline { display: inline; margin: 0; }

/* Aperçu des caractéristiques d'un gabarit. Les chips placées sont cliquables
   (retirer/remettre dans la génération) ; les chips RETIRÉES ou NON PLACÉES sont
   grisées mais gardent le repère ambre des colonnes identifiantes (.col-id). */
.chip.readonly { cursor: default; }
.overview-chip.clickable { cursor: pointer; }
.overview-chip.is-out { opacity: 0.5; border-style: dashed; }
.overview-chip.is-out > span { text-decoration: line-through; }

/* Compartiments de colonnes (identifiantes / descriptives). */
.fiches-col-group { gap: 6px; }
.group-label { margin: 0; font-weight: 600; }

/* Repère des colonnes identifiantes (#nature = identifier/key) — ambre. */
.chip.col-id, .chip-check.col-id { background: var(--id-soft); border-color: var(--id); }
.check.col-id > span, .fiches-field-name.col-id { color: var(--id); font-weight: 600; }
.fiches-filter.col-id > summary > span:first-child { color: var(--id); font-weight: 600; }
/* Texte ambre aussi dans les chips de la réserve (au-delà du fond), et liseré
   ambre sur la rangée d'un champ identifiant — pour qu'aucun contexte de
   l'éditeur n'oublie de mettre en avant les colonnes identifier/key. */
.chip.col-id > span:not(.drag-handle) { color: var(--id); font-weight: 600; }
.fiches-field-row:has(.fiches-field-name.col-id) { border-left: 3px solid var(--id); }

/* Résumé du paramétrage. */
.fiche-summary-line { margin: 0; }

/* Filtres : un <details> par colonne. */
.fiches-filter { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; }
.fiches-filter > summary {
  cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px;
  list-style-position: inside;
}
.fiches-filter[open] > summary { margin-bottom: 8px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; padding: 0 6px; height: 1.5em;
  background: var(--accent); color: var(--on-accent);
  border-radius: 999px; font-size: 0.8rem; font-weight: 700;
}
.fiches-filter-values { display: flex; flex-wrap: wrap; gap: 6px; }

/* Une valeur de filtre = puce cliquable ; grisée si la cocher ne laisserait
   aucune ligne (grisage dynamique, SPECS §7). */
.chip-check {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 0.9rem;
}
.chip-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.chip-check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.chip-check.unavailable { opacity: 0.4; cursor: not-allowed; }

/* ===================== Modèle de fiche (.fiche) ============================ */

.fiche {
  /* Interlignage (multiplicateur des écarts) et densité (réduite en compact). */
  --fiche-space: 1;
  --fiche-density: 1;
  --fiche-gap: calc(14px * var(--fiche-space));
  /* Couleurs de rôle (surchargées en ligne par l'éditeur) — par défaut elles
     suivent la palette effective de la fiche. */
  --fiche-accent: var(--accent);
  --fiche-title-rule: var(--fiche-accent); /* barre sous le titre */
  --fiche-title: var(--text);
  --fiche-subtitle: var(--muted);
  --fiche-label: var(--muted);
  --fiche-box-title: var(--fiche-accent);
  --fiche-box-bg: var(--surface-2);
  --fiche-box-border: var(--border);
  --fiche-box-bw: 1px;            /* épaisseur de bordure d'encadré */
  --fiche-text: var(--text);
  --fiche-sep: var(--border);
  background: var(--surface);
  /* Cadre global (#7) : surchargé en ligne par l'éditeur ; défauts = look standard. */
  border: var(--fiche-frame-bw, 1px) var(--fiche-frame-style, solid) var(--fiche-frame-color, var(--border));
  border-radius: var(--fiche-frame-radius, var(--radius));
  box-shadow: var(--shadow);
  padding: 20px 22px;
  color: var(--fiche-text);
  /* Échelle de police globale (préserve les ratios) × densité (compact). */
  font-size: calc(1rem * var(--fiche-scale, 1) * var(--fiche-density));
  display: flex; flex-direction: column; gap: var(--fiche-gap);
  position: relative; /* ancre le QR code en coin */
}

/* Corps (encadrés) : pile verticale, ou 2 colonnes de page si demandé. */
.fiche-body { display: flex; flex-direction: column; gap: var(--fiche-gap); }
.fiche-body.fiche-cols { display: block; column-count: 2; column-gap: 18px; }
.fiche-body.fiche-cols > * { break-inside: avoid; margin-bottom: var(--fiche-gap); }

/* QR code (vers le quiz du périmètre). Positions :
   - pos-header : dans le slot droit de l'en-tête (flux) → le trait sous le titre,
     porté par .fiche-head-text, s'arrête naturellement avant lui ; il est
     dimensionné en JS à la hauteur du titre (bas du QR ≈ fin du trait) ;
   - pos-page-br : bas-droite de la page (quand une photo occupe la bannière) ;
   - pos-top-left : coin absolu ; pos-below : sous l'en-tête. */
.fiche-qr { display: flex; flex-direction: column; align-items: center; line-height: 0; }
.fiche-qr svg { display: block; border-radius: 4px; background: #fff; }
/* Légende optionnelle sous le QR. */
.fiche-qr-cap { margin-top: 3px; line-height: 1.1; font-size: 0.58rem; text-align: center; color: var(--fiche-label); letter-spacing: 0.02em; max-width: 100px; }
.fiche-qr.pos-header { flex: 0 0 auto; align-self: flex-start; }
.fiche-qr.pos-page-br { position: absolute; bottom: 16px; right: 18px; }
.fiche-qr.pos-top-left { position: absolute; top: 16px; left: 18px; }
.fiche-qr.pos-below { margin: 2px 0; }
@media (max-width: 520px) {
  .fiche-qr.pos-top-left { position: static; margin-top: 8px; }
}

/* Filigranes de fond (subtils, derrière le contenu). */
.fiche.wm-dots { background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px); background-size: 14px 14px; }
.fiche.wm-grid {
  background-image: linear-gradient(color-mix(in srgb, var(--muted) 18%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--muted) 18%, transparent) 1px, transparent 1px);
  background-size: 18px 18px;
}
.fiche.wm-diagonal { background-image: repeating-linear-gradient(45deg, color-mix(in srgb, var(--muted) 16%, transparent) 0 1px, transparent 1px 12px); }

/* Texte à trous : valeur masquée (barre grise), révélée au clic. */
.fiche.cloze-mode .cloze:not(.revealed) {
  color: transparent; background: var(--surface-2); border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--border); cursor: pointer; padding: 0 6px;
}
.fiche.cloze-mode .cloze:not(.revealed) .chip { color: transparent; background: var(--surface-2); border-color: var(--border); }

/* Légende automatique des teintes conditionnelles. */
.fiche-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--fiche-sep);
}
.fiche-legend-title { font-weight: 700; color: var(--fiche-label); text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.72rem; }
.fiche-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; }
.fiche-legend-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.15); display: inline-block; }
.fiche.compact { --fiche-density: 0.92; --fiche-gap: calc(8px * var(--fiche-space)); padding: 14px 16px; }

/* Cadre global désactivable / sans ombre (#7). */
.fiche.no-frame { border-color: transparent; border-width: 0; }
.fiche.no-shadow { box-shadow: none; }
/* Bande d'accent latérale (gauche), suivant les coins arrondis de la fiche. */
.fiche.accent-bar { overflow: hidden; }
.fiche.accent-bar::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  background: var(--fiche-accent-bar, var(--fiche-accent));
}

/* Familles de police (polices système, sans dépendance). */
.fiche.ff-serif { font-family: Georgia, 'Times New Roman', Cambria, serif; }
.fiche.ff-mono { font-family: ui-monospace, 'Cascadia Code', Consolas, 'Courier New', monospace; }

/* Tailles de police : base par élément × facteur d'élément × échelle × densité. */
.fiche-title { font-size: calc(1.5rem * var(--fiche-f-title, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-subtitle { font-size: calc(1rem * var(--fiche-f-subtitle, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-box-title { font-size: calc(0.95rem * var(--fiche-f-box-title, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-label { font-size: calc(0.72rem * var(--fiche-f-label, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-label.inline { font-size: calc(0.9rem * var(--fiche-f-label, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-value { font-size: calc(1rem * var(--fiche-f-value, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }
.fiche-value.lg { font-size: calc(1.25rem * var(--fiche-f-value, 1) * var(--fiche-scale, 1) * var(--fiche-density)); }

/* En-tête héros : titre + sous-titre à gauche, photo en bandeau à droite. */
.fiche-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.fiche-head-text { min-width: 0; flex: 1; }
.fiche-title {
  margin: 0; line-height: 1.2; color: var(--fiche-title);
  padding-bottom: 8px; border-bottom: 2px solid var(--fiche-title-rule);
}
.fiche-subtitle { margin: 6px 0 0; font-style: italic; color: var(--fiche-subtitle); }

.fiche-hero { margin: 0; flex: 0 0 38%; max-width: 38%; }
.fiche-hero-frame {
  width: 100%; aspect-ratio: var(--fiche-media-ratio, 4 / 3); max-height: var(--fiche-media-maxh, none);
  border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}

/* Grille des caractéristiques : les champs COURTS s'écoulent en colonnes
   (auto-fill), les champs LONGS (.span-full) prennent toute la largeur. */
.fiche-grid {
  display: grid; gap: var(--fiche-gap) 18px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-items: start;
}
.fiche-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fiche-field.span-full { grid-column: 1 / -1; }
.fiche-label {
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--fiche-label); font-weight: 600;
}
/* Casse des libellés forcée (quelle que soit la position dessus/en ligne). */
.fiche.labels-upper .fiche-label, .fiche.labels-upper .fiche-label.inline { text-transform: uppercase; }
.fiche.labels-normal .fiche-label, .fiche.labels-normal .fiche-label.inline { text-transform: none; }
.fiche-value { overflow-wrap: anywhere; }
.fiche-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Fiche de GROUPE : bloc « membres » (valeurs identifiantes de toutes les
   entités du groupe) — chips au repère ambre identifiant, pleine largeur. */
.fiche-members { grid-column: 1 / -1; }
.fiche-members .fiche-chips .chip {
  background: var(--id-soft);
  border: 1px solid color-mix(in srgb, var(--id) 45%, transparent);
}

/* Vue « TABLEAU DES MEMBRES » (group-views/table.js) : une ligne par entité.
   Tout le style est piloté par variables (--gt-*) posées depuis layout.group. */
.fiche-gtable-wrap { grid-column: 1 / -1; overflow-x: auto; }
.fiche-gtable {
  width: 100%; border-collapse: separate; border-spacing: 0;
  border: var(--gt-bw, 1px) var(--gt-bstyle, solid) var(--gt-border, var(--fiche-box-border, var(--border)));
  border-radius: var(--gt-radius, 8px);
  font-size: calc(0.92rem * var(--fiche-f-value, 1) * var(--fiche-scale, 1) * var(--fiche-density));
}
.fiche-gtable.no-outer { border: 0; border-radius: 0; }
.fiche-gtable th, .fiche-gtable td {
  padding: calc(5px * var(--gt-pad, 1) * var(--fiche-space, 1)) calc(9px * var(--gt-pad, 1));
  text-align: left; vertical-align: top;
}
.fiche-gtable th {
  color: var(--gt-head-text, var(--fiche-label, var(--muted)));
  background: var(--gt-head-bg, transparent);
  font-size: 0.82em; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  border-bottom: var(--gt-bw, 1px) var(--gt-bstyle, solid) var(--gt-border, var(--fiche-box-border, var(--border)));
}
/* Lignes internes : rangées et/ou colonnes, selon layout.group.lines. */
.fiche-gtable.lines-rows tbody td, .fiche-gtable.lines-both tbody td {
  border-bottom: 1px var(--gt-bstyle, solid) var(--gt-border, var(--fiche-sep, var(--border)));
}
.fiche-gtable.lines-rows tbody tr:last-child td, .fiche-gtable.lines-both tbody tr:last-child td { border-bottom: 0; }
.fiche-gtable.lines-cols th:not(:last-child), .fiche-gtable.lines-cols td:not(:last-child),
.fiche-gtable.lines-both th:not(:last-child), .fiche-gtable.lines-both td:not(:last-child) {
  border-right: 1px var(--gt-bstyle, solid) var(--gt-border, var(--fiche-sep, var(--border)));
}
.fiche-gtable.zebra tbody tr:nth-child(even) td {
  background: var(--gt-zebra, color-mix(in srgb, var(--accent) 6%, var(--surface)));
}
.fiche-gtable td.gt-id { color: var(--id); font-weight: 600; }
.fiche-gtable th.gt-num, .fiche-gtable td.gt-num { text-align: right; }
.fiche-gtable td.gt-em, .fiche-gtable th.gt-em { font-weight: 700; }
/* Largeur par colonne (layout.group.colWidths) : étroite = au contenu,
   large = colonne dominante (textes longs), les autres se partagent le reste. */
.fiche-gtable th.gt-w-narrow, .fiche-gtable td.gt-w-narrow { width: 1%; white-space: nowrap; }
.fiche-gtable th.gt-w-wide, .fiche-gtable td.gt-w-wide { width: 36%; }
.fiche-gtable td.gt-empty { opacity: 0.45; }
.fiche-gtable tfoot td {
  border-top: var(--gt-bw, 1px) var(--gt-bstyle, solid) var(--gt-border, var(--fiche-box-border, var(--border)));
  font-weight: 600; color: var(--fiche-label, var(--muted));
}
.fiche-gtable .gt-foot-label { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.03em; }
/* « Texte à trous » PAR COLONNE du tableau (indépendant du cloze global) :
   cellule masquée, révélée au clic ; ligne à compléter à l'impression. */
.fiche-gtable td.gt-cloze:not(.revealed) {
  color: transparent; background: var(--surface-2); cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--border);
}

/* Vue « MOSAÏQUE » (group-views/mosaic.js) : grille de vignettes légendées. */
.fiche-mosaic-wrap { grid-column: 1 / -1; }
.fiche-mosaic { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(var(--mosaic-w, 120px), 1fr)); }
.fiche-mosaic.size-s { --mosaic-w: 88px; }
.fiche-mosaic.size-l { --mosaic-w: 170px; }
.fiche-mosaic-item { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.fiche-mosaic-frame { aspect-ratio: 1 / 1; overflow: hidden; border-radius: var(--radius-sm); background: var(--surface-2); }
/* Les conteneurs internes du média (media-box/slot) remplissent le cadre 1:1. */
.fiche-mosaic-frame .media-box, .fiche-mosaic-frame .media-slot { height: 100%; }
.fiche-mosaic-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fiche-mosaic-frame .media-attribution, .fiche-mosaic-frame .media-source { display: none; } /* crédits illisibles en vignette */
.fiche-mosaic-cap { font-size: 0.78rem; text-align: center; color: var(--fiche-text, var(--text)); overflow-wrap: anywhere; }
.fiche.cloze-mode .fiche-mosaic-cap.cloze:not(.revealed) { color: transparent; background: var(--surface-2); border-radius: 4px; cursor: pointer; }

/* Cadre média à RATIO FIXE : homogénéise des images de tailles différentes
   (object-fit: cover recadre sans déformer). */
.fiche-media { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.fiche-media-frame {
  width: 100%; max-width: 420px; aspect-ratio: var(--fiche-media-ratio, 4 / 3); max-height: var(--fiche-media-maxh, none);
  border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
/* Ratio « libre » : le cadre épouse la hauteur de l'image (pas de recadrage),
   globalement (.fiche.mr-free) ou par champ (.fiche-media-frame.mr-free-frame). */
.fiche.mr-free .fiche-hero-frame, .fiche.mr-free .fiche-media-frame, .fiche-media-frame.mr-free-frame { aspect-ratio: auto; }
.fiche.mr-free .fiche-hero-frame img, .fiche.mr-free .fiche-hero-frame .fiche-img, .fiche.mr-free .fiche-hero-frame .media,
.fiche.mr-free .fiche-media-frame img, .fiche.mr-free .fiche-media-frame .fiche-img, .fiche.mr-free .fiche-media-frame .media,
.fiche-media-frame.mr-free-frame img, .fiche-media-frame.mr-free-frame .fiche-img, .fiche-media-frame.mr-free-frame .media {
  height: auto; object-fit: contain;
}
.fiche-hero-frame .fiche-img, .fiche-hero-frame .media, .fiche-hero-frame img,
.fiche-aside-frame .fiche-img, .fiche-aside-frame .media, .fiche-aside-frame img,
.fiche-media-frame .fiche-img, .fiche-media-frame .media, .fiche-media-frame img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

/* Image « sous le bandeau » : ~50 % à côté du 1er encadré. Le cadre s'étire à la
   hauteur de l'encadré voisin (align-items: stretch) mais est PLAFONNÉ à la
   hauteur de l'image (--aside-cap, posée en JS par capAsideToImage) : il ne
   déborde donc plus en grand cadre vide quand l'encadré est court. */
.fiche-aside-row { display: flex; gap: 16px; align-items: stretch; }
.fiche-aside { margin: 0; flex: 0 0 var(--fiche-aside-w, 48%); max-width: var(--fiche-aside-w, 48%); display: flex; flex-direction: column; }
.fiche-aside-frame {
  flex: 1; min-height: 0; width: 100%; max-height: var(--aside-cap, none);
  border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
.fiche-aside-row > .fiche-box { flex: 1; min-width: 0; }
@media (max-width: 540px) {
  .fiche-aside-row { flex-direction: column; align-items: stretch; }
  .fiche-aside { max-width: 100%; flex-basis: auto; width: 100%; }
  /* Empilé : on rend une vignette paysage classique plutôt qu'un cadre étiré. */
  .fiche-aside-frame { flex: none; max-height: none; aspect-ratio: 4 / 3; }
}

/* Fond du cadre photo désactivable (layout.mediaFrameBg = false) : cadre
   « invisible », l'image flotte sans aplat gris. */
.fiche.no-media-bg .fiche-hero-frame,
.fiche.no-media-bg .fiche-aside-frame,
.fiche.no-media-bg .fiche-media-frame { background: transparent; }
.fiche-media-frame audio { width: 90%; height: auto; }
.fiche-media-na { padding: 12px; text-align: center; }

/* Petite largeur : l'en-tête passe en colonne (photo sous le titre). */
@media (max-width: 540px) {
  .fiche-head { flex-direction: column; }
  .fiche-hero { max-width: 100%; flex-basis: auto; width: 100%; }
}

/* ===================== Deck consultable (scroll-snap) ===================== */

.fiches-deck-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg); display: flex; flex-direction: column;
}
.fiches-deck-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex: none;
}
.fiches-deck-list {
  flex: 1; overflow-y: auto; scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
}
.fiches-deck-page {
  min-height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; box-sizing: border-box;
}
/* Deck HORIZONTAL (gabarit en paysage) : une fiche par écran, balayage latéral. */
.fiches-deck-list.deck-h {
  display: flex; flex-direction: row;
  overflow-y: hidden; overflow-x: auto; scroll-snap-type: x mandatory;
}
.fiches-deck-list.deck-h .fiches-deck-page {
  flex: 0 0 100%; min-height: 0; height: 100%;
  overflow-y: auto; /* une fiche plus haute que l'écran reste lisible */
}
.fiches-deck-page .fiche { width: 100%; max-width: 560px; }
/* Orientation PAYSAGE du gabarit : la fiche s'élargit (deck, aperçu éditeur) —
   la largeur gagnée profite au tableau des membres et aux encadrés multi-colonnes. */
.fiches-deck-page .fiche.landscape { max-width: 940px; }
@media (prefers-reduced-motion: reduce) { .fiches-deck-list { scroll-behavior: auto; } }

/* ===================== Impression (PDF) =================================== */

/* Caché à l'écran : n'existe que pour l'impression. */
.fiches-print { display: none; }

@media print {
  /* Ne montrer que les fiches : l'app entière disparaît. Exception mutuelle
     avec l'impression du QR d'instance (.qr-print, styles/main.css). */
  body > *:not(.fiches-print):not(.qr-print) { display: none !important; }
  .fiches-print { display: block; }
  /* Imposer le rendu des aplats (fonds d'encadrés, accents…) à l'imprimante. */
  .fiches-print, .fiches-print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Couleurs FIDÈLES (SPECS §9, Lot 7) : sur fond blanc, les rôles laissés sur
     « Défaut » reçoivent ICI une valeur d'ENCRE (lisible dans les deux modes) ;
     une couleur CHOISIE est posée en variable --fiche-* EN LIGNE (sur la fiche
     ou sur l'encadré), qui l'emporte sur ces défauts — elle est donc restituée
     telle quelle. Accent et titre d'encadré gardent la couleur de la palette
     (saturée, lisible sur blanc). */
  .fiches-print .fiche {
    --fiche-title: #111; --fiche-subtitle: #555; --fiche-label: #555;
    --fiche-text: #111; --fiche-box-bg: #f4f4f4; --fiche-box-border: #ccc; --fiche-sep: #ccc;
    background: #fff; color: var(--fiche-text); box-shadow: none;
    /* Cadre global : couleur choisie (var en ligne) sinon encre #ccc. */
    border: var(--fiche-frame-bw, 1px) var(--fiche-frame-style, solid) var(--fiche-frame-color, #ccc);
    border-radius: var(--fiche-frame-radius, var(--radius));
    break-inside: avoid;
  }
  .fiches-print .fiche.no-frame { border: 0; }
  .fiches-print .fiche-hero-frame,
  .fiches-print .fiche-aside-frame,
  .fiches-print .fiche-media-frame { background: #f0f0f0; }
  .fiches-print .fiche.no-media-bg .fiche-hero-frame,
  .fiches-print .fiche.no-media-bg .fiche-aside-frame,
  .fiches-print .fiche.no-media-bg .fiche-media-frame { background: transparent; }
  .fiches-print .chip { background: #eee; color: #111; border: 1px solid #ccc; }
  .fiches-print .fiche-box { break-inside: avoid; }
  /* Texte à trous imprimé : ligne vierge à compléter (pas d'aplat). */
  .fiches-print .fiche.cloze-mode .cloze:not(.revealed) { color: transparent !important; background: transparent; box-shadow: none; border-bottom: 1px solid #999; min-width: 90px; display: inline-block; }
  .fiches-print .fiche.cloze-mode .cloze:not(.revealed) .chip { color: transparent !important; background: transparent; border-color: #bbb; }
  /* Colonne à trous du tableau des membres : cellule vierge à compléter. */
  .fiches-print .fiche-gtable td.gt-cloze:not(.revealed) { color: transparent !important; background: transparent; box-shadow: none; border-bottom: 1px solid #999; }
  .fiches-print .fiche-gtable-wrap { overflow-x: visible; }
  /* Grand tableau (50+ membres) : il PEUT se couper entre deux pages — chaque
     ligne reste insécable et l'EN-TÊTE se répète en haut de chaque page
     (table-header-group, comportement natif du navigateur). */
  .fiches-print .fiche-gtable { break-inside: auto; }
  .fiches-print .fiche-gtable thead { display: table-header-group; break-inside: avoid; }
  .fiches-print .fiche-gtable tr { break-inside: avoid; }
  /* 2 colonnes de page à l'impression. */
  .fiches-print .fiche-body.fiche-cols { column-count: 2; column-gap: 8mm; }

  /* 1 fiche par page : saut de page après chaque fiche. */
  .fiches-print[data-perpage="1"] .fiche { break-after: page; }
  .fiches-print[data-perpage="1"] .fiche:last-of-type { break-after: auto; }

  /* 2 par page : empilées, l'évitement de coupure les répartit (~2/page). */
  .fiches-print[data-perpage="2"] .fiche { margin-bottom: 6mm; }

  /* 4 par page : grille 2 colonnes (~4/page via break-inside: avoid). */
  .fiches-print[data-perpage="4"] { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
  /* 4-up : on réduit la DENSITÉ (préserve les ratios et respecte les tailles choisies). */
  .fiches-print[data-perpage="4"] .fiche { padding: 12px 14px; --fiche-density: 0.8; }
}

/* ===================== Encadrés (gabarit personnalisé) ==================== */

.fiche-box { display: flex; flex-direction: column; gap: calc(8px * var(--fiche-space, 1)); }
.fiche-box.bordered { border: var(--fiche-box-bw, 1px) var(--fiche-box-bstyle, solid) var(--fiche-box-border); border-radius: var(--fiche-box-radius, var(--radius-sm)); padding: calc(12px * var(--fiche-box-pad, 1)) calc(14px * var(--fiche-box-pad, 1)); }
.fiche-box.filled { background: var(--fiche-box-bg); border-radius: var(--fiche-box-radius, var(--radius-sm)); padding: calc(12px * var(--fiche-box-pad, 1)) calc(14px * var(--fiche-box-pad, 1)); }
.fiche-box-title { margin: 0 0 2px; font-weight: 700; color: var(--fiche-box-title); }
.fiche-box-grid {
  display: grid; gap: calc(10px * var(--fiche-space, 1)) 18px; align-items: start;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}
.fiche-box-grid .fiche-field.span-full { grid-column: 1 / -1; }

/* « Pavé » média : la grille passe en flux DENSE (les autres caractéristiques
   comblent les cellules libres autour du média, pas de perte d'espace). Le média
   remplit la largeur des colonnes qu'il occupe ; sa proportion est conservée par
   le ratio du cadre. L'étendue (grid-column/grid-row: span) est posée en ligne. */
.fiche-box-grid.dense { grid-auto-flow: row dense; }
/* Le pavé REMPLIT les cellules qu'il occupe (étiré à la hauteur du texte adjacent)
   pour ne laisser aucun blanc ; la proportion de l'image est préservée par le
   recadrage (object-fit: cover). */
.fiche-field.media-span { align-self: stretch; }
.fiche-field.media-span .fiche-media { flex: 1; min-height: 0; margin: 0; }
.fiche-field.media-span .fiche-media-frame { height: 100%; max-width: none; width: 100%; aspect-ratio: auto; }

/* Habillage : le média flotte, les caractéristiques de l'encadré s'écoulent
   autour (façon magazine). Le conteneur passe en MULTI-COLONNES (le nombre de
   colonnes de l'encadré, --flow-cols) : le texte habille l'image dans la 1re
   colonne puis continue dans les colonnes suivantes. Un clearfix referme la
   hauteur ; un champ ne se coupe pas entre deux colonnes. */
.fiche-box-flow { column-count: var(--flow-cols, 1); column-gap: 18px; }
.fiche-box-flow > .fiche-field { margin-bottom: calc(8px * var(--fiche-space, 1)); break-inside: avoid; }
.fiche-flow-clear { clear: both; }
.fiche-field.is-float { width: var(--fiche-float-w, 45%); max-width: 100%; }
.fiche-field.is-float.float-left { float: left; margin: 0 16px 8px 0; }
.fiche-field.is-float.float-right { float: right; margin: 0 0 8px 16px; }
@media (max-width: 540px) {
  /* Sur petit écran, le média reprend toute la largeur (pas d'habillage étroit). */
  .fiche-field.is-float { float: none; width: 100%; margin: 0 0 8px; }
}

.fiche-field-line { margin: 0; }
.fiche-label.inline { text-transform: none; letter-spacing: 0; font-weight: 600; }
.fiche-value.b { font-weight: 700; }
.fiche-value.i { font-style: italic; }
.fiche-value.lg { font-weight: 600; }
/* Champ vide rendu « — » (option showEmpty du gabarit) : atténué. */
.fiche-value.is-empty { opacity: 0.45; }

/* Teinte conditionnelle (badge selon la valeur, ex. statut UICN). La couleur
   choisie est posée en variable --tint sur l'élément. */
.fiche-value.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  background: var(--tint); border: 1px solid rgba(0, 0, 0, 0.12);
}
.fiche-chips .chip.tinted { background: var(--tint); border-color: rgba(0, 0, 0, 0.12); }

/* Lignes de séparation optionnelles : un trait court sous chaque champ
   (largeur ~88 % de la colonne). Granulaire (Lot 4) : la classe .has-sep est
   posée par le rendu selon le tri-état champ → encadré → global. */
.fiche-field.has-sep { padding-bottom: calc(8px * var(--fiche-space, 1)); }
.fiche-field.has-sep::after {
  content: ''; display: block; width: 88%; height: 1px;
  margin-top: calc(8px * var(--fiche-space, 1)); background: var(--fiche-sep);
}
.fiche.separators .fiche-box + .fiche-box { border-top: 1px solid var(--fiche-sep); padding-top: 10px; }

/* ===================== Éditeur de mise en page =========================== */

/* L'éditeur sort du conteneur étroit (#app, 720px) pour occuper l'écran. */
.fiches-editor-screen {
  width: min(98vw, 1600px);
  margin-left: 50%;
  transform: translateX(-50%);
}
.fiches-editor {
  display: grid; gap: var(--gap); align-items: start;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
}
/* Gabarit en PAYSAGE : l'aperçu réclame la largeur (la fiche fait ~940 px). */
.fiches-editor.landscape-preview { grid-template-columns: minmax(0, 1fr) minmax(320px, 1.6fr); }
.fiches-editor.no-preview { grid-template-columns: 1fr; }
@media (max-width: 860px) { .fiches-editor { grid-template-columns: 1fr; } }
/* Commutateur de MODE de l'éditeur (haut de page) : deux ateliers — fiches par
   entité / fiches de groupe — pour un seul gabarit. */
.fiches-mode-bar { align-items: center; gap: 10px; margin-bottom: 8px; }
.mode-switch { gap: 0; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.mode-switch .mode-btn {
  border: 0; border-radius: 0; padding: 6px 14px; font-size: 0.9rem;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.mode-switch .mode-btn.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.fiches-editor-preview-wrap { position: sticky; top: 8px; }
.fiches-editor-preview {
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 12px;
}
.fiches-editor-preview .fiche { max-width: 560px; margin: 0 auto; }
.fiches-editor-preview .fiche.landscape { max-width: 940px; }
.fiches-preview-bar { margin-bottom: 8px; gap: 10px 14px; align-items: flex-end; }

/* Aperçu « page » (impression) : feuille blanche au ratio du format choisi,
   rendu fidèle à l'export (mêmes couleurs ; voir @media print). On y voit ce
   qui tient sur une page (débordement masqué). */
.fiches-page-wrap { display: flex; justify-content: center; }
.fiches-page-preview {
  width: 100%; background: #fff; color: #111;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 6mm; box-sizing: border-box; overflow: hidden;
}
.fiches-page-preview[data-perpage="2"] { display: flex; flex-direction: column; gap: 4mm; }
.fiches-page-preview[data-perpage="4"] { display: grid; grid-template-columns: 1fr 1fr; gap: 4mm; }
/* La fiche sur la feuille adopte les couleurs d'impression : fond blanc, encre
   par défaut, MAIS les couleurs choisies (variables --fiche-* posées en ligne)
   l'emportent — l'aperçu reflète donc fidèlement l'export PDF. */
.fiches-page-preview .fiche {
  --fiche-title: #111; --fiche-subtitle: #555; --fiche-label: #555;
  --fiche-text: #111; --fiche-box-bg: #f4f4f4; --fiche-box-border: #ccc; --fiche-sep: #ccc;
  background: #fff; color: var(--fiche-text); box-shadow: none;
  border: var(--fiche-frame-bw, 1px) var(--fiche-frame-style, solid) var(--fiche-frame-color, #ccc);
  border-radius: var(--fiche-frame-radius, var(--radius));
}
.fiches-page-preview .fiche.no-frame { border: 0; }
.fiches-page-preview[data-perpage="4"] .fiche { padding: 12px 14px; font-size: 0.9rem; }

/* Encadrés empilés verticalement — l'éditeur reflète la fiche (les encadrés y
   sont aussi les uns sous les autres ; un encadré occupe toute la largeur). */
.fiches-boxes { display: flex; flex-direction: column; gap: var(--gap); }

.fiches-tray {
  display: flex; flex-wrap: wrap; gap: 8px; min-height: 42px; padding: 8px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
}
.chip.draggable { gap: 6px; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; padding: 0 2px; }
.drag-handle:active { cursor: grabbing; }
.drop-hover { outline: 2px dashed var(--accent); outline-offset: 2px; }
/* Indicateur d'insertion AVANT une rangée de champ (drag&drop intra-encadré). */
.drop-hover-row { box-shadow: inset 0 3px 0 var(--accent); }

.fiches-box-edit { gap: 10px; }
/* Bloc « Couleurs & bordure de l'encadré » repliable. */
.fiches-box-colors > summary { cursor: pointer; display: flex; align-items: center; gap: 6px; list-style: none; color: var(--muted); }
.fiches-box-colors > summary::-webkit-details-marker { display: none; }
.fiches-box-colors .chevron { transition: transform var(--speed); }
.fiches-box-colors[open] > summary .chevron { transform: rotate(90deg); }
.icon-input { width: 70px; text-align: center; }
.fiches-box-head input[type="text"] { flex: 1; min-width: 140px; }
/* Champs d'un encadré : disposés selon le NOMBRE DE COLONNES de l'encadré
   (l'éditeur reflète la fiche). Sur très petite largeur, on retombe à 1 colonne. */
.fiches-box-fields {
  display: grid; gap: 6px; align-items: start;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}
@media (max-width: 560px) { .fiches-box-fields { grid-template-columns: 1fr; } }
.fiches-field-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
}
.fiches-box-empty { grid-column: 1 / -1; }

/* Case COMPOSITE dans l'éditeur : rangée marquée d'un liseré accent, libellé
   éditable en tête, parts (chips de colonnes + segments de texte) listées dans
   un sous-bloc qui est aussi une cible de dépôt. */
.fiches-field-row.comp-row { border-left: 3px solid var(--accent); }
.comp-badge { user-select: none; }
.comp-title-input { flex: 1; min-width: 90px; font-weight: 600; font-size: 0.9rem; }
.comp-parts { gap: 4px; padding: 6px; border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.comp-part { gap: 6px; align-items: center; flex-wrap: wrap; }
.comp-part-kind { min-width: 34px; }
.comp-sep-input { width: 110px; font-size: 0.85rem; }

/* Reflet « pavé » dans l'éditeur : la rangée du média s'étend sur les colonnes
   et porte un badge, pour signaler qu'il occupe plusieurs cellules. */
.fiches-field-row.media-span-row { border-left: 3px solid var(--accent); }
.pave-badge { font-size: 0.7rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 0 7px; white-space: nowrap; }

/* Bloc « Plus de mise en forme » par champ (alignements/casse/police séparés,
   habillage média) — repliable, marqueur natif masqué. */
.fiches-field-more > summary { cursor: pointer; display: flex; align-items: center; gap: 6px; list-style: none; }
.fiches-field-more > summary::-webkit-details-marker { display: none; }
.fiches-field-more .chevron { transition: transform var(--speed); color: var(--muted); }
.fiches-field-more[open] > summary .chevron { transform: rotate(90deg); }
.fiches-field-more > .row { margin-top: 4px; gap: 6px 10px; }
.field-row-main { gap: 6px; align-items: center; }
.field-row-tools { gap: 4px; flex-wrap: wrap; }
.fiches-field-name { flex: 1; font-weight: 600; min-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-field { flex-direction: row; align-items: center; gap: 6px; }
.mini-select { font-size: 0.85rem; max-width: 100%; }
.fmt-toggle { font-weight: 700; min-width: 30px; }
.fmt-toggle.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Barre de gabarits enregistrés (presets) + dialogue « Copier d'une base ». */
.fiche-presets-bar .row { gap: 8px; align-items: center; }
.fiche-copy-dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 18px 20px; max-width: 440px; width: 92vw;
}
.fiche-copy-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.fiche-copy-dialog h3 { margin: 0 0 12px; }
.fiche-copy-dialog .field { margin-bottom: 10px; }
.tint-dialog { max-width: 540px; }
.tint-rows { max-height: 52vh; overflow: auto; }
.tint-val { min-width: 130px; flex: 1; }

/* Bloc « Couleurs » rétractable (chevron, marqueur natif masqué). */
.fiches-color-card > summary {
  cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none;
}
.fiches-color-card > summary::-webkit-details-marker { display: none; }
.fiches-color-card .chevron { color: var(--muted); transition: transform var(--speed); }
.fiches-color-card[open] > summary .chevron { transform: rotate(90deg); }

/* Nuanciers de couleur (rôles de la fiche). */
.color-row { gap: 6px; align-items: center; }
.color-role { min-width: 64px; }
.swatch {
  width: 26px; height: 26px; min-width: 26px; padding: 0; line-height: 1;
  border-radius: 6px; border: 1px solid var(--border); cursor: pointer;
}
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Pastille « color picker complet » (input natif type=color, code hex). */
.swatch-picker { padding: 0; overflow: hidden; cursor: pointer; background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); }
.swatch-picker::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-picker::-webkit-color-swatch { border: none; border-radius: 5px; }
.swatch-picker::-moz-color-swatch { border: none; border-radius: 5px; }

/* ===================== Tactile (cibles élargies) ========================== */

@media (pointer: coarse) {
  .check input[type="checkbox"] { width: 22px; height: 22px; }
  .chip-check { padding: 8px 12px; }
  .chip-check input[type="checkbox"] { width: 20px; height: 20px; }
}
