/* Les couleurs viennent de la palette de l'application (lib/core/theme/palette.dart) :
   l'outil n'est pas l'app, mais il travaille sa matière — autant qu'il en ait le ton. */
:root {
  --fond: #F7F4EE;
  --carte: #FFFDF9;
  --texte: #262421;
  --texte-lecture: #4A443C;
  --texte-second: #6E675C;
  --accent: #B0563A;
  --accent-soutenu: #A34E33;
  --accent-pale: #F2E4DE;
  --filet: #E6E0D5;
  --vert: #4C6B4F;
  --vert-pale: #E7EEE6;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --rayon: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #161A1D; --carte: #1E2326; --texte: #F2EDE4; --texte-lecture: #DBD3C6;
    --texte-second: #9A9287; --accent: #C97857; --accent-soutenu: #D98A69;
    --accent-pale: #2E2018; --filet: #2F373B; --vert: #8FB292; --vert-pale: #1F2A20;
  }
}

* { box-sizing: border-box; }

/* Plusieurs classes de mise en page posent `display: flex`, qui l'emporterait
   sur le `display: none` implicite de l'attribut `hidden`. */
[hidden] { display: none !important; }

a { color: var(--accent); }

body {
  margin: 0;
  font: 15px/1.5 var(--sans);
  color: var(--texte);
  background: var(--fond);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ————— Barre du haut ————————————————————————————————————————— */

.barre {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--filet);
  background: var(--carte);
  flex: 0 0 auto;
}
.marque { font-family: var(--serif); font-size: 17px; }
.marque b { letter-spacing: .02em; }
.separateur { color: var(--texte-second); margin: 0 8px; }
.marque span:last-child { color: var(--texte-second); font-size: 14px; }

.barre-etat { display: flex; gap: 14px; align-items: center; margin-left: auto; font-size: 13px; color: var(--texte-second); }
.barre-etat .verdict { font-variant-numeric: tabular-nums; }
.barre-etat .alerte { color: var(--accent); font-weight: 600; }
.barre-actions { display: flex; gap: 8px; }
.barre-etat + .barre-actions { margin-left: 0; }
.barre-etat[hidden] + .barre-actions { margin-left: auto; }

/* ————— Boutons ————————————————————————————————————————————— */

.bouton {
  padding: 7px 14px; border-radius: var(--rayon);
  border: 1px solid var(--filet); background: var(--carte);
  cursor: pointer;
}
.bouton:hover { border-color: var(--texte-second); }
.bouton-accent { background: var(--accent); border-color: var(--accent); color: #FFFDF9; }
.bouton-accent:hover { background: var(--accent-soutenu); border-color: var(--accent-soutenu); }
.bouton-discret { background: none; border-style: dashed; color: var(--texte-second); width: 100%; }
.bouton-large { padding: 11px 22px; font-size: 16px; }

/* ————— Accueil ————————————————————————————————————————————— */

.accueil { flex: 1; display: grid; place-items: center; padding: 24px; }
.depot {
  max-width: 520px; text-align: center;
  padding: 48px 40px; background: var(--carte);
  border: 2px dashed var(--filet); border-radius: 14px;
}
.depot.survol { border-color: var(--accent); background: var(--accent-pale); }
.depot h1 { font-family: var(--serif); font-weight: 500; font-size: 26px; margin: 0 0 10px; }
.conduite { color: var(--texte-second); margin: 0 0 22px; }
.depot code { background: var(--fond); padding: 1px 5px; border-radius: 4px; }
.note { margin: 20px 0 0; font-size: 13px; color: var(--texte-second); }
.avertissement { color: var(--accent); }
.reprise { margin: 20px 0 0; font-size: 14px; }
.reprise button { background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; }

/* ————— Onglets ————————————————————————————————————————————— */

.atelier { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.onglets { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--filet); background: var(--carte); flex: 0 0 auto; }
.onglet {
  padding: 9px 16px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--texte-second); cursor: pointer;
}
.onglet.actif { color: var(--texte); border-bottom-color: var(--accent); }

