/* ===================================================================
   منظومة الموارد البشرية — نظام التصميم
   HR System — design system
   =================================================================== */
:root {
  color-scheme: light;
  --brand:          #0f766e;
  --brand-600:      #0d6560;
  --brand-700:      #115e59;
  --brand-50:       #eefaf8;
  --brand-100:      #d5f1ee;

  --surface-0:      #f4f7f8;
  --surface-1:      #ffffff;
  --surface-2:      #f8fafb;
  --surface-3:      #eef2f4;
  --border:         #dde5e9;
  --border-strong:  #c3d0d6;

  --text-primary:   #0f1b20;
  --text-secondary: #4a5b63;
  --text-muted:     #7b8c95;
  --text-invert:    #ffffff;

  --good:           #15803d;
  --good-bg:        #e8f6ed;
  --warning:        #b45309;
  --warning-bg:     #fdf3e3;
  --serious:        #c2410c;
  --serious-bg:     #fdeee6;
  --critical:       #b91c1c;
  --critical-bg:    #fdeaea;
  --info:           #1d4ed8;
  --info-bg:        #e9effd;

  /* سلاسل الرسوم البيانية — palette validated for CVD + contrast */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 15px;
  --shadow-1:  0 1px 2px rgba(15, 27, 32, .05), 0 1px 3px rgba(15, 27, 32, .05);
  --shadow-2:  0 4px 14px rgba(15, 27, 32, .09);
  --shadow-3:  0 12px 38px rgba(15, 27, 32, .17);
  --sidebar-w: 290px;
  --header-h:  60px;
  --font: "Segoe UI", "Noto Kufi Arabic", "Tahoma", system-ui, -apple-system, Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand:          #2dd4bf;
  --brand-600:      #14b8a6;
  --brand-700:      #0d9488;
  --brand-50:       #11292b;
  --brand-100:      #15373a;

  --surface-0:      #0d1316;
  --surface-1:      #151e22;
  --surface-2:      #1b262b;
  --surface-3:      #233136;
  --border:         #2c3b42;
  --border-strong:  #3d5058;

  --text-primary:   #eef4f6;
  --text-secondary: #a9bcc4;
  --text-muted:     #7c9099;
  --text-invert:    #0d1316;

  --good: #4ade80;    --good-bg:     #12301f;
  --warning: #fbbf24; --warning-bg:  #35270c;
  --serious: #fb923c; --serious-bg:  #35200f;
  --critical: #f87171;--critical-bg: #351616;
  --info: #93b4fd;    --info-bg:     #16233d;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --shadow-1: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-3: 0 12px 38px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--surface-0);
  color: var(--text-primary); font-size: 17.5px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body[dir="ltr"] { font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.35; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid var(--surface-0); }

/* ---------- شاشة الدخول ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 15% -5%, rgba(15, 118, 110, .16), transparent 60%),
    radial-gradient(800px 480px at 90% 105%, rgba(42, 120, 214, .13), transparent 60%),
    var(--surface-0);
}
.login-card {
  width: 100%; max-width: 408px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3); padding: 34px 30px;
}
.login-logo {
  width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-700));
  color: #fff; font-size: 32.5px; margin: 0 auto 16px; box-shadow: var(--shadow-2);
}
.login-card h1 { font-size: 26.5px; text-align: center; margin-bottom: 5px; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 16.5px; margin-bottom: 24px; }
.demo-creds {
  margin-top: 20px; padding: 13px 15px; background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-size: 15.5px;
}
.demo-creds b { color: var(--brand); }
.demo-creds .row { display: flex; justify-content: space-between; gap: 10px; padding: 2.5px 0; }

/* ---------- الهيكل ---------- */
#app { display: none; }
#app.ready { display: block; }
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
body[dir="ltr"] .layout { grid-template-columns: var(--sidebar-w) 1fr; }

.sidebar {
  background: var(--surface-1); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: hidden;
}
.brand {
  display: flex; align-items: center; gap: 11px; padding: 15px 17px;
  border-bottom: 1px solid var(--border); min-height: var(--header-h);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 auto;
  background: linear-gradient(145deg, var(--brand), var(--brand-700)); color: #fff; font-size: 21.5px;
}
.brand-text { min-width: 0; }
.brand-text .n { font-weight: 800; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text .r { font-size: 14.5px; color: var(--text-muted); }

.nav { flex: 1; overflow-y: auto; padding: 10px 9px 18px; }
.nav-group { margin-bottom: 4px; }
.nav-group > .label {
  font-size: 13px; font-weight: 700; color: var(--text-muted); letter-spacing: .07em;
  padding: 13px 9px 5px; text-transform: uppercase;
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8.5px 11px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 17px; font-weight: 500; margin-bottom: 1px;
  transition: background .13s, color .13s;
}
.nav a:hover { background: var(--surface-3); color: var(--text-primary); }
.nav a.active { background: var(--brand-50); color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .nav a.active { background: var(--brand-100); }
.nav a .ico { width: 19px; text-align: center; font-size: 19px; flex: 0 0 auto; }
.nav a .badge-n {
  margin-inline-start: auto; background: var(--critical); color: #fff; font-size: 13px;
  font-weight: 700; min-width: 19px; height: 19px; border-radius: 10px; display: grid;
  place-items: center; padding: 0 5px;
}

.main { min-width: 0; display: flex; flex-direction: column; }
.header {
  height: var(--header-h); background: var(--surface-1); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px; position: sticky; top: 0; z-index: 30;
}
.header h2 { font-size: 20.5px; }
.header .spacer { flex: 1; }
.icon-btn {
  width: 35px; height: 35px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-secondary); cursor: pointer; display: grid;
  place-items: center; font-size: 19px; transition: .13s; flex: 0 0 auto; position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text-primary); }
.icon-btn .dot {
  position: absolute; top: 5px; inset-inline-end: 5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--critical); border: 1.5px solid var(--surface-1);
}
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 11px 5px 5px; border-radius: 30px;
  border: 1px solid var(--border); background: var(--surface-1); cursor: pointer;
}
.user-chip:hover { background: var(--surface-3); }
.avatar {
  width: 27px; height: 27px; border-radius: 50%; background: var(--brand-100); color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: 0 0 auto;
}
.user-chip .nm { font-size: 15.5px; font-weight: 600; }
.user-chip .rl { font-size: 13px; color: var(--text-muted); }

