/* Atelier gold PA-PH (repris de l'atelier gold v2) : thème clair, police système, dense, sans animation. */

:root {
  --texte: #1f2328;
  --muted: #59636e;
  --bord: #d1d9e0;
  --surface: #f6f8fa;
  --fond-image: #e9edf1;
  --accent: #0b5cad;
  --accent-clair: #e6f0fb;
  --vert: #1a7f37;
  --vert-clair: #e7f5eb;
  --rouge: #c21f2c;
  --rouge-clair: #fdecee;
  --orange: #b35300;
  --orange-clair: #fff3e6;
  --jaune-clair: #fff8db;
  --violet: #6f3fc4;
  --violet-clair: #f6f0ff;
  --panneau: 364px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--texte);
  background: #fff;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--bord); border-bottom-width: 2px; border-radius: 3px;
  padding: 1px 4px; background: #fff; color: var(--texte);
}

/* ── Ossature ─────────────────────────────────────────────────── */
.atelier { height: 100vh; display: flex; flex-direction: column; }
.entete {
  display: flex; align-items: center; gap: 16px; padding: 6px 12px;
  border-bottom: 1px solid var(--bord); flex-shrink: 0; min-height: 44px;
}
.entete-ref { min-width: 0; flex: 1; }
.entete h1 { font-size: 14px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entete p { margin: 0; font-size: 12px; }
.entete-droite { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.corps { flex: 1; min-height: 0; display: flex; }
.zone-image { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.canvas-box { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--fond-image); }
.canvas-box canvas { position: absolute; inset: 0; touch-action: none; }
.canvas-msg {
  position: absolute; inset: 0; margin: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none;
}
.canvas-msg:empty { display: none; }

.barre-outils {
  display: flex; align-items: center; gap: 4px; padding: 4px 8px; flex-shrink: 0;
  border-top: 1px solid var(--bord); font-size: 12px; min-height: 34px;
}
.barre-outils .sep { width: 1px; height: 16px; background: var(--bord); margin: 0 6px; }
.espace { flex: 1; }
.survol { max-width: 38%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

button.icone, button.texte {
  border: 1px solid transparent; background: none; border-radius: 4px; padding: 2px 7px; cursor: pointer;
  min-width: 26px; line-height: 20px;
}
button.icone:hover, button.texte:hover { background: var(--surface); border-color: var(--bord); }
button:disabled { opacity: .4; cursor: default; }

/* ── Bande de pages ───────────────────────────────────────────── */
.bande-pages {
  width: 88px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--bord);
  padding: 6px; display: flex; flex-direction: column; gap: 6px; background: #fff;
}
.vignette {
  display: block; width: 100%; padding: 0; border: 1px solid var(--bord); border-radius: 4px;
  background: var(--surface); cursor: pointer; position: relative;
}
.vignette img { display: block; width: 100%; height: auto; border-radius: 3px 3px 0 0; }
.vignette span { display: block; font-size: 10px; color: var(--muted); padding: 1px 0; text-align: center; }
.vignette.active { border-color: var(--accent); outline: 1px solid var(--accent); }
.vignette .retenue {
  position: absolute; top: 2px; right: 2px; background: var(--accent); color: #fff;
  font-size: 9px; padding: 0 3px; border-radius: 3px;
}

/* ── Panneau de qualification ─────────────────────────────────── */
.panneau {
  width: var(--panneau); flex-shrink: 0; border-left: 1px solid var(--bord);
  overflow-y: auto; padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 10px;
}
.bloc h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 5px; }

/* Consigne du lot et bandeaux de la pièce */
.consigne { font-size: 12px; color: #0a3f78; background: var(--accent-clair); border: 1px solid #a9c8ec; border-radius: 6px; padding: 5px 8px; }
.consigne p { margin: 0; }
.consigne p + p { margin-top: 3px; }
.consigne .lecture-seule { color: #86111b; font-weight: 600; }
.bandeau-piece:empty { display: none; }
.bandeau-piece p { margin: 0 0 4px; font-size: 12px; border-radius: 6px; padding: 4px 8px; }
.bandeau-piece .motif { background: var(--orange-clair); border: 1px solid #f2c08f; color: #6d3300; }
.bandeau-piece .doublon-probable { background: var(--rouge-clair); border: 1px solid #f1a9b0; color: #86111b; }
.bandeau-piece .note-lot { background: var(--surface); border: 1px solid var(--bord); }

/* Bandeau d'avancement du lot : fait / à faire / rejetées / doublons, puis par doctype */
.avancement { border: 1px solid var(--bord); border-radius: 6px; padding: 5px 8px; background: var(--surface); font-size: 12px; }
.av-ligne { display: flex; flex-wrap: wrap; gap: 3px 10px; align-items: baseline; }
.av-ligne strong { font-size: 14px; }
.av-lot { color: var(--accent); }
.av-doctypes { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 3px; font-size: 11px; }
.av-dt { white-space: nowrap; }

.notice { font-size: 12px; border-radius: 6px; padding: 5px 8px; border: 1px solid; }
.notice.ok { color: #0f5323; background: var(--vert-clair); border-color: #9fd5ad; }
.notice.erreur { color: #86111b; background: var(--rouge-clair); border-color: #f1a9b0; }
.notice.info { color: #0a3f78; background: var(--accent-clair); border-color: #a9c8ec; }

/* Doctypes */
.bloc h2 { display: flex; align-items: center; gap: 6px; }
.avis-btn {
  margin-left: auto; font: inherit; font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--muted);
  border: 1px solid var(--bord); background: #fff; border-radius: 3px; padding: 0 5px; cursor: help;
  max-width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grille-doctypes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; }
.btn-doctype {
  position: relative; border: 1px solid var(--bord); background: #fff; border-radius: 4px;
  padding: 3px 4px; cursor: pointer; font-size: 11px; line-height: 1.3; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-doctype kbd { display: inline-block; margin: 0 4px 0 0; font-size: 9px; padding: 0 3px; }
.btn-doctype:hover { border-color: var(--muted); }
.btn-doctype.actif { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-doctype.actif kbd { color: var(--texte); }
.btn-doctype.propose::after {
  content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--orange);
}
.speciaux { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-top: 3px; }
.speciaux .btn-doctype { display: flex; align-items: center; gap: 5px; justify-content: center; }
.speciaux .btn-doctype kbd { display: inline-block; margin: 0; }
.speciaux .btn-doctype.actif { background: var(--orange); border-color: var(--orange); }
#saisie-speciale { margin-top: 4px; }

/* Champs : sections compactes, une ligne par champ */
.sect { margin-bottom: 6px; }
.sect-titre {
  display: flex; align-items: baseline; gap: 4px; width: 100%; font: inherit; font-size: 11px; font-weight: 600;
  color: var(--muted); border: 0; border-bottom: 1px solid var(--bord); background: none; padding: 2px 0; margin-bottom: 2px;
  text-align: left;
}
button.sect-titre { cursor: pointer; }
.sect-compte { margin-left: auto; font-weight: 400; font-variant-numeric: tabular-nums; }
.sect.rares .chevron { display: inline-block; width: 10px; }
.sect.rares:not(.ferme) .chevron { transform: rotate(90deg); }
.sect.ferme .champ:not(.notable) { display: none; }
.sect-montres { font-weight: 400; }

.champ { position: relative; border-left: 3px solid transparent; padding: 1px 0 1px 5px; border-radius: 2px; }
.champ.st-prerempli { border-left-color: #e3b400; }
.champ.st-confirme { border-left-color: var(--vert); }
.champ.st-corrige { border-left-color: var(--accent); }
.champ.st-absent, .champ.st-illisible { border-left-color: #8c959f; }
.champ.actif { background: var(--accent-clair); }
.c-ligne { display: grid; grid-template-columns: 40% 1fr; align-items: center; gap: 6px; min-height: 26px; }
.c-lib { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.c-saisie { display: flex; align-items: center; gap: 3px; min-width: 0; }
.saisie {
  width: 100%; min-width: 0; border: 1px solid var(--bord); border-radius: 4px; padding: 2px 6px; background: #fff;
  font-size: 13px; line-height: 18px;
}
.saisie:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.saisie::placeholder { color: #8c959f; font-style: italic; }
.champ.st-prerempli .saisie { background: #fffdf2; }
.champ.st-absent .saisie, .champ.st-illisible .saisie { background: #f3f4f6; }
.pastille-lot {
  font-size: 9px; font-weight: 600; color: #fff; background: #1b7c83; border-radius: 3px; padding: 0 4px;
  line-height: 15px; white-space: nowrap;
}
.pastille-lot:empty { display: none; }
.controle { width: 13px; text-align: center; font-weight: 700; flex-shrink: 0; font-size: 12px; }
.controle.ok { color: var(--vert); }
.controle.ko { color: var(--rouge); }
.c-note {
  flex-shrink: 0; border: 0; background: none; padding: 0 1px; color: #b3bac2; cursor: pointer; line-height: 0;
}
.c-note:hover { color: var(--muted); }
.c-note.a-note { color: var(--orange); }
.c-rev { margin: 1px 0 2px 40%; padding-left: 6px; font-size: 11px; color: var(--orange); font-weight: 600; }
.c-rev[hidden] { display: none; }

/* Détail (état, puces, note) : au focus ; au survol après un court délai, en surimpression
   (pas de décalage des lignes sous le curseur). */
.c-detail { display: none; padding: 3px 0 4px 0; }
.champ.actif .c-detail, .champ.note-ouverte .c-detail { display: block; }
.champ:not(.actif):not(.note-ouverte) .c-detail {
  display: block; visibility: hidden; position: absolute; left: 30%; right: 0; top: 100%; z-index: 5;
  background: #fff; border: 1px solid var(--bord); border-radius: 6px; padding: 4px 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.champ:not(.actif):not(.note-ouverte):hover .c-detail { visibility: visible; transition: visibility 0s .35s; }
.c-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.c-raccourcis { margin-left: auto; font-size: 10px; }
.champ:not(.actif) .c-raccourcis { display: none; }
.c-note-txt { display: none; width: 100%; margin-top: 4px; border: 1px solid var(--bord); border-radius: 4px; padding: 3px 6px; font-size: 12px; resize: vertical; }
.champ.note-ouverte .c-note-txt { display: block; }
.etat { font-size: 10px; border-radius: 3px; padding: 0 5px; line-height: 16px; white-space: nowrap; }
.etat-prerempli { background: var(--jaune-clair); color: #6b4f00; border: 1px solid #ecd78a; }
.etat-a_saisir { background: var(--surface); color: var(--muted); border: 1px solid var(--bord); }
.etat-confirme { background: var(--vert-clair); color: var(--vert); border: 1px solid #9fd5ad; }
.etat-corrige { background: var(--accent-clair); color: var(--accent); border: 1px solid #a9c8ec; }
.etat-absent, .etat-illisible { background: #eef0f3; color: #3d444d; border: 1px solid #c3cad3; }
.puces { display: flex; flex-wrap: wrap; gap: 3px; min-width: 0; }
.puce {
  border: 1px solid var(--bord); background: var(--surface); border-radius: 10px; padding: 0 7px;
  font-size: 11px; line-height: 18px; cursor: pointer; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.puce:hover { border-color: var(--accent); background: var(--accent-clair); }
.puce.choisie { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.puce .ck { color: var(--vert); margin-left: 3px; }
.puce .pg { color: var(--muted); margin-left: 3px; }
/* Proposition Qwen : violet, préfixe « Qwen », jamais confondue avec une entité. */
.puce.qwen { border-color: #b69ce8; background: var(--violet-clair); color: var(--violet); }
.puce.qwen b { font-weight: 700; }
.puce.qwen:hover { border-color: var(--violet); background: #efe6ff; }
.puce.qwen.choisie { border-color: var(--violet); font-weight: 600; }
/* Valeur du lot précédent : sarcelle, comme la pastille. */
.puce.lot { border-color: #8cc5c9; background: #eaf6f7; color: #145e63; }
.puce.lot b { font-weight: 700; }
.accord-eq { font-size: 10px; font-weight: 600; white-space: nowrap; border-radius: 3px; padding: 0 4px; line-height: 16px; }
.accord-eq:empty { display: none; }
.accord-eq.oui { color: var(--vert); }
.accord-eq.non { color: #fff; background: var(--orange); }
.legende-puces { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; margin: 6px 0 0; }
.ambigu { font-size: 11px; color: var(--orange); }
.vide-special { font-size: 12px; color: var(--muted); padding: 6px 0; }

textarea#commentaire { width: 100%; border: 1px solid var(--bord); border-radius: 4px; padding: 4px 6px; resize: vertical; }

/* Actions */
/* Actions collées en bas du panneau : « Valider » toujours visible, sans défilement. */
.actions {
  display: flex; flex-direction: column; gap: 6px; margin-top: auto;
  position: sticky; bottom: -16px; background: #fff; padding: 8px 0 16px;
  border-top: 1px solid var(--bord); z-index: 1;
}
.avert { font-size: 12px; background: var(--orange-clair); border: 1px solid #f2c08f; color: #6d3300; border-radius: 6px; padding: 5px 8px; }
button.primaire {
  background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 6px;
  padding: 7px 10px; font-weight: 600; cursor: pointer;
}
button.primaire:hover { background: #094c90; }
button.primaire:focus-visible { outline: 3px solid #8cb8e8; outline-offset: 1px; }
button.secondaire {
  background: #fff; border: 1px solid var(--bord); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button.secondaire:hover { border-color: var(--muted); }
.nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.option { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 3px; white-space: nowrap; cursor: pointer; }

.badge { font-size: 11px; border-radius: 10px; padding: 1px 8px; border: 1px solid var(--bord); white-space: nowrap; }
.badge.a_faire { background: var(--surface); color: var(--muted); }
.badge.brouillon { background: var(--jaune-clair); color: #6b4f00; border-color: #ecd78a; }
.badge.valide { background: var(--vert-clair); color: var(--vert); border-color: #9fd5ad; }

/* ── Liste ────────────────────────────────────────────────────── */
.liste { min-height: 100vh; }
.liste-corps { padding: 10px 14px; overflow-x: auto; }
.filtres { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 6px; }
.filtres label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.filtres select, .filtres input { border: 1px solid var(--bord); border-radius: 4px; padding: 3px 5px; background: #fff; color: var(--texte); }
.table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--bord); padding: 4px 6px; position: sticky; top: 0; background: #fff; }
.table td { border-bottom: 1px solid #eceff2; padding: 4px 6px; }
.table th[data-tri] { cursor: pointer; user-select: none; }
.table th[data-tri]:hover { color: var(--texte); }
.table th.trie { color: var(--texte); }
.table th.trie[data-sens="asc"]::after { content: " ▲"; font-size: 9px; }
.table th.trie[data-sens="desc"]::after { content: " ▼"; font-size: 9px; }
.table td.motif-cell { max-width: 360px; }
.table .doublon-probable { color: var(--rouge); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--accent-clair); }
.table td.ref { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Aide ─────────────────────────────────────────────────────── */
.aide { position: fixed; inset: 0; background: rgba(15, 20, 25, .35); display: flex; align-items: center; justify-content: center; z-index: 10; }
.aide-boite { background: #fff; border-radius: 8px; padding: 14px 18px; max-width: 760px; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.aide-boite h2 { margin: 0 0 8px; font-size: 15px; }
.aide-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.aide-boite table { border-collapse: collapse; font-size: 12px; }
.aide-boite th { text-align: left; padding: 4px 0; color: var(--muted); }
.aide-boite td { padding: 2px 8px 2px 0; vertical-align: top; }

/* ── Mode direct : fiche d'extraction ─────────────────────────── */
.compteur-fiche { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
.compteur-fiche:empty { display: none; }
.compteur-fiche b { color: var(--texte); }
.compteur-fiche .cpt-corr { color: var(--accent); }
.compteur-fiche .cpt-ctrl { color: var(--orange); font-weight: 600; }
.champ.direct .c-ligne { grid-template-columns: 18px 36% 1fr; }
.src-pastille {
  font-size: 9px; font-weight: 700; text-align: center; border-radius: 3px; line-height: 14px; color: #fff;
  opacity: .75;
}
.src-pastille:empty { visibility: hidden; }
.src-l1 { background: #1b7c83; }
.src-q { background: var(--violet); }
.src-e { background: #59636e; }
/* Aucun état à gérer : seule une correction change l'aspect du champ, nettement. */
.champ.direct { border-left-color: transparent; }
.champ.direct.modifie { border-left-color: var(--accent); background: #f2f7fd; }
.champ.direct.modifie .saisie { border-color: var(--accent); background: #fff; font-weight: 600; }
.champ.direct.modifie.vide .saisie { background: repeating-linear-gradient(135deg, #fff, #fff 6px, #f1f4f8 6px, #f1f4f8 12px); }
.champ.direct.actif { background: var(--accent-clair); }
.champ.direct .saisie { background: #fff; }
.corrige-btn {
  flex-shrink: 0; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 3px;
  font-size: 10px; line-height: 15px; padding: 0 4px; cursor: pointer; white-space: nowrap;
}
.corrige-btn:hover { background: #094c90; }
.corrige-btn[hidden] { display: none; }
.repere, .repere-exemple {
  flex-shrink: 0; width: 15px; height: 15px; border-radius: 50%; background: var(--orange); color: #fff;
  font-size: 10px; font-weight: 700; text-align: center; line-height: 15px; cursor: help;
}
.repere-exemple { display: inline-block; }
.repere[hidden] { display: none; }
.champ.direct.a-controler:not(.modifie) .saisie { border-color: #e7a66a; }
#aide-direct table td { padding: 2px 10px 2px 0; vertical-align: top; }
/* Mode direct : détail (puces, note) sous le champ actif seulement, jamais au survol
   (la surimpression masquerait le champ en cours de relecture). */
.champ.direct:not(.actif):not(.note-ouverte) .c-detail { display: none; }

/* ── Ajouts de l'atelier PA-PH ────────────────────────────────── */
.src-a { background: #0f7b4f; }
.puce.agent { border-color: #8fd1b4; background: #e9f7f0; color: #0f5c3c; }
.puce.agent b { font-weight: 700; }
.c-lib.oblig::after { content: " *"; color: var(--rouge); font-weight: 700; }
.autres-types {
  width: 100%; margin-top: 3px; border: 1px solid var(--bord); border-radius: 4px; padding: 2px 4px;
  background: #fff; font-size: 11px; color: var(--muted);
}
.autres-types.actif { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.choix-vague { border: 1px solid var(--bord); border-radius: 4px; padding: 1px 4px; background: #fff; font-size: 12px; }
#btn-nom { color: var(--accent); }
.boite-nom { width: 380px; display: flex; flex-direction: column; gap: 8px; }
.boite-nom p { margin: 0; font-size: 12px; }
.boite-actions { display: flex; justify-content: flex-end; }
.texte-ocr {
  margin: 0; max-height: 32vh; overflow: auto; border-top: 1px solid var(--bord); padding: 6px 10px;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; background: #fff;
}
.bandeau-piece .agent { background: #e9f7f0; border: 1px solid #8fd1b4; color: #0f5c3c; }
/* Avancement par type : faites (vert), proposées par un agent (vert d'eau), restantes (gris). */
.av-types { display: flex; flex-direction: column; gap: 3px; margin-top: 5px; }
.av-type { display: grid; grid-template-columns: 1fr 92px auto; gap: 6px; align-items: center; font-size: 11px; }
.av-type .nom { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-barre { display: flex; height: 7px; border-radius: 4px; overflow: hidden; background: #e3e8ee; }
.av-barre .fait { background: var(--vert); }
.av-barre .agent { background: #57c49a; }
.av-type .chiffres { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.badge.propose_agent { background: #e9f7f0; color: #0f5c3c; border-color: #8fd1b4; }
.liste .entete-droite a + a { margin-left: 4px; }
