:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #f0ebe0;
  --text: #22211f;
  --muted: #6d685f;
  --line: #ddd5c6;
  --accent: #2f5d50;
  --accent-2: #e0b25c;
  --accent-text: #ffffff;
  --male: #3b6ea5;
  --female: #b5476b;
  --unknown: #8a8578;
  --male-bg: #e8eff8;
  --female-bg: #f8e9ee;
  --unknown-bg: #efede8;
  --err: #b3261e;
  --warn: #9a6400;
  --ok: #2e7d4f;
  --proven: #2e7d4f;
  --lead: #9a6400;
  --hyp: #b3261e;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161816;
    --surface: #1f2320;
    --surface-2: #272c28;
    --text: #ebe8e1;
    --muted: #a19c92;
    --line: #363c37;
    --accent: #6fb39d;
    --accent-2: #e0b25c;
    --accent-text: #0f1a16;
    --male: #82aee0;
    --female: #e48aa8;
    --unknown: #a8a397;
    --male-bg: #1f2a36;
    --female-bg: #34222a;
    --unknown-bg: #2a2a27;
    --err: #f28b82;
    --warn: #e6b65c;
    --ok: #7fcf9c;
    --proven: #7fcf9c;
    --lead: #e6b65c;
    --hyp: #f28b82;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
small { font-size: .85em; }

