/* ============================================================
   ورشتي — نظام التصميم
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  /* عائلة واحدة حديثة بتدرّج أوزان — أوضح وأهدأ من خلط خطّين */
  --font: 'Cairo', 'Noto Sans Arabic', 'Segoe UI', system-ui, sans-serif;
  --font-head: var(--font);
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  --fw-normal: 400;
  --fw-med:    500;
  --fw-semi:   600;
  --fw-bold:   700;
  --fw-black:  800;

  /* منحنيات الحركة */
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  --bg:          #f5f7fa;
  --surface:     #ffffff;
  --surface-2:   #fafbfd;
  --surface-3:   #f0f3f7;
  --border:      #e3e8ef;
  --border-soft: #edf1f6;

  --text:   #0d1626;
  --text-2: #46536b;
  --muted:  #78859b;

  --brand:      #102a4a;
  --brand-2:    #1c3f6e;
  --brand-soft: #e9eff7;

  --accent:      #ef7c1b;
  --accent-2:    #cf6407;
  --accent-soft: #fdf0e2;

  --ok: #0f9457;  --ok-soft: #e3f5ea;
  --warn: #d9880a; --warn-soft: #fdf2de;
  --danger: #d94848; --danger-soft: #fdeaea;
  --info: #2477cc; --info-soft: #e7f1fc;

  /* أنصاف أقطار أدقّ — الحواف الحادة أقرب للطابع المؤسسي */
  --radius:    12px;
  --radius-sm: 9px;
  --radius-lg: 16px;

  --shadow-xs: 0 1px 2px rgba(13, 22, 38, .04);
  --shadow-sm: 0 1px 3px rgba(13, 22, 38, .06), 0 1px 2px rgba(13, 22, 38, .04);
  --shadow:    0 4px 14px rgba(13, 22, 38, .07), 0 1px 3px rgba(13, 22, 38, .05);
  --shadow-lg: 0 16px 44px rgba(13, 22, 38, .13), 0 3px 10px rgba(13, 22, 38, .06);

  --ring: 0 0 0 3px rgba(28, 63, 110, .14);
  --ring-accent: 0 0 0 3px rgba(239, 124, 27, .2);

  --sidebar: 226px;
}

[data-theme="dark"] {
  --bg:          #0b1220;
  --surface:     #131c2b;
  --surface-2:   #161f30;
  --surface-3:   #1c2637;
  --border:      #243043;
  --border-soft: #1d2739;

  --text:   #e8edf5;
  --text-2: #a8b5c8;
  --muted:  #7d8b a0;
  --muted:  #7d8ba0;

  --brand:      #16294a;
  --brand-2:    #1f3d68;
  --brand-soft: #1a2740;

  --accent-soft: #2c1f10;
  --ok-soft:     #102a1e;
  --warn-soft:   #2b2110;
  --danger-soft: #2d1618;
  --info-soft:   #101f33;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
  --shadow:    0 6px 20px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.62;
  font-size: 14px;
  font-weight: var(--fw-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

/* ── سلّم العناوين: التدرّج بالوزن والحجم، لا بتغيير الخط ─── */
h1, h2, h3, h4, h5 {
  font-weight: var(--fw-bold);
  line-height: 1.35;
  letter-spacing: -.011em;
}

/* الأرقام الكبيرة تُشدّ قليلاً لتبدو مصمّتة */
.kpi-value, .lc-points .n, .stat-value, .v-facts b, .hero-num {
  font-weight: var(--fw-bold);
  letter-spacing: -.025em;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* عناصر الواجهة: نصف غامق يكفي — الغامق الكامل للعناوين فقط */
.nav a, .card-head h3, .kpi-label, .field label, thead th,
.tabs button, .btn, .badge, .table-count, .board-col > h4,
.crumb, .nav-label, .demo-head {
  font-weight: var(--fw-semi);
}

/* المناطق الكثيفة أقرب تباعداً */
table td, table th, .svc-item, .cell-main, .cell-sub,
.badge, .btn, .chip, .tiny, .small, .hint,
.kpi-label, .kpi-foot, .board-card, .stat-row, .timeline {
  line-height: 1.5;
}
.input, .select, .textarea { line-height: 1.55; }

/* الأرقام بمحاذاة جدولية أينما وردت */
.num, .money, table td, .kpi-value, .stat-value, .plate, .c-code, .delta {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* ── الأيقونات الخطّية ───────────────────────────── */
svg.ico {
  width: 1.15em; height: 1.15em; flex: 0 0 auto;
  display: inline-block; vertical-align: -.18em;
  stroke: currentColor; fill: none;
}
svg.ico.lg { width: 1.4em; height: 1.4em; }
svg.ico.sm { width: 1em; height: 1em; }

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--accent); color: #fff; }

/* ── شريط التمرير: رفيع وشفاف، يظهر عند الحاجة فقط ──── */
:root {
  --scroll-thumb:       rgba(13, 22, 38, .19);
  --scroll-thumb-hover: rgba(13, 22, 38, .34);
}
[data-theme="dark"] {
  --scroll-thumb:       rgba(255, 255, 255, .16);
  --scroll-thumb-hover: rgba(255, 255, 255, .3);
}

/* فايرفوكس فقط — لو طُبّقت scrollbar-width في كروم لأبطلت التنسيق التفصيلي أدناه */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}

/* كروم / إيدج / سفاري */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 100px;
  /* حدّ شفاف يجعل السُمك المرئي ٥ بكسل فقط ويبعده عن حافة الصفحة */
  border: 2px solid transparent;
  background-clip: content-box;
  transition: background-color .18s;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
::-webkit-scrollbar-thumb:active { background: var(--scroll-thumb-hover); background-clip: content-box; }

/* ============================================================
   صفحة الدخول
   ============================================================ */
/* بطاقة واحدة في منتصف الشاشة: نموذج + لوحة تعريفية */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.2rem;
  position: relative;
  background: #eef1f6;
}
/* شبكة تقنية خفيفة + توهّج واحد هادئ — بدل التدرّجات المتراكمة */
.auth-wrap::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(16, 42, 74, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 42, 74, .045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 42%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #000 0%, transparent 78%);
}
.auth-wrap::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(900px 460px at 50% -8%, rgba(28, 63, 110, .1), transparent 70%);
}
[data-theme="dark"] .auth-wrap { background: #0a1120; }
[data-theme="dark"] .auth-wrap::before {
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
}
[data-theme="dark"] .auth-wrap::after {
  background: radial-gradient(900px 460px at 50% -8%, rgba(43, 127, 212, .14), transparent 70%);
}

.auth-split {
  width: 100%; max-width: 940px;
  display: grid; grid-template-columns: 1.02fr .98fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(13, 22, 38, .13), 0 2px 8px rgba(13, 22, 38, .05);
  overflow: hidden;
  position: relative; z-index: 1;
  animation: rise .45s var(--ease-out) both;
}

/* ── نصف النموذج ── */
.auth-form {
  padding: 2.1rem 2.2rem;
  display: flex; flex-direction: column;
}
.auth-brand-row {
  display: flex; align-items: center; gap: .65rem;
  padding-bottom: 1.15rem; margin-bottom: 1.3rem;
  border-bottom: 1px solid var(--border-soft);
}
.auth-brand-row .mark {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
}
.auth-brand-row .mark svg.ico { width: 19px; height: 19px; stroke-width: 1.9; }
.auth-brand-row .name { font-size: .95rem; font-weight: var(--fw-bold); line-height: 1.3; }
.auth-brand-row .tag { font-size: .73rem; color: var(--muted); line-height: 1.35; }

.auth-form h1 {
  font-size: 1.4rem; font-weight: var(--fw-bold);
  letter-spacing: -.025em; margin-bottom: .2rem;
}
.auth-form .sub { color: var(--muted); font-size: .82rem; margin-bottom: 1.1rem; }

/* حقل بأيقونة داخلية */
.auth-form .field { margin-bottom: .85rem; }
.auth-form .field label {
  font-size: .79rem; font-weight: var(--fw-semi);
  color: var(--text-2); margin-bottom: .32rem;
}
.f-icon { position: relative; display: block; }
.f-icon svg.ico {
  position: absolute; inset-inline-start: .8rem; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: #9aa6b8; pointer-events: none; transition: color .15s;
}
/* الأيقونة تقع دائماً على يمين الحقل — حتى لو قُلب اتجاه النص إلى LTR
   لإدخال الأرقام، لذا نستخدم padding-right الصريح لا المنطقي */
.f-icon .input { padding-right: 2.35rem; padding-left: .85rem; padding-block: .66rem; font-size: .92rem; }
.f-icon:focus-within svg.ico { color: var(--brand-2); }

.auth-form .btn-lg { margin-top: .45rem; padding-block: .74rem; font-size: .93rem; }

/* ── نصف اللوحة — بهوية النظام الكحلية ── */
.auth-visual {
  padding: 2.1rem 2rem;
  background: #0c2140;
  color: #fff;
  display: flex; flex-direction: column; gap: 1.5rem;
  position: relative; overflow: hidden;
}
.auth-visual .v-lead { margin-block: auto; }
.auth-visual::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 38px 38px;
}
.auth-visual::after {
  content: ''; position: absolute; inset-block-start: -30%; inset-inline-end: -22%;
  width: 68%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(239, 124, 27, .28), transparent 68%);
}
.auth-visual > * { position: relative; z-index: 1; }

