:root {
  color-scheme: light;
  --bg: #f2f5fb; --surface: #ffffff; --surface-2: #f7f9fd; --line: #e0e7f2; --line-strong: #c6d2e4;
  --ink: #15233b; --ink-2: #4f5f79; --ink-3: #73829b;
  --brand: #2253a2; --brand-2: #2b66c2; --brand-ink: #ffffff; --brand-soft: #e6eefb;
  --gold: #a87b1f; --gold-soft: #f8efd8;
  --side-bg: #173f80; --side-ink: #dbe6f8; --side-active: rgba(255, 255, 255, .16); --side-head: #a7c0e6;
  --good: #14703f; --good-bg: #e2f3e9; --warn: #8f5d00; --warn-bg: #fbf0d6; --bad: #b3261e; --bad-bg: #fbe6e4; --info: #1f5f99; --info-bg: #e4eff9; --mute-bg: #e9eef7;
  --series-1: #2a78d6; --series-2: #eb6834;
  --shadow: 0 1px 2px rgba(23, 50, 96, .06), 0 6px 18px rgba(23, 50, 96, .06);
  --radius: 10px;
  /* لمعة الأزرار الكرستالية: الحافة العلوية واللمعة على النصف العلوي */
  --gloss: rgba(255, 255, 255, .9); --sheen: rgba(255, 255, 255, .7);
  /* --ui-font و--print-font يضبطهما إعداد الخطوط، وغيابهما يعني خط الجهاز الافتراضي */
  --font-default: "Segoe UI", "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, "Geeza Pro", Arial, sans-serif;
  font-family: var(--ui-font, var(--font-default));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1422; --surface: #141f33; --surface-2: #19263d; --line: #27384f; --line-strong: #3a4f70;
    --ink: #e8eef8; --ink-2: #a9b8d0; --ink-3: #8293ae;
    --brand: #4d87e2; --brand-2: #6fa2f0; --brand-ink: #06142b; --brand-soft: #19305a;
    --gold: #e0ba62; --gold-soft: #3a3019;
    --side-bg: #0b1322; --side-ink: #bdcbe2; --side-active: rgba(120, 165, 240, .18); --side-head: #7288a8;
    --good: #5bd08d; --good-bg: #16332a; --warn: #e6b84f; --warn-bg: #362b12; --bad: #f28b82; --bad-bg: #3b1c1a; --info: #82bbf0; --info-bg: #17293a; --mute-bg: #22314b;
    --series-1: #3987e5; --series-2: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --gloss: rgba(255, 255, 255, .16); --sheen: rgba(255, 255, 255, .09);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1422; --surface: #141f33; --surface-2: #19263d; --line: #27384f; --line-strong: #3a4f70;
  --ink: #e8eef8; --ink-2: #a9b8d0; --ink-3: #8293ae;
  --brand: #4d87e2; --brand-2: #6fa2f0; --brand-ink: #06142b; --brand-soft: #19305a;
  --gold: #e0ba62; --gold-soft: #3a3019;
  --side-bg: #0b1322; --side-ink: #bdcbe2; --side-active: rgba(120, 165, 240, .18); --side-head: #7288a8;
  --good: #5bd08d; --good-bg: #16332a; --warn: #e6b84f; --warn-bg: #362b12; --bad: #f28b82; --bad-bg: #3b1c1a; --info: #82bbf0; --info-bg: #17293a; --mute-bg: #22314b;
  --series-1: #3987e5; --series-2: #d95926;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --gloss: rgba(255, 255, 255, .16); --sheen: rgba(255, 255, 255, .09);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 700; }
a { color: var(--brand-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.t-money, td.t-int, td.t-number, th.t-money, th.t-int, th.t-number { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

/* ===== الإطار ===== */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100dvh; }
.side { background: linear-gradient(175deg, var(--side-bg), color-mix(in srgb, var(--side-bg) 78%, #000)); color: var(--side-ink); position: sticky; top: 0; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; scrollbar-width: thin; z-index: 40; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px 14px; border-bottom: 1px solid rgba(255, 255, 255, .12); margin-bottom: 8px; }
.brand img { width: 50px; height: 50px; flex: none; background: #fff; border-radius: 12px; padding: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.brand b { display: block; color: #fff; font-size: 13.5px; line-height: 1.35; }
.nav { padding: 4px 8px 20px; }
.nav-group { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; color: inherit; padding: 9px 10px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; text-align: start; transition: background .18s; }
.nav-group:hover { background: rgba(255, 255, 255, .08); }
.nav-group span { flex: 1; }
.nav-group .chev { transition: transform .25s ease; opacity: .7; }
.nav-section.open .chev { transform: rotate(180deg); }
.nav-section.open > .nav-group { color: #fff; }
.nav-items { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .26s ease; }
.nav-section.open .nav-items { grid-template-rows: 1fr; }
.nav-items-inner { overflow: hidden; min-height: 0; }
.nav-sub { font-size: 12px; font-weight: 700; color: var(--side-head); padding: 10px 14px 3px; }
.nav-sub:first-child { padding-top: 4px; }
.nav a { display: block; color: inherit; text-decoration: none; padding: 7px 10px; margin-block: 1px; margin-inline-start: 30px; border-radius: 7px; font-size: 13.5px; opacity: .92; transition: background .16s, transform .16s, opacity .16s; }
.nav a:hover { background: rgba(255, 255, 255, .09); opacity: 1; transform: translateX(-2px); }
[dir="ltr"] .nav a:hover { transform: translateX(2px); }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 600; opacity: 1; box-shadow: inset -3px 0 0 #9cc2ff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 6px; padding: 8px 22px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.top .grow { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.content { padding: 22px; max-width: 1500px; width: 100%; margin-inline: auto; }
.scrim { display: none; }

.page-head { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ===== العناصر ===== */
/* المظهر الكرستالي: تدرج خفيف من أعلى الزر إلى أسفله، وحافة علوية لامعة، ولمعة زجاجية على النصف العلوي.
   الوضوح أولاً: الكتابة بلونها الكامل وليست شفافة، واللمعة خلف الكتابة لا فوقها (z-index سالب داخل الزر)،
   وهي تتلاشى قبل منتصف الزر حيث الكتابة، فيبقى التباين كما كان. */
.btn {
  position: relative; isolation: isolate;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 6px 14px; border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 88%, #fff) 0%, var(--surface) 46%, color-mix(in srgb, var(--surface) 88%, var(--brand)) 100%);
  box-shadow: inset 0 1px 0 var(--gloss), inset 0 -1px 0 color-mix(in srgb, var(--ink) 7%, transparent), 0 1px 2px color-mix(in srgb, var(--ink) 10%, transparent);
  cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--ink); white-space: nowrap;
  transition: background .16s, box-shadow .16s, transform .1s, border-color .16s, filter .16s;
}
.btn::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  inset: 1px 1px 50% 1px; border-radius: 8px 8px 60% 60% / 8px 8px 9px 9px;
  background: linear-gradient(180deg, var(--sheen) 0%, transparent 100%);
  transition: opacity .16s;
}
.btn:hover { border-color: var(--brand-2); box-shadow: inset 0 1px 0 var(--gloss), inset 0 -1px 0 color-mix(in srgb, var(--ink) 7%, transparent), 0 3px 10px color-mix(in srgb, var(--brand) 22%, transparent); }
.btn:active { transform: translateY(1px) scale(.99); box-shadow: inset 0 2px 5px color-mix(in srgb, var(--ink) 22%, transparent); }
.btn:active::before { opacity: .35; }
/* التدرج يفتح أعلى الزر فقط ويعود إلى لون الهوية نفسه قبل موضع الكتابة */
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 84%, #fff) 0%, var(--brand) 42%, color-mix(in srgb, var(--brand) 92%, #000) 100%);
  border-color: color-mix(in srgb, var(--brand) 82%, #000); color: var(--brand-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .38), inset 0 -1px 0 rgba(0, 0, 0, .16), 0 2px 8px color-mix(in srgb, var(--brand) 35%, transparent);
}
.btn.primary::before { background: linear-gradient(180deg, rgba(255, 255, 255, .30) 0%, rgba(255, 255, 255, 0) 100%); }
.btn.primary:hover { filter: brightness(1.06) saturate(1.05); border-color: color-mix(in srgb, var(--brand) 82%, #000); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -1px 0 rgba(0, 0, 0, .16), 0 5px 16px color-mix(in srgb, var(--brand) 45%, transparent); }
.btn.primary:active { filter: none; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .30); }
.btn.danger {
  color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, var(--surface));
  background: linear-gradient(180deg, color-mix(in srgb, var(--bad-bg) 35%, var(--surface)) 0%, color-mix(in srgb, var(--bad-bg) 70%, var(--surface)) 46%, var(--bad-bg) 100%);
}
.btn.danger:hover { border-color: var(--bad); box-shadow: inset 0 1px 0 var(--gloss), 0 3px 10px color-mix(in srgb, var(--bad) 24%, transparent); }
/* أزرار الشريط العلوي تبقى مسطحة حتى لا تزدحم الواجهة، وتأخذ الزجاج عند المرور فقط */
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost::before { opacity: 0; }
.btn.ghost:hover { border-color: transparent; background: var(--mute-bg); box-shadow: inset 0 1px 0 var(--gloss); }
.btn.ghost:hover::before { opacity: 1; }
.btn.sm { min-height: 30px; padding: 2px 10px; font-size: 13px; border-radius: 8px; }
.btn.sm::before { border-radius: 7px 7px 60% 60% / 7px 7px 8px 8px; }
.btn:disabled { opacity: .55; cursor: default; filter: none; box-shadow: none; }
.btn:disabled::before { display: none; }
/* وضع التباين العالي في النظام: يسقط التأثير كله ويبقى الزر بحدوده */
@media (forced-colors: active) { .btn { background: ButtonFace; box-shadow: none; } .btn::before { display: none; } }
.icon-btn { position: relative; width: 38px; height: 38px; padding: 0; }
.dot-count { position: absolute; top: -4px; inset-inline-start: -4px; background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.card > h3 { font-size: 15px; padding: 14px 16px 0; }
.card .body { padding: 14px 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-inline-start: 3px solid var(--brand); border-radius: 12px; padding: 13px 15px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; transition: transform .18s, box-shadow .18s, border-color .18s; }
a.kpi:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(23, 50, 96, .14); border-color: var(--brand-2); }
.kpi.alert { border-inline-start-color: var(--warn); }
.kpi span { display: block; color: var(--ink-2); font-size: 13px; }
.kpi b { display: block; font-size: 23px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi b small { font-size: 12px; font-weight: 500; color: var(--ink-3); margin-inline-start: 3px; }
.kpi.alert b { color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar input[type=search] { flex: 1 1 200px; min-width: 150px; }

input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { min-height: 38px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); width: 100%; }
.toolbar select, .toolbar input[type=month], .toolbar input[type=date] { width: auto; max-width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input[type=date], input[type=month], input[type=time] { direction: ltr; text-align: end; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
label.field { display: block; font-size: 13px; color: var(--ink-2); font-weight: 600; }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; font-weight: 400; color: var(--ink); font-size: 15px; }
label.field .req { color: var(--bad); }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 38px; }
label.check input { width: 18px; height: 18px; flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset.group { border: 0; padding: 0; margin: 0 0 18px; }
fieldset.group legend { font-weight: 700; font-size: 14px; color: var(--brand-2); padding: 0 0 8px; }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: start; background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--ink); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: var(--surface-2); }
table.data td.t-money, table.data td.t-int, table.data td.t-number, table.data th.t-money, table.data th.t-int, table.data th.t-number { text-align: left; direction: ltr; white-space: nowrap; }
table.data td.nw { white-space: nowrap; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line-strong); }
tr.r-head td { font-weight: 700; color: var(--brand-2); background: var(--surface-2); }
tr.r-sub td { font-weight: 700; border-top: 1px solid var(--line-strong); }
td.row-actions { white-space: nowrap; text-align: end; }
td.row-actions .btn + .btn { margin-inline-start: 4px; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-2); }
.pager { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 13px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 20px; font-size: 12.5px; font-weight: 600; background: var(--mute-bg); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

.note { background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; }
.note.info { background: var(--info-bg); border-color: transparent; }
.muted { color: var(--ink-2); font-size: 13px; }

/* ===== النوافذ ===== */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog.modal.wide { width: min(1040px, calc(100vw - 24px)); }
dialog.modal.small { width: min(440px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(10, 25, 22, .5); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }

#toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; z-index: 1000; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }

/* ===== الدخول ===== */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #173f80, #2253a2 55%, #2b66c2); position: relative; z-index: 21; overflow: hidden; }
.login::before, .login::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .13); }
.login::before { width: 620px; height: 620px; inset-block-start: -220px; inset-inline-start: -180px; box-shadow: 0 0 0 70px rgba(255, 255, 255, .03), 0 0 0 150px rgba(255, 255, 255, .02); }
.login::after { width: 420px; height: 420px; inset-block-end: -170px; inset-inline-end: -120px; box-shadow: 0 0 0 60px rgba(255, 255, 255, .03); }
.login-card { position: relative; z-index: 1; width: min(420px, 100%); background: var(--surface); border-radius: 18px; padding: 28px 26px; box-shadow: 0 24px 70px rgba(5, 20, 50, .4); animation: rise .5s cubic-bezier(.2, .8, .25, 1) both; }
.login-card > img { width: 148px; height: auto; display: block; margin: 0 auto 14px; background: #fff; border-radius: 14px; padding: 6px; animation: logoIn .7s cubic-bezier(.2, .8, .25, 1) both; }
.login-card h1 { text-align: center; font-size: 19px; }
.login-card p { text-align: center; color: var(--ink-2); margin: 4px 0 20px; font-size: 13.5px; }
.login-card form { display: grid; gap: 13px; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }

/* ===== الرسوم البيانية ===== */
.chart { --h: 190px; position: relative; padding-top: 6px; }
.plot { position: relative; height: var(--h); margin-inline-start: 46px; border-bottom: 1px solid var(--line-strong); }
.gridline { position: absolute; inset-inline: 0; border-top: 1px solid var(--line); }
.gridline span { position: absolute; inset-inline-start: -46px; width: 42px; top: -9px; font-size: 11px; color: var(--ink-3); text-align: end; font-variant-numeric: tabular-nums; }
.cols { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding-inline: 2px; cursor: default; border-radius: 4px; }
.col:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.bar { flex: 1; max-width: 22px; min-height: 0; border-radius: 4px 4px 0 0; }
.bar.s1 { background: var(--series-1); }
.bar.s2 { background: var(--series-2); }
.xlabels { display: flex; margin-inline-start: 46px; margin-top: 5px; }
.xlabels span { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--ink-3); overflow: hidden; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-inline-end: 5px; }
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 10px; background: var(--mute-bg); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 5px; }
.hbar .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#tip { position: fixed; z-index: 1100; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 10px; border-radius: 6px; font-size: 12.5px; box-shadow: var(--shadow); max-width: 240px; white-space: pre-line; }
details.as-table { margin-top: 10px; font-size: 13px; }
details.as-table summary { cursor: pointer; color: var(--ink-2); }

/* ===== الملف والقسيمة ===== */
.profile-head { display: flex; gap: 16px; align-items: center; padding: 16px; flex-wrap: wrap; }
.avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-size: 30px; font-weight: 700; flex: none; }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 11px 16px; }
.dl div span { display: block; color: var(--ink-3); font-size: 12.5px; }
.dl div b { font-weight: 600; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 9px 14px; cursor: pointer; font-weight: 600; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand-2); border-color: var(--brand-2); }
.slip-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.slip-line { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.slip-line.total { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--line-strong); margin-top: 4px; }
.slip-net { margin-top: 14px; display: flex; justify-content: space-between; padding: 12px 14px; background: var(--brand-soft); border-radius: 8px; font-size: 18px; font-weight: 700; }
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th { font-size: 12.5px; color: var(--ink-2); text-align: start; padding: 4px; }
.lines-table td { padding: 3px 4px; vertical-align: top; }
.steps { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; margin-bottom: 14px; font-size: 13px; color: var(--ink-3); }
.steps b { color: var(--brand-2); }
.steps .past { color: var(--ink-2); }
.matrix { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.matrix th, .matrix td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: start; white-space: nowrap; }
.popover { position: absolute; top: 52px; inset-inline-end: 12px; width: min(360px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); z-index: 60; }
.popover a { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; font-size: 13.5px; }
.popover a.unread { font-weight: 700; }
.popover a small { display: block; color: var(--ink-3); font-weight: 400; }

/* ===== الهاتف ===== */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(280px, 84vw); transform: translateX(100%); transition: transform .2s; }
  .shell.open .side { transform: none; }
  .shell.open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .top { padding: 8px 12px; }
  .content { padding: 14px 12px 28px; }
  .page-head h1 { font-size: 19px; }
}
@media (max-width: 640px) {
  .slip-cols { grid-template-columns: 1fr; }
  .top .grow { visibility: hidden; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi b { font-size: 19px; overflow-wrap: anywhere; }
  .xlabels span:nth-child(even) { visibility: hidden; }
  /* الجداول تتحول إلى بطاقات */
  table.data.cards thead { display: none; }
  table.data.cards, table.data.cards tbody, table.data.cards tfoot { display: block; width: 100%; }
  table.data.cards tr { display: block; padding: 8px 12px; border-bottom: 1px solid var(--line-strong); }
  table.data.cards td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: end !important; direction: rtl; white-space: normal; }
  table.data.cards td::before { content: attr(data-label); color: var(--ink-3); font-size: 12.5px; text-align: start; flex: none; max-width: 45%; }
  table.data.cards td:empty { display: none; }
  table.data.cards td.row-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 8px; gap: 4px; }
  table.data.cards td.row-actions::before { display: none; }
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font-size: 16px; }
  dialog.modal, dialog.modal.wide, dialog.modal.small { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .modal-inner { max-height: 100dvh; height: 100%; }
  .modal-body { flex: 1; }
  .modal-foot .btn { flex: 1; }
  .lines-table, .lines-table tbody { display: block; }
  .lines-table thead { display: none; }
  .lines-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines-table td { padding: 0; }
  .lines-table td.span { grid-column: 1 / -1; }
}

