/* ==========================================================================
   نظام الشركة التجارية — Design System v18 "Ledger"
   هوية: أزرق ملكي + حبر داكن + رمادي بارد · RTL · فاتح/داكن · متجاوب
   ========================================================================== */

@font-face { font-family: "Cairo"; font-weight: 400; src: url("../assets/fonts/Cairo-Regular.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Cairo"; font-weight: 600; src: url("../assets/fonts/Cairo-SemiBold.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Cairo"; font-weight: 700; src: url("../assets/fonts/Cairo-Bold.ttf") format("truetype"); font-display: swap; }

/* ---------- 1) الرموز (Tokens) ---------- */
:root {
  --brand-50: #eef3ff;
  --brand-100: #dde8ff;
  --brand-200: #bfd2ff;
  --brand-300: #93b0ff;
  --brand-400: #6189fb;
  --brand-500: #3d63f0;
  --brand-600: #2a49d6;
  --brand-700: #2239ab;
  --brand-800: #1d3086;
  --brand-900: #182763;

  --primary: var(--brand-600);
  --primary-hover: var(--brand-700);
  --primary-soft: var(--brand-50);
  --primary-muted: var(--brand-200);
  --primary-glow: rgba(42, 73, 214, 0.30);

  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eff2f8;
  --border: #e4e8f0;
  --border-strong: #d2d9e6;
  --text: #0e1630;
  --text-2: #36425f;
  --muted: #667391;
  --faint: #98a3bd;

  --success: #079669;  --success-soft: #e6f7f0;
  --warning: #b45309;  --warning-soft: #fff4dc;
  --error:   #d92d3f;  --error-soft:   #fdebed;
  --info:    #2a49d6;  --info-soft:    #eaf0ff;

  --chart-1: #2a49d6;
  --chart-2: #9aa7c4;
  --chart-3: #6189fb;
  --chart-4: #f2a516;
  --chart-5: #12b886;
  --chart-6: #c2cbe0;

  --sidebar-bg: #0b1226;
  --sidebar-bg-2: #111a38;
  --sidebar-text: rgba(255,255,255,0.90);
  --sidebar-muted: rgba(255,255,255,0.46);
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active: linear-gradient(270deg, rgba(97,137,251,0.22), rgba(97,137,251,0.05));

  --shadow-xs: 0 1px 2px rgba(14,22,48,0.05);
  --shadow: 0 1px 2px rgba(14,22,48,0.04), 0 6px 20px rgba(14,22,48,0.04);
  --shadow-md: 0 10px 30px rgba(14,22,48,0.09), 0 2px 6px rgba(14,22,48,0.05);
  --shadow-lg: 0 28px 70px rgba(14,22,48,0.22), 0 6px 16px rgba(14,22,48,0.08);

  --radius: 16px;
  --radius-sm: 11px;
  --ring: 0 0 0 4px rgba(42,73,214,0.15);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 0.2s;
  --sidebar-w: 272px;
  --sidebar-w-collapsed: 80px;
  --topbar-h: 68px;
  color-scheme: light;
}

html.dark {
  --brand-50: rgba(97,137,251,0.13);
  --primary: #7799ff;
  --primary-hover: #9db6ff;
  --primary-soft: rgba(97,137,251,0.14);
  --primary-muted: rgba(97,137,251,0.34);
  --primary-glow: rgba(97,137,251,0.38);

  --bg: #080d1c;
  --surface: #0f1730;
  --surface-2: #131d3b;
  --surface-3: #19254a;
  --border: #1d2a4d;
  --border-strong: #2a3a66;
  --text: #e9eefb;
  --text-2: #c4cee6;
  --muted: #8a98ba;
  --faint: #62729a;

  --success: #34d399;  --success-soft: rgba(52,211,153,0.12);
  --warning: #fbbf24;  --warning-soft: rgba(251,191,36,0.12);
  --error:   #fb7185;  --error-soft:   rgba(251,113,133,0.12);
  --info:    #7f9fff;  --info-soft:    rgba(127,159,255,0.12);

  --chart-1: #6e92ff;
  --chart-2: #5c6c93;
  --chart-3: #93b0ff;
  --chart-6: #3a4a74;

  --sidebar-bg: #060a17;
  --sidebar-bg-2: #0a1126;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.35);
  --shadow: 0 1px 2px rgba(0,0,0,0.35), 0 8px 24px rgba(0,0,0,0.25);
  --shadow-md: 0 12px 34px rgba(0,0,0,0.5);
  --shadow-lg: 0 30px 80px rgba(0,0,0,0.65);
  --ring: 0 0 0 4px rgba(119,153,255,0.24);
  color-scheme: dark;
}

/* ---------- 2) الأساسيات ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.65;
  background: var(--bg); color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
::selection { background: var(--primary-muted); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.muted { color: var(--muted); }
.accent { color: var(--primary); font-weight: 700; }
td.accent { color: var(--error); font-weight: 700; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }
.kbd {
  display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 6px; font-size: 11px; line-height: 1.6;
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom-width: 2px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, monospace; direction: ltr;
}

/* ---------- 3) عناصر النماذج ---------- */
button, input, select, textarea {
  font: inherit; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 14px; background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    background var(--dur) var(--ease), transform .15s var(--ease), color var(--dur);
}
input, select, textarea { width: 100%; min-height: 42px; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--primary); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); background: var(--surface); }
select { cursor: pointer; appearance: none; -webkit-appearance: none; padding-inline-end: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2398a3bd' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; }
textarea { resize: vertical; min-height: 84px; }
input[type="number"] { direction: ltr; text-align: end; }
input[type="date"] { direction: ltr; text-align: end; }

button {
  cursor: pointer; background: var(--surface); font-weight: 600; font-size: 13.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; white-space: nowrap; box-shadow: var(--shadow-xs);
}
button svg { width: 17px; height: 17px; flex: none; }
button:hover { background: var(--surface-2); border-color: var(--faint); }
button:active { transform: scale(0.98); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
  background: linear-gradient(180deg, var(--brand-500), var(--brand-700));
  color: #fff; border-color: var(--brand-700);
  box-shadow: 0 1px 0 rgba(255,255,255,.22) inset, 0 6px 16px var(--primary-glow);
}
button.primary:hover { background: linear-gradient(180deg, var(--brand-400), var(--brand-600)); transform: translateY(-1px); border-color: var(--brand-600); }
button.primary:active { transform: translateY(0); }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
button.ghost:hover { background: var(--surface-3); color: var(--text); }
button.danger { background: var(--error-soft); color: var(--error); border-color: transparent; box-shadow: none; }
button.danger:hover { background: var(--error); color: #fff; }
button.small { padding: 4px 12px; font-size: 12.5px; min-height: 32px; border-radius: 9px; }
a > button { pointer-events: none; }

/* مجموعة أزرار مقسّمة */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 12px; border: 1px solid var(--border); }
.seg button { min-height: 30px; padding: 2px 14px; border: 0; border-radius: 9px; background: transparent; box-shadow: none; color: var(--muted); font-size: 12.5px; }
.seg button:hover { background: transparent; color: var(--text); }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-xs), 0 0 0 1px var(--border); }

