/* ═══ الموارد البشرية — نظام تصميم متناسق مع منصّة مسار ═══ */
:root {
  --bg: #f6f7fb; --surface: #fff; --surface-2: #f9fafd;
  --border: #e7e9f2; --border-strong: #d6d9e6;
  --text: #14162b; --text-soft: #3c4162; --muted: #7a809b; --faint: #9aa1b8;
  --primary: #0d9488; --primary-600: #0f766e; --primary-700: #115e59; --primary-050: #e6f5f3;
  --brand: #4f46e5; --brand-050: #eef0fe;
  --green: #16a34a; --green-050: #e9f8ef; --red: #e11d48; --red-050: #fdecef;
  --amber: #d97706; --amber-050: #fdf2e3; --sky: #0284c7; --sky-050: #e6f3fb;
  --radius: 18px; --radius-sm: 12px; --radius-xs: 9px;
  --shadow-xs: 0 1px 2px rgba(20,22,43,.05);
  --shadow: 0 2px 6px rgba(20,22,43,.05), 0 12px 28px rgba(20,22,43,.06);
  --shadow-lg: 0 18px 48px rgba(20,22,43,.16);
  --ring: 0 0 0 4px var(--primary-050);
  --sidebar: linear-gradient(180deg, #0f2e2b, #123a35 60%, #0d2a27);
}
* { box-sizing: border-box; }
html { font-size: clamp(14px, 1.5vw, 15.5px); }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh;
  font-family: "Readex Pro","Inter","Segoe UI",Tahoma,system-ui,sans-serif; line-height: 1.7; -webkit-font-smoothing: antialiased; }
html[dir="ltr"] body { font-family: "Inter","Readex Pro",system-ui,sans-serif; line-height: 1.6; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); } small.muted { font-size: .82rem; }
.mono { font-family: "Inter", monospace; font-size: .84rem; }

/* ── الهيكل ── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 250px; flex: none; display: flex; flex-direction: column; background: var(--sidebar); color: #eafaf7;
  position: sticky; top: 0; height: 100vh; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 1.08rem; }
.brand__logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), #34d399); flex: none; position: relative; }
.brand__logo::after { content: "HR"; position: absolute; inset: 0; display: grid; place-items: center; font: 700 .62rem "Inter"; color: #fff; }
.nav { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 3px; }
.navitem { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 0; background: transparent; color: rgba(255,255,255,.82);
  border-radius: 10px; padding: 10px 12px; font: inherit; font-size: .92rem; font-weight: 500; transition: background .12s, color .12s; }
.navitem:hover { background: rgba(255,255,255,.08); color: #fff; }
.navitem.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.navitem .ico { width: 20px; display: inline-flex; }
.nav__sep { font-size: .68rem; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: .06em; font-weight: 800; padding: 12px 12px 4px; }
.sidebar__foot { border-top: 1px solid rgba(255,255,255,.08); padding: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 clamp(14px,3vw,24px); height: 58px; flex: none; background: var(--surface); border-bottom: 1px solid var(--border); }
.crumb { font-size: 1.05rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami { display: flex; align-items: center; gap: 9px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), #34d399); color: #fff; font-weight: 700; flex: none; }
.content { flex: 1; overflow-y: auto; overflow-x: hidden; padding: clamp(16px,3vw,30px); }
.burger { display: none; }
.iconbtn { background: transparent; border: 1px solid var(--border); color: var(--text-soft); border-radius: 9px; width: 36px; height: 36px; font-size: 1.1rem; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(10,12,24,.5); z-index: 39; }
.scrim.show { display: block; }

/* ── مكوّنات ── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.3rem,3vw,1.7rem); } .page-head p { margin: 5px 0 0; color: var(--muted); max-width: 62ch; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: .92rem; font-weight: 600; transition: transform .08s, background .15s, border-color .15s; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn--primary:hover { background: var(--primary-600); }
.btn--ghost { background: transparent; border-color: var(--border-strong); color: var(--text-soft); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--ok { background: var(--green); color: #fff; } .btn--danger { background: var(--red); color: #fff; }
.btn--sm { padding: 7px 12px; font-size: .84rem; } .btn--block { width: 100%; }
.btn[disabled] { opacity: .6; pointer-events: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); padding: 20px; }
.grid { display: grid; gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; }

/* بطاقات المؤشّرات */
.kpi { background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--accent, var(--primary)); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-xs); }
.kpi b { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; display: block; }
.kpi span { color: var(--muted); font-size: .9rem; }