/* شعار اللوحة */
.v-mark {
  display: inline-flex; align-items: center; gap: .5rem;
  font-size: .82rem; font-weight: var(--fw-semi); color: rgba(255,255,255,.75);
}
.v-mark i {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.12);
}
.v-mark svg.ico { width: 15px; height: 15px; color: #ffb066; }

/* عنوان اللوحة */
.v-lead h2 {
  font-size: 1.42rem; font-weight: var(--fw-bold); line-height: 1.5;
  letter-spacing: -.022em; margin-bottom: .5rem;
}
.v-lead h2 span { color: #ffb066; }
.v-lead p { font-size: .82rem; color: rgba(255, 255, 255, .58); line-height: 1.7; }

/* مزايا مختصرة */
.v-points { display: flex; flex-direction: column; gap: .7rem; margin-top: 1.35rem; }
.v-point { display: flex; align-items: center; gap: .6rem; font-size: .8rem; }
.v-point .tick {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 7px;
  background: rgba(255, 255, 255, .09); border: 1px solid rgba(255,255,255,.1);
  color: #7fd8a6; display: grid; place-items: center;
}
.v-point .tick svg.ico { width: 12px; height: 12px; stroke-width: 2.4; }
.v-point span { color: rgba(255, 255, 255, .84); }

/* شريط أرقام أسفل اللوحة */
.v-facts {
  padding-top: 1.15rem;
  border-top: 1px solid rgba(255, 255, 255, .11);
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.v-facts > div { position: relative; padding-inline: .3rem; }
.v-facts > div + div { border-inline-start: 1px solid rgba(255,255,255,.11); }
.v-facts b {
  display: block; font-size: 1.18rem; font-weight: var(--fw-bold);
  line-height: 1.25; letter-spacing: -.03em;
}
.v-facts small { font-size: .68rem; color: rgba(255, 255, 255, .5); }

/* في الوضع الليلي يتقارب لون النصفين، فنفصل بينهما بخط رفيع */
[data-theme="dark"] .auth-visual { border-inline-start: 1px solid rgba(255, 255, 255, .08); }
/* والزر النشط في المبدّل يجب أن يبدو مرتفعاً لا غائراً */
[data-theme="dark"] .tabs { background: rgba(255, 255, 255, .04); border-color: rgba(255,255,255,.06); }
[data-theme="dark"] .tabs button.active {
  background: var(--surface-3); box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

/* الشاشات الصغيرة: النموذج وحده */
@media (max-width: 880px) {
  .auth-wrap { padding: 1.4rem 1rem; }
  .auth-split { grid-template-columns: 1fr; max-width: 420px; }
  .auth-visual { display: none; }
  .auth-form { padding: 1.85rem 1.5rem; }
  .auth-form h1 { font-size: 1.3rem; }
}

.brand-mark {
  display: flex; align-items: center; gap: .85rem;
  font-weight: 700; font-size: 1.4rem; letter-spacing: -.01em;
}
.brand-badge {
  width: 42px; height: 42px; border-radius: 11px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 1.2rem; flex: 0 0 auto;
}
.brand-badge svg.ico { width: 55%; height: 55%; stroke-width: 1.9; }

.auth-foot {
  margin-top: 1rem; padding-top: .8rem;
  border-top: 1px solid var(--border-soft);
  font-size: .74rem; color: var(--muted);
  display: flex; gap: .9rem; flex-wrap: wrap;
}

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: .2rem;
  background: var(--surface-3); padding: .2rem; border-radius: 10px; margin-bottom: 1.05rem;
  border: 1px solid var(--border-soft);
}
.tabs button {
  border: 0; background: transparent; padding: .45rem; border-radius: 8px;
  font-weight: var(--fw-semi); font-size: .83rem; color: var(--muted); cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s;
  display: inline-flex; align-items: center; justify-content: center; gap: .38rem;
}
.tabs button:hover { color: var(--text-2); }
.tabs button.active {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 2px rgba(13,22,38,.07);
}
.tabs button svg.ico { width: 15px; height: 15px; }

/* ============================================================
   عناصر النماذج
   ============================================================ */
/* عنوان مجموعة حقول داخل نموذج طويل */
.form-section {
  font-size: .8rem; font-weight: var(--fw-bold); color: var(--text-2);
  margin: 1.15rem 0 .7rem; padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: .45rem;
}
.form-section::before {
  content: ''; width: 3px; height: 1em; border-radius: 3px;
  background: var(--accent); flex: 0 0 auto;
}

.field { margin-bottom: 1.05rem; }
.field label {
  display: block; font-size: .855rem; font-weight: 600;
  color: var(--text-2); margin-bottom: .42rem;
}
.field label .req { color: var(--danger); }
/* أيقونة صغيرة داخل عنوان الحقل */
.field label svg.ico { width: 14px; height: 14px; vertical-align: -.14em; opacity: .75; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .35rem; line-height: 1.45; }

.input, .select, .textarea {
  width: 100%; padding: .6rem .85rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
  font-size: .9rem;
}
.input::placeholder, .textarea::placeholder { color: #a6b1c2; }
.input:hover:not(:disabled), .select:hover:not(:disabled) { border-color: #d3dbe6; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: var(--ring);
}
.input:disabled, .select:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
.textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
.input.ltr { direction: ltr; text-align: right; }
.input.num-input { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }

.input-group { position: relative; }
.input-group .suffix {
  position: absolute; inset-inline-start: .9rem; top: 50%; transform: translateY(-50%);
  font-size: .82rem; color: var(--muted); pointer-events: none;
}
.input-group .input { padding-inline-start: 3.2rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.grid-2 > .span-2, .grid-3 > .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── الأزرار ──────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .58rem 1.05rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: var(--fw-semi); font-size: .875rem;
  cursor: pointer; transition: background .15s, box-shadow .15s, color .15s, border-color .15s;
  white-space: nowrap; text-decoration: none !important;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ألوان مصمتة بلا تدرّجات — أهدأ وأقرب للطابع المؤسسي */
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-2); }
.btn-accent:focus-visible { box-shadow: var(--ring-accent); }

.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border-color: #d7dee8; }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-block { width: 100%; }
.btn-lg { padding: .72rem 1.3rem; font-size: .94rem; border-radius: var(--radius-sm); }
.btn-sm { padding: .34rem .7rem; font-size: .8rem; border-radius: 7px; gap: .35rem; }
.btn-icon { padding: .42rem; width: 33px; height: 33px; }

/* ============================================================
   التنبيهات والشارات
   ============================================================ */
.alert {
  padding: .75rem .95rem; border-radius: var(--radius-sm);
  font-size: .85rem; display: flex; gap: .6rem; align-items: flex-start;
  margin-bottom: 1rem; line-height: 1.55;
}
.alert .a-ico { flex: 0 0 auto; display: grid; place-items: center; margin-top: .1rem; }
.alert .a-ico svg.ico { width: 17px; height: 17px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok    { background: var(--ok-soft); color: var(--ok); }
.alert-warn  { background: var(--warn-soft); color: var(--warn); }
.alert-info  { background: var(--info-soft); color: var(--info); }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .18rem .58rem; border-radius: 100px;
  font-size: .76rem; font-weight: 700; line-height: 1.6;
  white-space: nowrap;
}
.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(--info-soft); color: var(--info); }
.badge-muted  { background: var(--surface-3); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent-2); }

.tier-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .65rem; border-radius: 100px;
  font-size: .78rem; font-weight: 700; color: #fff;
}

/* ============================================================
   الهيكل العام (بوابة + لوحة)
   ============================================================ */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: #0c2140;
  color: #fff; padding: 1.15rem .7rem;
  display: flex; flex-direction: column; gap: 1rem;
  position: sticky; top: 0;
  /* dvh يستثني شريط عنوان المتصفح على الجوال — بـ vh وحدها يُقصّ أسفل الدرج */
  height: 100vh; height: 100dvh;
  /* التمرير داخل القائمة لا الشريط كله، ليبقى التذييل مثبّتاً */
  overflow: hidden;
  border-inline-start: 1px solid rgba(255,255,255,.06);
  /* الشريط كحليّ في الوضعين، فمقبض التمرير فيه فاتح دائماً */
  --scroll-thumb:       rgba(255, 255, 255, .14);
  --scroll-thumb-hover: rgba(255, 255, 255, .28);
}

.sidebar .brand-mark { font-size: .98rem; padding: .1rem .35rem .2rem; gap: .6rem; }
.sidebar .brand-badge { width: 33px; height: 33px; border-radius: 9px; font-size: .95rem; }
.sidebar .brand-sub { font-size: .68rem; color: rgba(255,255,255,.42); font-weight: var(--fw-normal); }

