/* ==========================================================================
   نظام الدفاتر — نظام تصميم (Design System)
   RTL أولاً · فاتح/داكن · كبير وواضح لكبار السن · جوال/تابلت/سطح مكتب
   ========================================================================== */

:root {
  /* ارتفاع الشريط العلوي — يلتصق به رأس الجدول فلا يختفي مع التمرير */
  --topbar-h: 68px;
  --tbl-gap: 46px;   /* هامش أسفل حاوية الجدول */
  /* الألوان — فاتح */
  --bg:            #eef2f7;
  --bg-2:          #e2e8f2;
  --surface:       #ffffff;
  --surface-2:     #f7fafc;
  --surface-3:     #eff3f8;
  --border:        #d8e0ea;
  --border-strong: #c3cede;
  --text:          #0f1b2d;
  --text-2:        #46566b;
  --text-muted:    #7a8aa0;

  /* الهوية — ذهب + زمرّدي (محل مجوهرات) */
  --gold:          #c6972f;
  --gold-soft:     #f6e8c8;
  --gold-deep:     #8a6414;
  --brand:         #0e7c66;   /* زمرّدي */
  --brand-2:       #0b6353;
  --brand-soft:    #d6efe8;

  /* دلالات */
  --riyal:         #1d64c4;   /* الأزرق = الريال (مطابق للجداول) */
  --riyal-soft:    #dbeafe;
  --metal:         #b9852b;   /* الذهبي = الذهب */
  --metal-soft:    #fbeecb;
  --ok:            #0f9d63;
  --ok-soft:       #d5f2e4;
  --warn:          #cf8a00;
  --warn-soft:     #fdeecb;
  --danger:        #d64545;
  --danger-soft:   #fbe0e0;

  /* أبعاد وحركة */
  --radius:   16px;
  --radius-sm:11px;
  --radius-lg:24px;
  --shadow:   0 1px 2px rgba(16,27,45,.06), 0 8px 24px rgba(16,27,45,.06);
  --shadow-lg:0 24px 60px rgba(16,27,45,.16);
  --ring:     0 0 0 4px rgba(14,124,102,.22);

  /* الخطوط — أكبر من المعتاد للوضوح */
  --font: "Segoe UI", "Tahoma", "Noto Naskh Arabic", system-ui, -apple-system, sans-serif;
  --fs-base: 18px;
  --sidebar: 268px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0b1220; --bg-2:#0e1626; --surface:#141d2e; --surface-2:#1a2436; --surface-3:#202c41;
    --border:#28344a; --border-strong:#374561; --text:#eef3fb; --text-2:#aebbcf; --text-muted:#7e8da4;
    --gold:#e2b64e; --gold-soft:#3a2f14; --gold-deep:#f0d38a;
    --brand:#2bb596; --brand-2:#22a184; --brand-soft:#123028;
    --riyal:#5aa0f5; --riyal-soft:#122543; --metal:#e0b357; --metal-soft:#32270f;
    --ok:#37c98a; --ok-soft:#0f2e22; --warn:#e6b23c; --warn-soft:#312611;
    --danger:#f0736f; --danger-soft:#331617;
    --shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px rgba(0,0,0,.35);
    --shadow-lg:0 30px 70px rgba(0,0,0,.55); --ring:0 0 0 4px rgba(43,181,150,.3);
  }
}
:root[data-theme="dark"] {
  --bg:#0b1220; --bg-2:#0e1626; --surface:#141d2e; --surface-2:#1a2436; --surface-3:#202c41;
  --border:#28344a; --border-strong:#374561; --text:#eef3fb; --text-2:#aebbcf; --text-muted:#7e8da4;
  --gold:#e2b64e; --gold-soft:#3a2f14; --gold-deep:#f0d38a;
  --brand:#2bb596; --brand-2:#22a184; --brand-soft:#123028;
  --riyal:#5aa0f5; --riyal-soft:#122543; --metal:#e0b357; --metal-soft:#32270f;
  --ok:#37c98a; --ok-soft:#0f2e22; --warn:#e6b23c; --warn-soft:#312611;
  --danger:#f0736f; --danger-soft:#331617;
  --shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px rgba(0,0,0,.35);
  --shadow-lg:0 30px 70px rgba(0,0,0,.55); --ring:0 0 0 4px rgba(43,181,150,.3);
}

* { box-sizing: border-box; }
html { font-size: var(--fs-base); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.6; letter-spacing: 0; -webkit-font-smoothing: antialiased;
  min-height: 100vh; overflow-x: hidden;
}
h1,h2,h3,h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 800; }
a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; height: auto; }

/* ===== التخطيط العام ===== */
.layout { display: flex; min-height: 100vh; }
.main   { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content{ padding: clamp(16px, 3vw, 32px); flex: 1; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ===== الشريط الجانبي ===== */
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: var(--surface);
  border-inline-start: 1px solid var(--border); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto; z-index: 40;
}
.brand { padding: 22px 22px 14px; display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--gold), var(--gold-deep)); color: #fff;
  font-weight: 900; font-size: 22px; box-shadow: var(--shadow); flex-shrink: 0;
}
.brand .brand-txt b { font-size: 1.12rem; display: block; }
.brand .brand-txt span { font-size: .82rem; color: var(--text-muted); }

.nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 3px; }
.nav .sec { font-size: .74rem; color: var(--text-muted); padding: 14px 14px 6px; font-weight: 700; letter-spacing: .04em; }
.nav a {
  display: flex; align-items: center; gap: 13px; padding: 13px 14px; border-radius: 13px;
  color: var(--text-2); font-weight: 600; font-size: 1.02rem; transition: .15s; position: relative;
}
.nav a .ic { width: 26px; text-align: center; font-size: 1.28rem; flex-shrink: 0; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 800; }
.nav a.active .ic { transform: scale(1.06); }
.nav .badge { margin-inline-start: auto; }

/* ===== الشريط العلوي ===== */
.topbar {
  position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 12px clamp(14px,3vw,28px); min-height: 68px;
}
.topbar h1 { font-size: 1.28rem; margin: 0; }
.topbar .sub { color: var(--text-muted); font-size: .86rem; font-weight: 600; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); display: grid; place-items: center;
  cursor: pointer; font-size: 1.3rem; transition: .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-btn { display: none; }

.userchip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; }
.userchip .av {
  width: 42px; height: 42px; border-radius: 11px; background: linear-gradient(140deg,var(--brand),var(--brand-2));
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
}
.userchip .who b { display: block; font-size: .96rem; line-height: 1.15; }
.userchip .who span { font-size: .78rem; color: var(--text-muted); }

