/* ================================================================
   قالب فاتورة نور الصباح — مطابق للتصميم المعتمد
   الطباعة على ورق A5. الألوان أبيض وأسود عشان تطلع زي الأصل بالظبط.
   ================================================================ */

.inv-paper {
  direction: rtl;
  font-family: "Calibri", "Segoe UI", Tahoma, sans-serif;
  color: #000;
  background: #fff;
  width: 100%;
  font-size: 8.2pt;
  line-height: 1.28;
  font-weight: 700;        /* الفاتورة كلها بولد */
}

.inv-paper * { box-sizing: border-box; }

/* ---------------------------------------------------- الرأس
   اللوجو على الشمال، والعناوين على اليمين، و«فاتورة:...» في نص الورقة
   والتاريخ تحت اللوجو على نفس السطر — بالظبط زي الأصل. */
.inv-top { position: relative; }

/* table-layout: fixed عشان تقسيم 32/68 يتحترم مهما كبر الشعار —
   من غيره المتصفح بيوسّع خانة الشعار على مقاس الصورة ويزحّق الجدول بره الورقة */
.inv-head { width: 100%; border-collapse: collapse; table-layout: fixed; }
.inv-head td { vertical-align: top; padding: 0; }

.inv-titles { width: 68%; }

.inv-logo-cell { width: 32%; text-align: center; vertical-align: top; }
/* الشعار أكبر 50% — كان 56%. النسبة من عرض الخانة، والحد الأقصى 100%
   عشان مهما كبّرناه ميخرجش من خانته. */
.inv-logo-cell img { width: 84%; max-width: 100%; height: auto; display: inline-block; }

.inv-date {
  position: absolute;
  left: 0;              /* فيزيائي عن قصد — لازم تحت اللوجو على الشمال */
  bottom: 0;
  width: 32%;
  font-weight: 700;
  font-size: 10pt;
  text-align: center;
  line-height: 1.3;
}

/* اسم الشركة عربي وإنجليزي — 16 */
.inv-title-ar { font-weight: 700; font-size: 16pt; text-align: center; line-height: 1.15; }
.inv-title-en { font-weight: 700; font-size: 16pt; text-align: center; line-height: 1.15; }