/* ---------- 4) الهيكل ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns .3s var(--ease); }
.layout.collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.main { min-width: 0; display: flex; flex-direction: column; }

/* السايدبار */
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 40;
  display: flex; flex-direction: column;
  background:
    radial-gradient(320px 220px at 100% 0%, rgba(97,137,251,.16), transparent 70%),
    linear-gradient(180deg, var(--sidebar-bg-2) 0%, var(--sidebar-bg) 55%);
  color: var(--sidebar-text);
  overflow: hidden;
}
.sidebar::after { content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 1px; background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.03)); pointer-events: none; }
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 14px; }
.brand-icon {
  flex: none; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-300), var(--brand-600) 55%, var(--brand-800)); color: #fff;
  box-shadow: 0 10px 24px rgba(61,99,240,.5), inset 0 1px 0 rgba(255,255,255,.4);
}
.brand-icon svg { width: 23px; height: 23px; }
.brand b { display: block; font-size: 15px; font-weight: 700; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 165px; }
.brand span { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--sidebar-muted); }
.brand span::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,.2); }
.brand-text { min-width: 0; }

.sidebar-search-wrap { padding: 4px 14px 8px; position: relative; }
.sidebar-search-wrap svg { position: absolute; inset-inline-start: 26px; top: 50%; transform: translateY(-62%); width: 16px; height: 16px; color: var(--sidebar-muted); pointer-events: none; }
.menu-search {
  background: rgba(255,255,255,.055) !important; border: 1px solid rgba(255,255,255,.08) !important;
  color: #fff !important; border-radius: 11px; font-size: 13px; min-height: 40px; padding: 7px 12px; padding-inline-start: 38px;
  box-shadow: none !important;
}
.menu-search::placeholder { color: var(--sidebar-muted) !important; }
.menu-search:focus { border-color: var(--brand-400) !important; background: rgba(255,255,255,.09) !important; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 2px 12px 14px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.14) transparent; }
.nav-group { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--sidebar-muted); padding: 18px 12px 6px; }
a.nav {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 7px 10px; margin-bottom: 2px; border-radius: 11px;
  color: var(--sidebar-text); font-weight: 600; font-size: 13.5px;
  transition: background var(--dur) var(--ease), color var(--dur), transform var(--dur) var(--ease);
}
a.nav .nav-ic { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; color: var(--sidebar-muted); transition: all var(--dur) var(--ease); }
a.nav .nav-ic svg { width: 18px; height: 18px; }
a.nav:hover { background: var(--sidebar-hover); }
a.nav:hover .nav-ic { color: #fff; transform: scale(1.06); }
a.nav.active { background: var(--sidebar-active); color: #fff; }
a.nav.active .nav-ic { background: linear-gradient(135deg, var(--brand-400), var(--brand-600)); color: #fff; box-shadow: 0 6px 14px rgba(61,99,240,.5), inset 0 1px 0 rgba(255,255,255,.3); }
a.nav.active::after { content: ""; position: absolute; inset-inline-start: -12px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand-300); box-shadow: 0 0 12px var(--brand-400); }

.sidebar-foot { padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--sidebar-muted); }
.sidebar-foot .sidebar-ver { padding-inline-start: 6px; display: flex; flex-direction: column; line-height: 1.4; }
.sidebar-foot .sidebar-ver b { color: rgba(255,255,255,.8); font-weight: 600; font-size: 12px; }
.collapse-btn { background: rgba(255,255,255,.07); border: 0; color: #fff; width: 34px; min-height: 34px; padding: 0; border-radius: 10px; box-shadow: none; }
.collapse-btn:hover { background: rgba(255,255,255,.15); }
.collapse-btn svg { width: 16px; height: 16px; transition: transform .3s var(--ease); }

/* سايدبار مطوي */
.layout.collapsed .brand-text, .layout.collapsed .nav-label, .layout.collapsed .sidebar-search-wrap,
.layout.collapsed .sidebar-ver, .layout.collapsed .nav-group span { display: none; }
.layout.collapsed .brand { justify-content: center; padding-inline: 0; }
.layout.collapsed a.nav { justify-content: center; padding-inline: 0; }
.layout.collapsed .nav-group { height: 1px; padding: 0; margin: 10px 18px; background: rgba(255,255,255,.08); font-size: 0; }
.layout.collapsed .sidebar-foot { justify-content: center; }
.layout.collapsed .collapse-btn svg { transform: rotate(180deg); }
.layout.collapsed a.nav[data-label]:hover::before {
  content: attr(data-label); position: absolute; inset-inline-end: calc(100% + 14px); top: 50%; transform: translateY(-50%);
  background: #0b1226; color: #fff; padding: 5px 12px; border-radius: 8px; font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow-md); z-index: 60;
}

/* الشريط العلوي */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 32px; min-height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; width: 42px; padding: 0; }
.topbar-title { flex: 1; min-width: 0; }
.breadcrumb { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.bc-link:hover { color: var(--primary); }
.bc-sep { color: var(--faint); font-size: 10px; }
.bc-current { color: var(--text-2); font-weight: 600; }
.topbar h1 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; margin-top: 1px; }
.topbar .sub { display: none; }
.topbar-end { display: flex; align-items: center; gap: 8px; }
.topbar-end .ghost { width: 42px; padding: 0; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-xs); }
.topbar-end .ghost:hover { border-color: var(--border-strong); background: var(--surface-2); }
.topbar-end .ghost svg { width: 18px; height: 18px; }
.top-search {
  display: flex; align-items: center; gap: 10px; min-width: 250px; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-xs);
  color: var(--faint); font-weight: 500; font-size: 13px; justify-content: flex-start;
}
.top-search:hover { border-color: var(--border-strong); background: var(--surface); }
.top-search svg { width: 17px; height: 17px; }
.top-search span:not(.kbd) { flex: 1; text-align: start; }
.top-search .kbd { flex: none; }
.clock { font-size: 12px; padding-inline: 6px; white-space: nowrap; line-height: 1.3; text-align: end; }
.clock b { display: block; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.quick-wrap { position: relative; }
.quick-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 10px); min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop .18s var(--ease); z-index: 50;
}
.quick-menu[hidden] { display: none; }
.quick-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--text-2); }
.quick-item svg { width: 17px; height: 17px; color: var(--primary); }
.quick-item:hover { background: var(--primary-soft); color: var(--primary); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-xs); }
.user-chip .av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: linear-gradient(135deg, var(--brand-400), var(--brand-800)); box-shadow: inset 0 1px 0 rgba(255,255,255,.3); }
.user-chip .un { font-size: 12.5px; font-weight: 700; line-height: 1.25; }
.user-chip .un small { display: block; font-weight: 500; color: var(--muted); font-size: 10.5px; }

