/* «مرج» — هوية أولى: ضوء، أخضر ناعم، زجاج خفيف، مساحة تتنفّس. */
:root{
  --bg:#F5F8F5; --surface:#FFFFFF; --surface-2:#F0F5F1;
  --ink:#0F231C; --muted:#5B7067; --faint:#8AA096;
  --accent:#0E7C5A; --accent-2:#159A70; --accent-soft:#DCF0E5;
  --line:#E2EAE4; --warn:#B4791F; --warn-soft:#FBEFD8;
  --radius:18px; --shadow:0 1px 2px rgba(15,35,28,.04),0 12px 30px -18px rgba(15,35,28,.22);
  --font-body:'IBM Plex Sans Arabic',system-ui,sans-serif;
  --font-head:'Noto Kufi Arabic',serif;
  --font-mono:'JetBrains Mono',monospace;
}
*,*::before,*::after{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:var(--font-body); background:
    radial-gradient(900px 500px at 92% -12%, #E4F3EA 0%, transparent 62%),
    radial-gradient(700px 420px at 4% 108%, #EAF2FF 0%, transparent 60%), var(--bg);
  color:var(--ink); -webkit-font-smoothing:antialiased; font-size:15px; line-height:1.6;
  min-height:100vh;
}
h1,h2,h3{font-family:var(--font-head); margin:0; letter-spacing:-.01em; line-height:1.35}
h2{font-size:22px} h3{font-size:15px;font-weight:600}
p{margin:0}
button{font-family:inherit; font-size:inherit; color:inherit; cursor:pointer}
.mono{font-family:var(--font-mono); font-size:12.5px}
.ltr{direction:ltr; unicode-bidi:embed}
.ico{display:inline-block; vertical-align:-3px; stroke-width:1.75; flex:0 0 auto}

.shell{display:grid; grid-template-columns:252px minmax(0,1fr); min-height:100vh}

/* الشريط الجانبي */
.rail{
  position:sticky; top:0; height:100vh; padding:22px 16px; display:flex; flex-direction:column; gap:22px;
  background:rgba(255,255,255,.72); backdrop-filter:blur(14px); border-inline-end:1px solid var(--line);
}
.brand{display:flex; align-items:center; gap:11px; padding:0 6px}
.mark{
  width:39px; height:39px; border-radius:13px; display:grid; place-items:center; color:#fff;
  background:linear-gradient(145deg,var(--accent-2),var(--accent));
  box-shadow:0 8px 18px -8px rgba(14,124,90,.65);
}
.brand-text{display:flex; flex-direction:column; line-height:1.25}
.brand-text b{font-family:var(--font-head); font-size:16px; letter-spacing:.01em}
.brand-text small{color:var(--faint); font-size:11.5px}
.nav{display:flex; flex-direction:column; gap:4px}
.nav-btn{
  display:flex; align-items:center; gap:10px; padding:10px 12px; border:0; border-radius:12px;
  background:transparent; color:var(--muted); text-align:start; transition:background .18s ease,color .18s ease,transform .18s ease;
}
.nav-btn:hover{background:var(--surface-2); color:var(--ink); transform:translateX(-2px)}
.nav-btn.is-active{background:var(--accent-soft); color:var(--accent); font-weight:600}
.rail-foot{margin-top:auto; display:flex; flex-direction:column; gap:6px; padding:12px; border-radius:14px; background:var(--surface-2)}
.schema{font-family:var(--font-mono); font-size:11px; color:var(--faint); direction:ltr}

/* المنطقة الرئيسية */
.main{min-width:0; display:flex; flex-direction:column}
.topbar{
  position:sticky; top:0; z-index:20; display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding:14px 30px; background:rgba(245,248,245,.82); backdrop-filter:blur(12px); border-bottom:1px solid var(--line);
}
.crumb{display:flex; align-items:center; gap:7px; color:var(--faint); font-size:13px}
.crumb b{color:var(--ink); font-weight:600}
.tools{display:flex; align-items:center; gap:10px}
.search{
  display:flex; align-items:center; gap:8px; padding:0 12px; height:38px; min-width:270px;
  background:var(--surface); border:1px solid var(--line); border-radius:12px; color:var(--faint);
  transition:border-color .18s ease, box-shadow .18s ease;
}
.search:focus-within{border-color:var(--accent-2); box-shadow:0 0 0 3px rgba(21,154,112,.14)}
.search input{border:0; outline:0; background:transparent; font-family:inherit; font-size:13.5px; color:var(--ink); width:100%}
.btn{
  display:inline-flex; align-items:center; gap:7px; height:38px; padding:0 15px; border-radius:11px;
  border:1px solid transparent; font-size:13.5px; font-weight:600; transition:transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.btn:hover{transform:translateY(-1px)}
.btn-primary{background:linear-gradient(150deg,var(--accent-2),var(--accent)); color:#fff; box-shadow:0 8px 20px -12px rgba(14,124,90,.8)}
.btn-ghost{background:var(--surface); border-color:var(--line); color:var(--ink)}
.btn-ghost:hover{border-color:#CBDCD2; box-shadow:var(--shadow)}
.btn-quiet{background:transparent; color:var(--muted)}
.btn[disabled]{opacity:.45; cursor:not-allowed; transform:none}

.views{padding:26px 30px 46px}
.view{display:none}
.view.is-active{display:block; animation:fadeUp .45s cubic-bezier(.22,.8,.3,1) both}
@keyframes fadeUp{from{opacity:0; transform:translateY(10px)}to{opacity:1; transform:none}}

/* البطاقات العلوية */
.stats{display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:14px; margin-bottom:18px}
.stat{
  padding:16px 18px; border-radius:var(--radius); background:rgba(255,255,255,.78);
  border:1px solid rgba(226,234,228,.9); box-shadow:var(--shadow); backdrop-filter:blur(8px);
  display:flex; flex-direction:column; gap:2px; transition:transform .2s ease, box-shadow .2s ease;
}
.stat:hover{transform:translateY(-2px); box-shadow:0 18px 34px -22px rgba(15,35,28,.3)}
.stat-k{font-size:12px; color:var(--faint)}
.stat-v{font-family:var(--font-head); font-size:26px; font-weight:700; line-height:1.3}
.stat-s{font-size:11.5px; color:var(--muted)}

.split{display:grid; grid-template-columns:minmax(0,1.15fr) minmax(0,.85fr); gap:16px; align-items:start}
.panel{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--shadow); overflow:hidden;
}
.panel.wide{width:100%}
.panel-head{
  display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;
  padding:15px 18px; border-bottom:1px solid var(--line); background:linear-gradient(180deg,rgba(240,245,241,.65),transparent);
}
.panel-head h3{display:flex; align-items:center; gap:8px}
.hint{font-size:11.5px; color:var(--faint)}
.eyebrow{display:block; font-size:11px; letter-spacing:.08em; color:var(--accent); text-transform:uppercase; margin-bottom:6px}

/* الشجرة */
.tree-wrap{padding:10px 12px 16px; max-height:min(62vh,620px); overflow:auto}
.tree,.children{list-style:none; margin:0; padding:0}
.children{margin-inline-start:19px; border-inline-start:1px dashed #D7E4DC; padding-inline-start:8px}
.node-row{
  display:flex; align-items:center; gap:8px; padding:7px 9px; border-radius:10px; cursor:pointer;
  border:1px solid transparent; transition:background .16s ease, border-color .16s ease;
}
.node-row:hover{background:var(--surface-2)}
.node-row:focus-visible{outline:2px solid var(--accent-2); outline-offset:1px}
.is-selected>.node-row{background:linear-gradient(90deg,var(--accent-soft),rgba(220,240,229,.35)); border-color:#CDE7DA}
.is-selected>.node-row .node-label{color:var(--accent); font-weight:600}
.twisty{
  width:22px; height:22px; display:grid; place-items:center; border:0; border-radius:7px;
  background:var(--surface-2); color:var(--muted); transition:transform .2s ease, background .16s ease;
}
.twisty:hover{background:#E2EEE7; color:var(--accent)}
.twisty.is-open{transform:rotate(180deg)}
.dot{width:22px; height:22px; display:grid; place-items:center}
.dot::after{content:''; width:5px; height:5px; border-radius:50%; background:#B9CFC4}
.is-selected .dot::after{background:var(--accent)}
.num{font-family:var(--font-mono); font-size:11px; color:var(--faint); min-width:38px; direction:ltr}
.node-label{flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:13.8px}
.node-code{
  font-family:var(--font-mono); font-size:10.5px; color:#7C9488; background:var(--surface-2);
  padding:1px 6px; border-radius:6px; max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.node-count{
  font-family:var(--font-mono); font-size:11px; color:var(--muted); background:#fff;
  border:1px solid var(--line); border-radius:999px; padding:0 8px; min-width:30px; text-align:center;
}

/* لوحة التفاصيل */
.detail-panel{padding:0}
.detail-panel .panel-head{align-items:flex-start; flex-direction:column; gap:6px}
.detail-title{display:flex; align-items:center; gap:10px; flex-wrap:wrap}
.detail-note{font-size:13px; color:var(--muted); margin-top:4px}
.chip{
  display:inline-flex; align-items:center; gap:5px; font-size:11px; font-weight:600;
  padding:3px 9px; border-radius:999px; border:1px solid transparent;
}
.chip-ok{background:var(--accent-soft); color:var(--accent); border-color:#C4E4D3}
.chip-muted{background:var(--surface-2); color:var(--muted); border-color:var(--line)}
.chip-warn{background:var(--warn-soft); color:var(--warn); border-color:#F0DDB4}
.kv{margin:0; padding:8px 18px 4px}
.kv-row{display:flex; justify-content:space-between; gap:14px; padding:8px 0; border-bottom:1px solid #EFF4F0; font-size:13px}
.kv-row:last-child{border-bottom:0}
.kv dt{color:var(--faint)}
.kv dd{margin:0; color:var(--ink); text-align:end; max-width:62%; overflow:hidden; text-overflow:ellipsis}
.detail-actions{display:flex; flex-wrap:wrap; gap:8px; padding:14px 18px 18px}
.detail-actions .btn{height:34px; font-size:12.5px; padding:0 12px}
.add-row{display:flex; gap:8px; padding:0 18px 18px}
.add-row input{
  flex:1; height:36px; padding:0 12px; border:1px solid var(--line); border-radius:10px;
  font-family:inherit; font-size:13px; outline:0; background:var(--surface-2);
}
.add-row input:focus{border-color:var(--accent-2); background:#fff; box-shadow:0 0 0 3px rgba(21,154,112,.12)}
.add-row .btn{height:36px; font-size:12.5px}
.add-row[hidden]{display:none}

/* الجداول */
.table-wrap{overflow:auto}
.matrix{width:100%; border-collapse:collapse; font-size:13px}
.matrix th{
  text-align:start; font-weight:600; font-size:11.5px; color:var(--faint);
  padding:10px 16px; background:var(--surface-2); border-bottom:1px solid var(--line); white-space:nowrap;
}
.matrix td{padding:9px 16px; border-bottom:1px solid #F0F5F1}
.matrix tbody tr{transition:background .15s ease}
.matrix tbody tr:hover{background:#F7FBF8}
.matrix .num-col{width:64px; color:var(--faint)}
.leaf-name{font-weight:500}
.zero{color:#C3D3CB}
.matrix.compact th,.matrix.compact td{padding:8px 10px; font-size:12px}
.legend{display:flex; align-items:center; gap:10px; flex-wrap:wrap; padding:14px 18px; border-top:1px solid var(--line); background:#FBFDFB}

.grid-2{display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; align-items:start}
.foot-note{font-size:12px; color:var(--muted); padding:14px 18px; border-top:1px solid var(--line); line-height:1.7}
.import-bar{display:flex; gap:9px; flex-wrap:wrap; padding:14px 18px 6px}
.import-report{margin:0 18px 18px; padding:14px; border-radius:12px; background:var(--surface-2); border:1px solid var(--line); animation:fadeUp .3s ease both}
.rep-row{display:flex; justify-content:space-between; padding:4px 0; font-size:13px}
.rep-row .accent{color:var(--warn)}
.import-report p{margin:8px 0 0; font-size:12px; color:var(--muted)}

/* إشعار */
.toast{
  position:fixed; inset-block-end:24px; inset-inline-start:50%; transform:translate(50%,18px);
  background:var(--ink); color:#F3FAF6; padding:11px 18px; border-radius:12px; font-size:13px;
  box-shadow:0 18px 40px -20px rgba(15,35,28,.7); opacity:0; pointer-events:none;
  transition:opacity .22s ease, transform .22s ease; z-index:60; max-width:min(92vw,520px);
}
.toast.is-on{opacity:1; transform:translate(50%,0)}

@media (max-width:1120px){
  .stats{grid-template-columns:repeat(2,minmax(0,1fr))}
  .split,.grid-2{grid-template-columns:minmax(0,1fr)}
}
@media (max-width:860px){
  .shell{grid-template-columns:1fr}
  .rail{position:static; height:auto; flex-direction:row; align-items:center; gap:14px; flex-wrap:wrap; border-inline-start:0; border-bottom:1px solid var(--line)}
  .nav{flex-direction:row; flex-wrap:wrap}
  .rail-foot{display:none}
  .topbar{padding:12px 16px; flex-wrap:wrap}
  .search{min-width:0; flex:1}
  .views{padding:18px 16px 34px}
}
@media (max-width:520px){
  .stats{grid-template-columns:1fr 1fr; gap:10px}
  .stat-v{font-size:22px}
  .node-code{display:none}
}
@media (prefers-reduced-motion:reduce){*{animation:none!important; transition:none!important}}