.content { padding: 20px; flex: 1; min-width: 0; }
.menu-toggle { display: none; }

/* ---------- بطاقات ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-1); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h3 { font-size: 18px; }
.card-head .spacer { flex: 1; }
.card-head .sub { font-size: 15px; color: var(--text-muted); font-weight: 400; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span4 { grid-column: span 4; }

/* ---------- بطاقات الأرقام ---------- */
.stat {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: var(--shadow-1); position: relative; overflow: hidden;
}
.stat .lbl { font-size: 15px; color: var(--text-secondary); font-weight: 600; margin-bottom: 7px; }
.stat .val { font-size: 34px; font-weight: 800; line-height: 1.12; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .val .unit { font-size: 16.5px; font-weight: 600; color: var(--text-muted); margin-inline-start: 3px; }
.stat .meta { font-size: 14.5px; color: var(--text-muted); margin-top: 5px; }
.stat .ico-bg {
  position: absolute; inset-inline-end: 12px; top: 12px; font-size: 25px; opacity: .17;
}
.stat.accent { border-inline-start: 3px solid var(--brand); }
.stat.ok      { border-inline-start: 3px solid var(--good); }
.stat.warn    { border-inline-start: 3px solid var(--warning); }
.stat.bad     { border-inline-start: 3px solid var(--critical); }
.stat.info    { border-inline-start: 3px solid var(--info); }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); font-size: 16.5px; font-weight: 600; cursor: pointer;
  transition: .13s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
:root[data-theme="dark"] .btn.primary { color: var(--text-invert); }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 5px 10px; font-size: 15px; }
.btn.xs { padding: 3px 8px; font-size: 14.5px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- حقول ---------- */
.field { margin-bottom: 13px; }
.field > label, .lbl-t {
  display: block; font-size: 15.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px;
}
.field .req { color: var(--critical); }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password],
input[type=email], input[type=search], input[type=month], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-primary); transition: .13s; font-size: 17px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50);
}
textarea { resize: vertical; min-height: 78px; line-height: 1.7; }
select { cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; font-size: 16.5px; cursor: pointer; }
.hint { font-size: 14.5px; color: var(--text-muted); margin-top: 4px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px; margin: 0 0 15px; }
legend { font-size: 15.5px; font-weight: 700; color: var(--brand); padding: 0 7px; }