/* ===== البطاقات ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card + .card { margin-top: 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.14rem; display: flex; align-items: center; gap: 10px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 20px; }
.card-pad { padding: 20px; }

/* ===== شبكة الإحصائيات ===== */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px;
}
.stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 6px; background: var(--brand); }
.stat.riyal::before { background: var(--riyal); }
.stat.metal::before { background: var(--metal); }
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.danger::before { background: var(--danger); }
.stat .lbl { color: var(--text-muted); font-size: .92rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.stat .lbl .ic { font-size: 1.15rem; }
.stat .val { font-size: 1.9rem; font-weight: 900; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .val small { font-size: .8rem; font-weight: 700; color: var(--text-muted); margin-inline-start: 4px; }
.stat .foot { font-size: .82rem; color: var(--text-2); }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 22px; min-height: 52px; border-radius: 13px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); font-family: inherit; font-size: 1.02rem;
  font-weight: 700; cursor: pointer; transition: .16s; white-space: nowrap; text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .ic { font-size: 1.2rem; }
.btn-primary { background: linear-gradient(140deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: var(--shadow); }
.btn-gold    { background: linear-gradient(140deg, var(--gold), var(--gold-deep)); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border-strong); }
.btn-ghost   { background: transparent; }
.btn-danger  { background: var(--danger-soft); color: var(--danger); }
.btn-ok      { background: var(--ok-soft); color: var(--ok); }
.btn-sm { padding: 8px 14px; min-height: 40px; font-size: .92rem; border-radius: 10px; }
.btn-lg { padding: 16px 30px; min-height: 62px; font-size: 1.18rem; border-radius: 16px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ===== النماذج ===== */
.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 700; margin-bottom: 8px; font-size: .98rem; color: var(--text-2); }
.field .hint { color: var(--text-muted); font-size: .82rem; margin-top: 6px; }
.input, .select, textarea.input {
  width: 100%; padding: 14px 16px; min-height: 54px; border-radius: 13px; border: 1.5px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: 1.05rem;
  transition: .15s; font-variant-numeric: tabular-nums;
}
textarea.input { min-height: 90px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input::placeholder { color: var(--text-muted); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
/* خاصية hidden تسبق أي display من الأصناف — وإلا ظهر عنصر .form-grid[hidden]
   لأن display:grid من ورقة المؤلّف تتغلّب على [hidden] في ورقة المتصفح. */
[hidden], .is-hidden { display: none !important; }
/* عمود الملاحظة داخل الصف: مضغوط ولا يتمدّد على حساب بقية الأعمدة */
td.notecell { min-width: 150px; max-width: 240px; }
td.notecell .input-sm { min-height: 38px; padding: 6px 9px; font-size: .9rem; }
/* عند الطباعة: يظهر نصّ الملاحظة لا حقل الإدخال */
@media print {
  td.notecell form { display: none }
  td.notecell::after { content: attr(data-note); font-size: .85rem; color: #444 }
}
/* حقول مضغوطة: للنماذج الكثيفة (دفتر الخارج) — أصغر بلا إخلال بلمس الجوال */
.input-sm, .select.input-sm {
  padding: 9px 12px; min-height: 44px; border-radius: 10px; font-size: .97rem;
}
input[type="file"].input-sm { padding: 7px 10px; }
.form-grid:has(.input-sm) { gap: 11px; }
input[type="file"].input { padding: 10px; }
input[type="date"].input, input[type="month"].input { font-family: inherit; }

/* ===== الجداول ===== */
/* ═══ الجدول: حاوية تمرير واحدة صريحة ═══
   جذر المشكلة: أي عنصرٍ قابل للتمرير في محورٍ واحد يبقى «حاوية تمرير»
   في نظر CSS، فالرأس اللاصق يلتصق بأعلى **الصندوق** لا بأعلى الشاشة.
   وما دام الصندوق بلا ارتفاع محدَّد، فأعلاه ثابت لا يتحرّك — فيقف الرأس
   عند مسافةٍ ثابتة فوق الصف الأول ويغطّيه، وهو ما ظهر بالضبط.
   ولا مخرج من هذا: الجدول العريض يحتاج تمريراً أفقياً، والتمرير الأفقي
   يخلق الحاوية. فالحلّ الجذري أن نمنح الحاوية ارتفاعاً واضحاً: يصير
   التمرير داخلها، ويعلوها الرأس دائماً حتى آخر سطر — وتُثبَّت معه
   الإجماليات في الأسفل، وهي فائدةٌ لم تكن موجودة أصلاً. */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - var(--tbl-gap, 46px));
  /* أفقياً: احبس التمرير كي لا يفسّره المتصفح «رجوعاً للخلف».
     رأسياً: دعه يتسلسل — إذا بلغ القارئ آخر الجدول تابعت الصفحة النزول
     بدل أن تقف تحت يده. */
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch; border-radius: var(--radius);
}
/* dvh يحسب شريط المتصفح المتحرّك على الجوال — مع إبقاء vh لمن لا يدعمه */
@supports (height: 100dvh) {
  .table-wrap { max-height: calc(100dvh - var(--topbar-h) - var(--tbl-gap, 46px)); }
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 1rem; min-width: 620px; }
table.tbl thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-3); color: var(--text-2); font-weight: 800;
  padding: 14px 14px; text-align: start; white-space: nowrap; border-bottom: 2px solid var(--border-strong);
  font-size: .92rem; box-shadow: 0 1px 0 var(--border-strong);
}
table.tbl tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.tbl tbody tr:hover td { background: var(--surface-2); }
table.tbl tbody tr.deleted td { opacity: .55; text-decoration: line-through; text-decoration-color: var(--danger); }
/* الإجماليات تلتصق بالأسفل: المحاسب يرى المجموع وهو يقرأ أي سطر */
table.tbl tfoot td {
  position: sticky; bottom: 0; z-index: 3;
  padding: 15px 14px; font-weight: 900; background: var(--surface-3); border-top: 2px solid var(--border-strong);
  font-size: 1.05rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 -1px 0 var(--border-strong);
}
/* خطوط فاصلة رأسية بين الأعمدة — تُسهّل تتبّع الصف الطويل بالعين */
table.tbl thead th:not(:last-child),
table.tbl tbody td:not(:last-child),
table.tbl tfoot td:not(:last-child) { border-inline-end: 1px solid var(--border); }
table.tbl thead th:not(:last-child) { border-inline-end-color: var(--border-strong); }

/* تلوين الأعمدة دلالياً (ريال أزرق، ذهب ذهبي) — مطابق لجداولك */
.col-riyal { background: var(--riyal-soft); }
.col-gold  { background: var(--metal-soft); }
/* تلوين نصّ فقط — col-gold/col-riyal لتظليل أعمدة الجداول، ووضعهما على
   عنصر مضمَّن يرسم مربّعاً مظلّلاً خلف الرقم. */