.nav {
  display: flex; flex-direction: column; gap: .08rem;
  flex: 1; min-height: 0;      /* min-height لازمة ليعمل overflow داخل flex */
  overflow-y: auto; overscroll-behavior: contain;
}
.nav-label {
  font-size: .655rem; letter-spacing: .03em;
  color: rgba(255,255,255,.32); padding: .8rem .58rem .28rem; font-weight: var(--fw-semi);
}
.nav a {
  display: flex; align-items: center; gap: .55rem;
  padding: .48rem .58rem; border-radius: 8px;
  color: rgba(255,255,255,.7); font-size: .825rem; font-weight: var(--fw-med);
  cursor: pointer; transition: background .15s, color .15s;
  text-decoration: none !important; position: relative;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; font-weight: var(--fw-semi); }
/* مؤشّر القسم النشط على حافة الشريط */
.nav a.active::before {
  content: ''; position: absolute; inset-inline-start: -.4rem; top: 50%;
  transform: translateY(-50%); width: 3px; height: 58%;
  border-radius: 3px; background: var(--accent);
}
.nav a .ico { width: 18px; height: 18px; text-align: center; font-size: 1rem; flex: 0 0 auto; opacity: .82; }
.nav a:hover .ico, .nav a.active .ico { opacity: 1; }
.nav a.active .ico { color: var(--accent); }
.nav a .count {
  margin-inline-start: auto; background: var(--accent); color: #fff;
  font-size: .66rem; font-weight: 700; padding: .05rem .36rem; border-radius: 100px;
  min-width: 19px; text-align: center; line-height: 1.55;
}
.nav a .count.quiet { background: rgba(255,255,255,.14); }

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.09); padding-top: .85rem;
  display: flex; align-items: center; gap: .5rem;
  /* يبقى مرئياً مهما طالت القائمة، مع مراعاة شريط الإيماءات في الجوال */
  flex: 0 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.sidebar-foot .avatar { width: 33px; height: 33px; font-size: .85rem; }
.sidebar-foot .icon-btn { width: 28px; height: 28px; border-radius: 8px; }
.sidebar-foot .icon-btn svg.ico { width: 15px; height: 15px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(140deg, var(--accent), #ffa552);
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: .95rem;
}
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who b { display: block; font-size: .81rem; font-weight: var(--fw-semi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .who small { font-size: .7rem; color: rgba(255,255,255,.5); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: rgba(255,255,255,.08); border: 0; color: rgba(255,255,255,.75);
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer; display: grid; place-items: center;
  transition: all .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.18); color: #fff; }
/* زر اللغة نصّي لا أيقونة */
.lang-btn {
  font-family: var(--font); font-size: .72rem; font-weight: var(--fw-bold);
  letter-spacing: .02em;
}

/* الحقول المقلوبة لاتجاه LTR (جوال، SKU، رمز) تحاذي بداية القراءة */
.input.ltr, .input.num-input { text-align: end; }
[dir="ltr"] .input.ltr, [dir="ltr"] .input.num-input { text-align: start; }
/* أيقونة الحقل تتبع اتجاه الصفحة */
[dir="ltr"] .f-icon .input { padding-right: .85rem; padding-left: 2.35rem; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .8rem 1.6rem; display: flex; align-items: center; gap: .9rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.06rem; font-weight: var(--fw-bold); letter-spacing: -.018em; }
.topbar .crumb { font-size: .78rem; color: var(--muted); }
.topbar .spacer { flex: 1; }

.search-box { position: relative; min-width: 250px; }
.search-box .input { padding-inline-start: 2.3rem; }
.search-box .ico {
  position: absolute; inset-inline-start: .72rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); width: 16px; height: 16px; pointer-events: none;
}

.content { padding: 1.5rem 1.6rem 2.4rem; flex: 1; max-width: 1520px; width: 100%; }

.menu-toggle { display: none; }

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; z-index: 100;
    width: 258px; transform: translateX(100%); transition: transform .25s;
    box-shadow: var(--shadow-lg);
  }
  /* في الإنجليزية الدرج على اليسار فينزلق لجهته */
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .content { padding: 1.1rem; }
  .topbar { padding: .9rem 1.1rem; }
  .search-box { min-width: 0; flex: 1; }
}

.scrim {
  position: fixed; inset: 0; background: rgba(10,20,35,.5); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ============================================================
   البطاقات
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-xs);
}
.card-pad { padding: 1.2rem; }
.card-head {
  padding: .95rem 1.2rem; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: .7rem;
}
.card-head h3 { font-size: .9rem; font-weight: var(--fw-semi); letter-spacing: -.008em; }
.card-head .spacer { flex: 1; }
.card-head p { font-size: .8rem; color: var(--muted); }
.card-body { padding: 1.2rem; }
.card-body.tight { padding: .5rem; }

/* عنوان القسم: شريط لوني رفيع + نصّ نصف غامق — علامة بصرية هادئة وموحّدة */
.section-title {
  font-size: .93rem; font-weight: var(--fw-bold); letter-spacing: -.01em;
  margin: 0 0 .85rem; display: flex; align-items: center; gap: .6rem;
  padding-inline-start: .62rem; position: relative; min-height: 1.5rem;
}
.section-title::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 1.05em; border-radius: 3px; background: var(--accent);
}
.section-title.mt-3, .section-title.mt-4 { margin-top: 1.6rem; }
.section-title .spacer { flex: 1; }

.grid { display: grid; gap: 1.1rem; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.split-main { display: grid; grid-template-columns: 1.65fr 1fr; gap: 1.1rem; align-items: start; }
@media (max-width: 1100px) { .split-main { grid-template-columns: 1fr; } }

/* ── مؤشرات الأداء ────────────────────────────────── */
/* هيكل ثابت: رأس (أيقونة + عنوان) ← قيمة ← تذييل بخط فاصل.
   كل البطاقات بنفس الارتفاع والمحاذاة مهما اختلف محتواها. */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem .75rem;
  position: relative;
  display: flex; flex-direction: column;
  min-height: 126px;
  transition: border-color .18s, box-shadow .18s;
}
.kpi:hover { border-color: #d5dde8; box-shadow: var(--shadow-sm); }

.kpi-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .45rem; }

.kpi-ico {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: .9rem; line-height: 1;
  background: var(--brand-soft); color: var(--brand-2);
  animation: kpi-pop .45s var(--ease-out) both;
}
.kpi-ico svg.ico { width: 16px; height: 16px; }
.kpi.ok .kpi-ico     { background: var(--ok-soft);     color: var(--ok); }
.kpi.info .kpi-ico   { background: var(--info-soft);   color: var(--info); }
.kpi.warn .kpi-ico   { background: var(--warn-soft);   color: var(--warn); }
.kpi.danger .kpi-ico { background: var(--danger-soft); color: var(--danger); }
.kpi.accent .kpi-ico { background: var(--accent-soft); color: var(--accent-2); }
@keyframes kpi-pop { from { opacity: 0; transform: scale(.7); } }

