:root {
  --page-bg: #f3f4f6;
  --text-main: #1f2937;
  --text-muted: #64748b;
  --text-label: #475569;
  --heading-color: #334155;
  --card-bg: #ffffff;
  --border-color: #e5e7eb;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-modal: 0 10px 40px rgba(0,0,0,0.25);
  --th-color: #64748b;
  --scrollbar-track: #f1f5f9;
  --hover-bg: #f0f9ff;
  --tab-bg: #f8fafc;
  --tab-border: #e5e7eb;
  --tab-color: #334155;
  --subtle-bg: #f8fafc;
  /* القائمة الجانبية: في الفاتح كحلي، في الغامق نفس لون خلفية الصفحة */
  --sb-bg: #1e293b;
  --sb-text: #cbd5e1;
  --sb-text-strong: #ffffff;
  --sb-muted: #64748b;
  --sb-faint: #475569;
  --sb-hover: rgba(255,255,255,0.05);
  --sb-line: rgba(255,255,255,0.08);
  --sb-btn: rgba(255,255,255,0.1);
  --sb-btn-hover: rgba(255,255,255,0.2);
  --sb-thumb: rgba(255,255,255,0.25);
  --sb-accent: #60a5fa;
}
/* غامق: كحلي غامق مريح للعين، مش أسود خالص */
:root[data-theme="dark"] {
  --page-bg: #0b1222;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --text-label: #cbd5e1;
  --heading-color: #cbd5e1;
  --card-bg: #121b32;
  --border-color: #26335a;
  --input-bg: #0e172c;
  --input-border: #35416b;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-modal: 0 10px 40px rgba(0,0,0,0.65);
  --th-color: #94a3b8;
  --scrollbar-track: #17213d;
  --hover-bg: #17213d;
  --tab-bg: #17213d;
  --tab-border: #2c3a63;
  --tab-color: #cbd5e1;
  --subtle-bg: #1a2744;
  --sb-bg: var(--page-bg);
  --sb-text: #cbd5e1;
  --sb-text-strong: #ffffff;
  --sb-muted: #64748b;
  --sb-faint: #475569;
  --sb-hover: rgba(255,255,255,0.05);
  --sb-line: rgba(255,255,255,0.08);
  --sb-btn: rgba(255,255,255,0.1);
  --sb-btn-hover: rgba(255,255,255,0.2);
  --sb-thumb: rgba(255,255,255,0.25);
  --sb-accent: #60a5fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text-main);
  direction: rtl;
  transition: background-color .15s ease, color .15s ease;
}

* { font-family: inherit; }

.topbar {
  background: #1e293b;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
}

.topbar .user-info {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* المحتوى بياخد عرض الشاشة كله (طلب صاحب المشروع): لما تصغّر الشاشة بـ Ctrl + عجلة الماوس
   الجداول بتبان أكتر بدل ما تفضل محبوسة في عرض ثابت في النص */
.container {
  max-width: none;
  margin: 20px 0;
  padding: 0 20px 0 84px; /* الشمال أوسع شوية: مكان زرار + الأخضر العايم عشان ميغطيش على حاجة */
}
.in-frame .container { padding: 0 12px; margin: 12px 0; } /* جوه شاشة الفواتير الموحدة: مفيش زرار عايم */

.card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.card h2 {
  margin-top: 0;
  font-size: 17px;
  color: var(--heading-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

th {
  color: var(--th-color);
  font-weight: 600;
  white-space: nowrap;
}

#products-header-row th,
#si-header-row th { font-size: 11px; color: var(--text-main); }

#products-table,
#customers-table,
#drawer-stmt-table,
#sales-inv-table {
  table-layout: fixed;
  width: 100%; /* لازم عرض محدد عشان المتصفح يحترم عرض كل عمود (شوف .fixed-table) */
}
#products-table td,
#customers-table td,
#drawer-stmt-table td,
#sales-inv-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* عمود الإجراءات (عرض/تعديل/دفع...) يفضل مثبّت ظاهر على الشمال حتى لو الجدول اتسحب أفقيًا.
   قاعدة ثابتة: أي جدول فيه عمود إجراءات بنحط على خلاياه class="sticky-col" */
.table-scroll-wrap td.sticky-col,
.table-scroll-wrap th.sticky-col {
  position: sticky;
  left: 0;
  background: var(--card-bg);
  z-index: 5;
  box-shadow: -3px 0 6px rgba(0,0,0,0.06);
}
.table-scroll-wrap tr:hover td.sticky-col { background: var(--hover-bg); }
/* عنوان عمود الأزرار فوق الخلايا وهي بتتحرك (ركن الجدول) */
.table-scroll-wrap thead th.sticky-col { z-index: 6; }
/* الأزرار نفسها لازقة في أقصى الشمال جوه عمودها (مش على يمينه وسايبة فراغ يغطي الأعمدة) */
.table-scroll-wrap td.sticky-col > div { justify-content: flex-end; }

/* شريط "الإجمالي" تحت جدول المنتجات: عنصر عادي (مش جوه الجدول) عشان يفضل
   ثابت تحت مهما عملت سكرول - أكتر ثباتًا من التثبيت جوه خلايا جدول */
#products-totals-bar,
#sales-inv-totals-bar {
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
  border-top: 2px solid var(--border-color);
  padding: 6px 14px;
  font-weight: 700;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  z-index: 10;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
}
#products-totals-text,
#sales-inv-totals-text {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  white-space: nowrap;
}
#products-totals-bar > *,
#sales-inv-totals-bar > * { flex-shrink: 0; }
#products-totals-text > *,
#sales-inv-totals-text > * { flex-shrink: 0; }
#products-totals-text:empty,
#sales-inv-totals-text:empty { display: none; }

/* فلتر الفروع المميز - بيبان بوضوح فوق أي شاشة فيها بضاعة/أرقام مرتبطة بفرع */
#branch-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.branch-tab {
  flex: 1;
  min-width: 130px;
  padding: 10px 14px;
  border: 2px solid var(--tab-border);
  border-radius: 10px;
  background: var(--tab-bg);
  color: var(--tab-color);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: all .12s;
}
.branch-tab:hover { border-color: #93c5fd; }
.branch-tab.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.date-preset-tab {
  padding: 7px 12px;
  border: 2px solid var(--tab-border);
  border-radius: 8px;
  background: var(--tab-bg);
  color: var(--tab-color);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: all .12s;
}
.date-preset-tab:hover { border-color: #93c5fd; }
.date-preset-tab.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

#pe-totals-bar {
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
  border-top: 2px solid var(--border-color);
  padding: 6px 14px;
  z-index: 10;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
}

/* الجدول بقى صندوق مقفول بارتفاع معين وله سكرول بتاعه (يمين شمال وفوق تحت)،
   عشان تقدر توصله وتتحكم فيه بإيدك من غير ما تنزل في الصفحة كلها */
.table-scroll-wrap {
  overflow: auto;
  max-height: 62vh;
  scrollbar-width: auto;
}
.table-scroll-wrap::-webkit-scrollbar {
  width: 13px;
  height: 13px;
}
.table-scroll-wrap::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 8px;
}
.table-scroll-wrap::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 8px;
  border: 2px solid var(--scrollbar-track);
}
.table-scroll-wrap::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* عنوان الجدول يفضل ظاهر فوق حتى وإنت نازل في الصفوف جوه الصندوق */
.table-scroll-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 4;
}

