:root {
  --papier: #f6f1e7;
  --papier-2: #efe7d6;
  --carte: #fffdf8;
  --encre: #2b2620;
  --encre-2: #6b6255;
  --trait: #ddd2bd;
  --vert: #2f5d50;
  --vert-2: #3f7a69;
  --vert-pale: #e3ece6;
  --brique: #a4492f;
  --or: #b88a2e;
  --homme: #dce8f2;
  --homme-b: #6f93b3;
  --femme: #f5e1e3;
  --femme-b: #b87b84;
  --neutre: #ece7dc;
  --neutre-b: #a59c8b;
  --rayon: 10px;
  --ombre: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 14px rgba(60, 45, 20, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--papier); color: var(--encre); font: 15px/1.5 var(--sans); }
a { color: var(--vert); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .01em; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; }
small, .discret { color: var(--encre-2); }
[hidden] { display: none !important; }

/* En-tête */
.entete { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.4rem; background: var(--vert); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.marque { color: #fff; text-decoration: none; font-family: var(--serif); font-size: 1.2rem; display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.marque-icone { color: #e6c66f; font-size: 1.4rem; }
.nav { display: flex; align-items: center; gap: .2rem; flex: 1; }
.nav a { color: #e8f0ec; text-decoration: none; padding: .4rem .75rem; border-radius: 6px; }
.nav a:hover { background: rgba(255,255,255,.1); }
.nav a.actif { background: rgba(255,255,255,.18); color: #fff; }
.nav-sep { flex: 1; }
.burger { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }

.app { max-width: 1240px; margin: 0 auto; padding: 1.6rem 1.4rem 4rem; }
.app.plein { max-width: none; padding: 0; }
.chargement { padding: 3rem; text-align: center; color: var(--encre-2); }

/* Composants */
.carte { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 1.2rem 1.3rem; box-shadow: var(--ombre); }
.grille { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pile > * + * { margin-top: 1rem; }
.ligne { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.entre { justify-content: space-between; }
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--vert); background: var(--vert); color: #fff; padding: .48rem .95rem; border-radius: 7px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--vert-2); }
.btn.sec { background: transparent; color: var(--vert); }
.btn.sec:hover { background: var(--vert-pale); }
.btn.danger { background: transparent; border-color: var(--brique); color: var(--brique); }
.btn.petit { padding: .25rem .6rem; font-size: .86rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.lien-btn { background: none; border: 0; color: var(--vert); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
label { display: block; font-size: .87rem; color: var(--encre-2); margin-bottom: .2rem; }
input, select, textarea { width: 100%; font: inherit; padding: .5rem .65rem; border: 1px solid var(--trait); border-radius: 7px; background: #fff; color: var(--encre); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--vert-2); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 90px; resize: vertical; }
.champ { margin-bottom: .8rem; }
.case { display: flex; gap: .45rem; align-items: center; color: var(--encre); font-size: .95rem; }
.case input { width: auto; }
.badge { display: inline-block; padding: .08rem .5rem; border-radius: 99px; font-size: .78rem; background: var(--papier-2); color: var(--encre-2); border: 1px solid var(--trait); }
.badge.vert { background: var(--vert-pale); color: var(--vert); border-color: #bcd3c6; }
.badge.or { background: #f6ecd4; color: #8a6514; border-color: #e5d0a0; }
.badge.brique { background: #f6e2dc; color: var(--brique); border-color: #e7c1b5; }
.erreur { background: #f8e3dd; color: #7d2a16; border: 1px solid #ecc1b3; border-radius: 7px; padding: .6rem .8rem; margin-bottom: .8rem; }
.info { background: var(--vert-pale); color: var(--vert); border: 1px solid #bcd3c6; border-radius: 7px; padding: .6rem .8rem; }
.vide { color: var(--encre-2); font-style: italic; padding: .4rem 0; }
.sep { border: 0; border-top: 1px solid var(--trait); margin: 1.2rem 0; }

/* Accueil / auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(circle at 20% 10%, #fbf7ee, var(--papier) 60%), var(--papier); }
.auth-boite { width: 100%; max-width: 430px; }
.auth-boite h1 { text-align: center; }
.auth-orn { text-align: center; color: var(--or); font-size: 2.2rem; line-height: 1; margin-bottom: .4rem; }
.auth-sous { text-align: center; color: var(--encre-2); margin: -.2rem 0 1.4rem; }
.stat { text-align: center; padding: 1rem; }
.stat b { display: block; font-family: var(--serif); font-size: 2rem; color: var(--vert); line-height: 1.1; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.hero p { margin: 0; color: var(--encre-2); }

/* Listes */
.liste { list-style: none; margin: 0; padding: 0; }
.liste li { padding: .55rem 0; border-bottom: 1px dashed var(--trait); }
.liste li:last-child { border-bottom: 0; }
.personne-ligne { display: flex; align-items: center; gap: .7rem; padding: .45rem .6rem; border-radius: 7px; text-decoration: none; color: inherit; }
.personne-ligne:hover { background: var(--papier-2); }
.pastille { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: .8rem; font-weight: 600; border: 1.5px solid; }
.pastille.M { background: var(--homme); border-color: var(--homme-b); color: #2d4e6a; }
.pastille.F { background: var(--femme); border-color: var(--femme-b); color: #78414a; }
.pastille.\? { background: var(--neutre); border-color: var(--neutre-b); }
.personne-ligne .nom { font-weight: 600; }
.personne-ligne .dates { color: var(--encre-2); font-size: .88rem; }
.personne-ligne .droite { margin-left: auto; display: flex; gap: .35rem; }
details.groupe { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); margin-bottom: .7rem; box-shadow: var(--ombre); }
details.groupe summary { cursor: pointer; padding: .7rem 1rem; font-family: var(--serif); font-size: 1.08rem; display: flex; gap: .6rem; align-items: center; list-style: none; }
details.groupe summary::-webkit-details-marker { display: none; }
details.groupe summary::before { content: "▸"; color: var(--or); transition: transform .15s; }
details.groupe[open] summary::before { transform: rotate(90deg); }
details.groupe .contenu { padding: 0 .6rem .6rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.outils { display: flex; gap: .7rem; flex-wrap: wrap; align-items: end; margin-bottom: 1.1rem; }
.outils .champ { margin: 0; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { border: 1px solid var(--trait); background: var(--carte); border-radius: 99px; padding: .2rem .7rem; cursor: pointer; font-size: .85rem; display: inline-flex; gap: .35rem; align-items: center; }
.chip.on { background: var(--vert); color: #fff; border-color: var(--vert); }
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* Fiche */
.fiche-tete { display: flex; gap: 1.2rem; align-items: center; margin-bottom: 1.2rem; flex-wrap: wrap; }
.portrait { width: 92px; height: 92px; border-radius: 50%; object-fit: cover; border: 3px solid var(--carte); box-shadow: var(--ombre); background: var(--papier-2); display: grid; place-items: center; font-family: var(--serif); font-size: 2rem; color: var(--encre-2); flex: none; }
.fiche-tete h1 { margin: 0; }
.fiche-tete .dates { color: var(--encre-2); font-size: 1.02rem; }
.fiche-actions { margin-left: auto; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: .35rem .9rem; margin: 0; }
.dl dt { color: var(--encre-2); font-size: .9rem; }
.dl dd { margin: 0; }
.famille-bloc + .famille-bloc { margin-top: 1rem; }
.famille-bloc h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; color: var(--encre-2); font-family: var(--sans); font-weight: 600; }
.notes { white-space: pre-wrap; }

/* Preuves */
.galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem; }
.preuve-carte { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--ombre); display: flex; flex-direction: column; transition: transform .12s; }
.preuve-carte:hover { transform: translateY(-2px); }
.preuve-vignette { aspect-ratio: 4/3; background: var(--papier-2) center/cover no-repeat; display: grid; place-items: center; font-size: 2.4rem; color: var(--encre-2); }
.preuve-carte .corps { padding: .6rem .7rem; font-size: .9rem; }
.preuve-carte .titre { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.visionneuse { background: #2a2622; border-radius: var(--rayon); display: grid; place-items: center; min-height: 300px; overflow: hidden; }
.visionneuse img { max-width: 100%; max-height: 78vh; display: block; }
.visionneuse iframe { width: 100%; height: 78vh; border: 0; background: #fff; }
.analyse { border-left: 3px solid var(--or); background: #fcf8ef; padding: .9rem 1rem; border-radius: 0 var(--rayon) var(--rayon) 0; }
.analyse + .analyse { margin-top: .8rem; }
.analyse .md p { margin: .4rem 0; }
.depot { border: 2px dashed var(--trait); border-radius: var(--rayon); padding: 1.4rem; text-align: center; color: var(--encre-2); cursor: pointer; background: #fff; }
.depot.survol { border-color: var(--vert); background: var(--vert-pale); }

/* Commentaires */
.commentaire { display: flex; gap: .75rem; padding: .8rem 0; border-bottom: 1px solid var(--trait); }
.commentaire:last-child { border-bottom: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--vert-pale); color: var(--vert); display: grid; place-items: center; font-weight: 600; flex: none; font-size: .85rem; }
.avatar.claude { background: #f6ecd4; color: #8a6514; }
.commentaire .meta { font-size: .84rem; color: var(--encre-2); }
.commentaire .texte { white-space: pre-wrap; margin-top: .15rem; }
.public-note { font-size: .82rem; color: var(--encre-2); }

/* Arbre */
.arbre-page { display: flex; flex-direction: column; height: calc(100vh - 54px); }
.arbre-barre { display: flex; gap: .8rem 1.2rem; align-items: center; flex-wrap: wrap; padding: .6rem 1.2rem; background: var(--carte); border-bottom: 1px solid var(--trait); }
.arbre-barre .champ { margin: 0; display: flex; align-items: center; gap: .4rem; }
.arbre-barre label { margin: 0; white-space: nowrap; }
.arbre-barre select { width: auto; padding: .3rem .5rem; }
.arbre-barre input[type=search] { width: 220px; padding: .35rem .6rem; }
.arbre-zone { position: relative; flex: 1; overflow: hidden; background:
  radial-gradient(circle, rgba(120,100,60,.13) 1px, transparent 1.2px) 0 0/22px 22px, var(--papier); cursor: grab; touch-action: none; }
.arbre-zone.drag { cursor: grabbing; }
.arbre-zone svg { width: 100%; height: 100%; display: block; user-select: none; }
.zoom { position: absolute; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .3rem; }
.zoom button { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--trait); background: var(--carte); font-size: 1.15rem; cursor: pointer; box-shadow: var(--ombre); }
.arbre-panneau { position: absolute; z-index: 2; left: 1rem; top: 1rem; width: 300px; max-height: calc(100% - 2rem); overflow: auto; }
.legende { position: absolute; left: 1rem; bottom: 1rem; font-size: .8rem; background: rgba(255,253,248,.92); border: 1px solid var(--trait); border-radius: 8px; padding: .4rem .7rem; display: flex; gap: .8rem; flex-wrap: wrap; max-width: 60%; }
.legende span { display: inline-flex; gap: .3rem; align-items: center; }
.legende i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.2); }
.noeud { cursor: pointer; }
.noeud rect.boite { transition: filter .12s; }
.noeud:hover rect.boite { filter: brightness(.96) drop-shadow(0 2px 4px rgba(0,0,0,.15)); }
.noeud text { font-family: var(--sans); pointer-events: none; }
.noeud .n1 { font-size: 13.5px; font-weight: 600; fill: #2b2620; }
.noeud .n2 { font-size: 12px; fill: #2b2620; letter-spacing: .03em; }
.noeud .n3 { font-size: 11px; fill: #6b6255; }
.lien { fill: none; stroke: #9b8f78; stroke-width: 1.5; }
.lien-union { stroke: #b88a2e; stroke-width: 2; }
.surligne rect.boite { stroke: #b88a2e !important; stroke-width: 3 !important; }

/* Tableaux */
table.tab { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tab th, .tab td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--trait); vertical-align: middle; }
.tab th { color: var(--encre-2); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.tab select { padding: .25rem .4rem; width: auto; }

/* Modale & toast */
.modale { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modale-fond { position: absolute; inset: 0; background: rgba(30, 25, 15, .45); }
.modale-boite { position: relative; background: var(--carte); border-radius: 12px; padding: 1.4rem 1.5rem; width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modale-x { position: absolute; right: .7rem; top: .5rem; background: none; border: 0; font-size: 1.6rem; cursor: pointer; color: var(--encre-2); }
.choix-personnes { max-height: 300px; overflow: auto; border: 1px solid var(--trait); border-radius: 7px; margin-top: .5rem; }
.choix-personnes button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--papier-2); background: #fff; padding: .5rem .7rem; cursor: pointer; font: inherit; }
.choix-personnes button:hover { background: var(--vert-pale); }
.toast { position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%); background: var(--encre); color: #fff; padding: .65rem 1.1rem; border-radius: 8px; z-index: 60; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.toast.erreur-t { background: var(--brique); }

@media (max-width: 900px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
  .burger { display: block; }
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--vert); padding: .5rem; }
  .nav.ouvert { display: flex; }
  .arbre-panneau { display: none; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: .4rem; }
}

.btn-options { display: none; }
@media (max-width: 700px) {
  .arbre-page { height: calc(100vh - 54px); height: calc(100dvh - 54px); }
  .arbre-barre { padding: .5rem .7rem; gap: .5rem; }
  .arbre-barre input[type=search] { flex: 1; width: auto; min-width: 0; }
  .btn-options { display: inline-flex; }
  #a-mode { width: 100%; }
  .arbre-barre > .champ, .arbre-barre > .opt-centre { display: none !important; }
  .arbre-barre.options-ouvertes > .champ, .arbre-barre.options-ouvertes > .opt-centre:not([hidden]) { display: flex !important; }
  .legende { display: none; }
  .chips .chip { font-size: .8rem; }
}

.preuve-vignette.citation { background: repeating-linear-gradient(0deg, #f7f0df, #f7f0df 22px, #efe5cd 23px); font-size: 2rem; }
.a-chercher { margin-top: .9rem; background: #f6ecd4; border: 1px solid #e5d0a0; color: #6d5212; border-radius: 8px; padding: .6rem .8rem; font-size: .92rem; }