/* ---------- شريط الأدوات والفلاتر ---------- */
.toolbar {
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 14px;
}
.toolbar .search { position: relative; flex: 1; min-width: 190px; max-width: 340px; }
.toolbar .search input { padding-inline-start: 33px; }
.toolbar .search .i {
  position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 16.5px; pointer-events: none;
}
.filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 11px;
  padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 14px;
}
.filters > div { min-width: 0; }
.filters input, .filters select { width: 100%; min-width: 0; }
.filters .range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filters .wide { grid-column: span 2; }
@media (max-width: 860px) { .filters .wide { grid-column: span 1; } }
.filters label.check { white-space: nowrap; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3.5px 10px; border-radius: 30px;
  background: var(--brand-50); color: var(--brand); font-size: 15px; font-weight: 600;
  border: 1px solid var(--brand-100);
}
.chip button { border: 0; background: transparent; cursor: pointer; color: inherit; padding: 0 1px; font-size: 17.5px; line-height: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  border: 0; background: var(--surface-1); padding: 6.5px 12px; cursor: pointer; font-size: 15.5px;
  font-weight: 600; color: var(--text-secondary); border-inline-end: 1px solid var(--border);
}
.seg button:last-child { border-inline-end: 0; }
.seg button.on { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .seg button.on { color: var(--text-invert); }

/* ---------- جداول ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 16.5px; }
table.data th {
  background: var(--surface-2); padding: 9px 11px; text-align: start; font-weight: 700; font-size: 15px;
  color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--brand); }
table.data th .arr { opacity: .4; font-size: 12.5px; margin-inline-start: 3px; }
table.data th .arr.on { opacity: 1; color: var(--brand); }
table.data td { padding: 8.5px 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td { background: var(--surface-2); font-weight: 800; border-top: 2px solid var(--border-strong); }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.data td.mid, table.data th.mid { text-align: center; }
table.data .group-row td {
  background: var(--brand-50); font-weight: 800; color: var(--brand); font-size: 15.5px;
}
table.compact td, table.compact th { padding: 5.5px 8px; font-size: 15.5px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2.5px 9px; border-radius: 20px;
  font-size: 14.5px; font-weight: 700; white-space: nowrap;
}
.badge.ok    { background: var(--good-bg);     color: var(--good); }
.badge.warn  { background: var(--warning-bg);  color: var(--warning); }
.badge.bad   { background: var(--critical-bg); color: var(--critical); }
.badge.info  { background: var(--info-bg);     color: var(--info); }
.badge.mute  { background: var(--surface-3);   color: var(--text-secondary); }
.badge.sr    { background: var(--serious-bg);  color: var(--serious); }

.pager { display: flex; align-items: center; gap: 9px; padding: 11px 15px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager .info { font-size: 15.5px; color: var(--text-muted); margin-inline-end: auto; }

.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty .i { font-size: 47.5px; opacity: .3; margin-bottom: 11px; }
.empty .t { font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; font-size: 17.5px; }
.empty .s { font-size: 15.5px; }

/* ---------- نوافذ منبثقة ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(8, 18, 22, .55); backdrop-filter: blur(3px);
  z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 36px 16px; overflow-y: auto; animation: fade .14s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface-1); border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  width: 100%; max-width: 620px; animation: pop .16s; border: 1px solid var(--border);
}
@keyframes pop { from { transform: translateY(-11px) scale(.985); opacity: 0; } }
.modal.lg { max-width: 940px; }
.modal.xl { max-width: 1220px; }
.modal.sm { max-width: 430px; }
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 15px 19px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 20px; flex: 1; }
.modal-body { padding: 19px; max-height: calc(100vh - 230px); overflow-y: auto; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end; padding: 14px 19px; border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.toasts { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-3); padding: 11px 15px; min-width: 258px; max-width: 390px;
  display: flex; gap: 10px; align-items: flex-start; font-size: 16.5px; animation: slide .18s;
  border-inline-start: 3px solid var(--brand);
}
@keyframes slide { from { transform: translateY(14px); opacity: 0; } }
.toast.ok  { border-inline-start-color: var(--good); }
.toast.err { border-inline-start-color: var(--critical); }
.toast .i { font-size: 19px; flex: 0 0 auto; }
.toast .m { flex: 1; }

/* ---------- الرسوم البيانية ---------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--text-secondary); }
.chart .axis-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; opacity: .65; }
.chart .tick { font-size: 13px; fill: var(--text-muted); }
.chart .val-label { font-size: 14px; font-weight: 700; fill: var(--text-primary); }
.chart .bar { transition: opacity .12s; }
.chart .bar:hover { opacity: .82; }
.chart .dot { stroke: var(--surface-1); stroke-width: 2; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 15px; color: var(--text-secondary); padding: 2px 0 10px; }
.legend .it { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.chart-tip {
  position: fixed; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-3); padding: 8px 11px; font-size: 15px;
  pointer-events: none; z-index: 300; min-width: 118px; opacity: 0; transition: opacity .1s;
}
.chart-tip.on { opacity: 1; }
.chart-tip .tt { font-weight: 700; margin-bottom: 4px; font-size: 15.5px; }
.chart-tip .rw { display: flex; align-items: center; gap: 7px; padding: 1.5px 0; }
.chart-tip .rw .sw { width: 9px; height: 9px; border-radius: 2px; }
.chart-tip .rw .v { margin-inline-start: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-toggle { display: flex; gap: 6px; }

.meter { height: 9px; border-radius: 5px; background: var(--surface-3); overflow: hidden; display: flex; gap: 2px; }
.meter > span { height: 100%; display: block; }
.bar-mini { height: 7px; border-radius: 4px; background: var(--surface-3); overflow: hidden; min-width: 44px; }
.bar-mini > span { display: block; height: 100%; border-radius: 4px; background: var(--brand); }

/* ---------- كشف الحضور الشهري ---------- */
.sheet-wrap { overflow: auto; max-height: 72vh; }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
table.sheet th, table.sheet td { border: 1px solid var(--border); padding: 3px 5px; white-space: nowrap; }
table.sheet thead th { background: var(--surface-2); position: sticky; top: 0; z-index: 3; font-size: 14px; }
table.sheet .nm {
  position: sticky; inset-inline-start: 0; background: var(--surface-1); z-index: 2;
  text-align: start; min-width: 168px; max-width: 168px; overflow: hidden; text-overflow: ellipsis;
}
table.sheet thead .nm { z-index: 4; background: var(--surface-2); }
table.sheet td.d { text-align: center; width: 27px; min-width: 27px; cursor: pointer; font-weight: 700; }
table.sheet td.d.we { background: var(--surface-3); color: var(--text-muted); }
table.sheet td.d.pr { background: var(--good-bg);     color: var(--good); }
table.sheet td.d.ab { background: var(--critical-bg); color: var(--critical); }
table.sheet td.d.lv { background: var(--info-bg);     color: var(--info); }
table.sheet td.d.ho { background: var(--brand-50);    color: var(--brand); }
table.sheet td.d.hf { background: var(--warning-bg);  color: var(--warning); }
table.sheet td.d.mp { background: var(--serious-bg);  color: var(--serious); }
table.sheet td.t { text-align: center; font-weight: 700; background: var(--surface-2); }

/* ---------- ملف الموظف ---------- */
.profile-head {
  display: flex; gap: 17px; align-items: center; padding: 19px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; flex-wrap: wrap;
}
.profile-head .ph {
  width: 70px; height: 70px; border-radius: 19px; background: var(--brand-100); color: var(--brand);
  display: grid; place-items: center; font-size: 31.5px; font-weight: 800; flex: 0 0 auto;
}
.profile-head .info { flex: 1; min-width: 190px; }
.profile-head .info h2 { font-size: 25px; margin-bottom: 3px; }
.profile-head .info .m { color: var(--text-secondary); font-size: 16.5px; }
.profile-head .info .m span + span::before { content: "•"; margin: 0 7px; color: var(--border-strong); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 15px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 9px 15px; cursor: pointer; font-size: 17px;
  font-weight: 600; color: var(--text-secondary); border-bottom: 2.5px solid transparent;
  white-space: nowrap; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1px 20px; }
.kv .r { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 16.5px; }
.kv .r .k { color: var(--text-muted); min-width: 118px; flex: 0 0 auto; font-size: 15.5px; }
.kv .r .v { font-weight: 600; word-break: break-word; }

/* ---------- الهيكل التنظيمي ---------- */
.tree { font-size: 17px; }
.tree ul { list-style: none; margin: 0; padding-inline-start: 21px; }
.tree > ul { padding-inline-start: 0; }
.tree li { position: relative; padding: 3px 0; }
.tree li::before {
  content: ""; position: absolute; inset-inline-start: -12px; top: 0; bottom: 0;
  border-inline-start: 1px solid var(--border);
}
.tree > ul > li::before { display: none; }
.tree .node {
  display: inline-flex; align-items: center; gap: 9px; padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); margin: 1px 0;
}
.tree .node:hover { border-color: var(--brand); background: var(--brand-50); }
.tree .node .n { font-weight: 700; }
.tree .node .c { font-size: 14.5px; color: var(--text-muted); }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 13px; }
.form-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; background: var(--surface-1);
  cursor: pointer; transition: .14s; display: flex; flex-direction: column; gap: 7px; box-shadow: var(--shadow-1);
}
.form-card:hover { border-color: var(--brand); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.form-card .ic { font-size: 25px; }
.form-card .t { font-weight: 700; font-size: 17px; }
.form-card .d { font-size: 15px; color: var(--text-muted); line-height: 1.55; flex: 1; }
.form-card .f { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text-muted); }
.doc-preview {
  background: #fff; color: #111827; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 22px; direction: rtl; max-height: 62vh; overflow-y: auto;
}
.doc-preview table { width: 100%; border-collapse: collapse; margin: 9px 0 13px; }
.doc-preview table th, .doc-preview table td { border: 1px solid #cbd5e1; padding: 6px 9px; font-size: 15.5px; }
.doc-preview table.kv th { background: #f1f5f9; width: 16%; text-align: right; }
.doc-preview table.grid th { background: #0f766e; color: #fff; }
.doc-preview h1 { font-size: 24px; }
.doc-preview h3 { font-size: 17.5px; color: #0f766e; margin: 15px 0 6px; border-right: 4px solid #0f766e; padding-right: 8px; }
.doc-preview .doc-head { text-align: center; border-bottom: 2.5px solid #0f766e; padding-bottom: 11px; margin-bottom: 17px; }
.doc-preview .doc-head .org { font-weight: 800; color: #0f766e; }
.doc-preview .doc-head .meta { font-size: 14.5px; color: #6b7280; }
.doc-preview .box { border: 1px solid #cbd5e1; border-radius: 5px; padding: 10px; min-height: 52px; background: #fcfdfe; white-space: pre-wrap; }
.doc-preview .note { font-size: 14.5px; color: #4b5563; background: #f8fafc; border-right: 3px solid #94a3b8; padding: 8px 10px; margin: 12px 0; }
.doc-preview .blank { color: #9ca3af; }
.doc-preview td.sig { height: 80px; vertical-align: top; font-size: 14.5px; color: #4b5563; }
.doc-preview ol.terms li { margin-bottom: 6px; }

.code-area {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace; font-size: 15.5px;
  line-height: 1.7; direction: ltr; text-align: left; min-height: 310px;
}
.ph-list { display: flex; flex-wrap: wrap; gap: 5px; max-height: 128px; overflow-y: auto; padding: 3px 0; }
.ph-list button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 5px; padding: 2.5px 7px;
  font-size: 14px; cursor: pointer; color: var(--text-secondary); font-family: inherit;
}
.ph-list button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-50); }

/* ---------- متفرقات ---------- */
.alert {
  display: flex; gap: 11px; padding: 12px 15px; border-radius: var(--radius); font-size: 16.5px;
  align-items: flex-start; margin-bottom: 14px; border: 1px solid transparent;
}
.alert.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.alert.warn { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.alert.bad  { background: var(--critical-bg); color: var(--critical); border-color: color-mix(in srgb, var(--critical) 22%, transparent); }
.alert.ok   { background: var(--good-bg); color: var(--good); border-color: color-mix(in srgb, var(--good) 22%, transparent); }
.alert .i { font-size: 20px; flex: 0 0 auto; }
.alert b { display: block; margin-bottom: 2px; }

.spinner {
  width: 17px; height: 17px; border: 2.5px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 56px; gap: 11px; color: var(--text-muted); }
.skeleton { background: var(--surface-3); border-radius: 6px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.mono { font-family: Consolas, "Courier New", monospace; font-size: 15.5px; direction: ltr; display: inline-block; }
.muted { color: var(--text-muted); }
.small { font-size: 15px; }
.nowrap { white-space: nowrap; }
.right { text-align: end; }
.center { text-align: center; }
.mb0 { margin-bottom: 0; }
.mt1 { margin-top: 14px; }
.flex { display: flex; gap: 9px; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 9px; }
.wrap { flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- الاستجابة ---------- */
@media (max-width: 1250px) { .g6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1050px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span4, .span3 { grid-column: span 2; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 272px; z-index: 60;
    transform: translateX(var(--off, 110%)); transition: transform .2s; box-shadow: var(--shadow-3);
  }
  body[dir="rtl"] .sidebar { --off: 110%; }
  body[dir="ltr"] .sidebar { --off: -110%; }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .g2, .g3, .g4, .g6 { grid-template-columns: 1fr; }
  .span2, .span3, .span4 { grid-column: span 1; }
  .content { padding: 14px; }
  .user-chip .nm, .user-chip .rl { display: none; }
  .scrim { position: fixed; inset: 0; background: rgba(8,18,22,.45); z-index: 55; }
}

@media print {
  .sidebar, .header, .toolbar, .filters, .pager, .btn, .tabs, .no-print { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
  body { background: #fff; }
}