.content { padding: 28px 32px 56px; width: 100%; max-width: 1520px; margin-inline: auto; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap { gap: 10px; }

/* شريط التقدم */
.nprogress { position: fixed; top: 0; inset-inline: 0; height: 3px; width: 0; z-index: 999; opacity: 0; background: linear-gradient(90deg, var(--brand-300), var(--brand-600)); box-shadow: 0 0 12px var(--primary); transition: width .4s var(--ease), opacity .2s; }
.nprogress.active { opacity: 1; }

/* ---------- 5) رأس الصفحة ---------- */
.page-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-toolbar h2 { display: none; }
.page-toolbar p { margin: 0 !important; font-size: 13px !important; }
.page-title { font-size: 18px; font-weight: 700; }
.page-toolbar > div:first-child { min-width: 0; }

/* ---------- 6) الكروت ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; font-weight: 700; }
.card.table-wrap, .card.table-card { padding: 0; overflow: hidden; }
.card.error { border-color: var(--error); color: var(--error); background: var(--error-soft); }
.panel-title, .section-head, .table-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.table-card .table-head { padding: 20px 22px 0; margin-bottom: 14px; }
.panel-title h3, .section-head h3, .table-head h3 { font-size: 15.5px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.tag, .chip {
  display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; color: var(--primary); background: var(--primary-soft);
  transition: background var(--dur), color var(--dur);
}
a.tag:hover { background: var(--primary); color: #fff; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.err { background: var(--error-soft); color: var(--error); }
.badge.demo { background: var(--warning-soft); color: var(--warning); }

/* ---------- 7) البطاقات الإحصائية ---------- */
.stats, .kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat, .kpi {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px 20px; box-shadow: var(--shadow);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .25s;
}
.stat:hover, .kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.stat { --stat-c: var(--primary); }
.stat.teal, .stat.blue { --stat-c: var(--primary); }
.stat.amber { --stat-c: #e89a0c; }
.stat.red { --stat-c: var(--error); }
.stat.green { --stat-c: var(--success); }
.stat .label, .kpi-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .label::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--stat-c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--stat-c) 18%, transparent); flex: none; }
.stat .value, .kpi-value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; color: var(--text); line-height: 1.2; }
.stat.amber .value { color: var(--warning); }
.stat.red .value { color: var(--error); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.delta svg { width: 12px; height: 12px; }
.delta.up { color: var(--success); background: var(--success-soft); }
.delta.down { color: var(--error); background: var(--error-soft); }
.delta.flat { color: var(--muted); background: var(--surface-3); }
.meter { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 12px; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-400), var(--brand-600)); transition: width .8s var(--ease); }

