:root {
  --bg: #F4F1EA;
  --bg-tree: #FAF8F3;
  --surface: #FFFEFB;
  --input: #FFFFFF;
  --ink: #23201B;
  --ink-2: #433E36;
  --muted: #5F5A50;
  --border: #D3CDBF;
  --border-soft: #E2DDD1;
  --rule: #EFEBE2;
  --line: #B5AD9C;
  --seg: #ECE8DE;
  --green: #2E5A4C;
  --green-dark: #1F3F35;
  --green-tint: #EAF2EE;
  --green-tint-2: #F3F7F5;
  --green-border: #BFD0C8;
  --green-soft-text: #D5E3DD;
  --ochre: #B08A4A;
  --ochre-text: #7A5418;
  --ochre-dark: #5E4012;
  --ochre-bg: #FBF6EC;
  --ochre-border: #E8D9BE;
  --ochre-tint: #F4E9D6;
  --danger: #A2321E;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid #E0B34D; outline-offset: 2px; }
a { color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); text-decoration: none; white-space: nowrap; }
.btn:hover { background: #F7F4ED; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--green-dark); }
.btn-outline { border-color: var(--green); color: var(--green); font-weight: 600; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--seg); }
.btn-link { border: 0; background: none; padding: 0 4px; min-height: 44px; color: var(--green); font-weight: 600; }
.btn-danger { border-color: #E6C2BA; color: var(--danger); }
.btn-icon { width: 44px; min-height: 44px; padding: 0; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 15px; }

/* ---------- En-tête ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 24px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand-title { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 25px; line-height: 1; margin: 0; }
.brand-sub { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search-box { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 16px; border: 1px solid var(--border); border-radius: 10px; background: #FDFCF8; }
.search-box input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; }
.search-results { position: absolute; left: 0; right: 0; top: 54px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 30px rgba(35,32,27,.14); padding: 6px; max-height: 60vh; overflow: auto; z-index: 30; }
.result { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; text-align: left; }
.result:hover, .result.active { background: var(--green-tint); }
.result .r-name { font-family: var(--serif); font-weight: 600; font-size: 17px; }
.result .r-meta { font-size: 13px; color: var(--muted); }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--seg); border-radius: 12px; }
.seg button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); }
.seg button[aria-current="page"], .seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.topstats { margin-left: auto; display: flex; align-items: center; gap: 18px; font-size: 14px; color: var(--muted); }
.topstats strong { font-family: var(--serif); font-weight: 600; font-size: 20px; color: var(--ink); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 52px; min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 30px rgba(35,32,27,.14); padding: 6px; z-index: 30; display: flex; flex-direction: column; }
.menu button, .menu a { min-height: 44px; padding: 0 12px; border: 0; background: none; text-align: left; border-radius: 8px; color: var(--ink); text-decoration: none; display: flex; align-items: center; }
.menu button:hover, .menu a:hover { background: var(--seg); }

/* ---------- Mise en page arbre ---------- */
.layout { display: flex; flex-wrap: wrap; align-items: stretch; min-height: calc(100vh - 78px); }
.tree-col { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 14px; padding: 20px 24px; }
.tree-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.tree-head h1 { margin: 0; font-family: var(--serif); font-size: 28px; font-weight: 600; }
.tree-tools { margin-left: auto; display: flex; gap: 8px; }
.tree-scroll { flex: 1; min-height: 520px; overflow: auto; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--bg-tree); }
.tree-sizer { position: relative; }
.tree-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; padding: 36px 40px 48px 124px; display: flex; flex-direction: column; gap: 56px; min-width: 100%; }
.tree-lines { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tree-lines path { fill: none; stroke: var(--line); stroke-width: 2; }
.tree-lines path.half { stroke-dasharray: 6 5; }
.tree-row { display: flex; align-items: center; justify-content: center; gap: 0 36px; }
.row-label { position: absolute; width: 100px; font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--muted); line-height: 1.25; }
.tree-split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 56px; }
.tree-split > .side { display: flex; justify-content: center; gap: 32px; }
.tree-row.focal-row { gap: 0 36px; align-items: center; }
.cluster { display: flex; gap: 36px; align-items: center; }
.children-row { display: flex; justify-content: center; gap: 56px; align-items: flex-start; flex-wrap: nowrap; }

