/* Volet d'aperçu, zone d'état, fiche structurée, fiche complète et mode lecture
   (refonte du suivi, SPEC § 4.4 à 4.6 et § 7). Complète public/css/app.css (jetons
   clair et sombre) et public/css/composants.css (liste dense, zone de travail).
   Aucune règle ne cible un élément nu ni une classe définie ailleurs ; aucun style
   en ligne : le script public/js/pilotage.js ne pose que des classes et des attributs. */

/* --- Volet : colonne collante dès 1600 px, tiroir en dessous ------------------ */
.volet {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--ombre-douce); display: flex; flex-direction: column; min-width: 0;
}
.volet:focus { outline: none; }
@media (min-width: 1600px) {
  .volet {
    position: sticky; top: calc(var(--haut-colle) + 12px);
    max-height: calc(100vh - var(--haut-colle) - var(--hauteur-bandeau) - 24px);
  }
  .volet-fermer { display: none !important; }
  .voile { display: none !important; }
}
@media (max-width: 1599px) {
  .volet {
    position: fixed; z-index: 45; top: var(--hauteur-barre); right: 0; bottom: 0; width: min(600px, 100%);
    border-radius: var(--radius-lg) 0 0 0; box-shadow: var(--ombre-carte);
    transform: translateX(102%); transition: transform 0.18s ease-out; visibility: hidden;
  }
  body.volet-ouvert .volet { transform: none; visibility: visible; }
  .voile { position: fixed; inset: var(--hauteur-barre) 0 0 0; z-index: 44; background: rgba(10, 14, 24, 0.45); }
  .voile[hidden] { display: none; }
  body.mode-lecture .volet { width: min(920px, 100%); }
}
@media (max-width: 640px) {
  .volet { top: 0; width: 100%; border-radius: 0; z-index: 50; }
  .voile { display: none !important; }
}
/* Sans script (html sans la classe « js ») : pas de tiroir ; le volet rendu côté
   serveur (?apercu=<id>) s'affiche sous la liste, dans le flux de la page. */
@media (max-width: 1599px) {
  html:not(.js) .volet {
    position: static; transform: none; visibility: visible; width: auto; z-index: auto;
    border-radius: var(--radius-lg); box-shadow: var(--ombre-douce); margin-top: 16px;
  }
  html:not(.js) .volet:not(:has(.volet-titre)) { display: none; }
}

.volet-contenu, #volet-contenu { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.volet-entete { padding: 14px 18px 10px; border-bottom: 1px solid var(--border-leger); }
.volet-reperes { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.volet-ref { font-family: var(--police-mono); font-size: 0.82rem; color: var(--text-2); -webkit-user-select: all; user-select: all; }
.volet-titre { margin: 0; font-size: 1.12rem; line-height: 1.3; overflow-wrap: anywhere; }
.volet-titre:focus { outline: none; }
.volet-titre:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.volet-nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.volet-nav .btn { min-height: 30px; padding: 2px 8px; }
/* Téléphone : les touches k et j sont masquées ; un chevron dessiné en CSS (haut pour
   le point précédent, bas pour le suivant) garde les boutons lisibles. */
/* Chevron dessiné en CSS (haut : précédent, bas : suivant), à toutes les largeurs :
   les touches k et j ne sont indiquées que si les raccourcis sont actifs. */
.volet-nav [data-nav] { display: inline-flex; align-items: center; gap: 6px; }
.volet-nav [data-nav]::before {
  content: ''; width: 8px; height: 8px; border-left: 2px solid currentColor; border-top: 2px solid currentColor;
  transform: translateY(2px) rotate(45deg);
}
.volet-nav [data-nav="1"]::before { transform: translateY(-2px) rotate(225deg); }
@media (max-width: 640px) {
  .volet-nav [data-nav] { min-width: 40px; min-height: 40px; justify-content: center; }
}
.volet-progression { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }
.volet-progression:empty { display: none; }

.volet-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; padding: 10px 18px;
  border-bottom: 1px solid var(--border-leger); background: var(--surface-2);
}
.volet-actions .espace { flex: 1; }
.volet-actions .btn { min-height: 30px; }