/* بطاقة KPI المتقدمة (لوحة التحكم) */
.kpi-card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 4px;
  padding: 18px 20px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .25s;
  --kc: var(--primary);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.kpi-card.c-amber { --kc: #e89a0c; }
.kpi-card.c-green { --kc: var(--success); }
.kpi-card.c-gray { --kc: #7b88a8; }
.kpi-card.c-red { --kc: var(--error); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kpi-top .kl { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: var(--kc); background: color-mix(in srgb, var(--kc) 12%, transparent); flex: none; }
.kpi-ic svg { width: 18px; height: 18px; }
.kpi-card .kv { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.25; margin-top: 6px; display: flex; align-items: baseline; gap: 6px; }
.kpi-card .kv small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.kpi-card .kmeta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); min-height: 24px; }
.kpi-card .spark { display: block; width: calc(100% + 40px); height: 54px; margin: 6px -20px 0; }
.kpi-card .spark path.line { fill: none; stroke: var(--kc); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.kpi-card .spark path.fill { fill: url(#sg); opacity: .9; }
.kpi-card.no-spark { padding-bottom: 18px; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.mini {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs);
  --kc: var(--primary); transition: border-color .2s, transform .2s var(--ease);
}
.mini:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.mini.c-amber { --kc: #e89a0c; } .mini.c-green { --kc: var(--success); } .mini.c-red { --kc: var(--error); }
.mini .kpi-ic { width: 42px; height: 42px; border-radius: 12px; }
.mini .ml { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.4; }
.mini .mv { font-size: 19px; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }

/* ---------- 8) الجداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; text-align: start; padding: 13px 18px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
tbody td b { color: var(--text); }
tbody td:first-child { color: var(--text); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface-2); }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover { background: var(--primary-soft); }
table.clickable tbody tr:hover td:first-child { color: var(--primary); }
td .small + .small { margin-inline-start: 6px; }
td.muted, td .muted { font-size: 12.5px; }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.empty::before { content: ""; display: block; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px;
  background: var(--primary-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232a49d6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 8v13H3V8'/%3E%3Cpath d='M1 3h22v5H1z'/%3E%3Cpath d='M10 12h4'/%3E%3C/svg%3E") center/30px no-repeat; }
td.empty { padding: 56px 20px; }
tr:has(> td.empty):hover { background: transparent; }
.empty.compact { padding: 22px 16px; }
.empty.compact::before { display: none; }

/* ---------- 9) النماذج والمودال ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.field.full { grid-column: 1 / -1; }
.toolbar-search, #q { max-width: 420px; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(7,11,26,.58); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  animation: fade .2s ease;
}
.modal { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 28px; box-shadow: var(--shadow-lg); animation: pop .28s var(--ease); border-radius: 20px; }
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px !important; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.modal .row[style*="flex-end"] { margin-top: 8px; padding-top: 18px; border-top: 1px solid var(--border); }

.toast {
  position: fixed; bottom: 26px; inset-inline-start: 26px; z-index: 200; max-width: 400px;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; border-radius: 14px; font-weight: 600; font-size: 13.5px; color: #fff;
  background: #0e1630; box-shadow: var(--shadow-lg); border: 1px solid rgba(255,255,255,.08);
  transform: translateY(16px) scale(.97); opacity: 0; transition: all .3s var(--ease);
}
.toast::before { content: ""; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--success) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E") center/13px no-repeat; }
.toast.error::before { background: var(--error) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M12 6v7M12 18h.01'/%3E%3C/svg%3E") center/13px no-repeat; }
.toast.show { transform: none; opacity: 1; }

/* ---------- 10) الفواتير ---------- */
.invoice-hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 24px 26px; border-radius: var(--radius); color: #fff;
  background: radial-gradient(600px 240px at 0% 0%, rgba(147,176,255,.38), transparent 60%), linear-gradient(135deg, var(--brand-800), var(--brand-900));
}
.invoice-hero .muted { color: rgba(255,255,255,.7); }
.invoice-hero button:not(.primary) { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); box-shadow: none; }
.invoice-hero button:not(.primary):hover { background: rgba(255,255,255,.22); }
.invoice-hero button.primary { background: #fff; color: var(--brand-700); border-color: #fff; box-shadow: 0 8px 20px rgba(0,0,0,.22); }
.invoice-hero .badge.ok { background: rgba(52,211,153,.2); color: #6ee7b7; }
.big-num { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.invoice-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.box { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--border); }
.box span { font-size: 12px; color: var(--muted); font-weight: 600; }
.box b { font-size: 18px; }

/* ---------- 11) لوحة التحكم ---------- */
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-head h2 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.dash-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.dash-head p b { color: var(--text-2); }
.dash-head .live-dot { flex: none; }

.hero-banner {
  position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  padding: 30px 34px; border-radius: 22px; color: #fff;
  background:
    radial-gradient(520px 260px at 8% 0%, rgba(147,176,255,.40), transparent 62%),
    radial-gradient(420px 260px at 100% 100%, rgba(97,137,251,.38), transparent 60%),
    linear-gradient(135deg, #182763 0%, #2239ab 55%, #2a49d6 100%);
  box-shadow: 0 22px 46px rgba(34,57,171,.28);
}
.hero-banner::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 32px 32px; mask-image: linear-gradient(120deg, transparent 20%, #000 100%); -webkit-mask-image: linear-gradient(120deg, transparent 20%, #000 100%); }
.hero-banner > * { position: relative; z-index: 1; }
.hero-banner h2 { font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.hero-banner p { margin: 6px 0 0; color: rgba(255,255,255,.8); }
.hero-banner button { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.28); backdrop-filter: blur(8px); box-shadow: none; }
.hero-banner button:hover { background: rgba(255,255,255,.24); }
.hero-banner button.primary { background: #fff; color: var(--brand-700); border-color: #fff; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 4px rgba(52,211,153,.3); animation: pulse 2s infinite; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.dash-grid > .card { display: flex; flex-direction: column; }
.dash-grid > .card > .chart-box { flex: 1; display: flex; align-items: center; }
.dash-grid > .card > .donut-wrap { flex: 1; align-content: center; }
.dash-grid.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.chart-legend b { color: var(--text); }
.chart-box { position: relative; width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-box .gridline { stroke: var(--border); stroke-dasharray: 3 5; }
.chart-box text { fill: var(--faint); font-family: inherit; font-size: 11px; }
.chart-box .area-s { fill: url(#gArea); }
.chart-box .line-s { fill: none; stroke: var(--chart-1); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.chart-box .line-p { fill: none; stroke: var(--chart-2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 5 5; }
.chart-box .cross { stroke: var(--border-strong); stroke-width: 1; opacity: 0; transition: opacity .12s; }
.chart-box .dot { opacity: 0; transition: opacity .12s; stroke: var(--surface); stroke-width: 3; }
.chart-box.hover .cross, .chart-box.hover .dot { opacity: 1; }
.chart-draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.1s var(--ease) .1s forwards; }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; padding: 10px 14px; border-radius: 12px; font-size: 12px; line-height: 1.7; background: #0e1630; color: #fff; box-shadow: var(--shadow-md); white-space: nowrap; opacity: 0; transform: translate(-50%, -112%); transition: opacity .12s; border: 1px solid rgba(255,255,255,.08); }
.chart-tip b { display: block; font-size: 12.5px; margin-bottom: 2px; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 7px; }
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; justify-content: center; }
.donut-wrap svg { width: 172px; height: 172px; flex: none; }
.donut-wrap circle.seg { transition: stroke-width .2s var(--ease), opacity .2s; cursor: pointer; }
.donut-wrap:hover circle.seg { opacity: .55; }
.donut-wrap circle.seg:hover { opacity: 1; stroke-width: 24; }
.donut-wrap text { fill: var(--muted); font-family: inherit; }
.donut-center { font-size: 23px; font-weight: 700; fill: var(--text) !important; }
.donut-sub { font-size: 11px; }
.legend-list { display: flex; flex-direction: column; gap: 11px; flex: 1; min-width: 160px; }
.legend-list .li { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.legend-list .li span { display: flex; align-items: center; gap: 9px; color: var(--text-2); min-width: 0; }
.legend-list .li span em { font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-list .li i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-list .li b { color: var(--text); }
.activity { display: flex; flex-direction: column; }
.act-item { display: flex; align-items: center; gap: 13px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.act-item:first-child { padding-top: 0; }
.act-item:last-child { border-bottom: 0; padding-bottom: 0; }
.act-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.act-ic svg { width: 17px; height: 17px; }
.act-ic.in { color: var(--success); background: var(--success-soft); }
.act-ic.out { color: var(--info); background: var(--info-soft); }
.act-ic.bad { color: var(--error); background: var(--error-soft); }
.act-body { flex: 1; min-width: 0; font-weight: 600; font-size: 13.5px; }
.act-body small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; text-align: start; }
.act-amt { font-weight: 700; white-space: nowrap; }
.act-amt.in { color: var(--success); }
.act-amt.bad { color: var(--error); }
.quick-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.q-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: 13px; transition: all .2s var(--ease); }
.q-tile:hover { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-2px); }
.q-tile .ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); }
.q-tile:hover .ic { background: var(--primary); color: #fff; }
.q-tile .ic svg { width: 18px; height: 18px; }

/* شريط ملخص أسفل المخطط */
.chart-foot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.chart-foot div { display: flex; flex-direction: column; gap: 2px; }
.chart-foot span { font-size: 12px; color: var(--muted); font-weight: 600; }
.chart-foot b { font-size: 16px; letter-spacing: -.01em; }
.chart-foot small { font-size: 11.5px; color: var(--faint); font-weight: 500; }

/* لوحة الأوامر */
.cmd-overlay { position: fixed; inset: 0; z-index: 150; display: grid; place-items: start center; padding-top: 13vh; background: rgba(7,11,26,.58); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); animation: fade .15s ease; }
.cmd-overlay[hidden] { display: none; }
.cmd-palette { width: min(620px, 92vw); padding: 0; overflow: hidden; box-shadow: var(--shadow-lg); animation: pop .22s var(--ease); border-radius: 20px; }
.cmd-palette input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 20px 22px; font-size: 16px; box-shadow: none !important; background: transparent; }
.cmd-results { max-height: 360px; overflow-y: auto; padding: 8px; }
.cmd-row { width: 100%; justify-content: flex-start; text-align: start; border: 0; box-shadow: none; background: transparent; padding: 9px 12px; border-radius: 11px; font-weight: 600; }
.cmd-row.on, .cmd-row:hover { background: var(--primary-soft); color: var(--primary); }
.cmd-row .nav-ic { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-3); color: var(--muted); }
.cmd-row.on .nav-ic { background: var(--primary); color: #fff; }
.cmd-row .nav-ic svg { width: 16px; height: 16px; }
.cmd-group { margin-inline-start: auto; font-size: 11.5px; font-weight: 500; }
.cmd-foot { padding: 11px 20px; font-size: 11.5px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; gap: 14px; flex-wrap: wrap; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

/* هيكل تحميل */
.skel { border-radius: 12px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }

/* ---------- 12) حركة ---------- */
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.97) } to { opacity: 1; transform: none } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
@keyframes draw { to { stroke-dashoffset: 0 } }
@keyframes shimmer { to { background-position: -200% 0 } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 4px rgba(52,211,153,.3) } 50% { box-shadow: 0 0 0 8px rgba(52,211,153,0) } }
.anim-stagger > * { animation: fade .22s ease both; }
.page-leave { opacity: 0; transform: translateY(-4px); transition: all .18s ease; }

/* سكرول */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; border: 2px solid transparent; }

/* ---------- 13) متجاوب — موبايل وتابلت ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }

@media (max-width: 1200px) {
  .dash-grid, .dash-grid.even { grid-template-columns: 1fr; }
  .clock { display: none; }
  .top-search { min-width: 0; width: 42px; padding: 0; justify-content: center; }
  .top-search span, .top-search .kbd { display: none; }
}
@media (max-width: 1000px) { .user-chip .un { display: none; } .user-chip { padding: 4px; } }

@media (max-width: 900px) {
  .layout, .layout.collapsed { grid-template-columns: 1fr; min-height: 100dvh; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    width: min(300px, 88vw);
    height: 100%; height: 100dvh;
    transform: translateX(100%);
    transition: transform .28s var(--ease);
    box-shadow: var(--shadow-lg);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 50;
  }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .layout.nav-open .sidebar { transform: none; }
  /* طبقة تعتيم قابلة للنقر لإغلاق القائمة */
  .layout.nav-open::before {
    content: ""; position: fixed; inset: 0; z-index: 45;
    background: rgba(7,11,26,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  }
  .layout.collapsed .brand-text, .layout.collapsed .nav-label, .layout.collapsed .sidebar-search-wrap, .layout.collapsed .sidebar-ver { display: revert; }
  .layout.collapsed .sidebar-ver { display: flex; }
  .layout.collapsed a.nav { justify-content: flex-start; padding-inline: 10px; }
  .layout.collapsed .nav-group span { display: revert; }
  .layout.collapsed .nav-group { height: auto; margin: 0; padding: 18px 12px 6px; font-size: 11px; background: none; }
  .layout.collapsed .brand { justify-content: flex-start; padding-inline: 18px; }
  .collapse-btn { display: none; }
  .menu-btn { display: inline-flex; min-width: 44px; min-height: 44px; touch-action: manipulation; }
  .topbar {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top, 0));
    min-height: 56px;
    gap: 8px;
  }
  .topbar h1 { font-size: 16px; }
  .topbar .sub { display: none; }
  .breadcrumb { font-size: 11px; }
  .content {
    padding: 14px 12px max(28px, env(safe-area-inset-bottom, 0));
  }
  .hero-banner { padding: 18px; }
  .hero-banner h2, .dash-head h2 { font-size: 18px; }
  .topbar-end { gap: 6px; }
  .topbar-end .badge, .topbar-end .quick-wrap .small span { display: none; }
  .topbar-end .quick-wrap .small { padding: 0; width: 44px; min-height: 44px; border-radius: 12px; }
  .topbar-end .ghost, .theme-btn, .install-btn { width: 44px; min-height: 44px; padding: 0; }

  /* منع تكبير iOS عند التركيز على الحقول */
  input, select, textarea { font-size: 16px !important; }

  /* الجداول: تمرير أفقي سلس */
  .table-wrap, .card.table-wrap, .card.table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  table { min-width: 520px; }
  thead th, tbody td { padding: 12px 14px; font-size: 13px; }

  /* النماذج */
  .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .page-toolbar { gap: 10px; }
  .page-toolbar .row { width: 100%; flex-wrap: wrap; }
  .toolbar-search, #q { max-width: none; flex: 1 1 160px; }

  /* المودال */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal {
    width: 100%;
    max-height: min(92dvh, calc(100vh - 24px));
    border-radius: 18px 18px 12px 12px;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0));
  }
  .modal.wide { width: 100%; }

  /* صفوف بنود الفاتورة */
  #lines > .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  #lines > .form-grid .field:first-child { grid-column: 1 / -1; }

  .inv-layout { grid-template-columns: 1fr; }
  .top-panel .top-row { gap: 8px; }
  .top-panel .chips { margin-inline-start: 0; width: 100%; }
  .chip { min-width: 0; flex: 1 1 40%; }
  .top-actions { width: 100%; }
  .top-actions button { flex: 1 1 auto; }

  .toast {
    inset-inline: 12px;
    bottom: max(16px, env(safe-area-inset-bottom, 0));
    max-width: none;
  }

  .cmd-overlay { padding-top: max(8vh, env(safe-area-inset-top, 0)); padding-inline: 10px; }
  .cmd-palette { width: 100%; max-width: none; border-radius: 16px; }

  .seg { flex-wrap: wrap; max-width: 100%; }
  .seg button { min-height: 36px; padding: 4px 12px; }

  button, a.nav, .chip-btn { touch-action: manipulation; }
}

@media (max-width: 560px) {
  .stats, .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mini-stats { grid-template-columns: 1fr; gap: 10px; }
  .stat, .kpi, .kpi-card { padding: 12px; }
  .stat .value, .kpi-value { font-size: 18px; }
  .kpi-card .kv { font-size: 19px; }
  .kpi-ic { display: none; }
  .mini { padding: 12px; }
  .mini .kpi-ic { display: none; }
  .quick-tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  thead th, tbody td { padding: 10px 10px; font-size: 12.5px; }
  .top-search { display: none; }
  .donut-wrap { gap: 12px; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  #lines > .form-grid { grid-template-columns: 1fr 1fr; }
  .chart-foot { grid-template-columns: 1fr; gap: 8px; }
  .card { padding: 14px; border-radius: 14px; }
  .table-card .table-head { padding: 14px 14px 0; }
  .user-chip { padding: 2px; }
  .user-chip .av { width: 32px; height: 32px; }
  .stack { gap: 14px; }
  .content { padding-inline: 10px; }
  .sidebar { width: min(280px, 92vw); }
  a.nav { min-height: 44px; padding: 8px 10px; font-size: 14px; }
  .brand { padding: 14px 14px 8px; }
}

/* هواتف صغيرة جداً */
@media (max-width: 380px) {
  .stats, .kpi-grid, .quick-tiles { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 15px; }
  .chip { flex: 1 1 100%; }
}

/* وضع أفقي على الموبايل */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .sidebar { width: min(260px, 70vw); }
  .topbar { min-height: 48px; padding-block: 4px; }
  .content { padding-block: 10px; }
  .modal { max-height: 94dvh; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } .chart-draw { stroke-dashoffset: 0; } }

/* ---------- 14) طباعة ---------- */
@media print {
  .sidebar, .topbar, .page-toolbar, .toast, .nprogress, .seg { display: none !important; }
  .layout { display: block; } .content { padding: 0; max-width: none; }
  body { background: #fff; } .card, .stat, .kpi-card { box-shadow: none; }
}

/* ---------- 15) بنود الفاتورة داخل النموذج ---------- */
#lines > .form-grid {
  grid-template-columns: minmax(0, 2.2fr) minmax(0, .8fr) minmax(0, 1fr) auto; align-items: end; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--border) !important; border-radius: 13px;
  padding: 12px 14px !important; margin-bottom: 10px !important;
}
#lines > .form-grid .field[style*="flex-end"] { justify-content: flex-end; }
#add-line { align-self: flex-start; border: 1px dashed var(--border-strong); background: transparent; color: var(--primary); }
#add-line:hover { background: var(--primary-soft); border-color: var(--primary); }
@media (max-width: 700px) {
  #lines > .form-grid { grid-template-columns: 1fr 1fr; }
  #lines > .form-grid > .field:first-child { grid-column: 1 / -1; }
  .breadcrumb { display: none; }
}

