/* نظام إدارة الأوردرات والمخزون — نسخة مستقلة — تصميم بريميوم (لافندر + بيرجاندي) */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  /* لافندر */
  --lav-50: #F6F2FC;
  --lav-100: #EDE7F8;
  --lav-200: #DDD2F2;
  --lav-300: #C9B8E8;
  --lav-400: #A98FD8;
  --lav-500: #8B6CC6;
  --lav-600: #7C5CBF;
  --lav-700: #6D28D9;
  /* بيرجاندي */
  --burg-500: #9D2C4A;
  --burg-600: #8E2A4A;
  --burg-700: #7B1E3B;
  --burg-800: #5E1730;
  /* ذهبي خفيف — لمسة بس */
  --gold: #C9A227;
  /* أساسيات */
  --bg: #F2EDFA;
  --card: #ffffff;
  --text: #2E2140;
  --muted: #7A6A92;
  --border: #E4DCF3;
  --primary: #8E2A4A;
  --primary-dark: #7B1E3B;
  --green: #16a34a;
  --orange: #ea580c;
  --red: #dc2626;
  --purple: #7c3aed;
  --radius: 16px;
  --shadow-soft: 0 6px 20px rgba(124, 92, 191, 0.10);
  --shadow-lift: 0 10px 28px rgba(123, 30, 59, 0.16);
}
body {
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  background: linear-gradient(180deg, #F2EDFA 0%, #EFE7F9 40%, #F2EDFA 100%);
  background-attachment: fixed;
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
}
/* الوضع الليلي 🌙 — بيقلب الألوان كلها غامقة.
   الفاتورة والشيتات والليبلات بيضاء أصلًا في الـ CSS بتاعها، فبتفضل بيضاء وبتتطبع زي ما هي. */
body.dark {
  --bg: #171221;
  --card: #221B31;
  --text: #F1EAFB;
  --muted: #B3A6CC;
  --border: #3A2F52;
  --lav-50: #2A2140;
  --lav-100: #332847;
  --lav-200: #453863;
  --lav-300: #5B4A7D;
  --lav-400: #8B6CC6;
  --lav-500: #A98FD8;
  --lav-600: #B9A3E3;
  --lav-700: #C9B8E8;
  --primary: #E0789A;
  --primary-dark: #E0789A;
  --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 10px 28px rgba(0, 0, 0, 0.45);
  background: linear-gradient(180deg, #171221 0%, #1D1629 40%, #171221 100%);
  background-attachment: fixed;
}
body.dark h2, body.dark h3, body.dark .card .value, body.dark .field label,
body.dark .sidebar-title, body.dark .lock-card h2, body.dark .rate-row label { color: #E9A8BF; }
body.dark .sidebar { background: linear-gradient(180deg, #1E1729 0%, #241B33 100%); }
body.dark .sidebar-nav .nav-btn { color: var(--text); }
body.dark .sidebar-nav .nav-btn:hover { background: var(--lav-100); color: #E9D8F5; }
body.dark tbody tr:nth-child(even) td { background: #2A2138; }
body.dark tbody tr:hover td { background: #332847; }
body.dark .field input, body.dark .field select, body.dark .field textarea,
body.dark .variant-row input, body.dark .variant-row select,
body.dark .paste-box textarea, body.dark .search-row input,
body.dark .inline-select, body.dark .rate-row input, body.dark .pr-row input[type="number"] { background: #2A2138; color: var(--text); }
body.dark .paste-box { background: linear-gradient(135deg, #2A2140, #241B33); }
body.dark .paste-note { color: #7ED491; }
body.dark .modal-overlay { background: rgba(10, 6, 18, 0.72); }
body.dark #lockScreen { background: linear-gradient(160deg, #171221 0%, #241B33 45%, #2A1B2E 100%); }
body.dark .setup-banner { background: #3A2F10; border-color: #8A6D1B; color: #F5D67A; }
body.dark .btn.secondary { color: #E9D8F5; }
body.dark .btn.secondary:hover { background: var(--lav-200); }
body.dark .close-btn { color: #E9D8F5; }
body.dark .close-btn:hover { background: var(--lav-200); }
body.dark .bar-track { background: var(--lav-100); }
body.dark .rate-row { background: var(--lav-50); }
body.dark .low-stock { color: #F87171; }
body.dark .stuck-alert { background: #3A1D24; border-color: #7B2D3B; color: #F5B8C4; }
h1, h2, h3, .sidebar-title, .card .value { font-family: "Alexandria", "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif; }
header {
  background: linear-gradient(135deg, #7B1E3B 0%, #9D2C4A 55%, #8E2A4A 100%);
  border-bottom: 3px solid var(--gold);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 4px 18px rgba(123, 30, 59, 0.25);
}
.header-inner { max-width: 1100px; margin: 0 auto; }
header h1 { font-size: 20px; font-weight: 800; color: #fff; }
header .subtitle { color: #E9D5F5; font-size: 13px; }
.header-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
header .btn.secondary { background: rgba(255,255,255,0.16); color: #fff; border: 1px solid rgba(255,255,255,0.35); }
header .btn.secondary:hover { background: rgba(255,255,255,0.28); }

/* شاشة القفل: السيستم كله مخفي لحد ما تدخل كلمة السر */
body.app-locked header, body.app-locked main { display: none; }
#lockScreen { display: none; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #EDE7F8 0%, #DDD2F2 45%, #F3E3EA 100%); }
body.app-locked #lockScreen { display: flex; }
.lock-card { background: var(--card); border: 1px solid var(--lav-200); border-radius: 22px; padding: 32px 26px 28px; max-width: 430px; width: 100%; text-align: center; box-shadow: 0 18px 50px rgba(123, 30, 59, 0.20); position: relative; overflow: hidden; }
.lock-card::before { content: ""; position: absolute; top: 0; right: 0; left: 0; height: 6px; background: linear-gradient(90deg, var(--burg-600), var(--lav-500), var(--gold)); }
.lock-icon { font-size: 44px; margin-bottom: 8px; width: 84px; height: 84px; line-height: 84px; margin-left: auto; margin-right: auto; border-radius: 50%; background: var(--lav-100); border: 1px solid var(--lav-200); }
.lock-card h2 { margin-bottom: 4px; color: var(--burg-700); font-weight: 800; }
.lock-card h2::after { display: none; }
.lock-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.lock-form { display: none; text-align: right; }
.lock-form.show { display: block; }
.lock-form .field { margin-bottom: 12px; }
.lock-form .btn { width: 100%; margin-top: 4px; }
.lock-msg { font-size: 13px; color: var(--red); min-height: 20px; margin-top: 10px; text-align: center; }
.lock-msg.ok { color: var(--green); }
.lock-hint { font-size: 12.5px; color: var(--muted); margin-top: 10px; text-align: center; }
nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.nav-btn {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.nav-btn.active { background: linear-gradient(135deg, var(--burg-600), var(--burg-700)); color: #fff; border-color: var(--burg-700); }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
.tab { display: none; }
.tab.active { display: block; }
h2 { font-size: 19px; margin-bottom: 14px; font-weight: 800; color: var(--burg-700); }
h2::after { content: ""; display: block; width: 58px; height: 4px; border-radius: 999px; background: linear-gradient(90deg, var(--burg-500), var(--lav-400), var(--gold)); margin-top: 6px; }
.toolbar h2::after { display: none; }
h3 { font-size: 15px; margin: 18px 0 10px; font-weight: 700; color: var(--burg-700); }

/* تنبيه الإعداد */
.setup-banner {
  display: none;
  background: #FEF6E0;
  border: 1px solid #E8C87A;
  color: #7A5410;
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  box-shadow: var(--shadow-soft);
}
.setup-banner.show { display: block; }

/* كروت لوحة التحكم */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}
.card .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.card .value { font-size: 28px; font-weight: 800; margin-top: 4px; color: var(--burg-700); }
.card .value small { font-size: 13px; color: var(--muted); font-weight: 400; }

/* جداول */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-soft); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: linear-gradient(135deg, #8E2A4A, #7B1E3B); color: #fff; font-weight: 700; }
tbody tr:nth-child(even) td { background: #FAF7FE; }
tbody tr:hover td { background: #F3EFFA; }
tr:last-child td { border-bottom: none; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* أزرار */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  background: linear-gradient(135deg, var(--burg-500), var(--burg-700));
  color: #fff;
  box-shadow: 0 4px 14px rgba(123, 30, 59, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.btn.secondary { background: var(--lav-100); color: var(--burg-700); box-shadow: none; border: 1px solid var(--lav-200); }
.btn.secondary:hover { background: var(--lav-200); box-shadow: var(--shadow-soft); }
.btn.green { background: linear-gradient(135deg, #1E9E52, #15803D); }
.btn.red { background: linear-gradient(135deg, #E05252, #B91C1C); }
.btn.small { padding: 6px 12px; font-size: 12px; border-radius: 9px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar .spacer { flex: 1; }

/* شارات الحالة */
.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge-new { background: var(--lav-100); color: var(--lav-700); border-color: var(--lav-300); }
.badge-confirmed { background: #FEF6E0; color: #8A6D1B; border-color: #E8C87A; }
.badge-shipped { background: #EDE7F8; color: var(--burg-600); border-color: var(--lav-300); }
.badge-delivered { background: #E3F6EA; color: #166534; border-color: #A7E3C0; }
.badge-returned { background: #FBE9EE; color: var(--burg-700); border-color: #E8B4C4; }
.badge-partial { background: #F6F2FC; color: #6B4FA1; border-color: var(--lav-300); }
.badge-cancelled { background: #FDECEC; color: #991b1b; border-color: #F5C6C6; }
.low-stock { color: var(--red); font-weight: 700; }

/* نماذج */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 13px; color: var(--burg-700); font-weight: 700; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--lav-200);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus, .search-row input:focus {
  outline: none;
  border-color: var(--lav-500);
  box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22);
}
.variant-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: end;
}
.variant-row input, .variant-row select { padding: 9px 10px; border: 1.5px solid var(--lav-200); border-radius: 10px; font-size: 13px; width: 100%; font-family: inherit; background: #fff; color: var(--text); }
.variant-row input:focus, .variant-row select:focus { outline: none; border-color: var(--lav-500); box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22); }
@media (max-width: 700px) {
  .variant-row { grid-template-columns: 1fr 1fr; }
}

/* صفوف المرتجع الجزئي */
.pr-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pr-row .pr-name { flex: 1; font-size: 14px; }
.pr-row .pr-max { font-size: 12px; color: var(--muted); }
.pr-row input[type="number"] { width: 76px; padding: 9px; border: 1.5px solid var(--lav-200); border-radius: 10px; font-size: 14px; text-align: center; font-family: inherit; }
.pr-row input[type="number"]:focus { outline: none; border-color: var(--lav-500); box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22); }

/* سطر المرتجع في الفاتورة */
.rcpt-returned td { color: #991b1b; }
.rcpt-returned td:first-child { text-decoration: line-through; }

/* نوافذ منبثقة */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(46, 33, 64, 0.55);
  z-index: 50;
  overflow-y: auto;
  padding: 20px 10px;
}
.modal-overlay.open { display: block; }
.modal {
  background: var(--card);
  border-radius: 20px;
  border: 1px solid var(--lav-200);
  max-width: 700px;
  margin: 0 auto;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(46, 33, 64, 0.30);
}
.modal.wide { max-width: 850px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 800; color: var(--burg-700); }
.close-btn { background: var(--lav-100); border: none; font-size: 20px; cursor: pointer; color: var(--burg-700); width: 34px; height: 34px; border-radius: 50%; line-height: 1; }
.close-btn:hover { background: var(--lav-200); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }

/* لصق رسالة الأوردر */
.paste-box {
  background: linear-gradient(135deg, #F6F2FC, #EFE7F9);
  border: 1px solid var(--lav-300);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.paste-box label { display: block; font-size: 13px; color: var(--burg-700); margin-bottom: 6px; font-weight: 700; }
.paste-box textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--lav-200);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 8px;
  resize: vertical;
  background: #fff;
}
.paste-box textarea:focus { outline: none; border-color: var(--lav-500); box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22); }
.paste-note { font-size: 13px; color: #166534; margin-top: 8px; }
.match-picker { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.match-picker .match-btn { margin: 0; }
.inline-select { padding: 8px 10px; border: 1.5px solid var(--lav-200); border-radius: 10px; font-family: inherit; font-size: 14px; background: var(--card); color: var(--text); }
.inline-select:focus { outline: none; border-color: var(--lav-500); box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22); }

/* الفاتورة — إيصال مدمج صغير زي الصورة المرجعية (أبيض وأسود، خطوط رفيعة) */
#invoiceSheet, .bulk-invoice {
  background: #fff;
  color: #111;
  border: 1px solid #999;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.35;
  font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, "Geeza Pro", Arial, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
#invoiceSheet table, .bulk-invoice table { min-width: 0; }
.bulk-invoice { margin-bottom: 16px; }

/* خانات تحديد الأوردرات للطباعة الجماعية */
.order-select, #selectAllOrders { width: 18px; height: 18px; cursor: pointer; }
.rcpt { max-width: 520px; margin: 0 auto; }
.inv-ltr { direction: ltr; unicode-bidi: embed; }

/* الصف العلوي: الماركة + QR */
.rcpt-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid #111; }
.rcpt-brand { min-width: 0; }
.rcpt-brand-name { font-size: 16px; font-weight: 700; line-height: 1.2; }
.rcpt-brand-sub { font-size: 10.5px; color: #444; margin-top: 1px; }
.rcpt-qr { width: 56px; height: 56px; flex-shrink: 0; }
.rcpt-qr img, .rcpt-qr canvas { width: 56px !important; height: 56px !important; }

/* رقم المسلسل */
.rcpt-serial { display: flex; align-items: baseline; gap: 8px; padding: 6px 0 4px; }
.rcpt-serial-label { font-size: 12px; color: #444; }
.rcpt-serial-num { font-size: 21px; font-weight: 800; line-height: 1.1; }

/* بيانات العميل */
.rcpt-meta { border-top: 1px solid #999; border-bottom: 1px solid #999; padding: 4px 0; margin-bottom: 7px; }
.rcpt-meta-row { display: flex; gap: 8px; padding: 1px 0; font-size: 11.5px; }
.rcpt-meta-label { width: 58px; flex-shrink: 0; color: #444; }
.rcpt-meta-value { font-weight: 600; }

/* الكاشير / موظف المبيعات / الماركة */
.rcpt-trio { display: grid; grid-template-columns: 1fr 1fr 1fr; border: 1px solid #999; margin-bottom: 8px; }
.rcpt-trio-cell { padding: 4px 6px; text-align: center; }
.rcpt-trio-cell + .rcpt-trio-cell { border-right: 1px solid #999; }
.rcpt-trio-label { font-size: 10px; color: #444; }
.rcpt-trio-value { font-size: 12px; font-weight: 700; }

/* جدول الأصناف */
.rcpt-items { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.rcpt-items th { font-size: 11px; padding: 4px 6px; border-top: 1px solid #111; border-bottom: 1px solid #111; background: #f2f2f2; }
.rcpt-items td { padding: 4px 6px; font-size: 11.5px; border-bottom: 1px solid #ccc; }
.rcpt-items th:nth-child(n+2), .rcpt-items td:nth-child(n+2) { text-align: center; }

/* الحساب */
.rcpt-totals { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.rcpt-totals td { padding: 3px 6px; font-size: 11.5px; border-bottom: 1px dotted #bbb; }
.rcpt-totals td:nth-child(odd) { color: #444; }
.rcpt-totals td:nth-child(even) { font-weight: 700; text-align: center; }

/* المبلغ الكلي مع التوصيل */
.rcpt-grand { display: flex; justify-content: space-between; align-items: center; border: 2px solid #111; padding: 6px 10px; font-size: 13px; font-weight: 800; margin-bottom: 8px; }
.rcpt-grand-value { font-size: 16px; }
.rcpt-notes { border: 1px solid #999; padding: 5px 8px; font-size: 11.5px; margin-bottom: 8px; }
.rcpt-notes-label { font-weight: 800; color: #444; margin-left: 4px; }

/* ملاحظة آخر الفاتورة + الباركود */
.rcpt-footer { text-align: center; font-size: 10.5px; color: #444; margin-bottom: 6px; }
.rcpt-barcode { text-align: center; padding-top: 2px; }
.rcpt-barcode svg { max-width: 100%; }
.rcpt-barcode-text { font-size: 13px; font-weight: 700; letter-spacing: 1px; }

/* القائمة الجانبية — على اليمين (RTL) */
.sidebar {
  background: linear-gradient(180deg, #F8F5FD 0%, #EFE8FA 100%);
  border-left: 1px solid var(--lav-200);
  padding: 18px 12px;
  z-index: 40;
}
.sidebar-title { font-size: 16px; font-weight: 800; color: var(--burg-700); padding: 4px 10px 14px; border-bottom: 1px solid var(--lav-200); margin-bottom: 12px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 5px; }
.sidebar-nav .nav-btn {
  border: none;
  background: transparent;
  padding: 11px 13px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  text-align: right;
  width: 100%;
  color: var(--text);
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-nav .nav-btn:hover { background: var(--lav-100); color: var(--burg-700); }
.sidebar-nav .nav-btn.active { background: linear-gradient(135deg, var(--burg-600), var(--burg-700)); color: #fff; box-shadow: 0 4px 14px rgba(123, 30, 59, 0.30); }
.sidebar-foot { margin-top: 16px; padding: 12px 10px 0; border-top: 1px solid var(--lav-200); font-size: 12px; color: var(--muted); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(46, 33, 64, 0.45); z-index: 35; }
.sidebar-overlay.show { display: block; }
.menu-btn { font-size: 18px; padding: 5px 12px; }

/* الكمبيوتر: القائمة ظاهرة على طول والمحتوى بيتزاح على الشمال */
@media (min-width: 901px) {
  .sidebar { position: fixed; top: 0; right: 0; bottom: 0; width: 230px; overflow-y: auto; }
  header, main { margin-right: 230px; }
  main { margin-left: auto; }
  .menu-btn { display: none; }
  .sidebar-overlay { display: none !important; }
}

/* الموبايل: القائمة درج منزلق من اليمين، بيتفتح من زرار ☰ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; width: 260px;
    transform: translateX(105%);
    transition: transform 0.25s ease;
    box-shadow: -4px 0 24px rgba(46, 33, 64, 0.25);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
}

/* القائمة الجانبية مخفية خالص لما السيستم مقفول */
body.app-locked .sidebar, body.app-locked .sidebar-overlay { display: none; }

/* تقسيم الأوردرات حسب الحالة: زرار لكل حالة فيه العدد والنسبة المئوية */
.status-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 999px; background: var(--card); cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text); }
.status-chip b { font-size: 14px; }
.status-chip .status-pct { color: var(--muted); font-size: 12px; font-weight: 600; }
.status-chip.active { background: var(--burg-600); border-color: var(--burg-600); color: #fff; }
.status-chip.active .status-pct { color: #F3E8EE; }

/* تنبيه الأوردرات المتأخرة — أوردرات «جديد» بقالها أكتر من يومين */
.stuck-alert { background: #FDECEC; border: 1px solid #F5C6C6; color: #991b1b; border-radius: var(--radius); padding: 14px; margin-bottom: 16px; box-shadow: var(--shadow-soft); }
.stuck-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; font-size: 14px; border-top: 1px dashed #F5C6C6; margin-top: 6px; }

/* بحث الأوردرات */
.search-row { margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.search-row input {
  flex: 1;
  min-width: 200px;
  padding: 11px 14px;
  border: 1.5px solid var(--lav-200);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  box-shadow: var(--shadow-soft);
}

/* تلميح الشحن التلقائي تحت خانة الشحن */
.shipping-hint { font-size: 12.5px; color: var(--lav-700); font-weight: 500; margin-top: 5px; min-height: 0; }
.shipping-hint:empty { display: none; }

/* شبكة أسعار الشحن في الإعدادات */
.rates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.rate-row { display: flex; align-items: center; gap: 8px; background: var(--lav-50); border: 1px solid var(--lav-200); border-radius: 12px; padding: 8px 12px; }
.rate-row label { flex: 1; font-size: 13px; font-weight: 700; color: var(--burg-700); }
.rate-row input { width: 92px; padding: 8px 10px; border: 1.5px solid var(--lav-200); border-radius: 10px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); text-align: center; }
.rate-row input:focus { outline: none; border-color: var(--lav-500); box-shadow: 0 0 0 3px rgba(139, 108, 198, 0.22); }

/* أعمدة التقارير (CSS بس من غير مكتبات) */
.bar-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.bar-label { width: 64px; flex-shrink: 0; color: var(--muted); }
.bar-track { flex: 1; background: var(--lav-100); border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--burg-500), var(--lav-500)); border-radius: 999px; min-width: 0; }
.bar-value { width: 110px; flex-shrink: 0; text-align: left; font-weight: 700; white-space: nowrap; }

/* شيت المندوب — ورقة بيضاء نظيفة للطباعة */
.courier-sheet { background: #fff; color: #111; border: 1px solid #bbb; border-radius: 10px; padding: 16px; margin-bottom: 16px; direction: rtl; }
.courier-sheet .sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 2px solid #111; padding-bottom: 8px; margin-bottom: 10px; }
.courier-sheet .sheet-title { font-size: 20px; font-weight: 800; }
.courier-sheet .sheet-meta { display: flex; flex-wrap: wrap; gap: 8px 24px; font-size: 14px; margin-bottom: 12px; }
.courier-sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.courier-sheet th, .courier-sheet td { border: 1px solid #999; padding: 6px 8px; text-align: right; vertical-align: top; }
.courier-sheet thead th { background: #f0f0f0; }
.courier-sheet .sheet-check { text-align: center; font-size: 18px; }
/* إجمالي الشيت: سطر عادي تحت الجدول (مش tfoot) — عشان يطبع مرة واحدة
   في آخر الشيت بس، مش تحت كل صفحة لما الجدول يتقسم على صفحات */
.courier-sheet .sheet-total { margin-top: 10px; padding-top: 8px; border-top: 2px solid #111; font-size: 15px; font-weight: 700; text-align: left; }
.courier-sheet .sheet-sign { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; margin-top: 18px; font-size: 14px; }

/* الطباعة: اطبع الفاتورة بس (مع الإطار) — وفي الطباعة الجماعية اطبع الفواتير كلها */
@media print {
  .sidebar, .sidebar-overlay, .menu-btn { display: none !important; }
  header, main { margin-right: 0 !important; }
  body * { visibility: hidden; }
  #invoiceSheet, #invoiceSheet * { visibility: visible; }
  body.bulk-printing #invoiceSheet, body.bulk-printing #invoiceSheet * { visibility: hidden; }
  body.bulk-printing #bulkInvoiceSheet, body.bulk-printing #bulkInvoiceSheet * { visibility: visible; }
  body.sheet-printing #invoiceSheet, body.sheet-printing #invoiceSheet * { visibility: hidden; }
  body.sheet-printing #courierSheetContent, body.sheet-printing #courierSheetContent * { visibility: visible; }
  body.prep-printing #invoiceSheet, body.prep-printing #invoiceSheet * { visibility: hidden; }
  body.prep-printing #prepSummaryContent, body.prep-printing #prepSummaryContent * { visibility: visible; }
  body.label-printing #invoiceSheet, body.label-printing #invoiceSheet * { visibility: hidden; }
  body.label-printing #deliveryLabelContent, body.label-printing #deliveryLabelContent * { visibility: visible; }
  #invoiceSheet, #bulkInvoiceSheet, #courierSheetContent, #prepSummaryContent, #deliveryLabelContent {
    position: absolute;
    top: 0; right: 0; left: 0;
  }
  /* الليبل ميتقسمش على صفحتين */
  .delivery-label { page-break-inside: avoid; break-inside: avoid; }
  .modal-overlay { position: static; background: none; padding: 0; overflow: visible; }
  .modal { padding: 0; max-width: none; }
  /* كل فاتورة في صفحة لوحدها في الطباعة الجماعية */
  .bulk-invoice { page-break-after: always; break-after: page; margin-bottom: 0; }
  .bulk-invoice:last-child { page-break-after: auto; break-after: auto; }
  /* كل شيت مندوب في صفحة لوحده */
  .courier-sheet { page-break-after: always; break-after: page; margin-bottom: 0; border: none; }
  .courier-sheet:last-child { page-break-after: auto; break-after: auto; }
  /* طباعة مضغوطة للشيتات (شيت المندوب + ملخص التجهيز): خط أصغر ومسافات
     أقل عشان نفس المحتوى ياخد صفحات أقل — من غير ما يتغير شكل الفاتورة */
  .courier-sheet { padding: 8px; }
  .courier-sheet .sheet-head { padding-bottom: 4px; margin-bottom: 6px; }
  .courier-sheet .sheet-title { font-size: 15px; }
  .courier-sheet .sheet-meta { font-size: 11px; margin-bottom: 6px; gap: 6px 16px; }
  .courier-sheet table { font-size: 10px; line-height: 1.3; }
  .courier-sheet th, .courier-sheet td { padding: 2px 4px; }
  .courier-sheet thead th { font-size: 10px; }
  .courier-sheet tfoot td { font-size: 12px; }
  .courier-sheet .sheet-check { font-size: 13px; }
  .courier-sheet .sheet-sign { font-size: 11px; margin-top: 8px; gap: 6px 16px; }
  .courier-sheet .sheet-total { font-size: 12px; margin-top: 6px; padding-top: 4px; }
  @page { size: A4; margin: 10mm; }
}

/* ليبل التوصيل — ورقة صغيرة تتلزق على الكيس (بيضاء على طول حتى في الوضع الليلي) */
.delivery-labels { display: flex; flex-wrap: wrap; gap: 12px; }
.delivery-label { width: calc(50% - 6px); background: #fff; color: #111; border: 2px solid #111; border-radius: 10px; padding: 12px; direction: rtl; }
.delivery-label .label-head { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid #111; padding-bottom: 6px; margin-bottom: 8px; font-size: 13px; }
.delivery-label .label-num { font-size: 18px; font-weight: 800; }
.delivery-label .label-name { font-size: 17px; font-weight: 800; }
.delivery-label .label-phone { font-size: 16px; font-weight: 700; }
.delivery-label .label-addr { font-size: 13px; margin: 4px 0; }
.delivery-label .label-items { font-size: 13px; border-top: 1px dashed #999; border-bottom: 1px dashed #999; padding: 6px 0; margin: 6px 0; }
.delivery-label .label-total { font-size: 14px; margin-bottom: 6px; }
.delivery-label .label-barcode { text-align: center; }
.delivery-label .label-barcode svg { max-width: 100%; }
@media (max-width: 700px) { .delivery-label { width: 100%; } }

/* نص الملخصات القابلة للنسخ (ملخص تغيير الحالة + ملخص اليوم) — سطور عادية بخط واضح */
.summary-text { white-space: pre-wrap; font-family: inherit; font-size: 15px; line-height: 1.9; margin: 0; }

/* رقم الموبايل لينك اتصال — تدوس عليه يفتح الاتصال على طول */
.phone-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