.volet-corps { padding: 12px 18px 16px; overflow-y: auto; min-height: 0; flex: 1; }
.volet-infos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; margin: 0 0 14px; font-size: 0.86rem; }
.volet-infos-1 { grid-template-columns: minmax(0, 1fr); }
.volet-infos > div { min-width: 0; }
.volet-infos dt { color: var(--muted); font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.volet-infos dd { margin: 0; overflow-wrap: anywhere; }
.volet-bloc { margin: 0 0 14px; }
.volet-etiquette { margin: 0 0 4px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.volet-texte { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; font-size: 0.92rem; max-width: 78ch; }
.volet-vide { color: var(--muted); font-style: italic; }
.volet-reponse { border-left: 3px solid var(--ok); padding-left: 12px; }
.volet-note { border: 1px dashed var(--border); border-radius: var(--radius-md); padding: 8px 12px; }
.volet-note > summary { cursor: pointer; font-size: 0.84rem; font-weight: 600; color: var(--text-2); }
.volet-note .volet-texte { margin-top: 8px; font-size: 0.84rem; color: var(--text-2); }
.note-interne + .note-interne { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border-leger); }
.note-interne .meta { margin: 8px 0 0; }
.volet-avis { display: block; margin: 0 0 12px; padding: 8px 12px; border-radius: var(--radius-md); background: var(--info-bg); color: var(--info-tx); font-size: 0.85rem; max-width: 78ch; }
.volet-avis-warn { background: var(--warn-bg); color: var(--warn-tx); }
/* Sur la fiche complète, l'avis s'aligne sur la bande « brouillon » qui le précède (pleine largeur). */
.principal > .volet-avis { max-width: none; }
.volet-avis a { color: inherit; font-weight: 600; }
.volet-pied { padding: 8px 18px; border-top: 1px solid var(--border-leger); font-size: 0.76rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.volet-pied kbd { margin-right: 4px; }

/* Suivi : commentaires, position, dernier événement, origine ; modération rapide */
.volet-suivi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; margin: 0; font-size: 0.84rem; }
.volet-suivi > div { min-width: 0; }
.volet-suivi dt { color: var(--muted); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.volet-suivi dd { margin: 0; overflow-wrap: anywhere; }
.volet-attente { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.volet-attente-element { border: 1px dashed var(--accent); border-radius: var(--radius-md); padding: 8px 10px; background: var(--surface); }
.volet-attente-entete { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin: 0 0 4px; font-size: 0.82rem; }
.volet-attente-texte { margin: 0 0 8px; font-size: 0.86rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.volet-attente-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Lecteurs du dossier */
.volet-lecteurs-liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.86rem; }
.volet-lecteurs-liste li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.volet-lecteur-nom { font-weight: 600; }
.volet-lecteurs-vide { margin: 0 0 4px; }

/* --- Zone d'état : message et « Annuler », en tête du volet (ne recouvre aucune ligne) --- */
.volet-etat {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 18px;
  background: var(--topbar); color: var(--topbar-texte); font-size: 0.88rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.volet-etat[hidden] { display: none; }
/* Zone vide : visuellement cachée mais présente pour les lecteurs d'écran (role="status"). */
.volet-etat.volet-etat-vide { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.volet-etat > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.volet-etat button {
  font: inherit; font-size: 0.84rem; font-weight: 600; cursor: pointer; color: var(--accent);
  background: none; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: var(--radius-sm); padding: 4px 8px; min-height: 30px;
}
.volet-etat button[hidden] { display: none; }
.volet-etat kbd { color: inherit; background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.3); }
.volet-etat-err { background: var(--err-bg); color: var(--err-tx); }
.volet-etat-err button { color: var(--err-tx); border-color: var(--err); }

/* --- Fiche structurée (volet, fiche complète, vue client) ----------------------- */
.fiche { max-width: 78ch; }
.fiche-section { margin: 0 0 14px; }
.fiche-section:last-child { margin-bottom: 0; }
/* p.fiche-question seulement : la section de la question porte aussi la classe
   « fiche-question » (fiche-<clé>), et pre-line y rendrait les retours à la ligne
   du gabarit comme des lignes vides. */
.fiche-paragraphe, p.fiche-question, .fiche-option-texte { white-space: pre-line; }
.fiche-section p, .fiche-defaut p { margin: 0; line-height: 1.6; font-size: 0.93rem; overflow-wrap: anywhere; }
/* 78 caractères par ligne au plus (SPEC § 2 et § 4.1), dans le volet comme sur la fiche. */
.fiche-paragraphe, .fiche-section p, .fiche-options, .fil-texte { max-width: 78ch; }
.fiche-section p + p { margin-top: 6px; }
.fiche-etiquette { margin: 0 0 4px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); line-height: 1.4; }
.fiche-section p.fiche-question { font-size: 1.08rem; font-weight: 600; color: var(--text); line-height: 1.45; }
.fiche-qui { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: 0 0 12px; font-size: 0.88rem; }
.fiche-qui dt { display: inline; color: var(--muted); font-weight: 600; margin-right: 6px; }
.fiche-qui dd { display: inline; margin: 0; }
.fiche-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fiche-option {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: start;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.92rem; line-height: 1.5;
}
.fiche-option-lettre {
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2); font-weight: 700; font-size: 0.82rem;
}
.fiche-option-texte { overflow-wrap: anywhere; }
.fiche-option-reco { border-color: var(--ok); background: var(--ok-bg); }
/* Lettre de l'option recommandée : --ok-tx sur --ok-bg (contraste AA ; blanc sur --ok = 4,38:1). */
.fiche-option-reco .fiche-option-lettre { background: var(--ok-tx); color: var(--ok-bg); }
.fiche-option-reco .badge { margin-left: 6px; }
.fiche-defaut { margin: 0 0 14px; padding: 10px 14px; border-left: 4px solid var(--warn); border-radius: var(--radius-md); background: var(--warn-bg); color: var(--warn-tx); }
.fiche-defaut .fiche-etiquette { color: var(--warn-tx); }
.fiche-suite { margin: 0 0 12px; font-size: 0.88rem; font-weight: 600; }
.fiche-vide { color: var(--muted); font-style: italic; }

/* Fiche complète annotée : le texte reste celui du point, étiquettes comprises ;
   l'étiquette de tête de chaque paragraphe (« Question : ») prend l'allure d'un titre de section. */
.fiche-annotee .fiche-section > .annot-unite:first-child .annot-texte > .annot-etiquette:first-of-type,
.fiche-annotee .fiche-options-section > .annot-unite:first-child .annot-texte > .annot-etiquette:first-of-type {
  /* En bloc « en ligne » sur toute la largeur : l'espace qui suit « Question : » dans le texte
     (gardé tel quel pour les positions des passages commentés) reste en fin de ligne, sans
     décaler le début du paragraphe. */
  display: inline-block; width: 100%; margin: 0 0 2px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); line-height: 1.4;
}
.fiche-annotee .fiche-question .annot-texte { font-size: 1.1rem; font-weight: 600; color: var(--text); line-height: 1.45; }
.fiche-annotee .fiche-defaut .annot-texte > .annot-etiquette:first-of-type { display: none; }
.fiche-annotee .fiche-defaut .annot-unite { margin-bottom: 4px; }
.fiche-annotee .fiche-option { grid-template-columns: minmax(0, 1fr) auto; }
.fiche-annotee .fiche-option .annot-unite { margin: 0; }
.fiche-annotee .fiche-option .annot-texte > .annot-etiquette:first-of-type {
  display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; margin-right: 6px;
  padding: 0 4px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 0.8rem; font-weight: 700;
}
.fiche-annotee .fiche-option-reco .annot-texte > .annot-etiquette:first-of-type { background: var(--ok-tx); color: var(--ok-bg); }
.fiche-annotee .fiche-option > .badge { align-self: start; margin-top: 2px; }

/* --- Fiche complète --------------------------------------------------------------- */
.fiche-entete { margin: 0 0 12px; }
.fiche-titre { margin: 6px 0 10px; font-size: 1.45rem; max-width: 60ch; overflow-wrap: anywhere; }
.fiche-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fiche-actions > form { margin: 0; }
.fiche-plus { position: relative; }
.fiche-plus > summary { list-style: none; }
.fiche-plus > summary::-webkit-details-marker { display: none; }
.fiche-plus > summary::after {
  content: ''; width: 6px; height: 6px; margin: -3px 0 0 4px; border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor; transform: rotate(45deg);
}
.fiche-plus-menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 240px; display: grid; gap: 2px;
  padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--ombre-carte);
}
.fiche-plus-menu form { margin: 0; }
.fiche-plus-menu .btn { justify-content: flex-start; width: 100%; }
.fiche-grille { display: grid; gap: 16px; align-items: start; }
@media (min-width: 1280px) { .fiche-grille { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); } }
.fiche-principale, .fiche-laterale { display: grid; gap: 16px; min-width: 0; align-content: start; }
.fiche-principale > .carte, .fiche-laterale > .carte, .fiche-principale > .annot-zone { margin: 0; }
.fiche-principale .fiche-question .annot-texte { font-size: 1.2rem; }
.fiche-laterale .volet-lecteurs { margin: 0; }
.choix-options { display: grid; gap: 6px; margin: 0 0 12px; padding: 0; border: 0; }
.choix-options legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.choix-options label { display: flex; gap: 8px; align-items: center; min-height: 32px; }
.champ-texte {
  width: 100%; max-width: 78ch; padding: 8px 10px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-champ); border-radius: var(--radius-md); margin-bottom: 10px;
}

