/* Généalogie — feuille de style de base.
 *
 * Direction : neutre chaud, clair et sombre. Sans-serif pour l'interface, serif
 * pour les noms de personnes — ce sont eux le contenu, le reste est de la
 * plomberie. Bordures de 1 px, aucune ombre portée : on consulte cet outil
 * longtemps, il ne doit pas fatiguer.
 *
 * Règle qui gouverne tout le reste : 40 % des fiches ne portent qu'un nom.
 * L'absence d'information se présente comme une absence assumée — jamais un
 * squelette, jamais une rangée de tirets, jamais l'air cassé.
 *
 * Polices système : aucune requête réseau, aucun fichier binaire au dépôt.
 * On vendorisera une vraie fonte le jour où le look sera arrêté.
 */

:root {
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: ui-serif, "Iowan Old Style", Georgia, "Palatino Linotype", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-sunken: #f2f0ec;
  --text: #1f1d1a;
  --text-muted: #6b665e;
  --text-faint: #9b958b;
  --border: #e3ded6;
  --border-strong: #cdc6ba;
  --accent: #2f5d8a;
  --accent-soft: #e8eff6;
  --warn: #8a6a2f;
  --warn-soft: #f6f0e4;
  --node: #8c8479;
  --node-fill: #ffffff;
  --edge: #cfc8bc;

  --nav-h: 3.25rem;
  --index-w: 15rem;
  --card-w: 23rem;
  --radius: 4px;
  --gap: 0.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #1f1e1b;
    --surface-sunken: #141312;
    --text: #eae7e1;
    --text-muted: #9a948a;
    --text-faint: #6f6a62;
    --border: #322f2a;
    --border-strong: #494439;
    --accent: #7ea8cf;
    --accent-soft: #1d2833;
    --warn: #c9a86a;
    --warn-soft: #2a241a;
    --node: #8f8879;
    --node-fill: #2b2925;
    --edge: #4a463e;
  }
}