/* --- En-tête --- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 16px;
  background: var(--accent); color: var(--accent-text);
}
.brand { color: inherit; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .45rem; }
.brand:hover { text-decoration: none; }
#nav { display: flex; gap: .15rem; flex-wrap: wrap; }
#nav a { color: inherit; opacity: .85; padding: .3rem .6rem; border-radius: 6px; }
#nav a:hover { opacity: 1; text-decoration: none; background: rgb(255 255 255 / 12%); }
#nav a.active { opacity: 1; background: rgb(255 255 255 / 20%); font-weight: 600; }
body:not(.logged) #nav, body:not(.logged) #menu-btn { display: none; }
#menu-btn { display: none; margin-left: auto; color: inherit; font-size: 1.3rem; }
@media (max-width: 860px) {
  #menu-btn { display: block; }
  #nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--accent); padding: .4rem 16px .8rem; }
  body.menu-open #nav { display: flex; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1.2rem 16px 3rem; }
.loading { color: var(--muted); }

/* --- Éléments communs --- */
button, .btn {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .42rem .85rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.danger { color: var(--err); }
button.danger:hover { border-color: var(--err); }
.small { padding: .2rem .6rem; font-size: .88rem; }
button.icon { border: 0; background: none; padding: .2rem .5rem; font-size: 1.4rem; line-height: 1; }
button.link { border: 0; background: none; padding: 0 .3rem; color: var(--accent); font-size: .88rem; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--err); }
.btns { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.form { display: flex; flex-direction: column; gap: .7rem; }
.form.compact { gap: .5rem; }
.field { display: flex; flex-direction: column; gap: .2rem; }
.field label { font-size: .88rem; font-weight: 600; }
.hint { color: var(--muted); }
.check { display: flex; align-items: center; gap: .4rem; font-size: .92rem; }
.check input { width: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
fieldset { border: 1px dashed var(--line); border-radius: 8px; padding: .5rem .8rem .8rem; display: flex; flex-direction: column; gap: .5rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.page-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .8rem; flex-wrap: wrap; }
.toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.toolbar input { max-width: 420px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

.badge { display: inline-block; font-size: .74rem; padding: .05rem .45rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge.c-proven { color: var(--proven); border-color: var(--proven); }
.badge.c-lead { color: var(--lead); border-color: var(--lead); }
.badge.c-hypothesis { color: var(--hyp); border-color: var(--hyp); }
.living { color: var(--ok); font-size: .8em; }
.years { color: var(--muted); font-size: .9em; }
.plink { font-weight: 500; }
.plink.sex-M { color: var(--male); }
.plink.sex-F { color: var(--female); }
.sex-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; background: var(--unknown); }
.sex-dot.sex-M { background: var(--male); }
.sex-dot.sex-F { background: var(--female); }
.note { white-space: pre-wrap; color: var(--muted); font-size: .92rem; margin: .2rem 0; }
.ext { margin-left: .2rem; }

ul.plain, ul.rows, ul.results, ul.cits, ul.timeline { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .2rem 0; }
ul.rows > li { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; padding: .45rem 0; border-top: 1px solid var(--line); }
ul.rows > li:first-child { border-top: 0; }
.row-actions { display: flex; flex-shrink: 0; gap: .1rem; flex-wrap: wrap; justify-content: flex-end; }

/* --- Accueil --- */
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 { font-size: 2rem; }
.search-wrap { max-width: 560px; margin: 1rem auto 0; text-align: left; position: relative; }
.big-search { font-size: 1.1rem; padding: .7rem 1rem; border-radius: 12px; }
.search-wrap .results { margin-top: .3rem; background: var(--surface); border-radius: 10px; border: 1px solid var(--line); }
.search-wrap .results:empty { display: none; }
.search-wrap .results li { padding: .4rem .9rem; border-top: 1px solid var(--line); }
.search-wrap .results li:first-child { border-top: 0; }
.root-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.root-card h2 { font-size: 1.25rem; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; display: flex; flex-direction: column; color: var(--text); }
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat strong { font-size: 1.5rem; color: var(--accent); line-height: 1.2; }
.stat span { color: var(--muted); font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: .15rem .65rem; font-size: .9rem; color: var(--text); }
.chip span { color: var(--muted); margin-left: .35rem; font-size: .8rem; }
.chip:hover { border-color: var(--accent); text-decoration: none; }

/* --- Connexion --- */
.login { max-width: 360px; margin: 10vh auto 0; background: var(--surface); padding: 1.6rem; border-radius: 14px; border: 1px solid var(--line); box-shadow: var(--shadow); }

/* --- Liste --- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .5rem .8rem; border-top: 1px solid var(--line); vertical-align: top; }
table.list th { border-top: 0; font-size: .85rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
table.list tr:hover td { background: var(--surface-2); }

/* --- Fiche --- */
.person-head { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; align-items: start; margin-bottom: 1rem; }
.person-head .btns { grid-column: 1 / -1; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 1.3rem; background: var(--unknown-bg); color: var(--unknown); border: 2px solid currentColor; }
.avatar.sex-M { background: var(--male-bg); color: var(--male); }
.avatar.sex-F { background: var(--female-bg); color: var(--female); }
.surname { text-transform: uppercase; letter-spacing: .02em; }
.nick { color: var(--muted); font-weight: 400; font-size: .8em; }
.person-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .person-grid { grid-template-columns: 1fr; } }
.more { position: relative; }
.more > summary { list-style: none; }
.more > summary::-webkit-details-marker { display: none; }
.more .menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 240px; padding: .3rem; }
.more .menu button { border: 0; text-align: left; justify-content: flex-start; }
@media (max-width: 560px) { .more .menu { right: auto; left: 0; } }

ul.timeline > li { display: grid; grid-template-columns: 9.5rem 1fr auto; gap: .6rem; padding: .5rem 0; border-top: 1px solid var(--line); }
ul.timeline > li:first-child { border-top: 0; }
.ev-date { font-weight: 600; font-size: .92rem; }
ul.timeline.small > li { grid-template-columns: 8rem 1fr auto; font-size: .93rem; }
@media (max-width: 560px) {
  ul.timeline > li, ul.timeline.small > li { grid-template-columns: 1fr; gap: .1rem; }
  .row-actions { justify-content: flex-start; }
}
.family { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem; margin-bottom: .7rem; background: var(--surface-2); }
.family:last-child { margin-bottom: 0; }
.couple, .union-head { display: flex; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.couple > div { flex: 1; min-width: 160px; }
.link-info { font-size: .9rem; margin-top: .4rem; }
.siblings { margin-top: .4rem; font-size: .92rem; }
.children { margin-top: .5rem; }
.children ul.rows > li { padding: .3rem 0; }
details.small summary { cursor: pointer; font-size: .88rem; margin-top: .5rem; }
details.small .btns { margin-top: .4rem; }

ul.cits { margin-top: .2rem; }
ul.cits li { font-size: .9rem; padding: .15rem 0; }
ul.cits.compact li { font-size: .85rem; }
.src-icon { color: var(--accent-2); font-weight: 700; margin-right: .3rem; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; margin-bottom: .6rem; }
.media-grid figure { margin: 0; }
.media-grid img, .media-grid .pdf { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.media-grid figcaption { font-size: .8rem; color: var(--muted); word-break: break-word; }
.task.st-done strong { text-decoration: line-through; color: var(--muted); }
.task input[type=checkbox] { width: auto; vertical-align: middle; }

/* --- Fenêtres --- */
dialog.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / 30%); }
dialog.modal.wide { width: min(820px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem .4rem; position: sticky; top: 0; background: var(--surface); }
dialog header h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: .4rem 1.1rem 1.1rem; }
.picker .results { margin: .6rem 0; max-height: 45vh; overflow-y: auto; }
.picker .results li { border-top: 1px solid var(--line); }
.picker .results li:first-child { border-top: 0; }
.result { width: 100%; border: 0; background: none; text-align: left; padding: .5rem .3rem; border-radius: 6px; display: block; }
.result:hover { background: var(--surface-2); }
.create summary { cursor: pointer; color: var(--accent); font-weight: 600; margin: .4rem 0 .6rem; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); transition: opacity .4s; }
.toast.err { background: var(--err); color: #fff; }
.toast.out { opacity: 0; }

/* --- Contrôle --- */
.lvl-err h2 { color: var(--err); }
.lvl-warn h2 { color: var(--warn); }
.lvl-info h2 { color: var(--muted); }

/* --- Parenté --- */
.rel .row { margin-bottom: 1rem; }
.big { font-size: 1.2rem; }

/* --- Arbres --- */
.chart-bar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .6rem; }
.chart-title { font-weight: 600; flex: 1; min-width: 180px; }
.chart-bar output { font-size: .88rem; color: var(--muted); min-width: 6.5rem; text-align: center; }
.sep { width: .6rem; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tab { padding: .35rem .8rem; color: var(--text); background: var(--surface); }
.tab + .tab { border-left: 1px solid var(--line); }
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab:hover { text-decoration: none; }
.chart-host { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); height: calc(100vh - 210px); min-height: 380px; overflow: hidden; touch-action: none; }
svg.chart { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
svg.chart:active { cursor: grabbing; }
.card { cursor: pointer; }
.card rect:first-child { fill: var(--unknown-bg); stroke: var(--line); }
.card.sex-M rect:first-child { fill: var(--male-bg); }
.card.sex-F rect:first-child { fill: var(--female-bg); }
.card .stripe { fill: var(--unknown); }
.card.sex-M .stripe { fill: var(--male); }
.card.sex-F .stripe { fill: var(--female); }
.card.root rect:first-child { stroke: var(--accent-2); stroke-width: 2.5; }
.card:hover rect:first-child, .card:focus rect:first-child { stroke: var(--accent); stroke-width: 2; }
.card:focus { outline: none; }
.card text, .fan-cell text { fill: var(--text); font-size: 13px; }
.card .given { font-weight: 600; }
.card .surname { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.card .yrs, .fan-cell .yrs { fill: var(--muted); font-size: 11px; }
.link { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.link.c-lead { stroke-dasharray: 7 4; stroke: var(--lead); }
.link.c-hypothesis { stroke-dasharray: 2 4; stroke: var(--hyp); stroke-width: 2; }
.link.non-bio { stroke: var(--accent-2); }
.link.spouse { stroke: var(--accent-2); stroke-width: 2; }
text.more { fill: var(--muted); font-size: 12px; }
.fan-cell { cursor: pointer; }
.fan-cell path, .fan-cell circle { fill: var(--unknown-bg); stroke: var(--surface); stroke-width: 1; }
.fan-cell.sex-M path, .fan-cell.sex-M circle { fill: var(--male-bg); }
.fan-cell.sex-F path, .fan-cell.sex-F circle { fill: var(--female-bg); }
.fan-cell.root circle { stroke: var(--accent-2); stroke-width: 3; }
.fan-cell.c-hypothesis path { stroke: var(--hyp); stroke-dasharray: 3 3; stroke-width: 1.5; }
.fan-cell:hover path { fill: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
.fan-cell .given { font-weight: 600; font-size: 12px; }
.fan-cell .given.small { font-size: 11px; }
.fan-cell .surname { font-size: 11px; text-transform: uppercase; }
.fan-empty { fill: none; stroke: var(--line); stroke-dasharray: 2 3; }
.legend { font-size: .85rem; margin-top: .5rem; }
.lg::before { content: ""; display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--muted); vertical-align: middle; margin-right: .3rem; }
.lg-lead::before { border-top: 2px dashed var(--lead); }
.lg-hyp::before { border-top: 2px dotted var(--hyp); }