/* Historique regroupé par jour puis par nature */
.historique { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.historique-date { margin: 0 0 4px; font-size: 0.78rem; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }
.historique-details { list-style: none; margin: 4px 0 0; padding: 0 0 0 10px; border-left: 2px solid var(--border-leger); font-size: 0.86rem; }

/* --- Mode lecture : l'aperçu s'agrandit, la liste passe en colonne étroite -------- */
@media (min-width: 1600px) {
  body.mode-lecture .zone-travail { grid-template-columns: minmax(380px, 0.7fr) minmax(0, 1.5fr); }
}
body.mode-lecture .volet-corps { padding: 18px 28px 24px; }
body.mode-lecture .volet-titre { font-size: 1.35rem; }
body.mode-lecture .fiche-section p.fiche-question { font-size: 1.3rem; }
body.mode-lecture .fiche-section p, body.mode-lecture .fiche-defaut p, body.mode-lecture .fiche-option { font-size: 1rem; }
body.mode-lecture .volet-actions { padding: 12px 28px; }
body.mode-lecture [data-mode-lecture] { background: var(--selection); border-color: var(--action); }

/* --- Téléphone : barre Publier / Masquer / Passer collée en bas du volet ----------- */
@media (max-width: 640px) {
  .volet-actions {
    order: 5; position: sticky; bottom: 0; z-index: 2; border-top: 1px solid var(--border); border-bottom: 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.12);
  }
  .volet-actions .btn { min-height: 40px; }
  .volet-actions .btn-lien, .volet-actions .espace { display: none; }
  .volet-actions kbd, .volet-pied { display: none; }
  .volet-suivi, .volet-infos { grid-template-columns: minmax(0, 1fr); }
  .volet-nav .btn { min-height: 40px; min-width: 40px; }
  .fiche-plus-menu { left: auto; right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .volet { transition: none; }
}

@media print {
  .volet, .voile, .volet-etat, .fiche-actions, .choix-options { display: none !important; }
  .fiche-grille { display: block; }
}