/* ===== الحركة: فتح الشاشات والنوافذ ===== */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes logoIn { from { opacity: 0; transform: scale(.86); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes modalOut { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes routeBar { from { transform: scaleX(0); } to { transform: scaleX(.85); } }
.page-in > * { animation: rise .32s cubic-bezier(.2, .8, .25, 1) both; }
.page-in > *:nth-child(2) { animation-delay: .04s; }
.page-in > *:nth-child(3) { animation-delay: .08s; }
.page-in > *:nth-child(4) { animation-delay: .12s; }
.page-in .kpi, .page-in .tile { animation: rise .36s cubic-bezier(.2, .8, .25, 1) both; }
.page-in .kpi:nth-child(2), .page-in .tile:nth-child(2) { animation-delay: .03s; }
.page-in .kpi:nth-child(3), .page-in .tile:nth-child(3) { animation-delay: .06s; }
.page-in .kpi:nth-child(4), .page-in .tile:nth-child(4) { animation-delay: .09s; }
.page-in .kpi:nth-child(5), .page-in .tile:nth-child(5) { animation-delay: .12s; }
.page-in .kpi:nth-child(n+6), .page-in .tile:nth-child(n+6) { animation-delay: .15s; }
.page-in .bar { animation: barUp .55s cubic-bezier(.2, .8, .25, 1) both; transform-origin: bottom; }
@keyframes barUp { from { transform: scaleY(0); } to { transform: none; } }
.page-in .hbar .fill { animation: barGrow .6s cubic-bezier(.2, .8, .25, 1) both; transform-origin: right; }
[dir="ltr"] .page-in .hbar .fill { transform-origin: left; }
@keyframes barGrow { from { transform: scaleX(0); } to { transform: none; } }
dialog.modal[open] { animation: modalIn .24s cubic-bezier(.2, .8, .25, 1) both; }
dialog.modal[open]::backdrop { animation: fadeIn .2s ease both; backdrop-filter: blur(3px); }
dialog.modal.closing { animation: modalOut .14s ease both; }
#route-bar { position: fixed; inset-block-start: 0; inset-inline: 0; height: 3px; background: linear-gradient(90deg, #2b66c2, #8fb8ff); transform-origin: right; z-index: 2000; pointer-events: none; opacity: 0; }
[dir="ltr"] #route-bar { transform-origin: left; }
#route-bar.on { opacity: 1; animation: routeBar 1.2s ease-out both; }
.skeleton { display: grid; gap: 12px; }
.skeleton div { height: 74px; border-radius: 12px; background: linear-gradient(90deg, var(--mute-bg) 25%, var(--surface-2) 50%, var(--mute-bg) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton div:first-child { height: 34px; width: 40%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ===== نواقص الموظفين ===== */
.sf-card { margin-bottom: 18px; }
.sf-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sf-list { max-height: 400px; overflow-y: auto; }
.sf-row { display: block; padding: 11px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; transition: background .14s; }
.sf-row:last-child { border-bottom: 0; }
.sf-row:hover { background: var(--surface-2); }
.sf-who { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 6px; }
.sf-count { margin-inline-start: auto; min-width: 26px; height: 26px; line-height: 26px; padding-inline: 7px; text-align: center; border-radius: 13px; background: var(--warn-bg); color: var(--warn); font-weight: 700; font-size: 13px; }
.sf-group { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 4px; }
.sf-label { font-size: 12px; color: var(--ink-3); min-width: 38px; }

/* ===== جداول التقارير على الشاشة ===== */
table.data.report { border-collapse: separate; border-spacing: 0; }
table.data.report th { background: var(--brand); color: var(--brand-ink); font-size: 13px; font-weight: 700; padding: 10px 12px; border-bottom: 0; }
table.data.report td { font-size: 14.5px; padding: 9px 12px; }
table.data.report tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--brand) 5%, transparent); }
table.data.report tbody tr:last-child td { border-bottom: 2px solid var(--brand); }
table.data.report tfoot td { background: var(--brand-soft); color: var(--ink); font-size: 14.5px; border-top: 0; border-bottom: 2px solid var(--brand); }
table.data.report tr.r-head td { background: var(--brand-soft); color: var(--brand-2); font-size: 15px; }
table.data.report tr.r-sub td { background: var(--surface-2); border-top: 1px solid var(--brand); }

/* ===== الوصول السريع ===== */
.section-title { font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 4px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: inherit; font-weight: 600; font-size: 13.5px; box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s, border-color .18s; }
.tile:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(23, 50, 96, .15); border-color: var(--brand-2); }
.tile i { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--brand-soft); color: var(--brand-2); transition: background .18s, color .18s; }
.tile:hover i { background: var(--brand); color: var(--brand-ink); }

/* ===== الاستيراد ===== */
.import-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 12px; }
.import-kpis div { padding: 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.import-kpis b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.import-kpis span { font-size: 12.5px; color: var(--ink-2); }
.drop { border: 2px dashed var(--line-strong); border-radius: 12px; padding: 24px; text-align: center; display: block; cursor: pointer; transition: border-color .16s, background .16s; }
.drop:hover { border-color: var(--brand-2); background: var(--brand-soft); }

/* ===== شعار الخلفية ===== */
#watermark { position: fixed; inset: 0; margin: auto; width: min(58vmin, 520px); height: min(58vmin, 520px); object-fit: contain; opacity: .06; pointer-events: none; z-index: 20; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #watermark { filter: brightness(0) invert(1); opacity: .05; } }
:root[data-theme="dark"] #watermark { filter: brightness(0) invert(1); opacity: .05; }

/* ===== المرفقات ===== */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.thumb { border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: center; background: var(--surface-2); min-width: 0; }
.thumb img, .thumb-file { width: 100%; height: 90px; object-fit: cover; border-radius: 5px; display: grid; place-items: center; background: var(--mute-bg); color: var(--ink-2); font-weight: 700; }
.thumb a { text-decoration: none; display: block; }
.thumb-name { font-size: 12px; margin-top: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.doc-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.doc-head > b { flex: 0 1 auto; }
.bio-btn { min-height: 48px; font-size: 16px; padding-inline: 22px; }
.steps-list { margin: 0; padding-inline-start: 20px; display: grid; gap: 6px; }

/* ===== الواجهة الإنجليزية (من اليسار لليمين) ===== */
[dir="ltr"] .nav a.active { box-shadow: inset 3px 0 0 #9cc2ff; }
[dir="ltr"] table.data td.t-money, [dir="ltr"] table.data td.t-int, [dir="ltr"] table.data td.t-number,
[dir="ltr"] table.data th.t-money, [dir="ltr"] table.data th.t-int, [dir="ltr"] table.data th.t-number { text-align: right; }
[dir="ltr"] input[type=date], [dir="ltr"] input[type=month], [dir="ltr"] input[type=time] { text-align: start; }
@media (max-width: 900px) {
  [dir="ltr"] .side { transform: translateX(-100%); }
  [dir="ltr"] .shell.open .side { transform: none; }
}
@media (max-width: 640px) {
  [dir="ltr"] table.data.cards td { direction: ltr; }
  .top-user { display: none; }
}

/* ===== الطباعة ===== */
#print-root { display: none; }
@media print {
  /* الطباعة بألوان فاتحة دائماً حتى لو كان الجهاز في الوضع الليلي */
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] {
    color-scheme: light;
    --surface: #fff; --surface-2: #fff; --bg: #fff; --ink: #000; --ink-2: #333; --ink-3: #555;
    --line: #999; --line-strong: #666; --brand-2: #2253a2; --brand-soft: #fff;
  }
  :root { font-family: var(--print-font, var(--ui-font, var(--font-default))); }
  table.data tfoot td { background: none; }
  body { background: #fff; color: #000; font-size: calc(var(--print-size, 10.5pt) + .5pt); font-weight: 500; }
  #app, #toasts, #tip, dialog { display: none !important; }
  #watermark { opacity: .07; z-index: 0; width: 125mm; height: 125mm; filter: none; }
  #route-bar { display: none; }
  #print-root { position: relative; z-index: 1; }
  #print-root { display: block; }
  body { margin: 0; }
  #print-root { padding: 0 11mm; }
  .lh-table { width: 100%; border-collapse: collapse; }
  .lh-table > thead > tr > td, .lh-table > tfoot > tr > td, .lh-table > tbody > tr > td { padding: 0; border: 0; }
  .lh-head { display: grid; grid-template-columns: 34mm 1fr 42mm; align-items: center; gap: 3mm; direction: rtl; padding-top: 6mm; padding-bottom: 2.5mm; border-bottom: .5mm solid var(--brand, #2253a2); margin-bottom: 4mm; }
  .lh-head img { width: 32mm; height: auto; max-height: 26mm; object-fit: contain; }
  .lh-names { text-align: center; color: var(--brand, #2253a2); }
  .lh-names b { display: block; font-size: 15pt; line-height: 1.3; }
  .lh-names span { display: block; font-size: 10pt; font-weight: 600; letter-spacing: .2px; direction: ltr; }
  .lh-meta { font-size: 8.5pt; color: #333; line-height: 1.75; text-align: right; }
  .lh-meta .ref { display: inline-block; min-width: 18mm; border-bottom: 1px dotted #777; }
  .lh-space { height: 19mm; }
  /* صورة الورق المعنون: صفحة A4 كاملة خلف المحتوى، تتكرر في كل صفحة لأنها ثابتة الموضع */
  .lh-page { position: fixed; top: 0; left: 0; width: 210mm; height: 297mm; z-index: -1; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* مع ورق معنون خاص لا يُطبع شعار المنظومة خلف المحتوى */
  body.lh-custom #watermark { display: none; }
  .lh-foot { position: fixed; inset-inline: 0; bottom: 0; height: 15mm; display: flex; align-items: center; justify-content: space-between; gap: 6mm; padding: 0 11mm; background: var(--brand, #2253a2); color: var(--brand-ink, #fff); direction: ltr; font-size: 8.5pt; line-height: 1.5; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .lh-foot div { display: flex; flex-direction: column; }
  .lh-foot .mid { text-align: center; }
  .lh-foot .end { text-align: right; }
  .lh-foot svg { vertical-align: -1.5px; margin-inline-end: 3px; }
  .print-title { text-align: center; font-size: 15pt; font-weight: 800; margin: 1mm 0 4mm; color: #000; }
  .print-title small { display: block; font-size: 10pt; font-weight: 600; color: #222; margin-top: 1mm; }
  .table-wrap { overflow: visible; }
  /* الجدول الرسمي: شبكة سوداء كاملة حول كل خانة وإطار أثخن، دون ألوان، فيصلح للطباعة بالأبيض والأسود والتصوير.
     الجدول مقفل من كل الجهات حتى عند انتهائه في منتصف الصفحة أو انقسامه على صفحتين */
  #print-root table.data { border-collapse: collapse; width: 100%; border: 1.4pt solid #000; font-size: var(--print-size, 10.5pt); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-root table.data th { background: #e4e4e4; color: #000; font-size: var(--print-size, 10.5pt); font-weight: 700; padding: 6px 8px; border: .75pt solid #000; border-bottom: 1.4pt solid #000; text-align: center; white-space: normal; vertical-align: middle; }
  #print-root table.data td { color: #000; font-weight: 500; padding: 5px 8px; border: .75pt solid #000; vertical-align: middle; background: none; line-height: 1.45; }
  #print-root table.data th:first-child, #print-root table.data td:first-child { border-inline-start: 1.4pt solid #000; }
  #print-root table.data th:last-child, #print-root table.data td:last-child { border-inline-end: 1.4pt solid #000; }
  #print-root table.data tbody tr:nth-child(even) td { background: none; }
  #print-root table.data tbody tr:last-child td { border-bottom: 1.4pt solid #000; }
  #print-root table.data tfoot td { background: #efefef; color: #000; font-weight: 800; font-size: var(--print-size, 10.5pt); padding: 7px 8px; border: .75pt solid #000; border-top: 1.4pt solid #000; border-bottom: 1.4pt solid #000; }
  #print-root table.data tr.r-head td { background: #e4e4e4; color: #000; font-weight: 800; font-size: calc(var(--print-size, 10.5pt) + .5pt); }
  #print-root table.data tr.r-sub td { background: #f3f3f3; font-weight: 800; border-top: 1.4pt solid #000; }
  #print-root table.data.dense, #print-root table.data.dense th, #print-root table.data.dense tfoot td { font-size: calc(var(--print-size, 10.5pt) - 2pt); }
  #print-root table.data.dense td, #print-root table.data.dense th { padding: 3px 4px; }
  /* أعمدة الأرقام بعرض محتواها فقط، فيبقى العرض لأعمدة النص ولا تنكسر الأسماء على أسطر كثيرة */
  #print-root table.data td.t-money, #print-root table.data td.t-int, #print-root table.data td.t-number, #print-root table.data td.nw { white-space: nowrap; width: 1%; }
  #print-root table.data a { color: #000; text-decoration: none; }
  /* بيانات رأس السند والقسيمة وملف الموظف: خانات مقفلة بالشبكة نفسها بدل نص سائب */
  #print-root .dl { display: flex; flex-wrap: wrap; gap: 0; border: 1.4pt solid #000; margin-bottom: 4mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* خانات الصف الأخير تتمدد لتملأ العرض، فلا يبقى فراغ بلا حدود داخل الإطار */
  #print-root .dl > div { flex: 1 1 42mm; display: flex; flex-direction: column; border: .375pt solid #000; break-inside: avoid; }
  #print-root .dl + p { border: 1.4pt solid #000; padding: 4px 6px; margin: 0 0 4mm; color: #000; }
  #print-root .dl div span { color: #000; font-size: 8.5pt; font-weight: 700; background: #e4e4e4; padding: 2px 6px; border-bottom: .75pt solid #000; }
  #print-root .dl div b { color: #000; font-weight: 600; padding: 4px 6px; min-height: 1.5em; flex: 1; }
  #print-root fieldset.group { margin: 0 0 4mm; break-inside: avoid; }
  #print-root fieldset.group legend { color: #000; font-size: 11pt; padding-bottom: 1.5mm; }
  #print-root .slip-cols { gap: 0; border: 1.4pt solid #000; }
  #print-root .slip-cols > * { padding: 2mm 3mm; border: .375pt solid #000; }
  #print-root .slip-line { border-bottom: .75pt solid #000; color: #000; }
  #print-root .slip-line.total { border-bottom: 0; border-top: 1.4pt solid #000; }
  #print-root h3, #print-root h4 { color: #000; }
  #print-root .muted { color: #222; }
  table.data thead { display: table-header-group; }
  table.data tfoot { display: table-row-group; }
  table.data tr { break-inside: avoid; }
  .card { border: 0; box-shadow: none; }
  .signs { display: flex; justify-content: space-between; margin-top: 16mm; gap: 12mm; break-inside: avoid; }
  .signs div { flex: 1; text-align: center; border-top: 1px solid #000; padding-top: 5px; font-size: 10.5pt; font-weight: 700; color: #000; }
  .print-foot { margin-top: 6mm; font-size: 8.5pt; font-weight: 400; color: #555; }
  .badge { background: none !important; color: #000 !important; padding: 0; }
  .badge::before { display: none; }
  .slip-net { background: #efefef; border: 1.4pt solid #000; border-radius: 0; margin-top: 4mm; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.signs { display: none; }
@media print { .signs { display: flex; } }
