/* styles.css — Arbre généalogique Toffolet
   Design responsive (mobile / tablette / PC), thème clair & sombre. */

:root {
  --green: #2f6d4f;
  --green-600: #285f45;
  --green-050: #e8f2ec;
  --male: #3d7ea6;
  --male-050: #e7f0f6;
  --female: #b0567e;
  --female-050: #f8eaf1;
  --neutral: #7a8a99;

  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --line: #e2e7e3;
  --text: #1d2622;
  --text-2: #5d6b64;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 8px 24px rgba(20, 40, 30, .08);
  --shadow-lg: 0 12px 40px rgba(20, 40, 30, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"], .dark-auto {
  --bg: #10161a;
  --surface: #182127;
  --surface-2: #131b20;
  --line: #273239;
  --text: #e7ede9;
  --text-2: #9db0a7;
  --green: #4f9e75;
  --green-050: #1c2b23;
  --male-050: #17262f;
  --female-050: #2a1a22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 44px rgba(0,0,0,.55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161a;
    --surface: #182127;
    --surface-2: #131b20;
    --line: #273239;
    --text: #e7ede9;
    --text-2: #9db0a7;
    --green: #4f9e75;
    --green-050: #1c2b23;
    --male-050: #17262f;
    --female-050: #2a1a22;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 16px 44px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body.locked { overflow: hidden; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
.muted { color: var(--text-2); }
.muted.pad { padding: 14px; }

/* ------------------- Barre supérieure ------------------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px; padding-top: env(safe-area-inset-top, 0);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { font-size: 26px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.2px; white-space: nowrap; }
.brand-sub {
  font-size: 11px; color: var(--green); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px;
}
.toolbar { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.tool {
  width: 40px; height: 40px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 11px; font-size: 17px; color: var(--text);
  display: grid; place-items: center; transition: .15s;
}
.tool:hover { background: var(--surface-2); border-color: var(--green); }
.tool:active { transform: scale(.94); }
.tool-accent { background: var(--green); border-color: var(--green); color: #fff; font-size: 22px; font-weight: 300; }
.tool-accent:hover { background: var(--green-600); }

.menu-wrap { position: relative; }
.drop-menu {
  position: absolute; right: 0; top: 46px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  min-width: 190px; padding: 6px; display: none; flex-direction: column; z-index: 60;
}
.drop-menu.open { display: flex; }
.drop-item {
  text-align: left; background: none; border: 0; color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; text-decoration: none; display: block;
}
.drop-item:hover { background: var(--surface-2); }
.drop-danger { color: #c0392b; }

.auth-box { display: flex; align-items: center; }
.auth-user { display: flex; align-items: center; gap: 8px; }
.link { background: none; border: 0; color: var(--green); font-weight: 600; font-size: 13px; }

/* ------------------- Recherche ------------------- */
.search-wrap {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 45;
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 10px 14px;
  transform: translateY(-120%); transition: transform .22s ease, visibility .22s; max-height: 70vh; overflow: auto;
  visibility: hidden;
}
.search-wrap.open { transform: translateY(0); visibility: visible; }
#search-input {
  width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line);
  border-radius: 11px; background: var(--surface-2); color: var(--text);
}
#search-input:focus { outline: 2px solid var(--green); border-color: var(--green); }
.search-results { margin-top: 8px; display: flex; flex-direction: column; }
.search-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px; background: none;
  border: 0; border-radius: 9px; text-align: left; color: var(--text); width: 100%;
}
.search-item:hover { background: var(--surface-2); }
.si-name { display: block; font-weight: 600; font-size: 14px; }
.si-sub { display: block; font-size: 12px; color: var(--text-2); }

/* ------------------- Disposition ------------------- */
.layout { display: flex; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.canvas { position: relative; flex: 1; overflow: hidden; }

/* ------------------- Arbre ------------------- */
.tree { position: absolute; inset: 0; }
.tree-viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; background:
  radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0) 0 0 / 26px 26px; }