/* ---------- 16) الدخول والتسجيل ---------- */
.auth-body { background: var(--bg); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-hero {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; gap: 32px;
  padding: 44px 52px; color: #fff;
  background: radial-gradient(560px 320px at 0% 0%, rgba(147,176,255,.40), transparent 62%),
    radial-gradient(480px 300px at 100% 100%, rgba(97,137,251,.36), transparent 60%),
    linear-gradient(150deg, #0b1226 0%, #182763 50%, #2239ab 100%);
}
.auth-hero::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .45;
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 36px 36px; mask-image: linear-gradient(160deg, transparent 10%, #000 100%); -webkit-mask-image: linear-gradient(160deg, transparent 10%, #000 100%); }
.auth-hero > * { position: relative; z-index: 1; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 17px; }
.auth-brand .brand-icon svg { width: 23px; height: 23px; }
.auth-hero h1 { font-size: 38px; line-height: 1.3; font-weight: 700; letter-spacing: -.01em; }
.auth-hero p { margin: 14px 0 0; color: rgba(255,255,255,.78); font-size: 15.5px; max-width: 460px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 13px; }
.auth-points li { display: flex; align-items: center; gap: 12px; font-weight: 600; color: rgba(255,255,255,.92); }
.auth-points i { flex: none; width: 22px; height: 22px; border-radius: 50%; background: rgba(52,211,153,.2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236ee7b7' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E") center/12px no-repeat; }
.auth-foot { font-size: 12px; color: rgba(255,255,255,.5); }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: min(460px, 100%); padding: 30px; border-radius: 22px; box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: 22px; }
.auth-tabs { display: flex; }
.auth-tabs button { flex: 1; min-height: 38px; }
.auth-h { font-size: 22px; font-weight: 700; }
.auth-submit { width: 100%; min-height: 48px; font-size: 15px; }
.auth-err { padding: 10px 14px; border-radius: 11px; background: var(--error-soft); color: var(--error); font-weight: 600; font-size: 13px; }
.auth-err[hidden], form[hidden] { display: none; }
.pw { position: relative; }
.pw input { padding-inline-end: 46px; }
.pw-eye { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); min-height: 34px; width: 38px; padding: 0; }
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { padding: 26px 22px; gap: 18px; }
  .auth-hero h1 { font-size: 24px; }
  .auth-hero p, .auth-points, .auth-foot { display: none; }
}

/* حساب موقوف */
.suspended-card { width: min(440px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 36px 30px; }
.susp-ic { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--error-soft); color: var(--error); }
.susp-ic svg { width: 30px; height: 30px; }
.suspended-card h2 { font-size: 22px; }
.suspended-card p { margin: 0; }
.susp-note { padding: 10px 14px; border-radius: 11px; background: var(--warning-soft); color: var(--warning); font-weight: 600; font-size: 13px; }

/* ---------- 17) صفحة الإدارة ---------- */
.u-cell { display: flex; align-items: center; gap: 12px; }
.u-av { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--brand-400), var(--brand-800)); }
.u-av.lg { width: 52px; height: 52px; border-radius: 16px; font-size: 20px; }
.adm-table td { white-space: nowrap; }
.actions-cell { display: flex; gap: 6px; }
.modal.wide { width: min(860px, 100%); }
.det-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.det-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.day-grid { display: grid; grid-template-columns: repeat(30, 1fr); gap: 4px; }
.day-grid .day { aspect-ratio: 1; border-radius: 4px; background: var(--surface-3); }
.day-grid .day.h1 { background: color-mix(in srgb, var(--brand-500) 35%, var(--surface-3)); }
.day-grid .day.h2 { background: color-mix(in srgb, var(--brand-500) 65%, var(--surface-3)); }
.day-grid .day.h3 { background: var(--brand-600); }
.tbl-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: 34px; padding: 4px 13px; border-radius: 999px; font-size: 12.5px; background: var(--surface-2); }
.chip-btn b { color: var(--primary); }
.chip-btn.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
@media (max-width: 700px) { .day-grid { grid-template-columns: repeat(15, 1fr); } }

