:root {
  --bg: #f4f1ea;
  --grid: rgba(60, 50, 30, 0.07);
  --surface: #ffffff;
  --surface-2: #f7f5f0;
  --border: #e3ddd0;
  --text: #24221d;
  --muted: #706a5e;
  --brand: #2f6f5e;
  --brand-ink: #ffffff;
  --accent: #c2703d;
  --line: #a59d8c;
  --couple: #2f6f5e;
  --male: #3f74c9;
  --male-soft: #e5edfa;
  --female: #c9507f;
  --female-soft: #fae6ee;
  --unknown: #8d8778;
  --unknown-soft: #eeebe4;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 4px 14px rgba(40, 30, 10, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a19;
    --grid: rgba(255, 255, 255, 0.05);
    --surface: #222725;
    --surface-2: #1c201f;
    --border: #353c39;
    --text: #ece9e2;
    --muted: #a39e93;
    --brand: #5fb39b;
    --brand-ink: #0d1a16;
    --accent: #e0915d;
    --line: #6f7873;
    --couple: #5fb39b;
    --male: #7ea6ec;
    --male-soft: #23324a;
    --female: #ec88ae;
    --female-soft: #47283a;
    --unknown: #a8a394;
    --unknown-soft: #34352f;
    --danger: #f2817a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: 7px 12px;
  white-space: nowrap;
}
button:hover { border-color: var(--line); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.accent { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.icon { width: 36px; padding: 7px 0; font-size: 16px; }
button:disabled { opacity: .4; cursor: default; }

/* ---------- Barre d'outils ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--brand); }
.brand svg rect { fill: var(--brand); }
.brand svg path { stroke: var(--brand); }
.tree-name {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 600;
  min-width: 120px;
  width: 220px;
}
.tree-name:hover, .tree-name:focus { border-color: var(--border); background: var(--surface-2); }
.tb-group { display: flex; gap: 6px; align-items: center; }
.tb-group.right { margin-left: auto; }
.search input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 7px 10px;
  width: 220px;
}
.count { color: var(--muted); font-size: 13px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 250px;
  z-index: 20;
}
.menu[hidden] { display: none; }
.menu button { border: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; background: transparent; }
.menu button:hover { background: var(--surface-2); }
.menu small { color: var(--muted); }
.menu.menu-left { right: auto; left: 0; min-width: 300px; max-width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto; }
.menu-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 8px; }
.menu-title small { text-transform: none; letter-spacing: 0; }
.tree-item { display: flex; align-items: stretch; border-radius: 9px; }
.tree-item > button:first-child { flex: 1; min-width: 0; }
.tree-item b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item.current { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.tree-item.current b { color: var(--brand); }
.menu .tree-del { flex: none; justify-content: center; padding: 0 10px; opacity: .55; }
.menu .tree-del:hover { opacity: 1; background: color-mix(in srgb, var(--danger) 12%, transparent); }
.menu .tree-new { border-top: 1px solid var(--border); border-radius: 0 0 9px 9px; margin-top: 4px; color: var(--brand); font-weight: 600; }

/* ---------- Zone de l'arbre ---------- */
.main { flex: 1; display: flex; min-height: 0; position: relative; }
.viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  /* Glisser pour déplacer la vue ne doit jamais sélectionner de texte (légende, cartes…). */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.viewport.dragging { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.links { position: absolute; overflow: visible; pointer-events: none; }
.links path { fill: none; stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.links path.couple { stroke: var(--couple); stroke-width: 3; }
.links path.divorce { stroke: var(--couple); stroke-width: 2.5; stroke-dasharray: 6 5; }

/* ---------- Cartes ---------- */
.card {
  position: absolute;
  width: 200px;
  height: 92px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow .15s, transform .15s;
}
.card::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--unknown);
}
.card.sex-M::before { background: var(--male); }
.card.sex-F::before { background: var(--female); }
.card:hover { box-shadow: 0 0 0 1px var(--line), var(--shadow); }
.card.selected { box-shadow: 0 0 0 3px var(--brand), var(--shadow); }
.card.flash { animation: flash 1s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 10px rgba(194, 112, 61, .45); } 100% { box-shadow: 0 0 0 3px var(--brand); } }
.card { -webkit-touch-callout: none; cursor: grab; }
.card.moving { cursor: grabbing; transition: none; transform: scale(1.04); box-shadow: 0 0 0 2px var(--accent), 0 10px 28px rgba(0, 0, 0, .22); z-index: 5; }
.card.moving .add { display: none; }
.zoom button[hidden] { display: none; }
.card.deceased { background: var(--surface-2); }
.card.deceased .name, .card.deceased .lastname { color: var(--muted); }

.avatar {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  background: var(--unknown-soft);
  color: var(--unknown);
  position: relative;
}
.sex-M .avatar, .avatar.sex-M { background: var(--male-soft); color: var(--male); }
.sex-F .avatar, .avatar.sex-F { background: var(--female-soft); color: var(--female); }
.deceased .avatar::after {
  content: "†";
  position: absolute;
  right: -5px; bottom: -6px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  color: var(--muted);
}
.info { min-width: 0; flex: 1; line-height: 1.3; }
.info > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name { font-weight: 650; font-size: 14.5px; }
.lastname { font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.dates { font-size: 12px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.age { font-size: 12px; color: var(--text); }
.placeholder { color: var(--muted); font-style: italic; font-weight: 500; }

.add {
  position: absolute;
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  border: 2px solid var(--surface);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(.7);
  transition: opacity .12s, transform .12s;
  z-index: 2;
}
.card:hover .add, .card.selected .add { opacity: 1; transform: scale(1); }
.add:hover { background: var(--accent); }
.add-parent { left: 50%; top: -14px; margin-left: -13px; }
.add-child { left: 50%; bottom: -14px; margin-left: -13px; }
.add-spouse { right: -14px; top: 50%; margin-top: -13px; }
@media (hover: none) { .card .add { opacity: 1; transform: scale(1); } }

/* ---------- Écran vide ---------- */
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; pointer-events: none; }
.empty[hidden] { display: none; }
.empty-box {
  pointer-events: auto;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px;
  text-align: center;
  cursor: default;
}
.empty-box h1 { margin: 0 0 8px; font-size: 22px; }
.empty-box p { color: var(--muted); margin: 0 0 18px; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.zoom { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 38px; height: 38px; padding: 0; font-size: 18px; box-shadow: var(--shadow); }
.legend {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; font-size: 12px; color: var(--muted);
  pointer-events: none;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend .legend-privacy { pointer-events: auto; border-left: 1px solid var(--border); padding-left: 12px; color: var(--brand); cursor: help; }
.privacy-note { font-size: 13px; color: var(--brand) !important; margin: 18px 0 0 !important; }

/* ---------- Mot de passe ---------- */
.pwd-dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 22px;
  width: min(400px, calc(100vw - 32px));
}
.pwd-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.pwd-dialog h2 { margin: 0 0 6px; font-size: 18px; }
.pwd-dialog .muted { margin-bottom: 14px; }
.pwd-dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.pwd-dialog label[hidden] { display: none; }
.pwd-dialog input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 9px 10px;
  color: var(--text);
  font-size: 15px;
}
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.pdf-dialog { width: min(440px, calc(100vw - 32px)); }
/* Poster décoratif */
.poster-dialog { width: min(900px, calc(100vw - 32px)); }
.poster-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.poster-preview { position: relative; display: flex; justify-content: center; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 14px; min-height: 240px; overflow: hidden; }
.poster-preview canvas { display: block; max-width: 100%; height: auto; box-shadow: 0 6px 22px rgba(0,0,0,.18), 0 1px 3px rgba(0,0,0,.12); }
#posterCanvas { cursor: zoom-in; touch-action: none; }
.poster-preview .poster-lens { position: absolute; left: 0; top: 0; width: 190px; height: 190px; max-width: none; border-radius: 50%;
  pointer-events: none; border: 3px solid #fff; box-shadow: 0 8px 28px rgba(0,0,0,.35), 0 0 0 1px rgba(0,0,0,.2); z-index: 2; }
.poster-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.script-pick { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 13px; }
.script-pick select { max-width: 9rem; padding: 6px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.arabic.alt-ltr { text-align: left; }
.poster-opts .seg { max-width: none; }
.poster-opts label { margin-bottom: 10px; }
.poster-styles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.poster-styles button { display: flex; align-items: center; gap: 8px; padding: 7px 9px; font-size: 13.5px; justify-content: flex-start; }
.poster-styles button.on { border-color: var(--brand); box-shadow: 0 0 0 1.5px var(--brand) inset; font-weight: 600; }
.sw { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.sw-classique { background: linear-gradient(135deg, #fbf9f4 55%, #2f6f5e 55%); }
.sw-calligraphie { background: linear-gradient(135deg, #0f1e36 55%, #c9a54a 55%); }
.sw-parchemin { background: linear-gradient(135deg, #f1e4c3 55%, #6b4a24 55%); }
.sw-moderne { background: linear-gradient(135deg, #ffffff 55%, #e3ecfb 55%); }
.menu .menu-poster b { color: var(--brand); }
@media (max-width: 700px) {
  .poster-body { grid-template-columns: 1fr; }
  .poster-preview { min-height: 0; }
}
.pdf-field { margin-bottom: 14px; }
.pdf-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.pdf-dialog .seg { max-width: 200px; }
.pdf-dialog label.pdf-choice { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.pdf-dialog label.pdf-choice:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.pdf-choice input { margin-top: 3px; accent-color: var(--brand); }
.pdf-choice span { display: flex; flex-direction: column; gap: 2px; }
.pdf-choice small { color: var(--muted); font-size: 12.5px; }
.pdf-info { font-size: 13px; color: var(--text); background: var(--surface-2); border-radius: 9px; padding: 9px 11px; margin: 0 0 14px; }

/* ---------- Conjoint (nouveau ou existant) et branche ---------- */
#branchDialog .seg { max-width: none; }
#branchDialog input[type=text], .pick-dialog input[type=text] { width: 100%; box-sizing: border-box; margin-bottom: 6px; }
#branchDialog select { width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 9px; padding: 4px; font-size: 14px; }
#branchDialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 4px 0 0; }
.pick-dialog { width: min(440px, calc(100vw - 32px)); }
.pick-dialog .wide { width: 100%; padding: 11px; font-size: 15px; margin: 8px 0 4px; }
.pick-or { font-size: 13px; color: var(--muted); margin: 14px 0 8px; }
.pick-list { max-height: min(300px, 45vh); overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 14px; }
.pick-list button { display: flex; width: 100%; justify-content: space-between; align-items: baseline; gap: 10px; text-align: left; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; padding: 9px 11px; font-size: 14px; }
.pick-list button:last-child { border-bottom: 0; }
.pick-list button:hover, .pick-list button:focus-visible { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.pick-list small { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.pick-list small.kin { color: var(--brand); font-weight: 600; }
.pick-list .pick-head { padding: 6px 11px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.pick-empty { padding: 12px; font-size: 13px; color: var(--muted); }

.install-dialog { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.install-head { display: flex; align-items: center; justify-content: space-between; }
.install-head h2 { margin: 0; }
.install-head .close { border: 0; font-size: 24px; padding: 0 8px; background: transparent; }
.install-dialog > .muted { margin: 6px 0 14px; }
.install-dialog .seg { margin-bottom: 16px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.step { margin: 0; }
.step svg { display: block; width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.step figcaption { font-size: 13.5px; margin-top: 8px; line-height: 1.4; }
.step figcaption b.n { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 12px; margin-right: 6px; }
.install-note { font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.install-now { margin: 0 0 14px; }
@media (max-width: 620px) { .steps { grid-template-columns: 1fr; } .step svg { max-width: 300px; margin: 0 auto; } }
.pwd-error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 0 0 8px; }
.pwd-actions { display: flex; justify-content: flex-end; gap: 8px; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--couple); }
.legend i.l-divorce { border-top: 2.5px dashed var(--couple); }
.legend i.l-child { border-top: 2px solid var(--line); }

/* ---------- Panneau latéral ---------- */
.panel {
  width: 380px;
  flex: none;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0 0 30px;
}
.panel[hidden] { display: none; }
.panel-head {
  position: sticky; top: 0;
  background: var(--surface);
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.panel-head h2 { margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-head .sub { color: var(--muted); font-size: 13px; }
.panel-head > div:nth-child(2) { flex: 1; min-width: 0; }
.panel-head .close { border: 0; font-size: 22px; padding: 2px 8px; background: transparent; }
.panel section { padding: 14px 16px 4px; }
.panel h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.panel label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.panel input[type=text], .panel textarea, .panel select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  width: 100%;
}
.panel textarea { min-height: 80px; resize: vertical; }
.panel input.invalid { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; border-radius: 0; background: var(--surface-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  max-width: 100%;
}
.chip button { border: 0; background: transparent; border-radius: 0; padding: 4px 10px; overflow: hidden; text-overflow: ellipsis; }
.chip button.x { padding: 4px 9px 4px 4px; color: var(--muted); }
.chip button.x:hover { color: var(--danger); }
.chip.sex-M { border-color: color-mix(in srgb, var(--male) 40%, var(--border)); }
.chip.sex-F { border-color: color-mix(in srgb, var(--female) 40%, var(--border)); }
.chip small { color: var(--muted); padding-right: 8px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.btn-row button { font-size: 13px; padding: 6px 10px; }
.link-btn { border: 0; background: transparent; color: var(--danger); padding: 4px 0; font-size: 13px; }

.union-box { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--surface-2); }
.union-box .chips { margin-bottom: 6px; }
.union-box .row2 label { margin-bottom: 6px; }
.union-box .row2 select, .union-box .row2 input { background: var(--surface); }
.union-title { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.kids-label { font-size: 12px; color: var(--muted); margin: 4px 0 6px; }

.link-list { max-height: 170px; }
.danger-zone { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 14px; }
.danger-zone button { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Sélection multiple ---------- */
.card.multi { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.card.multi::after {
  content: "✓"; position: absolute; top: -9px; left: -9px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.viewport.sel-mode, .viewport.sel-mode .card { cursor: crosshair; }
.viewport.dragging { cursor: grabbing !important; }
@media (hover: none) { .legend-mouse { display: none; } }
#selMode.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.sel-rect {
  position: absolute; z-index: 6; pointer-events: none;
  border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 4px;
}
.sel-rect[hidden] { display: none; }
/* Barres en haut de l'arbre : sauvegarde, sélection, affichage */
.top-bars {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 8; display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100% - 24px);
}
.backup-bar, .view-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 8px 10px 8px 14px; font-size: 13.5px; max-width: 640px;
}
.backup-bar { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.backup-bar .bk-actions { display: flex; gap: 6px; margin-left: auto; }
/* Pastille « pas encore enregistré dans un fichier » */
#btnSave { position: relative; }
#btnSave.unsaved::after { content: ""; position: absolute; top: -4px; inset-inline-end: -4px; width: 11px; height: 11px; border-radius: 50%; background: #e5484d; border: 2px solid var(--bg, #fff); animation: unsavedPulse 2s ease-in-out 3; }
@keyframes unsavedPulse { 50% { transform: scale(1.35); } }
.menu-title.unsaved { color: #c4373c; font-weight: 600; }
.backup-bar button, .view-bar button { padding: 5px 10px; font-size: 13px; }
.backup-bar[hidden], .view-bar[hidden] { display: none; }
.view-bar { flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 8px 6px 12px; }
.vb-item { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.fam-legend {
  position: absolute; left: 14px; bottom: 56px; z-index: 3; pointer-events: none;
  display: flex; flex-wrap: wrap; gap: 6px 12px; max-width: min(520px, calc(100% - 100px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 12px;
}
.fam-legend[hidden] { display: none; }
.fam-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.auto-chip { font-size: 12.5px; padding: 5px 9px; border-radius: 999px; color: var(--brand); border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); }
.auto-chip.paused { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.auto-chip[hidden] { display: none; }
.menu .tree-new small { font-weight: 400; }
#colorMode.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Cartes : surnom, nom arabe, lien de parenté, branche repliée, couleurs par famille */
.ar-hint { font-weight: 400; color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.ar-hint .link-btn { font-size: 11.5px; padding: 0; color: inherit; text-decoration: underline; }
.arabic { font-size: 13px; font-weight: 600; text-align: right; line-height: 1.35; }
.kin-badge {
  position: absolute; top: -11px; right: 10px; z-index: 3; max-width: 180px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.card.rel-ref { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.fold {
  position: absolute; right: 8px; bottom: -11px; z-index: 2;
  min-width: 26px; height: 22px; padding: 0 7px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; line-height: 1;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .12s;
}
.card:hover .fold, .card.selected .fold, .fold.on { opacity: 1; }
.fold.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
@media (hover: none) { .fold { opacity: 1; } }
#cards.by-fam .card::before { background: var(--fam); width: 6px; }
#cards.by-fam .card { background: color-mix(in srgb, var(--fam) 9%, var(--surface)); }
#cards.by-fam .card .avatar { background: color-mix(in srgb, var(--fam) 18%, var(--surface)); color: var(--fam); }

/* Fiche : lien de parenté */
.kin-result { font-size: 14px; margin: 8px 0 0; line-height: 1.45; }
.kin-result:empty { display: none; }

/* Fusion */
.merge-dialog { width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.merge-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 50vh; overflow-y: auto; }
.merge-head { display: grid; grid-template-columns: 22px 1fr 24px 1fr; gap: 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 10px; }
.merge-dialog label.merge-row {
  display: grid; grid-template-columns: 22px 1fr 24px 1fr; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; margin: 0; cursor: pointer;
  color: var(--text); font-size: 14px;
}
.merge-dialog label.merge-row:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, transparent); }
.merge-row input { accent-color: var(--brand); width: 18px; height: 18px; }
.merge-row span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.merge-row small { color: var(--muted); font-size: 12px; }
.merge-arrow { text-align: center; color: var(--muted); }
@media (max-width: 560px) {
  .merge-head { display: none; }
  .merge-dialog label.merge-row { grid-template-columns: 22px 1fr; }
  .merge-row .merge-arrow { display: none; }
  .merge-row > span:last-child { grid-column: 2; border-top: 1px dashed var(--border); padding-top: 4px; }
}
.pick-list-sub button { flex-direction: column; align-items: flex-start; gap: 2px; }
.pick-list-sub small { white-space: normal; }

.multi-bar {
  z-index: 8; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 7px 8px 7px 14px; white-space: nowrap;
  max-width: calc(100% - 24px);
}
.multi-bar[hidden] { display: none; }
.multi-bar span { font-size: 14px; }
.multi-bar button { padding: 6px 10px; font-size: 13.5px; }
.multi-bar button.danger { color: #fff; background: var(--danger); border-color: var(--danger); font-weight: 600; }
.multi-bar #multiClear { border: 0; background: transparent; }
@media (max-width: 480px) { .multi-bar #multiAll { display: none; } }

/* ---------- Assistant ---------- */
.assist-fab {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 30; border-radius: 999px; padding: 10px 18px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.assist-fab[hidden] { display: none; }
@media (min-width: 721px) { .assist-fab { left: auto; right: 72px; transform: none; } }
.assist {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(580px, calc(100vw - 24px)); max-height: min(70vh, 560px);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  z-index: 40;
}
.assist[hidden] { display: none; }
.assist-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 8px 16px; }
.assist-head > div { flex: 1; display: flex; flex-direction: column; }
.assist-head small { color: var(--muted); font-size: 12px; }
.assist-head button { border: 0; background: transparent; }
.assist-head button.assist-undo { border: 1px solid var(--border); background: var(--surface-2); padding: 6px 10px; font-size: 13.5px; white-space: nowrap; }
.assist-head button.assist-undo:disabled { opacity: .4; cursor: default; }
.assist-out { overflow-y: auto; padding: 0 16px; font-size: 14px; }
.assist-out:empty { display: none; }
.assist-out .a-lines { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.assist-out .a-lines li { background: var(--surface-2); border-radius: 9px; padding: 8px 10px; }
.assist-out .a-q { font-weight: 600; margin: 4px 0 8px; }
.assist-out .a-info { margin: 4px 0 10px; line-height: 1.45; }
.assist-out .a-err { color: var(--danger); margin: 4px 0 8px; }
.assist-out .a-ok { color: var(--brand); font-weight: 600; margin: 4px 0 10px; }
.assist-out .a-opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.assist-out button { white-space: normal; overflow-wrap: anywhere; }
.assist-out .a-opts button { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 9px 11px; }
.assist-out .a-opts small { color: var(--muted); font-size: 12px; }
.assist-out .a-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }
.assist-out .a-ex { margin: 4px 0 10px; display: flex; flex-direction: column; gap: 4px; }
.assist-out .a-ex button { text-align: left; border: 0; background: transparent; padding: 5px 0; display: flex; flex-direction: column; border-radius: 0; border-bottom: 1px solid var(--border); }
.assist-out .a-ex button:last-child { border-bottom: 0; }
.assist-out .a-ex small { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.assist-out .a-ex span { color: var(--brand); }
.assist-out .muted { color: var(--muted); }
.assist-form { display: flex; gap: 6px; padding: 8px 12px 12px; border-top: 1px solid var(--border); }
.assist-form input {
  flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 10px; padding: 10px 12px; font-size: 16px; color: var(--text);
}
.assist-form button.icon { width: 44px; font-size: 18px; }
#assistMic.on { background: var(--danger); color: #fff; border-color: var(--danger); animation: micPulse 1.2s infinite; }
@keyframes micPulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .search input { width: 160px; }
  .tree-name { width: 150px; }
  .count { display: none; }
}
@media (max-width: 720px) {
  .toolbar { padding: 8px 12px; gap: 6px; }
  .brand span { display: none; }
  .tree-name { flex: 1; width: auto; }
  .search { order: 10; flex: 1 1 100%; }
  .search input { width: 100%; }
  .tb-group.right { margin-left: 0; flex-wrap: wrap; max-width: 100%; }
  .tb-group.right > button, .tb-group.right .menu-wrap > button { padding-inline: 9px; }
  .legend { display: none; }
  body.panel-open .assist-fab { display: none; }
  .assist-fab { bottom: 14px; }
  .assist { left: 0; right: 0; bottom: 0; transform: none; width: auto; border-radius: 18px 18px 0 0; max-height: 75vh; }
  .panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 70%;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .2);
    z-index: 15;
  }
}

/* Combiner un fichier : choix à l'ouverture et résumé */
.oc-choices { display: grid; gap: 8px; margin: 12px 0 4px; }
.oc-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 12px 14px; white-space: normal; }
.oc-btn small { font-weight: 400; font-size: 12.5px; opacity: .85; }
.merge-summary { margin: 10px 0 6px; display: grid; gap: 6px; }
.merge-summary .ms-line { font-size: 15px; }
.merge-summary .ms-line b { display: inline-block; min-width: 2ch; font-size: 18px; }
.merge-summary .ms-doubt { font-size: 13px; color: var(--muted); }
.merge-detail-btn { margin: 4px 0 8px; }
.merge-list[hidden], .merge-summary[hidden], .merge-detail-btn[hidden] { display: none; }

/* Vérifier l'arbre */
.check-list { max-height: min(60vh, 520px); overflow: auto; display: grid; gap: 4px; margin: 8px 0; }
.check-row { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: start; padding: 8px 10px; white-space: normal; border-inline-start: 4px solid #d9a441; }
.check-row.err { border-inline-start-color: #c0392b; }
.check-row span { font-size: 13px; color: var(--muted); }
.check-ok { display: grid; gap: 4px; padding: 16px 4px; font-size: 15px; }

/* Langue : bouton FR / عربي, et mise en page de droite à gauche */
.lang-btn { font-weight: 600; }
/* Lignée Pro */
.pro-btn { font-weight: 600; color: #8a6400; border-color: #e3c56a; background: #fff8e1; }
.is-pro .pro-btn { color: var(--muted); background: var(--surface); border-color: var(--border); font-weight: 500; }
.pro-tag { display: inline-block; font-size: 10.5px; font-weight: 700; line-height: 1; padding: 3px 6px 2px; border-radius: 999px; background: #f5d77a; color: #5b4300; vertical-align: 2px; margin-inline-start: 4px; letter-spacing: .02em; }
.is-pro .pro-tag, .is-pro .free-note { display: none; }
.menu small.free-note { color: #8a6400; }
.pro-dialog { width: min(470px, calc(100vw - 32px)); }
.pro-reason { background: #fff8e1; border: 1px solid #f0d98c; color: #5b4300; border-radius: 9px; padding: 9px 11px; font-size: 14px; margin: 0 0 12px; }
.pro-list { margin: 0 0 12px; padding-inline-start: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.pro-list li { position: relative; padding-inline-start: 24px; }
.pro-list li::before { content: "✓"; position: absolute; inset-inline-start: 2px; top: 0; color: var(--brand); font-weight: 700; }
.pro-price { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.pro-price b { font-size: 22px; color: var(--text); margin-inline-end: 6px; }
.pro-privacy { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }
.pro-buy { width: 100%; padding: 11px; font-size: 15px; margin-bottom: 14px; }
.pro-key { display: flex; gap: 8px; align-items: flex-end; }
.pro-key label { flex: 1; margin: 0; }
.pro-key input { font-family: ui-monospace, Consolas, monospace; letter-spacing: .04em; }
.pro-ok { font-size: 15px; margin: 0 0 8px; }
@media (prefers-color-scheme: dark) {
  .pro-btn { color: #f5d77a; background: color-mix(in srgb, #f5d77a 12%, transparent); border-color: #7a6320; }
  .pro-reason { background: color-mix(in srgb, #f5d77a 12%, transparent); color: #f5d77a; border-color: #7a6320; }
  .menu small.free-note { color: #e3c56a; }
}
[dir="rtl"] .stage { direction: ltr; }
[dir="rtl"] .card .kin-badge { direction: rtl; }
[dir="rtl"] body { font-family: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
[dir="rtl"] .menu { right: auto; left: 0; }
[dir="rtl"] .menu.menu-left { left: auto; right: 0; }
[dir="rtl"] .menu button { text-align: right; }