.espace { flex: 1; display: grid; grid-template-columns: minmax(280px, 360px) 1fr; min-height: 0; }

/* ————— Liste ————————————————————————————————————————————— */

.colonne-liste { border-right: 1px solid var(--filet); display: flex; flex-direction: column; min-height: 0; background: var(--carte); }
.recherche { padding: 12px 12px 8px; }
.recherche input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--filet);
  border-radius: var(--rayon); background: var(--fond);
}
.filtres { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.filtre {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--filet); background: var(--fond);
  color: var(--texte-second); cursor: pointer;
}
.filtre.actif { background: var(--accent-pale); border-color: var(--accent); color: var(--accent); }

.liste { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; }
.entree {
  padding: 9px 10px; border-radius: var(--rayon); cursor: pointer;
  border-left: 3px solid transparent; margin-bottom: 2px;
}
.entree:hover { background: var(--fond); }
.entree.choisie { background: var(--accent-pale); border-left-color: var(--accent); }
.entree.dehors { border-left-color: var(--accent); }
.entree-titre { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entree-titre.vide { color: var(--texte-second); font-style: italic; }
.entree-detail { display: flex; gap: 8px; font-size: 12px; color: var(--texte-second); margin-top: 2px; }
.pastille-dehors { color: var(--accent); font-weight: 600; }
.pied-liste { padding: 10px 12px; border-top: 1px solid var(--filet); }
.vide-liste { padding: 24px 14px; color: var(--texte-second); font-size: 14px; text-align: center; }

/* ————— Fiche ————————————————————————————————————————————— */

.colonne-fiche { overflow-y: auto; padding: 22px 28px 80px; }
.fiche-interne { max-width: 720px; margin: 0 auto; }
.fiche-vide { color: var(--texte-second); text-align: center; padding-top: 80px; }

.entete-fiche { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
.entete-fiche h2 { font-family: var(--serif); font-weight: 500; font-size: 20px; margin: 0; }
.identifiant { font-size: 12px; color: var(--texte-second); font-variant-numeric: tabular-nums; }

.verdict-fiche { padding: 11px 14px; border-radius: var(--rayon); margin-bottom: 20px; font-size: 14px; }
.verdict-fiche.dedans { background: var(--vert-pale); color: var(--vert); }
.verdict-fiche.dehors { background: var(--accent-pale); color: var(--accent-soutenu); }
.verdict-fiche b { display: block; margin-bottom: 4px; }
.verdict-fiche ul { margin: 4px 0 0; padding-left: 18px; }

.champ { margin-bottom: 18px; }
.champ > label { display: block; font-size: 13px; color: var(--texte-second); margin-bottom: 5px; }
.champ .aide { font-size: 12px; color: var(--texte-second); margin-top: 4px; }
.champ.manquant > label { color: var(--accent); }
.champ input[type=text], .champ textarea, .champ select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--filet);
  border-radius: var(--rayon); background: var(--carte); resize: none;
}
.champ input:focus, .champ textarea:focus, .champ select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.champ.manquant input, .champ.manquant textarea { border-color: var(--accent); }
.champ textarea { overflow: hidden; min-height: 44px; line-height: 1.55; }
.champ textarea.citation { font-family: var(--serif); font-size: 19px; line-height: 1.45; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.reserve { font-size: 12px; color: var(--accent-soutenu); margin-top: 5px; }
.compteur { float: right; font-variant-numeric: tabular-nums; }
.compteur.trop { color: var(--accent); }

.choix { display: flex; gap: 8px; }
.choix label {
  padding: 6px 12px; border: 1px solid var(--filet); border-radius: 999px;
  cursor: pointer; font-size: 14px;
}
.choix input { position: absolute; opacity: 0; }
.choix label:has(input:checked) { background: var(--accent-pale); border-color: var(--accent); color: var(--accent); }

/* Jetons : thèmes (plusieurs) et catégorie (un seul). Même geste des deux côtés —
   on clique pour poser, on reclique pour retirer, on crée au bout de la rangée. */
.jetons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.jeton {
  font-size: 13px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--filet); background: var(--carte); cursor: pointer; color: var(--texte-second);
}
.jeton.pose { background: var(--accent-pale); border-color: var(--accent); color: var(--accent); }
.jeton-nouveau { border-style: dashed; }