/* جداول */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; min-width: 560px; }
.tbl th, .tbl td { text-align: start; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: .9rem; white-space: nowrap; }
.tbl th { background: var(--surface-2); font-size: .78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; } .tbl tbody tr.click:hover { background: var(--primary-050); }

.badge { font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; display: inline-block; }
.b-green { background: var(--green-050); color: var(--green); } .b-red { background: var(--red-050); color: var(--red); }
.b-amber { background: var(--amber-050); color: var(--amber); } .b-sky { background: var(--sky-050); color: var(--sky); }
.b-gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill { font-size: .72rem; padding: 2px 9px; border-radius: 6px; background: var(--brand-050); color: var(--brand); font-weight: 600; }

/* نماذج */
.field { display: grid; gap: 6px; font-size: .88rem; font-weight: 500; color: var(--text-soft); }
.field input, .field select, .field textarea { padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit; font-size: .95rem; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span2 { grid-column: 1 / -1; }
.formfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 26px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm); }
.section-title { font-size: 1.1rem; margin: 26px 0 14px; }
.avatar-lg { width: 74px; height: 74px; border-radius: 20px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), #34d399); color: #fff; font-weight: 700; font-size: 1.7rem; flex: none; }

.list { display: grid; gap: 10px; }
.rowcard { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 16px; box-shadow: var(--shadow-xs); }
.rowcard .grow { flex: 1; min-width: 0; }
.rowcard .t { font-weight: 600; }
.rowcard .m { font-size: .82rem; color: var(--muted); }

/* بار تقدّم الرصيد */
.bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent, var(--primary)); }

/* إشعارات + حوار */
.toasts { position: fixed; inset-block-end: 20px; inset-inline-start: 20px; z-index: 90; display: grid; gap: 10px; }
.toast { background: var(--text); color: var(--surface); padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: .9rem; font-weight: 500; max-width: 440px; animation: tin .3s ease; }
.toast--err { background: var(--red); color: #fff; } .toast--ok { background: #0f5e54; color: #fff; }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }
.modal-root { position: fixed; inset: 0; z-index: 100; background: rgba(10,12,24,.5); display: grid; place-items: center; padding: 20px; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-bottom: 14px; }

/* ── الهيكل التنظيمي (org chart) — ثلاثة أنماط عرض ── */
.oc-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.oc-tools__sp { flex: 1 1 auto; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; color: var(--text-soft); font: inherit; font-size: .82rem; padding: 6px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: background .14s, color .14s; }
.segmented button .ico { font-size: .95em; opacity: .8; }
.segmented button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-xs); font-weight: 600; }

.orgchart-wrap { overflow: auto; padding: 10px 6px 26px; border: 1px solid var(--border); border-radius: var(--radius); background:
  radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 22px 22px, var(--surface); }
.orgchart ul { list-style: none; margin: 0; }
.orgchart li { list-style: none; position: relative; }

/* العقدة (مشتركة) */
.orgnode { display: inline-flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  border-top: 3px solid var(--rt, var(--primary)); border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow-xs);
  cursor: pointer; transition: box-shadow .16s, transform .08s; position: relative; text-align: start; min-width: 190px; }