/* Le sélecteur de thème doit gagner dans les deux sens. */
:root[data-theme="light"] {
  --bg: #faf9f7; --surface: #ffffff; --surface-sunken: #f2f0ec;
  --text: #1f1d1a; --text-muted: #6b665e; --text-faint: #9b958b;
  --border: #e3ded6; --border-strong: #cdc6ba;
  --accent: #2f5d8a; --accent-soft: #e8eff6;
  --warn: #8a6a2f; --warn-soft: #f6f0e4;
  --node: #8c8479; --node-fill: #ffffff; --edge: #cfc8bc;
}
:root[data-theme="dark"] {
  --bg: #171614; --surface: #1f1e1b; --surface-sunken: #141312;
  --text: #eae7e1; --text-muted: #9a948a; --text-faint: #6f6a62;
  --border: #322f2a; --border-strong: #494439;
  --accent: #7ea8cf; --accent-soft: #1d2833;
  --warn: #c9a86a; --warn-soft: #2a241a;
  --node: #8f8879; --node-fill: #2b2925; --edge: #4a463e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- structure */

.app {
  display: grid;
  grid-template-rows: var(--nav-h) 1fr;
  grid-template-columns: var(--index-w) 1fr 0;
  grid-template-areas: "nav nav nav" "index stage card";
  height: 100vh;
  overflow: hidden;
}
/* La fiche est une colonne à part entière : elle prend sa place au lieu de
 * recouvrir l'arbre, et l'arbre se recentre sur la largeur qui lui reste. */
.app.has-card { grid-template-columns: var(--index-w) 1fr var(--card-w); }

.navbar {
  grid-area: nav;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font: 600 15px/1 var(--serif);
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.nav-spacer { flex: 1; }
.nav-actions { display: flex; align-items: center; gap: 0.35rem; }

.btn {
  font: inherit;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}
.btn:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.btn[aria-pressed="true"] { border-color: var(--border-strong); color: var(--text); }
/* Fonction pas encore écrite plutôt que lien mort : visible, mais sans retour au
 * survol, pour ne pas laisser croire que le clic va se passer quelque chose. */
.btn[disabled] { color: var(--text-faint); cursor: default; }
.btn[disabled]:hover { background: transparent; color: var(--text-faint); }
.btn.is-primary {
  color: var(--accent);
  border-color: var(--accent);
  margin-bottom: 0.9rem;
}

.counts { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.counts strong { color: var(--text-muted); font-weight: 500; }

/* ------------------------------------------------------- liste des personnes */

.index {
  grid-area: index;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.index-search {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.index-search input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
}
.index-search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.index-sort { display: flex; gap: 0.2rem; margin-top: 0.5rem; }
.index-sort .btn { font-size: 11px; padding: 0.2rem 0.4rem; }

.index-list {
  list-style: none;
  margin: 0;
  padding: 0 0 2rem;
  overflow-y: auto;
  flex: 1;
}
.index-group {
  font: 600 10px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0.9rem 0.8rem 0.3rem;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.index-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  width: 100%;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  padding: 0.24rem 0.8rem;
  cursor: pointer;
}
.index-item:hover { background: var(--surface-sunken); }
.index-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.index-item[aria-current="true"] {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}
.index-name { font-family: var(--serif); }
.index-year {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}
.index-empty { padding: 1.2rem 0.8rem; color: var(--text-faint); font-size: 13px; }

/* --------------------------------------------------------------------- scène */

.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 24px 24px;
}
.stage svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.stage.is-panning svg { cursor: grabbing; }
.stage-zoom { display: flex; gap: 0.15rem; }
.stage-zoom .btn { padding: 0.15rem 0.45rem; min-width: 1.6rem; }

.stage-controls {
  position: absolute;
  left: 0.9rem;
  top: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-size: 12px;
  color: var(--text-muted);
}
.depth { display: flex; align-items: center; gap: 0.45rem; }
.depth input[type="range"] { width: 5.5rem; accent-color: var(--accent); }
.depth output { font-variant-numeric: tabular-nums; color: var(--text); }
.stage-count { color: var(--text-faint); font-variant-numeric: tabular-nums; }

.stage-hint {
  position: absolute;
  left: 0.9rem;
  bottom: 0.7rem;
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
  pointer-events: none;
}

/* Nœuds. Tous identiques : ni l'absence de données ni le statut d'une union ne se
 * lisent dans le trait. Ces informations sont dans la fiche et dans /gaps, où elles
 * se lisent en mots plutôt qu'en pointillés à déchiffrer. */
.node { cursor: pointer; }
.node-dot { fill: var(--node-fill); stroke: var(--node); stroke-width: 1.5px; }
.node.role-focus .node-dot { fill: var(--accent); stroke: var(--accent); }
.node.is-picked .node-dot { stroke: var(--accent); stroke-width: 3px; }
.node:hover .node-dot { stroke: var(--accent); }
.node:focus-visible { outline: none; }
.node:focus-visible .node-dot { stroke: var(--accent); stroke-width: 3px; }

.node-name {
  font: 11.5px/1 var(--serif);
  fill: var(--text);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.node.role-sibling .node-name,
.node.role-in-law .node-name { fill: var(--text-muted); }
.node.is-picked .node-name { font-weight: 700; }

.node-year {
  font: 10px/1 var(--sans);
  fill: var(--text-faint);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
}

/* Un trait unique : mariage, union libre ou statut inconnu se dessinent pareil. */
.marriage { stroke: var(--node); stroke-width: 2px; stroke-linecap: round; }
.descent { stroke: var(--edge); stroke-width: 1.2px; fill: none; }

/* ------------------------------------------------- fiche, en superposition */

.card {
  grid-area: card;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.card[hidden] { display: none; }
.card-body { overflow-y: auto; padding: 1rem 1.05rem 2.5rem; }
.card-loading { color: var(--text-faint); font-size: 13px; }

/* ---------------------------------------------------------- fiche personne */
/* Même vocabulaire de classes que tools/design_cases.py. */

.person .display-name {
  font: 400 21px/1.25 var(--serif);
  margin: 0 0 0.15rem;
}
.person .civil-name {
  font: italic 13px/1.4 var(--serif);
  color: var(--text-muted);
  margin: 0;
}

/* .person-head is the optional name+avatar row _sidebar.html adds around
   .display-name/.civil-name; tools/design_cases.py still renders those two
   flat, and the descendant selectors above cover both. */
.person-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.6rem;
}
.avatar {
  order: -1; /* left of the name, PDF keeps its own DOM-order right placement */
  flex: none;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 50%;
  object-fit: cover;
}
.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  color: var(--text-faint);
  font: 600 1.3rem/1 var(--sans);
  letter-spacing: 0.02em;
}
.nothing-known {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  margin: 0.6rem 0;
}

.card h2 {
  font: 600 11px/1 var(--sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 1.5rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

/* Naissance et décès — les deux seuls faits affichés sur une fiche. */
.vitals { margin: 0.2rem 0 0.4rem; }
.vital {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: var(--gap);
  padding: 0.34rem 0;
  border-bottom: 1px solid var(--border);
}
.vital:last-child { border-bottom: 0; }
.vital-label {
  font-size: 11px;
  color: var(--text-faint);
  padding-top: 0.1rem;
}
.vital-body .place::before { content: " · "; }

.card h3 {
  font: 600 10px/1 var(--sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0.9rem 0 0.35rem;
}

.event {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.15rem var(--gap);
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.event:last-child { border-bottom: 0; }
.event-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: lowercase;
  padding-top: 0.1rem;
}
.event-body { min-width: 0; }

.date { font-variant-numeric: tabular-nums; }
.date[data-kind="approx"],
.date[data-kind="before"],
.date[data-kind="after"],
.date[data-kind="range"] { font-style: italic; color: var(--text-muted); }
.date[data-kind="unknown"] { color: var(--text-faint); font-style: italic; }
.date[data-precision="year"],
.date[data-precision="month"] { color: var(--text-muted); }

.as-written {
  font: 11px/1 var(--mono);
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.1rem 0.25rem;
  margin-left: 0.35rem;
  white-space: nowrap;
}
.place { color: var(--text-muted); }
.place::before { content: "· "; color: var(--text-faint); }

/* Force de la preuve : de l'acte d'état civil au « on m'a dit ». */
.evidence {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  font-size: 11px;
  margin-top: 0.15rem;
  color: var(--text-faint);
}
.evidence::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
  transform: translateY(-1px);
}
.evidence[data-strength="1"] { color: var(--accent); }
.evidence[data-strength="2"] { color: var(--accent); }
.evidence[data-strength="3"] { color: var(--text-muted); }
.evidence[data-strength="4"] { color: var(--text-faint); }
.evidence[data-strength="9"] { color: var(--warn); }
.evidence[data-strength="9"]::before { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }

.event[data-confidence="medium"] .date { border-bottom: 1px dotted var(--border-strong); }
.event[data-confidence="low"] .date { border-bottom: 1px dashed var(--warn); }

.event-note {
  grid-column: 2;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0.2rem 0 0;
}

/* Listes de personnes */
.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 0.22rem 0; }
.people.is-ordered { list-style: decimal inside; }
.people.is-ordered li { padding-left: 0.1rem; }

.node-link { font-family: var(--serif); }

.person-date { font-size: 12px; color: var(--text-muted); margin-left: 0.3rem; }

.household { margin-top: 0.4rem; }
.status {
  font: 10px/1 var(--sans);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.12rem 0.3rem;
  margin-left: 0.4rem;
}
[data-status="unmarried"] .status,
[data-status="unknown"] .status { color: var(--warn); border-color: var(--warn); }

.derived { font-size: 12px; color: var(--text-faint); margin: 0.1rem 0 0.5rem; }

.note {
  font: 13px/1.5 var(--serif);
  border-left: 2px solid var(--accent);
  padding-left: 0.7rem;
  margin: 0.6rem 0;
}
.extraction-note {
  font-size: 12px;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 0.7rem;
  margin: 0.5rem 0;
}
.extraction-note[data-needs-confirmation="true"] {
  border-left-color: var(--warn);
  background: var(--warn-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.4rem 0.6rem 0.4rem 0.7rem;
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 64rem) {
  .app,
  .app.has-card {
    grid-template-columns: 1fr;
    grid-template-areas: "nav" "stage";
    grid-template-rows: var(--nav-h) 1fr;
  }
  .index { display: none; }
  /* Trop étroit pour trois colonnes : la fiche redevient une surcouche. */
  .app.has-card .card {
    position: absolute;
    inset: var(--nav-h) 0 0 0;
    border-left: 0;
  }
  .counts { display: none; }
}