.tree-viewport:active { cursor: grabbing; }
.tree-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.tree-edges { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.edge { fill: none; stroke: var(--neutral); stroke-width: 1.6; opacity: .55; }
.edge-couple { stroke: var(--green); stroke-width: 3.4; opacity: 1; }
.union-badge { fill: var(--surface); stroke: var(--green); stroke-width: 2.5; }
.union-heart { fill: var(--green); font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.tree-nodes { position: absolute; top: 0; left: 0; }

.person-card {
  position: absolute; background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 13px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
  padding: 0 12px; text-align: left; color: var(--text); overflow: hidden; transition: transform .12s, box-shadow .15s, border-color .15s;
  border-left-width: 5px;
}
.person-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.person-card.sex-m { border-left-color: var(--male); }
.person-card.sex-f { border-left-color: var(--female); }
.person-card.sex-u { border-left-color: var(--neutral); }
.person-card.kind-focus, .person-card.selected { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-050), var(--shadow-lg); }
.person-card.deceased { opacity: .96; }
.person-card.deceased .pc-name::after { content: " †"; color: var(--text-2); font-weight: 400; }

.pc-avatar, .mini-avatar, .big-avatar {
  display: grid; place-items: center; border-radius: 50%; font-weight: 700; color: #fff;
  background: var(--neutral); flex-shrink: 0;
}
.has-photo { background-size: cover !important; background-position: center; color: transparent; text-indent: -9999px; }
.pc-avatar { width: 40px; height: 40px; font-size: 15px; }
.sex-m .pc-avatar, .mini-avatar.sex-m, .big-avatar.sex-m { background: var(--male); }
.sex-f .pc-avatar, .mini-avatar.sex-f, .big-avatar.sex-f { background: var(--female); }
.pc-body { display: flex; flex-direction: column; min-width: 0; }
.pc-name { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-dates { font-size: 11.5px; color: var(--text-2); white-space: nowrap; }

.tree-toggle {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--green); background: var(--surface); color: var(--green);
  font-size: 15px; font-weight: 700; line-height: 1; padding: 0;
  display: grid; place-items: center; z-index: 6; box-shadow: var(--shadow);
}
.tree-toggle:hover { background: var(--green); color: #fff; }
.tree-toggle.collapsed { background: var(--green); color: #fff; }
.tree-toggle.collapsed:hover { background: var(--green-600); }

.tree-controls {
  position: absolute; right: 14px; bottom: 78px; display: flex; flex-direction: column; gap: 6px; z-index: 10;
}
.tctl {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 20px; box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.tctl:hover { border-color: var(--green); }
.tctl.active { background: var(--green); color: #fff; border-color: var(--green); }

.stats-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px;
  display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 6px; box-shadow: var(--shadow); z-index: 10;
}
.stat { display: flex; flex-direction: column; align-items: center; padding: 2px 14px; line-height: 1.15; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat strong { font-size: 15px; color: var(--green); }
.stat span { font-size: 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .3px; }

/* ------------------- État vide ------------------- */
.empty-state, .login-gate { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; z-index: 20; }
.login-gate { position: fixed; background: var(--bg); z-index: 80; }
.empty-card, .login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow); padding: 34px 30px; max-width: 420px; text-align: center;
}
.empty-emoji { font-size: 52px; display: block; margin-bottom: 10px; }
.empty-card h1, .login-card h1 { font-size: 22px; margin-bottom: 10px; letter-spacing: -.3px; }
.empty-card p, .login-card p { color: var(--text-2); font-size: 14.5px; line-height: 1.5; margin: 0 0 22px; }
.login-card .field { text-align: left; margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; margin-top: 4px; }
.login-error { color: #c0392b; font-size: 13px; min-height: 18px; margin: 0 0 8px; }

/* ------------------- Panneau détails ------------------- */
.panel {
  width: 360px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--line);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.panel-inner { padding: 20px 20px 60px; position: relative; }
.panel-close { display: none; }

.person-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.big-avatar { width: 62px; height: 62px; font-size: 24px; }
.big-avatar.deceased { filter: grayscale(.3); }
.person-headmeta h2 { font-size: 20px; letter-spacing: -.3px; line-height: 1.2; }
.person-headmeta .lifespan { font-size: 13px; color: var(--text-2); margin: 3px 0 0; }
.person-headmeta p { margin: 2px 0 0; font-size: 13px; }

.fact-grid { display: flex; flex-direction: column; gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 16px; }
.fact { background: var(--surface-2); padding: 11px 14px; display: flex; flex-direction: column; gap: 2px; }
.fact-label { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }
.fact-value { font-size: 14px; }

.panel-actions { display: flex; gap: 8px; margin-bottom: 6px; }
.panel-actions .btn { flex: 1; }

.panel-sec { border-top: 1px solid var(--line); padding: 16px 0 4px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sec-head h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-2); }
.chips { display: flex; flex-direction: column; gap: 8px; }
.relchip { display: flex; align-items: stretch; gap: 6px; width: 100%; }
.relchip-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; color: var(--text); text-align: left;
}
.relchip-main:hover { border-color: var(--green); background: var(--green-050); }
.relchip-menu {
  flex-shrink: 0; width: 42px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 11px; color: var(--text-2); font-size: 18px; line-height: 1;
}
.relchip-menu:hover { border-color: var(--green); color: var(--green); background: var(--green-050); }

.rel-actions { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.rel-actions h2 { font-size: 18px; }
.rel-actions-sub { margin: -14px 0 6px; font-size: 14px; }
.rel-actions .btn { width: 100%; text-align: center; }
.mini-avatar { width: 32px; height: 32px; font-size: 12px; }
.relchip-text { display: flex; flex-direction: column; min-width: 0; }
.relchip-name { font-weight: 600; font-size: 14px; }
.relchip-sub { font-size: 12px; color: var(--text-2); }
.add-rel {
  align-self: flex-start; background: none; border: 1.5px dashed var(--line); color: var(--green);
  padding: 8px 14px; border-radius: 11px; font-weight: 600; font-size: 13px;
}
.add-rel:hover { border-color: var(--green); background: var(--green-050); }
.add-mini { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--green); font-size: 16px; }

.claim-banner {
  margin: 0 0 16px; padding: 12px 14px; background: var(--green-050); border: 1px solid var(--green);
  border-radius: 12px; font-size: 13.5px; display: flex; flex-direction: column; gap: 8px;
}
.claim-banner strong { color: var(--green); }

/* ------------------- Boutons ------------------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 11px; font-size: 14px; font-weight: 600; transition: .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-600); }
.btn-ghost { background: none; }
.btn-danger { background: #c0392b; border-color: #c0392b; color: #fff; }

/* ------------------- Dialogue / formulaire ------------------- */
.dialog {
  border: 0; border-radius: 18px; padding: 0; max-width: 520px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(10, 20, 15, .5); backdrop-filter: blur(3px); }
.person-form, .confirm { padding: 24px; }
.person-form h2, .confirm h2 { font-size: 19px; margin-bottom: 18px; }
.photo-field { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.photo-preview {
  width: 76px; height: 76px; border-radius: 50%; flex-shrink: 0; background: var(--surface-2);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 30px;
  background-size: cover; background-position: center; color: var(--text-2);
}
.photo-preview.has { border-color: var(--green); }
.photo-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14.5px;
  background: var(--surface-2); color: var(--text); font-family: inherit; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--green); border-color: var(--green); }
.form-group { border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px 0; margin-bottom: 14px; }
.form-group legend { font-size: 12px; font-weight: 700; color: var(--green); padding: 0 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.confirm p { margin: 0 0 20px; line-height: 1.5; }

/* ------------------- Toast ------------------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  background: #1d2622; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .25s; z-index: 90;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------- Responsive ------------------- */
@media (max-width: 860px) {
  .panel {
    position: fixed; inset: auto 0 0 0; width: 100%; max-height: 82vh; height: auto;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow-lg); transform: translateY(100%); transition: transform .28s ease; z-index: 70;
  }
  .panel.open { transform: translateY(0); }
  .panel-close {
    display: grid; place-items: center; position: absolute; top: 12px; right: 14px;
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
    background: var(--surface-2); font-size: 22px; color: var(--text-2); z-index: 2;
  }
  .panel-inner::before {
    content: ""; display: block; width: 42px; height: 5px; border-radius: 3px;
    background: var(--line); margin: -6px auto 14px;
  }
  .stats-bar { bottom: 12px; }
  .tree-controls { bottom: 70px; }
}

@media (max-width: 520px) {
  .brand-sub { display: none; }
  .toolbar { gap: 3px; }
  .tool { width: 38px; height: 38px; }
  .stat { padding: 2px 11px; }
}