.kpi-label {
  font-size: .78rem; color: var(--muted); font-weight: var(--fw-semi);
  line-height: 1.35; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* القيمة تلتصق بأسفل المساحة المتاحة فتتحاذى كل الأرقام أفقياً */
.kpi-main {
  margin-top: auto;
  display: flex; align-items: baseline; gap: .35rem; flex-wrap: wrap;
}
.kpi-value {
  font-size: 1.56rem; font-weight: var(--fw-bold); letter-spacing: -.032em; line-height: 1.08;
}
.kpi-unit { font-size: .76rem; font-weight: var(--fw-med); color: var(--muted); }

.kpi-foot {
  margin-top: .55rem; padding-top: .48rem;
  border-top: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: .4rem;
  font-size: .74rem; color: var(--muted);
  min-height: 1.7rem;
}
.kpi-foot .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* بطاقة بلا تذييل: خط شفاف يحفظ نفس الارتفاع */
.kpi-foot.empty { border-color: transparent; }

.trend-up { color: var(--ok); font-weight: 700; }
.trend-down { color: var(--danger); font-weight: 700; }

/* ============================================================
   الجداول
   ============================================================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
thead th {
  text-align: start; padding: .62rem 1rem; font-weight: var(--fw-semi); font-size: .755rem;
  color: var(--muted); background: var(--surface-2); letter-spacing: .01em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0;
}
tbody td { padding: .72rem 1rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background .12s; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.actions { text-align: end; white-space: nowrap; }
td .cell-main { font-weight: var(--fw-semi); }
td .cell-sub { font-size: .78rem; color: var(--muted); }
/* عمود الاسم لا ينهار حين يزاحمه جدول عريض — الأسماء الإنجليزية أطول */
td .cell-main, td .cell-sub { min-width: 8.5rem; }
td.nowrap .cell-main, td.nowrap .cell-sub { min-width: 0; }
/* قصّ النصوص الطويلة إلى سطرين حتى تبقى ارتفاعات الصفوف متقاربة */
.clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.t-end { text-align: end; }
.t-center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ── تبويبات داخل الصفحة ─────────────────────────── */
.page-tabs {
  display: flex; gap: .3rem; margin-bottom: 1.1rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .35rem;
}
.page-tabs button {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .5rem .85rem; border-radius: var(--radius-sm);
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: .855rem; font-weight: var(--fw-semi); color: var(--muted);
  transition: background .15s, color .15s;
}
.page-tabs button:hover { background: var(--surface-3); color: var(--text-2); }
.page-tabs button.active { background: var(--brand); color: #fff; }
.page-tabs button svg.ico { width: 16px; height: 16px; }
.page-tabs button .pt-badge {
  background: rgba(0, 0, 0, .12); border-radius: 100px;
  padding: 0 .38rem; font-size: .7rem; min-width: 18px; text-align: center;
}
.page-tabs button.active .pt-badge { background: rgba(255, 255, 255, .22); }
.page-tabs button.warn:not(.active) { color: var(--warn); }

/* ── ورقة الجرد ──────────────────────────────────── */
.count-input {
  width: 92px; text-align: center; padding: .35rem .4rem;
  font-variant-numeric: tabular-nums; font-weight: var(--fw-semi);
}
tr.stk-surplus  { background: rgba(15, 148, 87, .07); }
tr.stk-shortage { background: rgba(217, 72, 72, .07); }
tr.stk-pending .var-cell { color: var(--muted); }
.var-cell { font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.var-cell.up   { color: var(--ok); }
.var-cell.down { color: var(--danger); }

/* شريط تقدّم الجرد */
.stk-progress {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .85rem 1.1rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem;
}
.stk-progress .bar { flex: 1; min-width: 180px; height: 8px; margin: 0; }

/* ============================================================
   شاشة الإعدادات: شريط أقسام بأيقونات + لوحة محتوى
   ============================================================ */
.settings-layout {
  display: grid; grid-template-columns: 248px 1fr; gap: 1.1rem; align-items: start;
}

.set-rail {
  position: sticky; top: 5.2rem;
  display: flex; flex-direction: column; gap: .25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .5rem;
}
.set-tab {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .6rem .65rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent;
  cursor: pointer; text-align: start; width: 100%;
  font: inherit; color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
}
.set-tab:hover { background: var(--surface-3); color: var(--text); }
.set-tab.active {
  background: var(--brand-soft); border-color: rgba(28, 63, 110, .18); color: var(--brand);
}
.set-tab .t-ico {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2);
  transition: background .15s, color .15s;
}
.set-tab.active .t-ico { background: var(--brand); color: #fff; }
.set-tab .t-ico svg.ico { width: 16px; height: 16px; }
.set-tab .t-body { min-width: 0; flex: 1; }
.set-tab .t-name { font-size: .85rem; font-weight: var(--fw-semi); line-height: 1.4; }
.set-tab .t-hint {
  font-size: .715rem; color: var(--muted); line-height: 1.45;
  display: block; margin-top: .05rem;
}
.set-tab.active .t-hint { color: var(--brand-2); opacity: .8; }

.set-panel > section { display: none; }
.set-panel > section.active { display: block; animation: rise .28s var(--ease-out) both; }

/* ترويسة القسم داخل اللوحة */
.set-head {
  display: flex; align-items: center; gap: .8rem;
  padding-bottom: .85rem; margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
}
.set-head .h-ico {
  width: 40px; height: 40px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-2);
}
.set-head .h-ico svg.ico { width: 20px; height: 20px; }
.set-head h2 { font-size: 1.02rem; font-weight: var(--fw-bold); letter-spacing: -.015em; }
.set-head p { font-size: .78rem; color: var(--muted); margin-top: .1rem; }

/* مجموعة حقول داخل القسم */
.set-block { margin-bottom: 1.4rem; }
.set-block:last-child { margin-bottom: 0; }
.set-block > h3 {
  font-size: .82rem; font-weight: var(--fw-semi); color: var(--text-2);
  margin-bottom: .8rem; padding-inline-start: .6rem; position: relative;
}
.set-block > h3::before {
  content: ''; position: absolute; inset-inline-start: 0; top: .16em;
  width: 3px; height: 1em; border-radius: 3px; background: var(--accent);
}

/* صفّ مستوى الولاء */
.tier-row {
  display: grid; grid-template-columns: 150px repeat(3, 1fr); gap: .7rem;
  align-items: center; padding: .6rem .75rem;
  border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  margin-bottom: .5rem; background: var(--surface-2);
}
.tier-row .t-lbl { display: flex; align-items: center; gap: .45rem; font-weight: var(--fw-semi); font-size: .87rem; }
.tier-row .field { margin-bottom: 0; }
.tier-row .field label { font-size: .7rem; margin-bottom: .2rem; }
.tier-row .input { padding: .42rem .6rem; font-size: .85rem; }

/* شريط الحفظ الثابت أسفل اللوحة */
.set-save {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  margin-top: 1.3rem; padding: .85rem 1.1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 -4px 16px rgba(13, 22, 38, .07);
}
.set-save .s-note { font-size: .78rem; color: var(--muted); flex: 1; min-width: 160px; }

@media (max-width: 900px) {
  .settings-layout { grid-template-columns: 1fr; }
  /* الشريط يصبح صفّاً أفقياً قابلاً للتمرير */
  .set-rail {
    position: sticky; top: 4.4rem; z-index: 6;
    flex-direction: row; overflow-x: auto;
    gap: .4rem; padding: .45rem; scrollbar-width: none;
  }
  .set-rail::-webkit-scrollbar { display: none; }
  .set-tab { width: auto; flex: 0 0 auto; align-items: center; }
  .set-tab .t-hint { display: none; }
  .set-tab .t-name { white-space: nowrap; }
  .tier-row { grid-template-columns: 1fr 1fr; }
  .tier-row .t-lbl { grid-column: 1 / -1; }
}

/* شريط التنقل السفلي العائم يحجب شريط الحفظ، فنرفعه فوقه */
@media (max-width: 760px) {
  .set-save {
    bottom: calc(82px + env(safe-area-inset-bottom));
    flex-direction: column; align-items: stretch; gap: .5rem;
  }
  .set-save .s-note { text-align: center; }
  .set-save .btn { width: 100%; }
  .set-panel { padding-bottom: 5rem; }
}

/* ── محرّر الصلاحيات ─────────────────────────────── */
.perm-group {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: .9rem; overflow: hidden;
}
.perm-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .85rem; background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft); font-size: .875rem;
}
.perm-head svg.ico { width: 17px; height: 17px; color: var(--brand-2); }
.perm-head .btn-sm { padding: .2rem .5rem; font-size: .72rem; }

.perm-row {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .55rem .85rem; cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  transition: background .13s;
}
.perm-row:last-child { border-bottom: 0; }
.perm-row:hover { background: var(--surface-2); }
.perm-row input { width: 16px; height: 16px; margin-top: .18rem; flex: 0 0 auto; accent-color: var(--brand-2); cursor: pointer; }
.perm-row .p-body { flex: 1; min-width: 0; }
.perm-row .p-name {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  font-size: .845rem; font-weight: var(--fw-semi);
}
.perm-row .p-hint { display: block; font-size: .755rem; color: var(--muted); line-height: 1.5; }
.perm-row .p-key {
  font-family: var(--font-mono); font-size: .66rem; color: var(--muted);
  direction: ltr; flex: 0 0 auto; opacity: .7; padding-top: .18rem;
}
.perm-row .p-flag { font-size: .68rem; font-weight: var(--fw-semi); }

/* استثناء عن افتراضي الدور: منح أو منع */
.perm-row.granted { background: var(--ok-soft); }
.perm-row.granted .p-flag { color: var(--ok); }
.perm-row.revoked { background: var(--danger-soft); }
.perm-row.revoked .p-flag { color: var(--danger); }
.perm-row.granted::before, .perm-row.revoked::before {
  content: ''; position: absolute; inset-inline-start: 0; width: 3px; height: 100%;
}
@media (max-width: 640px) { .perm-row .p-key { display: none; } }

/* ── بيانات المشتري في الفاتورة الضريبية ─────────── */
.tax-party {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .85rem 1rem;
}
.tax-party .tp-head {
  font-size: .755rem; font-weight: var(--fw-semi); color: var(--muted);
  margin-bottom: .6rem; padding-bottom: .45rem;
  border-bottom: 1px solid var(--border-soft);
}