.t-gold  { color: var(--metal); }
.t-riyal { color: var(--riyal); }
th.col-riyal, td.col-riyal { color: color-mix(in srgb, var(--riyal) 78%, var(--text)); }
th.col-gold,  td.col-gold  { color: color-mix(in srgb, var(--metal) 72%, var(--text)); }
.num { text-align: start; font-variant-numeric: tabular-nums; font-weight: 700; }
.tbl .idcell { font-weight: 900; color: var(--brand-2); }

/* ===== بطاقات حساب الموظف ===== */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-row .stat {
  display: grid; gap: 3px; padding: 14px 16px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); position: static;
}
.stat-row .stat::before { display: none; }
.stat-row .stat span { font-size: .82rem; color: var(--text-2); }
.stat-row .stat b { font-size: 1.34rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat-row .stat.big { background: var(--surface-3); border-color: var(--border-strong); }
.stat-row .stat.big b { font-size: 1.6rem; }
.stat-row .neg { color: var(--danger); }
.stat-row .pos { color: var(--ok); }

/* ===== صندوق اختيار الموظف بالبحث ===== */
.combo { position: relative; display: grid; gap: 5px; }
.combo-box { position: relative; }
.combo-in { width: 100%; padding-inline-end: 38px; }
.combo-in.bad { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.combo-clear {
  position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--text-2); cursor: pointer; font-size: 1rem;
  width: 26px; height: 26px; border-radius: 7px; line-height: 1;
}
.combo-clear:hover { background: var(--surface-3); color: var(--text); }
.combo-list {
  position: absolute; z-index: 40; inset-inline: 0; top: calc(100% - 18px);
  margin: 0; padding: 5px; list-style: none; max-height: 264px; overflow-y: auto;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 14px 38px rgba(0, 0, 0, .38);
}
.combo-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: 9px; cursor: pointer; font-size: .94rem;
}
.combo-list li.on, .combo-list li:hover { background: var(--surface-3); }
.combo-list .cno {
  min-width: 30px; text-align: center; font-weight: 900; color: var(--brand-2);
  background: var(--surface); border-radius: 6px; padding: 1px 5px; font-size: .84rem;
}
.combo-list .crole {
  margin-inline-start: auto; font-style: normal; font-size: .76rem; white-space: nowrap;
  color: var(--text-2); background: var(--surface); padding: 2px 8px; border-radius: 999px;
}
.combo-list li > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-none { color: var(--text-2); cursor: default; justify-content: center; }
.combo-none:hover { background: none; }
.combo-hint { font-size: .78rem; }
.combo-hint.err { color: var(--danger); font-weight: 800; }

/* ===== الشارات ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: .82rem; font-weight: 800; line-height: 1;
}
.badge.ok     { background: var(--ok-soft); color: var(--ok); }
.badge.warn   { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info   { background: var(--riyal-soft); color: var(--riyal); }
.badge.gold   { background: var(--gold-soft); color: var(--gold-deep); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.pill { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:999px;
  background: var(--surface-2); border:1px solid var(--border); font-size:.85rem; font-weight:700; }

/* ===== التنبيهات ===== */
/* كتلة لا flex: مع flex يصير كل <b> داخل النصّ عنصراً مستقلاً فيتباعد الكلام
   ويظهر التنبيه مبعثراً على عرض الشاشة. */
