/* ============================================================
   شجرة عائلة القراريش — تصميم Mobile-first (تراثي عصري)
   زمرّدي عميق + ذهبي + كريمي، مع زخرفة هندسية وحركات ناعمة
   ============================================================ */

:root{
  --em-950:#062a1e; --em-900:#0a3a29; --em-800:#0e4a36; --em-700:#136248;
  --teal-700:#0d5f57;
  --gold:#cda23f; --gold-1:#e3c577; --gold-2:#b5841f;
  --cream:#f8f2e4; --cream-2:#efe6d2; --card:#fffdf7;
  --ink:#1b241e; --ink-2:#4c5a51; --muted:#64746a;
  --fam0:#1f7a52; --fam1:#b5841f; --fam2:#2d6da8; --fam3:#7d4a98; --fam4:#b04332; --fam5:#0d8a80;
  --line:#e4dcc7; --danger:#b04332; --ok:#1f7a52;

  --r-sm:12px; --r:18px; --r-lg:26px;
  --pad:18px;
  --shadow-1:0 2px 10px rgba(6,42,30,.06);
  --shadow-2:0 18px 50px -20px rgba(6,42,30,.45);
  --tap:50px;
  --maxw:780px;
  --safe-b:env(safe-area-inset-bottom,0px);
  color-scheme:light;
}