.orgnode:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.orgnode__av { width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; background: var(--rt, var(--primary)); }
.orgnode__t { min-width: 0; } .orgnode__t b { display: block; font-size: .92rem; white-space: nowrap; } .orgnode__t small { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.orgnode__toggle { flex: none; width: 22px; height: 22px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft); font-size: .72rem; font-weight: 700; cursor: pointer; }
.orgnode__toggle:hover { border-color: var(--primary); color: var(--primary); }
.orgnode__toggle--leaf { border-color: transparent; background: transparent; pointer-events: none; }
.orgnode__mgr { flex: none; width: 22px; height: 22px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: .8rem; cursor: pointer; }
.orgnode__mgr:hover { border-color: var(--primary); color: var(--primary); }
.orgchart li.collapsed > ul { display: none; }
.orgchart li.collapsed > .orgnode { border-style: dashed; }
.orgchart li.collapsed > .orgnode .orgnode__toggle { background: var(--primary-050); color: var(--primary); border-color: var(--primary); }

/* — نمط 1: شجرة عمودية (من الأعلى للأسفل) — */
.orgchart.v { display: inline-block; min-width: 100%; text-align: center; padding: 10px 20px; }
.orgchart.v ul { display: flex; justify-content: center; gap: 0; padding-top: 22px; position: relative; }
.orgchart.v li { padding: 22px 10px 0; text-align: center; }
.orgchart.v li::before, .orgchart.v li::after { content: ''; position: absolute; top: 0; width: 50%; height: 22px; border-top: 2px solid var(--border-strong); }
.orgchart.v li::before { inset-inline-end: 50%; }
.orgchart.v li::after { inset-inline-start: 50%; border-inline-start: 2px solid var(--border-strong); }
.orgchart.v li:only-child::before, .orgchart.v li:only-child::after { display: none; }
.orgchart.v li:first-child::before, .orgchart.v li:last-child::after { border-top: 0; }
.orgchart.v li:last-child::before { border-inline-end: 2px solid var(--border-strong); border-start-end-radius: 8px; }
.orgchart.v li:first-child::after { border-inline-start: 2px solid var(--border-strong); border-start-start-radius: 8px; }
.orgchart.v ul ul::before { content: ''; position: absolute; top: 0; inset-inline-start: 50%; height: 22px; border-inline-start: 2px solid var(--border-strong); }
.orgchart.v > ul { padding-top: 0; }
.orgchart.v > ul > li:only-child::after, .orgchart.v > ul::before { display: none; }

/* — نمط 2: شجرة أفقية (من اليمين لليسار) — */
.orgchart.h { display: inline-block; min-width: 100%; text-align: start; padding: 16px 20px; }
.orgchart.h ul { display: flex; flex-direction: column; justify-content: center; gap: 0; padding-inline-start: 46px; position: relative; }
.orgchart.h > ul { padding-inline-start: 0; }
.orgchart.h li { display: flex; flex-direction: row; align-items: center; padding: 7px 0; }
.orgchart.h li > .orgnode { flex: none; }
.orgchart.h li > ul::before { content: ''; position: absolute; top: 50%; inset-inline-start: 0; width: 23px; border-top: 2px solid var(--border-strong); }
.orgchart.h ul > li::before { content: ''; position: absolute; top: 50%; inset-inline-start: -23px; width: 23px; border-top: 2px solid var(--border-strong); }
.orgchart.h ul > li::after { content: ''; position: absolute; inset-inline-start: -23px; top: 0; bottom: 0; border-inline-start: 2px solid var(--border-strong); }
.orgchart.h ul > li:first-child::after { top: 50%; }
.orgchart.h ul > li:last-child::after { bottom: 50%; }
.orgchart.h ul > li:only-child::after { display: none; }
.orgchart.h > ul > li::before, .orgchart.h > ul > li::after { display: none; }