/* Le tampon de relecture : discret tant qu'il n'est pas posé, franc une fois là. */
.relecture {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 9px 14px; margin-bottom: 20px;
  border: 1px solid var(--filet); border-radius: var(--rayon);
}
.relecture.posee { background: var(--vert-pale); border-color: var(--vert); }
.relecture label { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; }
.relecture.posee label { color: var(--vert); font-weight: 600; }
.relecture input { accent-color: var(--vert); cursor: pointer; }
.relecture input:disabled { cursor: not-allowed; }
.relecture-note { font-size: 12px; color: var(--texte-second); }

/* Une fiche fermée se lit encore sans effort : on retire l'invitation à écrire,
   pas la lisibilité du texte. */
/* `input[type=text]` et non `input` : les boutons radio des pastilles sont
   masqués par `opacity: 0`, qu'une règle plus large ici viendrait rallumer. */
.fiche-interne.verrouillee input[type="text"],
.fiche-interne.verrouillee textarea,
.fiche-interne.verrouillee select { background: var(--fond); color: var(--texte-lecture); opacity: 1; }
.fiche-interne.verrouillee .jeton { opacity: .55; }
.fiche-interne.verrouillee .jeton-nouveau { display: none; }
.fiche-interne.verrouillee .choix label { opacity: .6; cursor: default; }

.pastille-relue { color: var(--vert); }

.rappel-partage { font-size: 13px; color: var(--texte-second); background: var(--fond); border-left: 3px solid var(--filet); padding: 8px 12px; margin-bottom: 16px; }
.lien { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }

/* ————— Bilan ————————————————————————————————————————————— */

.bilan { overflow-y: auto; padding: 28px; flex: 1; }
.bilan-interne { max-width: 860px; margin: 0 auto; }
.bilan h2 { font-family: var(--serif); font-weight: 500; margin: 32px 0 12px; }
.bilan h2:first-child { margin-top: 0; }
.cartes { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.carte { background: var(--carte); border: 1px solid var(--filet); border-radius: var(--rayon); padding: 14px 16px; }
.carte .nombre { font-family: var(--serif); font-size: 28px; line-height: 1.1; }
.carte .quoi { font-size: 13px; color: var(--texte-second); margin-top: 3px; }
.carte.alerte .nombre { color: var(--accent); }
.carte.cliquable { cursor: pointer; }
.carte.cliquable:hover { border-color: var(--accent); }

.jauge { height: 8px; border-radius: 4px; background: var(--filet); overflow: hidden; margin: 8px 0 4px; }
.jauge > div { height: 100%; background: var(--accent); }
.jauge-legende { font-size: 13px; color: var(--texte-second); }

.bilan h3 { font-size: 13px; font-weight: 600; color: var(--texte-second); margin: 20px 0 8px;
  text-transform: uppercase; letter-spacing: .06em; }
.panneau h3:first-child { margin-top: 0; }

/* Deux colonnes tant que la place le permet : les répartitions se comparent
   mieux côte à côte qu'empilées sur deux écrans de défilement. */
.colonnes-stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px 32px; }

.repartition { width: 100%; border-collapse: collapse; font-size: 14px; }
/* Le libellé se replie plutôt que de pousser la barre hors du tableau : c'est la
   barre qui porte la lecture, pas le texte. */
.repartition th { font-weight: 400; text-align: left; padding: 5px 10px 5px 0; max-width: 15em; }
.repartition td { padding: 5px 0; }
.repartition .barre { width: 100%; min-width: 56px; }
.repartition .barre > div { height: 7px; border-radius: 4px; background: var(--accent); min-width: 2px; }
.repartition .nb { text-align: right; padding-left: 14px; white-space: nowrap;
  font-variant-numeric: tabular-nums; }