/* ============ الثيم الغامق (متغيّرات) ============ */
:root[data-theme="dark"]{
  --cream:#17231c; --cream-2:#1f2f26; --card:#253831;
  --ink:#f0f4f0; --ink-2:#c6d4ca; --muted:#a3b6a9;
  --line:#41594b; --ok:#3fae7e; --danger:#d4705e;
  --fam0:#3fae7e; --fam1:#d8a93f; --fam2:#5b9bd5; --fam3:#a878c5; --fam4:#d4705e; --fam5:#3db3a8;
  --shadow-1:0 2px 10px rgba(0,0,0,.45);
  --shadow-2:0 18px 50px -22px rgba(0,0,0,.8);
  color-scheme:dark;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html{ -webkit-text-size-adjust:100%; font-size:clamp(15px, 14.3px + .12vw, 17px); }

/* ============================================================
   نظام الدقات: المنصة تتكيف آلياً مع قياس الشاشة
   (سمات data-device/data-res تضبطها js/device.js)
   - جوال  < 680      : عمود واحد، أهداف لمس كبيرة
   - تابلت 680–1023   : عمود واحد أعرض
   - لابتوب 1024–1279 : عمود أعرض + تحسينات مؤشر
   - FHD   1280+      : تخطيط عمودين (مشجرة + شريط جانبي ثابت)
   - 2K    2200+      : تكبير 115% ومساحات أوسع
   - 4K    3400+      : تكبير 150%
   ============================================================ */
@media (min-width:2200px){ body{ zoom:1.15; } }
@media (min-width:2800px){ body{ zoom:1.3; } }
@media (min-width:3400px){ body{ zoom:1.5; } }
html,body{ margin:0; padding:0; }
body{
  font-family:"Readex Pro",system-ui,-apple-system,sans-serif;
  color:var(--ink); line-height:1.75; min-height:100dvh;
  font-size:16px;
  background:var(--cream);
  -webkit-font-smoothing:antialiased;
}
a{ color:var(--em-700); }
img{ max-width:100%; }

/* أنماط زخرفية مشتركة */
.geo-bg{ position:fixed; inset:0; z-index:0; pointer-events:none; opacity:.06;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='none' stroke='%23062a1e' stroke-width='1'%3E%3Cpath d='M30 2l8 8-8 8-8-8z M30 42l8 8-8 8-8-8z M2 30l8-8 8 8-8 8z M42 30l8-8 8 8-8 8z'/%3E%3C/g%3E%3C/svg%3E"); }

/* ============ شريط التطبيق العلوي ============ */
.appbar{
  position:sticky; top:0; z-index:50;   /* فوق القوائم المنسدلة (40) ودون التوست (60) */
  background:linear-gradient(135deg,var(--em-900),var(--em-700) 70%,var(--teal-700));
  color:#fbf6e9; box-shadow:var(--shadow-2);
  border-bottom:2px solid var(--gold);
}
.appbar-in{ max-width:var(--maxw); margin:0 auto; padding:12px 16px;
  display:flex; align-items:center; gap:12px; }
.appbar .logo{ width:44px; height:44px; flex:0 0 auto; border-radius:50%;
  display:grid; place-items:center;
  color:var(--em-950); background:radial-gradient(circle at 35% 30%,var(--gold-1),var(--gold));
  box-shadow:inset 0 0 0 2px rgba(255,255,255,.3),0 4px 12px rgba(0,0,0,.3); }
.appbar .logo svg{ width:64%; height:64%; display:block; }
.appbar h1{ font-family:"Amiri",serif; font-size:1.25rem; margin:0; line-height:1.2; flex:1; }
.appbar .sub{ display:block; font-family:"Readex Pro"; font-size:.66rem; color:var(--gold-1); letter-spacing:.3px; }
.appbar .who{ font-size:.7rem; text-align:left; opacity:.9; }

.iconbtn{ width:42px; height:42px; border-radius:12px; border:1px solid rgba(227,197,119,.35);
  background:rgba(255,255,255,.08); color:#fbf6e9; display:grid; place-items:center; cursor:pointer;
  font-size:1.1rem; transition:background .15s; }
.iconbtn:hover{ background:rgba(255,255,255,.16); }

/* ============ التخطيط العام ============ */
main{ max-width:var(--maxw); margin:0 auto; padding:16px 16px calc(40px + var(--safe-b)); position:relative; z-index:1; }
.section-head{ display:flex; align-items:center; gap:10px; margin:22px 4px 12px; }
.section-head h2{ font-family:"Amiri",serif; font-size:1.3rem; color:var(--em-800); margin:0; }
.section-head .dot{ width:8px; height:8px; border-radius:50%; background:var(--gold); box-shadow:0 0 0 4px rgba(205,162,63,.18); }

.card{ background:var(--card); border:1px solid var(--line); border-radius:var(--r-lg);
  padding:var(--pad); box-shadow:var(--shadow-1); margin-bottom:16px; }
.muted{ color:var(--muted); font-size:.86rem; }

/* حركة دخول متدرجة
   ملاحظة مهمة: fill-mode هنا backwards وليس forwards — حتى لا تبقى البطاقة
   سياق تراصّ دائماً بعد انتهاء الحركة فتُحجب القوائم المنسدلة خلف البطاقات التالية */
.reveal{ animation:rise-in .6s cubic-bezier(.2,.7,.2,1) backwards; }
.reveal:nth-child(2){ animation-delay:.06s } .reveal:nth-child(3){ animation-delay:.12s }
.reveal:nth-child(4){ animation-delay:.18s } .reveal:nth-child(5){ animation-delay:.24s }
@keyframes rise-in{ from{ opacity:0; transform:translateY(14px) } }
@keyframes rise{ to{ opacity:1; transform:none } }

/* ============ أزرار ============ */
.btn{ font-family:inherit; font-size:1rem; font-weight:600; cursor:pointer; border:none;
  border-radius:14px; min-height:var(--tap); padding:0 22px; display:inline-flex; align-items:center;
  justify-content:center; gap:8px; transition:transform .08s, filter .15s, box-shadow .15s; width:auto; }
.btn:active{ transform:translateY(1px) scale(.99); }
.btn-block{ width:100%; }
.btn-primary{ background:linear-gradient(135deg,var(--em-800),var(--em-700)); color:#fff;
  box-shadow:0 10px 24px -10px rgba(10,58,41,.7); }
.btn-gold{ background:linear-gradient(135deg,var(--gold-2),var(--gold)); color:var(--em-950);
  box-shadow:0 10px 24px -10px rgba(181,132,31,.7); font-weight:700; }
.btn-ghost{ background:transparent; color:var(--em-800); border:1.5px solid var(--line); }
.btn-ghost:hover{ background:var(--cream-2); }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-sm{ min-height:38px; padding:0 14px; font-size:.82rem; border-radius:11px; }
.btn-row{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.chk{ display:inline-flex; align-items:center; gap:8px; margin:0; font-size:.82rem; font-weight:500;
  color:var(--ink-2); cursor:pointer; }
.chk input{ width:auto; min-height:auto; margin:0; accent-color:var(--em-700); cursor:pointer; }

/* ============ نماذج ============ */
label{ display:block; font-size:.82rem; font-weight:600; color:var(--ink-2); margin:0 0 7px; }
input,select,textarea{ width:100%; font-family:inherit; font-size:16px; color:var(--ink);
  background:var(--cream); border:1.5px solid var(--line); border-radius:14px;
  min-height:var(--tap); padding:12px 15px; transition:border .15s, box-shadow .15s, background .15s; }
select{ appearance:none; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237c8a80' stroke-width='1.6' fill='none'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:left 16px center; }
input:focus,select:focus,textarea:focus{ outline:none; border-color:var(--em-700); background:var(--card);
  box-shadow:0 0 0 4px rgba(19,98,72,.12); }
.field{ margin-bottom:14px; }
.fhint{ margin:6px 2px 0; font-size:.72rem; color:var(--muted); line-height:1.55; }
.grid{ display:grid; gap:14px; }

/* ============ الشجرة (تخطيط أفقي شجري) ============ */
.tools{ display:flex; gap:8px; flex-wrap:wrap; margin-top:12px; align-items:center; }
.tools .spacer{ flex:1 1 auto; }
.zoombar{ display:inline-flex; gap:6px; align-items:center; }
.zoombar .zlabel{ font-size:.78rem; color:var(--muted); min-width:46px; text-align:center; }

.tree-scroll{ overflow:auto; -webkit-overflow-scrolling:touch; margin-top:14px;
  padding:16px 8px; max-height:72vh;
  border:1.5px solid var(--line); border-radius:var(--r);
  background:
    radial-gradient(circle at 1px 1px, rgba(6,42,30,.05) 1px, transparent 0) 0 0/22px 22px,
    var(--card); }
#treeRoot{ transform-origin:top center; }

.tree{ list-style:none; margin:0; padding:4px 0 0; display:flex; justify-content:center;
  min-width:max-content; }
.tree ul{ list-style:none; margin:0; padding:30px 0 0; position:relative;
  display:flex; justify-content:center; }
.tree li{ position:relative; padding:30px 14px 0; display:flex;
  flex-direction:column; align-items:center; }

/* وصلات الفروع (خطوط الربط بين الأب وأبنائه) */
.tree li::before, .tree li::after{ content:""; position:absolute; top:0; right:50%;
  width:50%; height:30px; border-top:2px solid var(--line); }
.tree li::after{ right:auto; left:50%; border-left:2px solid var(--line); }
.tree li::before{ border-right:2px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after{ display:none; }
.tree li:only-child{ padding-top:0; }
/* ملاحظة: الصفحة RTL فالطفل الأول يظهر يميناً — لذا تُعكس قواعد الأطراف */
.tree li:first-child::after, .tree li:last-child::before{ border:0 none; }
.tree li:first-child::before{ border-radius:0 8px 0 0; }
.tree li:last-child::after{ border-radius:8px 0 0 0; }
.tree ul::before{ content:""; position:absolute; top:0; left:50%; width:0; height:30px;
  border-left:2px solid var(--line); }

/* الجذر: بلا وصلات علوية */
.tree>li{ padding-top:0; }
.tree>li::before, .tree>li::after{ display:none; }

.node-row{ display:inline-flex; align-items:center; justify-content:center; position:relative; }
.toggle{ position:absolute; bottom:-13px; left:50%; transform:translateX(-50%);
  width:24px; height:24px; z-index:3; border-radius:999px; cursor:pointer;
  border:1.5px solid var(--line); background:var(--card); color:var(--em-700);
  display:grid; place-items:center; font-size:14px; font-weight:700; line-height:1;
  box-shadow:var(--shadow-1); }
.toggle:hover{ border-color:var(--em-700); color:var(--em-900); }
.toggle.leaf{ display:none; }
.node{ display:inline-flex; align-items:center; gap:8px; cursor:pointer; flex-direction:column;
  background:var(--card); border:1.5px solid var(--line); border-radius:13px; padding:10px 16px;
  box-shadow:var(--shadow-1); transition:all .15s; min-height:44px; text-align:center; }
.node:hover{ border-color:var(--em-700); transform:translateY(-1px); }
.node .name{ font-weight:600; white-space:nowrap; }
.node .alias{ font-size:.74rem; color:var(--gold-2); white-space:nowrap; }
.node.is-highlight{ background:linear-gradient(135deg,var(--em-800),var(--em-700)); color:#fff; border-color:var(--em-900); }
.node.is-highlight .alias{ color:var(--gold-1); }

/* ---- تظليل مسار نقطة الالتقاء داخل المشجرة ---- */
.node.is-path{ border-color:var(--em-700); background:#eef5f0; box-shadow:0 0 0 2px rgba(19,98,72,.18); }
.node.is-endpoint{ background:linear-gradient(135deg,var(--gold),var(--gold-2)); color:#231a05;
  border-color:var(--gold-2); font-weight:700; box-shadow:0 6px 16px -6px rgba(181,132,31,.6); }
.node.is-endpoint .alias{ color:#4a3708; }
.node.is-anc{ outline:3px solid var(--gold); outline-offset:2px;
  background:linear-gradient(135deg,var(--em-800),var(--em-700)); color:#fff; border-color:var(--em-900); }
.node.is-anc .alias{ color:var(--gold-1); }
/* وضع التركيز: تعتيم ما هو خارج المسار لإبراز نقطة الالتقاء */
.tree.focus .node{ opacity:.3; }
.tree.focus .node.is-path,
.tree.focus .node.is-endpoint,
.tree.focus .node.is-anc{ opacity:1; }

/* الجذر (قريش) مميّز */
.tree>li>.node-row>.node{ border-color:var(--gold-1);
  background:linear-gradient(160deg,#fffef9,#f4ebd2); }
.tree>li>.node-row>.node .name{ font-family:"Amiri",serif; font-size:1.15rem; color:var(--em-900); }

.badge{ font-size:.64rem; padding:3px 9px; border-radius:999px; background:var(--cream-2);
  color:var(--ink-2); border:1px solid var(--line); white-space:nowrap; }
.collapsed>ul{ display:none; }

/* ============ نتيجة نقطة الالتقاء ============ */
.result-card{ background:linear-gradient(160deg,#fffef9,#f1e7ce); border:1.5px solid var(--gold-1);
  border-radius:var(--r); padding:18px; margin-top:14px; }
.result-card .anc-name{ font-family:"Amiri",serif; font-size:1.5rem; color:var(--em-900); }
.chip{ display:inline-block; background:var(--em-800); color:#fff; padding:7px 14px; border-radius:999px;
  font-size:.85rem; margin:5px 5px 0 0; }
.paths{ display:grid; gap:12px; margin-top:14px; }
.path-col h4{ margin:0 0 6px; color:var(--em-700); font-size:.88rem; }
.path-col ol{ margin:0; padding-inline-start:18px; font-size:.86rem; color:var(--ink-2); }

/* ============ إحصائيات ============ */
.stats{ display:grid; grid-template-columns:repeat(2,1fr); gap:10px; }
.stat{ background:linear-gradient(135deg,var(--em-800),var(--teal-700)); color:#fff;
  border-radius:var(--r); padding:14px; text-align:center; }
.stat b{ font-family:"Amiri",serif; font-size:1.7rem; display:block; line-height:1; }
.stat span{ font-size:.72rem; color:var(--gold-1); }

/* ============ جداول (تتحول بطاقات على الجوال) ============ */
.tbl{ width:100%; border-collapse:collapse; font-size:.9rem; }
.tbl thead{ display:none; }
.tbl tr{ display:block; background:var(--card); border:1.5px solid var(--line); border-radius:var(--r);
  margin-bottom:10px; padding:8px 12px; }
.tbl td{ display:flex; justify-content:space-between; gap:12px; padding:6px 2px; border:none;
  border-bottom:1px dashed var(--line); }
.tbl td:last-child{ border-bottom:none; padding-top:10px; }
.tbl td::before{ content:attr(data-label); font-weight:700; color:var(--em-700); font-size:.78rem; }
.tbl td > .btn{ margin-inline-start:auto; }

.row-actions{ display:flex; gap:8px; }

/* ============ شارات الأدوار ============ */
.badge-role{ font-size:.68rem; padding:3px 11px; border-radius:999px; font-weight:700;
  background:var(--gold); color:var(--em-950); }
.badge-role.admin{ background:#e7f0ea; color:var(--em-700); }
.badge-role.viewer{ background:var(--cream-2); color:var(--ink-2); }

/* ============ Toast ============ */
.toast{ position:fixed; left:50%; bottom:calc(20px + var(--safe-b)); transform:translateX(-50%) translateY(24px);
  background:var(--em-900); color:#fff; padding:13px 22px; border-radius:999px; z-index:60;
  box-shadow:var(--shadow-2); opacity:0; transition:all .3s; font-size:.9rem; border:1px solid var(--gold);
  max-width:90vw; text-align:center; }
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }
.toast.err{ background:var(--danger); }

/* ============ صفحة الترحيب ============ */
.hero{ min-height:100dvh; display:flex; flex-direction:column; position:relative; overflow:hidden;
  color:#fbf6e9; text-align:center;
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(205,162,63,.28), transparent 55%),
    radial-gradient(120% 80% at -10% 110%, rgba(13,95,87,.55), transparent 55%),
    linear-gradient(150deg,var(--em-950),var(--em-800) 60%,var(--teal-700)); }
.hero .geo{ position:absolute; inset:0; opacity:.10; pointer-events:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23e3c577' stroke-width='1'%3E%3Cpath d='M40 4l10 10-10 10-10-10z M40 56l10 10-10 10-10-10z M4 40l10-10 10 10-10 10z M56 40l10-10 10 10-10 10z M40 24v32 M24 40h32'/%3E%3C/g%3E%3C/svg%3E"); }
.hero-in{ position:relative; z-index:2; margin:auto; padding:32px 24px calc(40px + var(--safe-b)); max-width:520px; width:100%; }
.emblem{ width:108px; height:108px; margin:0 auto 22px; border-radius:50%; display:grid; place-items:center;
  color:var(--em-950);
  background:radial-gradient(circle at 35% 28%,var(--gold-1),var(--gold) 70%,var(--gold-2));
  box-shadow:inset 0 0 0 3px rgba(255,255,255,.35),0 22px 50px -16px rgba(0,0,0,.6);
  animation:rise .7s cubic-bezier(.2,.7,.2,1) both; }
.emblem svg{ width:70%; height:70%; display:block; }
.hero h1{ font-family:"Amiri",serif; font-size:2.5rem; margin:0 0 8px; line-height:1.15;
  animation:rise .7s .08s cubic-bezier(.2,.7,.2,1) both; }
.hero .tag{ color:var(--gold-1); font-size:1rem; margin:0 0 6px; animation:rise .7s .14s both; }
.hero .note{ color:rgba(251,246,233,.78); font-size:.9rem; margin:0 auto 30px; max-width:380px;
  animation:rise .7s .2s both; }
.hero .actions{ display:flex; flex-direction:column; gap:12px; animation:rise .7s .26s both; }
.hero .divider{ width:70px; height:3px; margin:18px auto; border-radius:3px;
  background:linear-gradient(90deg,transparent,var(--gold),transparent); }
.hero-foot{ position:relative; z-index:2; padding:0 24px calc(22px + var(--safe-b)); font-size:.78rem;
  color:rgba(251,246,233,.6); font-family:"Amiri",serif; }

/* ============ بطاقة الدخول ============ */
.auth-wrap{ min-height:100dvh; display:grid; place-items:center; padding:24px;
  background:radial-gradient(120% 80% at 80% -10%, rgba(205,162,63,.16), transparent 55%),var(--cream); }
.auth-card{ width:100%; max-width:420px; background:var(--card); border:1px solid var(--line);
  border-radius:var(--r-lg); padding:30px 24px calc(28px); box-shadow:var(--shadow-2);
  animation:rise .6s both; }
.auth-card .emblem{ width:80px; height:80px; border-radius:50%; margin-bottom:16px; animation:none; }
.auth-card h1{ font-family:"Amiri",serif; text-align:center; color:var(--em-800); font-size:1.6rem; margin:0 0 4px; }
.auth-card .sub{ text-align:center; color:var(--muted); font-size:.86rem; margin:0 0 22px; }
.otp-input{ text-align:center; letter-spacing:.6em; font-size:1.5rem; font-family:"Amiri",serif; padding-inline-start:.6em; }
.hint{ font-size:.8rem; color:var(--muted); text-align:center; margin-top:12px; }
.msg{ text-align:center; font-size:.85rem; margin-top:12px; min-height:1.2em; }

@media (min-width:680px){
  :root{ --pad:24px; }
  .grid-2{ grid-template-columns:1fr 1fr; }
  .paths{ grid-template-columns:1fr 1fr; }
  .stats{ grid-template-columns:repeat(4,1fr); }
  .hero h1{ font-size:3rem; }
  .hero .actions{ flex-direction:row; justify-content:center; }
  .hero .actions .btn{ min-width:180px; }
}

/* ===== لابتوب: عمود أعرض ===== */
@media (min-width:1024px){
  :root{ --maxw:980px; }
}

/* ===== FHD فأعلى: تخطيط عمودين — المشجرة رئيسية + شريط جانبي ثابت ===== */
@media (min-width:1280px){
  :root{ --maxw:min(1880px, 94vw); }
  main.layout{
    display:grid; grid-template-columns:minmax(0,1fr) 410px;
    gap:28px; align-items:start;
  }
  .col-side{
    position:sticky; top:80px;
    max-height:calc(100dvh - 100px); overflow:auto;
    padding-inline-end:2px;
  }
  .col-side .section-head:first-child{ margin-top:0; }
  .col-side .stats{ grid-template-columns:1fr 1fr; }
  .col-main .section-head:first-child{ margin-top:0; }
  .tree-scroll{ max-height:calc(100dvh - 300px); min-height:440px; }

  /* الإدارة: نموذج الإضافة ثابت جانبياً + المحتوى رئيسي */
  main.layout-admin{
    display:grid; grid-template-columns:430px minmax(0,1fr);
    gap:28px; align-items:start;
  }
  .col-form{ position:sticky; top:80px; max-height:calc(100dvh - 100px); overflow:auto; }
  .col-form .section-head:first-child, .col-content .section-head:first-child{ margin-top:0; }
}

/* ===== على الشاشات الكبيرة: بطاقة الشخص حوار مركزي بدل شريط سفلي ===== */
@media (min-width:1024px){
  .sheet{
    bottom:auto; top:50%; max-width:600px;
    border-bottom:1.5px solid var(--line); border-radius:24px;
    transform:translate(-50%,-46%); opacity:0; visibility:hidden;
    transition:transform .28s cubic-bezier(.2,.7,.2,1), opacity .25s, visibility .25s;
    padding:22px 26px; max-height:80vh;
  }
  .sheet.show{ transform:translate(-50%,-50%); opacity:1; visibility:visible; }
  .sheet .grab{ display:none; }
}

/* ===== أجهزة اللمس: تعطيل تأثيرات المرور العالقة وأهداف لمس أكبر ===== */
:root[data-pointer="touch"] .card:hover{ transform:none; box-shadow:var(--shadow-1); }
:root[data-pointer="touch"] .node:hover{ transform:none; }
:root[data-pointer="touch"] .btn:hover{ transform:none; }
:root[data-pointer="touch"] .toggle{ width:28px; height:28px; }
:root[data-device="mobile"] .zoombar .zlabel{ min-width:40px; }

/* ============ زر تبديل الثيم ============ */
.theme-toggle{ position:fixed; top:14px; inset-inline-start:14px; z-index:70;
  width:44px; height:44px; border-radius:50%; border:1.5px solid var(--line);
  background:var(--card); color:var(--ink); font-size:20px; cursor:pointer;
  box-shadow:var(--shadow-1); display:grid; place-items:center; line-height:1; }
.theme-toggle:hover{ border-color:var(--gold); }

/* ============ حركات عامة (كل الثيمات) ============ */
/* انتقال ناعم عند تبديل الثيم */
body, .card, .tbl tr, .sheet, .modal, input, select, textarea, .lchip, .tree-scroll{
  transition:background-color .35s ease, border-color .35s ease, color .35s ease; }

/* دخول الترويسة */
.appbar-in{ animation:fadeDown .5s ease both; }
@keyframes fadeDown{ from{ opacity:0; transform:translateY(-10px) } }

/* دخول عقد المشجرة بتتابع (التأخير يُضبط من JS حسب الجيل)
   وإعادة فتح فرع مطوي تعيد تشغيله = تتالٍ جميل */
.tree li{ animation:nodeIn .4s ease both; }
@keyframes nodeIn{ from{ opacity:0; transform:scale(.92) translateY(6px) } }

/* أزرار أكثر حيوية */
.btn:hover{ transform:translateY(-1px); }
.btn:active{ transform:translateY(1px) scale(.97); }
.lchip{ transition:all .2s ease; }
.lchip:hover{ transform:translateY(-1px); }
.iconbtn{ transition:background .15s, transform .15s; }
.iconbtn:active{ transform:scale(.92); }

/* نبض ذهبي على نقطة الالتقاء (السلف المشترك) */
.node.is-anc{ animation:ancPulse 1.8s ease-in-out infinite; }
@keyframes ancPulse{
  0%,100%{ box-shadow:0 0 0 0 rgba(205,162,63,.55) }
  50%{ box-shadow:0 0 0 14px rgba(205,162,63,0) } }

/* ظهور الطرفين ونتائج البحث بنطّة خفيفة */
.node.is-endpoint, .node.is-highlight{ animation:popIn .35s cubic-bezier(.2,.7,.3,1.35); }
@keyframes popIn{ from{ transform:scale(.78); opacity:.4 } }

/* بطاقة النتيجة والقوائم المنسدلة */
.result-card{ animation:rise .45s cubic-bezier(.2,.7,.2,1) both; }
.combo.open .combo-list{ animation:fadeDown .18s ease; }

/* الشعار: دوران بطيء للحلقة المنقّطة + طفو في الترحيب */
.emblem svg circle, .appbar .logo svg circle{ transform-origin:center; animation:spinSlow 50s linear infinite; }
@keyframes spinSlow{ to{ transform:rotate(360deg) } }
.hero .emblem{ animation:rise .7s cubic-bezier(.2,.7,.2,1) both, float 6s 1.2s ease-in-out infinite; }
@keyframes float{ 0%,100%{ transform:translateY(0) } 50%{ transform:translateY(-8px) } }

/* ===== حزمة حركات إضافية (كل الثيمات) ===== */
/* دخول ناعم لكل صفحة */
body{ animation:pageIn .45s ease; }
@keyframes pageIn{ from{ opacity:0 } }

/* الزخرفة الخلفية تنجرف ببطء شديد */
.geo-bg{ animation:geoDrift 90s linear infinite; }
@keyframes geoDrift{ to{ background-position:600px 600px } }

/* البطاقات ترتفع قليلاً عند المرور */
.card{ transition:background-color .35s ease, border-color .35s ease, color .35s ease,
       transform .25s ease, box-shadow .25s ease; }
.card:hover{ transform:translateY(-2px); box-shadow:0 14px 34px -18px rgba(6,42,30,.35); }
/* بطاقة فيها قائمة منسدلة مفتوحة: تثبت مرفوعةً فوق كل البطاقات
   (وإلا غطّت البطاقةُ المجاورة عند المرور عليها القائمةَ المفتوحة) */
.card:has(.combo.open){ transform:none; position:relative; z-index:46; }

/* نبض نقطة عناوين الأقسام */
.section-head .dot{ animation:dotPulse 2.6s ease-in-out infinite; }
@keyframes dotPulse{
  0%,100%{ box-shadow:0 0 0 4px rgba(205,162,63,.18) }
  50%{ box-shadow:0 0 0 9px rgba(205,162,63,.04) } }

/* لمعان دوري يعبر الزر الذهبي */
.btn-gold{ position:relative; overflow:hidden; }
.btn-gold::after{ content:""; position:absolute; top:0; bottom:0; width:55%;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,.38),transparent);
  transform:translateX(-200%) skewX(-18deg); animation:sheen 5s ease-in-out infinite; }
@keyframes sheen{ 0%,72%{ transform:translateX(-200%) skewX(-18deg) }
  100%{ transform:translateX(340%) skewX(-18deg) } }

/* بطاقات الإحصاءات: دخول متتابع + ارتفاع عند المرور */
.stat{ transition:transform .2s ease; animation:rise-in .5s both; }
.stat:hover{ transform:translateY(-3px) scale(1.02); }
.stats .stat:nth-child(1){animation-delay:.03s} .stats .stat:nth-child(2){animation-delay:.08s}
.stats .stat:nth-child(3){animation-delay:.13s} .stats .stat:nth-child(4){animation-delay:.18s}
.stats .stat:nth-child(5){animation-delay:.23s} .stats .stat:nth-child(6){animation-delay:.28s}
.stats .stat:nth-child(7){animation-delay:.33s} .stats .stat:nth-child(8){animation-delay:.38s}

/* شرائح العوائل: دخول متتابع */
.legend .lchip{ animation:rise-in .4s both; }
.legend .lchip:nth-child(1){animation-delay:.04s} .legend .lchip:nth-child(2){animation-delay:.1s}
.legend .lchip:nth-child(3){animation-delay:.16s} .legend .lchip:nth-child(4){animation-delay:.22s}
.legend .lchip:nth-child(5){animation-delay:.28s} .legend .lchip:nth-child(6){animation-delay:.34s}

/* توهج بلون العائلة عند المرور على العقدة */
.node.fam:hover{ box-shadow:0 6px 18px -6px var(--famc); }

/* شعار الترويسة يميل عند المرور */
.appbar .logo{ transition:transform .25s ease; }
.appbar .logo:hover{ transform:rotate(-8deg) scale(1.07); }

/* التوست يقفز قفزة خفيفة */
.toast.show{ animation:toastIn .45s cubic-bezier(.2,.7,.3,1.3); }
@keyframes toastIn{ from{ transform:translateX(-50%) translateY(34px); opacity:0 } }

/* المودال يظهر بارتداد */
.modal-backdrop.show .modal{ transition:transform .28s cubic-bezier(.2,.7,.3,1.35); }

/* حقل رمز التحقق ينبض عند التركيز */
.otp-input:focus{ animation:otpPulse 1.8s ease-in-out infinite; }
@keyframes otpPulse{
  0%,100%{ box-shadow:0 0 0 4px rgba(19,98,72,.14) }
  50%{ box-shadow:0 0 0 9px rgba(19,98,72,.04) } }

/* كرتان ضوئيتان تطفوان في صفحة الترحيب */
.hero{ overflow:hidden; }
.hero .orb{ position:absolute; border-radius:50%; filter:blur(64px); opacity:.32;
  pointer-events:none; z-index:1; }
.hero .orb.o1{ width:320px; height:320px; background:var(--gold);
  top:-90px; inset-inline-start:-70px; animation:orbFloat 15s ease-in-out infinite; }
.hero .orb.o2{ width:260px; height:260px; background:var(--em-700);
  bottom:-70px; inset-inline-end:-50px; animation:orbFloat 19s ease-in-out infinite reverse; }
@keyframes orbFloat{ 0%,100%{ transform:translate(0,0) scale(1) }
  50%{ transform:translate(34px,42px) scale(1.08) } }

/* فاصل الترحيب الذهبي يتنفس */
.hero .divider{ animation:dividerGlow 3s ease-in-out infinite; }
@keyframes dividerGlow{ 0%,100%{ opacity:.7; transform:scaleX(1) }
  50%{ opacity:1; transform:scaleX(1.25) } }

/* احترام من يفضّل تقليل الحركة */
@media (prefers-reduced-motion:reduce){
  *, *::before, *::after{
    animation-duration:.01ms !important; animation-iteration-count:1 !important;
    transition-duration:.01ms !important; scroll-behavior:auto !important; }
}

/* ============ ألوان العوائل على العقد ============ */
.node.fam{ border-top:3px solid var(--famc); }
.node .badge.fam{ background:color-mix(in srgb, var(--famc) 14%, transparent);
  color:var(--famc); border-color:color-mix(in srgb, var(--famc) 35%, transparent); }
.node.is-me{ box-shadow:0 0 0 2.5px var(--gold); }
.me-chip{ font-size:.6rem; font-weight:700; background:var(--gold); color:var(--em-950);
  border-radius:999px; padding:2px 8px; }
.lock-ico{ font-size:.68rem; opacity:.75; }

/* وسيلة الإيضاح / فلتر العوائل */
.legend{ display:flex; gap:8px; flex-wrap:wrap; margin:10px 0 2px; }
.lchip{ display:inline-flex; align-items:center; gap:7px; cursor:pointer; font-size:.78rem;
  font-weight:600; color:var(--ink-2); background:var(--card); border:1.5px solid var(--line);
  border-radius:999px; padding:6px 13px; transition:all .15s; }
.lchip .swatch-dot{ width:11px; height:11px; border-radius:50%; background:var(--famc); }
.lchip:hover{ border-color:var(--famc); }
.lchip.active{ background:color-mix(in srgb, var(--famc) 12%, var(--card));
  border-color:var(--famc); color:var(--famc); }
.tree.fam-focus .node{ opacity:.25; }
.tree.fam-focus .node.fam-lit{ opacity:1; }

/* ============ البطاقة السفلية (تفاصيل الشخص) ============ */
.sheet-backdrop{ position:fixed; inset:0; background:rgba(6,42,30,.45); z-index:80;
  opacity:0; pointer-events:none; transition:opacity .25s; }
.sheet-backdrop.show{ opacity:1; pointer-events:auto; }
.sheet{ position:fixed; bottom:0; left:50%; transform:translateX(-50%) translateY(105%);
  width:100%; max-width:560px; z-index:81; background:var(--card);
  border:1.5px solid var(--line); border-bottom:none; border-radius:24px 24px 0 0;
  padding:10px 20px calc(22px + var(--safe-b)); box-shadow:0 -18px 50px -20px rgba(6,42,30,.5);
  transition:transform .28s cubic-bezier(.2,.7,.2,1); max-height:75dvh; overflow:auto; }
.sheet.show{ transform:translateX(-50%) translateY(0); }
.sheet .grab{ width:44px; height:5px; border-radius:99px; background:var(--line); margin:4px auto 14px; }
.sheet h3{ font-family:"Amiri",serif; font-size:1.45rem; color:var(--em-800); margin:0; }
:root[data-theme="dark"] .sheet h3{ color:var(--gold-1); }
.sheet .lineage{ font-size:.85rem; color:var(--ink-2); margin:8px 0 0; line-height:1.9; }
.sheet .srow{ display:flex; gap:8px; flex-wrap:wrap; margin-top:16px; }
.sheet .meta{ display:flex; gap:14px; flex-wrap:wrap; margin-top:10px; font-size:.8rem; color:var(--muted); }

/* ============ مودال تأكيد أنيق (بديل confirm) ============ */
.modal-backdrop{ position:fixed; inset:0; background:rgba(6,42,30,.5); z-index:90;
  display:grid; place-items:center; padding:24px; opacity:0; pointer-events:none; transition:opacity .2s; }
.modal-backdrop.show{ opacity:1; pointer-events:auto; }
.modal{ width:100%; max-width:380px; background:var(--card); border:1.5px solid var(--line);
  border-radius:var(--r-lg); padding:24px; box-shadow:var(--shadow-2);
  transform:scale(.94); transition:transform .2s; }
.modal-backdrop.show .modal{ transform:scale(1); }
.modal h3{ margin:0 0 8px; font-size:1.05rem; color:var(--ink); }
.modal p{ margin:0 0 18px; font-size:.88rem; color:var(--ink-2); line-height:1.8; }
.modal .btn-row{ justify-content:flex-end; }

/* ============ هيكل تحميل ============ */
.skel{ border-radius:12px; background:linear-gradient(90deg,var(--cream-2) 25%,var(--card) 50%,var(--cream-2) 75%);
  background-size:200% 100%; animation:shimmer 1.2s infinite linear; }
@keyframes shimmer{ to{ background-position:-200% 0 } }

/* ============ مُنتقي بالكتابة (combobox) ============ */
.combo{ position:relative; }
.combo.open{ z-index:45; }   /* يرفع الحقل المفتوح فوق بقية محتوى الصفحة */
.combo .combo-list{ position:absolute; top:calc(100% + 4px); inset-inline:0; z-index:40;
  background:var(--card); border:1.5px solid var(--line); border-radius:14px;
  max-height:250px; overflow:auto; box-shadow:var(--shadow-2); display:none; }
.combo.open .combo-list{ display:block; }
.combo-list .opt{ display:block; width:100%; text-align:start; background:none; border:none;
  cursor:pointer; padding:11px 15px; font-family:inherit; font-size:.9rem; color:var(--ink);
  border-bottom:1px dashed var(--line); }
.combo-list .opt:last-child{ border-bottom:none; }
.combo-list .opt:hover, .combo-list .opt.hl{ background:color-mix(in srgb, var(--em-700) 9%, var(--card)); }
.combo-list .opt .sub{ display:block; font-size:.7rem; color:var(--muted); }
.combo-list .none{ padding:12px 15px; font-size:.82rem; color:var(--muted); }

/* سحب المشجرة للتجوال */
.tree-scroll{ cursor:grab; }
.tree-scroll.dragging{ cursor:grabbing; user-select:none; }
.tree-scroll.dragging .node{ pointer-events:none; }

/* تبديل طرفي نقطة الالتقاء */
.swap-btn{ align-self:center; }

/* شرائح فلترة العوائل في الإدارة */
.fchips{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:12px; }

/* ============ سجل النشاط ============ */
.log-row{ display:flex; align-items:flex-start; gap:12px; padding:12px 4px;
  border-bottom:1px dashed var(--line); animation:rise-in .3s both; }
.log-row:last-child{ border-bottom:none; }
.log-row.undone{ opacity:.55; }
.log-ico{ font-size:1.1rem; flex:0 0 auto; margin-top:2px; }
.log-body{ flex:1; min-width:0; font-size:.88rem; line-height:1.7; }
.log-diff{ font-size:.78rem; color:var(--ink-2); background:var(--cream-2);
  border-radius:9px; padding:3px 10px; display:inline-block; margin-top:3px; }
.log-time{ font-size:.72rem; color:var(--muted); margin-top:2px; }
.log-row .btn{ flex:0 0 auto; margin-top:4px; }

/* تحسين قراءة أسماء العقد على الجوال */
@media (max-width:680px){ .node .name{ font-size:1rem; } }

/* ============ تصحيحات الثيم الغامق للأسطح ذات الألوان الثابتة ============ */
:root[data-theme="dark"] .section-head h2,
:root[data-theme="dark"] .auth-card h1{ color:var(--gold-1); }
:root[data-theme="dark"] a{ color:#7dd3ab; }
:root[data-theme="dark"] .btn-ghost{ color:#e2ece5; border-color:#4d6757; }
:root[data-theme="dark"] .btn-ghost:hover{ background:#2e463a; border-color:var(--gold-2); }
:root[data-theme="dark"] .toggle{ color:var(--gold-1); border-color:#4d6757; }
:root[data-theme="dark"] .toggle:hover{ border-color:var(--gold); color:var(--gold); }
:root[data-theme="dark"] .path-col h4{ color:#6ec79f; }
:root[data-theme="dark"] .tbl td::before{ color:#6ec79f; }
:root[data-theme="dark"] .formCtx b{ color:var(--gold-1); }
:root[data-theme="dark"] select{ background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2391a497' stroke-width='1.6' fill='none'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] .sheet-backdrop,
:root[data-theme="dark"] .modal-backdrop{ background:rgba(0,0,0,.6); }
:root[data-theme="dark"] .btn-primary{ box-shadow:0 10px 24px -10px rgba(0,0,0,.85); }
:root[data-theme="dark"] .modal h3{ color:var(--gold-1); }
input::placeholder, textarea::placeholder{ color:var(--muted); opacity:.75; }
:root[data-theme="dark"] .node.is-path{ background:#2a4136; box-shadow:0 0 0 2px rgba(227,197,119,.22); }
:root[data-theme="dark"] .tree>li>.node-row>.node{ background:linear-gradient(160deg,#31493c,#283b30); }
:root[data-theme="dark"] .tree>li>.node-row>.node .name{ color:var(--gold-1); }
:root[data-theme="dark"] .result-card{ background:linear-gradient(160deg,#2b4034,#314226); border-color:var(--gold-2); }
:root[data-theme="dark"] .result-card .anc-name{ color:var(--gold-1); }
:root[data-theme="dark"] .badge-role.admin{ background:rgba(19,98,72,.28); color:var(--gold-1); }
:root[data-theme="dark"] .tree-scroll{
  background:radial-gradient(circle at 1px 1px, rgba(227,197,119,.06) 1px, transparent 0) 0 0/22px 22px, var(--card); }
:root[data-theme="dark"] .geo-bg{ filter:invert(1) brightness(1.3); opacity:.05; }