/* ── أعمار الديون ─────────────────────────────────── */
.aging { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.aging-cell {
  padding: .8rem .9rem; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.aging-cell .ag-amt {
  font-size: 1.15rem; font-weight: var(--fw-bold); letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
}
.aging-cell .ag-lbl { font-size: .755rem; color: var(--muted); margin-bottom: .5rem; }
.aging-cell.ok     { border-color: rgba(15, 148, 87, .28); }
.aging-cell.warn   { border-color: rgba(217, 136, 10, .3); }
.aging-cell.danger { border-color: rgba(217, 72, 72, .3); }
.aging-cell.ok .ag-amt     { color: var(--ok); }
.aging-cell.warn .ag-amt   { color: var(--warn); }
.aging-cell.danger .ag-amt { color: var(--danger); }
.bar > i.bg-ok     { background: var(--ok); }
.bar > i.bg-warn   { background: var(--warn); }
.bar > i.bg-danger { background: var(--danger); }
.bar > i.bg-brand  { background: var(--brand-2); }

/* ── شريط تنقّل الصفحات ──────────────────────────── */
[hidden] { display: none !important; }

.pager {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .7rem 1rem;
  border-top: 1px solid var(--border-soft);
}
.pager .pg-info { font-size: .765rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pager .pg-btns { display: flex; align-items: center; gap: .22rem; margin-inline-start: auto; }
.pager .pg {
  min-width: 30px; height: 30px; padding: 0 .45rem;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); border-radius: 8px; cursor: pointer;
  font: inherit; font-size: .79rem; font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums; line-height: 1;
  transition: background .14s, border-color .14s, color .14s;
}
.pager .pg:hover:not(:disabled):not(.active) { background: var(--surface-3); border-color: #d3dbe6; color: var(--text); }
.pager .pg.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .pg:disabled { opacity: .38; cursor: not-allowed; }
.pager .pg-gap { color: var(--muted); padding: 0 .15rem; font-size: .78rem; }

/* شبكات البطاقات المقسّمة: الشريط بلا خط علوي وبمسافة أعلاه */
[data-paged] + .pager { border-top: 0; padding-inline: 0; margin-top: .3rem; }

@media (max-width: 560px) {
  .pager { justify-content: center; }
  .pager .pg-btns { margin-inline-start: 0; }
  .pager .pg-info { width: 100%; text-align: center; }
}

.empty {
  padding: 3rem 1.5rem; text-align: center; color: var(--muted);
}
.empty .ico { font-size: 2.6rem; opacity: .35; display: block; margin-bottom: .7rem; }
.empty .ico svg.ico { width: 40px; height: 40px; margin: 0 auto .2rem; display: block; stroke-width: 1.4; }
.empty h4 { font-weight: 700; color: var(--text-2); margin-bottom: .25rem; font-size: .98rem; }
.empty p { font-size: .86rem; }

/* ============================================================
   المركبات وبطاقات الصيانة
   ============================================================ */
.vehicle-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: box-shadow .2s, transform .2s; cursor: pointer;
}
.vehicle-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.vehicle-head {
  padding: 1.1rem 1.2rem; display: flex; gap: 1rem; align-items: flex-start;
  border-bottom: 1px solid var(--border-soft);
}
.vehicle-icon {
  width: 48px; height: 48px; border-radius: 13px; flex: 0 0 auto;
  background: var(--brand-soft); display: grid; place-items: center; font-size: 1.4rem;
}
.vehicle-title { font-weight: 700; font-size: .96rem; letter-spacing: -.01em; }
.vehicle-sub { font-size: .81rem; color: var(--muted); }

.plate {
  display: inline-flex; align-items: stretch; border: 2px solid var(--text);
  border-radius: 6px; overflow: hidden; background: #fff; color: #111;
  font-weight: 700; font-size: .82rem; line-height: 1; direction: ltr;
}
.plate .p-side {
  background: var(--text); color: #fff; padding: .28rem .3rem;
  font-size: .5rem; display: grid; place-items: center; letter-spacing: .02em;
}
.plate .p-main { padding: .3rem .55rem; display: flex; gap: .45rem; align-items: center; font-variant-numeric: tabular-nums; }

/* حلقة الحالة الصحية */
.health-ring { position: relative; width: 62px; height: 62px; flex: 0 0 auto; }
.health-ring svg { transform: rotate(-90deg); }
.health-ring .val {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-size: .92rem; letter-spacing: -.02em;
}

/* بند صيانة */
.svc-item {
  display: flex; gap: .85rem; align-items: center;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border-soft);
}
.svc-item:last-child { border-bottom: 0; }
.svc-ico {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 1.05rem; background: var(--surface-3);
}
.svc-body { flex: 1; min-width: 0; }
.svc-name { font-weight: 600; font-size: .91rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.svc-meta { font-size: .78rem; color: var(--muted); margin-top: .1rem; }
.svc-side { text-align: end; flex: 0 0 auto; }

.bar { height: 5px; border-radius: 100px; background: var(--surface-3); overflow: hidden; margin-top: .45rem; }
.bar > i { display: block; height: 100%; border-radius: 100px; transition: width .6s cubic-bezier(.4,0,.2,1); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; display: inline-block; }

/* ============================================================
   بطاقة الولاء
   ============================================================ */
.loyalty-card {
  border-radius: var(--radius-lg); padding: 1.7rem;
  color: #fff; position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.loyalty-card::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(600px 300px at 85% -20%, rgba(255,255,255,.22), transparent 65%),
    radial-gradient(400px 300px at 10% 120%, rgba(0,0,0,.22), transparent 60%);
}
.loyalty-card::after {
  content: ''; position: absolute; inset-block-start: -40%; inset-inline-start: -10%;
  width: 55%; height: 180%; background: rgba(255,255,255,.05);
  transform: rotate(18deg);
}
.loyalty-card > * { position: relative; z-index: 1; }

.lc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.4rem; }
.lc-tier { font-size: .8rem; opacity: .8; font-weight: 600; }
.lc-tier-name { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: .45rem; }
.lc-points { text-align: end; }
.lc-points .n { font-size: 2.1rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.lc-points .l { font-size: .78rem; opacity: .8; }
.lc-name { font-size: 1.02rem; font-weight: 700; }
.lc-code { font-size: .8rem; opacity: .7; direction: ltr; text-align: start; font-variant-numeric: tabular-nums; }
.lc-progress { margin-top: 1.3rem; }
.lc-progress .lbl { display: flex; justify-content: space-between; font-size: .8rem; opacity: .88; margin-bottom: .45rem; }
.lc-bar { height: 7px; background: rgba(255,255,255,.22); border-radius: 100px; overflow: hidden; }
.lc-bar > i { display: block; height: 100%; background: #fff; border-radius: 100px; transition: width .8s cubic-bezier(.4,0,.2,1); }

/* بطاقة مكافأة */
.reward {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.15rem; display: flex; flex-direction: column; gap: .7rem;
  transition: box-shadow .2s, transform .2s; position: relative;
}
.reward.eligible { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.reward:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.reward .r-ico { font-size: 1.9rem; line-height: 1; }
.reward .r-name { font-weight: 700; font-size: .98rem; line-height: 1.4; }
.reward .r-desc { font-size: .82rem; color: var(--muted); line-height: 1.5; flex: 1; }
.reward .r-foot { display: flex; align-items: center; gap: .6rem; padding-top: .4rem; margin-top: auto; border-top: 1px solid var(--border-soft); }
.reward .r-list { display: flex; flex-direction: column; gap: .3rem; }
.reward .r-list > div { display: flex; justify-content: space-between; gap: .5rem; font-size: .78rem; }
.reward .r-more { color: var(--muted); font-size: .75rem; }
.reward .r-cost { font-weight: 700; font-size: 1rem; color: var(--accent-2); }
.reward .r-cost small { font-size: .75rem; font-weight: 600; color: var(--muted); }
.reward.locked { opacity: .68; }

/* كوبون */
.coupon {
  border: 2px dashed var(--accent); border-radius: var(--radius);
  background: var(--accent-soft); padding: 1rem 1.15rem;
  display: flex; align-items: center; gap: 1rem;
}
.coupon.used, .coupon.expired { border-color: var(--border); background: var(--surface-3); opacity: .75; }
.coupon .c-code {
  font-family: var(--font-mono);
  font-weight: 700; font-size: 1.05rem; letter-spacing: .06em; direction: ltr;
  background: var(--surface); padding: .35rem .7rem; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer;
}

/* ============================================================
   الخط الزمني
   ============================================================ */
.timeline { position: relative; padding-inline-start: 1.7rem; }
.timeline::before {
  content: ''; position: absolute; inset-block: .6rem; inset-inline-start: .38rem;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: 1.5rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ''; position: absolute; inset-inline-start: -1.7rem; top: .45rem;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
  transform: translateX(50%);
}
.tl-date { font-size: .79rem; color: var(--muted); font-weight: 600; }
.tl-title { font-weight: 700; font-size: .95rem; margin: .1rem 0 .25rem; }
.tl-body { font-size: .86rem; color: var(--text-2); line-height: 1.6; }

/* ============================================================
   النوافذ المنبثقة
   ============================================================ */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(9,18,32,.55);
  backdrop-filter: blur(3px); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2.5rem 1rem; overflow-y: auto;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-scrim.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 620px; box-shadow: var(--shadow-lg);
  transform: translateY(-14px) scale(.985); transition: transform .22s;
  margin: auto;
}
.modal-scrim.show .modal { transform: none; }
.modal.wide { max-width: 1000px; }
.modal.narrow { max-width: 440px; }
.modal-head {
  padding: 1.2rem 1.5rem; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: .8rem;
}
.modal-head h3 { font-size: 1.02rem; font-weight: 700; flex: 1; letter-spacing: -.01em; }
.modal-body { padding: 1.5rem; }
.modal-foot {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border-soft);
  display: flex; gap: .6rem; justify-content: flex-end; background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── الإشعارات العائمة ────────────────────────────── */
.toasts {
  position: fixed; inset-block-end: 1.5rem; inset-inline-start: 1.5rem;
  z-index: 300; display: flex; flex-direction: column; gap: .6rem; max-width: 380px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-inline-start: 4px solid var(--ok);
  border-radius: var(--radius-sm); padding: .8rem 1rem;
  box-shadow: var(--shadow); font-size: .89rem; font-weight: 500;
  display: flex; gap: .6rem; align-items: flex-start;
  animation: toast-in .28s cubic-bezier(.2,.9,.3,1.2);
}
.toast.error { border-inline-start-color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }
.toast.info { border-inline-start-color: var(--info); }
.toast .x { margin-inline-start: auto; cursor: pointer; opacity: .4; background: none; border: 0; font-size: 1.1rem; line-height: 1; }
.toast .x:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px); } }