.inv-rule { border-top: 2.2px solid #000; margin: 2px 0; }

/* بيانات الشركة: العنوان والسجل التجاري والرقم الضريبي والتليفون — 10 */
.inv-org { font-weight: 700; font-size: 10pt; text-align: center; line-height: 1.42; }

/* «فاتورة:مبيعات» متوسّطة على عرض الورقة كلها زي الأصل */
.inv-kind { font-weight: 700; font-size: 10pt; text-align: center; padding-top: 3px; }

/* صف رقم الفاتورة ونوعها */
.inv-meta { width: 100%; border-collapse: collapse; margin-top: 2px; }
.inv-meta td { font-weight: 700; font-size: 10pt; padding: 1px 2px; }
.inv-meta .r { text-align: right; }
.inv-meta .l { text-align: left; }

.inv-customer { font-weight: 700; font-size: 10pt; text-align: center; padding: 3px 0 1px; }

.inv-contact { width: 100%; border-collapse: collapse; margin-bottom: 3px; }
.inv-contact td { font-weight: 700; font-size: 10pt; padding: 1px 2px; }
.inv-contact .r { text-align: right; }
.inv-contact .l { text-align: left; }

/* ---------------------------------------------------- جدول الأصناف */
.inv-items {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

/* خطوط أفقية بين الصفوف، وضلعين رأسيين على طرفي الجدول بس —
   مفيش خطوط بين الأعمدة. */
.inv-items th,
.inv-items td {
  border: 0;
  border-bottom: 1.4px solid #000;
  padding: 2.5px 3px;
  text-align: center;
  font-size: 12pt;
  font-weight: 700;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.inv-items thead tr th { border-top: 1.4px solid #000; }

/* قفل الطرفين: أول خانة في كل صف (اليمين في RTL) وآخر خانة (الشمال).
   بنستعمل الخانات مش حدود الجدول عشان تمتد بطول الصفوف كلها. */
.inv-items tr > :first-child { border-right: 1.4px solid #000; }
.inv-items tr > :last-child  { border-left:  1.4px solid #000; }

.inv-items thead th { font-size: 12pt; }
.inv-items td.name { text-align: center; }
.inv-items td.num { font-family: "Calibri", sans-serif; }
.inv-items .c-sn    { width: 5%; }
.inv-items .c-name  { width: 37%; }
.inv-items .c-unit  { width: 14%; }
.inv-items .c-qty   { width: 14%; }
.inv-items .c-price { width: 14%; }
.inv-items .c-total { width: 16%; }

.inv-items tr.count-row td { text-align: center; }
.inv-items tr.count-row td.lbl { text-align: center; }

/* ---------------------------------------------------- الإجماليات */
.inv-tot {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 9px;
}

/* (2026-11-19) باركود الفاتورة (barcode.js) — تحت الإجماليات على الشمال */
/* (2026-11-19) باركود الصنف تحت اسمه — صغير وبالأرقام اللي على العبوة */
.inv-paper .ln-bc { font-size: 7.5pt; font-weight: 400; line-height: 1.15; letter-spacing: .3px; font-family: Consolas, 'Courier New', monospace; }
.inv-bc { text-align: left; margin-top: 2mm; page-break-inside: avoid; }

.inv-tot td {
  border: 0;
  border-bottom: 1.4px solid #000;
  padding: 3px 5px;
  font-size: 10pt;
  vertical-align: middle;
}

.inv-tot tr:first-child td { border-top: 1.4px solid #000; }

/* قفل الطرفين زي جدول الأصناف — من غير خطوط بين الأعمدة */
.inv-tot tr > :first-child { border-right: 1.4px solid #000; }
.inv-tot tr > :last-child  { border-left:  1.4px solid #000; }

/* العروض متقاسة من الفاتورة المعتمدة */
.inv-tot .lbl-r  { width: 44.5%; text-align: center; font-weight: 700; }
.inv-tot .val-r  { width: 13%;   text-align: center; font-weight: 700; }
.inv-tot .lbl-l  { width: 28%;   text-align: center; font-weight: 700; }
.inv-tot .val-l  { width: 14.5%; text-align: center; font-weight: 700; }

/* مفيش خطوط بالطول خالص */

.inv-tot .grey { background: #d9d9d9; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.inv-tot .wide { text-align: center; font-weight: 700; }
.inv-tot .note { text-align: center; font-weight: 700; }
.inv-tot .clerk { text-align: center; font-weight: 700; }

/* ================================================================
   أمر صرف — ورق حراري 80 مم (مطابق للنموذج المعتمد)
   ================================================================ */
.tw-paper {
  width: 72mm;
  direction: rtl;
  font-family: Arial, "Tahoma", sans-serif;
  font-weight: 700;
  color: #000;
  background: #fff;
  font-size: 11pt;
  line-height: 1.4;
}

.tw-title {
  font-size: 17pt;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
}

/* صفوف الرأس: تسمية يمين وقيمة في النص وخط تحت كل صف (و«ملاحظات» من غير خط) */
.tw-kv {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 0;
  border-bottom: 1px solid #000;
  font-size: 11pt;
}
.tw-kv.note { border-bottom: 0; }

.tw-kv .k { white-space: nowrap; }
.tw-kv .v { flex: 1; text-align: center; }
.tw-kv .m { margin-inline-start: auto; white-space: nowrap; }
.tw-kv .e { white-space: nowrap; direction: ltr; }

.tw-tbl {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
  table-layout: fixed;
  border: 1px solid #000;           /* الجدول في إطار — من غير خطوط بين الأعمدة (زي النموذج) */
}

.tw-tbl th,
.tw-tbl td {
  border: 0;
  border-bottom: 1px solid #000;
  padding: 9px 4px;
  text-align: center;
  font-size: 11pt;
  font-weight: 700;
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.tw-tbl td.nm { text-align: right; padding-inline-start: 6px; }   /* اسم الصنف لازق يمين */

.tw-tbl .nm, .tw-tbl th:nth-child(1) { width: 55%; }
.tw-tbl .un, .tw-tbl th:nth-child(2) { width: 25%; }
.tw-tbl .qt, .tw-tbl th:nth-child(3) { width: 20%; }

.tw-foot { margin-top: 6px; text-align: center; font-size: 10.5pt; }

/* ---------------------------------------------------- الطباعة */
@media print {
  /* هامش الصفحة صفر عن قصد.
     كروم بيلغي `@page margin` حسب إعداد الهوامش المحفوظ عنده، وهو بيرجّع
     الإعداد ده لقيمته القديمة كل ما البرنامج يقفل — فمينفعش نعتمد عليه.
     الهامش الحقيقي بقى `padding` على الورقة نفسها تحت، وده كروم مايقدرش
     يلغيه لأنه تخطيط عادي مش إعداد طباعة. */
  @page { size: A5 portrait; margin: 0; }

  html, body {
    background: #fff !important;
    overflow: visible !important;
    height: auto !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* بنشيل كل حاجة غير النوافذ المنبثقة بـ display مش visibility.
     visibility بتخفي العنصر بس بيفضل واخد مساحته، فكان لازم نسحب الفاتورة
     بـ position:absolute فوق الكلام المخفي — وده هو أصل المشكلة كلها. */
  body > *:not(#modals) { display: none !important; }
  #modals > *:not(:last-child) { display: none !important; }

  /* أي خاصية transform أو filter على أب بتخليه هو المرجع اللي العناصر
     المطلقة بتتحسب عليه بدل الصفحة — و`.modal` فيها animation فيها
     transform. فالفاتورة كانت بتتحسب على عرض النافذة مش عرض الورقة،
     فبتتقص لما النافذة تبقى أعرض. بنلغي ده كله. */
  #modals, .modal-bg, .modal, .modal > .body, .modal > .body > * {
    position: static !important;
    transform: none !important;
    animation: none !important;
    filter: none !important;
    backdrop-filter: none !important;
    display: block !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    background: #fff !important;
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    inset: auto !important;
  }

  .modal > header, .modal > footer { display: none !important; }

  /* الفاتورة بقت عنصر عادي في الصفحة: عرضها = عرض الورقة مهما كان،
     ومش متعلقة بأي حاجة تانية. */
  .inv-paper, .tw-paper {
    position: static !important;
    width: auto !important;
    margin: 0 !important;
    box-sizing: border-box;
  }

  /* 8 ملي على الجنبين: الطابعة نفسها مش بتطبع آخر ~4 ملي من حرف الورقة،
     والباقي هامش شكلي. من غيرهم الكلام بيتقص من على الحرف. */
  .inv-paper { padding: 6mm 8mm !important; }
  .tw-paper  { padding: 2mm 3mm !important; }   /* الحراري هامشه أضيق */

  .inv-items tr, .inv-tot tr { page-break-inside: avoid; }
  .inv-tot { page-break-inside: avoid; }
}

/* حجم A4 لو المستخدم غيّره من الإعدادات */
@media print {
  .paper-a4 .inv-paper { font-size: 10pt; }
}