.alert { padding: 14px 18px; border-radius: 13px; line-height: 1.75; font-weight: 600; margin-bottom: 18px; border: 1px solid transparent; }
.alert .ic { font-size: 1.4rem; margin-inline-end: 7px; vertical-align: -2px; }
.alert.ok     { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert.err    { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.warn   { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.info   { background: var(--riyal-soft); color: var(--riyal); }
.alert.lock   { background: var(--gold-soft); color: var(--gold-deep); border-color: color-mix(in srgb, var(--gold) 34%, transparent); }

/* ===== أدوات ===== */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.wrap-tools { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.muted { color: var(--text-muted); }
.small { font-size: .86rem; }
.strong { font-weight: 800; }
.center { text-align: center; }
.mt { margin-top: 18px; } .mb { margin-bottom: 18px; }
.page-title { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.page-title .em { font-size: 1.7rem; }
.hr { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.thumb { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; border: 1px solid var(--border); cursor: zoom-in; }
.empty { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty .big { font-size: 3rem; margin-bottom: 10px; opacity: .6; }

/* اختيار الفرع (شرائح) */
.branch-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.branch-tabs a {
  padding: 10px 18px; border-radius: 12px; background: var(--surface); border: 1.5px solid var(--border);
  font-weight: 700; color: var(--text-2); font-size: 1rem;
}
.branch-tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--shadow); }

/* شريط الفلاتر */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; }

/* ===== نافذة منبثقة (Modal) خفيفة ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(8,14,26,.6); backdrop-filter: blur(3px); z-index: 100; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); max-width: 560px; width: 100%; box-shadow: var(--shadow-lg); max-height: 92vh; overflow-y: auto; }
.modal .card-head { position: sticky; top: 0; background: var(--surface); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out; }
.lightbox.show { display: flex; } .lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 12px; }

/* ===== الدخول ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 100% 0, var(--brand-soft), transparent),
              radial-gradient(1000px 500px at 0 100%, var(--gold-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 430px; background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 38px 32px; border: 1px solid var(--border); }
.login-card .logo-lg { width: 74px; height: 74px; border-radius: 20px; margin: 0 auto 18px;
  background: linear-gradient(140deg, var(--gold), var(--gold-deep)); color: #fff; display: grid;
  place-items: center; font-size: 34px; font-weight: 900; box-shadow: var(--shadow); }

/* التنقّل السفلي للجوال */
.bottomnav { display: none; }

/* ===== الاستجابة ===== */
@media (max-width: 980px) {
  :root { --fs-base: 17px; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(100%);
    transition: transform .25s ease; box-shadow: var(--shadow-lg);
  }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(8,14,26,.5); z-index: 39; }
  .scrim.show { display: block; }
  .userchip .who { display: none; }
}

@media (max-width: 640px) {
  :root { --fs-base: 16.5px; --topbar-h: 62px; --tbl-gap: 104px; }
  .content { padding: 14px; }
  .stat .val { font-size: 1.65rem; }
  .card-body, .card-pad { padding: 15px; }
  .topbar h1 { font-size: 1.1rem; }
  /* تنقّل سفلي كبير وواضح */
  .bottomnav {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px 8px;
    justify-content: space-around; box-shadow: 0 -6px 20px rgba(16,27,45,.08);
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem;
    color: var(--text-muted); font-weight: 700; padding: 4px 8px; border-radius: 10px; flex: 1; }
  .bottomnav a .ic { font-size: 1.5rem; }
  .bottomnav a.active { color: var(--brand); }
  .main { padding-bottom: 74px; }
  .btn { min-height: 50px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
}
/* مساحة لمس مريحة على الجوال — بعد كل تصغيرٍ سابق كي تعلو عليه */
@media (max-width: 640px) {
  .btn-sm, .input-sm, .select.input-sm, .pgbtn,
  .searchbox .btn, .searchbox .sb-input { min-height: 44px; }
  .btn-sm { padding-inline: 14px; }
  .pgbtn { min-width: 44px; }
}

/* شاشات كبيرة جداً */
@media (min-width: 1600px) { :root { --fs-base: 19px; } }

/* الطباعة */
@media print {
  .sidebar, .topbar, .bottomnav, .btn, .wrap-tools, .no-print { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; border-color: #ccc; }
  .content { padding: 0; max-width: none; }
  /* الطباعة تحتاج الجدول كاملاً بلا حاوية تمرير ولا رأسٍ لاصق */
  .table-wrap { max-height: none !important; overflow: visible !important; }
  table.tbl thead th, table.tbl tfoot td { position: static !important; box-shadow: none !important; }
  table.tbl thead { display: table-header-group; }
}

/* ===== الإجراءات السريعة (شبكة بلاطات) ===== */
.qa-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.qa-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 100px; padding: 12px 10px; border-radius: 16px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 800; font-size: 1.02rem;
  text-decoration: none; text-align: center; line-height: 1.25; transition: .16s; box-shadow: var(--shadow);
  min-width: 0; overflow-wrap: anywhere; /* لا يتمدّد أفقياً على الشاشات الضيقة */
}
.qa-tile .ic { font-size: 1.95rem; line-height: 1; }
.qa-tile:hover { transform: translateY(-2px); border-color: var(--brand); box-shadow: var(--shadow-lg); }
.qa-tile:focus-visible { outline: none; box-shadow: var(--ring); }
.qa-tile.primary { background: linear-gradient(140deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.qa-tile.gold    { background: linear-gradient(140deg, var(--gold), var(--gold-deep)); color: #fff; border-color: transparent; }
.qa-tile.lg { min-height: 132px; font-size: 1.35rem; gap: 10px; }
.qa-tile.lg .ic { font-size: 2.7rem; }

@media (max-width: 640px) {
  .qa-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .qa-tile { min-height: 92px; font-size: .96rem; border-radius: 14px; padding: 10px 8px; }
  .qa-tile .ic { font-size: 1.75rem; }
  .qa-tile.lg { min-height: 118px; font-size: 1.15rem; }
  .qa-tile.lg .ic { font-size: 2.3rem; }
}
@media (max-width: 360px) { .qa-grid { grid-template-columns: 1fr 1fr; gap: 8px; } }

/* ===== إشعارات منبثقة (Toasts) ===== */
.toast-wrap {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 10px; width: min(460px, 92vw); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 15px 18px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-weight: 700; border-inline-start: 6px solid var(--brand);
  animation: toastIn .38s cubic-bezier(.2,.9,.3,1.2) both;
}
.toast.ok  { border-inline-start-color: var(--ok); }
.toast.err { border-inline-start-color: var(--danger); }
.toast .ic { font-size: 1.5rem; line-height: 1; }
.toast .msg { flex: 1; font-size: 1rem; }
.toast .x { background: none; border: 0; color: var(--text-muted); font-size: 1.15rem; cursor: pointer; padding: 4px; line-height: 1; }
.toast.hide { animation: toastOut .3s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(-18px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-14px) scale(.94); } }

/* ===== نافذة تأكيد أنيقة ===== */
.confirm-box { max-width: 430px; width: 100%; text-align: center; }
.confirm-ic {
  width: 74px; height: 74px; border-radius: 22px; display: grid; place-items: center; font-size: 34px;
  margin: 26px auto 4px; background: var(--danger-soft); color: var(--danger);
}
.confirm-box.kind-ok    .confirm-ic { background: var(--ok-soft);   color: var(--ok); }
.confirm-box.kind-warn  .confirm-ic { background: var(--warn-soft); color: var(--warn); }
.confirm-box h3 { font-size: 1.32rem; margin: 10px 0 4px; }
.confirm-box p  { padding: 0 26px; margin: 0 0 8px; line-height: 1.75; color: var(--text-2); }
.confirm-box .btn-row { padding: 18px 24px 26px; justify-content: center; }

/* ===== ختم الشطب (مَن حذف) ===== */
.delstamp {
  display: inline-flex; align-items: center; gap: 7px; font-size: .82rem; color: var(--text-2);
  background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 10px; padding: 5px 11px; white-space: nowrap;
}
.delstamp .pen { font-size: 1rem; }
.delstamp b { color: var(--danger); }
table.tbl tbody tr.deleted td { opacity: .62; text-decoration: line-through; text-decoration-color: var(--danger); text-decoration-thickness: 2px; }
table.tbl tbody tr.deleted td:last-child { text-decoration: none; }

/* حركات لطيفة */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card, .stat { animation: rise .3s ease both; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== ترقيم الصفحات ===== */
.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 14px 4px 4px; margin-top: 6px;
}
.pager-info { white-space: nowrap; }
.pager-btns { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pgbtn {
  display: inline-grid; place-items: center; min-width: 40px; min-height: 40px; padding: 0 12px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-weight: 700; font-size: .92rem; text-decoration: none;
  transition: background .16s, border-color .16s, transform .12s;
}
.pgbtn:hover:not(.disabled):not(.active) { background: var(--surface-2); border-color: var(--brand); transform: translateY(-1px); }
.pgbtn.active { background: var(--brand); border-color: var(--brand); color: #fff; cursor: default; }
.pgbtn.disabled { opacity: .42; cursor: not-allowed; }
.pgdots { padding: 0 2px; color: var(--text-2); }

/* ===== حقل البحث ===== */
.searchbox { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.searchbox .sb-ic { font-size: 1.05rem; opacity: .75; }
.searchbox .sb-input { max-width: 320px; min-width: 180px; min-height: 42px; }
.searchbox .btn { min-height: 42px; }

@media (max-width: 640px) {
  .pager { justify-content: center; }
  .pgbtn { min-width: 38px; min-height: 38px; padding: 0 9px; }
  .searchbox .sb-input { max-width: 100%; }
}

/* ===== المستندات: زر الكاميرا · المعاينة · نافذة التصوير ===== */
.doc-slot { display: flex; flex-direction: column; gap: 7px; }
.doc-row { display: flex; gap: 7px; align-items: stretch; flex-wrap: wrap; }
/* حقل الملف الأصلي مخفيّ بصرياً لا بـ display:none — الأخير يمنع فتحه بالنقر
   في بعض المتصفحات — وينوب عنه زرّ عربي بجانب زرّ التصوير. */
.doc-row input[type="file"] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.btn-file {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--border-strong);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 800;
  cursor: pointer; min-height: 44px; transition: .15s;
}
/* الزرّان يقتسمان السطر إن اتّسع، وإلا صار كلٌّ منهما بعرض كامل — لا حوافّ مسنّنة */
.doc-row > button { flex: 1 1 auto; justify-content: center; }
.btn-file:hover { background: var(--surface-3); }
.btn-file:active { transform: scale(.97); }
.btn-cam {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--brand); color: #fff; border: none; border-radius: 10px;
  padding: 9px 14px; font: inherit; font-weight: 800; cursor: pointer;
  min-height: 44px; transition: .15s;
}
.btn-cam:hover { filter: brightness(1.08); }
.btn-cam:active { transform: scale(.97); }

.doc-slot.busy { opacity: .6; pointer-events: none; }
.doc-prev {
  position: relative; display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--ok); border-radius: 12px; padding: 8px 10px;
  background: color-mix(in srgb, var(--ok) 7%, transparent);
}
.doc-prev img { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; flex: none; }
.doc-prev .doc-meta { display: flex; flex-direction: column; gap: 2px; font-size: .84rem; line-height: 1.5; }
.doc-prev .doc-meta b { color: var(--ok); }
.doc-prev .doc-meta i { color: var(--text-muted); font-style: normal; }
.doc-prev .doc-x {
  position: absolute; inset-inline-end: 7px; top: 7px; width: 26px; height: 26px;
  border-radius: 50%; border: none; background: var(--danger); color: #fff;
  cursor: pointer; font-size: .82rem; line-height: 1;
}
.doc-prev.pdf { border-color: var(--border-strong); background: var(--surface-2); }

/* نافذة الكاميرا */
.cam-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 3000;
  display: none; align-items: center; justify-content: center; padding: 12px;
}
.cam-bg.show { display: flex; }
.cam {
  width: min(560px, 100%); background: var(--surface); border-radius: 18px;
  overflow: hidden; display: flex; flex-direction: column; max-height: 96vh;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.cam-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cam-head .spacer { flex: 1; }
.cam-view { position: relative; background: #000; aspect-ratio: 4/3; overflow: hidden; }
.cam-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* إطار إرشادي: يساعد على توسيط المستند فتخرج الصورة مقروءة */
.cam-guide {
  position: absolute; inset: 8%; border: 2px dashed rgba(255,255,255,.55);
  border-radius: 12px; pointer-events: none;
}
.cam-msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: #fff; background: rgba(0,0,0,.72); padding: 20px; font-size: .95rem; line-height: 1.8;
}
.cam-bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.cam-hint { color: var(--text-muted); font-size: .82rem; flex: 1; text-align: start; }
.cam-shot {
  width: 62px; height: 62px; border-radius: 50%; border: 4px solid var(--brand);
  background: #fff; cursor: pointer; flex: none; margin-inline: auto; transition: .12s;
}
.cam-shot:hover { transform: scale(1.06); }
.cam-shot:active { transform: scale(.93); background: var(--brand); }

/* حالة المستند في الجداول */
.doc-state { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; }

/* ===== شريط التبويبات (صفحة المورد وغيرها) ===== */
.tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
  border-bottom: 2px solid var(--border); padding-bottom: 0;
}
.tabs .tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 11px 18px; border: none; background: transparent; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 1rem; color: var(--text-2);
  border-radius: 12px 12px 0 0; border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: .15s;
}
.tabs .tab:hover { background: var(--surface-2); color: var(--text); }
.tabs .tab.on {
  color: var(--brand-2); border-bottom-color: var(--brand);
  background: var(--brand-soft); font-weight: 800;
}
.tabs .tab-n {
  min-width: 24px; padding: 1px 7px; border-radius: 999px; font-size: .76rem;
  background: var(--surface-3); color: var(--text-2); font-weight: 800;
}
.tabs .tab.on .tab-n { background: var(--brand); color: #fff; }
.tabs .tab-n.zero { opacity: .45; }
@media (max-width: 560px) {
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs .tab { padding: 10px 13px; white-space: nowrap; }
}

/* ===== شارة المستند في الجداول — واضحة من نظرة واحدة ===== */
.doc-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 5px;
  border-radius: 10px; border: 1.5px solid var(--border-strong); background: var(--surface-2);
  font: inherit; font-size: .78rem; font-weight: 700; color: var(--text-2);
  cursor: default; line-height: 1; text-decoration: none;
}
.doc-chip .doc-ic { font-size: 1rem; }
.doc-chip.img {
  padding: 3px 8px 3px 3px; cursor: zoom-in;
  border-color: var(--ok); background: color-mix(in srgb, var(--ok) 9%, transparent);
  transition: .15s;
}
.doc-chip.img img {
  width: 42px; height: 42px; object-fit: cover; border-radius: 7px;
  border: 1px solid var(--border); display: block;
}
.doc-chip.img:hover { transform: scale(1.05); box-shadow: var(--shadow); }
.doc-chip.img .doc-tx { color: var(--ok); font-size: .9rem; }
.doc-chip.pdf { border-color: var(--riyal); color: var(--riyal); background: var(--riyal-soft); }
.doc-chip.pdf:hover { filter: brightness(.97); }
.doc-chip.off  { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.doc-chip.gone { border-style: dashed; opacity: .7; }
.doc-chip.none { border: none; background: none; color: var(--text-muted); padding: 0; }
@media print { .doc-chip.img { border: none; background: none } .doc-chip.img .doc-tx { display: none } }

/* ==========================================================================
   خانات العيار — مكوّن مخصّص
   ==========================================================================
   المشكلة التي يحلّها: كانت تُبنى من .stat (المصمَّم لبطاقات لوحة عريضة)
   داخل شبكة repeat(عدد العيارات, 1fr). في بطاقة عرضها ~330px يصير عرض
   الخانة ~48px بينما الرقم «100.071» يحتاج ~70px ⇒ يفيض ويُقصّ بصرياً
   (يظهر «.000» فقط) وتلتف التسميات عمودياً. الحل: عرض أدنى مضمون
   يلتفّ إلى صفّين بدل أن ينضغط، ورقم لا ينكسر أبداً.
   ========================================================================== */
.cal-grid {
  display: grid; gap: 8px;
  /* 120px ⇒ عمودان في بطاقة ~340px: أربعة عيارات تصير 2×2 متناظرة بدل
     3+1 غير متوازنة، والخانة تتّسع لرقم من ٧ خانات بلا قصّ */
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.cal-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-inline-start: 4px solid var(--metal); border-radius: 12px;
  padding: 9px 11px; display: flex; flex-direction: column; gap: 2px;
  min-width: 0;                      /* يسمح للخانة بالانكماش داخل الشبكة */
}
.cal-chip .k {
  font-size: .72rem; color: var(--text-muted); font-weight: 700;
  white-space: nowrap;               /* «عيار 24» سطر واحد دائماً */
}
.cal-chip .v {
  font-size: 1.05rem; font-weight: 800; line-height: 1.3;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;   /* لا قصّ صامت */
  direction: ltr; text-align: start;
}
.cal-chip .v small { font-size: .68rem; font-weight: 700; color: var(--text-muted); }
.cal-chip .s {
  font-size: .68rem; color: var(--text-muted); line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-chip.neg .v { color: var(--danger); }
.cal-chip.est   { border-inline-start-color: var(--warn); }
.cal-chip.est .v{ color: var(--warn); }
.cal-chip.ok    { border-inline-start-color: var(--ok); }
.cal-chip.zero  { opacity: .55; }

/* سطر «مفتاح: قيمة» داخل البطاقات — بديل منظّم لصفوف row المتناثرة */
.kv { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; }
.kv + .kv { border-top: 1px dashed var(--border); }
.kv .k { color: var(--text-2); font-size: .86rem; flex: 1; min-width: 0; }
.kv .v {
  font-weight: 800; font-variant-numeric: tabular-nums;
  white-space: nowrap; flex: none;
}
.kv.big .v { font-size: 1.12rem; }

/* بطاقات متساوية الارتفاع ومحتوى ينزل للأسفل بانتظام */
.box-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.box-grid > .card { display: flex; flex-direction: column; }
.box-grid > .card > .card-body { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.box-grid .card-head { gap: 8px; row-gap: 10px; padding: 15px 18px; }
/* سطران مقصودان: العنوان وحده ثم الإجراءات تحته.
   محاولة ضغطهما في سطر واحد كانت تكسر العنوان كلمةً كلمة وتختلف من بطاقة
   لأخرى؛ الفصل يضمن انتظاماً واحداً في كل البطاقات وعلى كل عرض شاشة. */
.box-grid .card-head h3 { font-size: 1.02rem; flex: 1 0 100%; min-width: 0; }
@media (max-width: 640px) { .box-grid .card-head .btn { min-height: 44px !important; } }
.box-grid .card-head .btn {
  flex: none; padding: 6px 12px; font-size: .84rem; min-height: 34px; gap: 6px;
}

/* حاشية البطاقة: تلتصق بالأسفل فتستوي البطاقات بصرياً */
.box-note {
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: .78rem; color: var(--text-muted); line-height: 1.65;
}

/* ===== تحصين عام: لا رقم يُقصّ في أي بطاقة إحصاء بأي شاشة ===== */
.stat .val {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.stat .lbl { overflow-wrap: anywhere; }
.stat .foot { overflow-wrap: anywhere; }

/* ===== الرقم يتكيّف مع عرض بطاقته =====
   قصّ الرقم بثلاث نقاط أسوأ من تصغيره: «250,000.00» كانت تُعرض «…50,000.00»
   فيقرؤها المحاسب خمسين ألفاً. cqi = 1% من عرض البطاقة، فيصغر الخطّ عند
   الحاجة فقط ويبقى 1.9rem في البطاقات الواسعة. */
.stat { container-type: inline-size; }
.stat .val { font-size: clamp(1.2rem, 11cqi, 1.9rem); }
.stat .val small { font-size: .52em; margin-inline-start: 5px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ===== انتظام الشبكة: الأرقام على خطّ واحد والحواشي بالأسفل =====
   بعض العناوين سطر وبعضها سطران، فكانت الأرقام تتراقص رأسياً داخل الصف.
   حجز سطرين للعنوان يضبط بداية الرقم في كل البطاقات على ارتفاع واحد. */
.stat { min-height: 100%; }
.stat .lbl { line-height: 1.35; min-height: 2.7em; align-items: flex-start; }
.stat .lbl .ic { line-height: 1.35; flex: none; }
.stat .foot { margin-top: auto; padding-top: 2px; line-height: 1.5; }

/* في الصفوف المدمجة نلصق الرقم بالأسفل بدل حجز سطرين — أوفر للمساحة
   ويعطي نفس النتيجة: كل الأرقام على خطّ واحد مهما طال العنوان. */
.stat-row .stat { align-content: space-between; }
.stat-row .stat > span { line-height: 1.35; overflow-wrap: anywhere; }
.stat-row .stat b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════ أقسام مطويّة (الإعدادات) ═══════════
   شاشة الإعدادات كانت اثنتي عشرة بطاقة متتابعة؛ الطيّ يجعل الوصول لقسمٍ
   نقرةً واحدة بدل تمريرٍ طويل، ويُبقي الصفحة خفيفة بصرياً. */
.acc {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden;
}
.acc[open] { border-color: var(--border-strong); }
.acc-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px; cursor: pointer;
  font-weight: 800; list-style: none; user-select: none; transition: background .15s;
}
.acc-head::-webkit-details-marker { display: none; }
.acc-head:hover { background: var(--surface-2); }
.acc[open] > .acc-head { border-bottom: 1px solid var(--border); background: var(--surface-2); }
.acc-ic { font-size: 1.3rem; flex: none; }
.acc-title { font-size: 1.05rem; flex: none; }
.acc-hint {
  color: var(--text-muted); font-size: .82rem; font-weight: 500;
  flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acc-arrow { flex: none; color: var(--text-2); font-size: 1.4rem; line-height: 1; transition: transform .18s; }
.acc[open] > .acc-head .acc-arrow { transform: rotate(180deg); }
/* البطاقة داخل القسم لا تُكرّر الإطار والظلّ */
.acc-body > .card { border: 0; box-shadow: none; border-radius: 0; margin: 0; background: transparent; }
.acc-body > .card > .card-head { border-top: 0; }
@media (max-width: 640px) { .acc-hint { display: none; } }


/* ===== منتقي «توحيد العيار» — قطعة واحدة في كل الدفاتر ===== */
.normpick {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--gold-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 11px; min-height: 44px;
}
.normpick .lbl { margin: 0; white-space: nowrap; font-weight: 800; color: var(--text-2); }
.normpick .select { min-height: 34px; padding-block: 4px; border-radius: 9px; min-width: 150px; }
@media (max-width: 700px) {
  .normpick { width: 100%; justify-content: space-between; }
  .normpick .select { flex: 1; min-width: 0; min-height: 44px; }
}


/* ═══ ملاحظات تعامل السوق — استرشادية لا محاسبية ═══
   تُميَّز بصرياً عمداً: حدٌّ متقطّع وخلفيةٌ باهتة ولا رقمَ في عمودٍ مُحاذى.
   المحاسب يقرأ الجداول المحاذاة على أنها أرقامٌ تُجمَع، فلو بدت هذه مثلها
   لحاول مطابقتها بالإقفال — والقصد أن تُقرأ سطراً لا أن تُحسَب. */
.mk-notes { border: 1px dashed var(--border-strong); background: var(--bg-soft); }
.mk-notes .card-head .badge { background: var(--warn-soft); color: var(--warn); }
.mk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mk-list li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
  padding: 8px 10px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); line-height: 1.7;
}
.mk-shop { font-weight: 700; color: var(--gold-deep); }
.mk-shop::after { content: '—'; margin-inline-start: 6px; color: var(--muted); font-weight: 400; }
.mk-bits { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.mk-in, .mk-out, .mk-cash { white-space: nowrap; font-variant-numeric: tabular-nums; }
.mk-in   { color: var(--ok); }
.mk-out  { color: var(--danger); }
.mk-cash { color: var(--muted); }
.mk-note { flex-basis: 100%; color: var(--muted); font-size: .85em; }

@media (max-width: 560px) {
  .mk-list li { flex-direction: column; align-items: stretch; gap: 4px; }
  .mk-bits { flex-direction: column; gap: 2px; }
  .mk-shop::after { content: ''; }
  /* على شاشةٍ ضيّقة المنع من الالتفاف يقصّ النصّ بدل أن يحفظه في سطر */
  .mk-in, .mk-out, .mk-cash { white-space: normal; }
}
@media print {
  .mk-notes { break-inside: avoid; border-color: #999; }
}

/* مفتاح اختيارٍ صغير بجانب زر — لا حقل نموذج */
.chk {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); cursor: pointer; user-select: none;
  padding: 6px 10px; border: 1px dashed var(--border-strong); border-radius: 8px;
  min-height: 44px; white-space: nowrap;
}
/* المربّع نفسه هدفُ اللمس: 40×40 حقيقية على الجوال (لا تحجيماً بـtransform،
   فهو يُصغّر المستطيل المقيس ويُعيدنا لهدفٍ صغير). والمربّع المرئي أصغر منه
   بالحشو مع background-clip: content-box، فيبدو مربّعاً عادياً ومساحتُه إصبع. */
.chk input {
  appearance: none; -webkit-appearance: none;
  width: 40px; height: 40px; margin: 0; flex: none; padding: 10px;
  box-sizing: border-box; cursor: pointer; border-radius: 10px;
  background: var(--surface) content-box;
  box-shadow: inset 0 0 0 2px var(--border-strong);
  transition: box-shadow .15s, background-color .15s;
}
.chk input:checked {
  background: var(--gold-deep) content-box;
  box-shadow: inset 0 0 0 2px var(--gold-deep);
}
.chk input:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }
/* على الشاشة الكبيرة الفأرة دقيقة، فلا حاجة لهدفٍ بحجم الإصبع */
@media (min-width: 561px) { .chk input { width: 26px; height: 26px; padding: 6px; border-radius: 7px; } }
.chk:hover { border-color: var(--gold-deep); color: var(--text); }

/* شبكة اختيارات — فروع محاسب الفرع */
.chk-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.chk-grid .chk { justify-content: flex-start; }

/* ══ لافتة طلبات الموافقة: قرارٌ في مكان الخبر ══
   الطلب وسببُه وصاحبُه في سطرين، والزرّان في آخر الصف — فلا ينتقل
   المسؤول إلى شاشةٍ أخرى ليفعل ما يستطيعه هنا. */
.appr-bar { border: 2px solid var(--warn); }
.appr-bar > .card-head { background: var(--warn-soft); }
.appr-list { list-style: none; margin: 0; padding: 10px 14px 14px; display: grid; gap: 8px; }
.appr-list li {
  display: grid; gap: 2px 12px; align-items: center;
  grid-template-columns: 1fr auto; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.appr-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 9px; line-height: 1.7; }
.appr-meta { grid-column: 1; }
.appr-act  { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; }
@media (max-width: 620px) {
  .appr-list li { grid-template-columns: 1fr; }
  .appr-act { grid-column: 1; grid-row: auto; margin-top: 6px; }
}

/* ══ شجرة الطاقم: محاسب ⇐ فروعه ⇐ مسؤوله وموظفوه ══
   الشبكة تُظهر الفروع جنباً إلى جنب على الشاشة الواسعة، وتنزل عموداً على
   الجوال — فالتنظيم يُقرأ بنظرة في الحالتين. */
.acc-card > .card-head { background: var(--surface-2, #f6f7f9); }
.br-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
/* بلا overflow:hidden — كان يقصّ قائمة «⋯» فتختفي خلف حدّ البطاقة */
.br-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.br-card > .br-head:first-child { border-radius: 11px 11px 0 0; }
.br-card.br-off { opacity: .62; }
.br-head {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 9px 11px; background: var(--warn-soft); border-bottom: 1px solid var(--border);
}
.br-ic { font-size: 1.05em; }
.br-act { display: flex; gap: 6px; align-items: center; }
.br-body { padding: 6px; display: grid; gap: 4px; }

.p-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 9px;
}
.p-row:hover { background: var(--warn-soft); }
.p-row.p-off { opacity: .6; }
.p-name { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.p-name:hover b { text-decoration: underline; }
.p-ini {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--gold-soft, #f3e6c4); color: var(--gold-deep);
}
.p-sub { display: block; font-size: .8em; color: var(--muted); direction: ltr; text-align: start; }
.p-act { display: flex; gap: 4px; align-items: center; flex: none; }
.p-more { position: relative; }
.p-more > summary { list-style: none; cursor: pointer; }
.p-more > summary::-webkit-details-marker { display: none; }
/* قائمة «⋯»: ثابتة الموضع يحسبه JS — فلا يقصّها صندوقٌ ولا تختفي خلف بطاقة،
   وتنقلب لأعلى إن ضاق ما تحتها. */
.p-menu {
  position: fixed; z-index: 9999;
  min-width: 220px; max-width: 92vw; padding: 10px; display: grid; gap: 8px;
  background: var(--surface, #fff); border: 2px solid var(--border);
  border-radius: 12px; box-shadow: 0 14px 40px rgba(0,0,0,.28);
}
.p-menu .btn, .p-menu .select, .p-menu .input { width: 100%; }
.p-more[open] > summary { background: var(--warn-soft); border-radius: 8px; }
/* حجابٌ خفيف يفصل القائمة عمّا تحتها ويُغلقها بأي ضغطة خارجها */
.p-veil { position: fixed; inset: 0; z-index: 9998; background: rgba(0,0,0,.18); }
.select-sm { padding: 4px 8px; font-size: .85em; max-width: 165px; }
@media (max-width: 560px) {
  .br-grid { grid-template-columns: 1fr; }
}

/* نماذج الإضافة داخل البطاقات — مطويّة حتى تُطلب، فلا تُزحم الشجرة */
.add-box { position: relative; }
.add-box > summary { list-style: none; cursor: pointer; }
.add-box > summary::-webkit-details-marker { display: none; }
.add-form {
  display: grid; gap: 7px; padding: 10px; margin-top: 7px;
  background: var(--warn-soft); border: 1px solid var(--border); border-radius: 10px;
}
.add-form .input, .add-form .select { font-size: .9em; padding: 6px 9px; }
.add-form.add-wide { min-width: 300px; }
.p-ini.p-mgr { background: var(--ok-soft, #d9f2e4); color: var(--ok); }
.acc-chief { border: 2px solid var(--danger); }
.acc-chief > .card-head { background: var(--danger-soft, #fde8e8); }

/* بطاقة المستخدم صارت رابطاً لحسابه — تبقى بشكلها وتُبيّن أنها تُضغط */
.userchip { text-decoration: none; color: inherit; cursor: pointer; border-radius: 10px; }
.userchip:hover { background: var(--warn-soft); }

/* ══ لون الفرع: لمسةٌ تُخبر بأيّ فرعٍ أنت قبل أن تقرأ اسمه ══
   خطٌّ علويّ ونقطةٌ فقط — لا تلوينَ كامل يُفسد التباين ولا يُقرأ في الداكن. */
.branch-bar.has-color {
  border-top: 3px solid var(--branch);
  border-radius: 10px 10px 0 0;
  padding-top: 9px;
}
.br-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--branch, var(--muted)); display: inline-block;
  margin-inline-end: 6px; flex: none;
}
.branch-tabs a { display: inline-flex; align-items: center; }
.branch-tabs a.active { box-shadow: inset 0 -3px 0 var(--branch, var(--brand)); }
.br-pill { display: inline-flex; align-items: center; }
.br-card[style*="--branch"] > .br-head { border-top: 3px solid var(--branch); }
/* شبكة الفروع: ثلاثة أعمدة على الشاشة الواسعة */
.br-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (min-width: 1100px) { .br-grid { grid-template-columns: repeat(3, 1fr); } }

/* قائمة موظفي الفرع: مطويّة حتى تُطلب — الشجرة تُقرأ بنظرة لا بتمريرٍ طويل */
.emp-box > summary { list-style: none; cursor: pointer; }
.emp-box > summary::-webkit-details-marker { display: none; }
.emp-sum {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px; border-radius: 9px;
  background: var(--surface-2, #f6f7f9); border: 1px dashed var(--border);
}
.emp-sum:hover { background: var(--warn-soft); }
.emp-chev { margin-inline-start: auto; transition: transform .16s; }
.emp-box[open] > summary .emp-chev { transform: rotate(180deg); }
.emp-box[open] > summary { background: var(--warn-soft); border-style: solid; }
.emp-list { display: grid; gap: 4px; padding-top: 5px; }

/* ══ سِمة الفرع: لونٌ واحد يقود الواجهة كلها ══
   النظام مبنيٌّ على --brand، فإبداله وحده يُلوّن الأزرار وإطارات الحقول
   وحلقة التركيز والتبويبات والترقيم — بلا لمس قواعدها.
   نسختان: فاتحة (--bl) وداكنة (--bd)، والـCSS يختار حسب الوضع. */
body.branded {
  --brand:      var(--bl);
  --brand-2:    var(--bl2);
  --brand-soft: var(--bls);
  --ring:       0 0 0 4px rgba(var(--brand-rgb, 14,124,102), .22);
  --branch:     var(--bl);
}
body.branded { --brand-rgb: var(--brgb); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body.branded {
    --brand: var(--bd); --brand-2: var(--bd2); --brand-soft: var(--bds);
    --ring: 0 0 0 4px rgba(var(--brgb), .34);
    --branch: var(--bd);
  }
}
:root[data-theme="dark"] body.branded {
  --brand: var(--bd); --brand-2: var(--bd2); --brand-soft: var(--bds);
  --ring: 0 0 0 4px rgba(var(--brgb), .34);
  --branch: var(--bd);
}

/* إطارات الحقول تحمل لون الفرع خفيفاً، وتشتدّ عند التركيز */
body.branded .input, body.branded .select, body.branded textarea.input {
  border-color: color-mix(in srgb, var(--brand) 26%, var(--border));
}
body.branded .input:focus, body.branded .select:focus, body.branded textarea.input:focus {
  border-color: var(--brand);
}
/* شارة الفرع في الشريط العلوي — أوضح إشارةٍ على مكانك */
.branch-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px; font-weight: 800; font-size: .92rem;
  color: #fff; background: linear-gradient(140deg, var(--brand), var(--brand-2));
  box-shadow: var(--shadow); white-space: nowrap;
}
.branch-chip .br-dot { background: rgba(255,255,255,.85); width: 8px; height: 8px; }
@media (max-width: 640px) { .branch-chip { display: none; } }

/* ══ تقويم الإقفال ══
   شبكةٌ صغيرة تقول ما أُقفل وما بقي — والأيام التي لم يأتِ دورها باهتةٌ
   ولا تُضغط، فلا يجرّب المستخدم شيئاً ثم يُردّ. */
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px;
}
.cal-w { text-align: center; font-size: .72rem; font-weight: 800; color: var(--text-muted); padding: 3px 0; }
.cal-x { visibility: hidden; }
.cal-d {
  position: relative; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1px; min-height: 46px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); text-decoration: none; font-size: .9rem; transition: transform .12s;
}
a.cal-d:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cal-d b { font-weight: 800; line-height: 1; }
.cal-i { font-size: .68rem; font-style: normal; opacity: .9; }
.cal-n {
  font-size: .62rem; font-style: normal; font-weight: 700;
  padding: 0 5px; border-radius: 999px; background: rgba(0,0,0,.08);
}
.cal-d.is-cert   { background: var(--ok-soft);     border-color: var(--ok);     color: var(--ok); }
.cal-d.is-closed { background: var(--brand-soft);  border-color: var(--brand);  color: var(--brand-2); }
.cal-d.is-next   { background: var(--warn-soft);   border-color: var(--warn);   color: var(--gold-deep);
                   font-weight: 900; box-shadow: 0 0 0 3px var(--warn-soft); }
.cal-d.is-open   { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.cal-d.is-hol    { background: var(--surface-3);   color: var(--text-muted); border-style: dashed; }
.cal-d.is-block  { background: var(--surface);     color: var(--text-muted); opacity: .45; cursor: not-allowed; }
.cal-d.is-today  { outline: 2px solid var(--brand); outline-offset: 1px; }

.cal-key { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: .78rem; color: var(--text-2); }
.cal-key span { display: inline-flex; align-items: center; gap: 5px; }
.cal-key .k { width: 13px; height: 13px; border-radius: 4px; border: 1px solid var(--border); display: inline-block; }
.cal-key .k.is-cert   { background: var(--ok-soft);     border-color: var(--ok); }
.cal-key .k.is-closed { background: var(--brand-soft);  border-color: var(--brand); }
.cal-key .k.is-next   { background: var(--warn-soft);   border-color: var(--warn); }
.cal-key .k.is-open   { background: var(--danger-soft); border-color: var(--danger); }
.cal-key .k.is-hol    { background: var(--surface-3);   border-style: dashed; }
.cal-key .k.is-block  { background: var(--surface);     opacity: .45; }
@media (max-width: 560px) { .cal-d { min-height: 40px; font-size: .82rem; } }