/* ── التحميل ──────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px; border: 2.5px solid var(--border);
  border-top-color: var(--brand-2); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 3.5rem; display: grid; place-items: center; gap: .8rem; color: var(--muted); font-size: .9rem; }
.loading .spinner { width: 28px; height: 28px; border-width: 3px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--border-soft) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 8px;
}
@keyframes sk { to { background-position: -200% 0; } }

/* ── مساعدات ──────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .35rem; } .gap-2 { gap: .6rem; } .gap-3 { gap: .9rem; } .gap-4 { gap: 1.2rem; }
.flex-1 { flex: 1; } .flex-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: .4rem; } .mt-2 { margin-top: .8rem; } .mt-3 { margin-top: 1.2rem; } .mt-4 { margin-top: 1.7rem; }
.mb-1 { margin-bottom: .4rem; } .mb-2 { margin-bottom: .8rem; } .mb-3 { margin-bottom: 1.2rem; } .mb-4 { margin-bottom: 1.7rem; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.bold { font-weight: 700; }
.strong { font-weight: 700; }
.hidden { display: none !important; }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); }
.text-danger { color: var(--danger); } .text-info { color: var(--info); }
.text-accent { color: var(--accent-2); }
.divider { height: 1px; background: var(--border-soft); margin: 1.1rem 0; }
.pill-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  padding: .35rem .8rem; border-radius: 100px; border: 1px solid var(--border);
  background: var(--surface); font-size: .84rem; font-weight: 600; cursor: pointer;
  color: var(--text-2); transition: all .15s; white-space: nowrap;
}
.chip:hover { border-color: var(--brand-2); color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* الرسم البياني البسيط */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.spark > i {
  flex: 1; background: linear-gradient(180deg, var(--brand-2), var(--brand));
  border-radius: 3px 3px 0 0; min-height: 3px; opacity: .85;
  transition: opacity .15s; position: relative;
}
.spark > i:hover { opacity: 1; }

/* الطباعة */
@media print {
  .sidebar, .topbar, .no-print, .toasts, .mobile-nav { display: none !important; }
  .app { grid-template-columns: 1fr; }
  body { background: #fff; }
  .content { padding: 0; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}

/* ============================================================
   الحركة — ظهور العناصر وعدّ الأرقام
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* البطاقات تظهر بتتابع لطيف */
.reveal { animation: rise .5s var(--ease-out) both; }
.reveal-stagger > * { animation: rise .5s var(--ease-out) both; }
.reveal-stagger > *:nth-child(1) { animation-delay: .02s; }
.reveal-stagger > *:nth-child(2) { animation-delay: .06s; }
.reveal-stagger > *:nth-child(3) { animation-delay: .10s; }
.reveal-stagger > *:nth-child(4) { animation-delay: .14s; }
.reveal-stagger > *:nth-child(5) { animation-delay: .18s; }
.reveal-stagger > *:nth-child(6) { animation-delay: .22s; }
.reveal-stagger > *:nth-child(7) { animation-delay: .26s; }
.reveal-stagger > *:nth-child(8) { animation-delay: .30s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ── بطاقة مؤشر محسّنة ────────────────────────────── */
.kpi {
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s;
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

/* شارة التغيّر عن الفترة السابقة */
.delta {
  display: inline-flex; align-items: center; gap: .15rem;
  font-weight: 700; font-size: .73rem;
  padding: .08rem .4rem; border-radius: 6px;
  flex: 0 0 auto;
  animation: rise .4s var(--ease-out) .55s both;
}
.delta.up   { color: var(--ok); background: var(--ok-soft); }
.delta.down { color: var(--danger); background: var(--danger-soft); }
.delta.flat { color: var(--muted); background: var(--surface-3); }

/* ============================================================
   الرسوم البيانية
   ============================================================ */
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border-soft); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .area-path { transition: opacity .4s; }
.chart .line-path {
  fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: var(--len); stroke-dashoffset: var(--len);
  animation: draw 1.1s var(--ease-out) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.chart .dot { transition: r .15s; cursor: pointer; }
.chart .dot:hover { r: 5; }

.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .7rem; }
.chart-legend span {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .8rem; color: var(--text-2);
}
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* الحلقة الدائرية */
.donut-wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.donut { flex: 0 0 auto; }
.donut circle { transition: stroke-dashoffset 1s var(--ease-out); }
.donut-center { text-anchor: middle; }
.donut-center .n { font-size: 20px; font-weight: 700; fill: var(--text); font-family: var(--font); }
.donut-center .l { font-size: 9px; fill: var(--muted); font-family: var(--font); }

/* الأعمدة */
.spark > i { animation: grow .8s var(--ease-out) both; transform-origin: bottom; }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* أشرطة التقدم تتحرك عند الظهور */
.bar > i { transition: width .9s var(--ease-out); }

/* ============================================================
   الجداول — الفرز والعرض على الجوال
   ============================================================ */
th.sortable {
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: color .15s;
}
th.sortable:hover { color: var(--text); }
th.sortable::after {
  content: '⇅'; opacity: .3; margin-inline-start: .3rem; font-size: .85em;
}
th.sortable.asc::after  { content: '↑'; opacity: 1; color: var(--brand-2); }
th.sortable.desc::after { content: '↓'; opacity: 1; color: var(--brand-2); }

.table-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .8rem 1.3rem; border-bottom: 1px solid var(--border-soft);
}
.table-count { font-size: .82rem; color: var(--muted); font-weight: 600; }

/* ============================================================
   لوحة اليوم (أعمدة الحالة)
   ============================================================ */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; align-items: start; }
.board-col {
  background: var(--surface-3); border-radius: var(--radius);
  padding: .8rem; min-height: 120px;
}
.board-col > h4 {
  font-size: .85rem; font-weight: 700; color: var(--text-2);
  display: flex; align-items: center; gap: .45rem; margin-bottom: .7rem; padding: 0 .25rem;
}
.board-col > h4 .n {
  margin-inline-start: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px; padding: 0 .45rem; font-size: .75rem;
}
.board-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .75rem .85rem; margin-bottom: .6rem;
  cursor: pointer; transition: transform .18s var(--ease), box-shadow .18s;
  border-inline-start: 3px solid var(--info);
}
.board-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.board-card.st-open        { border-inline-start-color: var(--info); }
.board-card.st-in_progress { border-inline-start-color: var(--warn); }
.board-card.st-ready       { border-inline-start-color: var(--accent); }
.board-card .t { font-weight: 700; font-size: .88rem; }
.board-card .s { font-size: .78rem; color: var(--muted); margin-top: .1rem; }

/* ============================================================
   المخزون والضمانات
   ============================================================ */
.stock-pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-weight: 700; font-size: .8rem; padding: .12rem .5rem; border-radius: 100px;
}
.stock-pill.in   { background: var(--ok-soft); color: var(--ok); }
.stock-pill.low  { background: var(--warn-soft); color: var(--warn); }
.stock-pill.out  { background: var(--danger-soft); color: var(--danger); }

.warranty {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem .9rem; border-radius: var(--radius-sm);
  background: var(--ok-soft); border: 1px solid transparent;
}
.warranty.expiring { background: var(--warn-soft); }
.warranty.expired  { background: var(--surface-3); opacity: .7; }
.warranty .w-ico { font-size: 1.3rem; flex: 0 0 auto; }

/* ============================================================
   شريط التنقل السفلي (الجوال)
   مطابق لنمط إنستقرام: أيقونات خطية أحادية اللون بلا نصوص،
   تتحول من مفرّغة إلى مصمتة عند التفعيل، وزر إنشاء مربع مقوّس.
   ============================================================ */
.mobile-nav { display: none; }

