:root {
  --background: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f5;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #dfe3e8;
  --border-strong: #c7cdd4;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #b42318;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--background); }
body { margin: 0; color: var(--text); background: var(--background); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { overflow-wrap: anywhere; }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; transform: translateY(-160%); padding: 9px 12px; color: white; background: var(--text); border-radius: 6px; }
.skip-link:focus { transform: translateY(0); }

.app-header { height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.app-title { color: var(--text); font-size: 17px; font-weight: 650; text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; }
.button:hover { background: var(--surface-muted); }
.button:focus-visible, .icon-button:focus-visible, .view-button:focus-visible, .person-button:focus-visible, .tree-person:focus-visible { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { color: white; background: var(--accent); border-color: var(--accent); }
.button-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-secondary, .button-ghost { color: var(--text); background: var(--surface); }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; cursor: pointer; }
.icon-button:hover { color: var(--text); background: var(--surface-muted); }
.icon-button svg { width: 18px; height: 18px; }

.app-layout { height: calc(100vh - 64px); display: grid; grid-template-columns: 250px minmax(500px, 1fr) 280px; overflow: hidden; }
.directory-panel, .profile-panel { min-width: 0; padding: 20px; background: var(--surface); overflow: auto; }
.directory-panel { border-right: 1px solid var(--border); }
.profile-panel { border-left: 1px solid var(--border); }
.tree-workspace { min-width: 0; display: flex; flex-direction: column; padding: 22px; overflow: auto; background: var(--background); }
.panel-heading, .workspace-heading, .profile-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-heading h1, .workspace-heading h2, .profile-panel h2 { margin: 0; color: var(--text); font-size: 18px; font-weight: 650; }
.workspace-heading h2 { font-size: 21px; }
.workspace-heading > div > p { margin: 5px 0 0; color: var(--text-muted); font-size: 13px; }
.count-badge { min-width: 27px; height: 27px; display: grid; place-items: center; padding: 0 8px; color: var(--text-muted); background: var(--surface-muted); border-radius: 14px; font-size: 12px; font-weight: 600; }

.search-field { position: relative; margin: 18px 0 14px; }
.search-field svg { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; color: var(--text-muted); transform: translateY(-50%); pointer-events: none; }
.search-field input { width: 100%; height: 40px; padding: 0 10px 0 36px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; outline: none; }
.search-field input:focus, .field input:not([type="checkbox"]):focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.person-list { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }
.person-button { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 9px; padding: 8px; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 7px; cursor: pointer; }
.person-button:hover { background: var(--surface-muted); }
.person-button.is-active { background: var(--accent-soft); border-color: #bfdbfe; }
.mini-avatar, .tree-avatar { display: grid; place-items: center; color: #4b5563; background: #e5e7eb; border-radius: 50%; font-weight: 650; }
.mini-avatar { width: 34px; height: 34px; font-size: 11px; }
.person-button.is-active .mini-avatar, .tree-person.is-center .tree-avatar { color: white; background: var(--accent); }
.person-summary { min-width: 0; }
.person-summary strong, .person-summary small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-summary strong { color: var(--text); font-size: 13px; font-weight: 600; }
.person-summary small { margin-top: 2px; color: var(--text-muted); font-size: 11px; }
.person-arrow { color: #9ca3af; }
.empty-message { color: var(--text-muted); font-size: 13px; text-align: center; }

.view-switcher { display: flex; padding: 3px; background: #e7eaee; border-radius: 7px; }
.view-button { min-height: 30px; padding: 0 11px; color: var(--text-muted); background: transparent; border: 0; border-radius: 5px; font-size: 11px; font-weight: 600; cursor: pointer; }
.view-button.is-active { color: var(--text); background: var(--surface); }
.tree-card { flex: 1; min-height: 520px; margin-top: 18px; padding: 0 16px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.tree-legend { height: 44px; display: flex; align-items: center; justify-content: flex-end; gap: 16px; color: var(--text-muted); font-size: 10px; }
.tree-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { width: 18px; height: 0; display: inline-block; border-top: 2px solid #9ca3af; }
.partner-line { border-top-style: dashed; border-color: #6b7280; }
.tree-stage { position: relative; height: calc(100% - 44px); min-width: 900px; min-height: 460px; overflow: visible; }
#tree-svg, .tree-nodes { position: absolute; inset: 0; width: 100%; height: 100%; }
#tree-svg { overflow: visible; pointer-events: none; }
.connector { fill: none; stroke: #b8c0c8; stroke-width: 2; }
.connector.partner { stroke: #8b949e; stroke-dasharray: 7 6; }
.tree-person { position: absolute; width: 142px; min-height: 96px; padding: 12px 10px 10px; transform: translate(-50%, -50%); text-align: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; }
.tree-person:hover { border-color: #9ca3af; background: #fafafa; }
.tree-person.is-center { width: 154px; min-height: 106px; border: 2px solid var(--accent); }
.tree-person.is-center::after { content: "Sélection"; position: absolute; top: -10px; left: 50%; padding: 2px 7px; color: white; background: var(--accent); border-radius: 8px; transform: translateX(-50%); font-size: 8px; font-weight: 700; text-transform: uppercase; }
.tree-avatar { width: 38px; height: 38px; margin: 0 auto 7px; font-size: 12px; }
.tree-person strong, .tree-person small { display: block; }
.tree-person strong { font-size: 13px; font-weight: 650; }
.tree-person small { margin-top: 3px; color: var(--text-muted); font-size: 10px; }
.relation-tag { position: absolute; top: -19px; left: 50%; color: var(--text-muted); transform: translateX(-50%); font-size: 9px; font-weight: 650; text-transform: uppercase; white-space: nowrap; }
.tree-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; }
.tree-empty h3 { margin: 0 0 6px; font-size: 18px; }
.tree-empty p { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.accessible-tree { flex: 1; margin-top: 18px; padding: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.accessible-tree h3 { margin-top: 0; font-size: 17px; }
.accessible-group { padding: 14px 0; border-top: 1px solid var(--border); }
.accessible-group h4 { margin: 0 0 7px; color: var(--text-muted); font-size: 11px; text-transform: uppercase; }
.accessible-group ul { margin: 0; padding-left: 20px; }
.accessible-group button { padding: 3px; color: var(--accent); background: none; border: 0; text-decoration: underline; cursor: pointer; }

.profile-placeholder { min-height: 65vh; display: grid; place-content: center; justify-items: center; text-align: center; }
.placeholder-mark { color: #9ca3af; font-size: 25px; }
.profile-placeholder h2 { margin-top: 14px; font-size: 17px; }
.profile-placeholder p { max-width: 180px; margin: 6px 0; color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.profile-topline { justify-content: flex-end; }
.profile-actions { display: flex; gap: 6px; }
.profile-close-button { display: none; font-size: 20px; }
.profile-avatar { width: 68px; height: 68px; display: grid; place-items: center; margin: 18px auto 12px; color: white; background: #4b5563; border-radius: 50%; font-size: 20px; font-weight: 650; }
.profile-panel h2 { text-align: center; font-size: 20px; }
.profile-lifespan { margin: 4px 0 20px; color: var(--text-muted); font-size: 12px; text-align: center; }
.facts { margin: 0; }
.fact { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 11px 0; border-top: 1px solid var(--border); }
.fact-icon { color: var(--text-muted); font-size: 13px; }
.fact dt { color: var(--text-muted); font-size: 10px; font-weight: 650; text-transform: uppercase; }
.fact dd { margin: 3px 0 0; font-size: 12px; line-height: 1.45; }
.bio-block, .profile-relations { padding-top: 16px; border-top: 1px solid var(--border); }
.bio-block h3, .profile-relations h3 { margin: 0 0 8px; color: var(--text-muted); font-size: 11px; text-transform: uppercase; }
.bio-block p { margin: 0 0 16px; font-size: 13px; line-height: 1.5; }
.relation-pill { display: inline-flex; margin: 0 4px 5px 0; padding: 5px 8px; color: var(--text); background: var(--surface-muted); border: 1px solid var(--border); border-radius: 14px; font-size: 10px; cursor: pointer; }

.modal { width: min(680px, calc(100vw - 28px)); max-height: min(88vh, 760px); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 20px 60px rgba(17, 24, 39, .18); }
.modal::backdrop { background: rgba(17, 24, 39, .42); }
.modal-small { width: min(460px, calc(100vw - 28px)); }
.modal form { display: flex; flex-direction: column; max-height: inherit; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 22px 24px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; background: #fafafa; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label:not(.check-label) { display: block; margin-bottom: 6px; color: var(--text); font-size: 12px; font-weight: 600; }
.field label span { color: var(--text-muted); font-size: 10px; font-weight: 400; }
.field input:not([type="checkbox"]), .field textarea, .field select { width: 100%; padding: 9px 10px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; outline: none; }
.field textarea { resize: vertical; }
.check-label { display: flex; align-items: flex-start; gap: 7px; margin-top: 7px; color: var(--text-muted); font-size: 11px; line-height: 1.45; }
.check-label input { margin-top: 2px; accent-color: var(--accent); }
.form-error { padding: 10px 11px; color: var(--danger); background: #fef3f2; border: 1px solid #fecdca; border-radius: 7px; font-size: 12px; }
.relationship-context { margin-top: 0; color: var(--text-muted); font-size: 13px; }
.modal-small .field + .field { margin-top: 17px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 200; max-width: 340px; padding: 12px 15px; color: white; background: #1f2937; border-radius: 7px; font-size: 12px; }

.login-page { min-height: 100vh; background: var(--background); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.login-heading h1 { margin: 0; font-size: 22px; font-weight: 650; }
.login-heading p { margin: 8px 0 24px; color: var(--text-muted); font-size: 13px; }
.password-field { position: relative; }
.password-field input { padding-right: 60px !important; }
.password-toggle { position: absolute; right: 6px; top: 50%; padding: 5px 7px; color: var(--accent); background: transparent; border: 0; transform: translateY(-50%); font-size: 11px; font-weight: 600; cursor: pointer; }
.login-button { width: 100%; min-height: 42px; margin-top: 14px; }
.privacy-note { margin: 20px 0 0; color: var(--text-muted); font-size: 11px; text-align: center; }

@media (max-width: 1080px) {
  .app-layout { grid-template-columns: 240px minmax(480px, 1fr); }
  .profile-panel { position: fixed; top: 64px; right: 0; bottom: 0; z-index: 20; width: 300px; box-shadow: -8px 0 24px rgba(17, 24, 39, .12); transform: translateX(100%); transition: transform .18s; }
  .profile-panel.has-selection { transform: translateX(0); }
  .profile-close-button { display: grid; }
}

@media (max-width: 760px) {
  .app-header { height: 58px; padding: 0 12px; }
  .app-title { font-size: 15px; }
  .header-actions .button { width: 38px; padding: 0; font-size: 0; }
  .header-actions .button span { font-size: 18px; }
  .app-layout { height: auto; min-height: calc(100vh - 58px); display: block; }
  .directory-panel { padding: 16px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .directory-panel nav { max-height: 180px; overflow: auto; }
  .search-field { margin: 13px 0 9px; }
  .tree-workspace { min-height: 620px; padding: 18px 10px; }
  .workspace-heading { align-items: flex-end; }
  .workspace-heading h2 { font-size: 19px; }
  .workspace-heading > div > p { display: none; }
  .tree-card { min-height: 470px; margin-top: 14px; padding: 0 5px 8px; }
  .tree-legend { justify-content: center; }
  .tree-person { width: 112px; min-height: 90px; padding: 10px 6px 8px; }
  .tree-person.is-center { width: 124px; min-height: 100px; }
  .tree-person strong { font-size: 12px; }
  .profile-panel { top: 58px; width: min(320px, 92vw); }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .modal-header, .modal-body, .modal-actions { padding-left: 18px; padding-right: 18px; }
  .login-shell { padding: 16px; }
  .login-card { padding: 24px; }
}