.repartition .part { text-align: right; padding-left: 10px; white-space: nowrap;
  color: var(--texte-second); font-variant-numeric: tabular-nums; }
.repartition tr.vide { color: var(--texte-second); }
.repartition tr.vide .barre > div { background: var(--filet); }
.repartition tr.cliquable { cursor: pointer; }
.repartition tr.cliquable:hover th { color: var(--accent); }
.repartition tr.cliquable:hover .barre > div { background: var(--accent-soutenu); }

.repartition.tableau tr:first-child th { color: var(--texte-second); font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--filet); }
.repartition.tableau tr + tr th, .repartition.tableau td { border-bottom: 1px solid var(--filet); }
.repartition.tableau tr:last-child th, .repartition.tableau tr:last-child td { border-bottom: none; }

.liste-plate { list-style: none; margin: 0; padding: 0; }
.liste-plate li { padding: 8px 12px; border-bottom: 1px solid var(--filet); font-size: 14px; }
.liste-plate li:last-child { border-bottom: none; }
.liste-plate .grave { color: var(--accent); }
.encadre { background: var(--carte); border: 1px solid var(--filet); border-radius: var(--rayon); overflow: hidden; }
.rien { color: var(--texte-second); font-size: 14px; }

/* ————— Le mode d'emploi ————————————————————————————————————— */

.bouton-aide { margin-left: auto; }
.barre-etat:not([hidden]) ~ .bouton-aide { margin-left: 0; }

.aide-plein {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px;
}
.aide-fenetre {
  background: var(--carte); border: 1px solid var(--filet); border-radius: 12px;
  width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.aide-entete {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 26px; border-bottom: 1px solid var(--filet); flex: 0 0 auto;
}
.aide-entete h1 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 0; }

.aide-texte { overflow-y: auto; padding: 8px 26px 30px; line-height: 1.62; color: var(--texte-lecture); }
.aide-texte h2 {
  font-family: var(--serif); font-weight: 500; font-size: 18px;
  color: var(--texte); margin: 28px 0 8px;
}
.aide-texte p { margin: 0 0 12px; }
.aide-texte .chapeau { font-size: 16px; color: var(--texte); margin-top: 18px; }
.aide-texte ul { margin: 0 0 12px; padding-left: 20px; }
.aide-texte li { margin-bottom: 6px; }
.aide-texte dl { margin: 0 0 12px; }
.aide-texte dt { font-weight: 600; color: var(--texte); margin-top: 10px; }
.aide-texte dd { margin: 2px 0 0; padding-left: 16px; border-left: 2px solid var(--filet); }
.aide-texte table { border-collapse: collapse; margin: 4px 0 14px; }
.aide-texte th { text-align: left; font-weight: 600; color: var(--texte);
  padding: 4px 16px 4px 0; vertical-align: top; white-space: nowrap; }
.aide-texte td { padding: 4px 0; }
.aide-texte code, .aide-texte kbd {
  background: var(--fond); border: 1px solid var(--filet); border-radius: 4px;
  padding: 1px 5px; font-size: 13px;
}
.aide-texte .encart {
  background: var(--fond); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 0 var(--rayon) var(--rayon) 0;
}
.aide-texte .vert { color: var(--vert); }
.aide-texte .orange { color: var(--accent); }

/* ————— Messages ————————————————————————————————————————————— */

.messages { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 10; }
.message {
  background: var(--texte); color: var(--fond); padding: 9px 16px;
  border-radius: 999px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.message.erreur { background: var(--accent); color: #FFFDF9; }

@media (max-width: 860px) {
  .espace { grid-template-columns: 1fr; }
  .colonne-liste { border-right: none; border-bottom: 1px solid var(--filet); max-height: 42vh; }
  .duo { grid-template-columns: 1fr; }
}