@media (max-width: 760px) {
  /* شريط عائم بأيقونة واسم قسم صغير تحتها */
  .mobile-nav {
    display: grid;
    position: fixed; z-index: 80;
    inset-inline: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    grid-auto-flow: column; grid-auto-columns: 1fr;
    align-items: center;
    height: 62px; padding: 0 4px;
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--border);
    box-shadow: 0 10px 28px rgba(16, 42, 74, .15), 0 2px 6px rgba(16, 42, 74, .07);
  }

  .mobile-nav a {
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    height: 54px; margin: 0 1px;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none !important;
    -webkit-tap-highlight-color: transparent;
    transition: color .18s, background .18s;
  }

  /* اسم القسم — صغير ومتناسق.
     line-height لا تقلّ عن 1.45: الحروف العربية (ي، ج، ط، ل) لها ذيل
     تحت السطر، ومع overflow:hidden كانت تُقصّ ٣٫٦ بكسل من كل كلمة. */
  .mobile-nav a .lbl {
    font-family: var(--font-head);
    font-size: .59rem; font-weight: 600; line-height: 1.6;
    letter-spacing: -.01em; white-space: nowrap;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis;
    padding: 0 2px;
  }

  .mobile-nav svg {
    width: 21px; height: 21px; display: block;
    transition: transform .14s ease;
  }
  .mobile-nav a:active svg { transform: scale(.88); }

  /* المفرّغة ظاهرة والمصمتة مخفية — والعكس عند التفعيل */
  .mobile-nav .ic-fill { display: none; }
  .mobile-nav a.active .ic-out { display: none; }
  .mobile-nav a.active .ic-fill { display: block; }

  /* التبويب النشط: لون العلامة التجارية + خلفية خفيفة */
  .mobile-nav a.active {
    color: var(--accent-2);
    background: var(--accent-soft);
  }
  .mobile-nav a.active .lbl { font-weight: 700; }

  /* نقطة التنبيه الحمراء */
  .mobile-nav a .dot {
    position: absolute; top: 7px; inset-inline-start: calc(50% + 6px);
    width: 8px; height: 8px; border-radius: 50%;
    background: #ff3040;
    border: 2px solid var(--surface);
  }

  /* تبويب الحساب: صورة دائرية */
  .mobile-nav a.avatar-tab .av {
    width: 21px; height: 21px; border-radius: 50%;
    background: linear-gradient(140deg, var(--accent), #ffa552);
    color: #fff; font-size: .55rem; font-weight: 700;
    display: grid; place-items: center;
    transition: transform .14s ease;
  }
  .mobile-nav a.avatar-tab:active .av { transform: scale(.88); }

  .main { padding-bottom: 5.8rem; }

  /* شريط البحث يأخذ سطراً كاملاً بدل أن ينضغط */
  .topbar { flex-wrap: wrap; row-gap: .6rem; }
  .topbar .search-box { order: 10; flex: 1 0 100%; min-width: 100%; }
  .topbar h1 { font-size: 1.1rem; }

  /* زر الإضافة موجود في الشريط السفلي — لا داعي لتكراره فوق */
  .topbar #newOrderBtn { display: none; }

  /* الصفحة فيها بحثها الخاص — لا نكرّر بحث الشريط العلوي */
  .topbar .search-box.dup-search { display: none; }
}

/* ── الجداول تتحول إلى بطاقات على الشاشات الصغيرة ── */
@media (max-width: 700px) {
  table.cards-sm thead { display: none; }
  table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: 100%; }
  table.cards-sm tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: .6rem; padding: .35rem .15rem; background: var(--surface);
    box-shadow: var(--shadow-xs);
  }
  table.cards-sm td {
    border: 0 !important; padding: .28rem .75rem;
    display: flex; justify-content: space-between; align-items: center; gap: .8rem;
    text-align: start !important;
    font-size: .82rem;
  }
  /* أول خلية = عنوان البطاقة: بارزة وبلا تسمية */
  table.cards-sm td:first-child {
    padding-bottom: .45rem; margin-bottom: .3rem;
    border-bottom: 1px solid var(--border-soft) !important;
  }
  table.cards-sm td:first-child::before { display: none; }
  table.cards-sm td:first-child .cell-main { font-size: .9rem; }
  /* في وضع البطاقات لا حاجة لأرضية العرض */
  table.cards-sm td .cell-main, table.cards-sm td .cell-sub { min-width: 0; }
  table.cards-sm td::before {
    content: attr(data-label);
    font-size: .73rem; color: var(--muted); font-weight: 600; flex: 0 0 auto;
  }
  table.cards-sm td:not([data-label])::before { content: ''; }
  table.cards-sm td.actions { justify-content: flex-start; flex-wrap: wrap; }
  table.cards-sm td.t-end, table.cards-sm td.t-center { text-align: start !important; }

  /* ── شبكات ومسافات ── */
  .grid { gap: .65rem; }
  /* البطاقات الصغيرة عمودان، والبطاقات العريضة عمود واحد */
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2, .split-main { grid-template-columns: 1fr; }
  .split-main { gap: .65rem; }

  /* أمان ضد التمدّد الأفقي: يسمح لأي عنصر بالانكماش داخل الشبكات */
  .grid > *, .split-main > *, .card > *, .flex > * { min-width: 0; }
  .content, .main { max-width: 100%; overflow-x: clip; }
  .content { padding: .8rem .7rem; }
  .mb-3, .mt-3 { margin-bottom: .8rem; }
  .mt-4 { margin-top: 1.1rem; }

  /* ── بطاقات المؤشرات ── */
  .kpi { padding: .75rem .8rem; min-height: 108px; }
  .kpi-head { gap: .45rem; margin-bottom: .35rem; }
  .kpi-ico { width: 27px; height: 27px; font-size: .82rem; border-radius: 8px; }
  .kpi-label { font-size: .7rem; }
  .kpi-value { font-size: 1.22rem; }
  .kpi-unit { font-size: .68rem; }
  .kpi-foot { font-size: .66rem; margin-top: .45rem; padding-top: .4rem; min-height: 1.5rem; }
  .delta { font-size: .64rem; padding: .05rem .3rem; }

  /* ── البطاقات والعناوين ── */
  .card-body, .card-pad { padding: .85rem; }
  .card-head { padding: .75rem .85rem; }
  .card-head h3 { font-size: .88rem; }
  .section-title { font-size: .93rem; margin-bottom: .6rem; }
  .modal-body { padding: 1rem; }
  .modal-foot, .modal-head { padding: .85rem 1rem; }
  .modal-scrim { padding: 1rem .6rem 5rem; }
  .modal-head h3 { font-size: .95rem; }

  /* ── الأزرار وأشرطة الأدوات ── */
  .btn { padding: .55rem .9rem; font-size: .84rem; }
  .btn-sm { padding: .34rem .6rem; font-size: .76rem; }
  .pill-row { gap: .35rem; }
  .chip { padding: .28rem .65rem; font-size: .78rem; }
  .table-toolbar { padding: .6rem .85rem; }

  /* ── عناصر القوائم ── */
  .svc-item { padding: .65rem .8rem; gap: .6rem; }
  .svc-ico { width: 32px; height: 32px; font-size: .9rem; border-radius: 9px; }
  .svc-name { font-size: .85rem; }
  .svc-meta { font-size: .73rem; }
  .timeline { padding-inline-start: 1.4rem; }

  /* ── لوحة اليوم ── */
  .board { grid-template-columns: 1fr; gap: .65rem; }
  .board-col { padding: .65rem; }

  /* ── بطاقة الولاء ── */
  .loyalty-card { padding: 1.15rem; border-radius: 16px; }
  .lc-points .n { font-size: 1.7rem; }
  .lc-tier-name { font-size: 1.25rem; }

  /* ── النماذج ── */
  .field { margin-bottom: .8rem; }
  .grid-2, .grid-3 { gap: 0; }
}

/* عمود واحد فقط على الشاشات الضيقة جداً */
@media (max-width: 359px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ============================================================
   تفاصيل إضافية
   ============================================================ */
.stat-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--border-soft);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row .lbl { font-size: .84rem; color: var(--text-2); display: flex; align-items: center; gap: .45rem; }
.stat-row .val { font-weight: 700; font-size: .9rem; }

.mini-bar { display: flex; height: 8px; border-radius: 100px; overflow: hidden; background: var(--surface-3); }
.mini-bar > i { display: block; height: 100%; transition: width .9s var(--ease-out); }

.tag-list { display: flex; gap: .35rem; flex-wrap: wrap; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .9rem; }
.info-grid > div > .k { font-size: .74rem; color: var(--muted); }
.info-grid > div > .v { font-weight: 700; font-size: .92rem; }

.copyable { cursor: pointer; border-bottom: 1px dashed var(--border); }
.copyable:hover { color: var(--brand-2); border-color: var(--brand-2); }

details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '▾'; display: inline-block; transition: transform .2s;
  margin-inline-end: .3rem; color: var(--muted);
}
details[open] > summary::before { transform: rotate(-90deg); }