/* — نمط 3: قائمة متداخلة (مخطّط هرمي) — */
.orgchart.list { display: block; text-align: start; padding: 6px 4px; }
.orgchart.list ul { display: block; margin-inline-start: 19px; padding-inline-start: 16px; border-inline-start: 1.5px solid var(--border); }
.orgchart.list > ul { margin-inline-start: 0; padding-inline-start: 0; border: 0; }
.orgchart.list li { display: block; padding: 3px 0; }
.orgchart.list .orgnode { display: flex; width: 100%; min-width: 0; border: 0; border-radius: 10px; box-shadow: none; background: transparent; padding: 7px 10px; }
.orgchart.list .orgnode::before { content: ''; position: absolute; inset-inline-start: 0; top: 11px; bottom: 11px; width: 3px; border-radius: 3px; background: var(--rt, var(--primary)); }
.orgchart.list .orgnode:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.orgchart.list .orgnode__av { width: 30px; height: 30px; border-radius: 9px; font-size: .85rem; }

/* ── أجهزة البصمة ── */
.hintbox { display: flex; gap: 12px; background: var(--primary-050, #eef2ff); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: .86rem; line-height: 1.75; }
.hintbox__i { font-size: 1.35rem; line-height: 1; }
.hintbox code { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-family: ui-monospace, "Cascadia Code", monospace; font-size: .85em; }
.hintbox code.copy { cursor: pointer; } .hintbox code.copy:hover { border-color: var(--primary); color: var(--primary); }
.devcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.devcard__h { display: flex; align-items: center; gap: 10px; }
.devcard__sub { font-size: .78rem; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.devcard__meta { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 14px; }
.devcard__meta > div { display: flex; flex-direction: column; min-width: 0; }
.devcard__meta span { font-size: .72rem; color: var(--muted); }
.devcard__meta b { font-size: .86rem; overflow: hidden; text-overflow: ellipsis; }
.devcard__foot { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot--on { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.dot--off { background: #94a3b8; box-shadow: 0 0 0 3px rgba(148,163,184,.15); }
.btn--xs { padding: 2px 8px; font-size: .72rem; border-radius: 7px; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-soft); }
.badge.b-sky { background: rgba(2,132,199,.12); color: #0369a1; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: grid; gap: 8px; background: var(--surface-2); }
.fieldset__t { font-weight: 600; font-size: .85rem; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: middle; border: 1px solid rgba(0,0,0,.12); }
.input { padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text, inherit); font: inherit; font-size: .9rem; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-050, rgba(79,70,229,.12)); }
.input--sm { padding: 6px 10px; font-size: .85rem; }
/* الخطّ الزمني لمسار الاعتماد */
.timeline { display: grid; gap: 0; margin-top: 8px; }
.tl__item { display: flex; gap: 12px; padding: 0 0 16px; position: relative; }
.tl__item::before { content: ''; position: absolute; inset-inline-start: 6px; top: 15px; bottom: -2px; width: 2px; background: var(--border); }
.tl__item:last-child::before { display: none; }
.tl__dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border-strong); flex: none; margin-top: 3px; z-index: 1; box-shadow: 0 0 0 3px var(--surface); }
.tl__item--approved .tl__dot { background: #16a34a; }
.tl__item--rejected .tl__dot { background: #e11d48; }
.tl__item--pending .tl__dot { background: #d97706; }
.tl__item--skipped .tl__dot { background: #94a3b8; }

/* ── وضع التضمين داخل «مسار» ── */
html.embed .sidebar, html.embed .topbar { display: none !important; }
html.embed .main { height: auto !important; }
html.embed .content { height: auto !important; overflow: visible !important; padding: clamp(14px,3vw,26px) !important; }
html.embed, html.embed body { background: var(--bg) !important; }
/* ثيم مسار الموحّد (نيلي) داخل التضمين */
html.embed { --primary: #4f46e5; --primary-600: #4338ca; --primary-700: #3730a3; --primary-050: #eef0fe; }

@media (max-width: 900px) {
  .sidebar { position: fixed; inset-inline-end: 0; top: 0; height: 100vh; width: min(280px,84vw); transform: translateX(100%); transition: transform .22s; box-shadow: var(--shadow-lg); }
  html[dir="ltr"] .sidebar { inset-inline-start: 0; inset-inline-end: auto; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .burger { display: inline-flex; align-items: center; justify-content: center; }
}
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } .whoami b { display: none; } }