.pcard { position: relative; width: 200px; min-height: 84px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; text-align: left; display: flex; flex-direction: column; gap: 3px; z-index: 1; flex: none; }
.pcard:hover { border-color: var(--green); box-shadow: 0 4px 12px rgba(46,90,76,.12); }
.pcard .n { font-family: var(--serif); font-size: 18px; font-weight: 600; line-height: 1.2; }
.pcard .y { font-size: 14px; color: var(--ink-2); }
.pcard .s { font-size: 13px; color: var(--muted); }
.pcard.focal { width: 224px; min-height: 100px; padding: 14px 16px; background: var(--green); border-color: var(--green); color: #fff; border-radius: 12px; box-shadow: 0 6px 18px rgba(30,60,50,.22); cursor: default; }
.pcard.focal .n { font-size: 21px; }
.pcard.focal .y { color: #fff; }
.pcard.focal .s { color: var(--green-soft-text); }
.pcard .sex { position: absolute; top: 10px; right: 12px; font-size: 13px; color: var(--muted); }
.pcard.focal .sex { color: var(--green-soft-text); }
.ghost { width: 200px; min-height: 84px; padding: 12px 14px; border: 2px dashed var(--ochre); border-radius: 10px; background: transparent; color: var(--ochre-text); display: flex; align-items: center; gap: 10px; text-align: left; z-index: 1; flex: none; }
.ghost:hover { background: var(--ochre-bg); }
.ghost .plus { width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--ochre-tint); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.ghost span:last-child { font-size: 14px; line-height: 1.35; }
.slot-empty { width: 200px; min-height: 84px; flex: none; }

/* ---------- Fiche ---------- */
.fiche { flex: 1 1 360px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--border-soft); padding: 24px; display: flex; flex-direction: column; gap: 22px; }
.fiche-id { display: flex; gap: 16px; align-items: center; }
.avatar { width: 72px; height: 72px; flex: none; border-radius: 50%; background: #E3ECE8; color: var(--green); display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-style: italic; font-size: 28px; font-weight: 500; }
.fiche h2 { margin: 0; font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1.1; }
.quick-add { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--green-tint-2); border-radius: 12px; }
.quick-add .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quick-add .grid button { min-height: 48px; padding: 4px 8px; border: 1px solid var(--green-border); border-radius: 10px; background: var(--surface); display: flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.2; }
.quick-add .grid button .plus { color: var(--green); font-size: 18px; }
.quick-add .grid button.done { border-style: dashed; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 10px; }
.event { display: flex; gap: 14px; }
.event .k { width: 92px; flex: none; font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--muted); padding-top: 1px; }
.event .v { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.event .v small { font-size: 14px; color: var(--muted); }
.event .edit { align-self: flex-start; min-height: 32px; font-size: 14px; }
.links { display: flex; flex-direction: column; gap: 2px; }
.link-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.link-row .rel { width: 92px; flex: none; font-size: 14px; color: var(--muted); }
.link-row .who { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 6px 0; color: var(--ink); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px; }
.link-row .who:hover { text-decoration-color: var(--green); }
.link-row .x { width: 40px; min-height: 40px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 20px; }
.link-row .x:hover { background: #F6E4E0; color: var(--danger); }
.source { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border-soft); border-radius: 10px; }
.source .t { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.source .t small { font-size: 13px; color: var(--muted); }
.notice { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--ochre-border); background: var(--ochre-bg); border-radius: 10px; color: var(--ochre-dark); font-size: 15px; }
.notes { white-space: pre-line; margin: 0; }
.fiche-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.fiche-actions .btn { flex: 1 1 140px; }

/* ---------- Modales ---------- */
.overlay { position: fixed; inset: 0; background: rgba(54,50,43,.62); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.dialog { width: 100%; max-width: 780px; background: var(--surface); border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; }
.dialog.narrow { max-width: 520px; }
.dialog-head { display: flex; align-items: flex-start; gap: 16px; padding: 24px 28px 18px; border-bottom: 1px solid #E8E3D8; }
.dialog-head h1 { margin: 0; font-family: var(--serif); font-size: 30px; font-weight: 600; line-height: 1.15; }
.dialog-body { padding: 22px 28px; display: flex; flex-direction: column; gap: 24px; }
.dialog-foot { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 28px 24px; border-top: 1px solid #E8E3D8; }
.dialog-foot .right { margin-left: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.close { width: 44px; height: 44px; border: 0; border-radius: 10px; background: #F2EFE7; margin-left: auto; flex: none; display: flex; align-items: center; justify-content: center; }
fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
legend { padding: 0; margin-bottom: 12px; font-weight: 600; }
legend .num { font-family: var(--serif); font-style: italic; font-weight: 500; color: var(--green); }
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.tiles button { min-height: 64px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 6px; }
.tiles button[aria-pressed="true"] { border: 2px solid var(--green); background: var(--green-tint); color: var(--green-dark); font-weight: 600; }
.panel { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; background: #F6F3EC; border-radius: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; }
.chip:has(input:checked) { border: 2px solid var(--green); }
.chip input { accent-color: var(--green); width: 18px; height: 18px; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.one { grid-template-columns: minmax(0, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 15px; color: var(--ink-2); }
.form-grid label small, .field small { font-size: 13px; color: var(--muted); }
.form-grid input:not([type=radio]):not([type=checkbox]), .form-grid textarea, .form-grid select { min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); color: var(--ink); }
.form-grid textarea { padding: 12px 14px; min-height: 110px; resize: vertical; }
.sexes { display: flex; gap: 8px; }
.sexes label { flex: 1; flex-direction: row; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); cursor: pointer; }
.sexes label:has(input:checked) { border: 2px solid var(--green); }
.sexes input { accent-color: var(--green); width: 18px; height: 18px; margin: 0; }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; min-height: 44px; color: var(--ink) !important; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow: auto; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); text-align: left; }
.pick[aria-pressed="true"] { border: 2px solid var(--green); background: var(--green-tint); }
.pick .r-name { font-family: var(--serif); font-weight: 600; }
.pick small { color: var(--muted); }
.alert { margin: 0; padding: 12px 14px; border-radius: 10px; background: #F6E4E0; color: var(--danger); border: 1px solid #E6C2BA; }

/* ---------- Ascendance / lieux ---------- */
.page { display: flex; flex-wrap: wrap; gap: 24px; padding: 24px; align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 6px; }
.card h1, .card h2 { margin: 0; font-family: var(--serif); font-weight: 600; }
.card h1 { font-size: 28px; }
.card h2 { font-size: 24px; }
.gens { flex: 1 1 320px; max-width: 420px; }
.gen-btn { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 2px solid transparent; border-radius: 10px; background: transparent; text-align: left; width: 100%; }
.gen-btn:hover { background: #F7F4ED; }
.gen-btn[aria-current="true"] { border-color: var(--green); background: var(--green-tint); }
.gen-btn .top { display: flex; justify-content: space-between; gap: 8px; width: 100%; }
.gen-btn .roman { font-family: var(--serif); font-style: italic; color: var(--green); }
.bar { height: 8px; border-radius: 4px; background: #E8E3D8; overflow: hidden; display: block; }
.bar > span { display: block; height: 100%; background: var(--green); border-radius: 4px; min-width: 3px; }
.gen-table-card { flex: 999 1 560px; min-width: 0; gap: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 640px; border-collapse: collapse; }
th { text-align: left; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); }
td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
td.sosa { font-family: var(--serif); font-style: italic; color: var(--muted); }
td .pname { font-family: var(--serif); font-size: 18px; font-weight: 600; border: 0; background: none; padding: 0; text-align: left; color: var(--ink); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px; }
tr.missing { background: #FBF8F1; }
tr.missing .who { color: var(--ochre-text); }
.btn-ochre { border-color: #C9A86E; color: var(--ochre-dark); }
.places { flex: 1 1 100%; max-width: 980px; }
.place { border-bottom: 1px solid var(--rule); }
.place > button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; border: 0; background: none; text-align: left; padding: 8px 4px; }
.place .pl { flex: 1; font-family: var(--serif); font-size: 18px; font-weight: 600; }
.place .cnt { font-size: 14px; color: var(--muted); }
.place ul { list-style: none; margin: 0 0 12px; padding: 0 0 0 4px; display: flex; flex-direction: column; gap: 2px; }
.place li { display: flex; gap: 12px; align-items: center; min-height: 40px; }
.place li .ev { width: 90px; font-size: 14px; color: var(--muted); }
.place li button { border: 0; background: none; padding: 4px 0; color: var(--ink); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px; }

/* ---------- Connexion / démarrage ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 18px; padding: 32px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 12px 40px rgba(35,32,27,.08); }
.login-card .brand-title { font-size: 40px; }
.start { max-width: 760px; margin: 40px auto; padding: 0 16px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(560px, calc(100% - 32px)); }
.toast { padding: 14px 18px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 15px; }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .topstats { display: none; }
  .topbar { padding-right: 64px; }
  .menu-wrap { position: absolute; top: 12px; right: 12px; }
  .menu { right: 0; }
  .tree-col { padding: 16px; }
  .fiche { border-left: 0; border-top: 1px solid var(--border-soft); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .dialog-head, .dialog-body, .dialog-foot { padding-left: 18px; padding-right: 18px; }
  .overlay { padding: 12px; }
  .page { padding: 16px; }
}