/* ==========================================================================
   18) صفحة إدخال الفاتورة / المرتجع (لوحتان + شريط الإجماليات)
   ========================================================================== */
.inv-page { --inv-accent: var(--primary); }
.inv-page[data-kind="purchase"] { --primary: #0e8a7c; --primary-hover: #0a6f64; --primary-soft: #e2f6f3; --primary-muted: #a7e0d8; --primary-glow: rgba(14,138,124,.30); }
.inv-page[data-kind="sale_return"], .inv-page[data-kind="purchase_return"] { --primary: #d12a3f; --primary-hover: #b01f33; --primary-soft: #fdebee; --primary-muted: #f5b4bd; --primary-glow: rgba(209,42,63,.30); }
html.dark .inv-page[data-kind="purchase"] { --primary-soft: rgba(14,138,124,.18); --primary-muted: rgba(14,138,124,.45); }
html.dark .inv-page[data-kind="sale_return"], html.dark .inv-page[data-kind="purchase_return"] { --primary-soft: rgba(209,42,63,.18); --primary-muted: rgba(209,42,63,.45); }

.inv-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.inv-head h2 { margin: 0; display: flex; align-items: center; gap: 10px; }
.kind-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary-muted); }

.inv-layout { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 16px; align-items: start; }
.inv-panel { display: flex; flex-direction: column; gap: 14px; }
.inv-card { position: relative; border-top: 3px solid var(--primary); }
.inv-sec { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin: 0 0 14px; color: var(--text); }
.inv-sec::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.inv-sec.alt { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border-strong); }
.inv-card .form-grid { gap: 10px 12px; }
.inv-card .field.half { grid-column: span 1; }
.inv-card .field.full { grid-column: 1 / -1; }
.inv-card label .opt { font-weight: 400; color: var(--faint); font-size: 11px; margin-inline-start: 4px; }
.inv-card .auto-badge { font-size: 10.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); margin-inline-start: 6px; }

