:root {
  --bg: #F6F6F3;
  --surface: #FFFFFF;
  --surface-2: #FBFBF9;
  --ink: #1B1D1C;
  --ink-2: #474B49;
  --muted: #5E6361;
  --line: #DCDCD6;
  --line-2: #EBEBE6;
  --field: #C9C9C2;
  --accent: #1D5361;
  --accent-ink: #123A45;
  --accent-soft: #E4EEF0;
  --accent-soft-2: #F2F7F8;
  --warm: #8C4F0E;
  --warm-soft: #F6EBDD;
  --plum: #6A3D66;
  --plum-soft: #F1E7F0;
  --danger: #8A2A1E;
  --private: #EFEFEA;
  --radius: 12px;
  --font: 'IBM Plex Sans Arabic', Tahoma, 'Segoe UI', system-ui, sans-serif;
  --display: 'Noto Naskh Arabic', 'Traditional Arabic', serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.7; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.45; margin: 0; }
h1 { font-size: clamp(28px, 4vw, 40px); }
h2 { font-size: 26px; }
h3 { font-size: 21px; }
p { margin: 0; }
:focus-visible { outline: 3px solid #E0A458; outline-offset: 2px; }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 50; }
.skip:focus { top: 12px; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 28px; }
.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.spread { display: flex; flex-wrap: wrap; gap: 12px; align-items: baseline; justify-content: space-between; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.page { padding: 32px 0 64px; display: flex; flex-direction: column; gap: 24px; }
.section-title { border-top: 1px solid var(--ink); padding-top: 18px; }

/* ── الرأس ───────────────────────────────────── */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.site-header .wrap { min-height: 70px; display: flex; align-items: center; gap: 28px; flex-wrap: wrap; padding-block: 6px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand .icon { color: var(--accent); }
.brand b { font-family: var(--display); font-size: 27px; font-weight: 700; }
.nav { display: flex; gap: 22px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--ink-2); text-decoration: none; font-weight: 500; padding: 6px 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.account-menu { display: flex; align-items: center; gap: 6px; }
.account-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 4px 8px; border-radius: 10px; }
.account-link:hover { background: var(--surface-2); color: var(--ink); }
.account-link .role-line { display: block; font-size: 12px; color: var(--muted); line-height: 1.3; }
.account-link b { display: block; font-size: 14px; line-height: 1.3; }
.auth-card { max-width: 480px; margin: 48px auto; }
.pw-meter { height: 6px; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.pw-meter span { display: block; height: 100%; width: 0; background: var(--warm); transition: width .2s; }
.pw-meter span.good { background: var(--accent); }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: start; padding: 10px; border-top: 1px solid var(--line-2); vertical-align: middle; }
.users-table thead th { border-top: 0; font-size: 14px; color: var(--muted); }

/* ── عناصر عامة ──────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--field); background: var(--surface); color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); color: #fff; }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 0 10px; border-radius: 999px; background: var(--private); color: var(--ink-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.warm { background: var(--warm-soft); color: var(--warm); }
.badge.plum { background: var(--plum-soft); color: var(--plum); }
.badge.warn { background: var(--warm-soft); color: var(--warm); }
.badge.info { background: var(--accent-soft-2); color: var(--accent); border: 1px dashed #A9C3CA; }
.badge.muted { background: var(--private); color: var(--muted); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: #F6E3E0; color: var(--danger); }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: #E2E2DC; overflow: hidden; flex: none; color: var(--ink-2); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .silhouette { fill: #9C9D96; }
.avatar.is-private { background: var(--private); }
.avatar.slot { background: transparent; border: 2px dashed var(--field); color: var(--muted); font-weight: 700; }
.slot-row .who > span:last-child > span:first-child { color: var(--muted); font-weight: 600; }
.node.slot { border-style: dashed; background: transparent; color: var(--muted); box-shadow: none; }
.family-block { border-inline-start: 4px solid var(--line); padding-inline-start: 18px; }
.kid-row { display: grid; grid-template-columns: minmax(160px, 2fr) 120px 150px minmax(120px, 1fr) auto; gap: 8px; align-items: end; }
@media (max-width: 720px) { .kid-row { grid-template-columns: 1fr 1fr; } }
.private-name { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .label { font-size: 14px; font-weight: 600; }
.field input, .field select, .field textarea, .input { padding: 9px 12px; border: 1px solid var(--field); border-radius: 8px; background: var(--surface); font-size: 16px; }
.field textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 13px; color: var(--muted); }
.error-box { background: #F6E3E0; color: var(--danger); border-radius: 8px; padding: 10px 14px; }
.ok-box { background: var(--accent-soft); color: var(--accent-ink); border-radius: 8px; padding: 10px 14px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.loading { padding: 48px; text-align: center; color: var(--muted); }
.segmented { display: inline-flex; background: var(--private); border-radius: 10px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.segmented a, .segmented button { min-height: 40px; display: inline-flex; align-items: center; padding: 0 14px; border-radius: 7px; border: 0; background: transparent; color: var(--ink-2); text-decoration: none; font-weight: 500; cursor: pointer; }
.segmented [aria-current="true"], .segmented [aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
bdi { unicode-bidi: isolate; }

/* ── الرئيسية ────────────────────────────────── */
.hero { padding: 72px 0 40px; display: flex; flex-direction: column; gap: 18px; }
.hero h1 { font-size: clamp(36px, 6vw, 60px); max-width: 900px; text-wrap: balance; }
.hero p.lead { font-size: 19px; color: var(--ink-2); max-width: 680px; }
.searchbar { margin-top: 18px; background: var(--surface); border: 1px solid var(--field); border-radius: 14px; padding: 10px; display: flex; flex-wrap: wrap; gap: 10px; box-shadow: 0 12px 32px rgba(27,29,28,.06); }
.searchbar .q { flex: 999 1 380px; display: flex; flex-direction: column; padding: 6px 14px; }
.searchbar .q input { border: 0; outline: none; font-size: 20px; padding: 2px 0; background: transparent; }
.searchbar .c { flex: 1 1 200px; display: flex; flex-direction: column; padding: 6px 14px; border-inline-start: 1px solid var(--line-2); }
.searchbar .c select { border: 0; font-size: 18px; background: transparent; }
.searchbar label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.searchbar .btn { min-height: 60px; padding: 0 30px; font-size: 18px; }
.place-card, .family-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: var(--ink); }
.place-card:hover, .family-card:hover { border-color: var(--accent); color: var(--ink); }
.big-name { font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.35; }

/* ── البحث والملف ────────────────────────────── */
.result { display: flex; gap: 14px; align-items: flex-start; text-decoration: none; color: var(--ink); padding: 16px 18px; }
.result:hover { border-color: var(--accent); color: var(--ink); }
.result .name { font-size: 18px; font-weight: 600; }
.result .sub { font-size: 15px; color: var(--ink-2); }
.profile-head { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.photo-slot { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.photo-frame { width: 150px; height: 180px; border-radius: 12px; border: 1px solid var(--line); background: var(--private); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; overflow: hidden; }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; }
.photo-frame .silhouette { fill: #B9BAB3; }
.rel-group { display: flex; flex-direction: column; gap: 2px; }
.rel-group .label { color: var(--muted); font-size: 14px; }
.rel-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.rel-row .who { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.facts { display: grid; grid-template-columns: 110px 1fr; gap: 10px 20px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 24px; background: var(--surface-2); border-block: 1px solid var(--line-2); margin-inline: -24px; }

/* ── الشجرة ──────────────────────────────────── */
.tree-shell { display: flex; flex-direction: column; flex: 1; min-height: 0; }
body.tree-mode { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.tree-mode main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.tree-mode .tree-root { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tree-toolbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; }
.tree-toolbar .title { flex: 1 1 260px; }
.tree-toolbar h1 { font-size: 26px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: center; font-size: 14px; color: var(--ink-2); padding: 6px 24px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.viewport { position: relative; flex: 1; overflow: hidden; background-color: var(--surface-2); background-image: radial-gradient(#DCDCD6 1px, transparent 1px); background-size: 24px 24px; cursor: grab; touch-action: none; }
.viewport.dragging { cursor: grabbing; }
.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.canvas svg.links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.links path { fill: none; stroke: #5E6361; stroke-width: 1.5; }
.links path.inferred { stroke-dasharray: 7 4; }
.links path.listed { stroke: var(--warm); stroke-dasharray: 2 5; stroke-width: 2; stroke-linecap: round; }
.node { position: absolute; width: 180px; min-height: 76px; display: flex; align-items: center; gap: 10px; padding: 9px 11px; background: var(--surface); border: 1px solid var(--field); border-radius: 10px; text-align: start; cursor: pointer; font-size: 13px; line-height: 1.45; color: var(--ink-2); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.node:hover { border-color: var(--accent); }
.node .nm { display: block; font-size: 14px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.node.private { background: var(--private); }
.node.selected { border: 2px solid var(--accent); background: var(--accent-soft); box-shadow: 0 6px 18px rgba(29,83,97,.18); }
.node.match { outline: 3px solid #E0A458; }
.node .more { position: absolute; inset-inline-end: -10px; top: -10px; min-width: 30px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.node .open { position: absolute; inset-inline-end: -10px; top: -10px; min-width: 22px; height: 22px; border-radius: 999px; background: var(--surface); border: 1px solid var(--accent); color: var(--accent); font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.node .sp { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.group-tag { position: absolute; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 10px; white-space: nowrap; }
.ref-node { position: absolute; width: 180px; min-height: 52px; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px dashed var(--accent); background: var(--accent-soft-2); border-radius: 10px; color: var(--accent); font-size: 13px; cursor: pointer; text-align: start; }
.tree-controls { position: absolute; inset-inline-start: 16px; top: 16px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.tree-controls button { width: 44px; height: 44px; border: 0; border-bottom: 1px solid var(--line-2); background: var(--surface); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.tree-controls button:last-child { border-bottom: 0; }
.tree-panel { position: absolute; inset-inline: 16px; bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; box-shadow: 0 8px 24px rgba(27,29,28,.1); }
.tree-panel .who { flex: 1 1 260px; display: flex; gap: 12px; align-items: center; }
.tree-hint { position: absolute; inset-inline-end: 16px; top: 12px; font-size: 14px; color: var(--muted); background: rgba(251,251,249,.85); padding: 2px 8px; border-radius: 6px; }

.outline { list-style: none; margin: 0; padding: 0; }
.outline ul { list-style: none; margin: 0; padding-inline-start: 26px; border-inline-start: 1px solid var(--line); margin-inline-start: 14px; }
.outline li > .ol-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.outline .toggle { width: 32px; height: 32px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.outline .toggle[aria-expanded="false"] .icon { transform: rotate(90deg); }
.outline .spacer { width: 32px; }

/* ── صلة القرابة ─────────────────────────────── */
.pickers { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.picker { position: relative; }
.picker .suggest { position: absolute; inset-inline: 0; top: 100%; z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; max-height: 320px; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.picker .suggest button { width: 100%; display: flex; gap: 10px; align-items: center; text-align: start; padding: 8px 12px; border: 0; background: transparent; cursor: pointer; }
.picker .suggest button:hover, .picker .suggest button:focus { background: var(--accent-soft-2); }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 0; row-gap: 14px; }
.path .pnode { width: 170px; min-height: 92px; padding: 10px 12px; border: 1px solid #A9C3CA; border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; justify-content: center; gap: 2px; font-size: 13px; color: var(--ink-2); }
.path .pnode.end { border: 2px solid var(--ink); }
.path .pnode.common { background: var(--accent-soft); border: 2px solid var(--accent); }
.path .pnode b { font-size: 15px; color: var(--ink); }
.path .pedge { display: flex; flex-direction: column; align-items: center; min-width: 96px; font-size: 13px; color: var(--ink-2); gap: 2px; }
.path .arrow { width: 80px; height: 10px; }
.path .arrow line { stroke: var(--accent); stroke-width: 2; }
.path .arrow.inferred line { stroke-dasharray: 6 4; }
.path .arrow.listed line { stroke: var(--warm); stroke-dasharray: 2 4; }
.path .arrow.marriage line { stroke: var(--ink-2); }
.alt { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; padding: 14px 18px; cursor: pointer; text-align: start; width: 100%; font: inherit; color: inherit; }
.alt[aria-pressed="true"] { border: 2px solid var(--accent); }

/* ── الإدارة ─────────────────────────────────── */
.admin-layout { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.queue { flex: 1 1 340px; max-width: 420px; display: flex; flex-direction: column; gap: 10px; }
.queue a { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); padding: 14px 18px; }
.queue a[aria-current="true"] { border: 2px solid var(--accent); }
.detail { flex: 999 1 600px; min-width: 0; padding: 0; overflow: hidden; }
.detail > section { padding: 20px 26px; border-bottom: 1px solid var(--line-2); }
.detail > section:last-child { border-bottom: 0; }
.diff { width: 100%; border-collapse: collapse; }
.diff th, .diff td { text-align: start; padding: 10px 12px; border-top: 1px solid var(--line-2); vertical-align: top; }
.diff thead th { font-size: 14px; color: var(--muted); border-top: 0; }
.diff .old { color: var(--ink-2); text-decoration: line-through; }
.diff .new { background: var(--accent-soft-2); font-weight: 600; }
.thread { display: flex; flex-direction: column; gap: 8px; }
.thread .msg { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 14px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 14px; padding: 8px 0; border-top: 1px solid var(--line-2); font-size: 15px; }

/* ── المساهمة ────────────────────────────────── */
.dropzone { border: 2px dashed #A9C3CA; border-radius: 12px; background: var(--accent-soft-2); padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }
.changed input, .changed textarea, .changed select { border: 2px solid var(--accent); background: var(--accent-soft-2); }

.site-footer { border-top: 1px solid var(--line); background: var(--surface); font-size: 14px; color: var(--muted); }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; padding-block: 16px; }
body.tree-mode .site-footer { display: none; }

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .site-header { position: static; }
  .site-header .wrap { gap: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; gap: 18px; overflow-x: auto; flex-wrap: nowrap; white-space: nowrap; }
  .account-link .role-line { display: none; }
  /* الشجرة على الجوال: الصفحة تُمرَّر، واللوحة تأخذ معظم الارتفاع، والبطاقة أسفلها */
  body.tree-mode { height: auto; overflow: auto; display: block; }
  body.tree-mode main, body.tree-mode .tree-root, .tree-shell { display: block; }
  .tree-toolbar { padding: 10px 16px; gap: 8px; }
  .tree-toolbar .hint { display: none; }
  .tree-toolbar input.input { width: 100% !important; }
  .legend { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; padding: 6px 16px; }
  .tree-shell > div:last-child { display: block !important; }
  .viewport { height: 68vh; }
  .tree-hint { display: none; }
  .tree-panel { position: static; margin: 10px; }
  .pickers { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
}