.table-scroll-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.table-scroll-nav button {
  background: var(--subtle-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  color: #334155;
}
.table-scroll-nav button:hover { background: var(--hover-bg); }

tr:hover td { background: var(--hover-bg); }

.btn {
  display: inline-block;
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: #1d4ed8; }

.btn.secondary {
  background: var(--subtle-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn.secondary:hover { background: var(--hover-bg); }

.btn.danger { background: #dc2626; }
.btn.danger:hover { background: #b91c1c; }

.btn.small { padding: 5px 10px; font-size: 12px; }

input, select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  width: 100%;
  background: var(--input-bg);
  color: var(--text-main);
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-label);
  margin-bottom: 4px;
  margin-top: 10px;
}

form .row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
form .row > div { flex: 1; min-width: 140px; }

.error-box {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

.success-box {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--card-bg);
  padding: 32px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.login-box h1 {
  text-align: center;
  color: #1e293b;
  margin-bottom: 24px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.badge.receipt { background: #dcfce7; color: #166534; }
.badge.payment { background: #fee2e2; color: #991b1b; }

.muted { color: var(--text-muted); font-size: 13px; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.back-link { display: inline-block; margin-bottom: 12px; color: #2563eb; text-decoration: none; }

.sort-arrow { font-size: 10px; color: #2563eb; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 4px;
}

.stat-card {
  background: var(--subtle-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stat-card .stat-label {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 700;
}

.stat-card.highlight {
  background: #1e293b;
  border-color: #1e293b;
}
.stat-card.highlight .stat-label { color: #cbd5e1; }
.stat-card.highlight .stat-value { color: #fff; font-size: 26px; }

/* هيكل الصفحة الجديد: قائمة جانبية ثابتة على اليمين + محتوى الصفحة.
   الشاشة كلها بارتفاع الشاشة بالظبط (مش أكتر)، والقائمة الجانبية ثابتة
   مكانها تمامًا، وبس الجزء الأبيض (main-content) هو اللي بيتحرك (سكرول)
   لوحده لما المحتوى يطول - القائمة الجانبية متتحركش معاه خالص. */
html, body { height: 100%; }
.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sb-bg);
  color: var(--sb-text-strong);
  border-left: 1px solid var(--sb-line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width .15s ease;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-header-text,
.sidebar.collapsed .sidebar-footer > div:first-child {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#sidebar-collapse-btn {
  background: var(--sb-btn);
  border: none;
  color: var(--sb-text-strong);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}
#sidebar-collapse-btn:hover { background: var(--sb-btn-hover); }

/* الموبايل: مفيش عمود على الشمال، فالخروج بيفضل جوه القائمة */
.rail-role, #rail-logout-btn { display: none; }
.sidebar-version {
  margin-top: 8px;
  text-align: center;
  font-size: 10px;
  color: var(--sb-faint);
}

.main-content {
  height: 100vh;
  overflow-y: auto;
}
.main-content::-webkit-scrollbar { width: 12px; }
.main-content::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.main-content::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 8px;
  border: 2px solid var(--scrollbar-track);
}
.main-content::-webkit-scrollbar-thumb:hover { background: #64748b; }

.sidebar-header {
  padding: 18px 16px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--sb-line);
  background: linear-gradient(180deg, rgba(96,165,250,.10), transparent);
}
.sidebar-header-text { display: flex; align-items: center; gap: 10px; }
/* اللوجو والاسم = زرار يرجّعك لنظرة عامة */
.sb-home { text-decoration: none; color: inherit; cursor: pointer; border-radius: 12px; padding: 2px 4px; margin: -2px -4px; transition: background .15s ease; }
.sb-home:hover { background: var(--sb-hover); }
.sb-home:hover .sb-logo { transform: scale(1.06); }
.sb-logo { transition: transform .15s ease; }
.sb-logo {
  width: 36px; height: 36px; border-radius: 11px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff; font-size: 20px; font-weight: 900;
  box-shadow: 0 4px 14px rgba(59,130,246,.45);
}
.sb-brand { color: var(--sb-text-strong); }
.sb-brand b { color: var(--sb-accent); font-weight: 800; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 0;
  /* بنقلب الاتجاه هنا بس عشان السكرول باين ينتقل لأقصى يمين القائمة
     (بعيد عن المحتوى الأبيض)، وبعدين برجع الاتجاه لعناصر القائمة نفسها
     تحت عشان الكلام يفضل مقروء صح من اليمين للشمال */
  direction: ltr;
}
.sidebar-nav > * {
  direction: rtl;
}

.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  border-radius: 6px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--sb-btn-hover); }

/* عنوان المجموعة: مقفول = باهت والسهم للشمال، مفتوح = أزرق مميز وشريط على اليمين والسهم لتحت */
.sidebar-group-label {
  margin: 6px 10px 2px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--sb-text);
  border-right: 3px solid transparent;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.sidebar-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.sg-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; background: var(--sb-btn);
  filter: grayscale(.6); opacity: .8;
  transition: background .18s ease, filter .18s ease, opacity .18s ease;
}
.sg-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-group-arrow {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--sb-text); background: var(--sb-btn);
  transform: rotate(90deg);
  transition: transform .22s ease, background .18s ease, color .18s ease;
}
.sidebar-group-toggle:hover { background: var(--sb-hover); color: var(--sb-text-strong); }
.sidebar-group-toggle:hover .sg-icon { filter: none; opacity: 1; }
.sidebar-group-toggle.open {
  background: rgba(96,165,250,.14);
  color: var(--sb-accent);
  border-right-color: var(--sb-accent);
}
.sidebar-group-toggle.open .sg-icon { background: rgba(96,165,250,.22); filter: none; opacity: 1; }
.sidebar-group-toggle.open .sidebar-group-arrow {
  transform: rotate(0deg);
  background: var(--sb-accent);
  color: #0f172a;
  box-shadow: 0 0 0 3px rgba(96,165,250,.18);
}
/* الفتح والقفل بحركة ناعمة */
.sidebar-group-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .22s ease;
}
.sidebar-group-body.open { grid-template-rows: 1fr; }
.sidebar-group-inner { min-height: 0; overflow: hidden; }
.sidebar-group-body.open .sidebar-group-inner {
  margin: 2px 22px 6px 10px;
  padding: 3px 0;
  border-right: 2px solid rgba(96,165,250,.25);
}
.sidebar-group-inner .sidebar-link { margin: 1px 6px 1px 0; padding: 8px 12px; font-size: 13.5px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 10px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, transform .15s ease;
}
.sidebar-link-text { overflow: hidden; text-overflow: ellipsis; }
.sidebar-icon { flex-shrink: 0; font-size: 16px; width: 20px; text-align: center; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 6px; margin: 1px 6px; }
.sidebar.collapsed .sidebar-group-body.open .sidebar-group-inner { margin: 0; padding: 0; border: none; }
.sidebar.collapsed .sidebar-group-inner .sidebar-link { margin: 1px 6px; padding: 10px 6px; }
.sidebar.collapsed .sidebar-header { padding: 18px 8px; justify-content: center; }
.sidebar.collapsed .sidebar-link-text,
.sidebar.collapsed .sidebar-group-label,
.sidebar.collapsed .badge-soon {
  display: none;
}
.sidebar-link:hover { background: var(--sb-hover); color: var(--sb-text-strong); transform: translateX(-2px); }
.sidebar-link.active {
  background: linear-gradient(270deg, #2563eb, #4f46e5);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(37,99,235,.35);
}
.sidebar-link.active:hover { transform: none; }
.sidebar-link.disabled { color: var(--sb-faint); }
.sidebar-link.disabled:hover { background: none; color: var(--sb-faint); }

.badge-soon {
  font-size: 10px;
  background: #334155;
  color: #94a3b8;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--sb-line);
  font-size: 13px;
}
.sidebar-footer .btn.secondary { background: var(--sb-btn); color: var(--sb-text-strong); border: 1px solid var(--sb-line); }
.sidebar-footer .btn.secondary:hover { background: rgba(239,68,68,.22); border-color: rgba(239,68,68,.5); }
.sb-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-width: 0; }
.sb-user:empty { display: none; }
.sb-user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0ea5e9, #6366f1); color: #fff; font-weight: 800; font-size: 15px;
}
.sb-user-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sb-user-info b { color: var(--sb-text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-info small { color: var(--sb-muted); font-size: 11px; }

.main-content {
  flex: 1;
  min-width: 0;
}

.page-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 24px;
}
.page-header h1 { margin: 0; font-size: 19px; color: #1e293b; }

/* نافذة منبثقة (Modal) */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 4px 8px;
}
.modal-close:hover { color: #1e293b; }

/* لموديل طويل محتاج زرار الحفظ يفضل ظاهر طول الوقت من غير ما تنزل لآخر الفورم */
.modal-box-scroll {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.modal-box-scroll .modal-header {
  padding: 22px 24px 0;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.modal-box-scroll .modal-scroll-body {
  overflow-y: auto;
  padding: 0 24px 20px;
  flex: 1;
  min-height: 0;
}
.modal-box-scroll .modal-sticky-footer {
  flex-shrink: 0;
  padding: 14px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--card-bg);
  border-radius: 0 0 12px 12px;
}

.subnav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.subnav-label {
  color: #94a3b8;
  font-size: 13px;
  margin-left: 10px;
}

.subnav-link {
  color: #334155;
  text-decoration: none;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 6px;
}

.subnav-link:hover { background: var(--hover-bg); }

.subnav-link.active {
  background: #e0e7ff;
  color: #3730a3;
  font-weight: 600;
}


/* ===== جداول الأعمدة الجديدة (نفس معاملة المنتجات): عرض ثابت، سطر واحد، وشريط إجماليات ثابت تحت =====
   الاستخدام: <table class="fixed-table"> جوه .table-scroll-wrap، و<div class="totals-bar"> بعده */
/* لازم الجدول يبقى ليه عرض محدد (100%) عشان المتصفح يحترم أرقام لوحة "الأعمدة"
   (width:auto كانت بتخلّيه يتجاهلها خالص). لو مجموع الأعمدة أصغر من المساحة، الزيادة
   بتتوزع عليهم بنفس النسبة (الجدول يملا مكانه)، ولو أكبر الجدول بيتحرك يمين وشمال */
.fixed-table { table-layout: fixed; width: 100%; }
.fixed-table th { position: relative; font-size: 11px; color: #000; }
.fixed-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.totals-bar {
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
  border-top: 2px solid var(--border-color);
  padding: 6px 14px;
  font-weight: 700;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  z-index: 10;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
}
.totals-bar > * { flex-shrink: 0; }
.totals-bar .totals-text { display: flex; gap: 14px; flex-wrap: nowrap; white-space: nowrap; }
.totals-bar .totals-text > * { flex-shrink: 0; }
.totals-bar .totals-text:empty { display: none; }


/* ===== الشريط العلوي (بحث عام في البرنامج) + زرار فاتورة بيع جديدة العايم ===== */
#user-chip {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 6px;
  /* شكل زجاجي (زي الآيفون): شفاف مع تغبيش اللي وراه */
  background: rgba(255,255,255,0.55);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.65);
  border-radius: 999px;
  padding: 5px 6px;
  box-shadow: 0 8px 30px rgba(15,23,42,0.16), inset 0 1px 0 rgba(255,255,255,0.7);
}
:root[data-theme="dark"] #user-chip {
  background: rgba(30,41,70,0.45);
  border-color: rgba(255,255,255,0.14);
  box-shadow: 0 8px 30px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
}
#user-chip #notif-btn, #user-chip #theme-toggle-btn { background: rgba(255,255,255,0.35); border-color: rgba(255,255,255,0.5); }
:root[data-theme="dark"] #user-chip #notif-btn,
:root[data-theme="dark"] #user-chip #theme-toggle-btn { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.14); }
.notif-wrap { position: relative; }
#notif-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--page-bg);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  position: relative;
}
#notif-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}
#notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(15,23,42,0.2);
  z-index: 200;
}
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  color: inherit;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--hover-bg); }
.notif-ico { font-size: 16px; flex-shrink: 0; }
.notif-t { font-weight: 700; font-size: 13px; color: var(--text-main); }
.notif-s { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.notif-empty { padding: 18px; text-align: center; color: var(--text-muted); font-size: 13px; }

#theme-toggle-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--page-bg);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.chip-avatar, .chip-avatar-placeholder {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chip-avatar-placeholder {
  background: var(--page-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
}

.gs-wrap {
  position: relative;
  width: 26px;
  height: 26px;
  transition: width .22s ease;
}
.gs-wrap:hover,
.gs-wrap:focus-within { width: 210px; }
#global-search-input {
  width: 100%;
  height: 26px;
  padding: 6px 30px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  margin: 0;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity .15s ease .05s;
}
.gs-wrap:hover #global-search-input,
.gs-wrap:focus-within #global-search-input { opacity: 1; }
#global-search-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.gs-icon {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  opacity: .7;
  font-size: 12px;
  z-index: 2;
}

#global-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(15,23,42,0.2);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 200;
}
.gs-group { padding: 6px 0; border-bottom: 1px solid var(--border-color); }
.gs-group:last-child { border-bottom: none; }
.gs-group-title { font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 4px 16px; }
.gs-item { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; }
.gs-item.active, .gs-item:hover { background: var(--hover-bg); }
.gs-item .gs-ico { width: 22px; text-align: center; flex-shrink: 0; }
.gs-item .gs-t { font-weight: 600; font-size: 14px; color: var(--text-main); }
.gs-item .gs-s { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.gs-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.gs-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 999px;
  background: var(--card-bg);
  white-space: nowrap;
}
.gs-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.gs-hint {
  position: absolute; left: 30px; top: 50%; transform: translateY(-50%);
  font-size: 10.5px; color: var(--text-muted); pointer-events: none;
  opacity: 0; transition: opacity .15s ease .05s; white-space: nowrap;
}
.gs-wrap:hover .gs-hint,
.gs-wrap:focus-within .gs-hint { opacity: 1; }

#new-invoice-fab {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 55;
  display: flex;
  align-items: center;
  direction: ltr;
  height: 50px;
  min-width: 50px;
  border-radius: 25px;
  background: linear-gradient(135deg, #22c55e, #15803d);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(22,163,74,0.45);
  overflow: hidden;
  transition: box-shadow .2s ease, transform .2s ease;
}
#new-invoice-fab:hover { box-shadow: 0 8px 24px rgba(22,163,74,0.6); transform: translateY(-50%) scale(1.03); }
#new-invoice-fab .fab-plus { width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; flex-shrink: 0; line-height: 1; }
#new-invoice-fab .fab-label {
  direction: rtl;
  max-width: 0;
  opacity: 0;
  white-space: nowrap;
  font-weight: 700;
  font-size: 14px;
  transition: max-width .25s ease, opacity .2s ease, padding .25s ease;
}
#new-invoice-fab:hover .fab-label, #new-invoice-fab:focus-visible .fab-label { max-width: 240px; opacity: 1; padding: 0 18px 0 0; }
#new-invoice-fab kbd { background: rgba(255,255,255,0.25); border-radius: 5px; padding: 1px 6px; font-size: 11px; margin-right: 6px; font-family: inherit; }


/* ===== إشعار مركزي واضح (تم حفظ الفاتورة وأمثاله) ===== */
.center-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -45%) scale(.92);
  background: #16a34a;
  color: #fff;
  padding: 34px 56px;
  border-radius: 20px;
  font-size: 26px;
  font-weight: 800;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  max-width: 90vw;
  transition: opacity .2s ease, transform .2s ease;
}
.center-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.center-toast.is-error { background: #dc2626; }
.center-toast.is-warning { background: #ea580c; }

/* ===== تحذير حذف كبير (الموافقة الأولى قبل نافذة سبب الحذف) ===== */
#big-delete-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 900;
  align-items: center;
  justify-content: center;
}
#big-delete-overlay.open { display: flex; }
.big-delete-box {
  background: #dc2626;
  color: #fff;
  border-radius: 18px;
  padding: 36px 40px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.big-delete-icon { font-size: 48px; margin-bottom: 10px; }
.big-delete-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.big-delete-sub { font-size: 13.5px; opacity: 0.92; margin-bottom: 22px; }
.big-delete-actions { display: flex; gap: 12px; justify-content: center; }
.big-delete-actions .btn.secondary { background: #fff; color: #991b1b; border: none; }
.big-delete-actions .btn.danger { background: #7f1d1d; }

/* الشهر الحالي هو أكتر فترة بتتستخدم في فلتر الوقت، فبيتميّز بلون وعلامة واضحة */
.date-filter-opt-starred { background: #fef3c7; color: #92400e; font-weight: 700; }
.date-filter-opt-starred:hover { background: #fde68a !important; }

/* ===== مربع بحث العملاء ===== */
.cp-wrap { position: relative; flex: 1; min-width: 0; }
.cp-input { width: 100%; padding-left: 30px !important; }
.cp-clear { position: absolute; left: 6px; top: 7px; display: none; border: none; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.cp-list { position: absolute; top: calc(100% + 4px); right: 0; left: 0; max-height: 320px; overflow-y: auto; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 10px; box-shadow: 0 12px 28px rgba(0,0,0,0.22); z-index: 120; }
.cp-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border-color); cursor: pointer; }
.cp-item:last-child { border-bottom: none; }
.cp-item.active, .cp-item:hover { background: var(--hover-bg); }
.cp-item-main { min-width: 0; display: flex; flex-direction: column; font-size: 13.5px; color: var(--text-main); }
.cp-item-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-phone { font-size: 11.5px; color: var(--text-muted); direction: ltr; text-align: right; }
.cp-item-side { display: flex; gap: 5px; flex-shrink: 0; }
.cp-pill { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.cp-branch { background: #e0e7ff; color: #3730a3; }
.cp-alayh { background: #fee2e2; color: #b91c1c; }
.cp-lahu { background: #dcfce7; color: #166534; }
.cp-zero { background: var(--subtle-bg); color: var(--text-muted); }
.cp-hint { padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); text-align: center; }
.cp-selected-meta { display: flex; gap: 5px; margin-top: 5px; min-height: 0; }
.cp-selected-meta:empty { display: none; }
.cp-cls-company { background: #ccfbf1; color: #0f766e; }
.cp-cls-tech { background: #f3e8ff; color: #7e22ce; }
.cp-cls-default { background: var(--subtle-bg); color: var(--text-muted); }

/* ===== أسماء العملاء/الموردين (روابط) جوه الجداول =====
   بدل لون المتصفح الافتراضي (أزرق/موف) اللي مش باين في الوضع الغامق */
td a:not(.btn), td a:not(.btn):visited { color: #1d4ed8; font-weight: 700; text-decoration: none; }
td a:not(.btn):hover { text-decoration: underline; }
:root[data-theme="dark"] td a:not(.btn),
:root[data-theme="dark"] td a:not(.btn):visited { color: #7dd3fc; }

/* ===== الوضع الغامق: أشرطة السكرول وعناصر المتصفح تبقى غامقة ===== */
:root[data-theme="dark"] { color-scheme: dark; }
/* القوايم المنسدلة (select): الاختيارات نفسها غامقة، من غير الجزء الأبيض اللي كان بيظهر */
:root[data-theme="dark"] select { color-scheme: dark; background-color: var(--input-bg); color: var(--text-main); }
:root[data-theme="dark"] select option,
:root[data-theme="dark"] select optgroup { background-color: #0e172c; color: #e2e8f0; }
:root[data-theme="dark"] select option:checked { background-color: #1d4ed8; color: #fff; }
:root[data-theme="dark"] ::-webkit-scrollbar { width: 12px; height: 12px; }
:root[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--scrollbar-track); }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #35416b; border-radius: 8px; border: 2px solid var(--scrollbar-track); }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #4b5b8f; }
:root[data-theme="dark"] ::-webkit-scrollbar-corner { background: var(--scrollbar-track); }

/* مبالغ داخل/خارج - أخضر/أحمر واضحين في الوضعين */
.amt-in { color: #166534; font-weight: 700; }
.amt-out { color: #b91c1c; font-weight: 700; }
:root[data-theme="dark"] .amt-in { color: #4ade80; }
:root[data-theme="dark"] .amt-out { color: #f87171; }
:root[data-theme="dark"] input[type="file"]::file-selector-button { background: var(--subtle-bg); color: var(--text-main); border: 1px solid var(--input-border); border-radius: 6px; padding: 4px 10px; cursor: pointer; }

/* الوضع الغامق: الأخضر/الأحمر الغامق المكتوب جوه الصفحات (له/عليه، داخل/خارج)
   بيتفتّح تلقائي عشان يبان على الخلفية الكحلي */
:root[data-theme="dark"] [style*="color:#166534"]:not([style*="background"]) { color: #4ade80 !important; }
:root[data-theme="dark"] [style*="color:#b91c1c"]:not([style*="background"]) { color: #f87171 !important; }

/* ===== لوحة الأعمدة المشتركة (createSmartTable في app.js) ===== */
.smart-cols-panel { position: absolute; left: 0; top: calc(100% + 6px); background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); color: var(--text-main); padding: 10px 14px; z-index: 50; min-width: 280px; max-height: 420px; overflow-y: auto; }
.smart-cols-row { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--border-color); }
.smart-cols-row:last-child { border-bottom: none; }
.smart-cols-row button { width: 22px; height: 22px; padding: 0; font-size: 11px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--subtle-bg); color: var(--text-main); cursor: pointer; }
.smart-cols-row button:disabled { opacity: .35; cursor: default; }
.smart-cols-row label { display: flex; align-items: center; gap: 6px; font-weight: normal; flex: 1; margin: 0; font-size: 13px; white-space: nowrap; }
.smart-cols-row input[type="number"] { width: 56px; padding: 3px 5px; font-size: 12px; }

/* ===== مربع «شير» (صورة / PDF / إكسيل / واتساب) ===== */
.share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.share-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 10px; border: 2px solid var(--border-color); border-radius: 14px; background: var(--card-bg); color: var(--text-main); cursor: pointer; font-family: inherit; font-size: 15px; transition: border-color .15s ease, background .15s ease; }
.share-tile:hover:not(:disabled) { border-color: #2563eb; background: var(--hover-bg); }
.share-tile:disabled { opacity: .55; cursor: not-allowed; }
.share-ico { font-size: 34px; line-height: 1; }
.share-tile small { font-size: 12px; color: var(--text-muted); }
.share-soon { background: #fef3c7; color: #92400e !important; padding: 1px 10px; border-radius: 99px; font-weight: 700; }

/* الصنف المعلّم بالكيبورد (↑ ↓) في قوايم اختيار الأصناف - Enter بيضيفه */
/* السطر كله أزرق غامق والكلام أبيض عريض عشان يبان من أول نظرة (فاتح وغامق) */
tr.kb-active td { background: #2563eb !important; color: #fff !important; font-weight: 700; }
tr.kb-active td * { color: #fff !important; }
tr.kb-active td:first-child { box-shadow: inset -5px 0 0 #f59e0b; }
.kb-active:not(tr) { background: #2563eb !important; color: #fff !important; font-weight: 700; box-shadow: inset -5px 0 0 #f59e0b; }
.kb-active:not(tr) * { color: #fff !important; }

/* خلية التاريخ والوقت في الجداول: خط أصغر شوية (بيتحط تلقائي من app.js) */
td.dt { font-size: 12px; color: var(--text-muted); letter-spacing: .2px; }

/* أزرار نهاية الفاتورة: حفظ وطباعة / حفظ وشير */
.save-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.save-only { background: #475569; }
.btn.save-only:hover:not(:disabled) { background: #334155; }
.btn.save-print { background: #16a34a; }
.btn.save-share { background: #2563eb; }

/* =====================================================================
   الموبايل والتابلت (أقل من 900px)
   القائمة الجانبية = درج بيتفتح بزرار ☰ من شريط فوق، والمحتوى بياخد الشاشة كلها
   ===================================================================== */
#mobile-topbar, #sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  /* الصفحة كلها بتعمل سكرول عادي (مش جزء جوه جزء) */
  html, body { height: auto; }
  .app-shell { display: block; height: auto; }
  .main-content { height: auto; overflow: visible; }
  body.has-mobile-shell .main-content { padding-top: 56px; }

  /* الشريط اللي فوق */
  #mobile-topbar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; right: 0; left: 0; height: 52px; z-index: 80;
    padding: 0 10px; background: var(--sb-bg); color: var(--sb-text-strong);
    border-bottom: 1px solid var(--sb-line); box-shadow: 0 2px 8px rgba(0,0,0,.15);
  }
  :root[data-theme="dark"] #mobile-topbar { background: #121b32; }
  #mobile-menu-btn {
    width: 40px; height: 40px; border: none; border-radius: 10px; font-size: 22px; line-height: 1;
    background: var(--sb-btn); color: var(--sb-text-strong); cursor: pointer;
  }
  .mobile-topbar-title { font-size: 19px; font-weight: 800; letter-spacing: .5px; }
  .mobile-topbar-title span { color: var(--sb-accent); }

  /* القائمة الجانبية كدرج من اليمين */
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; width: 280px; max-width: 85vw; height: 100%;
    z-index: 200; transform: translateX(105%); transition: transform .22s ease;
    background: #1e293b; box-shadow: none;
  }
  :root[data-theme="dark"] .sidebar { background: #121b32; }
  body.sidebar-open .sidebar { transform: none; box-shadow: -8px 0 30px rgba(0,0,0,.35); }
  body.sidebar-open { overflow: hidden; }
  #sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 150; }
  body.sidebar-open #sidebar-backdrop { display: block; }
  #sidebar-collapse-btn { display: none; }
  .sidebar-header { padding: 16px 18px; }
  .sidebar-link, .sidebar-group-inner .sidebar-link { padding: 11px 12px; font-size: 15px; }
  .sidebar-group-label { font-size: 14px; padding: 11px 10px; }

  /* شريحة البحث/الإشعارات: جوه الشريط اللي فوق على الشمال */
  #user-chip { top: 8px; left: 8px; z-index: 90; box-shadow: none; }
  .gs-wrap:hover, .gs-wrap:focus-within { width: 170px; }

  /* زرار + الأخضر: تحت على الشمال بدل نص الشاشة */
  #new-invoice-fab { top: auto; bottom: 16px; left: 16px; transform: none; }
  #new-invoice-fab:hover { transform: none; }

  /* المسافات والخطوط */
  .container { margin: 10px auto; padding: 0 8px; }
  .card { padding: 14px 12px; margin-bottom: 12px; border-radius: 10px; }
  h2 { font-size: 18px; }
  .page-header { padding: 12px 14px; }
  .page-header h1 { font-size: 17px; }

  /* خانات الإدخال: كبيرة وسهلة باللمس، و16px عشان الآيفون ميعملش زووم */
  input, select, textarea { font-size: 16px; max-width: 100%; }
  .btn { padding: 10px 14px; }
  form .row > div { min-width: 100%; }

  /* الجداول: تتحرك يمين وشمال جوه مكانها بدل ما توسّع الصفحة */
  .table-scroll-wrap { max-height: none; -webkit-overflow-scrolling: touch; }
  :not(.table-scroll-wrap) > table:not(.fixed-table):not(.items) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .totals-bar { flex-wrap: wrap; }
  .totals-bar .totals-text { flex-wrap: wrap; white-space: normal; gap: 6px 12px; }

  /* تابات الفروع وفترات الوقت أصغر شوية */
  .branch-tab { min-width: 0; flex: 1 1 45%; padding: 9px 8px; font-size: 13px; }

  /* النوافذ: بتاخد الشاشة كلها */
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal-box { max-width: 100% !important; width: 100%; max-height: 100%; height: 100%; border-radius: 0; padding: 16px 14px; }
  .share-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .center-toast { font-size: 19px; padding: 22px 26px; max-width: 88vw; }
  .big-delete-box { padding: 26px 20px; }

  /* لوحة الأعمدة: متخرجش برة الشاشة */
  .smart-cols-panel { min-width: 260px; max-width: calc(100vw - 24px); }

  /* سطور الأصناف في فواتير البيع/الشراء: اسم الصنف سطر لوحده والأرقام تحته */
  .inv-items-head { display: none !important; }
  .inv-item-row, .show-profit .inv-item-row {
    grid-template-columns: 1fr 1fr 1fr auto !important;
    padding: 8px 0; border-bottom: 1px solid var(--border-color);
  }
  .inv-item-row > div:first-child:not(.item-no) { grid-column: 1 / -1; font-weight: 700; } /* فاتورة الشراء */
  .inv-item-row .item-no { display: none; }
  .inv-item-row .item-name { grid-column: 1 / -1; font-weight: 700; }
  .inv-item-row .item-name::before { content: attr(data-no) ". "; color: var(--text-muted); }
  .pay-type-row { gap: 6px; }
  .pay-type-btn { font-size: 14px; padding: 12px 4px; }
  .pay-line, .pay-line.single { grid-template-columns: 1fr 1fr !important; }
  .pay-sticky { top: 56px; gap: 10px; }
}

/* ===== الموبايل: زراير عمود الإجراءات أيقونات صغيرة من غير كلام =====
   كل زرار بيتعرف من وظيفته (onclick/href) وبياخد أيقونته، والكلام بيستخبى */
@media (max-width: 900px) {
  .table-scroll-wrap td.sticky-col { padding: 4px; }
  .table-scroll-wrap td.sticky-col > div { gap: 4px !important; }
  .table-scroll-wrap td.sticky-col :is(
    [onclick^="openInvoice"], [onclick^="openPurchase"], [onclick^="openReturnDetail"], [onclick^="openTransferDetail"],
    [onclick^="openDeleted"], [onclick^="openEdit("], a[href^="customer.html"], a[href^="supplier.html"], a[href^="drawer-statement.html"],
    a[href*="edit="], [onclick^="openEditUser"], [onclick^="openEditItem"], [onclick^="openEditProduct"], [onclick^="editTx"],
    [onclick^="openDelete"], [onclick^="deleteQuote"], [onclick^="deleteItem"], [onclick^="deleteProduct"],
    [onclick^="openDuplicateProduct"], [onclick^="openPriceEdit"], [onclick^="openPayModal"], [onclick^="toggleActive"]
  ) {
    font-size: 0 !important; width: 30px; height: 30px; padding: 0 !important; border-radius: 8px !important;
    display: inline-flex !important; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: none !important;
  }
  .table-scroll-wrap td.sticky-col :is([onclick^="openInvoice"], [onclick^="openPurchase"], [onclick^="openReturnDetail"], [onclick^="openTransferDetail"], [onclick^="openDeleted"], [onclick^="openEdit("], a[href^="customer.html"], a[href^="supplier.html"])::before { content: "👁"; font-size: 15px; }
  .table-scroll-wrap td.sticky-col a[href^="drawer-statement.html"]::before { content: "📒"; font-size: 15px; }
  .table-scroll-wrap td.sticky-col :is(a[href*="edit="], [onclick^="openEditUser"], [onclick^="openEditItem"], [onclick^="openEditProduct"], [onclick^="editTx"])::before { content: "✎"; font-size: 16px; font-weight: 700; }
  .table-scroll-wrap td.sticky-col :is([onclick^="openDelete"], [onclick^="deleteQuote"], [onclick^="deleteItem"], [onclick^="deleteProduct"])::before { content: "🗑"; font-size: 14px; }
  .table-scroll-wrap td.sticky-col [onclick^="openDuplicateProduct"]::before { content: "⧉"; font-size: 16px; }
  .table-scroll-wrap td.sticky-col [onclick^="openPriceEdit"]::before { content: "💲"; font-size: 14px; }
  .table-scroll-wrap td.sticky-col [onclick^="openPayModal"]::before { content: "💸"; font-size: 15px; }
  .table-scroll-wrap td.sticky-col [onclick^="toggleActive"]::before { content: "⏻"; font-size: 15px; }
  .table-scroll-wrap td.sticky-col .muted { font-size: 10px !important; }

  /* عرض عمود الأزرار على قد الأيقونات (بيغطي على العرض المكتوب في الكود) */
  .table-scroll-wrap th.sticky-col { width: 108px !important; }                      /* 3 زراير */
  #po-table th.sticky-col { width: 142px !important; }                                 /* 4 زراير */
  :is(#suppliers-table, #usr-table, #ql-table, #items-table) th.sticky-col { width: 76px !important; }  /* زرارين */
  :is(#customers-table, #drawer-table, #dl-table, #ed-table) th.sticky-col { width: 44px !important; }  /* زرار واحد */
  #tx-table th.sticky-col { width: 60px !important; }
}

/* ===== الموبايل: كروت بدل الجداول (createMobileList / createSmartTable) - الكمبيوتر مبيتأثرش ===== */
.m-list, .m-only { display: none; }
@media (max-width: 900px) {
  .m-has-list, .m-hide { display: none !important; }
  .m-only { display: block; }
  .m-list { display: flex; flex-direction: column; gap: 8px; }
  .m-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 14px; padding: 11px 13px;
    box-shadow: var(--shadow-card); cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .m-card:active { background: var(--hover-bg); }
  .m-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
  .m-card-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 800; color: var(--heading-color); line-height: 1.5; word-break: break-word; }
  .m-card-main { flex: 1; min-width: 0; }
  .m-card-main .m-card-sub { margin-top: 1px; }
  .m-avatar { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800; color: var(--av); background: color-mix(in srgb, var(--av) 14%, transparent); }
  .m-contact { display: flex; gap: 8px; margin-top: 9px; }
  .m-contact a { flex: 1; text-align: center; padding: 8px 6px; border-radius: 10px; font-size: 13.5px; font-weight: 700; text-decoration: none;
    background: var(--subtle-bg); border: 1px solid var(--border-color); color: var(--text-main); direction: ltr; }
  .m-contact a.wa { flex: 0 0 auto; padding: 8px 14px; direction: rtl; background: rgba(22,163,74,.12); border-color: rgba(22,163,74,.3); color: #15803d; }
  :root[data-theme="dark"] .m-contact a.wa { color: #4ade80; }
  /* كارت رأس الشاشة (العميل / المورد): الاسم والرصيد كبار والأزرار شبكة */
  .m-hero > div:first-child > div:first-child { width: 100%; }
  .m-hero h2 { font-size: 21px; margin-bottom: 4px; }
  .m-hero #customer-balance-line, .m-hero #supplier-balance-line { font-size: 20px !important; padding: 10px 12px; border-radius: 12px; background: var(--subtle-bg); }
  .m-btn-grid { display: grid !important; grid-template-columns: repeat(3, 1fr); width: 100%; gap: 6px !important; }
  .m-btn-grid .btn { padding: 10px 4px; font-size: 12.5px; white-space: normal; line-height: 1.35; }
  /* عنوان الشاشة في الشريط اللي فوق بدل سطر العنوان الكبير */
  body.mt-has-title .page-header { display: none; }
  .mobile-topbar-page { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
  .mobile-topbar-logo { width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff; font-weight: 900; font-size: 15px; flex-shrink: 0; }
  /* ===== كارت الصنف (المنتجات): الأسعار التلاتة + كمية كل فرع ===== */
  .m-thumb { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border-color); }
  .m-product .m-avatar { width: 46px; height: 46px; }
  .m-chev { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    background: var(--subtle-bg); color: var(--text-muted); font-size: 12px; }
  .m-product.open { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15), var(--shadow-card); }
  .m-product.open .m-chev { background: #2563eb; color: #fff; }
  .m-prices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
  .m-price { border-radius: 11px; padding: 6px 8px; text-align: center; border: 1px solid transparent; }
  .m-price small { display: block; font-size: 11.5px; font-weight: 700; opacity: .85; }
  .m-price b { display: block; font-size: 17px; font-weight: 900; white-space: nowrap; }
  .m-price.sale { background: rgba(37,99,235,.10); color: #1d4ed8; border-color: rgba(37,99,235,.25); }
  .m-price.tech { background: rgba(234,88,12,.10); color: #c2410c; border-color: rgba(234,88,12,.25); }
  .m-price.comp { background: rgba(124,58,237,.10); color: #6d28d9; border-color: rgba(124,58,237,.25); }
  :root[data-theme="dark"] .m-price.sale { color: #93c5fd; }
  :root[data-theme="dark"] .m-price.tech { color: #fdba74; }
  :root[data-theme="dark"] .m-price.comp { color: #c4b5fd; }
  .m-stocks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .m-stock { font-size: 12.5px; padding: 4px 10px; border-radius: 99px; background: rgba(22,163,74,.10); color: #166534; font-weight: 600; white-space: nowrap; }
  .m-stock b { font-weight: 900; font-size: 13.5px; }
  .m-stock.low { background: rgba(217,119,6,.15); color: #b45309; }
  .m-stock.zero { background: rgba(220,38,38,.10); color: #b91c1c; }
  .m-stock.total { background: var(--subtle-bg); color: var(--text-main); }
  .m-stock.svc { background: rgba(79,70,229,.12); color: #4338ca; }
  .m-stock.sel { outline: 2px solid currentColor; }
  :root[data-theme="dark"] .m-stock { color: #4ade80; }
  :root[data-theme="dark"] .m-stock.low { color: #fbbf24; }
  :root[data-theme="dark"] .m-stock.zero { color: #f87171; }
  :root[data-theme="dark"] .m-stock.total { color: var(--text-main); }
  :root[data-theme="dark"] .m-stock.svc { color: #a5b4fc; }
  .m-details { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border-color); cursor: default; }
  .m-unit { margin-bottom: 10px; }
  .m-unit-name { font-size: 13.5px; font-weight: 800; color: var(--text-main); }
  .m-unit .m-prices { margin-top: 4px; }
  .m-unit .m-price b { font-size: 15px; }
  /* البحث يفضل ظاهر فوق وإنت بتعمل سكرول */
  .m-search-row { position: sticky; top: 52px; z-index: 30; background: var(--card-bg); padding: 8px 0; margin: -4px 0 6px !important; gap: 6px !important; }
  .m-search-row input { flex: 1 1 100% !important; min-width: 0 !important; font-size: 16px; padding: 12px 14px; border-radius: 12px; margin: 0; }
  .m-search-row .btn { flex: 1 1 40%; padding: 8px 10px !important; font-size: 12.5px; }
  /* ===== اختيار الأصناف في الفاتورة (بيع/شراء): ملء الشاشة على الموبايل ===== */
  #picker-close-m { display: none; }
  .picker-search-row { flex-wrap: wrap; gap: 6px !important; }
  #picker-search { flex: 1 1 100% !important; font-size: 16px; padding: 13px 14px; border-radius: 12px; }
  .picker-search-row .btn { flex: 1 1 auto; }
  .picker-wrap.open { position: fixed !important; inset: 0; z-index: 400; margin: 0 !important; background: var(--card-bg);
    display: flex; flex-direction: column; padding: 10px 10px 0; }
  body:has(.picker-wrap.open) { overflow: hidden; }
  .picker-wrap.open .picker-search-row { flex-wrap: wrap; gap: 6px !important; }
  .picker-wrap.open #picker-search { flex: 1 1 100% !important; font-size: 16px; padding: 13px 14px; border-radius: 12px; }
  .picker-wrap.open .picker-search-row .btn { flex: 1 1 auto; padding: 9px 8px; font-size: 13px; }
  .picker-wrap.open #picker-close-m { display: inline-flex; justify-content: center; }
  .picker-wrap:not(.open) #picker-filters-btn-m { display: none; }
  .picker-wrap.open .picker-dropdown { position: static !important; display: flex !important; flex-direction: column; flex: 1; min-height: 0;
    margin-top: 8px; padding: 0; border: none; box-shadow: none; background: transparent; }
  .picker-wrap.open .picker-dropdown .table-scroll-wrap { max-height: none !important; flex: 1; overflow-y: auto; border: none; }
  .picker-wrap.open #picker-table, .picker-wrap.open #picker-table tbody { display: block; width: 100%; }
  .picker-wrap.open #picker-table thead { display: none; }
  .picker-wrap.open #picker-table tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 12px; padding: 11px 6px;
    border-bottom: 1px solid var(--border-color); }
  .picker-wrap.open #picker-table tr:active { background: var(--hover-bg); }
  .picker-wrap.open #picker-table td { display: inline; padding: 0 !important; border: none !important; white-space: nowrap; font-size: 13px; color: var(--text-muted); }
  .picker-wrap.open #picker-table td[data-label]:not([data-label=""])::before { content: attr(data-label) ": "; font-size: 11.5px; }
  .picker-wrap.open #picker-table td[data-k="name"] { flex: 1 1 100%; white-space: normal; font-size: 15px; font-weight: 800; color: var(--heading-color); }
  .picker-wrap.open #picker-table td[data-k="name"]::before, .picker-wrap.open #picker-table td[data-k="id"] { display: none; }
  .picker-wrap.open #picker-table td:is([data-k="sale_price"], [data-k="technician_price"], [data-k="company_price"]) { color: #2563eb; font-weight: 800; font-size: 14px; }
  .picker-wrap.open #picker-table td[data-k="quantity"] { color: #16a34a; font-weight: 800; }
  /* رقم كبير مميز (إجمالي الخزنة...) */
  .m-big-total { border-radius: 16px; padding: 16px 18px; margin-bottom: 10px; color: #fff;
    background: linear-gradient(135deg, #1d4ed8 0%, #4f46e5 60%, #7c3aed 100%); box-shadow: 0 8px 22px rgba(79,70,229,.3); }
  .m-big-total small { display: block; font-size: 13px; font-weight: 700; opacity: .9; }
  .m-big-total b { display: block; font-size: 30px; font-weight: 900; letter-spacing: .5px; margin: 2px 0; }
  .m-big-total span { font-size: 12px; opacity: .85; }
  /* الأرقام بالسالب: علامة - على الشمال صح (مش بعد الرقم) */
  .m-big-total b, .m-summary b, .m-tx-amount > span { unicode-bidi: plaintext; text-align: right; }
  .m-big-total b, .m-summary b { direction: ltr; text-align: right; }
  /* سطر حركة (كشف حساب / خزنة): أيقونة + البيان + المبلغ والرصيد بعده */
  .m-tx { display: flex; align-items: center; gap: 10px; }
  .m-tx-main { flex: 1; min-width: 0; }
  .m-tx-main .m-card-title { font-size: 14px; }
  .m-tx-icon { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; }
  .m-tx-icon.alayh { background: rgba(220,38,38,.12); color: #dc2626; }
  .m-tx-icon.lahu { background: rgba(22,163,74,.13); color: #16a34a; }
  .m-tx-side { flex-shrink: 0; text-align: left; }
  .m-tx-amount { font-size: 15.5px; font-weight: 800; white-space: nowrap; text-align: left; }
  .m-tx-amount small { font-size: 11.5px; font-weight: 700; }
  .m-tx-amount.alayh { color: #dc2626; }
  .m-tx-amount.lahu { color: #16a34a; }
  .m-tx-bal { font-size: 12px; white-space: nowrap; margin-top: 2px; }
  .m-tx-bal span { font-weight: 700 !important; }
  .m-card-amount { flex-shrink: 0; font-size: 15px; font-weight: 800; white-space: nowrap; }
  .m-card-sub { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 12.5px; color: var(--text-muted); }
  .m-card-sub > span:not(:last-child)::after { content: "•"; margin-right: 10px; opacity: .6; }
  .m-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border-color); }
  .m-card-grid > div { min-width: 0; display: flex; flex-direction: column; }
  .m-card-grid small { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
  .m-card-grid span { font-size: 14px; font-weight: 700; color: var(--text-main); overflow: hidden; text-overflow: ellipsis; }
  .m-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; justify-content: flex-end; }
  .m-card-actions > div { display: flex !important; flex-wrap: wrap; gap: 6px !important; }
  .m-card-actions .btn, .m-card-actions button { padding: 7px 12px; font-size: 13px; }
  .m-sortbar { display: flex; align-items: center; gap: 6px; }
  .m-count { flex: 1; font-size: 13px; font-weight: 700; color: var(--text-muted); }
  .m-sortbar select { width: auto; max-width: 55%; margin: 0; padding: 7px 10px; font-size: 14px; }
  .m-sort-dir { width: 38px; height: 38px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--subtle-bg); color: var(--text-main); font-size: 13px; }
  .m-empty { text-align: center; padding: 24px; color: var(--text-muted); }
  .m-more { width: 100%; }
  .m-pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13.5px; font-weight: 800; white-space: nowrap; }
  .m-pill.alayh { background: rgba(220,38,38,.12); color: #b91c1c; }
  .m-pill.lahu { background: rgba(22,163,74,.13); color: #166534; }
  .m-pill.zero { background: var(--subtle-bg); color: var(--text-muted); }
  :root[data-theme="dark"] .m-pill.alayh { color: #f87171; }
  :root[data-theme="dark"] .m-pill.lahu { color: #4ade80; }
  /* كروت ملخص فوق القايمة (إجماليات) */
  .m-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; margin-bottom: 10px; }
  .m-summary > div { background: var(--subtle-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 8px 10px; }
  .m-summary small { display: block; font-size: 11.5px; color: var(--text-muted); font-weight: 700; }
  .m-summary b { font-size: 16px; white-space: nowrap; }
  /* شرايح اختيار سريعة (ترتيب / فلتر) بتتحرك يمين وشمال */
  .m-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
  .m-chips button { flex-shrink: 0; padding: 7px 13px; border-radius: 99px; border: 1px solid var(--border-color); background: var(--subtle-bg);
    color: var(--text-main); font-family: inherit; font-size: 13px; font-weight: 700; white-space: nowrap; }
  .m-chips button.active { background: #2563eb; border-color: #2563eb; color: #fff; }
  /* تابات الفروع (الشركة / بورسعيد / المطرية): سطر واحد بيتحرك يمين وشمال */
  #branch-filter-bar { display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  #branch-filter-bar .branch-tab { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; border-radius: 99px; margin: 0; }
  .m-scroll-row { flex-wrap: nowrap !important; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .m-scroll-row > * { flex-shrink: 0; white-space: nowrap; }
  /* زرار الفلاتر: الفلاتر مقفولة لحد ما تدوس عليه */
  .m-filter-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .m-filters:not(.open) { display: none !important; }
}

/* موبايل صغير جدًا */
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .share-tile { padding: 14px 6px; }
}


/* ===== عمود الأيقونات على الشمال (الكمبيوتر بس) =====
   فاتورة جديدة + بحث + إشعارات + الوضع الغامق + صورتك، فوق بعض في عمود ثابت بلون القائمة،
   والمحتوى بيبدأ بعده فمبيغطيش على أي قايمة أو جدول. اللي بيفتح (بحث/إشعارات) بيطلع على يمينه. */
@media (min-width: 901px) {
  #user-chip {
    top: 0; left: 0; bottom: 0;
    width: 60px;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-radius: 0;
    background: var(--sb-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border: none;
    border-right: 1px solid var(--sb-line);
    box-shadow: 2px 0 12px rgba(15,23,42,0.12);
  }
  :root[data-theme="dark"] #user-chip { background: var(--sb-bg); border-color: var(--sb-line); box-shadow: 2px 0 12px rgba(0,0,0,0.35); }
  .container { padding-left: 80px; }
  .rail-spacer { flex: 1; }

  /* تحت الصورة: الوظيفة بخط صغير + أيقونة الخروج. ومربع الاسم والخروج اللي تحت القائمة بيستخبى */
  #user-chip .rail-role {
    display: block; margin-top: -6px; max-width: 56px; font-size: 10px; font-weight: 700; color: var(--sb-muted);
    text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #user-chip #rail-logout-btn {
    display: inline-flex; width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer;
    align-items: center; justify-content: center; color: #fff;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.10);
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
  }
  #user-chip #rail-logout-btn:hover { background: rgba(239,68,68,.30); border-color: rgba(239,68,68,.6); transform: scale(1.06); }
  .sidebar-footer .sb-user, .sidebar-footer .sb-logout { display: none !important; }
  .sidebar-footer { padding: 8px 14px; }
  .sidebar-version { margin-top: 0; }

  /* كل الأيقونات نفس المقاس */
  #user-chip #notif-btn, #user-chip #theme-toggle-btn, #user-chip .gs-wrap,
  #user-chip .chip-avatar, #user-chip .chip-avatar-placeholder {
    width: 40px; height: 40px; border-radius: 12px; font-size: 18px;
  }
  #user-chip #notif-btn, #user-chip #theme-toggle-btn, #user-chip .chip-avatar-placeholder {
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); color: #fff;
    transition: background .15s ease, transform .15s ease;
  }
  #user-chip #notif-btn:hover, #user-chip #theme-toggle-btn:hover { background: rgba(255,255,255,0.18); transform: scale(1.06); }
  #user-chip .chip-avatar { border: 2px solid rgba(255,255,255,0.35); border-radius: 50%; }
  #user-chip .chip-avatar-placeholder { border-radius: 50%; }
  #user-chip #notif-badge { top: -5px; left: auto; right: -5px; min-width: 18px; height: 18px; font-size: 11px; }

  /* زرار فاتورة البيع الجديدة: مربع أخضر فوق، والاسم بيطلع على يمينه لما تقف عليه */
  #user-chip #new-invoice-fab {
    position: relative; left: auto; top: auto; transform: none;
    width: 44px; min-width: 44px; height: 44px; border-radius: 14px; overflow: visible; margin-bottom: 4px;
  }
  #user-chip #new-invoice-fab:hover { transform: scale(1.06); }
  #user-chip #new-invoice-fab .fab-plus { width: 44px; height: 44px; font-size: 26px; }
  #user-chip #new-invoice-fab .fab-label {
    position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    max-width: none; padding: 7px 12px; border-radius: 9px; background: #15803d; box-shadow: 0 6px 18px rgba(0,0,0,.2);
    pointer-events: none;
  }
  #user-chip #new-invoice-fab:hover .fab-label { opacity: 1; padding: 7px 12px; }

  /* البحث: الأيقونة في العمود، والخانة بتفتح على يمينها */
  #user-chip .gs-wrap { position: relative; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); cursor: text; transition: background .15s ease; }
  #user-chip .gs-wrap:hover, #user-chip .gs-wrap:focus-within { width: 40px; background: rgba(255,255,255,0.18); }
  #user-chip .gs-icon { right: 50%; transform: translate(50%, -50%); font-size: 17px; opacity: .95; }
  #user-chip #global-search-input {
    position: absolute; left: calc(100% + 12px); top: 0; height: 40px; width: 0; padding: 0;
    border-radius: 12px; opacity: 0; pointer-events: none;
    transition: width .2s ease, opacity .15s ease, padding .2s ease;
    box-shadow: 0 10px 28px rgba(15,23,42,0.22);
  }
  #user-chip .gs-wrap:focus-within #global-search-input { width: 340px; padding: 6px 12px; opacity: 1; pointer-events: auto; }
  #user-chip .gs-wrap:hover #global-search-input { opacity: 0; }
  #user-chip .gs-wrap:focus-within:hover #global-search-input { opacity: 1; }
  #user-chip .gs-hint { display: none; }
  #user-chip #global-search-results { left: calc(100% + 12px); top: 48px; width: 340px; }
  #user-chip #notif-panel { left: calc(100% + 12px); top: 0; }
}


/* ===== نافذة المستند فوق التقارير (openDocPopup) ===== */
.doc-popup-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(15,23,42,0.55); display: flex; align-items: center; justify-content: center; padding: 24px; }
.doc-popup { position: relative; width: min(1100px, 100%); height: min(92vh, 100%); background: var(--card-bg); border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.35); overflow: hidden; }
.doc-popup iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--card-bg); }
.doc-popup-close { position: absolute; top: 10px; left: 10px; z-index: 2; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border-color); background: var(--card-bg); color: var(--text-main); font-size: 18px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.doc-popup-close:hover { background: #dc2626; color: #fff; border-color: #dc2626; }
@media (max-width: 900px) { .doc-popup-overlay { padding: 0; } .doc-popup { width: 100%; height: 100%; border-radius: 0; } }
/* جوه النافذة: القايمة مستخبية والمستند واخد المساحة كلها */
.doc-embed .app-shell { display: none !important; }
.doc-embed body { background: var(--card-bg); }
.doc-embed .modal-overlay { background: transparent; padding: 0; align-items: stretch; }
.doc-embed .modal-box { max-width: 100% !important; width: 100%; max-height: 100%; height: 100%; border-radius: 0; box-shadow: none; padding-top: 18px; }
.doc-embed .modal-box .modal-close { display: none; }


/* ===== نافذة سؤال في نص الشاشة (showChoiceDialog) ===== */
.choice-overlay { position: fixed; inset: 0; z-index: 5000; background: rgba(15,23,42,0.55); display: flex; align-items: center; justify-content: center; padding: 20px; animation: choice-fade .15s ease; }
.choice-overlay.closing { opacity: 0; transition: opacity .12s ease; }
.choice-box {
  width: min(560px, 100%); background: var(--card-bg); color: var(--text-main); border-radius: 20px; padding: 26px 26px 20px; text-align: center;
  border-top: 6px solid #f59e0b; box-shadow: 0 24px 60px rgba(0,0,0,.35); animation: choice-pop .18s ease;
}
.choice-sticker { position: relative; width: 92px; height: 92px; margin: -64px auto 10px; border-radius: 50%; background: linear-gradient(135deg, #fde68a, #f59e0b); display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 24px rgba(245,158,11,.45); border: 5px solid var(--card-bg); }
.choice-sticker-main { font-size: 46px; line-height: 1; animation: choice-wiggle 1.6s ease-in-out infinite; }
.choice-sticker-badge { position: absolute; bottom: -2px; left: -4px; width: 36px; height: 36px; border-radius: 50%; background: #dc2626; color: #fff; font-size: 20px; display: flex; align-items: center; justify-content: center; border: 3px solid var(--card-bg); font-weight: 800; }
.choice-title { font-size: 21px; font-weight: 800; color: var(--heading-color); margin-bottom: 6px; }
.choice-msg { font-size: 14.5px; color: var(--text-muted); line-height: 1.8; margin-bottom: 4px; }
.choice-actions { display: flex; gap: 12px; margin-top: 18px; }
.choice-col { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 5px; min-width: 0; }
.choice-btn { display: flex; align-items: center; justify-content: center; gap: 7px; height: 48px; border-radius: 12px; font-family: inherit; font-size: 15px; font-weight: 800; cursor: pointer; border: 2px solid transparent; transition: transform .1s ease, filter .1s ease; white-space: nowrap; }
.choice-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.choice-btn:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.choice-btn.primary { background: #16a34a; color: #fff; }
.choice-btn.danger { background: transparent; color: #dc2626; border-color: #dc2626; }
.choice-btn.danger:hover { background: #dc2626; color: #fff; }
.choice-btn.neutral { background: var(--subtle-bg); color: var(--text-main); border-color: var(--border-color); }
.choice-keys { font-size: 11.5px; color: var(--text-muted); letter-spacing: .5px; }
@keyframes choice-fade { from { opacity: 0; } }
@keyframes choice-pop { from { transform: scale(.92); opacity: 0; } }
@keyframes choice-wiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-10deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-4deg); } 80% { transform: rotate(2deg); } }
@media (max-width: 600px) { .choice-actions { flex-direction: column; } }


/* ===== المرتجع: آجل (على الحساب) / نقدي / مقسوم ===== */
.settle-type-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.settle-type-btn { border: 2px solid var(--border-color); background: var(--card-bg); border-radius: 12px; padding: 12px 8px; font-size: 16px; font-weight: 800; cursor: pointer; font-family: inherit; color: var(--text-main); }
.settle-type-btn small { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-top: 2px; }
.settle-type-btn.active { border-color: #2563eb; background: #eff6ff; color: #1d4ed8; }
:root[data-theme="dark"] .settle-type-btn.active { background: rgba(37,99,235,0.2); color: #93c5fd; }
.settle-type-btn:disabled { opacity: .4; cursor: not-allowed; text-decoration: line-through; }
.settle-summary { padding: 10px 14px; border-radius: 10px; background: var(--subtle-bg); border: 1px solid var(--border-color); font-size: 14px; font-weight: 700; margin-bottom: 6px; }
@media (max-width: 900px) { .settle-type-row { gap: 6px; } .settle-type-btn { font-size: 14px; padding: 10px 4px; } }


/* ===== العروض الجاهزة: مربعات بصورة واسم وسعر ===== */
.pkg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.pkg-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0 0 12px; border: 2px solid var(--border-color); border-radius: 16px; background: var(--card-bg); color: var(--text-main); cursor: pointer; font-family: inherit; overflow: hidden; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; text-align: center; }
.pkg-tile:hover { transform: translateY(-3px); border-color: #2563eb; box-shadow: 0 10px 24px rgba(37,99,235,.18); }
.pkg-img { width: 100%; height: 130px; display: flex; align-items: center; justify-content: center; font-size: 54px; background: var(--subtle-bg); border-bottom: 1px solid var(--border-color); }
.pkg-img img { width: 100%; height: 100%; object-fit: cover; }
.pkg-name { font-size: 16px; font-weight: 800; padding: 6px 10px 0; color: var(--heading-color); }
.pkg-price { font-size: 22px; font-weight: 800; color: #16a34a; }
.pkg-price small { font-size: 13px; }
.pkg-old { font-size: 12.5px; color: var(--text-muted); text-decoration: line-through; margin-top: -4px; }
.pkg-count { font-size: 12px; color: var(--text-muted); }


/* سطر الصنف اللي لسه متضاف بالسكان: بينوّر أخضر ثانية */
@keyframes scan-flash { 0% { background: rgba(22,163,74,.45); box-shadow: inset 4px 0 0 #16a34a; } 100% { background: transparent; box-shadow: inset 4px 0 0 transparent; } }
.scan-flash, .scan-flash > * { animation: scan-flash 1.5s ease-out; }

/* ===== أقسام بتتفتح وتتقفل (الإعدادات / الصلاحيات) - بنفس روح القائمة الجانبية ===== */
.cs-card { border: 1px solid var(--border-color); border-radius: 14px; background: var(--card-bg); margin-bottom: 10px;
  box-shadow: var(--shadow-card); overflow: hidden; }
.cs-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; user-select: none;
  border-right: 4px solid transparent; transition: background .15s ease, border-color .15s ease; }
.cs-head:hover { background: var(--hover-bg); }
.cs-icon { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; background: var(--subtle-bg); }
.cs-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 800; color: var(--heading-color); }
.cs-sub { font-size: 12px; font-weight: normal; color: var(--text-muted); margin-right: 6px; }
.cs-arrow { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; background: var(--subtle-bg); color: var(--text-muted); transform: rotate(90deg); transition: transform .2s ease, background .15s ease, color .15s ease; }
.cs-card.open > .cs-head { border-right-color: #2563eb; background: rgba(37,99,235,.06); }
.cs-card.open > .cs-head .cs-title { color: #2563eb; }
:root[data-theme="dark"] .cs-card.open > .cs-head .cs-title { color: #60a5fa; }
.cs-card.open > .cs-head .cs-arrow { transform: rotate(0deg); background: #2563eb; color: #fff; }
.cs-body { padding: 4px 16px 16px; }
.cs-card:not(.open) > .cs-body { display: none; }
.cs-card .cs-card { box-shadow: none; margin-bottom: 8px; }
.cs-card .cs-card > .cs-head { padding: 9px 12px; }
.cs-card .cs-card .cs-title { font-size: 14px; }
.cs-card .cs-card .cs-icon { width: 28px; height: 28px; font-size: 15px; }
.pg-count { font-size: 12px; font-weight: 800; padding: 2px 10px; border-radius: 99px; background: rgba(22,163,74,.12); color: #16a34a; }
.pg-count.none { background: var(--subtle-bg); color: var(--text-muted); }
.pg-diff-count { font-size: 12px; font-weight: 800; padding: 2px 10px; border-radius: 99px; background: rgba(217,119,6,.16); color: #b45309; }
:root[data-theme="dark"] .pg-diff-count { color: #fbbf24; }
table.perm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.perm-table th { text-align: right; color: var(--text-muted); font-size: 12px; font-weight: 700; padding: 6px 8px; }
table.perm-table th.perm-action-col, table.perm-table td.perm-action-col { text-align: center; width: 70px; }
table.perm-table td { padding: 8px; border-top: 1px solid var(--border-color); }
table.perm-table td.perm-module-name { font-weight: 600; color: var(--text-main); }
table.perm-table input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
table.perm-table td.perm-diff { background: rgba(217,119,6,.16); box-shadow: inset 0 0 0 2px #d97706; border-radius: 6px; }

/* ===== نقاط الولاء ===== */
.loyalty-switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 800; font-size: 15px; cursor: pointer; }
.loyalty-switch input { width: 22px; height: 22px; margin: 0; accent-color: #16a34a; cursor: pointer; }
/* ===== نقاط الولاء في فاتورة البيع ===== */
.loyalty-box { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; margin-top: 10px;
  padding: 8px 12px; border-radius: 10px; border: 1.5px dashed #d97706; background: rgba(217,119,6,.08); color: var(--text-main); font-size: 14px; }
:root[data-theme="dark"] .loyalty-box { background: rgba(217,119,6,.16); }
.cp-pill.cp-points { background: rgba(217,119,6,.15); color: #b45309; }
:root[data-theme="dark"] .cp-pill.cp-points { color: #fbbf24; }

/* ===== اختيار الوحدة جوه سطر الصنف (لفة 100 / متر) ===== */
.unit-select { width: auto; margin: 0; padding: 3px 6px; font-size: 12.5px; font-weight: 800; border-radius: 8px;
  border: 1.5px solid #0891b2; background: rgba(8,145,178,.08); color: var(--text-main); cursor: pointer; }
:root[data-theme="dark"] .unit-select { background: rgba(8,145,178,.18); }

/* ===== محرر وحدات الصنف (شاشة المنتجات) ===== */
.unit-row { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; padding: 8px; margin-bottom: 6px;
  border: 1px solid var(--border-color); border-radius: 10px; background: var(--subtle-bg); }
.unit-cell { flex: 1 1 130px; min-width: 0; }
.unit-cell.sm { flex: 1 1 90px; }
.unit-cell label { font-size: 12px; margin: 0 0 2px; }
.unit-cell input { margin: 0; }
.unit-row .unit-del { flex: 0 0 auto; height: 34px; }

/* ===== نافذة موافقة المدير (كود سري) ===== */
.approval-form { margin-top: 6px; }
.approval-pin {
  display: block; width: 220px; max-width: 100%; margin: 6px auto 4px; text-align: center;
  font-size: 26px; font-weight: 800; letter-spacing: 10px; padding: 10px 12px;
  -webkit-text-security: disc; border: 2px solid #2563eb; border-radius: 12px;
  background: var(--input-bg, var(--card-bg)); color: var(--text-main);
}
.approval-err { min-height: 18px; color: #dc2626; font-weight: 700; font-size: 13px; text-align: center; margin-bottom: 6px; }