.sticky-actions {
  position: sticky; bottom: 0; background: var(--surface);
  border-top: 1px solid var(--border); padding: .8rem 1.3rem;
  display: flex; gap: .6rem; justify-content: flex-end;
}

/* ============================================================
   شاشة الفرع — مربّعات كبيرة تُلمس بالإصبع
   ------------------------------------------------------------
   مصمّمة لتابلت الكاونتر: كل قسم مربّع واحد بمساحة لمس مريحة،
   والعدّاد على زاويته يقول ما يحتاج انتباهاً قبل أن تدخله.
   ============================================================ */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: .8rem;
}

.hub-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .65rem; aspect-ratio: 1 / 1; padding: 1rem .65rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  color: var(--text); text-align: center; text-decoration: none;
  transition: transform .14s var(--ease), box-shadow .14s var(--ease), border-color .14s;
  -webkit-tap-highlight-color: transparent;
}
.hub-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d7dfea; }
.hub-tile:active { transform: scale(.975); box-shadow: var(--shadow-xs); }
.hub-tile:focus-visible { outline: none; box-shadow: var(--ring); }

.hub-ico {
  width: 56px; height: 56px; border-radius: 17px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-2);
  transition: background .14s, color .14s;
}
.hub-ico svg { width: 26px; height: 26px; }
.hub-tile:hover .hub-ico { background: var(--brand); color: #fff; }
.hub-name { font-weight: var(--fw-semi); font-size: .875rem; line-height: 1.35; }

/* الشارة في زاوية المربّع — تُظهر ما ينتظر العمل.
   شكلها مستقل عن شارة القائمة لأن خلفيتها فاتحة لا داكنة. */
.hub-tile .count {
  position: absolute; inset-block-start: .6rem; inset-inline-end: .6rem;
  background: var(--accent); color: #fff;
  font-size: .7rem; font-weight: var(--fw-bold); line-height: 1.6;
  min-width: 22px; padding: .05rem .4rem; border-radius: 100px; text-align: center;
}
.hub-tile .count.quiet { background: var(--surface-3); color: var(--text-2); }

/* نبرات لونية تميّز الأقسام التي تحتاج تدخّلاً */
.hub-tile.tone-accent .hub-ico { background: var(--accent-soft); color: var(--accent-2); }
.hub-tile.tone-accent:hover .hub-ico { background: var(--accent); color: #fff; }
.hub-tile.tone-warn .hub-ico { background: var(--warn-soft); color: var(--warn); }
.hub-tile.tone-warn:hover .hub-ico { background: var(--warn); color: #fff; }
.hub-tile.tone-ok .hub-ico { background: var(--ok-soft); color: var(--ok); }
.hub-tile.tone-ok:hover .hub-ico { background: var(--ok); color: #fff; }
.hub-tile.tone-info .hub-ico { background: var(--info-soft); color: var(--info); }
.hub-tile.tone-info:hover .hub-ico { background: var(--info); color: #fff; }

/* صفّ الإجراءات السريعة أعلى الشاشة */
.hub-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(186px, 1fr)); gap: .7rem;
}
.hub-act {
  min-height: 60px; font-size: .98rem; border-radius: var(--radius);
  gap: .55rem;
}
.hub-act svg.ico { width: 20px; height: 20px; }

/* شريط الترحيب */
.hub-hello { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.hub-hello .hh-main { flex: 1; min-width: 210px; }
.hub-hello .hh-name { font-size: 1.3rem; font-weight: var(--fw-bold); line-height: 1.3; }
.hub-hello .hh-date { opacity: .75; font-size: .88rem; margin-top: .15rem; }
.hub-stats { display: flex; gap: 1.6rem; flex-wrap: wrap; }
.hub-stats .hs-label { font-size: .74rem; opacity: .72; }
.hub-stats .hs-value { font-size: 1.35rem; font-weight: var(--fw-bold); line-height: 1.25; }

/* ============================================================
   وضع التابلت
   ------------------------------------------------------------
   يُفعَّل تلقائياً لموظف الفرع، ويمكن لأي موظف تشغيله من الشريط
   الجانبي. يكبّر مساحات اللمس ويحوّل القائمة إلى درج منزلق
   ليأخذ المحتوى عرض الشاشة كاملاً.
   ============================================================ */
html.tablet body { font-size: 15.5px; }

html.tablet .app { grid-template-columns: 1fr; }
html.tablet .sidebar {
  position: fixed; inset-inline-start: 0; top: 0; z-index: 100;
  width: 290px; transform: translateX(100%); transition: transform .25s var(--ease);
  box-shadow: var(--shadow-lg);
}
html.tablet[dir="ltr"] .sidebar { transform: translateX(-100%); }
html.tablet .sidebar.open { transform: translateX(0); }
html.tablet .menu-toggle { display: grid; }

/* مساحات لمس لا تقلّ عن ٤٤ بكسل — ما دون ذلك يخطئه الإصبع */
html.tablet .btn { padding: .72rem 1.15rem; font-size: .95rem; min-height: 46px; }
html.tablet .btn-sm { padding: .55rem .9rem; font-size: .87rem; min-height: 40px; }
html.tablet .icon-btn { width: 44px; height: 44px; }
html.tablet .input, html.tablet .select, html.tablet .textarea {
  min-height: 48px; font-size: .97rem;
}
html.tablet .textarea { min-height: 96px; }
html.tablet .nav a { padding: .72rem .7rem; font-size: .95rem; }
html.tablet .chip { min-height: 40px; padding-inline: .95rem; }
html.tablet .page-tabs a, html.tablet .page-tabs button { min-height: 46px; }
html.tablet thead th { padding: .8rem 1rem; }
html.tablet tbody td { padding: .85rem 1rem; }
html.tablet .pager .pg { min-width: 40px; min-height: 40px; }
html.tablet .set-tab { min-height: 48px; }

/* المربّعات أكبر على التابلت */
html.tablet .hub-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 1rem; }
html.tablet .hub-ico { width: 64px; height: 64px; border-radius: 20px; }
html.tablet .hub-ico svg { width: 30px; height: 30px; }
html.tablet .hub-name { font-size: .95rem; }
html.tablet .hub-act { min-height: 68px; font-size: 1.05rem; }

/* زر العودة لشاشة الفرع — يظهر في وضع التابلت فقط */
#hubBtn { display: none; }
html.tablet #hubBtn { display: grid; }

/* على الشاشات الصغيرة يبقى شريط الجوال هو الأصل */
@media (max-width: 620px) {
  .hub-grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: .6rem; }
  .hub-ico { width: 48px; height: 48px; border-radius: 15px; }
  .hub-ico svg { width: 23px; height: 23px; }
  .hub-name { font-size: .8rem; }
}

/* ============================================================
   إحساس التطبيق على الجوال
   ------------------------------------------------------------
   العملاء يفتحون البوابة من جوالهم، وكثير منهم يثبّتها على
   الشاشة الرئيسية فتعمل بلا شريط متصفح. هذي اللمسات تزيل ما
   يذكّر بأنها صفحة ويب: وميض اللمس، تحديد النصّ على الأزرار،
   والارتداد عند حافة التمرير.
   ============================================================ */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }

  body {
    /* الارتداد المطاطي يكشف خلفية المتصفح ويفضح أنها صفحة */
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* هيكل التطبيق لا يُحدَّد نصّه باللمس المطوّل — البيانات وحدها تُنسخ */
  .topbar, .mobile-nav, .nav, .sidebar-foot, .btn, .chip, .page-tabs, .pager {
    -webkit-user-select: none; user-select: none;
  }

  /* الشريط العلوي يلتصق كشريط تطبيق، ويحترم منطقة الشقّ العلوية */
  .topbar {
    padding-top: calc(.9rem + env(safe-area-inset-top));
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
  }

  /* تمرير بزخم داخل أي منطقة قابلة للتمرير */
  .content, .nav, .table-wrap, .modal-body { -webkit-overflow-scrolling: touch; }

  /* رأس البطاقة: العنوان في سطر والمرشّح في سطر تحته.
     بلا هذا يخرج المنسدل عن حافة الشاشة ويُقصّ. */
  .card-head { flex-wrap: wrap; row-gap: .55rem; }
  .card-head > .select,
  .card-head > .search-box { flex: 1 1 100%; width: 100% !important; min-width: 0; }

  /* الأزرار الأساسية بمساحة لمس مريحة */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }

  /* بطاقات الجداول: عنوان الحقل ثم قيمته في صفّ واحد مقروء */
  table.cards-sm td {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: .8rem; text-align: start;
  }
  table.cards-sm td .cell-main,
  table.cards-sm td .cell-sub { min-width: 0; text-align: end; }
  table.cards-sm td.t-end, table.cards-sm td.t-center { text-align: start; }
}

/* عند التثبيت على الشاشة الرئيسية (بلا شريط متصفح) */
@media (display-mode: standalone) {
  /* لا حاجة لتحذير «افتح في المتصفح» */
  .browser-only { display: none !important; }
  body { overscroll-behavior: none; }
}