.sugg-wrap { position: relative; }
.sugg { position: absolute; z-index: 30; inset-inline: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg); display: none; padding: 4px; }
.sugg.open { display: block; }
.sugg .it { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.sugg .it:hover, .sugg .it.hl { background: var(--primary-soft); }
.sugg .it small { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.sugg .none { padding: 12px; text-align: center; color: var(--muted); font-size: 12.5px; }
.party-note { margin-top: 6px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.party-note b { color: var(--text); }
.party-note .warn { color: var(--warning); font-weight: 700; }

.stock-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-weight: 600; }
.stock-pill.low { background: var(--warning-soft); color: var(--warning); }
.stock-pill.zero { background: var(--error-soft); color: var(--error); }

.inv-actions-row { display: flex; gap: 8px; margin-top: 14px; }
.inv-actions-row button { flex: 1; justify-content: center; }

.inv-items { padding: 0; overflow: hidden; }
.inv-items .panel-title { padding: 16px 20px 0; }
.count-badge { font-size: 11.5px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.inv-items .table-scroll { max-height: calc(100vh - 430px); min-height: 220px; overflow: auto; }
.inv-items td .note { display: block; font-size: 11.5px; color: var(--muted); }
.inv-items tr.editing td { background: var(--primary-soft); }
.inv-empty { padding: 42px 16px; text-align: center; color: var(--muted); }
.inv-empty b { display: block; color: var(--text-2); margin-bottom: 4px; }

.inv-bar { position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); }
.inv-totals { display: flex; gap: 8px; flex-wrap: wrap; }
.inv-tot { min-width: 96px; padding: 8px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.inv-tot .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.inv-tot .v { font-size: 16px; font-weight: 700; margin-top: 1px; }
.inv-tot.red .v { color: var(--error); }
.inv-tot.net { background: var(--primary); border-color: var(--primary); }
.inv-tot.net .l, .inv-tot.net .v { color: #fff; }
.inv-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.preview-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(10,16,38,.6); backdrop-filter: blur(4px); display: flex; flex-direction: column; align-items: center; padding: 24px 12px; overflow: auto; }
.preview-sheet { background: #fff; color: #0e1630; width: min(820px, 100%); border-radius: 14px; padding: 32px; box-shadow: var(--shadow-lg); line-height: 1.7; }
.preview-sheet h1 { font-size: 22px; margin: 0; color: #182763; }
.preview-sheet h2 { font-size: 14px; margin: 6px 0 16px; color: #fff; background: var(--primary); display: inline-block; padding: 4px 16px; border-radius: 999px; }
.preview-sheet .meta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 18px; padding: 14px 18px; background: #f3f5fa; border-radius: 12px; border: 1px solid #e4e8f0; }
.preview-sheet table { width: 100%; border-collapse: collapse; }
.preview-sheet th { background: #182763; color: #fff; padding: 9px 12px; text-align: right; font-size: 12px; }
.preview-sheet td { padding: 9px 12px; border-bottom: 1px solid #e4e8f0; text-align: right; }
.preview-sheet table.totals { width: 300px; margin: 18px auto 0 0; }
.preview-actions { display: flex; gap: 10px; margin-top: 16px; }

@media (max-width: 980px) {
  .inv-layout { grid-template-columns: 1fr; }
  .inv-items .table-scroll { max-height: none; }
}

/* ===== 19) الخزينة (نمط ROLLEX) ===== */
.top-panel{padding:14px 16px;display:flex;flex-direction:column;gap:12px}
.top-panel .top-row{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
.top-panel .reg-sel{min-width:160px;font-weight:700}
.top-panel .chips{display:flex;gap:8px;flex-wrap:wrap;margin-inline-start:auto}
.chip{display:flex;flex-direction:column;gap:2px;padding:6px 14px;border-radius:12px;background:var(--surface-2,#f3f5fa);border:1px solid var(--border,#e4e8f0);min-width:96px}
.chip span{font-size:11px;color:var(--muted,#6b7794)}.chip b{font-size:15px}
.chip.big{background:var(--primary-soft,#eef3ff);border-color:transparent}.chip.big b{color:var(--primary,#2a49d6);font-size:18px}
.chip.ok b{color:#15803d}.chip.warn b{color:#c2410c}
.top-actions{display:flex;gap:8px;flex-wrap:wrap}
.tre-info{display:flex;gap:16px;flex-wrap:wrap;align-items:center;margin-top:10px;font-size:13px}
.tre-table td.desc{max-width:340px}
.tre-table .in-c,.in-c{color:#15803d;font-weight:700}.tre-table .out-c,.out-c{color:#c2410c;font-weight:700}
mark{background:#fde68a;color:inherit;border-radius:3px;padding:0 2px}
html.dark mark{background:#854d0e}
.denoms{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:8px}
.den{display:grid;grid-template-columns:50px 1fr;gap:4px 8px;align-items:center;padding:8px;border:1px solid var(--border,#e4e8f0);border-radius:10px}
.den span{font-weight:700}.den em{grid-column:1/-1;font-style:normal;font-size:11px;color:var(--muted,#6b7794);text-align:end}
.cnt-sum{display:flex;gap:12px;flex-wrap:wrap}.cnt-sum>div{flex:1;min-width:120px;padding:10px 14px;border-radius:12px;background:var(--surface-2,#f3f5fa);display:flex;flex-direction:column}
.cnt-sum span{font-size:11px;color:var(--muted,#6b7794)}.cnt-sum b{font-size:17px}
.diff-box{padding:12px;border-radius:12px;font-weight:700;text-align:center}
.diff-box.match{background:#dcfce7;color:#166534}.diff-box.over{background:#fef3c7;color:#92400e}.diff-box.short{background:#fee2e2;color:#991b1b}
.modal:has(.denoms){max-width:640px;width:96vw}
.reg-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:14px}
.reg-card{display:flex;flex-direction:column;gap:10px;padding:16px}
.reg-head{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
.reg-bal{font-size:26px;font-weight:800;color:var(--primary,#2a49d6)}
.top-panel .reg-sel{width:auto;flex:0 0 220px}
.tre-table td[dir=ltr]{white-space:nowrap}
.reg-card.sel{outline:2px solid var(--primary,#2a49d6)}
.badge.danger{background:#fee2e2;color:#991b1b}


/* ======================================================================
   ثبات الشيل (v22): القائمة والشريط العلوي لا يختفيان ولا يتحركان أثناء التنقل
   ====================================================================== */
/* انتقال سلس بين الصفحات (Chrome/Edge/Safari الحديثة): تبقى القائمة والشريط ثابتين كما هما ويتبدّل المحتوى فقط */
@view-transition { navigation: auto; }
.sidebar { view-transition-name: app-sidebar; }
.topbar { view-transition-name: app-topbar; }
::view-transition-group(app-sidebar), ::view-transition-group(app-topbar) { animation: none; }
::view-transition-old(app-sidebar), ::view-transition-old(app-topbar) { display: none; }
::view-transition-new(app-sidebar), ::view-transition-new(app-topbar) { animation: none; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .14s; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* هيكل عظمي للقائمة عند أول تحميل (قبل وصول بيانات المستخدم) */
.nav-skel { height: 38px; margin: 6px 0; border-radius: 10px; background: linear-gradient(90deg, rgba(255,255,255,.05) 25%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.05) 75%); background-size: 200% 100%; }
.page-skel { padding-top: 4px; }
.user-slot { display: contents; }

/* ======================================================================
   PWA (v23): زر التثبيت + إرشاد iOS + وضع التطبيق المثبّت
   ====================================================================== */
.install-btn[hidden] { display: none !important; }
.install-btn { color: var(--primary); border-color: var(--primary) !important; }
.pwa-tip {
  position: fixed; inset-inline: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 1000;
  max-width: 420px; margin-inline: auto; padding: 16px 18px; border-radius: 16px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(7,11,26,.28); animation: fade .2s ease both;
}
.pwa-tip p { margin: 6px 0 12px; font-size: 13.5px; line-height: 1.8; color: var(--muted); }
.pwa-tip button { font: inherit; font-weight: 600; padding: 8px 22px; border: 0; border-radius: 10px; background: var(--primary); color: #fff; cursor: pointer; }
.pwa-share { font-weight: 700; color: var(--primary); }
/* عند التشغيل كتطبيق مثبّت: لا حاجة لزر التثبيت، واحترم حواف الشاشة (النوتش/الشريط السفلي) */
@media (display-mode: standalone) {
  .install-btn { display: none !important; }
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
}

/* لافتة "تثبيت التطبيق" التلقائية (موبايل) */
.pwa-banner {
  position: fixed; inset-inline: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 1001;
  max-width: 460px; margin-inline: auto; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 18px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 18px 50px rgba(7,11,26,.30); animation: fade .25s ease both;
}
.pwa-banner img { flex: none; width: 46px; height: 46px; border-radius: 12px; }
.pwa-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.pwa-banner-text b { font-size: 14px; }
.pwa-banner-text span { font-size: 12px; color: var(--muted); }
.pwa-banner-actions { display: flex; flex-direction: column; gap: 4px; }
.pwa-banner-actions button { font: inherit; font-size: 13px; font-weight: 600; border: 0; border-radius: 10px; padding: 7px 16px; cursor: pointer; }
.pwa-banner-actions .pwa-yes { background: var(--primary); color: #fff; }
.pwa-banner-actions .pwa-no { background: transparent; color: var(--muted); padding-block: 3px; font-weight: 500; }
@media (display-mode: standalone) { .pwa-banner { display: none !important; } }

/* ===== v27 — كشوف الحساب (آلية رولكس بألوان رصيد) ===== */
.stm-filters { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.stm-filters .field { margin: 0; min-width: 170px; }
.stm-filters .field.grow { flex: 1 1 260px; }
.stm-sumbar { display: flex; gap: 12px; flex-wrap: wrap; }
.stm-chip { display: inline-flex; align-items: center; gap: 10px; padding: 9px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs); font-size: 13px; color: var(--text-2); }
.stm-chip b { font-size: 15px; color: var(--primary); }
.stm-chip.warn b { color: var(--warning); } .stm-chip.err b { color: var(--error); }
.stm-list td.c, .stm-list th.c, .stm-table td.c, .stm-table th.c { text-align: center; }
.stm-list tbody tr[data-id] { cursor: pointer; }
.stm-list tbody tr[data-id]:hover td { background: var(--primary-soft); }
.dr { color: var(--error); font-weight: 700; } .cr { color: var(--success); font-weight: 700; }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.stm-overlay { z-index: 100; align-items: start; overflow: auto; }
.stm-box { width: min(980px, 100%); margin: 20px auto; background: var(--surface); border-radius: 18px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 0; overflow: hidden; }
.stm-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: linear-gradient(135deg, #182763, #2a49d6); color: #fff; }
.stm-head h3 { margin: 0; font-size: 16px; color: #fff; }
.stm-head .ghost { color: #fff; border-color: rgba(255,255,255,.4); background: transparent; }
.stm-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.stm-toolbar label { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.stm-toolbar input[type=date] { min-height: 34px; padding: 4px 8px; }
.stm-toolbar .sp { flex: 1; }
.stm-pdf { background: #fdecea; color: #b3261e; border-color: #f5c6c2; } .stm-xls { background: #e7f6ee; color: #1b7a4b; border-color: #bfe5cf; } .stm-prn { background: var(--primary-soft); color: var(--primary); }
.stm-warn { margin: 12px 20px 0; padding: 10px 14px; border-radius: 12px; background: var(--warning-soft); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 13px; }
.stm-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px 20px 6px; }
.stm-summary .box { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; text-align: center; background: var(--surface); }
.stm-summary small { display: block; font-size: 11.5px; color: var(--text-2); } .stm-summary b { font-size: 16px; }
.stm-summary .debit b { color: var(--error); } .stm-summary .credit b { color: var(--success); }
.stm-summary .final { background: linear-gradient(135deg, #182763, #2a49d6); border-color: transparent; } .stm-summary .final small { color: #c9d3f5; } .stm-summary .final b { color: #fff; }
.stm-tablewrap { padding: 8px 20px 20px; overflow: auto; max-height: 60vh; }
.stm-table { width: 100%; border-collapse: collapse; }
.stm-table th { position: sticky; top: 0; z-index: 1; }
.stm-table tr.open td { background: var(--surface-3); font-weight: 700; }
.stm-table tr.tot td { background: var(--primary-soft); font-weight: 800; border-top: 2px solid var(--primary); }
.stm-table td.nw { white-space: nowrap; }
@media (max-width: 640px) { .stm-box { margin: 0; border-radius: 0; min-height: 100vh; } .stm-toolbar .sp { display: none; } }

/* ===== v33 — كثافة مدمجة (افتراضية): تقليل الأحجام قليلًا حتى لا تخرج الجداول العريضة (مثل المستخدمين) من الصفحة.
   للرجوع للحجم القديم: html[data-density="normal"] (من الإعدادات ← المظهر) ===== */
:root:not([data-density="normal"]) { --sidebar-w: 236px; }
:root:not([data-density="normal"]) body { font-size: 13px; }
:root:not([data-density="normal"]) .content { padding: 18px 20px 40px; }
:root:not([data-density="normal"]) .card { padding: 16px; }
:root:not([data-density="normal"]) table { font-size: 12.5px; }
:root:not([data-density="normal"]) thead th { padding: 9px 10px; font-size: 11px; }
:root:not([data-density="normal"]) tbody td { padding: 9px 10px; }
:root:not([data-density="normal"]) .card.table-wrap, :root:not([data-density="normal"]) .card.table-card { padding: 0; }
:root:not([data-density="normal"]) td .small + .small { margin-inline-start: 4px; }
:root:not([data-density="normal"]) button.small, :root:not([data-density="normal"]) a.small.button { padding-inline: 10px; }
:root:not([data-density="normal"]) .stats { gap: 12px; }
:root:not([data-density="normal"]) .modal { padding: 20px; }
/* جدول أي صفحة: لا يتجاوز عرض الشاشة — يلتف النص بدل الخروج، والتمرير الأفقي احتياطي فقط */
.table-wrap { max-width: 100%; }
:root:not([data-density="normal"]) tbody td { overflow-wrap: anywhere; }
:root:not([data-density="normal"]) td[dir="ltr"], :root:not([data-density="normal"]) td.nw { overflow-wrap: normal; }

/* ===== v36 — شعار رصيد في القائمة وصفحة الدخول ===== */
.brand-logo { width: 42px; height: 42px; flex: none; object-fit: contain; display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.brand b { font-size: 14.5px; letter-spacing: 0; }
.auth-brand { display: flex; align-items: center; gap: 14px; }
.auth-brand .brand-logo { width: 52px; height: 52px; }
.auth-brand b { font-size: 20px; }

/* ===== v38 — صفحة «إدارة المستخدمين» (admin): تصغير العرض 20% ===== */
body[data-page="admin"] #page,
body[data-page="admin"] .modal-overlay .modal { zoom: .8; }
/* احتياطي لمتصفحات بلا دعم zoom: تصغير الخط والحشو بما يقارب 20% */
@supports not (zoom: 1) {
  body[data-page="admin"] #page, body[data-page="admin"] .modal-overlay .modal { font-size: 80%; }
  body[data-page="admin"] #page table { font-size: 10px; }
  body[data-page="admin"] #page thead th, body[data-page="admin"] #page tbody td { padding: 7px 8px; }
  body[data-page="admin"] #page .stat .value { font-size: 80%; }
}

/* اختيار اللغة (قائمة منسدلة) */
.lang-select { width: auto; min-width: 118px; height: 42px; padding-block: 0; padding-inline: 12px 34px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background-color: var(--surface); box-shadow: var(--shadow-xs); }
.lang-select:hover { border-color: var(--border-strong); background-color: var(--surface-2); }
html[dir="ltr"] .lang-select { background-position: right 10px center; padding-inline: 12px 34px; }
@media (max-width: 900px) { .topbar-end .lang-select { min-width: 0; width: 92px; min-height: 44px; padding-inline: 8px 28px; } }
