/* قالب پیش‌فاکتور AFV؛ هم‌خوان با ساختار رسمی پیش‌فاکتور مرجع دیجی‌قطعه */
.invoice-preview {
  padding: 28px;
  background: #f2f5f7;
}

/* رسید تحویل چک: تعداد ردیف و مدیریت پیوست در فرم + خوانایی تصویر در خروجی */
.check-receipt-empty-hint {
  margin: 8px 0 0;
  padding: 9px 11px;
  color: #70818d;
  border: 1px dashed #c9d8e2;
  border-radius: 7px;
  background: #fbfdfe;
  font-size: 9px;
  text-align: center;
}
.check-receipt-empty-hint[hidden] { display: none !important; }
.check-receipt-existing-image-row {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  max-width: 100% !important;
}
.check-receipt-existing-image-row .check-receipt-existing-image {
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
.check-receipt-remove-image {
  width: 24px !important;
  height: 24px !important;
  flex: 0 0 24px !important;
  padding: 0 !important;
  color: #b44545 !important;
  border: 1px solid #e8bfc1 !important;
  border-radius: 6px !important;
  background: #fff7f7 !important;
  cursor: pointer !important;
}
.check-receipt-image-remove-help {
  display: block !important;
  margin-top: 6px !important;
  color: #8998a2 !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  align-items: start !important;
  gap: 10mm !important;
  margin-top: 7mm !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature,
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-stamp {
  min-width: 0 !important;
  text-align: center !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature > small,
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature > strong,
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature > span,
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-stamp > small {
  display: block !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature > strong {
  margin-top: 7mm !important;
  line-height: 1.8 !important;
  white-space: nowrap !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-approval-signature > span {
  margin-top: 2mm !important;
  line-height: 1.7 !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 4mm !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-card {
  height: 52mm !important;
  padding: 2mm !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-card img {
  height: 45mm !important;
}
/* تصاویر چک داخل بدنهٔ رسید می‌مانند؛ هیچ تصویری نباید به فوتر یا صفحهٔ بعد رانده شود. */
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-images {
  width: 100% !important;
  max-width: 100% !important;
  margin: 4mm 0 0 !important;
  box-sizing: border-box !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}
html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-grid {
  max-width: 100% !important;
  overflow: hidden !important;
}
@media print {
  body.printing-check-receipt #modal-root .check-receipt-print-wrap {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-v3-content {
    overflow: hidden !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-v3-images {
    break-before: auto !important;
    break-after: avoid-page !important;
    page-break-before: auto !important;
    page-break-after: avoid !important;
  }
}
@media (max-width: 700px) {
  html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-grid {
    grid-template-columns: 1fr !important;
  }
  html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-card {
    height: 65mm !important;
  }
  html body #modal-root .check-receipt-print-wrap .check-receipt-v3 .check-receipt-v3-image-card img {
    height: 57mm !important;
  }
}

/* پیوست مستقل برای همهٔ اسناد: اصل فایل، آخرین صفحهٔ A4 و بدون پوستهٔ CRM */
html body #modal-root .document-attachment-page {
  box-sizing: border-box !important;
  position: relative !important;
  display: block !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto 10mm !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #fff !important;
  background-image: none !important;
  box-shadow: 0 8px 25px #1b293722 !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

html body #modal-root .document-attachment-page > .letter-attachment-page-body {
  position: absolute !important;
  inset: 13mm !important;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
  background: #fff !important;
}

html body #modal-root .document-attachment-page .letter-attachment-content-frame {
  box-sizing: border-box !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #fff !important;
}

html body #modal-root .document-attachment-page .letter-attachment-visual,
html body #modal-root .document-attachment-page .letter-attachment-embed,
html body #modal-root .document-attachment-page .letter-attachment-pdf-canvas {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  border: 0 !important;
  object-fit: contain !important;
}

html body #modal-root .document-attachment-page > .quality-official-header,
html body #modal-root .document-attachment-page > .quality-paper-head,
html body #modal-root .document-attachment-page > .quality-paper-footer,
html body #modal-root .document-attachment-page > .invoice-native-letterhead,
html body #modal-root .document-attachment-page > .technical-paper-head,
html body #modal-root .document-attachment-page > .technical-paper-footer,
html body #modal-root .document-attachment-page .document-attachment-status {
  display: none !important;
}

@media print {
  body.printing-invoice #modal-root .document-attachment-page,
  body.printing-receipt #modal-root .document-attachment-page,
  body.printing-check-receipt #modal-root .document-attachment-page,
  body.printing-quality #modal-root .document-attachment-page,
  body.printing-technical-report #modal-root .document-attachment-page,
  body.printing-letter #modal-root .document-attachment-page {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    page: afv-document-a4-portrait-final !important;
    break-before: auto !important;
    break-after: page !important;
    page-break-before: auto !important;
    page-break-after: always !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .document-attachment-page:last-child,
  body.printing-receipt #modal-root .document-attachment-page:last-child,
  body.printing-check-receipt #modal-root .document-attachment-page:last-child,
  body.printing-quality #modal-root .document-attachment-page:last-child,
  body.printing-technical-report #modal-root .document-attachment-page:last-child,
  body.printing-letter #modal-root .document-attachment-page:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

/* QA-07: پیش‌نمایش و چاپ باید یک مدل صفحه‌بندی داشته باشند. رسید تحویل
   در هر برگه فضای جدول را تا قبل از فوتر مصرف می‌کند و گزارش فنی نیز هر
   سکشن را در همان A4 می‌چیند؛ پیوست‌ها از این چیدمان جدا می‌مانند. */
#modal-root .receipt-preview-wrap > .receipt-paper.receipt-redesigned:not(.document-attachment-page) {
  display: block !important;
  position: relative !important;
  box-sizing: border-box !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  overflow: hidden !important;
}
#modal-root .receipt-preview-wrap > .receipt-paper.receipt-redesigned:not(.document-attachment-page) > .receipt-redesigned-content {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  padding: 34mm 0 31mm !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}
#modal-root .receipt-redesigned .receipt-redesign-head,
#modal-root .receipt-redesigned .receipt-redesign-total,
#modal-root .receipt-redesigned .receipt-redesign-note,
#modal-root .receipt-redesigned .receipt-redesign-confirmation,
#modal-root .receipt-redesigned .receipt-redesigned-signatures,
#modal-root .receipt-redesigned .receipt-redesign-signatures {
  flex: 0 0 auto !important;
}
#modal-root .receipt-redesigned .receipt-redesign-items-section {
  display: flex !important;
  flex: 1 1 auto !important;
  flex-direction: column !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
#modal-root .receipt-redesigned .receipt-redesign-items-section .receipt-redesign-section-title {
  flex: 0 0 auto !important;
}
#modal-root .receipt-redesigned .receipt-redesign-items-section .receipt-redesign-items {
  display: table !important;
  flex: 1 1 auto !important;
  height: 100% !important;
  min-height: 0 !important;
  margin-bottom: 0 !important;
}

#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  position: relative !important;
  box-sizing: border-box !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto !important;
  padding: 0 24mm 8mm 14mm !important;
  overflow: hidden !important;
  background: #fff !important;
}
#modal-root .technical-preview-wrap > .technical-paper.has-letterhead:not(.document-attachment-page) > .official-letterhead-image,
#modal-root .technical-preview-wrap > .technical-paper.has-letterhead:not(.document-attachment-page) > .technical-official-letterhead,
#modal-root .technical-preview-wrap > .technical-paper.has-letterhead:not(.document-attachment-page) > .invoice-native-letterhead {
  position: absolute !important;
  inset: 0 !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: fill !important;
  z-index: 1 !important;
  visibility: visible !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > :not(.official-letterhead-image):not(.technical-official-letterhead):not(.invoice-native-letterhead) {
  position: relative !important;
  z-index: 2 !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .technical-paper-head {
  flex: 0 0 34mm !important;
  min-height: 34mm !important;
  margin: 0 !important;
  padding: 0 0 5mm !important;
  border-bottom: 0 !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .technical-paper-footer {
  position: static !important;
  order: 99 !important;
  flex: 0 0 7mm !important;
  width: auto !important;
  min-height: 7mm !important;
  margin: auto -11mm 0 -1mm !important;
  padding: 2mm 0 0 !important;
  box-sizing: border-box !important;
  border-top: .35mm solid #f15a24 !important;
  background: #fff !important;
  z-index: 3 !important;
}

@media print {
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .receipt-redesigned-content {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 !important;
    overflow: hidden !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page .receipt-redesign-items-section {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page .receipt-redesign-items-section .receipt-redesign-items {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
    margin-bottom: 0 !important;
  }
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page:not(.document-attachment-page) {
    display: flex !important;
    flex-direction: column !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 24mm 8mm 14mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page:not(.document-attachment-page) > .technical-paper-footer {
    position: static !important;
    order: 99 !important;
    flex: 0 0 7mm !important;
    margin: auto -11mm 0 -1mm !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .document-attachment-print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .document-attachment-print-page,
  body.printing-quality #modal-root .quality-preview-wrap > .document-attachment-print-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .document-attachment-print-page,
  body.printing-letter #modal-root .letter-preview-wrap > .document-attachment-print-page {
    display: block !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    break-before: page !important;
    page-break-before: always !important;
    break-after: page !important;
    page-break-after: always !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .document-attachment-print-page.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .document-attachment-print-page.print-page-last,
  body.printing-quality #modal-root .quality-preview-wrap > .document-attachment-print-page.print-page-last,
  body.printing-technical-report #modal-root .technical-preview-wrap > .document-attachment-print-page.print-page-last,
  body.printing-letter #modal-root .letter-preview-wrap > .document-attachment-print-page.print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

/* وضعیت پیوست داخل سند اصلی نمایش داده می‌شود؛ اصل فایل در صفحهٔ مستقل انتهایی می‌آید. */
.document-attachment-note {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid #dce7e8;
  border-radius: 10px;
  background: #f8fbfb;
  color: #516d73;
  font-size: 11px;
  line-height: 1.9;
}
.document-attachment-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin: 10px 0;
  padding: 5px 12px;
  border: 1px solid #d5e8df;
  border-radius: 999px;
  background: #f2fbf6;
  color: #1a7650;
  font-size: 11px;
  font-weight: 700;
}
@media print {
  .document-attachment-status {
    margin: 5mm 0 3mm;
    padding: 1.5mm 4mm;
    border-color: #cfded7 !important;
    background: #f7fbf8 !important;
    color: #315e4a !important;
    font-size: 9pt;
  }
}

/* نامهٔ وارده: فقط فایل اصلی و کدینگ داخلی؛ بدون سربرگ، فوتر و اطلاعات سازمانی AFV. */
.letter-preview-wrap.letter-incoming-original-only {
  background: #eef2f4 !important;
}
.letter-preview-wrap .letter-incoming-original-page {
  position: relative !important;
  box-sizing: border-box !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto 10mm !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: #fff !important;
  background-image: none !important;
  border: 0 !important;
  box-shadow: 0 2mm 8mm rgba(24, 37, 48, .12) !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-incoming-coding {
  position: absolute !important;
  z-index: 3 !important;
  top: 9mm !important;
  right: 13mm !important;
  left: 13mm !important;
  height: 8mm !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 6mm !important;
  box-sizing: border-box !important;
  padding: 1.5mm 3mm !important;
  border-bottom: .35mm solid #b8c3c9 !important;
  color: #41515a !important;
  background: #fff !important;
  direction: rtl !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 9pt !important;
  line-height: 1.2 !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-incoming-coding strong {
  color: #26333b !important;
  font-weight: 700 !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-incoming-coding span {
  color: #a84e2b !important;
  font-weight: 700 !important;
  direction: ltr !important;
  unicode-bidi: plaintext !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-attachment-page-body {
  top: 23mm !important;
  right: 13mm !important;
  bottom: 13mm !important;
  left: 13mm !important;
  z-index: 1 !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-attachment-content-frame {
  border: 0 !important;
  border-radius: 0 !important;
}
.letter-preview-wrap .letter-incoming-original-page .letter-incoming-missing-file {
  width: 100% !important;
  margin: auto !important;
  padding: 12mm !important;
  border: 1px dashed #c8d1d6 !important;
  color: #788891 !important;
  text-align: center !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 11pt !important;
}
@media print {
  body.printing-letter #modal-root .letter-preview-wrap.letter-incoming-original-only,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap.letter-incoming-original-only {
    background: #fff !important;
  }
  body.printing-letter #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-original-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-original-page {
    margin: 0 !important;
    box-shadow: none !important;
  }
}

/* قفل نهایی سازگار با Firefox: هر صفحهٔ صفحه‌بندی‌شده یک برگهٔ مستقل است.
   این بلوک عمداً در انتهای فایل قرار دارد تا قواعد قدیمی flex/fragment روی
   صفحات میانی اثر نگذارند و هدر/فوتر به صفحهٔ بعد منتقل نشوند. */
@media print {
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page {
    display: block !important;
    position: relative !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-before: auto !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page:not(.print-page-last),
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page:not(.print-page-last) {
    page-break-after: always !important;
    break-after: page !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page-last {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .receipt-redesigned-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    max-width: 30mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 21 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo img,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    object-fit: contain !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 20 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding: 2mm 0 0 !important;
    display: grid !important;
    visibility: visible !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }
}

/* QA-07 final precedence: these rules intentionally come after the legacy
   print locks so the screen preview and browser print use the same geometry. */
#modal-root .receipt-preview-wrap > .receipt-paper.receipt-redesigned:not(.document-attachment-page) > .receipt-redesigned-content {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  padding: 34mm 0 31mm !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}
#modal-root .receipt-redesigned .receipt-redesign-items-section {
  display: flex !important;
  flex: 1 1 auto !important;
  flex-direction: column !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
#modal-root .receipt-redesigned .receipt-redesign-items-section .receipt-redesign-items {
  display: table !important;
  flex: 1 1 auto !important;
  height: 100% !important;
  min-height: 0 !important;
  margin-bottom: 0 !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) {
  display: flex !important;
  flex-direction: column !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 0 24mm 8mm 14mm !important;
  margin: 0 auto !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .official-letterhead-image,
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .technical-official-letterhead {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: fill !important;
  z-index: 1 !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .technical-paper-head {
  flex: 0 0 34mm !important;
  min-height: 34mm !important;
  margin: 0 !important;
  padding: 0 0 5mm !important;
  border-bottom: 0 !important;
  z-index: 2 !important;
}
#modal-root .technical-preview-wrap > .technical-paper:not(.document-attachment-page) > .technical-paper-footer {
  position: static !important;
  order: 99 !important;
  flex: 0 0 7mm !important;
  min-height: 7mm !important;
  width: auto !important;
  margin: auto -11mm 0 -1mm !important;
  padding: 2mm 0 0 !important;
  border-top: .35mm solid #f15a24 !important;
  box-sizing: border-box !important;
  z-index: 3 !important;
}
@media print {
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .receipt-redesigned-content {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page .receipt-redesign-items-section {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page .receipt-redesign-items-section .receipt-redesign-items {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
    margin-bottom: 0 !important;
  }
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page:not(.document-attachment-page) {
    display: flex !important;
    flex-direction: column !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 0 24mm 8mm 14mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page:not(.document-attachment-page) > .technical-paper-footer {
    position: static !important;
    order: 99 !important;
    flex: 0 0 7mm !important;
    margin: auto -11mm 0 -1mm !important;
  }
}


/* چاپ چندصفحه‌ای نامه: محفظه نباید به ارتفاع یک A4 قفل شود.
   فقط هر برگهٔ نامه/پیوست یک صفحهٔ مستقل است؛ wrapper باید تمام صفحات را
   در جریان چاپ نگه دارد تا پیوست PDF حذف یا به صفحهٔ سفید تبدیل نشود. */
@media print {
  html:has(body.printing-letter),
  html:has(body.printing-letter-horizontal) {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  body.printing-letter,
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap,
  body.printing-letter-horizontal,
  body.printing-letter-horizontal .modal-backdrop,
  body.printing-letter-horizontal .modal-card,
  body.printing-letter-horizontal .modal-body,
  body.printing-letter-horizontal .letter-preview,
  body.printing-letter-horizontal .letter-preview-wrap {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.printing-letter .letter-preview-wrap,
  body.printing-letter-horizontal .letter-preview-wrap {
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal {
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  body.printing-letter .letter-preview-wrap .letter-paper:last-child,
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}

/* آخرین لایهٔ نامهٔ وارده؛ بعد از تمام overrideهای عمومی چاپ اعمال می‌شود. */
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-original-page {
  position: relative !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto 10mm !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: #fff !important;
  box-shadow: 0 2mm 8mm rgba(24, 37, 48, .12) !important;
}
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-coding {
  position: absolute !important;
  z-index: 3 !important;
  top: 9mm !important;
  right: 13mm !important;
  left: 13mm !important;
  height: 8mm !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  box-sizing: border-box !important;
  padding: 1.5mm 3mm !important;
  border-bottom: .35mm solid #b8c3c9 !important;
  color: #41515a !important;
  background: #fff !important;
  direction: rtl !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 9pt !important;
  line-height: 1.2 !important;
}
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-coding strong { color: #26333b !important; font-weight: 700 !important; }
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-coding span { color: #a84e2b !important; font-weight: 700 !important; direction: ltr !important; unicode-bidi: plaintext !important; }
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-attachment-page-body {
  top: 23mm !important;
  right: 13mm !important;
  bottom: 13mm !important;
  left: 13mm !important;
  z-index: 1 !important;
}
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-attachment-content-frame { border: 0 !important; border-radius: 0 !important; }
html body #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-missing-file {
  width: 100% !important;
  margin: auto !important;
  padding: 12mm !important;
  border: 1px dashed #c8d1d6 !important;
  color: #788891 !important;
  text-align: center !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 11pt !important;
}
@media print {
  body.printing-letter #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-original-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap.letter-incoming-original-only .letter-incoming-original-page {
    margin: 0 !important;
    box-shadow: none !important;
  }
}

/* قفل صفحهٔ آخر پیش‌فاکتور: مهر و امضا خارج از محفظهٔ جدول قرار می‌گیرند تا
   overflow جدول آن‌ها را ناقص نکند. جدول نیز فضای آزاد بین سربرگ و فوتر را پر
   می‌کند، بدون اینکه به فوتر یا صفحهٔ بعد وارد شود. */
@media print {
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    overflow: hidden !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table tbody {
    height: 100% !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band {
    position: absolute !important;
    right: auto !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    max-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    z-index: 23 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-seller-signature {
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-signature-assets {
    width: 100% !important;
    height: 25mm !important;
    min-height: 25mm !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4mm !important;
    overflow: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-signature-image {
    width: 44mm !important;
    height: 20mm !important;
    max-width: 44mm !important;
    max-height: 20mm !important;
    object-fit: contain !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-stamp-image {
    width: 25mm !important;
    height: 25mm !important;
    max-width: 25mm !important;
    max-height: 25mm !important;
    object-fit: contain !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .signature-name,
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .signature-title {
    display: block !important;
    margin: 0 !important;
    line-height: 1.2 !important;
  }
}

/*
 * قفل نهایی هندسهٔ چاپ اسناد — ۱۴۰۵/۰۶/۲۴
 *
 * خط نارنجی فوتر در همهٔ برگه‌های A4 در bottom:8mm قرار دارد و ارتفاع خود
 * فوتر 7mm است. بنابراین پایان ناحیهٔ محتوای سند عمداً در 278mm (19mm از
 * پایین کاغذ) قفل می‌شود؛ 4mm فاصلهٔ خالی بین محتوا و ابتدای خط نارنجی
 * باقی می‌ماند. این بلوک باید آخرین override باشد تا قواعد قدیمی flex/height
 * نتوانند فوتر صفحهٔ دوم و صفحات بعدی را به صفحهٔ قبلی منتقل کنند.
 */
@page afv-document-a4-stable { size: A4 portrait; margin: 0; }

@media screen, print {
  /* هر article یک کاغذ مستقل و دقیقاً هم‌اندازهٔ A4 است. */
  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    position: relative !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  /* سربرگ مشترک: لوگو، خط عمودی و خط نارنجی همگی نسبت به همان برگه‌اند. */
  #modal-root .invoice-paper .invoice-native-letterhead,
  #modal-root .receipt-paper .invoice-native-letterhead,
  #modal-root .check-receipt-paper .invoice-native-letterhead,
  #modal-root .technical-paper .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    pointer-events: none !important;
    z-index: 20 !important;
  }

  #modal-root .invoice-paper .invoice-native-logo,
  #modal-root .receipt-paper .invoice-native-logo,
  #modal-root .check-receipt-paper .invoice-native-logo,
  #modal-root .technical-paper .invoice-native-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    max-width: 30mm !important;
    margin: 0 !important;
    z-index: 21 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-paper .invoice-native-side-rule,
  #modal-root .receipt-paper .invoice-native-side-rule,
  #modal-root .check-receipt-paper .invoice-native-side-rule,
  #modal-root .technical-paper .invoice-native-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border-left: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 20 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-paper .invoice-native-footer,
  #modal-root .receipt-paper .invoice-native-footer,
  #modal-root .check-receipt-paper .invoice-native-footer,
  #modal-root .technical-paper .invoice-native-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    display: grid !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }

  /* صفحات ساخته‌شده توسط paginator، همان هندسهٔ سربرگ اصلی را حفظ می‌کنند. */
  #modal-root .invoice-preview .print-flow-logo,
  #modal-root .receipt-preview-wrap .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    z-index: 21 !important;
  }

  #modal-root .invoice-preview .print-flow-logo img,
  #modal-root .receipt-preview-wrap .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    height: auto !important;
    max-width: 30mm !important;
    margin: 0 !important;
    object-fit: contain !important;
  }

  #modal-root .invoice-preview .print-flow-side-rule,
  #modal-root .receipt-preview-wrap .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border-left: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 20 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-preview .print-flow-footer,
  #modal-root .receipt-preview-wrap .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    display: grid !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }

  /* محتوای پیش‌فاکتور و رسید دقیقاً بین سربرگ و فاصلهٔ امن فوتر قرار دارد. */
  #modal-root .invoice-preview .invoice-paper.has-letterhead,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    padding: 0 !important;
    display: block !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead > .invoice-paper-content,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead > .receipt-redesigned-content,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead > .check-receipt-v3-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    z-index: 2 !important;
  }

  /* رسیدهای قدیمی که wrapper محتوا ندارند نیز باید همان فاصلهٔ پایین را داشته باشند. */
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead:not(:has(> .receipt-redesigned-content)) {
    padding: 34mm 24mm 19mm 14mm !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead > .invoice-paper-content > .invoice-paper-table,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-v3-table {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
  }

  /* گزارش کنترل کیفیت: اطلاعات صفحه سه میلی‌متر بالاتر از خط نارنجی می‌نشیند. */
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0 24mm 8mm 14mm !important;
  }

  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-header,
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-paper-head {
    flex: 0 0 34mm !important;
    height: 34mm !important;
    min-height: 34mm !important;
    max-height: 34mm !important;
    box-sizing: border-box !important;
  }

  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-page-info {
    order: 98 !important;
    flex: 0 0 5mm !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: auto 0 3mm !important;
    box-sizing: border-box !important;
  }

  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-footer {
    order: 99 !important;
    flex: 0 0 7mm !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 -11mm 0 -1mm !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
  }

  #modal-root .quality-preview-wrap .quality-paper.has-letterhead::before {
    top: 34mm !important;
    bottom: 15mm !important;
  }

  /* گزارش فنی هم از همان ناحیهٔ امن استفاده می‌کند؛ خط رسمی فوترش جداست. */
  #modal-root .technical-preview-wrap .technical-paper.has-letterhead {
    padding: 34mm 24mm 19mm 14mm !important;
    display: block !important;
  }

  #modal-root .technical-preview-wrap .technical-paper.has-letterhead > .technical-paper-footer {
    position: absolute !important;
    right: 24mm !important;
    bottom: 15mm !important;
    left: 14mm !important;
    width: auto !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: 0 !important;
    padding-top: 0 !important;
    box-sizing: border-box !important;
  }

  /* همهٔ صفحه‌های ایجادشدهٔ paginator فاصلهٔ صفحه‌ای قطعی دارند. */
  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    page: afv-document-a4-stable !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    page-break-after: always !important;
  }

  #modal-root .invoice-preview .invoice-paper:last-child,
  #modal-root .receipt-preview-wrap .receipt-paper:last-child,
  #modal-root .check-receipt-print-wrap .check-receipt-paper:last-child,
  #modal-root .quality-preview-wrap .quality-paper:last-child,
  #modal-root .technical-preview-wrap .technical-paper:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

@media print {
  /* در چاپ، wrapperهای اطراف نباید صفحهٔ اضافی بسازند؛ فقط خود articleها چاپ می‌شوند. */
  html:has(body.printing-invoice),
  html:has(body.printing-receipt),
  html:has(body.printing-check-receipt),
  html:has(body.printing-quality),
  html:has(body.printing-technical-report),
  body.printing-invoice,
  body.printing-receipt,
  body.printing-check-receipt,
  body.printing-quality,
  body.printing-technical-report {
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-shadow: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper + .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper + .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper + .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper + .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper + .technical-paper {
    break-before: page !important;
    page-break-before: always !important;
  }
}

/* چاپ واقعی اسناد مالی و رسید تحویل: هر برگه یک صفحهٔ مستقل A4 است.
   جدول‌های بلند قبل از چاپ توسط app.js به همین برگه‌ها تقسیم می‌شوند؛ این
   لایهٔ نهایی اجازه نمی‌دهد قواعد قدیمیِ ارتفاع ثابت، محتوا را زیر فوتر
   ببرند یا بعد از آخرین برگه صفحهٔ سفید بسازند. */
@page afv-document-a4-portrait { size: A4 portrait; margin: 0; }

@media print {
  html:has(body.printing-invoice),
  html:has(body.printing-receipt),
  body.printing-invoice,
  body.printing-receipt,
  body.printing-invoice > #modal-root,
  body.printing-receipt > #modal-root,
  body.printing-invoice #modal-root .modal-backdrop,
  body.printing-receipt #modal-root .modal-backdrop,
  body.printing-invoice #modal-root .modal-card,
  body.printing-receipt #modal-root .modal-card,
  body.printing-invoice #modal-root .modal-body,
  body.printing-receipt #modal-root .modal-body {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
    display: block !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
    display: block !important;
    background: #fff !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    page: afv-document-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
    padding: 34mm 24mm 23mm 14mm !important;
    background: #fff !important;
    box-shadow: none !important;
    page-break-before: auto !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    break-after: page !important;
    break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper:last-of-type,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper:last-of-type {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: relative !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-head,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head {
    width: 100% !important;
    min-height: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 0 4mm !important;
    border-bottom: 0 !important;
    box-sizing: border-box !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head {
    padding-top: 0 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table {
    width: 100% !important;
    margin: 0 !important;
    border-collapse: collapse !important;
    break-inside: auto !important;
    page-break-inside: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table thead,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table thead {
    display: table-header-group !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table tr,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table th,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table td,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table th,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table td {
    padding-top: 2mm !important;
    padding-bottom: 2mm !important;
    font-size: 8pt !important;
    line-height: 1.3 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-party-section,
  body.printing-invoice #modal-root .invoice-preview .invoice-summary-grid,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-meta-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-party-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-total-strip,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-note,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-confirmation,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-customer-ack,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid {
    margin-top: 6mm !important;
  }

  /* فقط فوتر رسمی سربرگ چاپ شود؛ فوتر داخلی بدنه نباید صفحهٔ اضافی بسازد. */
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-footer {
    display: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    z-index: 3 !important;
    pointer-events: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-native-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-side-rule {
    border-left: 0 !important;
    width: 0 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-native-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-footer {
    position: absolute !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    z-index: 4 !important;
    width: auto !important;
    min-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-page-count {
    font-size: 9pt !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-page-count::after {
    content: none !important;
  }
}

/* فرم «رسید تحویل جدید»: اقلام مستقل باید مثل جدول واقعی قابل تکمیل باشند. */
#receipt-form .receipt-manual-items-table {
  min-width: 900px !important;
  table-layout: fixed !important;
}
#receipt-form .receipt-manual-items-table th,
#receipt-form .receipt-manual-items-table td {
  vertical-align: middle !important;
}
#receipt-form .receipt-manual-items-table th:nth-child(1),
#receipt-form .receipt-manual-items-table td:nth-child(1) { width: 6% !important; text-align: center !important; }
#receipt-form .receipt-manual-items-table th:nth-child(2),
#receipt-form .receipt-manual-items-table td:nth-child(2) { width: 15% !important; }
#receipt-form .receipt-manual-items-table th:nth-child(3),
#receipt-form .receipt-manual-items-table td:nth-child(3) { width: 24% !important; }
#receipt-form .receipt-manual-items-table th:nth-child(4),
#receipt-form .receipt-manual-items-table td:nth-child(4) { width: 12% !important; }
#receipt-form .receipt-manual-items-table th:nth-child(5),
#receipt-form .receipt-manual-items-table td:nth-child(5) { width: 10% !important; }
#receipt-form .receipt-manual-items-table th:nth-child(6),
#receipt-form .receipt-manual-items-table td:nth-child(6) { width: 25% !important; }
#receipt-form .receipt-manual-items-table th:nth-child(7),
#receipt-form .receipt-manual-items-table td:nth-child(7) { width: 8% !important; }
#receipt-form .receipt-manual-items-table input {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 38px !important;
  box-sizing: border-box !important;
  padding: 7px 8px !important;
  border: 1px solid #d8e0e6 !important;
  border-radius: 7px !important;
  background: #fff !important;
  color: #27343d !important;
  font: inherit !important;
}
#receipt-form .receipt-manual-items-table input:focus {
  border-color: #f15a24 !important;
  outline: 2px solid #f15a2426 !important;
}
#receipt-form .receipt-manual-items-actions {
  justify-content: space-between !important;
  margin: 9px 0 13px !important;
}
@media (max-width: 820px) {
  #receipt-form .receipt-manual-items-table { min-width: 780px !important; }
}

/* فرم نامه: نمایش تفکیک‌شدهٔ نامه وارده و انتخاب گیرندگان از کاربران CRM */
#letter-form .letter-recipient-users-field select[multiple] {
  min-height: 92px;
  padding: 8px 10px;
  line-height: 1.8;
}
#letter-form .letter-incoming-field,
#letter-form .letter-general-field {
  min-width: 0;
}
#letter-form .letter-incoming-detail {
  display: grid;
  gap: 6px;
  margin: 18px 0 10px;
  padding: 10px 12px;
  border: 1px solid #e2e9ee;
  border-radius: 8px;
  background: #fbfcfd;
  color: #53636d;
  font-size: 10px;
  line-height: 1.8;
}
#letter-form .letter-incoming-detail strong {
  color: #26333b;
}

/* خروجی نامه همیشه A4 است؛ فقط هر برگه صفحه‌بندی می‌شود، نه کل wrapper. */
@page afv-letter-a4-portrait { size: A4 portrait; margin: 0; }
@page afv-letter-a4-landscape { size: A4 landscape; margin: 0; }
@media print {
  body.printing-letter,
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }
  body.printing-letter .letter-preview-wrap {
    padding: 0 !important;
    display: block !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    page: afv-letter-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal):last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-letter-horizontal,
  body.printing-letter-horizontal .modal-backdrop,
  body.printing-letter-horizontal .modal-card,
  body.printing-letter-horizontal .modal-body,
  body.printing-letter-horizontal .letter-preview,
  body.printing-letter-horizontal .letter-preview-wrap {
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal {
    page: afv-letter-a4-landscape !important;
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-letter .letter-page-counter,
  body.printing-letter-horizontal .letter-page-counter {
    display: inline !important;
    font-size: 10px !important;
    direction: rtl !important;
    unicode-bidi: plaintext !important;
  }
  body.printing-letter .letter-page-counter::after,
  body.printing-letter-horizontal .letter-page-counter::after {
    content: none !important;
  }
}

/*
 * آخرین لایهٔ تثبیت حاشیهٔ فوتر — ۱۴۰۵/۰۶/۲۴
 * پایان محتوای هر برگه در 278mm است؛ خط نارنجی از 282mm شروع می‌شود.
 * این بلوک عمداً در انتهای فایل قرار دارد تا تمام قواعد قدیمی را قطعی override کند.
 */
@page afv-document-a4-stable-final { size: A4 portrait; margin: 0; }

@media screen, print {
  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    position: relative !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    display: block !important;
    padding: 0 !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead > .invoice-paper-content,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead > .receipt-redesigned-content,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead > .check-receipt-v3-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    z-index: 2 !important;
  }

  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead:not(:has(> .receipt-redesigned-content)) {
    padding: 34mm 24mm 19mm 14mm !important;
  }

  /* سربرگ و فوتر نسبت به همان article صفحه‌بندی می‌شوند، نه نسبت به wrapper. */
  #modal-root .invoice-preview .invoice-paper .invoice-native-letterhead,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-letterhead,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-letterhead,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    pointer-events: none !important;
    z-index: 20 !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-logo,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-logo,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-logo,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-logo,
  #modal-root .invoice-preview .print-flow-logo,
  #modal-root .receipt-preview-wrap .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-width: 30mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    z-index: 21 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-preview .print-flow-logo img,
  #modal-root .receipt-preview-wrap .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    object-fit: contain !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-side-rule,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-side-rule,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-side-rule,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-side-rule,
  #modal-root .invoice-preview .print-flow-side-rule,
  #modal-root .receipt-preview-wrap .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border-left: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 20 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-footer,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-footer,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-footer,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-footer,
  #modal-root .invoice-preview .print-flow-footer,
  #modal-root .receipt-preview-wrap .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    display: grid !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }

  /* QC: کد/تاریخ 3mm بالاتر از ابتدای خط نارنجی قرار می‌گیرد. */
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0 24mm 8mm 14mm !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-header,
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-paper-head {
    flex: 0 0 34mm !important;
    height: 34mm !important;
    min-height: 34mm !important;
    max-height: 34mm !important;
    box-sizing: border-box !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-page-info {
    order: 98 !important;
    flex: 0 0 5mm !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: auto 0 3mm !important;
    box-sizing: border-box !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-footer {
    order: 99 !important;
    flex: 0 0 7mm !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 -11mm 0 -1mm !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead::before {
    top: 34mm !important;
    bottom: 15mm !important;
  }

  /* گزارش فنی و نامه نیز پایین صفحه را قبل از خط نارنجی خالی نگه می‌دارند. */
  #modal-root .technical-preview-wrap .technical-paper.has-letterhead {
    display: block !important;
    padding: 34mm 24mm 19mm 14mm !important;
  }
  #modal-root .technical-preview-wrap .technical-paper.has-letterhead > .technical-paper-footer {
    position: absolute !important;
    right: 24mm !important;
    bottom: 15mm !important;
    left: 14mm !important;
    width: auto !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: 0 !important;
    padding-top: 0 !important;
    box-sizing: border-box !important;
  }
  #modal-root .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) > .letter-document {
    position: absolute !important;
    top: 49mm !important;
    right: 25mm !important;
    bottom: 22mm !important;
    left: 25mm !important;
    min-height: 0 !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    page: afv-document-a4-stable-final !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    page-break-after: always !important;
  }
  #modal-root .invoice-preview .invoice-paper:last-child,
  #modal-root .receipt-preview-wrap .receipt-paper:last-child,
  #modal-root .check-receipt-print-wrap .check-receipt-paper:last-child,
  #modal-root .quality-preview-wrap .quality-paper:last-child,
  #modal-root .technical-preview-wrap .technical-paper:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

@media print {
  html:has(body.printing-invoice),
  html:has(body.printing-receipt),
  html:has(body.printing-check-receipt),
  html:has(body.printing-quality),
  html:has(body.printing-technical-report),
  body.printing-invoice,
  body.printing-receipt,
  body.printing-check-receipt,
  body.printing-quality,
  body.printing-technical-report {
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-shadow: none !important;
  }
}

/* لایهٔ نهایی چاپ اسناد مالی و رسید تحویل؛ بعد از همهٔ overrideهای قدیمی قرار دارد. */
@page afv-document-a4-portrait-final { size: A4 portrait; margin: 0; }
@media print {
  html:has(body.printing-invoice),
  html:has(body.printing-receipt),
  body.printing-invoice,
  body.printing-receipt,
  body.printing-invoice > #modal-root,
  body.printing-receipt > #modal-root,
  body.printing-invoice #modal-root .modal-backdrop,
  body.printing-receipt #modal-root .modal-backdrop,
  body.printing-invoice #modal-root .modal-card,
  body.printing-receipt #modal-root .modal-card,
  body.printing-invoice #modal-root .modal-body,
  body.printing-receipt #modal-root .modal-body {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
    display: block !important;
    background: #fff !important;
    box-shadow: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
    display: block !important;
    background: #fff !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    page: afv-document-a4-portrait-final !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
    padding: 34mm 24mm 23mm 14mm !important;
    background: #fff !important;
    box-shadow: none !important;
    page-break-before: auto !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    break-after: page !important;
    break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper:last-of-type,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper:last-of-type {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: relative !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-head,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head {
    width: 100% !important;
    min-height: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 0 4mm !important;
    border-bottom: 0 !important;
    box-sizing: border-box !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head { padding-top: 0 !important; }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table {
    width: 100% !important;
    margin: 0 !important;
    border-collapse: collapse !important;
    break-inside: auto !important;
    page-break-inside: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table thead,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table thead { display: table-header-group !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table tr,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table th,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table td,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table th,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table td {
    padding-top: 2mm !important;
    padding-bottom: 2mm !important;
    font-size: 8pt !important;
    line-height: 1.3 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-party-section,
  body.printing-invoice #modal-root .invoice-preview .invoice-summary-grid,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-meta-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-party-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-total-strip,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-note,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-confirmation,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-customer-ack,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid { margin-top: 6mm !important; }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-footer { display: none !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    z-index: 3 !important;
    pointer-events: none !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-side-rule {
    border-left: 0 !important;
    width: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-footer {
    position: absolute !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    z-index: 4 !important;
    width: auto !important;
    min-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-page-count { font-size: 9pt !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-page-count::after { content: none !important; }
}

/* پیوست نامه در صفحهٔ جداگانه و بعد از متن اصلی قرار می‌گیرد؛ سربرگ نامه فقط «پیوست دارد» را نشان می‌دهد. */
.letter-attachment-content-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 310px;
  margin: 0 0 20px;
  overflow: hidden;
  border: 1px solid #dfe8ed;
  border-radius: 10px;
  background: #fbfcfd;
}
.letter-attachment-visual {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 590px;
  object-fit: contain;
}
.letter-attachment-pdf-frame { min-height: 420px; }
.letter-attachment-embed { display: block; width: 100%; height: 420px; border: 0; }
.letter-attachment-file-frame {
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
  padding: 24px;
  box-sizing: border-box;
  color: #536570;
  text-align: center;
}
.letter-attachment-file-frame strong { color: #26323a; font-size: 13px; }
.letter-attachment-file-frame small { font-size: 10px; }
.letter-attachment-file-icon { color: #3775c8; font-size: 36px; }
.letter-attachment-page-card { margin-top: 12px; }
.letter-attachment-page-body > p { margin-bottom: 0; }
@media print {
  .letter-attachment-content-frame { break-inside: avoid; page-break-inside: avoid; }
  .letter-attachment-visual { max-height: 165mm; }
  .letter-attachment-pdf-frame { min-height: 150mm; }
  .letter-attachment-embed { height: 150mm; }
  .letter-attachment-open { display: none !important; }
}

/* قفل آخر چاپ: ریشهٔ داشبورد حتی اگر قواعد قدیمیِ print بعداً فعال شوند،
   دیگر حق ندارد فضای صفحهٔ سفید برای PDF رزرو کند. */
@media print {
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #app,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #auth-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #toast-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #telephony-root {
    display: none !important;
    visibility: hidden !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop > .modal-card,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .modal-body {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }
}

/*
 * چاپ نهاییِ ایزوله برای همهٔ سندها.
 *
 * قوانین عمومی چاپ در styles.css از visibility:hidden استفاده می‌کنند؛ این
 * کار داشبورد را پنهان می‌کند اما ارتفاعش را نگه می‌دارد و در PDF یک یا چند
 * صفحهٔ سفید بعد از سند می‌سازد. در زمان چاپ، فقط modal-root باید در جریان
 * صفحه بماند و بقیهٔ ریشه‌ها باید از layout خارج شوند.
 */
@media print {
  html:has(body.printing-invoice),
  html:has(body.printing-letter),
  html:has(body.printing-letter-horizontal),
  html:has(body.printing-receipt),
  html:has(body.printing-check-receipt),
  html:has(body.printing-quality),
  html:has(body.printing-technical-report),
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) {
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    background: #fff !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
  }

  body.printing-letter-horizontal {
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #app,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #auth-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #toast-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #telephony-root {
    display: none !important;
    visibility: hidden !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop > .modal-card,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .modal-body {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .modal-header,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .modal-footer,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .print-mode-note,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .invoice-screen-only,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .receipt-screen-only,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .letter-screen-only,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .quality-screen-only,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .technical-screen-only,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .document-relation-wrap {
    display: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap,
  body.printing-letter #modal-root .letter-preview-wrap,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap {
    position: static !important;
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper {
    page: afv-a4-portrait !important;
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper {
    visibility: visible !important;
  }
}

/* هماهنگی پیش‌نمایش با PDF نامه و اصلاح ابعاد ریشهٔ چاپ A4 */
.letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
  page: afv-letter-final-a4-portrait !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  box-sizing: border-box !important;
}
.letter-paper .letter-incoming-detail {
  display: grid !important;
  gap: 6px !important;
  margin: 18px 0 10px !important;
  padding: 10px 12px !important;
  border: 1px solid #e2e9ee !important;
  border-radius: 8px !important;
  background: #fbfcfd !important;
  color: #53636d !important;
  font-size: 10px !important;
  line-height: 1.8 !important;
}
.letter-paper .letter-incoming-detail strong { color: #26333b !important; }
@media print {
  html:has(body.printing-letter) {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }
  html:has(body.printing-letter-horizontal) {
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }
}

/* رسید تحویل بازطراحی‌شده: همان سربرگ رسمی پیش‌فاکتور، بدون لایه‌های قدیمی و فشردگی. */
@page afv-receipt-redesigned-a4 { size: A4 portrait; margin: 0; }
.receipt-redesigned-wrap {
  padding: 0 !important;
  background: #fff !important;
}
.receipt-redesigned {
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 0 24mm 14mm 14mm !important;
  margin: 0 auto !important;
  overflow: hidden !important;
  background: #fff !important;
  box-shadow: none !important;
  page: afv-receipt-redesigned-a4 !important;
  page-break-after: avoid !important;
  break-after: avoid-page !important;
}
.receipt-redesigned::before { display: none !important; }
.receipt-redesigned > .invoice-native-letterhead {
  position: absolute !important;
  inset: 0 !important;
  z-index: 1 !important;
}
.receipt-redesigned-content {
  position: relative !important;
  z-index: 2 !important;
  display: block !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  padding: 34mm 0 31mm !important;
  box-sizing: border-box !important;
}
.receipt-redesign-head {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  align-items: center !important;
  min-height: 23mm !important;
  margin: 0 0 4mm !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  direction: ltr !important;
}
.receipt-redesign-meta {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 2.5mm 5mm !important;
  direction: rtl !important;
  text-align: right !important;
}
.receipt-redesign-meta > div { min-width: 0 !important; }
.receipt-redesign-meta small,
.receipt-redesign-meta strong { display: block !important; }
.receipt-redesign-meta small { color: #7f8b93 !important; font-size: 9px !important; }
.receipt-redesign-meta strong { margin-top: 1mm !important; color: #18232c !important; font-size: 11px !important; }
.receipt-redesign-title {
  direction: rtl !important;
  text-align: center !important;
}
.receipt-redesign-title h1 {
  margin: 0 !important;
  color: #17202b !important;
  font-size: 22px !important;
  line-height: 1.35 !important;
  font-weight: 800 !important;
}
.receipt-redesign-title span {
  display: block !important;
  margin-top: 1mm !important;
  color: #8a969e !important;
  direction: ltr !important;
  font-size: 9px !important;
  letter-spacing: .7px !important;
}
.receipt-redesign-related {
  display: flex !important;
  align-items: baseline !important;
  justify-content: center !important;
  gap: 5mm !important;
  width: 58% !important;
  min-height: 12mm !important;
  margin: 0 auto 4mm !important;
  padding: 2.5mm 5mm !important;
  border: 1px solid #d8e0e6 !important;
  border-radius: 4px !important;
  background: #fff !important;
  text-align: center !important;
}
.receipt-redesign-related small { color: #697985 !important; font-size: 9px !important; }
.receipt-redesign-related strong { color: #17202b !important; font-size: 12px !important; }
.receipt-redesign-parties {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 0 !important;
  width: 100% !important;
  margin: 0 0 5mm !important;
  padding: 3mm 0 !important;
  border-top: 1px solid #d8e0e6 !important;
  border-bottom: 1px solid #d8e0e6 !important;
  background: #fff !important;
  direction: rtl !important;
}
.receipt-redesign-parties > div {
  min-width: 0 !important;
  padding: 0 3mm !important;
  border-left: 1px solid #d8e0e6 !important;
  text-align: right !important;
}
.receipt-redesign-parties > div:last-child { border-left: 0 !important; }
.receipt-redesign-parties small,
.receipt-redesign-parties strong { display: block !important; }
.receipt-redesign-parties small { color: #7f8b93 !important; font-size: 9px !important; }
.receipt-redesign-parties strong { margin-top: 1mm !important; overflow: hidden !important; color: #17202b !important; font-size: 11px !important; text-overflow: ellipsis !important; white-space: nowrap !important; }
.receipt-redesign-section-title {
  margin: 0 0 2.5mm !important;
  color: #17202b !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  text-align: right !important;
}
.receipt-redesigned .receipt-redesign-items {
  width: 100% !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
}
.receipt-redesign-items th,
.receipt-redesign-items td {
  padding: 2.8mm 2mm !important;
  border-bottom: 1px solid #d8e0e6 !important;
  color: #43515a !important;
  font-size: 10px !important;
  line-height: 1.55 !important;
  vertical-align: middle !important;
  overflow-wrap: anywhere !important;
}
.receipt-redesign-items th { color: #6f7d86 !important; background: #f7f9fa !important; font-weight: 800 !important; }
.receipt-redesign-items th:nth-child(1), .receipt-redesign-items td:nth-child(1) { width: 8% !important; }
.receipt-redesign-items th:nth-child(2), .receipt-redesign-items td:nth-child(2) { width: 17% !important; }
.receipt-redesign-items th:nth-child(3), .receipt-redesign-items td:nth-child(3) { width: 31% !important; }
.receipt-redesign-items th:nth-child(4), .receipt-redesign-items td:nth-child(4) { width: 13% !important; }
.receipt-redesign-items th:nth-child(5), .receipt-redesign-items td:nth-child(5) { width: 11% !important; }
.receipt-redesign-items th:nth-child(6), .receipt-redesign-items td:nth-child(6) { width: 20% !important; }
.receipt-redesign-items td strong, .receipt-redesign-items td small { display: block !important; }
.receipt-redesign-items td small { margin-top: 1mm !important; color: #7f8b93 !important; font-size: 9px !important; }
.receipt-redesign-total {
  width: 42% !important;
  margin: 4mm 0 0 auto !important;
  padding: 2.5mm 3mm !important;
  border-right: 3px solid #f15a24 !important;
  border-radius: 0 !important;
  background: #fffaf6 !important;
  font-size: 10px !important;
}
.receipt-redesign-total strong { font-size: 12px !important; }
.receipt-redesign-note {
  margin: 5mm 0 0 !important;
  padding: 3mm 4mm !important;
  border: 1px solid #d8e0e6 !important;
  border-radius: 0 !important;
  background: #fff !important;
  color: #566873 !important;
  font-size: 10px !important;
  line-height: 1.8 !important;
}
.receipt-redesign-note strong { color: #f15a24 !important; font-size: 12px !important; }
.receipt-redesign-note p { margin: 1mm 0 0 !important; }
.receipt-redesign-confirmation {
  margin: 5mm 0 0 !important;
  padding: 3mm 4mm !important;
  border: 1px dashed #aebbc3 !important;
  background: #fff !important;
  color: #26343d !important;
  font-size: 11px !important;
  line-height: 2 !important;
  text-align: right !important;
}
.receipt-redesign-confirmation strong { display: block !important; margin-bottom: 1mm !important; color: #17202b !important; font-size: 12px !important; }
.receipt-redesign-confirmation p { margin: 0 !important; }
.receipt-redesign-confirmation > span { display: block !important; margin-top: 2mm !important; text-align: left !important; }
.receipt-redesign-signatures {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12mm !important;
  margin-top: 8mm !important;
  direction: rtl !important;
}
.receipt-redesign-signature-card {
  min-height: 32mm !important;
  color: #687882 !important;
  text-align: center !important;
}
.receipt-redesign-signature-card > strong { display: block !important; color: #17202b !important; font-size: 11px !important; }
.receipt-redesign-signature-card > span { display: block !important; margin-top: 1mm !important; color: #43515a !important; font-size: 11px !important; }
.receipt-redesign-signature-card > small { display: block !important; margin-top: 1mm !important; color: #7f8b93 !important; font-size: 9px !important; }
.receipt-redesign-blank-signature { width: 55mm !important; margin: 13mm auto 0 !important; border-bottom: .35mm solid #60717a !important; }
.receipt-redesign-signature-card .receipt-signature-image { width: 48mm !important; max-width: 100% !important; margin: 2mm auto 0 !important; }
.receipt-redesign-signature-card .receipt-signature-line { width: 42mm !important; margin: 9mm auto 2mm !important; }
.receipt-redesign-signature-card .receipt-stamp-image { width: 24mm !important; height: 24mm !important; margin: 2mm auto 0 !important; }
.receipt-redesigned .receipt-signature-disabled { height: auto !important; padding-top: 9mm !important; }
@media screen {
  .receipt-redesigned-wrap { overflow: auto !important; }
}
@media print {
  .receipt-redesigned-wrap { padding: 0 !important; background: #fff !important; }
  .receipt-redesigned { page: afv-receipt-redesigned-a4 !important; }
}

/* نامه رسمی: A4 ثابت، سربرگ در یک لایه و حاشیهٔ امن برای متن */
.letter-paper {
  box-sizing: border-box;
  background-image: none !important;
  overflow: hidden;
}
.letter-paper.has-letterhead > .official-letterhead-image {
  inset: 0 !important;
  z-index: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: fill !important;
}
.letter-paper > .letter-meta,
.letter-paper > .letter-document,
.letter-paper > .letter-print-page-footer { z-index: 1; }
.letter-paper > .letter-meta {
  top: 12mm;
  left: 12mm;
  width: 47mm;
  box-sizing: border-box;
  padding: 2mm;
  border: 1px solid #d9e1e6;
  border-radius: 2mm;
  background: rgba(255,255,255,.92);
}
.letter-document {
  box-sizing: border-box;
  min-height: 244mm;
  padding: 49mm 22mm 32mm !important;
  overflow-wrap: anywhere;
}
.letter-recipient {
  margin-top: 15mm !important;
  text-align: right;
}
.letter-recipient-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5mm;
  width: 100%;
  direction: rtl;
}
.letter-recipient-cell {
  min-width: 0;
  min-height: 16mm;
  box-sizing: border-box;
  padding: 3mm 4mm;
  border: 1px solid #cfd9df;
  border-radius: 1.5mm;
  background: rgba(255,255,255,.9);
  overflow-wrap: anywhere;
}
.letter-recipient-cell small,
.letter-recipient-cell strong { display: block; }
.letter-recipient-cell small {
  margin-bottom: 1.5mm;
  color: #788994;
  font-size: 8px;
  font-weight: 700;
}
.letter-recipient-cell strong {
  color: #18242c;
  font-size: 11px;
  line-height: 1.7;
}
.letter-body-content { max-width: 100%; overflow-wrap: anywhere; }
.letter-paper .letter-print-page-footer { display: none !important; }
.letter-recipient-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.letter-recipient-form-grid .form-field { min-width: 0; }
.letter-recipient-form-grid .form-field label { font-size: 8px; }
.letter-recipient-form-grid input { min-width: 0; }

@page letter-vertical { size: A4 portrait; margin: 0; }
@media print {
  .letter-paper:not(.letterhead-horizontal) {
    page: letter-vertical;
    width: 210mm !important;
    min-height: 297mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .letter-paper:not(.letterhead-horizontal) > .letter-meta {
    top: 12mm;
    left: 12mm;
  }
  .letter-paper:not(.letterhead-horizontal) > .letter-document {
    min-height: 244mm;
    padding: 49mm 22mm 32mm !important;
  }
  .letter-paper.letterhead-horizontal.has-letterhead > .official-letterhead-image {
    width: 100% !important;
    height: 100% !important;
    object-fit: fill !important;
  }
  .letter-recipient-cell { background: #fff; }
}

/* انتخاب پرونده در آپلود BOM؛ منوی native بلند و بریده جای خود را به فهرست خوانا و محدود می‌دهد. */
.bom-customer-picker {
  position: relative;
  width: 100%;
  direction: rtl;
  z-index: 30;
}
.bom-customer-picker-input {
  position: relative;
  display: flex;
  align-items: center;
}
.bom-customer-picker-input input[data-bom-customer-search] {
  width: 100%;
  min-height: 40px;
  padding: 8px 38px 8px 12px;
  border: 1px solid #d8e0e6;
  border-radius: 9px;
  background: #fff;
  color: var(--ink, #17202b);
  font: inherit;
  outline: 0;
  text-align: right;
}
.bom-customer-picker-input input[data-bom-customer-search]:focus {
  border-color: #f36b32;
  box-shadow: 0 0 0 3px rgba(243, 107, 50, .12);
}
.bom-customer-picker-input > span {
  position: absolute;
  inset-inline-end: 13px;
  color: #f36b32;
  pointer-events: none;
  font-size: 16px;
}
.bom-customer-menu {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 5px);
  max-height: 270px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #cfd9e2;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(23, 32, 43, .18);
  z-index: 80;
}
.bom-customer-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 7px 10px;
  border: 0;
  border-bottom: 1px solid #edf1f4;
  border-radius: 7px;
  background: #fff;
  color: var(--ink, #17202b);
  cursor: pointer;
  font: inherit;
  text-align: right;
}
.bom-customer-option:last-of-type { border-bottom: 0; }
.bom-customer-option:hover,
.bom-customer-option:focus-visible { background: #fff3ed; outline: 0; }
.bom-customer-option strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.bom-customer-option small { flex: 0 0 auto; color: #7a8a98; direction: ltr; font-size: 10px; }
.bom-customer-empty { padding: 14px 10px; color: #7a8a98; text-align: center; font-size: 10px; }
.bom-customer-picker-status.is-match { color: #16845b; }
.bom-customer-picker-status.is-error { color: #c65533; }
.bom-customer-menu[hidden],
.bom-customer-option[hidden],
.bom-customer-empty[hidden] { display: none !important; }
@media (max-width: 820px) {
  .letter-recipient-form-grid { grid-template-columns: 1fr; }
  .letter-recipient-grid { gap: 2.5mm; }
  .letter-recipient-cell { padding: 2mm; }
  .letter-recipient-cell small { font-size: 7px; }
  .letter-recipient-cell strong { font-size: 9px; }
}

.invoice-preview .invoice-paper {
  width: min(100%, 900px);
  margin: 0 auto;
  padding: 0 28px 26px;
  color: #1f2b33;
  background: #fff;
  border: 1px solid #d8e1e5;
  box-shadow: 0 14px 32px #1828321c;
  font-family: "BNazanin", "Vazirmatn", Tahoma, sans-serif;
}

.invoice-paper-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 0;
  margin: 0 -28px;
  border: 1px solid #273640;
  border-radius: 0;
  background: #fff;
}

.invoice-paper-head > * {
  display: flex;
  min-height: 124px;
  padding: 16px 18px;
}

.invoice-paper-head > * + * {
  border-right: 1px solid #cbd6da;
}

.invoice-paper-brand {
  flex-direction: column;
  align-items: center !important;
  justify-content: center;
  gap: 7px;
  text-align: center;
}

.invoice-paper-brand .letterhead-logo-mark {
  flex: 0 0 66px;
  width: 166px;
  height: 66px;
}

.invoice-paper-brand .letterhead-logo-mark img {
  top: -47px;
  right: -26px;
  width: 760px;
}

.invoice-paper-brand strong {
  color: #203340;
  font-family: "BTitr", "BNazanin", sans-serif;
  font-size: 16px;
}

.invoice-paper-brand small {
  color: #7e8d96;
  font-size: 11px;
}

.invoice-paper-brand-placeholder {
  background: #fff;
}

.invoice-document-title {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.invoice-document-title small {
  color: #d95420;
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .45px;
}

.invoice-document-title h1 {
  margin: 8px 0 3px;
  color: #172b38;
  font-family: "BTitr", "BNazanin", sans-serif;
  font-size: 26px;
}

.invoice-document-title span {
  color: #8b999f;
  font-size: 11px;
}

.invoice-paper-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  text-align: right;
}

.invoice-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.invoice-meta-row span {
  color: #6d7d86;
}

.invoice-meta-row strong {
  color: #1f303a;
  font-size: 13px;
  white-space: nowrap;
}

.invoice-party-section {
  margin-top: 16px;
  overflow: visible;
  border: 1px solid #263641;
  border-radius: 0;
  background: #fff;
}

.invoice-party-section h2 {
  margin: 0;
  padding: 8px;
  color: #182b35;
  background: #e8ecee;
  font-family: "BTitr", "BNazanin", sans-serif;
  font-size: 15px;
  text-align: center;
}

.invoice-party-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.invoice-party-field {
  display: flex;
  min-height: 46px;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 7px 10px;
  border-top: 1px solid #cbd5da;
  border-right: 1px solid #cbd5da;
}

.invoice-party-field:nth-child(4n + 1),
.invoice-party-field.full {
  border-right: 0;
}

.invoice-party-field.span-2 {
  grid-column: span 2;
}

.invoice-party-field.full {
  grid-column: 1 / -1;
}

.invoice-party-field span {
  color: #6f7d85;
  font-size: 11px;
}

.invoice-party-field strong {
  overflow-wrap: anywhere;
  color: #20333e;
  font-size: 13px;
  line-height: 1.55;
}

.invoice-document-section-title {
  margin-top: 16px;
  padding: 9px;
  color: #182b35;
  background: #e8ecee;
  font-family: "BTitr", "BNazanin", sans-serif;
  font-size: 15px;
  text-align: center;
}

.invoice-paper-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice-paper-table .col-index { width: 5%; }
.invoice-paper-table .col-code { width: 14%; }
.invoice-paper-table .col-brand { width: 14%; }
.invoice-paper-table .col-description { width: 28%; }
.invoice-paper-table .col-quantity { width: 10%; }
.invoice-paper-table .col-unit-price { width: 14.5%; }
.invoice-paper-table .col-total { width: 14.5%; }

.invoice-paper-table th,
.invoice-paper-table td {
  border: 1px solid #aebbc0;
  vertical-align: middle;
  text-align: right;
}

.invoice-paper-table th {
  padding: 9px 7px;
  color: #203541;
  background: #f2f4f5;
  font-size: 11px;
  line-height: 1.55;
  text-align: center;
}

.invoice-paper-table td {
  padding: 10px 7px;
  color: #263944;
  font-size: 12px;
  line-height: 1.7;
}

.invoice-paper-table td:first-child,
.invoice-paper-table td:nth-child(5) {
  text-align: center;
}

.invoice-paper-table .invoice-code-cell {
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 10px;
  text-align: center;
  word-break: break-word;
}

.invoice-paper-table .invoice-description-cell {
  font-size: 11px;
  line-height: 1.75;
}

.invoice-unit-label {
  display: block;
  color: #89979e;
  font-size: 10px;
}

.invoice-amount-cell {
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 10px !important;
  text-align: left !important;
  white-space: nowrap;
}

.invoice-summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(275px, .48fr);
  gap: 20px;
  margin-top: 15px;
  direction: rtl;
}

.invoice-amount-words {
  align-self: end;
  min-height: 83px;
  padding: 12px 14px;
  border: 1px solid #d5dfe3;
  background: #fbfcfd;
}

.invoice-amount-words span,
.invoice-amount-words small {
  display: block;
  color: #6c7c85;
  font-size: 11px;
}

.invoice-amount-words strong {
  display: block;
  margin-top: 11px;
  color: #182c38;
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 17px;
}

.invoice-total-box {
  width: auto;
  margin: 0;
}

.invoice-total-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  color: #6e7d85;
  border-bottom: 1px solid #dbe3e6;
  font-size: 12px;
}

.invoice-total-line strong {
  color: #203440;
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 13px;
  white-space: nowrap;
}

.invoice-total-line.final {
  color: #172c38;
  border-bottom: 2px solid #d95420;
  font-weight: 800;
}

.invoice-paper-notes {
  margin-top: 16px;
  padding: 12px 14px;
  color: #52636c;
  border: 1px solid #d5dfe3;
  border-right: 3px solid #d95420;
  border-radius: 0;
  background: #fffdfb;
  font-size: 12px;
  line-height: 2;
}

.invoice-paper-notes strong {
  display: block;
  margin-bottom: 5px;
  color: #bd572e;
  font-family: "BTitr", "BNazanin", sans-serif;
  font-size: 14px;
}

.invoice-paper-signature-band {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(190px, .9fr);
  gap: 0;
  margin-top: 18px;
  border: 1px solid #aebbc0;
  direction: rtl;
}

.invoice-signature-box {
  min-height: 158px;
  padding: 13px;
  border-left: 1px solid #aebbc0;
  text-align: center;
}

.invoice-signature-box:last-child {
  border-left: 0;
}

.invoice-signature-box > span {
  display: block;
  color: #263b47;
  font-size: 13px;
  font-weight: 800;
}

.invoice-signature-box > small {
  display: block;
  margin-top: 4px;
  color: #89979e;
  font-size: 11px;
}

.invoice-buyer-lines {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin-top: 54px;
  color: #85939a;
  font-size: 12px;
  text-align: right;
}

.invoice-signature-assets {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
}

.invoice-signature-person {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
}

.invoice-signature-image {
  width: 145px !important;
  max-width: 100%;
  height: auto;
  margin: 0 auto !important;
}

.invoice-signature-placeholder {
  display: block;
  min-height: 44px;
  padding-top: 22px;
  color: #9aa6ad;
  font-size: 10px;
}

.invoice-signature-assets .signature-name {
  display: block;
  margin-top: 4px;
  color: #293d49;
  font-size: 12px;
}

.invoice-signature-assets .signature-title {
  display: block;
  margin-top: 2px;
  color: #8c989f;
  font-size: 10px;
}

.invoice-stamp-image {
  width: 78px !important;
  height: 78px !important;
  margin: 0 !important;
  object-fit: contain;
}

.invoice-paper-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  padding-top: 9px;
  color: #8e9aa1;
  border-top: 1px solid #d7e0e4;
  font-size: 10px;
}

.invoice-paper-footer span:first-child {
  direction: ltr;
}

.invoice-screen-only {
  display: block;
}

@media screen and (max-width: 820px) {
  .invoice-preview {
    padding: 18px;
  }

  .invoice-preview .invoice-paper {
    padding-right: 18px;
    padding-left: 18px;
  }

  .invoice-paper-head {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    margin-right: -18px;
    margin-left: -18px;
  }

  .invoice-paper-head > * {
    min-height: 106px;
    padding: 12px;
  }

  .invoice-document-title {
    grid-column: 1 / -1;
    grid-row: 1;
    border-bottom: 1px solid #cbd6da;
  }

  .invoice-paper-brand {
    grid-column: 2;
    grid-row: 2;
  }

  .invoice-paper-meta {
    grid-column: 1;
    grid-row: 2;
  }

  .invoice-paper-head > * + * {
    border-right: 0;
  }

  .invoice-paper-meta {
    border-right: 1px solid #cbd6da !important;
  }

  .invoice-party-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .invoice-party-field:nth-child(4n + 1) {
    border-right: 1px solid #cbd5da;
  }

  .invoice-party-field:nth-child(2n + 1),
  .invoice-party-field.full {
    border-right: 0;
  }

  .invoice-summary-grid {
    grid-template-columns: 1fr;
  }

  .invoice-total-box {
    order: -1;
  }
}

/* هر صفحه یک برگه مستقل است؛ سکشن‌ها فقط بین برگه‌ها جابه‌جا می‌شوند و وسط سکشن نمی‌شکنند. */
.quality-preview-wrap {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 24px !important;
}
.quality-preview-wrap .quality-paper {
  flex: 0 0 auto !important;
}
.quality-preview-wrap .quality-paper + .quality-paper {
  margin-top: 0 !important;
}
.quality-preview-wrap .quality-paper > .quality-paper-section,
.quality-preview-wrap .quality-paper > .quality-meta-grid,
.quality-preview-wrap .quality-paper > .quality-signature-grid {
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}
@media print {
  .quality-preview-wrap {
    display: block !important;
    gap: 0 !important;
  }
  .quality-preview-wrap .quality-paper + .quality-paper {
    page-break-before: always !important;
    break-before: page !important;
  }
}

@media screen and (max-width: 560px) {
  .invoice-preview {
    padding: 10px;
  }

  .invoice-preview .invoice-paper {
    padding-right: 12px;
    padding-left: 12px;
  }

  .invoice-paper-head {
    margin-right: -12px;
    margin-left: -12px;
  }

  .invoice-paper-brand .letterhead-logo-mark {
    flex-basis: 48px;
    width: 120px;
    height: 48px;
  }

  .invoice-paper-brand .letterhead-logo-mark img {
    top: -34px;
    right: -19px;
    width: 550px;
  }

  .invoice-paper-brand strong {
    font-size: 13px;
  }

  .invoice-paper-brand small,
  .invoice-document-title span {
    font-size: 9px;
  }

  .invoice-document-title h1 {
    font-size: 21px;
  }

  .invoice-paper-meta {
    gap: 5px;
  }

  .invoice-meta-row {
    gap: 5px;
    font-size: 10px;
  }

  .invoice-meta-row strong {
    font-size: 10px;
  }

  .invoice-party-section h2,
  .invoice-document-section-title {
    font-size: 13px;
  }

  .invoice-party-field {
    min-height: 42px;
    padding: 6px 7px;
  }

  .invoice-party-field span {
    font-size: 9px;
  }

  .invoice-party-field strong {
    font-size: 11px;
  }

  .invoice-paper-table th {
    padding: 7px 4px;
    font-size: 9px;
  }

  .invoice-paper-table td {
    padding: 8px 4px;
    font-size: 10px;
  }

  .invoice-paper-table .invoice-code-cell,
  .invoice-paper-table .invoice-description-cell,
  .invoice-amount-cell {
    font-size: 9px !important;
  }

  .invoice-unit-label {
    font-size: 8px;
  }

  .invoice-summary-grid {
    gap: 12px;
  }

  .invoice-total-line {
    font-size: 10px;
  }

  .invoice-total-line strong {
    font-size: 11px;
  }

  .invoice-paper-notes {
    font-size: 10px;
  }

  .invoice-paper-signature-band {
    grid-template-columns: 1fr;
  }

  .invoice-signature-box {
    min-height: 128px;
    border-left: 0;
    border-bottom: 1px solid #aebbc0;
  }

  .invoice-signature-box:last-child {
    border-bottom: 0;
  }

  .invoice-paper-footer {
    flex-direction: column;
    gap: 4px;
    font-size: 9px;
  }
}

@media print {
  .invoice-screen-only,
  .invoice-preview > .print-mode-note {
    display: none !important;
  }

  .invoice-preview {
    padding: 0;
    background: #fff;
  }

  .invoice-preview .invoice-paper {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0 0 6mm;
    border: 0;
    box-shadow: none;
  }

  .invoice-paper-head,
  .invoice-party-section,
  .invoice-document-section-title,
  .invoice-summary-grid,
  .invoice-paper-notes,
  .invoice-paper-signature-band {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .invoice-paper-table {
    table-layout: fixed;
  }

  .invoice-paper-table thead {
    display: table-header-group;
  }

  .invoice-paper-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .invoice-paper-table th {
    padding: 3mm 2mm;
    font-size: 9pt;
  }

  .invoice-paper-table td {
    padding: 3mm 2mm;
    font-size: 9.5pt;
  }

  .invoice-paper-table .invoice-code-cell,
  .invoice-amount-cell {
    font-size: 8.5pt !important;
  }

  .invoice-paper-table .invoice-description-cell {
    font-size: 9pt;
  }

  .invoice-party-field strong {
    font-size: 10pt;
  }

  .invoice-party-field span,
  .invoice-meta-row,
  .invoice-paper-notes,
  .invoice-total-line {
    font-size: 9pt;
  }

  .invoice-total-line strong {
    font-size: 10pt;
  }

  .invoice-paper-footer {
    font-size: 8.5pt;
  }
}

/* در پیش‌نمایش داخل مودال، سربرگ از زیر نوار عنوان پنهان نشود؛ چاپ همچنان در جای اصلی A4 می‌ماند. */
@media screen {
  .invoice-preview .invoice-native-logo,
  .receipt-preview-wrap .invoice-native-logo {
    top: 25mm;
  }
}

/* آخرین لایهٔ قطعی چاپ؛ این قواعد عمداً در انتهای فایل هستند تا override نشوند. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-letterhead {
    z-index: 3 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
    position: absolute !important;
    z-index: 4 !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    min-height: 7mm !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4mm !important;
    padding-top: 2mm !important;
    color: #43515a !important;
    border-top: .35mm solid #f15a24 !important;
    font-size: 7.5pt !important;
    line-height: 1.35 !important;
    white-space: nowrap !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span {
    display: block !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:first-child {
    flex: 1 1 auto !important;
    text-align: right !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:nth-child(2) {
    flex: 0 0 auto !important;
    text-align: center !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:last-child {
    flex: 0 0 auto !important;
    color: #f15a24 !important;
    font-weight: 800 !important;
    direction: ltr !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party {
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 3mm !important;
    padding: 2.5mm !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
    display: flex !important;
    min-width: 0 !important;
    min-height: 16mm !important;
    height: auto !important;
    padding: 2.5mm 3mm !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 1.2mm !important;
    overflow: visible !important;
    border: .35mm solid #b9c7cf !important;
    border-radius: 1.5mm !important;
    background: #fff !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span,
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    display: block !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
    color: #60717c !important;
    font-size: 9.5pt !important;
    line-height: 1.2 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    color: #162a35 !important;
    font-size: 12pt !important;
    line-height: 1.35 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    min-height: 44mm !important;
    margin-top: auto !important;
    padding-top: 4mm !important;
    align-items: flex-end !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 104mm !important;
    min-height: 42mm !important;
    margin: 0 auto 0 0 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    min-height: 32mm !important;
    gap: 7mm !important;
    margin-top: 2mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 50mm !important;
    height: 25mm !important;
    max-width: 50mm !important;
    max-height: 25mm !important;
    object-fit: contain !important;
    object-position: center !important;
    mix-blend-mode: multiply !important;
    filter: grayscale(1) contrast(1.35) brightness(1.04) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 30mm !important;
    height: 30mm !important;
    max-width: 30mm !important;
    max-height: 30mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    font-size: 10.5pt !important;
    line-height: 1.35 !important;
  }
}

/* تثبیت نهایی فوتر AFV، رشد خودکار توضیحات و مهر بزرگ‌تر. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
    font-size: 8pt !important;
    font-weight: 800 !important;
    font-variant-numeric: tabular-nums !important;
    letter-spacing: 0 !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-summary-notes,
  .invoice-preview .invoice-paper-notes {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    align-self: stretch !important;
  }

  .invoice-preview .invoice-summary-notes > div,
  .invoice-preview .invoice-paper-notes > div {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature {
    width: 132mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
    width: 132mm !important;
    min-height: 52mm !important;
    height: 52mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
    width: 52mm !important;
    height: 52mm !important;
    max-width: 52mm !important;
    max-height: 52mm !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-stamp-image {
    width: 50mm !important;
    height: 50mm !important;
    max-width: 100% !important;
    max-height: 50mm !important;
  }

  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-stamp-box img {
    width: 46mm !important;
    height: 46mm !important;
    max-width: 100% !important;
    max-height: 46mm !important;
  }
}

/* اصلاح نهایی جانمایی نامه: حاشیهٔ امن سربرگ، متادیتای بالا-چپ و امضای کنترل‌شده */
.letter-paper > .letter-meta,
.letter-paper.has-letterhead > .letter-meta {
  top: 9mm !important;
  left: 8mm !important;
  width: 52mm !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  text-align: left !important;
}
.letter-paper > .letter-meta > div { grid-template-columns: auto 1fr !important; gap: 4mm !important; }
.letter-paper > .letter-document {
  min-height: 245mm !important;
  padding: 49mm 25mm 40mm !important;
  box-sizing: border-box !important;
}
.letter-subject strong { font-weight: 900 !important; }
.letter-signature-area {
  width: 175px !important;
  margin-top: 16mm !important;
  margin-left: 0 !important;
  margin-right: auto !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}
.letter-signature-image {
  width: 125px !important;
  max-width: 125px !important;
  max-height: 34mm !important;
  object-fit: contain !important;
  margin: 0 auto -1px !important;
}
.letter-signature-area > strong { font-size: 10px !important; line-height: 1.35 !important; }
.letter-signature-area > span { font-size: 9px !important; line-height: 1.35 !important; }
.letter-stamp-image { width: 80px !important; height: 80px !important; }
.letter-output-toggles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media print {
  .letter-paper > .letter-document { padding: 49mm 25mm 40mm !important; }
  .letter-signature-area { margin-top: 16mm !important; }
  .letter-signature-image { width: 125px !important; max-width: 125px !important; }
}

/* آخرین قفل چاپ نامه؛ قواعد قدیمی A5 نباید روی نامهٔ عمودی اثر بگذارند. */
@media print {
  html:has(body.printing-letter) {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
  }
  body.printing-letter,
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    page: afv-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  body.printing-letter .letter-paper > .letter-meta,
  body.printing-letter .letter-paper.has-letterhead > .letter-meta {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
}

/* رسید چک: تاریخ درخواست در کادر درخواست‌کننده و فوتر یک درجه کوچک‌تر. */
@media screen, print {
  html body #modal-root .check-receipt-v3 .check-receipt-v3-request-date {
    margin-top: 3mm !important;
    color: #7f8b93 !important;
    font-size: 8px !important;
  }
html body #modal-root .check-receipt-v3 .check-receipt-v3-request-date-value {
    margin-top: 1mm !important;
    color: #17202b !important;
    font-size: 10px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-merged {
    width: 94% !important;
    min-height: 0 !important;
    margin: 0 auto 3mm !important;
    border: .3mm solid #d8e0e6 !important;
    border-radius: 2mm !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-merged > div {
    min-height: 16mm !important;
    padding: 2mm 3mm !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-merged > div + div {
    border-right: 0 !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-merged small {
    font-size: 8px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-merged strong {
    font-size: 11px !important;
  }
  html body #modal-root .check-receipt-print-wrap .invoice-native-footer,
  html body #modal-root .check-receipt-print-wrap .invoice-native-footer * {
    font-size: 7pt !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver {
    width: 94% !important;
    margin: 3mm auto 0 !important;
    padding: 2mm 3mm 2.5mm !important;
    border: .3mm solid #d8e0e6 !important;
    border-radius: 3mm !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver .check-receipt-v3-section-title {
    margin: 0 0 1.5mm !important;
    font-size: 10px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid {
    gap: 2mm 6mm !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid > div {
    padding: 1mm 0 .5mm !important;
    border-bottom: .2mm dotted #d8e0e6 !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid small {
    font-size: 8px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid span {
    min-height: 4mm !important;
  }
  .check-receipt-image-upload {
    margin: 0 0 4mm !important;
  }
  .check-receipt-image-upload .file-upload-control {
    min-height: 58px !important;
  }
  .check-receipt-existing-images {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    margin-top: 8px !important;
    color: #7f8b93 !important;
    font-size: 11px !important;
  }
  .check-receipt-existing-image {
    padding: 5px 8px !important;
    border: 1px solid #d8e0e6 !important;
    border-radius: 8px !important;
    color: #38566d !important;
    text-decoration: none !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-images {
    width: 94% !important;
    margin: 3mm auto 0 !important;
    padding: 2mm 3mm 3mm !important;
    border: .3mm solid #d8e0e6 !important;
    border-radius: 3mm !important;
    box-sizing: border-box !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-images .check-receipt-v3-section-title {
    margin: 0 0 1.5mm !important;
    font-size: 10px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-image-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 2.5mm !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-image-card {
    min-width: 0 !important;
    height: 34mm !important;
    margin: 0 !important;
    padding: 1.5mm !important;
    border: .2mm solid #e1e6ea !important;
    border-radius: 2mm !important;
    background: #fafbfc !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    text-align: center !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-image-card img {
    display: block !important;
    width: 100% !important;
    height: 28mm !important;
    object-fit: contain !important;
    object-position: center !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-image-card figcaption {
    margin-top: 1mm !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    color: #7f8b93 !important;
    font-size: 7px !important;
  }
  html body #modal-root .check-receipt-v3 .check-receipt-v3-images-empty {
    padding: 5mm 2mm !important;
    color: #9aa5ad !important;
    font-size: 9px !important;
    text-align: center !important;
  }
}

/* رسید تحویل: فوتر دقیقاً همان فوتر سربرگ پیش‌فاکتور باشد. */
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer {
  position: absolute !important;
  right: 13mm !important;
  bottom: 8mm !important;
  left: 13mm !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 4mm !important;
  width: auto !important;
  min-height: 7mm !important;
  box-sizing: border-box !important;
  padding-top: 2mm !important;
  color: #43515a !important;
  border-top: .35mm solid #f15a24 !important;
  font-size: 7.5pt !important;
  line-height: 1.35 !important;
  white-space: nowrap !important;
  direction: rtl !important;
}
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer > span {
  display: block !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer > span:first-child {
  flex: 1 1 auto !important;
  text-align: right !important;
}
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer > span:nth-child(2) {
  flex: 0 0 auto !important;
  text-align: center !important;
}
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer > span:last-child {
  flex: 0 0 auto !important;
  color: #f15a24 !important;
  font-weight: 800 !important;
  direction: ltr !important;
}
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-contacts,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone b,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax b,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone bdi,
.receipt-redesigned .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax bdi {
  direction: ltr !important;
  unicode-bidi: isolate !important;
  white-space: nowrap !important;
}

/* رسید تحویل A4 ثابت است؛ کنترل‌های اجزای چاپ و حالت چاپ عمداً در فرم نمایش داده نمی‌شوند. */
#receipt-form .receipt-fixed-options {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

/* فوتر مرجع نهایی AFV: وب‌سایت، تلفن و فکس در چپ؛ آدرس در راست. */
html body #modal-root .invoice-native-letterhead .invoice-native-footer {
  display: grid !important;
  grid-template-columns: max-content max-content max-content minmax(0, 1fr) !important;
  grid-template-rows: 1fr !important;
  align-items: center !important;
  justify-content: initial !important;
  gap: 0 7mm !important;
  right: 13mm !important;
  bottom: 8mm !important;
  left: 13mm !important;
  width: auto !important;
  min-height: 7mm !important;
  box-sizing: border-box !important;
  padding-top: 2mm !important;
  color: #43515a !important;
  border-top: .35mm solid #f15a24 !important;
  font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
  font-size: 8pt !important;
  font-weight: 800 !important;
  line-height: 1.35 !important;
  direction: ltr !important;
  white-space: nowrap !important;
}

/* Final attachment pagination lock: a page must have only one fragmentation
   rule. The previous cascade gave the document page an after-break and the
   attachment page a before-break at the same boundary, which produced a blank
   trailing page in Chrome print output. */
@media print {
  html body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page,
  html body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page {
    break-before: auto !important;
    page-break-before: auto !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  html body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page + .letter-paper.print-page,
  html body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page + .letter-paper.print-page {
    break-before: page !important;
    page-break-before: always !important;
  }

  html body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page-last,
  html body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  html body.printing-letter #modal-root .letter-preview-wrap .letter-attachment-pdf-canvas,
  html body.printing-letter-horizontal #modal-root .letter-preview-wrap .letter-attachment-pdf-canvas,
  html body.printing-letter #modal-root .letter-preview-wrap .letter-attachment-visual,
  html body.printing-letter-horizontal #modal-root .letter-preview-wrap .letter-attachment-visual {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
  }
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer > .invoice-footer-website {
  grid-column: 1 !important;
  grid-row: 1 !important;
  display: block !important;
  flex: none !important;
  color: #f15a24 !important;
  direction: ltr !important;
  text-align: left !important;
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer > .invoice-footer-contacts {
  grid-column: 2 / span 2 !important;
  grid-row: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  flex: none !important;
  gap: 7mm !important;
  color: #f15a24 !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax {
  display: inline-flex !important;
  align-items: center !important;
  flex: none !important;
  gap: 1.5mm !important;
  color: #f15a24 !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone b,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax b,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone bdi,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax bdi {
  color: #f15a24 !important;
  font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
  font-weight: 800 !important;
  direction: ltr !important;
  unicode-bidi: isolate !important;
  white-space: nowrap !important;
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer > .invoice-footer-address {
  grid-column: 4 !important;
  grid-row: 1 !important;
  display: block !important;
  flex: none !important;
  min-width: 0 !important;
  overflow: visible !important;
  color: #43515a !important;
  direction: rtl !important;
  text-align: right !important;
  unicode-bidi: plaintext !important;
  white-space: nowrap !important;
}

/* نسخهٔ سادهٔ رسید: اطلاعات در چهار سطر چپ، عنوان بالای پیش‌فاکتور مرتبط. */
.receipt-redesigned .receipt-redesign-head {
  grid-template-columns: 46mm minmax(0, 1fr) !important;
  align-items: start !important;
  direction: ltr !important;
}
.receipt-redesigned .receipt-redesign-head > div:first-child {
  min-width: 0 !important;
}
.receipt-redesigned .receipt-redesign-meta {
  grid-template-columns: 1fr !important;
  gap: 2.5mm !important;
  direction: rtl !important;
  text-align: right !important;
}
.receipt-redesigned .receipt-redesign-meta > div {
  display: grid !important;
  grid-template-columns: 17mm minmax(0, 1fr) !important;
  align-items: baseline !important;
  gap: 2mm !important;
}
.receipt-redesigned .receipt-redesign-meta small,
.receipt-redesigned .receipt-redesign-meta strong {
  display: block !important;
  margin: 0 !important;
}
.receipt-redesigned .receipt-redesign-title {
  align-self: start !important;
  padding-top: 0 !important;
}
.receipt-redesigned .receipt-redesign-title h1 {
  font-size: 23px !important;
}
.receipt-redesigned .receipt-redesign-related {
  width: 82% !important;
  min-height: 11mm !important;
  margin: 5mm auto 0 !important;
  padding: 2mm 4mm !important;
  border: 1px solid #d8e0e6 !important;
  border-radius: 2px !important;
  background: #fff !important;
  box-sizing: border-box !important;
}
.receipt-redesigned .receipt-redesign-items-section {
  width: 100% !important;
  margin: 4mm 0 0 !important;
  padding: 3mm 3mm 0 !important;
  border: 1px solid #d8e0e6 !important;
  background: #fff !important;
  box-sizing: border-box !important;
}
.receipt-redesigned .receipt-redesign-items-section .receipt-redesign-section-title {
  margin: 0 0 2mm !important;
  padding: 0 !important;
  font-size: 13px !important;
}
.receipt-redesigned .receipt-redesign-items {
  margin: 0 !important;
  border: 0 !important;
}
.receipt-redesigned .receipt-redesign-items th,
.receipt-redesigned .receipt-redesign-items td {
  border-left: 0 !important;
  border-right: 0 !important;
}
.receipt-redesigned .receipt-redesign-confirmation {
  margin-top: 6mm !important;
  border-color: #dce3e7 !important;
  border-style: dotted !important;
  color: #26343d !important;
}
.receipt-redesigned .receipt-confirmation-blank {
  display: inline-block !important;
  min-width: 28mm !important;
  height: 3.5mm !important;
  margin: 0 1mm !important;
  vertical-align: middle !important;
  border-bottom: .25mm dotted #cbd5da !important;
}
.receipt-redesigned .receipt-confirmation-blank-name { min-width: 34mm !important; }
.receipt-redesigned .receipt-confirmation-blank-national { min-width: 27mm !important; }
.receipt-redesigned .receipt-confirmation-blank-title { min-width: 29mm !important; }
.receipt-redesigned .receipt-redesign-signatures {
  display: none !important;
}

/* جدول رسید باید کاملاً بسته و هم‌عرض محدودهٔ محتوا باشد. */
.receipt-redesigned .receipt-redesign-items-section {
  width: 100% !important;
  margin-right: 0 !important;
  margin-left: 0 !important;
  padding: 3mm 0 0 !important;
  overflow: hidden !important;
}
.receipt-redesigned .receipt-redesign-items-section .receipt-redesign-section-title {
  padding: 0 3mm !important;
  text-align: center !important;
}
.receipt-redesigned .receipt-redesign-items {
  display: table !important;
  width: 100% !important;
  margin: 0 !important;
  border: 1px solid #d8e0e6 !important;
  border-collapse: collapse !important;
  table-layout: fixed !important;
}
.receipt-redesigned .receipt-redesign-items th,
.receipt-redesigned .receipt-redesign-items td {
  box-sizing: border-box !important;
  border: 1px solid #d8e0e6 !important;
}

/* در سربرگ فقط خط نارنجی عمودی باقی بماند. */
html body #modal-root .invoice-native-letterhead .invoice-native-side-rule {
  border-left: 0 !important;
}

/* رسید تحویل چک: قالب سادهٔ A4 با اطلاعات تحویل‌گیرنده در پایین جمع چک‌ها. */
html body #modal-root .check-receipt-v3-wrap {
  padding: 0 !important;
  background: #fff !important;
}
html body #modal-root .check-receipt-v3 {
  position: relative !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 0 24mm 14mm 14mm !important;
  margin: 0 auto !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  background: #fff !important;
  box-shadow: none !important;
  page: afv-a4-portrait !important;
}
html body #modal-root .check-receipt-v3 .invoice-native-side-rule {
  border-left: 0 !important;
}
html body #modal-root .check-receipt-v3-content {
  position: relative !important;
  z-index: 2 !important;
  width: 100% !important;
  min-height: 0 !important;
  padding: 34mm 0 24mm !important;
  box-sizing: border-box !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-paper-head {
  width: 100% !important;
  min-height: 23mm !important;
  margin: 0 0 5mm !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  text-align: center !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-title-block {
  margin: 0 !important;
  text-align: center !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-title-block h1 {
  margin: 0 !important;
  font-size: 22px !important;
  line-height: 1.35 !important;
  font-weight: 800 !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-title-block span {
  display: block !important;
  margin-top: 1mm !important;
  font-size: 9px !important;
}
html body #modal-root .check-receipt-v3-merged {
  display: grid !important;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) !important;
  width: 100% !important;
  margin: 0 0 5mm !important;
  border: 1px solid #d8e0e6 !important;
  background: #fff !important;
  box-sizing: border-box !important;
  direction: rtl !important;
}
html body #modal-root .check-receipt-v3-merged > div {
  min-width: 0 !important;
  min-height: 21mm !important;
  padding: 3mm 4mm !important;
  box-sizing: border-box !important;
  text-align: right !important;
}
html body #modal-root .check-receipt-v3-merged > div + div {
  border-right: 1px solid #d8e0e6 !important;
}
html body #modal-root .check-receipt-v3-merged small,
html body #modal-root .check-receipt-v3-merged strong {
  display: block !important;
}
html body #modal-root .check-receipt-v3-merged small {
  color: #7f8b93 !important;
  font-size: 9px !important;
}
html body #modal-root .check-receipt-v3-merged strong {
  margin-top: 1.5mm !important;
  color: #17202b !important;
  font-size: 12px !important;
}
html body #modal-root .check-receipt-v3-merged .check-receipt-v3-code-label {
  margin-top: 3mm !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-section-title {
  width: 100% !important;
  margin: 0 0 2.5mm !important;
  color: #17202b !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  text-align: center !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-table {
  display: table !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  border: 1px solid #d8e0e6 !important;
  border-collapse: collapse !important;
  table-layout: fixed !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-table th,
html body #modal-root .check-receipt-v3 .check-receipt-v3-table td {
  min-width: 0 !important;
  padding: 2mm 1.5mm !important;
  border: 1px solid #d8e0e6 !important;
  box-sizing: border-box !important;
  font-size: 9px !important;
  line-height: 1.4 !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  vertical-align: middle !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-total {
  width: 100% !important;
  margin: 4mm 0 0 !important;
  padding: 3mm 4mm !important;
  box-sizing: border-box !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver {
  width: 100% !important;
  margin: 5mm 0 0 !important;
  padding: 3mm 4mm 4mm !important;
  border: 1px solid #d8e0e6 !important;
  box-sizing: border-box !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 4mm 8mm !important;
  direction: rtl !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid > div {
  min-width: 0 !important;
  padding: 2mm 0 1mm !important;
  border-bottom: .25mm dotted #cbd5da !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid small {
  display: block !important;
  color: #7f8b93 !important;
  font-size: 9px !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-receiver-grid span {
  display: block !important;
  min-height: 6mm !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-v3-note {
  width: 100% !important;
  margin: 5mm 0 0 !important;
  padding: 3mm 4mm !important;
  box-sizing: border-box !important;
}
html body #modal-root .check-receipt-v3 .check-receipt-signatures,
html body #modal-root .check-receipt-v3 .check-receipt-footer,
html body #modal-root .check-receipt-v3 .document-relation {
  display: none !important;
}

/* تثبیت نهایی نامه: فقط یک لایهٔ سربرگ و حاشیهٔ امن A4 */
.letter-paper.has-letterhead {
  overflow: hidden !important;
}
.letter-paper.has-letterhead > .official-letterhead-image {
  height: 100% !important;
  object-fit: fill !important;
}
.letter-paper > .letter-document {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  max-width: 100%;
}
.letter-paper > .letter-meta {
  z-index: 2;
}

/* قفل نهایی چیدمان رسیدها پس از تمام لایه‌های قدیمی CSS. */
@page afv-receipt-a4-final { size: A4 portrait; margin: 0; }
@media screen, print {
  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    page: afv-receipt-a4-final !important;
    display: flex !important;
    flex-direction: column !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 0 24mm 14mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
    background: #fff !important;
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead > :not(.invoice-native-letterhead),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead > :not(.invoice-native-letterhead) {
    position: relative !important;
    z-index: 2 !important;
    flex: 0 0 auto !important;
    box-sizing: border-box !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-head,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-paper-head {
    flex: 0 0 auto !important;
    min-height: 24mm !important;
    margin: 0 0 3mm !important;
    padding: 34mm 0 2mm !important;
    border: 0 !important;
    background: transparent !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-meta-grid,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-party-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-meta,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-party,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-receiver-details,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-section-label,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-section-title {
    flex: 0 0 auto !important;
    width: 100% !important;
    margin-top: 0 !important;
    box-sizing: border-box !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td {
    min-width: 0 !important;
    padding: 1.6mm 1.2mm !important;
    font-size: 8.2pt !important;
    line-height: 1.25 !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-total-strip,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-note,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-confirmation,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-customer-ack,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-total,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-note {
    flex: 0 0 auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
    margin-bottom: 2mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    overflow-wrap: anywhere !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    flex: 0 0 38mm !important;
    min-height: 38mm !important;
    width: 100% !important;
    margin-top: auto !important;
    padding-top: 3mm !important;
    box-sizing: border-box !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-box,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-box {
    min-width: 0 !important;
    min-height: 34mm !important;
    padding: 2mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-footer,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-footer,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-screen-only {
    display: none !important;
  }
}

@media print {
  html,
  body,
  .modal-backdrop,
  .modal-card,
  .modal-body,
  .receipt-preview-wrap,
  .check-receipt-print-wrap,
  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    box-shadow: none !important;
    border: 0 !important;
    page: afv-receipt-a4-final !important;
  }
}

/* نسخه نهایی رسیدها: سربرگ مشترک با پیش‌فاکتور، عمودی و A4 ثابت. */
@page afv-receipt-a4 { size: A4 portrait; margin: 0; }

@media screen, print {
  .receipt-preview-wrap,
  .check-receipt-print-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    page: afv-receipt-a4 !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 24mm 14mm 14mm !important;
    background: #fff !important;
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead > :not(.invoice-native-letterhead),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead > :not(.invoice-native-letterhead) {
    position: relative !important;
    z-index: 2 !important;
    flex: 0 0 auto !important;
    box-sizing: border-box !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-head,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-paper-head {
    width: 100% !important;
    min-height: 24mm !important;
    margin: 0 0 3mm !important;
    padding: 34mm 0 2mm !important;
    border: 0 !important;
    background: transparent !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-title-block,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-title-block {
    margin: 0 !important;
    text-align: center !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-title-block h1,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-title-block h1 {
    margin: 1.5mm 0 !important;
    font-size: 17pt !important;
    line-height: 1.15 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-meta-grid,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-party-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-meta,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-party,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-receiver-details {
    width: 100% !important;
    margin: 0 0 3mm !important;
    gap: 2mm !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-meta-grid > div,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-party-grid > div,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-meta > div,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-party > div,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-receiver-grid > div {
    min-width: 0 !important;
    padding: 2mm !important;
    line-height: 1.35 !important;
    overflow-wrap: anywhere !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-section-label,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-section-title {
    width: 100% !important;
    margin: 1mm 0 2mm !important;
    line-height: 1.3 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 3mm !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td {
    min-width: 0 !important;
    padding: 1.8mm 1.4mm !important;
    font-size: 8.4pt !important;
    line-height: 1.3 !important;
    vertical-align: middle !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(1),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(1) { width: 8% !important; }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(2),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(2) { width: 17% !important; }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(3),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(3) { width: 31% !important; }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(4),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(4) { width: 13% !important; }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(5),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(5) { width: 11% !important; }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table th:nth-child(6),
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table td:nth-child(6) { width: 20% !important; }

  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(1),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(1) { width: 6% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(2),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(2) { width: 16% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(3),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(3) { width: 19% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(4),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(4) { width: 15% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(5),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(5) { width: 12% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(6),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(6) { width: 16% !important; }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table th:nth-child(7),
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table td:nth-child(7) { width: 16% !important; }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-total-strip,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-note,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-confirmation,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-customer-ack,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-total,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-note {
    width: 100% !important;
    margin: 0 0 3mm !important;
    padding: 2.5mm 3mm !important;
    box-sizing: border-box !important;
    line-height: 1.35 !important;
    overflow-wrap: anywhere !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-note p,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-confirmation p,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-note p {
    margin: 1mm 0 0 !important;
    font-size: 8.5pt !important;
    line-height: 1.4 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    width: 100% !important;
    min-height: 38mm !important;
    margin-top: auto !important;
    padding-top: 3mm !important;
    gap: 4mm !important;
    box-sizing: border-box !important;
    align-items: stretch !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-box,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-box {
    min-width: 0 !important;
    min-height: 34mm !important;
    padding: 2mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    text-align: center !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-image,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-image {
    width: 48mm !important;
    height: 22mm !important;
    max-width: 100% !important;
    max-height: 22mm !important;
    object-fit: contain !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-stamp-image,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-stamp-box img {
    width: 31mm !important;
    height: 31mm !important;
    max-width: 100% !important;
    max-height: 31mm !important;
    object-fit: contain !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-footer,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-footer,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-screen-only {
    display: none !important;
  }
}

@media print {
  html,
  body,
  .modal-backdrop,
  .modal-card,
  .modal-body,
  .receipt-preview-wrap,
  .check-receipt-print-wrap,
  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    box-shadow: none !important;
    border: 0 !important;
    page: afv-receipt-a4 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    z-index: 1 !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-table,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
  }

  .invoice-preview .invoice-paper.has-letterhead {
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
  }
}

/* نسخهٔ نهایی چاپ پیش‌فاکتور: فوتر رسمی، خریدار خوانا و مهر/امضای قابل تشخیص. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-letterhead {
    z-index: 3 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
    position: absolute !important;
    z-index: 4 !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    min-height: 7mm !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4mm !important;
    padding-top: 2mm !important;
    color: #43515a !important;
    border-top: .35mm solid #f15a24 !important;
    font-size: 7.5pt !important;
    line-height: 1.35 !important;
    white-space: nowrap !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span {
    display: block !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:first-child {
    flex: 1 1 auto !important;
    text-align: right !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:nth-child(2) {
    flex: 0 0 auto !important;
    text-align: center !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:last-child {
    flex: 0 0 auto !important;
    color: #f15a24 !important;
    font-weight: 800 !important;
    direction: ltr !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party {
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 3mm !important;
    padding: 2.5mm !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
    display: flex !important;
    min-width: 0 !important;
    min-height: 16mm !important;
    height: auto !important;
    padding: 2.5mm 3mm !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 1.2mm !important;
    overflow: visible !important;
    border: .35mm solid #b9c7cf !important;
    border-radius: 1.5mm !important;
    background: #fff !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field.full {
    min-height: 15mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span,
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    display: block !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
    color: #60717c !important;
    font-size: 9.5pt !important;
    line-height: 1.2 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    color: #162a35 !important;
    font-size: 12pt !important;
    line-height: 1.35 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    min-height: 44mm !important;
    margin-top: auto !important;
    padding-top: 4mm !important;
    align-items: flex-end !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 104mm !important;
    min-height: 42mm !important;
    margin: 0 auto 0 0 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span {
    font-size: 12pt !important;
    line-height: 1.25 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    min-height: 32mm !important;
    gap: 7mm !important;
    margin-top: 2mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 50mm !important;
    height: 25mm !important;
    max-width: 50mm !important;
    max-height: 25mm !important;
    object-fit: contain !important;
    object-position: center !important;
    mix-blend-mode: multiply !important;
    filter: grayscale(1) contrast(1.35) brightness(1.04) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 30mm !important;
    height: 30mm !important;
    max-width: 30mm !important;
    max-height: 30mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    font-size: 10.5pt !important;
    line-height: 1.35 !important;
  }
}

@media print {
  /* این فوتر، فوتر رسمی سند است؛ فوتر مرورگر (URL/تاریخ/ساعت) عمداً تولید نمی‌شود. */
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
  }

  .invoice-preview .invoice-preview,
  .invoice-preview .invoice-paper.has-letterhead {
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
  }
}

/* مرجع نهایی مشترک برای پیش‌نمایش و چاپ پیش‌فاکتور. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 16mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-head,
  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table,
  .invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    flex: 0 0 auto !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    margin-top: auto !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-signature-line {
    display: block !important;
    width: 34mm !important;
    height: 12mm !important;
    margin: 0 auto !important;
    border-bottom: .35mm solid #263b47 !important;
    box-sizing: border-box !important;
  }
}

/* قفل نهایی چاپ پیش‌فاکتور: یک صفحهٔ واقعی A4، بدون سرریز و بدون فوتر داخلی. */
@media print {
  @page { size: A4 portrait; margin: 0; }

  html,
  body {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  .modal-backdrop,
  .modal-card,
  .modal-body,
  .invoice-preview {
    position: static !important;
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    background: #fff !important;
  }

  .invoice-preview .print-mode-note,
  .invoice-preview .invoice-screen-only,
  .invoice-preview .invoice-paper-footer,
  .invoice-preview .invoice-native-footer {
    display: none !important;
  }

  .invoice-preview .invoice-paper,
  .invoice-preview .invoice-paper.has-letterhead {
    position: relative !important;
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    break-before: auto !important;
    break-after: auto !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 16mm 14mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper-signature-band {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* اصلاح نهایی خوانایی مشخصات خریدار و حذف خط خاکستری کنار لوگو. */
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-brand {
  display: none !important;
  visibility: hidden !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-section h2 {
  font-size: 12.5pt !important;
  padding: 3mm 3.5mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
  min-height: 14mm !important;
  padding: 2.8mm 3mm !important;
  gap: 1.2mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
  font-size: 9pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
  font-size: 11pt !important;
  line-height: 1.3 !important;
}

.invoice-preview .invoice-native-side-rule {
  border-left: 0 !important;
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-brand {
    display: none !important;
    visibility: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-side-rule {
    border-left: 0 !important;
  }
}

/* اصلاح نهایی بر اساس خروجی PF-1405-۰۲۳۹: سربرگ بالا و کادر خریدار خوانا و تفکیک‌شده. */
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
  align-self: start !important;
  margin-top: -10mm !important;
  transform: none !important;
  border-right: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-page-count {
  display: inline-block !important;
  min-width: 18mm;
  white-space: nowrap !important;
  text-align: left;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
  gap: 2mm !important;
  padding: 2mm !important;
  background: #fff !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
  min-height: 14mm !important;
  padding: 2.8mm 3mm !important;
  border: .35mm solid #c4d0d6 !important;
  border-radius: 1.5mm !important;
  background: #fff !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
  color: #60717c !important;
  font-size: 9.5pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
  color: #162a35 !important;
  font-size: 12pt !important;
  line-height: 1.35 !important;
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  text-overflow: clip !important;
}

.invoice-preview .invoice-native-side-rule {
  width: 0 !important;
  border-left: 0 !important;
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
    margin-top: -10mm !important;
    transform: none !important;
    border-right: 0 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
    gap: 2mm !important;
    padding: 2mm !important;
  }

  .invoice-preview .invoice-native-side-rule {
    width: 0 !important;
    border-left: 0 !important;
  }
}

/* یک منبع مشترک برای پیش‌نمایش و چاپ؛ سربرگ، خریدار، مهر و امضا در هر دو حالت یکسان‌اند. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 16mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-head,
  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table,
  .invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    flex: 0 0 auto !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    margin-top: auto !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-signature-line {
    display: block !important;
    width: 34mm !important;
    height: 12mm !important;
    margin: 0 auto !important;
    border-bottom: .35mm solid #263b47 !important;
    box-sizing: border-box !important;
  }
}

/* قفل نهایی آبشاری: این قوانین آخرین مرجع جانمایی پیش‌فاکتور هستند. */
.invoice-preview article.invoice-paper.has-letterhead,
.invoice-preview article.invoice-paper.invoice-paper-no-head {
  width: 210mm !important;
  min-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  padding: 0 !important;
  margin: 0 auto !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-content,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-content {
  display: block !important;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 34mm 25mm 18mm 14mm !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-head,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-head {
  display: grid !important;
  grid-template-columns: 48mm minmax(0, 1fr) 48mm !important;
  width: 100% !important;
  height: 24mm !important;
  min-height: 24mm !important;
  margin: 0 !important;
  padding: 0 0 3mm !important;
  gap: 4mm !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-parties-row,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-parties-row {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  margin: 3mm 0 0 !important;
  padding: 0 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-parties-row .invoice-party-section,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-parties-row .invoice-party-section {
  display: block !important;
  width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-party-grid,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-party-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  width: 100% !important;
  height: auto !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-party-field,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-party-field {
  display: flex !important;
  min-width: 0 !important;
  min-height: 8mm !important;
  height: 8mm !important;
  max-height: 8mm !important;
  padding: 1mm 1.8mm !important;
  gap: .5mm !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-party-field.full,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-party-field.full {
  grid-column: 1 / -1 !important;
  height: 8mm !important;
  max-height: 8mm !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-party-field span,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-party-field span {
  font-size: 7.2pt !important;
  line-height: 1.1 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-party-field strong,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-party-field strong {
  display: block !important;
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  font-size: 8.2pt !important;
  line-height: 1.1 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-document-section-title,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-document-section-title {
  width: 100% !important;
  height: 7mm !important;
  min-height: 7mm !important;
  margin: 4mm 0 0 !important;
  padding: 1.5mm 2mm !important;
  box-sizing: border-box !important;
  font-size: 9.5pt !important;
  line-height: 1.2 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-table,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-table {
  width: 100% !important;
  margin: 0 !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-table th,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-table th {
  height: 8mm !important;
  padding: 1.2mm 1.4mm !important;
  font-size: 8pt !important;
  line-height: 1.15 !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-table td,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-table td {
  height: 7mm !important;
  padding: 1mm 1.4mm !important;
  font-size: 8.3pt !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-table .invoice-description-cell,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-table .invoice-description-cell {
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-summary-grid,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-summary-grid {
  display: grid !important;
  grid-template-columns: 70mm minmax(0, 1fr) !important;
  align-items: start !important;
  width: 100% !important;
  height: auto !important;
  margin: 4mm 0 0 !important;
  gap: 6mm !important;
  direction: ltr !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-summary-side,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-summary-side {
  min-width: 0 !important;
  direction: rtl !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-notes,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-notes {
  height: 25mm !important;
  min-height: 25mm !important;
  max-height: 25mm !important;
  margin: 0 !important;
  padding: 2.5mm 3mm !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  font-size: 8pt !important;
  line-height: 1.5 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-total-line,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-total-line {
  min-height: 5mm !important;
  padding: 1mm 0 !important;
  font-size: 8pt !important;
  line-height: 1.1 !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-total-line strong,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-total-line strong {
  font-size: 8.5pt !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-signature-band,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-signature-band {
  display: flex !important;
  width: 100% !important;
  height: 30mm !important;
  min-height: 30mm !important;
  max-height: 30mm !important;
  margin: 6mm 0 0 !important;
  padding: 0 !important;
  justify-content: flex-start !important;
  align-items: flex-start !important;
  direction: ltr !important;
  border: 0 !important;
  background: transparent !important;
  box-sizing: border-box !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-seller-signature,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-seller-signature {
  width: 78mm !important;
  height: 30mm !important;
  min-height: 30mm !important;
  margin: 0 auto 0 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
  min-height: 17mm !important;
  height: 17mm !important;
  margin-top: 1mm !important;
  gap: 3mm !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-image {
  width: 32mm !important;
  max-height: 12mm !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
  width: 18mm !important;
  height: 18mm !important;
}

.invoice-preview article.invoice-paper.has-letterhead .invoice-paper-footer,
.invoice-preview article.invoice-paper.invoice-paper-no-head .invoice-paper-footer {
  display: none !important;
}

@media print {
  .invoice-preview article.invoice-paper.has-letterhead,
  .invoice-preview article.invoice-paper.invoice-paper-no-head {
    width: 210mm !important;
    min-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
  }
}

/*
 * چیدمان قطعی پیش‌فاکتور — یک جریان خطی واحد
 *
 * این بلوک عمداً آخر فایل است تا تنظیمات قدیمی چاپ، Flex/Wrap و مقادیر تکراری
 * روی قالب نهایی اثر نگذارند. خود سربرگ فقط لایهٔ تزئینی مطلق است و تمام محتوای
 * سند در یک جریان block عادی، از بالا به پایین، قرار می‌گیرد.
 */
.invoice-preview .invoice-paper,
.invoice-preview .invoice-paper.has-letterhead {
  position: relative !important;
  box-sizing: border-box !important;
  width: 210mm !important;
  min-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #fff !important;
  isolation: isolate !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-content,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-content {
  position: relative !important;
  z-index: 2 !important;
  display: block !important;
  width: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 0 !important;
  padding: 34mm 25mm 18mm 14mm !important;
  box-sizing: border-box !important;
  overflow: visible !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-head,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-head {
  display: grid !important;
  grid-template-columns: 48mm minmax(0, 1fr) 48mm !important;
  align-items: center !important;
  width: 100% !important;
  min-height: 24mm !important;
  height: 24mm !important;
  margin: 0 !important;
  padding: 0 0 3mm !important;
  border: 0 !important;
  box-sizing: border-box !important;
  direction: ltr !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-brand,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-brand {
  grid-column: 3 !important;
  grid-row: 1 !important;
  display: block !important;
  visibility: hidden !important;
  min-width: 0 !important;
  width: auto !important;
  height: 1px !important;
  padding: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-document-title {
  grid-column: 2 !important;
  grid-row: 1 !important;
  min-width: 0 !important;
  width: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  text-align: center !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title .invoice-basmalah,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-document-title .invoice-basmalah {
  display: block !important;
  margin: 0 0 1.5mm !important;
  font-size: 13pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title h1,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-document-title h1 {
  margin: 0 !important;
  font-size: 20pt !important;
  line-height: 1.15 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title > span,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-document-title > span {
  display: block !important;
  margin-top: 1mm !important;
  font-size: 8pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-meta {
  grid-column: 1 !important;
  grid-row: 1 !important;
  display: block !important;
  width: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  direction: rtl !important;
  text-align: right !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-meta-row {
  display: grid !important;
  grid-template-columns: 17mm minmax(0, 1fr) !important;
  align-items: baseline !important;
  gap: 2mm !important;
  min-height: 4.5mm !important;
  margin: 0 !important;
  font-size: 8.5pt !important;
  line-height: 1.25 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row strong,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-meta-row strong {
  font-size: 9pt !important;
  line-height: 1.25 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-parties-row,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-parties-row {
  display: block !important;
  width: 100% !important;
  margin: 3mm 0 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-parties-row .invoice-party-section,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-parties-row .invoice-party-section {
  display: block !important;
  width: 100% !important;
  margin: 0 !important;
  border: 0.25mm solid #6f7d84 !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-section h2,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-section h2 {
  height: 7mm !important;
  margin: 0 !important;
  padding: 1.5mm 2mm !important;
  box-sizing: border-box !important;
  font-size: 10pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-grid,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field {
  display: flex !important;
  min-width: 0 !important;
  min-height: 8mm !important;
  height: 8mm !important;
  justify-content: center !important;
  gap: 0.5mm !important;
  padding: 1mm 1.8mm !important;
  border-top: 0.2mm solid #cbd5da !important;
  border-right: 0.2mm solid #cbd5da !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field:nth-child(4n + 1),
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field:nth-child(4n + 1),
.invoice-preview .invoice-paper.has-letterhead .invoice-party-field.full,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field.full {
  border-right: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field.full,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field.full {
  grid-column: 1 / -1 !important;
  height: 8mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field span,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field span {
  font-size: 7.2pt !important;
  line-height: 1.1 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field strong,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-party-field strong {
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  font-size: 8.2pt !important;
  line-height: 1.15 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-section-title,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-document-section-title {
  width: 100% !important;
  height: 7mm !important;
  margin: 4mm 0 0 !important;
  padding: 1.5mm 2mm !important;
  box-sizing: border-box !important;
  font-size: 9.5pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-table {
  width: 100% !important;
  margin: 0 !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table th,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-table th {
  height: 8mm !important;
  padding: 1.2mm 1.4mm !important;
  font-size: 8pt !important;
  line-height: 1.15 !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table td,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-table td {
  height: 7mm !important;
  padding: 1mm 1.4mm !important;
  font-size: 8.3pt !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-description-cell,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-table .invoice-description-cell {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-unit-label,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-table .invoice-unit-label {
  display: inline !important;
  margin-right: 1mm !important;
  font-size: 7pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-summary-grid {
  display: grid !important;
  grid-template-columns: 70mm minmax(0, 1fr) !important;
  align-items: start !important;
  gap: 6mm !important;
  width: 100% !important;
  margin: 4mm 0 0 !important;
  direction: ltr !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-box,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-total-box {
  width: auto !important;
  margin: 0 !important;
  direction: rtl !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-line,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-total-line {
  min-height: 5mm !important;
  padding: 1mm 0 !important;
  font-size: 8pt !important;
  line-height: 1.1 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-line strong,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-total-line strong {
  font-size: 8.5pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-summary-side,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-summary-side {
  min-width: 0 !important;
  direction: rtl !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-notes,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-notes {
  min-height: 23mm !important;
  margin: 0 !important;
  padding: 2.5mm 3mm !important;
  font-size: 8pt !important;
  line-height: 1.55 !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-notes strong,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-notes strong {
  margin-bottom: 1mm !important;
  font-size: 9pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-signature-band {
  display: flex !important;
  width: 100% !important;
  min-height: 30mm !important;
  margin: 6mm 0 0 !important;
  padding: 0 !important;
  justify-content: flex-start !important;
  align-items: flex-start !important;
  direction: ltr !important;
  border: 0 !important;
  background: transparent !important;
  box-sizing: border-box !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature {
  width: 78mm !important;
  min-height: 30mm !important;
  margin: 0 auto 0 0 !important;
  padding: 0 !important;
  direction: rtl !important;
  text-align: center !important;
  border: 0 !important;
  background: transparent !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature > span {
  font-size: 9pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
  min-height: 17mm !important;
  gap: 3mm !important;
  margin-top: 1mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-image {
  width: 32mm !important;
  max-height: 12mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
  width: 18mm !important;
  height: 18mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-signature-assets .signature-name,
.invoice-preview .invoice-paper.has-letterhead .invoice-signature-assets .signature-title,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-signature-assets .signature-name,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-signature-assets .signature-title {
  font-size: 8pt !important;
  line-height: 1.2 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer,
.invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-footer {
  display: none !important;
}

@media print {
  .invoice-preview .invoice-paper,
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    min-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-content {
    display: block !important;
    padding: 34mm 25mm 18mm 14mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-head,
  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row,
  .invoice-preview .invoice-paper.has-letterhead .invoice-document-section-title,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table,
  .invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* بازطراحی نهایی پیش‌فاکتور: یک‌لایه، فشرده و بدون فضای تکراری سربرگ/بدنه. */
.invoice-preview .invoice-paper.has-letterhead {
  padding: 0 !important;
  background: #fff !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  min-height: 100%;
  padding: 19mm 22mm 17mm 13mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-head {
  display: grid;
  grid-template-columns: 43mm minmax(0, 1fr) 43mm;
  align-items: center;
  gap: 5mm;
  min-height: 28mm;
  height: auto;
  margin: 0 !important;
  padding: 0 0 3mm !important;
  border-bottom: .3mm solid #d8e0e6;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-brand {
  display: block;
  min-width: 0;
  grid-column: 3;
  grid-row: 1;
  visibility: hidden;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title {
  display: block !important;
  align-self: center;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  grid-column: 2;
  grid-row: 1;
  text-align: center;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title .invoice-basmalah {
  display: block;
  margin: 0 0 2mm !important;
  color: #1f2b33;
  font-size: 12pt !important;
  line-height: 1.25;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title h1 {
  margin: 0 !important;
  color: #101820;
  font-size: 20pt !important;
  line-height: 1.2;
  white-space: nowrap;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-title > span {
  display: block;
  margin-top: 1mm;
  font-size: 8pt;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
  grid-column: 1;
  grid-row: 1;
  justify-self: stretch;
  align-self: center;
  width: auto !important;
  margin: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row {
  min-height: 5.5mm;
  grid-template-columns: 16mm minmax(0, 1fr) !important;
  gap: 2mm !important;
  align-items: baseline;
  padding: 0 !important;
  font-size: 9.5pt !important;
  line-height: 1.25;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row strong {
  font-size: 9.5pt !important;
  white-space: nowrap;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-parties-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4mm;
  margin: 4mm 0 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-parties-row.is-single {
  grid-template-columns: minmax(0, 1fr) !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-section {
  min-width: 0;
  margin: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-section h2 {
  margin: 0 !important;
  padding: 2.5mm 3mm !important;
  font-size: 10.5pt !important;
  line-height: 1.2;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field {
  min-width: 0;
  min-height: 11mm !important;
  padding: 2mm 2.5mm !important;
  gap: 1mm;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field span {
  font-size: 7.5pt !important;
  line-height: 1.15;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-party-field strong {
  overflow: hidden;
  font-size: 9pt !important;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field.full strong {
  white-space: normal;
  line-height: 1.35;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-document-section-title {
  margin: 4mm 0 0 !important;
  padding: 2.5mm 3mm !important;
  font-size: 10.5pt !important;
  line-height: 1.2;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table {
  width: 100%;
  table-layout: fixed;
  margin: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table th {
  padding: 2mm 1.5mm !important;
  font-size: 8.5pt !important;
  line-height: 1.2;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table td {
  padding: 2.2mm 1.5mm !important;
  font-size: 9pt !important;
  line-height: 1.25;
  vertical-align: middle;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-description-cell {
  text-align: right;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-unit-label,
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-irr-secondary {
  font-size: 7.5pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid {
  display: grid;
  grid-template-columns: 67mm minmax(0, 1fr) !important;
  gap: 5mm !important;
  margin: 4mm 0 0 !important;
  align-items: start;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-box,
.invoice-preview .invoice-paper.has-letterhead .invoice-amount-words,
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-notes {
  margin: 0 !important;
  padding: 3mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-line {
  padding: 1.5mm 0 !important;
  font-size: 9pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-total-line strong {
  font-size: 10pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-notes {
  font-size: 8.5pt !important;
  line-height: 1.55;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
  min-height: 27mm !important;
  margin-top: auto !important;
  margin-bottom: 2mm !important;
  padding: 0 !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
  width: 72mm !important;
  min-height: 25mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span {
  font-size: 10pt !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
  min-height: 14mm;
  margin-top: 1mm;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
  max-height: 12mm !important;
}

.invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
  width: 17mm !important;
  height: 17mm !important;
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    padding: 19mm 22mm 17mm 13mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-head,
  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table,
  .invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* تراز نهایی متادیتای بالا و ترتیب چپ‌به‌راست شماره‌های فوتر. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
    width: 47mm !important;
    margin-top: -8mm !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row {
    display: grid !important;
    grid-template-columns: 17mm minmax(0, 1fr) !important;
    align-items: baseline !important;
    gap: 1.5mm !important;
    min-height: 5mm !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row span {
    white-space: nowrap !important;
    text-align: right !important;
    font-size: 8pt !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row strong {
    min-width: 0 !important;
    white-space: nowrap !important;
    text-align: left !important;
    unicode-bidi: isolate !important;
    font-size: 9pt !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
    margin-top: -8mm !important;
  }
}

/* اصلاح نهایی خروجی PDF: امضا واضح‌تر و فوتر با قالب ثابت شماره تلفن/فکس. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    width: 65mm !important;
    height: 32mm !important;
    max-width: 65mm !important;
    max-height: 32mm !important;
    object-fit: contain !important;
    object-position: center !important;
    image-rendering: auto !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.45) brightness(1.05) saturate(1.05) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line {
    display: block !important;
    width: 58mm !important;
    height: 18mm !important;
    margin: 0 auto !important;
    border-bottom: .6mm solid #263b47 !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    font-size: 11pt !important;
    line-height: 1.4 !important;
  }
}

/* قفل نهایی خروجی پیش‌فاکتور؛ بعد از این نقطه فقط قواعد چاپ A4 می‌آیند. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content { position: relative !important; display: block !important; height: 100% !important; min-height: 100% !important; max-height: 100% !important; padding: 34mm 24mm 49mm 14mm !important; box-sizing: border-box !important; overflow: hidden !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band { position: absolute !important; left: 14mm !important; bottom: 19mm !important; width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: block !important; z-index: 8 !important; direction: rtl !important; break-inside: avoid !important; page-break-inside: avoid !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature { width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: flex-start !important; border: 0 !important; background: transparent !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets { display: flex !important; align-items: center !important; justify-content: center !important; width: 100% !important; height: 29mm !important; min-height: 29mm !important; margin: 0 !important; gap: 5mm !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image { display: block !important; width: 50mm !important; height: 24mm !important; max-width: 50mm !important; max-height: 24mm !important; object-fit: contain !important; object-position: center !important; mix-blend-mode: multiply !important; filter: contrast(1.5) brightness(1.03) saturate(1.08) !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line { display: block !important; width: 50mm !important; height: 21mm !important; margin: 0 auto !important; border-bottom: .6mm solid #263b47 !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image { display: block !important; width: 28mm !important; height: 28mm !important; max-width: 28mm !important; max-height: 28mm !important; object-fit: contain !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title { display: block !important; margin: 0 !important; font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important; font-size: 10.5pt !important; line-height: 1.25 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer { display: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count { font-size: 10pt !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count::after { content: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-amount-cell { white-space: nowrap !important; direction: rtl !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer { display: grid !important; grid-template-columns: minmax(0, 1fr) auto auto !important; direction: ltr !important; align-items: center !important; gap: 4mm !important; text-align: left !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-address { direction: rtl !important; text-align: right !important; unicode-bidi: plaintext !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts { display: inline-flex !important; flex-direction: row !important; gap: 3mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; overflow: visible !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax { display: inline-flex !important; flex-direction: row !important; gap: 1mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b { direction: rtl !important; unicode-bidi: isolate !important; font-weight: 700 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-website { direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
}

@media print {
  @page { size: A4 portrait; margin: 0 !important; }

  html,
  body,
  .modal-backdrop,
  .modal-card,
  .modal-body,
  .invoice-preview,
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 49mm 14mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    position: absolute !important;
    left: 14mm !important;
    bottom: 18mm !important;
    width: 92mm !important;
    height: 43mm !important;
    min-height: 43mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: flex-end !important;
    justify-content: flex-start !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 92mm !important;
    height: 43mm !important;
    min-height: 43mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5mm !important;
    min-height: 30mm !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    width: 55mm !important;
    height: 27mm !important;
    max-width: 55mm !important;
    max-height: 27mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    width: 32mm !important;
    height: 32mm !important;
    max-width: 32mm !important;
    max-height: 32mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax {
    flex: 0 0 auto !important;
    text-align: left !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    display: inline-flex !important;
    flex-direction: row !important;
    gap: 3mm !important;
    direction: ltr !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax {
    display: inline-flex !important;
    flex-direction: row !important;
    gap: 1mm !important;
    direction: ltr !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b {
    flex: 0 0 auto !important;
    direction: rtl !important;
    unicode-bidi: isolate !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax {
    flex: 0 0 auto !important;
    text-align: left !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead {
    page-break-before: avoid !important;
    page-break-after: avoid !important;
    break-before: avoid-page !important;
    break-after: avoid-page !important;
  }
}

/* ریشهٔ صفحه هم با اندازهٔ سند چاپی هماهنگ می‌شود؛ مانع ایجاد صفحهٔ A4 اضافی برای A5 است. */
@media print {
  html:has(body.printing-letter),
  html:has(body.printing-check-receipt) {
    width: 148mm !important;
    min-width: 148mm !important;
    max-width: 148mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
  }
  html:has(body.printing-letter-horizontal),
  html:has(body.printing-check-receipt-a4) {
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
  }
  html:has(body.printing-check-receipt-a4) {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
  }
}

/* خروجی رسمی نامه و رسید تحویل چک؛ اندازه کاغذ از خود سند کنترل می‌شود. */
.letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
  page: afv-a5-portrait !important;
  width: 148mm !important;
  min-width: 148mm !important;
  max-width: 148mm !important;
  min-height: 210mm !important;
  height: 210mm !important;
  max-height: 210mm !important;
  box-sizing: border-box !important;
}

.letter-preview-wrap .letter-paper.letterhead-horizontal {
  page: afv-a4-landscape !important;
  width: 297mm !important;
  min-width: 297mm !important;
  max-width: 297mm !important;
  min-height: 210mm !important;
  height: 210mm !important;
  max-height: 210mm !important;
  box-sizing: border-box !important;
}

/* نام فایل پیوست همیشه زیر متن نامه و در یک بلوک خوانا نمایش داده می‌شود. */
.letter-preview-wrap .letter-attachment-detail {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box !important;
  margin: 7mm 0 0 !important;
  padding: 3mm 4mm !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}
.letter-preview-wrap .letter-attachment-detail ul {
  display: flex !important;
  flex-direction: column !important;
  gap: 1.5mm !important;
  margin: 2mm 0 0 !important;
  padding: 0 !important;
}
.letter-preview-wrap .letter-attachment-detail li {
  display: flex !important;
  align-items: baseline !important;
  justify-content: space-between !important;
  gap: 4mm !important;
  width: 100% !important;
  box-sizing: border-box !important;
  padding: 1.5mm 2mm !important;
}
.letter-preview-wrap .letter-attachment-detail li span {
  min-width: 0 !important;
  overflow-wrap: anywhere !important;
}
.letter-preview-wrap .letter-attachment-detail li small {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
}

/* رسید تحویل چک از همان اجزای سربرگ رسمی پیش‌فاکتور استفاده می‌کند. */
.check-receipt-print-wrap .check-receipt-paper {
  page: afv-a5-portrait !important;
  width: 148mm !important;
  min-width: 148mm !important;
  max-width: 148mm !important;
  min-height: 210mm !important;
  box-sizing: border-box !important;
}
.check-receipt-print-wrap .check-receipt-paper.check-receipt-size-a4 {
  page: afv-a4-portrait !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  min-height: 297mm !important;
  box-sizing: border-box !important;
}
.check-receipt-paper.has-letterhead .invoice-native-letterhead {
  position: absolute !important;
  inset: 0 !important;
  z-index: 0 !important;
  pointer-events: none !important;
}
.check-receipt-paper.has-letterhead .invoice-native-footer {
  display: grid !important;
  position: absolute !important;
  right: 8mm !important;
  bottom: 5mm !important;
  left: 8mm !important;
  z-index: 4 !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 4mm !important;
  width: auto !important;
  min-height: 7mm !important;
  box-sizing: border-box !important;
  padding-top: 2mm !important;
  border-top: .35mm solid #f15a24 !important;
  color: #43515a !important;
  font-size: 6.5pt !important;
  line-height: 1.35 !important;
  direction: rtl !important;
  white-space: nowrap !important;
}
.check-receipt-paper.check-receipt-size-a4.has-letterhead .invoice-native-footer {
  right: 13mm !important;
  bottom: 8mm !important;
  left: 13mm !important;
  font-size: 7.5pt !important;
}
.check-receipt-paper.has-letterhead .invoice-native-footer > * {
  min-width: 0 !important;
}
.check-receipt-paper.has-letterhead .check-receipt-paper-head,
.check-receipt-paper.has-letterhead .check-receipt-meta,
.check-receipt-paper.has-letterhead .check-receipt-party,
.check-receipt-paper.has-letterhead .document-relation,
.check-receipt-paper.has-letterhead .check-receipt-section-title,
.check-receipt-paper.has-letterhead .check-receipt-table,
.check-receipt-paper.has-letterhead .check-receipt-total,
.check-receipt-paper.has-letterhead .check-receipt-note,
.check-receipt-paper.has-letterhead .check-receipt-signatures {
  position: relative !important;
  z-index: 2 !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

@media print {
  /* این دو کلاس هنگام انتخاب «چاپ» روی body قرار می‌گیرند تا قواعد A4 عمومی به سند کوچک‌تر غلبه نکنند. */
  body.printing-letter,
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap {
    width: 148mm !important;
    min-width: 148mm !important;
    max-width: 148mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  body.printing-letter-horizontal,
  body.printing-letter-horizontal .modal-backdrop,
  body.printing-letter-horizontal .modal-card,
  body.printing-letter-horizontal .modal-body,
  body.printing-letter-horizontal .letter-preview,
  body.printing-letter-horizontal .letter-preview-wrap {
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    page: afv-a5-portrait !important;
    width: 148mm !important;
    min-width: 148mm !important;
    max-width: 148mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal {
    page: afv-a4-landscape !important;
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
  }
  body.printing-check-receipt,
  body.printing-check-receipt .modal-backdrop,
  body.printing-check-receipt .modal-card,
  body.printing-check-receipt .modal-body,
  body.printing-check-receipt .check-receipt-print-wrap {
    width: 148mm !important;
    min-width: 148mm !important;
    max-width: 148mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  body.printing-check-receipt-a4,
  body.printing-check-receipt-a4 .modal-backdrop,
  body.printing-check-receipt-a4 .modal-card,
  body.printing-check-receipt-a4 .modal-body,
  body.printing-check-receipt-a4 .check-receipt-print-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
  }
  body.printing-check-receipt .check-receipt-print-wrap .check-receipt-paper {
    page: afv-a5-portrait !important;
    width: 148mm !important;
    min-width: 148mm !important;
    max-width: 148mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    overflow: hidden !important;
  }
  body.printing-check-receipt-a4 .check-receipt-print-wrap .check-receipt-paper.check-receipt-size-a4 {
    page: afv-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
  }
  body.printing-letter .letter-preview-wrap .letter-attachment-detail {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* آخرین قفل خروجی PDF پیش‌فاکتور */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content { position: relative !important; display: block !important; height: 100% !important; min-height: 100% !important; max-height: 100% !important; padding: 34mm 24mm 49mm 14mm !important; box-sizing: border-box !important; overflow: hidden !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band { position: absolute !important; left: 14mm !important; bottom: 19mm !important; width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: block !important; z-index: 8 !important; direction: rtl !important; break-inside: avoid !important; page-break-inside: avoid !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature { width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: flex-start !important; border: 0 !important; background: transparent !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span { display: block !important; margin: 0 0 1mm !important; font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important; font-size: 11pt !important; line-height: 1.2 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets { display: flex !important; align-items: center !important; justify-content: center !important; width: 100% !important; height: 29mm !important; min-height: 29mm !important; margin: 0 !important; gap: 5mm !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image { display: block !important; width: 50mm !important; height: 24mm !important; max-width: 50mm !important; max-height: 24mm !important; object-fit: contain !important; object-position: center !important; mix-blend-mode: multiply !important; filter: contrast(1.5) brightness(1.03) saturate(1.08) !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line { display: block !important; width: 50mm !important; height: 21mm !important; margin: 0 auto !important; border-bottom: .6mm solid #263b47 !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image { display: block !important; width: 28mm !important; height: 28mm !important; max-width: 28mm !important; max-height: 28mm !important; object-fit: contain !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title { display: block !important; margin: 0 !important; font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important; font-size: 10.5pt !important; line-height: 1.25 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer { display: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count { font-size: 10pt !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count::after { content: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-amount-cell { white-space: nowrap !important; direction: rtl !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer { display: grid !important; grid-template-columns: minmax(0, 1fr) auto auto !important; direction: ltr !important; align-items: center !important; gap: 4mm !important; text-align: left !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-address { direction: rtl !important; text-align: right !important; unicode-bidi: plaintext !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts { display: inline-flex !important; flex-direction: row !important; gap: 3mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; overflow: visible !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax { display: inline-flex !important; flex-direction: row !important; gap: 1mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b { direction: rtl !important; unicode-bidi: isolate !important; font-weight: 700 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-website { direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
}
@media print {
  .invoice-preview .invoice-paper.has-letterhead { width: 210mm !important; height: 297mm !important; min-height: 297mm !important; max-height: 297mm !important; overflow: hidden !important; page-break-before: avoid !important; page-break-after: avoid !important; break-before: avoid-page !important; break-after: avoid-page !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content { padding: 34mm 24mm 49mm 14mm !important; overflow: hidden !important; }
}

/* قفل نهایی PDF پیش‌فاکتور؛ این بخش عمداً آخر فایل است تا روی همهٔ قواعد قبلی غالب باشد. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content { position: relative !important; display: block !important; height: 100% !important; min-height: 100% !important; max-height: 100% !important; padding: 34mm 24mm 49mm 14mm !important; box-sizing: border-box !important; overflow: hidden !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band { position: absolute !important; left: 14mm !important; right: auto !important; bottom: 19mm !important; width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: block !important; z-index: 8 !important; direction: rtl !important; break-inside: avoid !important; page-break-inside: avoid !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature { width: 88mm !important; height: 42mm !important; min-height: 42mm !important; margin: 0 !important; padding: 0 !important; display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: flex-start !important; border: 0 !important; background: transparent !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span { display: block !important; margin: 0 0 1mm !important; font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important; font-size: 11pt !important; line-height: 1.2 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets { display: flex !important; align-items: center !important; justify-content: center !important; width: 100% !important; height: 29mm !important; min-height: 29mm !important; margin: 0 !important; gap: 5mm !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image { display: block !important; width: 50mm !important; height: 24mm !important; max-width: 50mm !important; max-height: 24mm !important; object-fit: contain !important; object-position: center !important; mix-blend-mode: multiply !important; filter: contrast(1.5) brightness(1.03) saturate(1.08) !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line { display: block !important; width: 50mm !important; height: 21mm !important; margin: 0 auto !important; border-bottom: .6mm solid #263b47 !important; box-sizing: border-box !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image { display: block !important; width: 28mm !important; height: 28mm !important; max-width: 28mm !important; max-height: 28mm !important; object-fit: contain !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title { display: block !important; margin: 0 !important; font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important; font-size: 10.5pt !important; line-height: 1.25 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer { display: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count { font-size: 10pt !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count::after { content: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-amount-cell { white-space: nowrap !important; direction: rtl !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer { display: grid !important; grid-template-columns: minmax(0, 1fr) auto auto !important; direction: ltr !important; align-items: center !important; gap: 4mm !important; text-align: left !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-address { direction: rtl !important; text-align: right !important; unicode-bidi: plaintext !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts { display: inline-flex !important; flex-direction: row !important; gap: 3mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; overflow: visible !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax { display: inline-flex !important; flex-direction: row !important; gap: 1mm !important; direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b { direction: rtl !important; unicode-bidi: isolate !important; font-weight: 700 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-website { direction: ltr !important; unicode-bidi: isolate !important; white-space: nowrap !important; }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead { width: 210mm !important; height: 297mm !important; min-height: 297mm !important; max-height: 297mm !important; overflow: hidden !important; page-break-before: avoid !important; page-break-after: avoid !important; break-before: avoid-page !important; break-after: avoid-page !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content { padding: 34mm 24mm 49mm 14mm !important; overflow: hidden !important; }
}

/* نسخه نهایی خروجی پیش‌فاکتور: یک صفحه A4، اعداد هم‌واحد و امضا/مهر در پایین صفحه. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    position: relative !important;
    display: block !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 49mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    position: absolute !important;
    left: 14mm !important;
    right: auto !important;
    bottom: 19mm !important;
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    direction: rtl !important;
    z-index: 8 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    border: 0 !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span {
    display: block !important;
    margin: 0 0 1mm !important;
    font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important;
    font-size: 11pt !important;
    line-height: 1.2 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-height: 29mm !important;
    height: 29mm !important;
    margin: 0 !important;
    gap: 5mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-person {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    min-width: 48mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 50mm !important;
    height: 24mm !important;
    max-width: 50mm !important;
    max-height: 24mm !important;
    object-fit: contain !important;
    object-position: center !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.5) brightness(1.03) saturate(1.08) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line {
    display: block !important;
    width: 50mm !important;
    height: 21mm !important;
    margin: 0 auto !important;
    border-bottom: .6mm solid #263b47 !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 28mm !important;
    height: 28mm !important;
    max-width: 28mm !important;
    max-height: 28mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    display: block !important;
    margin: 0 !important;
    font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important;
    font-size: 10.5pt !important;
    line-height: 1.25 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer { display: none !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count { font-size: 10pt !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-page-count::after { content: none !important; }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-table .invoice-amount-cell {
    white-space: nowrap !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto auto !important;
    direction: ltr !important;
    align-items: center !important;
    gap: 4mm !important;
    text-align: left !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-address {
    direction: rtl !important;
    text-align: right !important;
    unicode-bidi: plaintext !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer > .invoice-footer-contacts {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 3mm !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 1mm !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b {
    direction: rtl !important;
    unicode-bidi: isolate !important;
    font-weight: 700 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-website {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
    break-before: avoid-page !important;
    break-after: avoid-page !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    padding: 34mm 24mm 49mm 14mm !important;
    overflow: hidden !important;
  }
}

/* سربرگ رسمی از همان فایل تصویری در پیش‌نمایش و چاپ استفاده می‌شود. */
.official-letterhead-image {
  position: absolute;
  inset: 0 0 auto;
  z-index: 0;
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  object-fit: contain;
  object-position: top center;
  pointer-events: none;
  user-select: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.invoice-paper.has-letterhead,
.receipt-paper.has-letterhead,
.check-receipt-paper.has-letterhead,
.letter-paper.has-letterhead {
  position: relative;
  isolation: isolate;
  overflow: visible;
  background-image: none !important;
  background-color: transparent !important;
}

.invoice-paper.has-letterhead {
  min-height: 297mm;
  padding-top: 38mm;
  padding-bottom: 30mm;
}

.receipt-paper.has-letterhead {
  min-height: 297mm;
  padding-top: 38mm;
  padding-bottom: 30mm;
}

.check-receipt-paper.has-letterhead {
  min-height: 210mm;
  padding-top: 28mm;
  padding-bottom: 19mm;
}

.invoice-paper.has-letterhead .invoice-paper-brand,
.receipt-paper.has-letterhead .receipt-paper-brand,
.check-receipt-paper.has-letterhead .check-receipt-paper-brand {
  display: none !important;
}

.invoice-paper.has-letterhead .invoice-paper-head {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  margin-right: 0;
  margin-left: 0;
  border: 0;
  background: transparent;
}

.invoice-paper.has-letterhead .invoice-paper-head,
.receipt-paper.has-letterhead .receipt-paper-head,
.check-receipt-paper.has-letterhead .check-receipt-paper-head {
  border-bottom-color: transparent;
  background: transparent;
}

.invoice-paper.has-letterhead .invoice-paper-head > *,
.receipt-paper.has-letterhead .receipt-paper-head > *,
.check-receipt-paper.has-letterhead .check-receipt-paper-head > *,
.invoice-paper.has-letterhead .invoice-party-section,
.invoice-paper.has-letterhead .invoice-document-section-title,
.invoice-paper.has-letterhead .invoice-paper-table,
.invoice-paper.has-letterhead .invoice-summary-grid,
.invoice-paper.has-letterhead .invoice-paper-notes,
.invoice-paper.has-letterhead .invoice-paper-signature-band,
.receipt-paper.has-letterhead .receipt-meta-grid,
.receipt-paper.has-letterhead .receipt-party-grid,
.receipt-paper.has-letterhead .receipt-section-label,
.receipt-paper.has-letterhead .receipt-items-table,
.receipt-paper.has-letterhead .receipt-total-strip,
.receipt-paper.has-letterhead .receipt-note,
.receipt-paper.has-letterhead .receipt-confirmation,
.receipt-paper.has-letterhead .receipt-signature-grid,
.check-receipt-paper.has-letterhead .check-receipt-meta,
.check-receipt-paper.has-letterhead .check-receipt-party,
.check-receipt-paper.has-letterhead .document-relation,
.check-receipt-paper.has-letterhead .check-receipt-section-title,
.check-receipt-paper.has-letterhead .check-receipt-table,
.check-receipt-paper.has-letterhead .check-receipt-total,
.check-receipt-paper.has-letterhead .check-receipt-note,
.check-receipt-paper.has-letterhead .check-receipt-signatures {
  position: relative;
  z-index: 1;
}

.invoice-paper.has-letterhead .invoice-paper-footer,
.receipt-paper.has-letterhead .receipt-paper-footer,
.check-receipt-paper.has-letterhead .check-receipt-footer {
  display: none !important;
}

.letter-paper.has-letterhead .letter-meta,
.letter-paper.has-letterhead .letter-document,
.letter-paper.has-letterhead .letter-print-page-footer {
  z-index: 1;
}

.letter-paper.has-letterhead .letter-document {
  position: relative;
}

/* جهت سربرگ برای همه خروجی‌های رسمی؛ نسخه افقی فضای بیشتری برای جدول و جلسه فراهم می‌کند. */
.invoice-paper.letterhead-horizontal,
.receipt-paper.letterhead-horizontal,
.check-receipt-paper.letterhead-horizontal {
  min-height: 210mm;
  padding-top: 30mm;
}
.invoice-paper.letterhead-horizontal .official-letterhead-image,
.receipt-paper.letterhead-horizontal .official-letterhead-image,
.check-receipt-paper.letterhead-horizontal .official-letterhead-image {
  height: 48mm;
  object-fit: cover;
  object-position: top center;
}
.invoice-paper.letterhead-horizontal .invoice-paper-head,
.receipt-paper.letterhead-horizontal .receipt-paper-head,
.check-receipt-paper.letterhead-horizontal .check-receipt-paper-head {
  min-height: 76px;
}

@media print {
  .invoice-paper.has-letterhead {
    min-height: 297mm;
    padding: 38mm 13mm 30mm !important;
  }

  .receipt-paper.has-letterhead {
    min-height: 297mm;
    padding: 38mm 13mm 30mm !important;
  }

  .check-receipt-paper.has-letterhead {
    min-height: 210mm;
    padding: 28mm 9mm 19mm !important;
  }

  .letter-paper.has-letterhead {
    min-height: 297mm;
    height: 297mm;
    background-image: none !important;
  }

  .letter-paper.has-letterhead .letter-meta {
    z-index: 1;
  }

  .invoice-paper.letterhead-horizontal,
  .receipt-paper.letterhead-horizontal {
    min-height: 210mm;
    padding: 30mm 13mm 20mm !important;
  }

  .check-receipt-paper.letterhead-horizontal {
    min-height: 180mm;
    padding: 25mm 9mm 15mm !important;
  }

  .invoice-paper.letterhead-horizontal .official-letterhead-image,
  .receipt-paper.letterhead-horizontal .official-letterhead-image,
  .check-receipt-paper.letterhead-horizontal .official-letterhead-image {
    height: 48mm;
  }
}

/* کد بایگانی در جدول متراکم ولی خوانا باقی بماند. */
.archive-code-cell strong {
  color: var(--orange);
  font-family: Tahoma, "Vazirmatn", sans-serif;
  font-size: 10px;
  white-space: nowrap;
}

/* فرم‌های ISO کنترل کیفیت و گزارش فنی */
.quality-preview-wrap,
.technical-preview-wrap { padding: 24px; background: #f3f6f8; }
.quality-paper,
.technical-paper { position: relative; isolation: isolate; width: min(100%, 794px); min-height: 1123px; margin: 0 auto; padding: 42px 48px 86px; overflow: visible; color: #20282e; background: #fff; box-shadow: 0 8px 25px #1b293722; font-family: 'BNazanin','B Nazanin','Vazirmatn',Tahoma,sans-serif; }
.quality-paper.has-letterhead,
.technical-paper.has-letterhead { padding-top: 38mm; background: transparent; }
.quality-paper-no-head,
.technical-paper-no-head { padding-top: 31px; }
.quality-paper-head,
.technical-paper-head { position: relative; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 5px 0 18px; border-bottom: 2px solid var(--orange); }
.quality-paper-head small,
.technical-paper-head small { color: #d95420; font-family: 'Vazirmatn',sans-serif; font-size: 9px; font-weight: 800; letter-spacing: .7px; }
.quality-paper-head h1,
.technical-paper-head h1 { margin: 3px 0 0; color: var(--ink); font-size: 25px; line-height: 1.45; }
.quality-paper-head span,
.technical-paper-head span { display: block; margin-top: 2px; color: #9ba6ae; font-size: 11px; }
.quality-paper-code,
.technical-paper-code { min-width: 142px; padding: 9px 11px; border: 1px solid #f0d7c9; border-radius: 8px; background: #fffaf7; text-align: left; direction: ltr; }
.quality-paper-code strong,
.technical-paper-code strong { display: block; color: #c45d30; font-family: Tahoma,Arial,sans-serif; font-size: 14px; }
.quality-paper-code small,
.technical-paper-code small { display: block; margin-top: 5px; color: #9a8377; font-size: 9px; letter-spacing: 0; text-align: right; direction: rtl; }
.quality-meta-grid,
.technical-meta-grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin: 17px 0 13px; padding: 11px; border: 1px solid #e2e9ed; border-radius: 8px; background: #fbfcfd; }
.quality-meta-grid > div,
.technical-meta-grid > div { min-width: 0; padding: 6px 7px; border-right: 2px solid #f0cdb9; }
.quality-meta-grid small,
.technical-meta-grid small { display: block; color: #9aa6b0; font-size: 9px; }
.quality-meta-grid strong,
.technical-meta-grid strong { display: block; margin-top: 3px; overflow: hidden; color: var(--ink); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.quality-paper-section,
.technical-paper-section { position: relative; z-index: 1; margin-top: 15px; padding: 11px 12px; border: 1px solid #e5ebee; border-radius: 8px; background: #fff; break-inside: avoid; page-break-inside: avoid; }
.quality-paper-section h3,
.technical-paper-section h3 { margin: 0 0 7px; color: var(--ink); font-size: 13px; }
.quality-paper-text,
.technical-paper-text,
.technical-parameters { color: #687780; font-size: 11px; line-height: 2; }
.quality-paper-text p,
.technical-paper-text p,
.technical-parameters p { margin: 0; }
.quality-result-grid { display: grid; grid-template-columns: 160px minmax(0,1fr); gap: 12px; }
.quality-result-grid small,
.quality-result-grid p { display: block; margin: 0; color: #7a8992; font-size: 10px; line-height: 1.9; }
.quality-result-grid strong { display: block; margin-top: 4px; color: var(--ink); font-size: 12px; }
.quality-two-column { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; border: 0; padding: 0; background: transparent; }
.quality-two-column > div { padding: 11px 12px; border: 1px solid #e5ebee; border-radius: 8px; background: #fff; }
.quality-attachment-block ul,
.technical-attachment-block ul { display: flex; flex-direction: column; gap: 5px; margin: 0; padding: 0; list-style: none; }
.quality-attachment-block li,
.technical-attachment-block li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px; border-radius: 6px; background: #f8fafb; color: #61727d; font-size: 10px; }
.quality-attachment-block li small,
.technical-attachment-block li small { color: #9aa6ae; white-space: nowrap; }
.technical-result-strip { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin-top: 15px; padding: 11px 12px; border-right: 3px solid var(--orange); border-radius: 7px; background: #fffaf7; break-inside: avoid; page-break-inside: avoid; }
.technical-result-strip small,
.technical-result-strip strong { display: block; }
.technical-result-strip small { color: #9a8377; font-size: 9px; }
.technical-result-strip strong { margin-top: 4px; color: var(--ink); font-size: 12px; }
.quality-signature-grid,
.technical-signature-grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin-top: 22px; break-inside: avoid; page-break-inside: avoid; }
.quality-signature-box,
.technical-signature-box { min-height: 105px; padding: 10px; border: 1px dashed #ced8df; border-radius: 7px; color: #8b98a1; font-size: 10px; text-align: center; }
.quality-signature-box > span,
.technical-signature-box > span { display: block; color: #697984; font-weight: 700; }
.quality-signature-box > strong,
.technical-signature-box > strong { display: block; margin-top: 5px; color: #526371; font-size: 11px; }
.quality-signature-box > small,
.technical-signature-box > small { display: block; margin-top: 2px; color: #9aa6ae; font-size: 9px; }
.quality-signature-image,
.technical-signature-image { display: block; width: 125px; max-width: 100%; height: 42px; margin: 4px auto 0; object-fit: contain; mix-blend-mode: multiply; }
.quality-signature-line,
.technical-signature-line { width: 100px; margin: 31px auto 8px; border-bottom: 1px solid #4b5962; color: #9aa4aa; font-size: 9px; }
.quality-signature-disabled { display: block; margin-top: 31px; color: #a0aab1; font-size: 9px; }
.quality-stamp-box,
.technical-stamp-box { border-color: #f2bda6; background: #fffaf7; }
.quality-stamp-image,
.technical-stamp-image { display: block; width: 66px; height: 66px; margin: 8px auto 0; object-fit: contain; }
.quality-paper-footer,
.technical-paper-footer { position: absolute; right: 48px; bottom: 29px; left: 48px; display: flex; justify-content: space-between; padding-top: 8px; border-top: 1px solid #e7ecef; color: #a0aab1; font-family: 'Vazirmatn',sans-serif; font-size: 9px; direction: ltr; }
.quality-paper-footer span:last-child,
.technical-paper-footer span:last-child { direction: rtl; }
.quality-screen-only,
.technical-screen-only { margin: 0 24px 10px; }
.quality-paper.letterhead-horizontal,
.technical-paper.letterhead-horizontal { padding-top: 31mm; }
.quality-paper.letterhead-horizontal .official-letterhead-image,
.technical-paper.letterhead-horizontal .official-letterhead-image { height: 54mm; object-fit: cover; object-position: top center; }
@media print {
  .quality-preview-wrap,
  .technical-preview-wrap { padding: 0; background: #fff; }
  .quality-paper,
  .technical-paper { width: 210mm; min-height: 297mm; padding: 11mm 13mm 22mm; box-shadow: none; }
  .quality-paper.has-letterhead,
  .technical-paper.has-letterhead { padding: 38mm 13mm 22mm !important; }
  .quality-paper.letterhead-horizontal,
  .technical-paper.letterhead-horizontal { padding-top: 31mm !important; }
  .quality-paper.letterhead-horizontal .official-letterhead-image,
  .technical-paper.letterhead-horizontal .official-letterhead-image { height: 54mm; }
  .quality-paper-footer,
  .technical-paper-footer { right: 13mm; bottom: 8mm; left: 13mm; font-size: 9pt; }
  .quality-paper-section,
  .technical-paper-section,
  .quality-signature-grid,
  .technical-signature-grid { break-inside: avoid; page-break-inside: avoid; }
}
@media(max-width:820px) {
  .quality-preview-wrap,
  .technical-preview-wrap { padding: 12px; }
  .quality-paper,
  .technical-paper { padding: 31px 28px 70px; }
  .quality-paper.has-letterhead,
  .technical-paper.has-letterhead { padding-top: 32mm; }
  .quality-meta-grid,
  .technical-meta-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media(max-width:560px) {
  .quality-paper,
  .technical-paper { width: 100%; min-height: calc(100vw * 1.414); padding: 6vw 5vw 15vw; }
  .quality-paper.has-letterhead,
  .technical-paper.has-letterhead { padding-top: 28vw; }
  .quality-paper-head,
  .technical-paper-head { gap: 10px; }
  .quality-paper-head h1,
  .technical-paper-head h1 { font-size: 18px; }
  .quality-paper-code,
  .technical-paper-code { min-width: 100px; padding: 6px; }
  .quality-paper-code strong,
  .technical-paper-code strong { font-size: 10px; }
  .quality-meta-grid,
  .technical-meta-grid,
  .quality-two-column,
  .quality-result-grid,
  .technical-result-strip,
  .quality-signature-grid,
  .technical-signature-grid { grid-template-columns: 1fr; }
  .quality-paper-footer,
  .technical-paper-footer { right: 5vw; bottom: 4vw; left: 5vw; font-size: 7px; }
}

/* نامه افقی و صفحات پیوست: هر صفحه با همان سربرگ رسمی و شماره‌گذاری چاپ می‌شود. */
.letter-paper.letterhead-horizontal {
  width: min(100%, 1123px);
  min-height: 794px;
  padding-top: 30mm;
}
.letter-paper.letterhead-horizontal .official-letterhead-image {
  height: 48mm;
  object-fit: cover;
  object-position: top center;
}
.letter-paper.letterhead-horizontal .letter-document {
  min-height: 575px;
  padding: 88px 78px 72px;
}
.letter-paper.letterhead-horizontal .letter-recipient { margin-top: 28px; }
.letter-paper.letterhead-horizontal .letter-body-content { line-height: 2.15; }
.letter-attachment-page-body {
  position: relative;
  z-index: 1;
  min-height: 905px;
  padding: 170px 88px 120px;
  color: #26323a;
}
.letter-attachment-kicker {
  display: inline-block;
  padding: 4px 9px;
  color: #c85a2e;
  border-radius: 6px;
  background: #fff0e9;
  font-family: 'Vazirmatn', sans-serif;
  font-size: 10px;
  font-weight: 800;
}
.letter-attachment-page-body h1 {
  margin: 18px 0 28px;
  color: #182530;
  font-family: 'BTitr','BNazanin','B Nazanin',sans-serif;
  font-size: 25px;
}
.letter-attachment-page-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 560px;
  padding: 18px 20px;
  border: 1px solid #e4d5ce;
  border-right: 3px solid var(--orange);
  border-radius: 10px;
  background: #fffaf7;
  font-family: 'BNazanin','B Nazanin',Tahoma,sans-serif;
}
.letter-attachment-page-card strong { color: #a84e2b; font-size: 13px; }
.letter-attachment-page-card span { color: #26323a; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.letter-attachment-page-card small { color: #7e8d96; font-size: 11px; }
.letter-attachment-open { align-self: flex-start; color: #3775c8; font-size: 10px; font-weight: 700; text-decoration: none; }
.letter-attachment-page-body > p {
  max-width: 620px;
  margin-top: 25px;
  color: #687985;
  font-family: 'BNazanin','B Nazanin',Tahoma,sans-serif;
  font-size: 13px;
  line-height: 2;
}
.letter-paper.letterhead-horizontal .letter-attachment-page-body {
  min-height: 575px;
  padding: 92px 78px 72px;
}

@page letter-horizontal { size: A4 landscape; margin: 0; }
@media print {
  .letter-paper.letterhead-horizontal {
    page: letter-horizontal;
    width: 297mm;
    min-height: 210mm;
    height: 210mm;
    padding: 30mm 13mm 20mm !important;
  }
  .letter-paper.letterhead-horizontal .official-letterhead-image { height: 48mm; }
  .letter-paper.letterhead-horizontal .letter-document {
    min-height: 145mm;
    padding: 21mm 18mm 16mm;
  }
  .letter-paper.letterhead-horizontal .letter-attachment-page-body {
    min-height: 145mm;
    padding: 35mm 18mm 16mm;
  }
  .letter-attachment-page-body {
    min-height: 257mm;
    padding: 45mm 18mm 20mm;
  }
  .letter-paper.letter-attachment-page { page-break-after: always; }
  .letter-paper.letter-attachment-page:last-child { page-break-after: auto; }
  .letter-attachment-open { display: none; }
}

.workflow-next-description {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8ec;
  color: #6f7f89;
  font-size: 8px;
  line-height: 1.9;
  white-space: pre-line;
}

/* چاپ رسمی پیش‌فاکتور: فقط خود سند روی صفحه A4 چاپ شود. */
.invoice-preview .invoice-paper {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  max-width: 100%;
  overflow: hidden;
  isolation: isolate;
}

.invoice-preview .invoice-paper > *:not(.official-letterhead-image) {
  position: relative;
  z-index: 1;
}

.invoice-preview .official-letterhead-image {
  z-index: 0;
  height: 100%;
  object-fit: fill;
}

.invoice-approval-panel,
.delivery-readiness-panel {
  margin-right: 19px;
  margin-left: 19px;
}

.bom-link-choice .check-card {
  transition: .16s ease;
}

.bom-link-choice .check-card.is-selected {
  color: #d95420;
  border-color: #f3a17f;
  background: #fff0e9;
  box-shadow: 0 0 0 2px #f26c3214;
}

#bom-request-form .form-field.is-disabled {
  opacity: .66;
}

#bom-request-form select[name="customerId"]:disabled {
  cursor: not-allowed;
  color: #98a4ad;
  background: #f1f4f6;
}

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    min-width: 210mm;
    margin: 0 !important;
    background: #fff !important;
  }

  .invoice-approval-panel,
  .delivery-readiness-panel,
  .invoice-screen-only,
  .invoice-preview > .print-mode-note,
  .invoice-preview > .document-relation,
  .invoice-preview > .form-note {
    display: none !important;
  }

  .modal-backdrop {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    padding: 0 !important;
    background: #fff !important;
  }

  .modal-card,
  .modal-card.wide {
    width: 210mm !important;
    max-width: none !important;
    max-height: none !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .modal-header,
  .modal-footer {
    display: none !important;
  }

  .invoice-preview {
    width: 210mm;
    padding: 0 !important;
    background: #fff !important;
  }

  .invoice-preview .invoice-paper {
    width: 210mm;
    max-width: none;
    min-height: 297mm;
    margin: 0;
    padding: 12mm 13mm 18mm;
    overflow: visible;
    border: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .invoice-preview .invoice-paper:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .invoice-preview .invoice-paper.has-letterhead {
    min-height: 297mm;
    padding: 38mm 13mm 22mm !important;
  }

  .invoice-preview .invoice-paper.letterhead-horizontal {
    min-height: 210mm;
    padding: 30mm 13mm 16mm !important;
  }

  .invoice-preview .official-letterhead-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
  }

  .invoice-paper-head,
  .invoice-party-section,
  .invoice-document-section-title,
  .invoice-paper-table,
  .invoice-summary-grid,
  .invoice-paper-notes,
  .invoice-paper-signature-band {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .invoice-paper-table thead {
    display: table-header-group;
  }

  .invoice-paper-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* نسخه نهایی پیش‌فاکتور: قالب یکدست، فشرده و آمادهٔ چاپ رسمی A4 */
.invoice-preview .invoice-paper,
.invoice-preview .invoice-paper * {
  font-family: "BNazanin", "Vazirmatn", Tahoma, sans-serif !important;
}
.invoice-preview .invoice-paper {
  color: #1f2b33;
  font-variant-numeric: proportional-nums;
}
.invoice-preview .invoice-document-title small {
  direction: rtl;
  letter-spacing: 0;
  font-size: 10px;
  font-weight: 700;
}
.invoice-preview .invoice-document-title h1 {
  font-size: 22px;
}
.invoice-preview .invoice-meta-row {
  gap: 8px;
  font-size: 10px;
}
.invoice-preview .invoice-meta-row strong {
  font-size: 11px;
}
.invoice-preview .invoice-party-section {
  margin-top: 11px;
}
.invoice-preview .invoice-party-section h2 {
  padding: 6px 8px;
  font-size: 12px;
}
.invoice-preview .invoice-party-field {
  min-height: 35px;
  gap: 1px;
  padding: 5px 8px;
}
.invoice-preview .invoice-party-field span {
  font-size: 9px;
}
.invoice-preview .invoice-party-field strong {
  font-size: 10.5px;
  line-height: 1.45;
}
.invoice-preview .invoice-document-section-title {
  margin-top: 12px;
  padding: 7px 9px;
  font-size: 13px;
}
.invoice-preview .invoice-paper-table th {
  padding: 7px 6px;
  font-size: 10.5px;
  line-height: 1.45;
}
.invoice-preview .invoice-paper-table td {
  padding: 8px 6px;
  font-size: 11px;
  line-height: 1.55;
}
.invoice-preview .invoice-paper-table .invoice-code-cell,
.invoice-preview .invoice-paper-table .invoice-amount-cell {
  font-size: 10.5px !important;
}
.invoice-preview .invoice-summary-grid {
  gap: 12px;
  margin-top: 11px;
}
.invoice-preview .invoice-amount-words,
.invoice-preview .invoice-total-box {
  padding: 9px 11px;
}
.invoice-preview .invoice-paper-notes {
  margin-top: 11px;
  padding: 9px 11px;
  font-size: 10px;
  line-height: 1.75;
}
.invoice-preview .invoice-paper-notes strong {
  font-size: 11px;
}
.invoice-preview .invoice-paper-footer {
  font-size: 9px;
}

@page invoice-portrait { size: A4 portrait; margin: 0; }
@page invoice-landscape { size: A4 landscape; margin: 0; }
@counter-style persian-digits {
  system: numeric;
  symbols: "۰" "۱" "۲" "۳" "۴" "۵" "۶" "۷" "۸" "۹";
  suffix: "";
}

@media print {
  html,
  body {
    width: auto !important;
    min-width: 0 !important;
  }
  .invoice-preview.invoice-orientation-vertical {
    page: invoice-portrait;
    width: 210mm !important;
  }
  .invoice-preview.invoice-orientation-horizontal {
    page: invoice-landscape;
    width: 297mm !important;
  }
  .invoice-preview.invoice-orientation-horizontal .invoice-paper {
    min-height: 210mm;
  }
  .invoice-preview .invoice-paper {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
  }
  .invoice-preview .invoice-paper.has-letterhead .official-letterhead-image {
    position: fixed !important;
    top: 0;
    right: auto;
    bottom: auto;
    left: 0;
    width: 210mm !important;
    height: 297mm !important;
    max-width: none !important;
    object-fit: fill !important;
  }
  .invoice-preview.invoice-orientation-horizontal .invoice-paper.has-letterhead .official-letterhead-image {
    width: 297mm !important;
    height: 210mm !important;
  }
  .invoice-preview .invoice-page-count {
    font-size: 0 !important;
  }
  .invoice-preview .invoice-page-count::after {
    content: "صفحه " counter(page, persian-digits) " از " counter(pages, persian-digits);
    font-size: 11px;
  }
}

/* چیدمان فشرده برای نسخهٔ یک‌صفحه‌ای و خوانایی بیشتر جدول کالا */
.invoice-preview .compact-party .invoice-party-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.invoice-preview .compact-party .invoice-party-field {
  min-height: 31px;
  border-right: 1px solid #cbd5da;
}
.invoice-preview .compact-party .invoice-party-field:first-child {
  border-right: 0;
}
.invoice-preview .compact-party .invoice-party-field strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-preview .invoice-summary-grid {
  grid-template-columns: minmax(245px, .48fr) minmax(0, 1fr);
  direction: ltr;
  align-items: start;
  gap: 12px;
}
.invoice-preview .invoice-total-box,
.invoice-preview .invoice-summary-side {
  direction: rtl;
}
.invoice-preview .invoice-summary-side {
  min-width: 0;
}
.invoice-preview .invoice-summary-side .invoice-amount-words {
  min-height: 0;
}
.invoice-preview .invoice-summary-notes {
  margin-top: 8px;
}
.invoice-preview .invoice-paper-table th {
  white-space: normal;
}
.invoice-preview .invoice-paper-table td {
  overflow-wrap: anywhere;
}
.invoice-preview .invoice-irr-secondary {
  display: block;
  margin-top: 1px;
  color: #8b999f;
  font-size: 8.5px;
  font-family: "BNazanin", "Vazirmatn", Tahoma, sans-serif !important;
}

@media print {
  .invoice-preview .compact-party .invoice-party-field {
    min-height: 28px;
    padding-top: 3px;
    padding-bottom: 3px;
  }
  .invoice-preview .invoice-paper-table th {
    padding-top: 5px;
    padding-bottom: 5px;
  }
  .invoice-preview .invoice-paper-table td {
    padding-top: 5px;
    padding-bottom: 5px;
  }
  .invoice-preview .invoice-summary-grid {
    gap: 9px;
    margin-top: 8px;
  }
  .invoice-preview .invoice-summary-notes {
    margin-top: 6px;
  }
}

/* آخرین تنظیم چاپ: محتوای سند نباید روی خطوط و نشانه‌های سربرگ قرار بگیرد. */
.invoice-preview .invoice-paper-content {
  position: relative;
  z-index: 1;
}

@media print {
  .invoice-preview .invoice-paper {
    box-sizing: border-box;
  }

  .invoice-preview .invoice-paper.has-letterhead {
    /* خط عمودی سربرگ در حاشیهٔ راست قرار دارد؛ این حاشیه فضای امن محتواست. */
    padding: 38mm 25mm 21mm 13mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer {
    display: none !important;
  }

  /* خروجی پیش‌فاکتور فقط به تعداد صفحات واقعی چاپ شود؛ صفحهٔ سفید انتهایی تولید نشود. */
  .invoice-preview .invoice-paper,
  .invoice-preview .invoice-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}

/* سربرگ پیش‌فاکتور به‌صورت اجزای مستقل؛ بدون قرار دادن تصویر کامل سربرگ روی سند. */
.invoice-native-letterhead {
  position: absolute !important;
  inset: 0 !important;
  z-index: 0;
  pointer-events: none;
  direction: rtl;
}
.invoice-native-logo {
  position: absolute;
  top: 8mm;
  right: 13mm;
  width: 39mm;
  color: #1f2b33;
  text-align: center;
}
.invoice-native-logo img {
  display: block;
  width: 30mm;
  height: auto;
  margin: 0 auto 1mm;
  object-fit: contain;
}
.invoice-native-logo strong,
.invoice-native-logo small {
  display: block;
  line-height: 1.35;
}
.invoice-native-logo strong {
  color: #3b4348;
  font-size: 10pt;
}
.invoice-native-logo small {
  color: #e9511d;
  font-size: 7.5pt;
}
.invoice-native-side-rule {
  position: absolute;
  top: 34mm;
  right: 14mm;
  bottom: 31mm;
  width: 11mm;
  border-right: .35mm solid #f15a24;
  border-left: .2mm solid #d8e0e6;
}
.invoice-native-side-rule i {
  position: absolute;
  top: 0;
  right: -1.25mm;
  width: 2.5mm;
  height: 2.5mm;
  border-radius: 50%;
  background: #f15a24;
}
.invoice-native-footer {
  position: absolute;
  right: 13mm;
  bottom: 8mm;
  left: 13mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4mm;
  padding-top: 2mm;
  color: #43515a;
  border-top: .35mm solid #f15a24;
  font-size: 7.5pt;
  line-height: 1.35;
  white-space: nowrap;
}
.invoice-native-footer span:first-child {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-native-footer span:last-child {
  color: #f15a24;
  font-weight: 800;
}

.invoice-preview .invoice-paper.has-letterhead .official-letterhead-image {
  display: none !important;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-head {
  display: grid;
  grid-template-columns: minmax(42mm, 1fr) auto minmax(42mm, 1fr);
  align-items: end;
  gap: 4mm;
  min-height: 34mm;
  padding-bottom: 5mm;
  border-bottom: 0;
  direction: ltr;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-brand {
  display: block;
  grid-column: 3;
  grid-row: 1;
  visibility: hidden;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-document-title {
  grid-column: 2;
  grid-row: 1;
  min-width: 56mm;
  direction: rtl;
  text-align: center;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-document-title .invoice-basmalah {
  display: block;
  margin-bottom: 2mm;
  color: #1f2b33;
  font-size: 16pt;
  font-weight: 500;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-document-title h1 {
  margin: 0;
  color: #101820;
  font-size: 22pt;
  line-height: 1.2;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-document-title > span {
  display: block;
  margin-top: 1.5mm;
  color: #8c99a3;
  font-size: 8.5pt;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  width: 48mm;
  direction: rtl;
  text-align: right;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row {
  grid-template-columns: 18mm 1fr;
  gap: 2mm;
  justify-content: start;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row span {
  color: #7e8b94;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-meta-row strong {
  color: #17242c;
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead {
    padding: 38mm 25mm 31mm 13mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    width: 100%;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-paper-head,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-document-section-title,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-paper-table,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-summary-grid,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-paper-signature-band,
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-paper-footer {
    flex: 0 0 100%;
    width: 100%;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-party-section {
    display: block !important;
    flex: 0 0 calc(50% - 2mm);
    width: auto !important;
    box-sizing: border-box;
    margin-top: 5mm;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-party {
    margin-left: 4mm !important;
    margin-right: 0 !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-document-section-title {
    clear: both;
    margin-top: 5mm;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    margin-top: 6mm;
  }
}

/* اصلاحات نهایی طبق نمونهٔ رسمی شرکت */
.invoice-preview .invoice-total-box {
  margin-top: 6px;
}
.invoice-preview .invoice-total-line {
  min-height: 0;
  padding: 3px 0;
  line-height: 1.25;
}
.invoice-preview .invoice-paper-signature-band {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  border: 0 !important;
  background: transparent;
}
.invoice-preview .invoice-seller-signature {
  width: 72mm;
  min-height: 46mm;
  padding: 0 3mm 0 0;
  border: 0 !important;
  background: transparent !important;
  text-align: center;
}
.invoice-preview .invoice-seller-signature > span {
  color: #263b47;
  font-size: 12px;
  font-weight: 800;
}
.invoice-preview .invoice-seller-signature .invoice-signature-assets {
  gap: 4mm;
  margin-top: 5mm;
}
.invoice-preview .invoice-seller-signature .invoice-signature-image {
  width: 37mm !important;
  max-height: 18mm;
  object-fit: contain;
}
.invoice-preview .invoice-seller-signature .invoice-stamp-image {
  width: 22mm;
  height: 22mm;
}
.invoice-preview .invoice-seller-signature .signature-name,
.invoice-preview .invoice-seller-signature .signature-title {
  font-size: 10px;
}
.invoice-preview .invoice-summary-single {
  grid-template-columns: minmax(0, 1fr);
}
.invoice-preview .invoice-summary-single .invoice-summary-side {
  grid-column: 1;
}
.invoice-output-toggles {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 6px;
}

/* مشخصات فروشنده و خریدار باید در چاپ دو کادر مستقل و خوانا داشته باشند. */
.invoice-preview .invoice-parties-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4mm;
  width: 100%;
  margin-top: 5mm;
  box-sizing: border-box;
}
.invoice-preview .invoice-parties-row.is-single {
  grid-template-columns: minmax(0, 1fr);
}
.invoice-preview .invoice-parties-row .invoice-party-section {
  min-width: 0;
  width: auto !important;
  margin: 0 !important;
  box-sizing: border-box;
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content > .invoice-parties-row {
    flex: 0 0 100%;
    width: 100%;
    box-sizing: border-box;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4mm;
    margin-top: 4mm;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-total-box {
    margin-top: 3mm;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-total-line {
    padding-top: 1.5mm;
    padding-bottom: 1.5mm;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    min-height: 35mm;
  }
}

/* طراحی پایهٔ جدید اسناد: A4 برای پیش‌فاکتور/رسید کالا و A5 برای سایر فرم‌ها. */
@page afv-a4-portrait { size: A4 portrait; margin: 0; }
@page afv-a4-landscape { size: A4 landscape; margin: 0; }
@page afv-a5-portrait { size: A5 portrait; margin: 0; }

.invoice-preview .invoice-paper,
.receipt-preview-wrap .receipt-paper {
  page: afv-a4-portrait;
}
.invoice-preview.invoice-orientation-horizontal .invoice-paper,
.receipt-preview-wrap .receipt-paper.letterhead-horizontal {
  page: afv-a4-landscape;
}
.letter-preview-wrap .letter-paper,
.check-receipt-print-wrap .check-receipt-paper,
.quality-preview-wrap .quality-paper,
.technical-preview-wrap .technical-paper {
  page: afv-a5-portrait;
}

/* تمام متن چاپی از یک خانوادهٔ فارسی استفاده می‌کند. */
.invoice-preview .invoice-paper,
.invoice-preview .invoice-paper *,
.receipt-preview-wrap .receipt-paper,
.receipt-preview-wrap .receipt-paper * {
  font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important;
}

/* سربرگ فقط از المان‌های رسمی لوگو، خط نارنجی و پابرگ ساخته می‌شود. */
.invoice-preview .invoice-paper.has-letterhead,
.receipt-preview-wrap .receipt-paper.has-letterhead {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  box-sizing: border-box;
  overflow: hidden;
  background: #fff;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-content,
.receipt-preview-wrap .receipt-paper.has-letterhead > :not(.invoice-native-letterhead) {
  position: relative;
  z-index: 2;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  box-sizing: border-box;
  padding: 34mm 24mm 23mm 14mm;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-head {
  flex: 0 0 auto;
  min-height: 34mm;
  margin: 0;
  padding: 0 0 5mm;
  border-bottom: 0;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-parties-row {
  flex: 0 0 auto;
  margin-top: 4mm;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-document-section-title {
  flex: 0 0 auto;
  margin-top: 5mm;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-table {
  flex: 0 0 auto;
  margin-top: 0;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-summary-grid {
  flex: 0 0 auto;
}
.invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 4mm;
}

/* کادر امضای کارشناس و مهر در آخرین بخش و سمت چپ صفحه قرار می‌گیرد. */
.invoice-preview .invoice-paper-signature-band {
  display: flex !important;
  justify-content: flex-start !important;
  align-items: flex-end;
  width: 100%;
  min-height: 38mm;
  direction: ltr;
  border: 0 !important;
  background: transparent !important;
}
.invoice-preview .invoice-seller-signature {
  width: 82mm !important;
  min-height: 34mm !important;
  margin: 0 auto 0 0 !important;
  padding: 0 !important;
  direction: rtl;
  border: 0 !important;
  background: transparent !important;
  text-align: center;
}
.invoice-preview .invoice-seller-signature > span {
  display: block;
  color: #263b47;
  font-size: 12pt;
  font-weight: 800;
}
.invoice-preview .invoice-seller-signature .invoice-signature-assets {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20mm;
  gap: 5mm;
  margin-top: 2mm;
}
.invoice-preview .invoice-seller-signature .invoice-signature-image {
  width: 38mm !important;
  max-height: 16mm !important;
  object-fit: contain;
}
.invoice-preview .invoice-seller-signature .invoice-stamp-image {
  width: 21mm !important;
  height: 21mm !important;
  object-fit: contain;
}
.invoice-preview .invoice-seller-signature .signature-name,
.invoice-preview .invoice-seller-signature .signature-title {
  display: block;
  font-size: 10pt;
  line-height: 1.35;
}

/* رسید کالا همان شبکهٔ رسمی را در A4 استفاده می‌کند. */
.receipt-preview-wrap {
  padding: 0;
  background: #fff;
}
.receipt-preview-wrap .receipt-paper.has-letterhead {
  padding: 0 14mm 0 14mm;
}
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-head,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-meta-grid,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-party-grid,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-section-label,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-items-table,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-total-strip,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-note,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-confirmation,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-footer {
  position: relative;
  z-index: 2;
}
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-head {
  margin: 0 0 4mm;
  padding-top: 34mm;
  border-bottom: 0;
}
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-meta-grid {
  margin-top: 0;
}
.receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid {
  margin-top: 8mm;
}

/* کنترل‌های چاپ در فرم صدور/ویرایش. */
.invoice-output-toggles,
.receipt-output-toggles {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}
.invoice-output-toggles .check-card,
.receipt-output-toggles .check-card {
  min-height: 38px;
  font-size: 9px;
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { margin: 0 !important; background: #fff !important; }
  .invoice-preview .invoice-paper.has-letterhead,
  .receipt-preview-wrap .receipt-paper.has-letterhead {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-shadow: none !important;
    page-break-after: auto !important;
    break-after: auto !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    min-height: 240mm;
    padding: 34mm 24mm 23mm 14mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-footer,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-footer {
    display: none !important;
  }
  .invoice-preview .invoice-paper-signature-band,
  .receipt-preview-wrap .receipt-signature-grid,
  .invoice-preview .invoice-paper-table,
  .receipt-preview-wrap .receipt-items-table,
  .receipt-preview-wrap .receipt-note,
  .receipt-preview-wrap .receipt-confirmation {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .letter-paper,
  .check-receipt-paper,
  .quality-paper,
  .technical-paper {
    width: 148mm !important;
    min-height: 210mm !important;
    height: 210mm !important;
    max-height: 210mm !important;
    box-sizing: border-box !important;
    page-break-after: auto !important;
    break-after: auto !important;
    overflow: hidden !important;
  }
  .letter-preview-wrap,
  .check-receipt-print-wrap,
  .quality-preview-wrap,
  .technical-preview-wrap {
    width: 148mm !important;
    padding: 0 !important;
    background: #fff !important;
  }
}

@media screen {
  .invoice-preview .invoice-native-logo,
  .receipt-preview-wrap .invoice-native-logo {
    top: 25mm;
  }
}

/* قفل نهایی واقعی: این لایه آخرین قواعد فایل است. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-letterhead { z-index: 3 !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
    position: absolute !important;
    z-index: 4 !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    min-height: 7mm !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4mm !important;
    padding-top: 2mm !important;
    color: #43515a !important;
    border-top: .35mm solid #f15a24 !important;
    font-size: 7.5pt !important;
    line-height: 1.35 !important;
    white-space: nowrap !important;
    direction: rtl !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span {
    display: block !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:first-child {
    flex: 1 1 auto !important;
    text-align: right !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:nth-child(2) {
    flex: 0 0 auto !important;
    text-align: center !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer span:last-child {
    flex: 0 0 auto !important;
    color: #f15a24 !important;
    font-weight: 800 !important;
    direction: ltr !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party { overflow: visible !important; }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 3mm !important;
    padding: 2.5mm !important;
    overflow: visible !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
    display: flex !important;
    min-width: 0 !important;
    min-height: 16mm !important;
    height: auto !important;
    padding: 2.5mm 3mm !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 1.2mm !important;
    overflow: visible !important;
    border: .35mm solid #b9c7cf !important;
    border-radius: 1.5mm !important;
    background: #fff !important;
    box-sizing: border-box !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span,
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    display: block !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
    color: #60717c !important;
    font-size: 9.5pt !important;
    line-height: 1.2 !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    color: #162a35 !important;
    font-size: 12pt !important;
    line-height: 1.35 !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    min-height: 44mm !important;
    margin-top: auto !important;
    padding-top: 4mm !important;
    align-items: flex-end !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 104mm !important;
    min-height: 42mm !important;
    margin: 0 auto 0 0 !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    min-height: 32mm !important;
    gap: 7mm !important;
    margin-top: 2mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 50mm !important;
    height: 25mm !important;
    max-width: 50mm !important;
    max-height: 25mm !important;
    object-fit: contain !important;
    object-position: center !important;
    mix-blend-mode: multiply !important;
    filter: grayscale(1) contrast(1.35) brightness(1.04) !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 30mm !important;
    height: 30mm !important;
    max-width: 30mm !important;
    max-height: 30mm !important;
    object-fit: contain !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    font-size: 10.5pt !important;
    line-height: 1.35 !important;
  }
}

/* قالب نهایی نامه: A4 واقعی، گیرندهٔ خطی و بدون کادرهای اضافی */
.letter-preview-wrap .letter-paper {
  page: afv-a4-portrait !important;
  width: 210mm !important;
  max-width: 100% !important;
  min-width: 0 !important;
  min-height: 297mm !important;
  height: 297mm !important;
  max-height: none !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}
.letter-preview-wrap {
  width: 100% !important;
  max-width: 210mm !important;
  margin: 0 auto !important;
  padding: 12px !important;
  box-sizing: border-box !important;
  overflow-x: auto !important;
}
.letter-paper > .letter-meta,
.letter-paper.has-letterhead > .letter-meta {
  top: 12mm !important;
  left: 12mm !important;
  width: 47mm !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
.letter-paper > .letter-meta > div { grid-template-columns: auto 1fr !important; gap: 5mm !important; }
.letter-recipient { margin-top: 15mm !important; }
.letter-recipient-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.4mm;
  width: 100%;
  margin: 0;
  padding: 0;
  color: #111;
  font-family: 'BNazanin','B Nazanin',Tahoma,sans-serif;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
  text-align: right;
}
.letter-recipient-stack > div { margin: 0; padding: 0; border: 0; background: transparent; }
.letter-subject { margin-top: 7mm !important; }
@media print {
  @page afv-a4-portrait { size: A4 portrait; margin: 0; }
  .letter-preview-wrap { width: 210mm !important; max-width: 210mm !important; padding: 0 !important; overflow: visible !important; }
  .letter-preview-wrap .letter-paper {
    page: afv-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    min-height: 297mm !important;
    height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  .letter-paper > .letter-meta,
  .letter-paper.has-letterhead > .letter-meta { border: 0 !important; background: transparent !important; }
  .letter-recipient-stack { gap: 1.4mm; }
}
@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer { display: flex !important; }
  .invoice-preview .invoice-paper.has-letterhead {
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
  }
}

/* چیدمان نهایی اطلاعات خریدار: عنوان و مقدار در یک ردیف، با شکست امن متن بلند. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
    flex-direction: row !important;
    align-items: baseline !important;
    justify-content: flex-start !important;
    gap: 2mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    text-align: right !important;
  }
}

/* نسخهٔ فشردهٔ قطعی خریدار: بدون فکس، با کادرهای کوتاه‌تر و چاپ پایدار در A4. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-grid {
    gap: 1.5mm !important;
    padding: 1.5mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field {
    min-height: 10.5mm !important;
    padding: 1.7mm 2mm !important;
    gap: 1.2mm !important;
    border-radius: 1mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field.full {
    min-height: 10mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field span {
    font-size: 8pt !important;
    line-height: 1.15 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party .invoice-party-field strong {
    font-size: 9.5pt !important;
    line-height: 1.2 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-buyer-party h2 {
    padding: 2mm 2.5mm !important;
    font-size: 10.5pt !important;
    line-height: 1.2 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-parties-row {
    margin-top: 2.5mm !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    padding-bottom: 14mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    min-height: 40mm !important;
    padding-top: 2mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    min-height: 38mm !important;
  }
}

/* آخرین تراز چاپ؛ فوتر و متادیتا بعد از تمام overrideهای قبلی اعمال می‌شوند. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
    width: 47mm !important;
    margin-top: -8mm !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row {
    display: grid !important;
    grid-template-columns: 17mm minmax(0, 1fr) !important;
    align-items: baseline !important;
    gap: 1.5mm !important;
    min-height: 5mm !important;
    direction: rtl !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row span {
    white-space: nowrap !important;
    text-align: right !important;
    font-size: 8pt !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-meta-row strong {
    min-width: 0 !important;
    white-space: nowrap !important;
    text-align: left !important;
    unicode-bidi: isolate !important;
    font-size: 9pt !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-meta {
    margin-top: -8mm !important;
  }
}

/* آخرین قفل واقعی چاپ PDF؛ این بلوک بعد از همهٔ قواعد قبلی قرار دارد. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    width: 65mm !important;
    height: 32mm !important;
    max-width: 65mm !important;
    max-height: 32mm !important;
    object-fit: contain !important;
    object-position: center !important;
    image-rendering: auto !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.45) brightness(1.05) saturate(1.05) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line {
    display: block !important;
    width: 58mm !important;
    height: 18mm !important;
    margin: 0 auto !important;
    border-bottom: .6mm solid #263b47 !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title {
    font-size: 11pt !important;
    line-height: 1.4 !important;
  }
}

@media print {
  @page { size: A4 portrait; margin: 0 !important; }

  html,
  body,
  .modal-backdrop,
  .modal-card,
  .modal-body,
  .invoice-preview,
  .invoice-preview .invoice-paper.has-letterhead {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 49mm 14mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    margin-top: 0 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead {
    page-break-before: avoid !important;
    page-break-after: avoid !important;
    break-before: avoid-page !important;
    break-after: avoid-page !important;
  }
}

/* آخرین اصلاح پیش‌فاکتور: امضا/مهر نسبت به خود برگه ثابت است، نه نسبت به جدول مبالغ. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead {
    position: relative !important;
    overflow: hidden !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    position: static !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    position: absolute !important;
    right: auto !important;
    left: 14mm !important;
    bottom: 22mm !important;
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    z-index: 12 !important;
    direction: rtl !important;
    background: transparent !important;
    border: 0 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature {
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow: visible !important;
    border: 0 !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: 29mm !important;
    min-height: 29mm !important;
    margin: 0 !important;
    gap: 5mm !important;
    overflow: visible !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 50mm !important;
    height: 24mm !important;
    max-width: 50mm !important;
    max-height: 24mm !important;
    object-fit: contain !important;
    object-position: center !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 28mm !important;
    height: 28mm !important;
    max-width: 28mm !important;
    max-height: 28mm !important;
    object-fit: contain !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line {
    display: block !important;
    width: 50mm !important;
    height: 21mm !important;
    margin: 0 auto !important;
    border-bottom: .6mm solid #263b47 !important;
    box-sizing: border-box !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    color: #43515a !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content {
    overflow: visible !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
    bottom: 22mm !important;
  }
}

/* قالب نهایی تثبیت‌شده: فوتر نارنجی و امضا/مهر در جریان طبیعی سند، بلافاصله پس از جمع کل. */
@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    color: #f15a24 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-content {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    padding: 34mm 24mm 14mm 14mm !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-signature-band {
    position: static !important;
    inset: auto !important;
    flex: 0 0 auto !important;
    align-self: flex-start !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 8mm 0 0 !important;
    padding: 0 !important;
    display: flex !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
    direction: ltr !important;
    z-index: auto !important;
    background: transparent !important;
    border: 0 !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature {
    width: 104mm !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 auto 0 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow: visible !important;
    border: 0 !important;
    background: transparent !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature > span,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature > span {
    font-size: 12pt !important;
    line-height: 1.25 !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
    display: flex !important;
    align-items: flex-start !important;
    justify-content: center !important;
    width: 100% !important;
    height: 36mm !important;
    min-height: 36mm !important;
    margin: 2mm 0 0 !important;
    gap: 4mm !important;
    overflow: visible !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-person,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-person {
    width: 66mm !important;
    flex: 0 0 66mm !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-image {
    display: block !important;
    width: 62mm !important;
    height: 30mm !important;
    max-width: 62mm !important;
    max-height: 30mm !important;
    object-fit: contain !important;
    object-position: center !important;
    image-rendering: auto !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.55) brightness(1.04) saturate(1.08) !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
    display: block !important;
    width: 35mm !important;
    height: 35mm !important;
    max-width: 35mm !important;
    max-height: 35mm !important;
    object-fit: contain !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-line,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-line {
    display: block !important;
    width: 60mm !important;
    height: 25mm !important;
    margin: 0 auto !important;
    border-bottom: .6mm solid #263b47 !important;
    box-sizing: border-box !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .signature-title,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .signature-name,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .signature-title {
    font-size: 11pt !important;
    line-height: 1.35 !important;
  }

  /* رسید کالا: همان فاصله، خوانایی و اندازهٔ بزرگ‌تر، بدون کادر مزاحم. */
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid {
    margin-top: 8mm !important;
    gap: 5mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-box {
    min-height: 38mm !important;
    padding: 3mm !important;
    border: 0 !important;
    background: transparent !important;
  }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-image {
    width: 58mm !important;
    max-width: 100% !important;
    height: 29mm !important;
    object-fit: contain !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.55) brightness(1.04) saturate(1.08) !important;
  }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-stamp-image {
    width: 32mm !important;
    height: 32mm !important;
    margin: 2mm auto 0 !important;
  }

  /* رسید تحویل چک: برای A5 نیز مهر و امضا بعد از جمع کل و خوانا بماند. */
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    margin-top: 8mm !important;
    gap: 4mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-box {
    min-height: 35mm !important;
    padding: 3mm !important;
    border: 0 !important;
    background: transparent !important;
  }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-image {
    display: block !important;
    width: 48mm !important;
    height: 24mm !important;
    max-width: 100% !important;
    object-fit: contain !important;
    mix-blend-mode: multiply !important;
    filter: contrast(1.55) brightness(1.04) saturate(1.08) !important;
  }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-stamp-box img {
    width: 28mm !important;
    height: 28mm !important;
    object-fit: contain !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-content,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-content {
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-paper-signature-band,
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .invoice-preview .invoice-paper.has-letterhead,
  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }
}

/* همهٔ رسیدها فعلاً با همان قاب رسمی پیش‌فاکتور و صفحهٔ کامل A4 چاپ می‌شوند. */
@media screen, print {
  .receipt-preview-wrap .receipt-paper,
  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    page: afv-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    padding: 0 24mm 14mm 14mm !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-head,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-paper-head {
    padding-top: 34mm !important;
    border-bottom-color: transparent !important;
    background: transparent !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer {
    display: flex !important;
    position: absolute !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    z-index: 4 !important;
    width: auto !important;
    min-height: 7mm !important;
    box-sizing: border-box !important;
    padding-top: 2mm !important;
    border-top: .35mm solid #f15a24 !important;
    color: #f15a24 !important;
    font-size: 7.5pt !important;
    line-height: 1.35 !important;
    direction: ltr !important;
    white-space: nowrap !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-address,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-address {
    flex: 1 1 auto !important;
    direction: rtl !important;
    text-align: right !important;
    unicode-bidi: plaintext !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts {
    display: inline-flex !important;
    flex: 0 0 auto !important;
    gap: 3mm !important;
    direction: ltr !important;
    white-space: nowrap !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax {
    display: inline-flex !important;
    flex: 0 0 auto !important;
    gap: 1mm !important;
    direction: ltr !important;
    white-space: nowrap !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-paper-footer,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-footer {
    display: none !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-grid,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signatures {
    margin-top: 8mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

@media print {
  body.printing-check-receipt,
  body.printing-check-receipt .modal-backdrop,
  body.printing-check-receipt .modal-card,
  body.printing-check-receipt .modal-body,
  body.printing-check-receipt .check-receipt-print-wrap,
  body.printing-check-receipt .check-receipt-print-wrap .check-receipt-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.printing-check-receipt .check-receipt-print-wrap .check-receipt-paper {
    page: afv-a4-portrait !important;
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }

  .receipt-preview-wrap .receipt-paper,
  .check-receipt-print-wrap .check-receipt-paper {
    page-break-after: avoid !important;
    break-after: avoid-page !important;
  }
}

/* فونت رسمی سایت AFV برای متن انگلیسی فوتر و خروجی اسناد. */
@font-face {
  font-family: "AFV Vazirmatn";
  src: url("/assets/fonts/Vazirmatn-wght.woff2") format("woff2");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@media screen, print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-contacts,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-preview .invoice-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .receipt-preview-wrap .receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax b,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-phone bdi,
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .invoice-native-footer .invoice-footer-fax bdi {
    font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
    font-variant-numeric: tabular-nums !important;
  }

  /* افزایش دو مرحله‌ای اندازه، بدون کشیدگی و با حفظ نسبت تصویر. */
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature {
    width: 122mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
    width: 122mm !important;
    height: 43mm !important;
    min-height: 43mm !important;
    gap: 5mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-person,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-person {
    width: 75mm !important;
    flex-basis: 75mm !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-image {
    width: 74mm !important;
    height: 38mm !important;
    max-width: 74mm !important;
    max-height: 38mm !important;
    object-fit: contain !important;
  }
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
    width: 42mm !important;
    height: 42mm !important;
    max-width: 42mm !important;
    max-height: 42mm !important;
  }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-signature-image {
    width: 70mm !important;
    height: 36mm !important;
    max-width: 100% !important;
    object-fit: contain !important;
  }
  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-stamp-image {
    width: 40mm !important;
    height: 40mm !important;
  }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-signature-image {
    width: 60mm !important;
    height: 30mm !important;
    max-width: 100% !important;
    object-fit: contain !important;
  }
  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-stamp-box img {
    width: 36mm !important;
    height: 36mm !important;
  }
}

/* آخرین لایهٔ تثبیت‌شدهٔ سربرگ AFV: متن دقیق، فونت و وزن یکسان، توضیحات شناور و مهر بزرگ‌تر. */
@media screen, print {
  .invoice-native-footer .invoice-footer-contacts,
  .invoice-native-footer .invoice-footer-phone,
  .invoice-native-footer .invoice-footer-fax,
  .invoice-native-footer .invoice-footer-phone b,
  .invoice-native-footer .invoice-footer-fax b,
  .invoice-native-footer .invoice-footer-phone bdi,
  .invoice-native-footer .invoice-footer-fax bdi {
    font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
    font-size: 8pt !important;
    font-weight: 800 !important;
    font-variant-numeric: tabular-nums !important;
    letter-spacing: 0 !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    white-space: nowrap !important;
  }

  .invoice-preview .invoice-summary-notes,
  .invoice-preview .invoice-paper-notes {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    align-self: stretch !important;
  }

  .invoice-preview .invoice-summary-notes > div,
  .invoice-preview .invoice-paper-notes > div {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
  }
}

@media print {
  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature {
    width: 132mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-signature-assets {
    width: 132mm !important;
    min-height: 52mm !important;
    height: 52mm !important;
  }

  .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-stamp-image,
  .invoice-preview .invoice-paper.invoice-paper-no-head .invoice-seller-signature .invoice-stamp-image {
    width: 52mm !important;
    height: 52mm !important;
    max-width: 52mm !important;
    max-height: 52mm !important;
  }

  .receipt-preview-wrap .receipt-paper.has-letterhead .receipt-stamp-image {
    width: 50mm !important;
    height: 50mm !important;
    max-width: 100% !important;
    max-height: 50mm !important;
  }

  .check-receipt-print-wrap .check-receipt-paper.has-letterhead .check-receipt-stamp-box img {
    width: 46mm !important;
    height: 46mm !important;
    max-width: 100% !important;
    max-height: 46mm !important;
  }
}

/* اصلاح نهایی جانمایی نامه: حاشیهٔ امن سربرگ، متادیتای بالا-چپ و امضای کنترل‌شده */
.letter-paper > .letter-meta,
.letter-paper.has-letterhead > .letter-meta {
  top: 9mm !important;
  left: 8mm !important;
  width: 52mm !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  text-align: left !important;
}
.letter-paper > .letter-meta > div { grid-template-columns: auto 1fr !important; gap: 4mm !important; }
.letter-paper > .letter-document {
  min-height: 245mm !important;
  padding: 49mm 25mm 40mm !important;
  box-sizing: border-box !important;
}
.letter-subject strong { font-weight: 900 !important; }
.letter-signature-area {
  width: 175px !important;
  margin-top: 16mm !important;
  margin-left: 0 !important;
  margin-right: auto !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}
.letter-signature-image {
  width: 125px !important;
  max-width: 125px !important;
  max-height: 34mm !important;
  object-fit: contain !important;
  margin: 0 auto -1px !important;
}
.letter-signature-area > strong { font-size: 10px !important; line-height: 1.35 !important; }
.letter-signature-area > span { font-size: 9px !important; line-height: 1.35 !important; }
.letter-stamp-image { width: 80px !important; height: 80px !important; }
.letter-output-toggles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media print {
  .letter-paper > .letter-document { padding: 49mm 25mm 40mm !important; }
  .letter-signature-area { margin-top: 16mm !important; }
  .letter-signature-image { width: 125px !important; max-width: 125px !important; }
}

/* آخرین قفل چاپ نامه؛ قواعد قدیمی A5 نباید روی نامهٔ عمودی اثر بگذارند. */
@media print {
  html:has(body.printing-letter) {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
  }
  body.printing-letter,
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    page: afv-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  body.printing-letter .letter-paper > .letter-meta,
  body.printing-letter .letter-paper.has-letterhead > .letter-meta {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
}
/* QC templates: PCBA and incoming electronic components */
.quality-template-banner{display:flex;flex-direction:column;gap:3px;margin:10px 0 14px;padding:11px 13px;border:1px solid #d9e7f5;border-right:3px solid var(--blue);border-radius:9px;background:linear-gradient(90deg,#f8fbff,#fff);color:var(--ink)}
.quality-template-banner strong{font-size:12px}.quality-template-banner small{color:#8b9aa4;font-size:8px;direction:ltr;text-align:right}
.quality-template-banner>div{display:flex;flex-direction:column;gap:3px}.quality-template-banner>label{display:flex;align-items:center;gap:8px;color:#6e7d87;font-size:8px;font-weight:700}.quality-template-banner select{min-width:170px;padding:6px 8px;border:1px solid #d8e4ee;border-radius:6px;color:#53636f;background:#fff;font-size:8px}
.quality-checklist-host{margin:0 0 13px}.quality-checklist{display:flex;flex-direction:column;gap:7px;padding:10px;border:1px solid #e2e9ed;border-radius:10px;background:#fbfcfd}
.quality-checklist-stage{display:flex;align-items:baseline;justify-content:space-between;gap:10px;margin-top:5px;padding:8px 10px;border-right:3px solid var(--orange);border-radius:6px;background:#fff7f2}.quality-checklist-stage strong{color:#a84f2b;font-size:10px}.quality-checklist-stage small{color:#9ba6ae;font-size:7px}
.quality-checklist-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:center;padding:8px 9px;border:1px solid #edf1f3;border-radius:7px;background:#fff}.quality-checklist-copy{min-width:0}.quality-checklist-copy strong{display:block;color:#53636f;font-size:8px;line-height:1.8}.quality-checklist-note{width:100%;margin-top:5px;padding:4px 6px;border:0;border-bottom:1px dashed #d9e2e8;color:#7c8b95;background:transparent;font-size:7px;outline:0}.quality-checklist-options{display:flex;gap:7px;align-items:center;white-space:nowrap}.quality-checklist-options label{display:flex;align-items:center;gap:3px;color:#778792;font-size:7px;cursor:pointer}.quality-checklist-options input{accent-color:#19875c}
.quality-checklist-report{overflow:hidden}.quality-checklist-summary{display:flex;flex-wrap:wrap;gap:5px;margin-bottom:8px}.quality-checklist-summary span{padding:4px 7px;border-radius:5px;background:#f3f7f9;color:#687984;font-size:8px}.quality-checklist-report table{width:100%;border-collapse:collapse;font-size:8px}.quality-checklist-report th,.quality-checklist-report td{padding:6px 7px;border:1px solid #e2e9ed;text-align:right;vertical-align:top}.quality-checklist-report th{color:#52636f;background:#f2f6f8;font-weight:800}.quality-checklist-report td{color:#687780;line-height:1.75}.quality-checklist-report td:nth-child(3){font-weight:800;white-space:nowrap}.quality-result-PASS{color:#16875c!important;background:#f1fbf5}.quality-result-FAIL{color:#c34e30!important;background:#fff4ef}.quality-result-NA,.quality-result-PENDING{color:#9aa6ae!important;background:#fafbfc}
.quality-test-type-grid{display:flex;flex-wrap:wrap;gap:6px;margin-top:4px}.quality-test-type-grid .check-card{min-height:31px;padding:6px 8px;font-size:8px}.quality-measurement-report{background:#fcfefd}.quality-test-tags{display:flex;flex-wrap:wrap;gap:5px;margin-bottom:8px}.quality-test-tags span{padding:4px 7px;border-radius:5px;background:#eef8f2;color:#2d7953;font-size:8px}.quality-measurement-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:7px}.quality-measurement-grid>div{padding:7px;border:1px solid #e0ece5;border-radius:6px;background:#fff;text-align:center}.quality-measurement-grid small,.quality-measurement-grid strong{display:block}.quality-measurement-grid small{color:#8b9a94;font-size:8px}.quality-measurement-grid strong{margin-top:3px;color:#26754e;font-size:12px}
@media print{.quality-checklist-report table{font-size:8pt}.quality-checklist-report th,.quality-checklist-report td{padding:5px}.quality-template-banner{display:none}}
@media(max-width:700px){.quality-checklist-row{grid-template-columns:1fr}.quality-checklist-options{justify-content:flex-start;flex-wrap:wrap}.quality-checklist-stage{align-items:flex-start;flex-direction:column}.quality-checklist-report{overflow:auto}.quality-checklist-report table{min-width:620px}.quality-measurement-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}

/* کنترل کیفیت: سربرگ پیش‌فاکتور، حاشیه امن یکسان و کاغذ A4 در پیش‌نمایش و چاپ. */
@page afv-quality-a4 { size: A4 portrait; margin: 0; }
.quality-preview-wrap {
  width: 100% !important;
  padding: 24px !important;
  background: #f3f6f8 !important;
}
.quality-preview-wrap .quality-paper {
  page: afv-quality-a4 !important;
  position: relative !important;
  width: 210mm !important;
  max-width: 100% !important;
  min-height: 297mm !important;
  height: 297mm !important;
  margin: 0 auto !important;
  padding: 11mm 13mm 22mm !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
  background: #fff !important;
  box-shadow: 0 8px 25px #1b293722 !important;
  font-family: "BNazanin", "B Nazanin", "Vazirmatn", Tahoma, sans-serif !important;
}
.quality-preview-wrap .quality-paper.has-letterhead {
  padding: 34mm 24mm 23mm 14mm !important;
}
.quality-preview-wrap .quality-paper > :not(.invoice-native-letterhead) {
  position: relative !important;
  z-index: 2 !important;
}
.quality-preview-wrap .quality-paper .invoice-native-letterhead {
  z-index: 1 !important;
}
.quality-preview-wrap .quality-paper .quality-paper-head {
  min-height: 34mm !important;
  margin: 0 !important;
  padding: 0 0 5mm !important;
  border-bottom: 0 !important;
}
.quality-preview-wrap .quality-paper .quality-paper-footer {
  display: none !important;
}
.quality-preview-wrap .quality-paper.quality-paper-no-head .quality-paper-footer {
  display: flex !important;
}
.quality-print-controls {
  margin-top: 8px;
  padding-top: 4px;
  border-top: 1px solid #edf1f3;
}
.quality-print-options-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}
.quality-print-options-grid select {
  min-height: 38px !important;
  font-weight: 700 !important;
}
.quality-print-mode-note {
  margin: 0 24px 10px;
  color: #778792;
  font-size: 9px;
}

/* دکمه‌ها و اعلان‌ها اندازه ثابت داشته باشند و در hover/اعلان نوسان نکنند. */
.button,
.button:hover,
.button:focus-visible,
.button:active {
  transform: none !important;
}
.workflow-notification-trigger.has-unread .workflow-notification-count,
.email-notification-trigger.has-unread .email-unread-count {
  animation: none !important;
  transform: none !important;
}
.workflow-notification-trigger,
.workflow-notification-trigger:hover,
.email-notification-trigger,
.email-notification-trigger:hover {
  width: 34px !important;
  min-width: 34px !important;
  max-width: 34px !important;
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  flex: 0 0 34px !important;
  transform: none !important;
}

/* جلوگیری از پرش کارت‌ها/باتن‌های تعاملی هنگام hover و دریافت اعلان. */
.mini-kpi-action,
.mini-kpi-action:hover,
.mini-kpi-action:focus-visible,
.mini-kpi-action:active,
.dossier-kpi-action,
.dossier-kpi-action:hover,
.dossier-kpi-action:focus-visible,
.dossier-kpi-action:active,
.customer-quick-action,
.customer-quick-action:hover,
.customer-quick-action:focus-visible,
.customer-quick-action:active {
  transform: none !important;
  transition-property: border-color, box-shadow, color, background-color !important;
}
.email-account-alert.has-unread .email-account-alert-count,
.email-notification-trigger.has-unread .email-unread-count {
  animation: none !important;
  transform: none !important;
}

@media print {
  html,
  body {
    width: 210mm !important;
    min-width: 210mm !important;
    margin: 0 !important;
    background: #fff !important;
  }
  .quality-print-mode-note,
  .quality-screen-only,
  .quality-preview-wrap + * {
    display: none !important;
  }
  .quality-preview-wrap {
    display: block !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    padding: 0 !important;
    background: #fff !important;
  }
  .quality-preview-wrap .quality-paper,
  .quality-preview-wrap .quality-paper.has-letterhead {
    page: afv-quality-a4 !important;
    width: 210mm !important;
    max-width: none !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 11mm 13mm 22mm !important;
    overflow: hidden !important;
    box-shadow: none !important;
  }
  .quality-preview-wrap .quality-paper.has-letterhead {
    padding: 34mm 24mm 23mm 14mm !important;
  }
  .quality-preview-wrap .quality-paper .quality-paper-section,
  .quality-preview-wrap .quality-paper .quality-signature-grid,
  .quality-preview-wrap .quality-paper .quality-meta-grid {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* شماره صفحه بالاتر از فوتر رسمی قرار می‌گیرد تا با آن تداخل نداشته باشد. */
.quality-preview-wrap .quality-paper.has-letterhead .quality-paper-footer {
  display: flex !important;
  right: 24mm !important;
  bottom: 18mm !important;
  left: 14mm !important;
  z-index: 3 !important;
  border-top: 0 !important;
  padding-top: 0 !important;
  font-size: 8px !important;
  height: 5mm !important;
  align-items: center !important;
  box-sizing: border-box !important;
  background: #fff !important;
  white-space: nowrap !important;
}

/* محتوای اصلی تا قبل از ناحیهٔ کد/تاریخ تمام شود؛ فوتر رسمی نارنجی پایین‌تر است. */
.quality-preview-wrap .quality-paper.has-letterhead {
  padding-bottom: 32mm !important;
}

/* فوتر QC دقیقاً از همان مقیاس فوتر پیش‌فاکتور استفاده کند؛ آدرس عمداً کوچک‌تر است. */
html body #modal-root .quality-preview-wrap .invoice-native-letterhead .invoice-native-footer {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto !important;
  direction: rtl !important;
  align-items: center !important;
  gap: 4mm !important;
  right: 13mm !important;
  bottom: 8mm !important;
  left: 13mm !important;
  width: auto !important;
  min-height: 7mm !important;
  padding-top: 2mm !important;
  box-sizing: border-box !important;
  font-size: 7.5pt !important;
  line-height: 1.35 !important;
}
html body #modal-root .quality-preview-wrap .invoice-native-letterhead .invoice-native-footer > .invoice-footer-address {
  grid-column: 1 !important;
  grid-row: 1 !important;
  min-width: 0 !important;
  direction: rtl !important;
  text-align: right !important;
  unicode-bidi: plaintext !important;
  font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
  font-size: 7.5pt !important;
  font-weight: 400 !important;
  line-height: 1.35 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
html body #modal-root .quality-preview-wrap .invoice-native-letterhead .invoice-native-footer > .invoice-footer-contacts {
  grid-column: 2 !important;
  grid-row: 1 !important;
  display: inline-flex !important;
  gap: 3mm !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
html body #modal-root .quality-preview-wrap .invoice-native-letterhead .invoice-native-footer > .invoice-footer-website {
  grid-column: 3 !important;
  grid-row: 1 !important;
}

/* چاپ QC باید دقیقاً همان برگه‌های مستقل پیش‌نمایش را چاپ کند؛
   هیچ سکشنی نصفه بین دو صفحه یا پشت قاب مودال باقی نماند. */
@media print {
  html:has(body.printing-quality),
  body.printing-quality {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  body.printing-quality .modal-backdrop,
  body.printing-quality .modal-card,
  body.printing-quality .modal-body,
  body.printing-quality .quality-preview-wrap {
    position: static !important;
    inset: auto !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  body.printing-quality .quality-preview-wrap .quality-paper {
    display: block !important;
    page-break-before: auto !important;
    break-before: auto !important;
    page-break-after: always !important;
    break-after: page !important;
  }
  body.printing-quality .quality-preview-wrap .quality-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-quality .quality-preview-wrap .quality-paper + .quality-paper {
    page-break-before: auto !important;
    break-before: auto !important;
  }
}

/* چاپ قطعی گزارش کنترل کیفیت: فقط خود برگه‌ها چاپ شوند؛ قاب مودال و داشبورد
   نباید قبل از گزارش فضای صفحه بسازند. اطلاعات کد/تاریخ نیز در نوار مستقل
   درست بالای خط نارنجی فوتر قرار می‌گیرد. */
@media print {
  html:has(body.printing-quality),
  html:has(body.printing-quality) body,
  body.printing-quality {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  body.printing-quality > #app,
  body.printing-quality > #auth-root,
  body.printing-quality > #toast-root,
  body.printing-quality > #telephony-root {
    display: none !important;
  }

  body.printing-quality > #modal-root,
  body.printing-quality > #modal-root > .modal-backdrop,
  body.printing-quality > #modal-root > .modal-backdrop > .modal-card,
  body.printing-quality #modal-root .modal-body,
  body.printing-quality #modal-root .quality-preview-wrap {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }

  body.printing-quality #modal-root .modal-backdrop {
    background: #fff !important;
    visibility: visible !important;
  }

  body.printing-quality #modal-root .modal-header,
  body.printing-quality #modal-root .modal-footer,
  body.printing-quality #modal-root .quality-print-mode-note,
  body.printing-quality #modal-root .quality-screen-only {
    display: none !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper,
  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead {
    position: relative !important;
    display: block !important;
    page: afv-quality-a4 !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 34mm 24mm 32mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
    page-break-before: auto !important;
    break-before: auto !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper > .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    z-index: 1 !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper > :not(.invoice-native-letterhead) {
    position: relative !important;
    z-index: 2 !important;
    visibility: visible !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper .quality-page-info,
  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead .quality-page-info {
    position: absolute !important;
    top: 276mm !important;
    right: 24mm !important;
    bottom: auto !important;
    left: 14mm !important;
    width: auto !important;
    height: 5mm !important;
    min-height: 5mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4mm !important;
    border: 0 !important;
    background: #fff !important;
    color: #a0aab1 !important;
    font-size: 8px !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    z-index: 4 !important;
    visibility: visible !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper .quality-page-info > span {
    display: block !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper .quality-page-info .quality-page-coding {
    direction: rtl !important;
    text-align: left !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper .quality-page-info .quality-page-date {
    direction: rtl !important;
    text-align: right !important;
  }
}

/* گزارش کنترل کیفیت: سربرگ و فوتر در هر برگه به‌صورت جریان مستقل قرار بگیرند.
   این ساختار از تکیه بر لایهٔ absolute برای صفحات میانی جلوگیری می‌کند و
   فضای کد/تاریخ را واقعاً بین محتوای گزارش و خط نارنجی فوتر رزرو می‌کند. */
.quality-preview-wrap .quality-paper {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  box-sizing: border-box !important;
}
.quality-preview-wrap .quality-paper.has-letterhead {
  padding: 34mm 24mm 8mm 14mm !important;
}
.quality-preview-wrap .quality-paper > .invoice-native-letterhead {
  display: contents !important;
  position: static !important;
  inset: auto !important;
}
.quality-preview-wrap .quality-paper > .quality-paper-head,
.quality-preview-wrap .quality-paper > .quality-meta-grid,
.quality-preview-wrap .quality-paper > .quality-paper-section,
.quality-preview-wrap .quality-paper > .quality-signature-grid {
  flex: 0 0 auto !important;
}
.quality-preview-wrap .quality-paper .invoice-native-logo {
  position: absolute !important;
  top: 8mm !important;
  right: 13mm !important;
  z-index: 1 !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .invoice-native-side-rule {
  position: absolute !important;
  top: 34mm !important;
  right: 14mm !important;
  bottom: 31mm !important;
  z-index: 1 !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .invoice-native-footer {
  position: static !important;
  order: 99 !important;
  flex: 0 0 7mm !important;
  width: auto !important;
  min-height: 7mm !important;
  margin: 0 -11mm 0 -1mm !important;
  padding: 2mm 0 0 !important;
  box-sizing: border-box !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto !important;
  align-items: center !important;
  gap: 4mm !important;
  border-top: .35mm solid #f15a24 !important;
  background: #fff !important;
  font-size: 7.5pt !important;
  line-height: 1.35 !important;
  direction: rtl !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .invoice-native-footer > .invoice-footer-address {
  grid-column: 1 !important;
  grid-row: 1 !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  direction: rtl !important;
  text-align: right !important;
  font-size: 7.5pt !important;
  font-weight: 400 !important;
}
.quality-preview-wrap .quality-paper .invoice-native-footer > .invoice-footer-contacts {
  grid-column: 2 !important;
  grid-row: 1 !important;
  display: inline-flex !important;
  gap: 3mm !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .invoice-native-footer > .invoice-footer-website {
  grid-column: 3 !important;
  grid-row: 1 !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-page-info {
  position: static !important;
  order: 98 !important;
  flex: 0 0 5mm !important;
  width: 100% !important;
  height: 5mm !important;
  min-height: 5mm !important;
  margin: auto 0 0 !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 4mm !important;
  border: 0 !important;
  background: #fff !important;
  color: #a0aab1 !important;
  font-size: 8px !important;
  line-height: 1.25 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  z-index: 4 !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .quality-page-info > span {
  display: block !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-page-info .quality-page-coding {
  direction: rtl !important;
  text-align: left !important;
}
.quality-preview-wrap .quality-paper .quality-page-info .quality-page-date {
  direction: rtl !important;
  text-align: right !important;
}

@media print {
  body.printing-quality .quality-preview-wrap .quality-paper,
  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead {
    padding: 34mm 24mm 8mm 14mm !important;
  }
  body.printing-quality .quality-preview-wrap .quality-paper .invoice-native-footer {
    margin: 0 -11mm 0 -1mm !important;
  }
}

/* سربرگ گزارش کنترل کیفیت به‌صورت جریان واقعی هر برگه؛ لوگو و خط عمودی
   برای هر صفحه از خود برگه ساخته می‌شوند و پابرگ رسمی در انتهای همان برگه
   قرار می‌گیرد تا صفحات میانی هم سربرگ/فوتر کامل داشته باشند. */
.quality-preview-wrap .quality-paper.has-letterhead {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 0 24mm 8mm 14mm !important;
}
.quality-preview-wrap .quality-paper.has-letterhead::before {
  content: "" !important;
  position: absolute !important;
  top: 34mm !important;
  right: 14mm !important;
  bottom: 31mm !important;
  width: 0 !important;
  border-right: .35mm solid #f15a24 !important;
  z-index: 1 !important;
  pointer-events: none !important;
}
.quality-preview-wrap .quality-paper.has-letterhead::after {
  content: "" !important;
  position: absolute !important;
  top: 33.2mm !important;
  right: 12.75mm !important;
  width: 2.5mm !important;
  height: 2.5mm !important;
  border-radius: 50% !important;
  background: #f15a24 !important;
  z-index: 1 !important;
  pointer-events: none !important;
}
.quality-preview-wrap .quality-paper > .quality-official-header {
  position: relative !important;
  flex: 0 0 34mm !important;
  height: 34mm !important;
  min-height: 34mm !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 2 !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .quality-official-logo {
  position: absolute !important;
  top: 8mm !important;
  right: 13mm !important;
  width: 39mm !important;
  height: auto !important;
  text-align: center !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .quality-official-logo img {
  display: block !important;
  width: 30mm !important;
  height: auto !important;
  margin: 0 auto !important;
  object-fit: contain !important;
}
.quality-preview-wrap .quality-paper > .quality-paper-head {
  flex: 0 0 34mm !important;
  min-height: 34mm !important;
  margin: 0 !important;
  padding: 0 0 5mm !important;
  border-bottom: 0 !important;
  z-index: 2 !important;
}
.quality-preview-wrap .quality-paper .quality-official-footer {
  position: static !important;
  order: 99 !important;
  flex: 0 0 7mm !important;
  width: auto !important;
  min-height: 7mm !important;
  margin: 0 -11mm 0 -1mm !important;
  padding: 2mm 0 0 !important;
  box-sizing: border-box !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto !important;
  align-items: center !important;
  gap: 4mm !important;
  border-top: .35mm solid #f15a24 !important;
  background: #fff !important;
  color: #43515a !important;
  font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
  font-size: 7.5pt !important;
  font-weight: 800 !important;
  line-height: 1.35 !important;
  direction: rtl !important;
  white-space: nowrap !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .quality-official-footer > .invoice-footer-address {
  grid-column: 1 !important;
  grid-row: 1 !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  direction: rtl !important;
  text-align: right !important;
  font-size: 7.5pt !important;
  font-weight: 400 !important;
}
.quality-preview-wrap .quality-paper .quality-official-footer > .invoice-footer-contacts {
  grid-column: 2 !important;
  grid-row: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 3mm !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-phone,
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-fax,
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-phone b,
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-fax b,
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-phone bdi,
.quality-preview-wrap .quality-paper .quality-official-footer .invoice-footer-fax bdi {
  color: #f15a24 !important;
  font-family: "AFV Vazirmatn", "Vazirmatn", Tahoma, sans-serif !important;
  font-size: 7.5pt !important;
  font-weight: 800 !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-official-footer > .invoice-footer-website {
  grid-column: 3 !important;
  grid-row: 1 !important;
  color: #f15a24 !important;
  direction: ltr !important;
  text-align: left !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-page-info {
  position: static !important;
  order: 98 !important;
  flex: 0 0 5mm !important;
  width: 100% !important;
  height: 5mm !important;
  min-height: 5mm !important;
  margin: auto 0 0 !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 4mm !important;
  border: 0 !important;
  background: #fff !important;
  color: #a0aab1 !important;
  font-size: 8px !important;
  line-height: 1.25 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  z-index: 4 !important;
  visibility: visible !important;
}
.quality-preview-wrap .quality-paper .quality-page-info > span {
  display: block !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
.quality-preview-wrap .quality-paper .quality-page-info .quality-page-coding {
  direction: rtl !important;
  text-align: left !important;
}
.quality-preview-wrap .quality-paper .quality-page-info .quality-page-date {
  direction: rtl !important;
  text-align: right !important;
}

@media print {
  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead {
    padding: 0 24mm 8mm 14mm !important;
  }
}

/* آخرین لایهٔ چاپ QC: این قوانین عمداً با همان specificity قوانین قدیمی
   چاپ نوشته شده‌اند تا صفحه‌ساز قدیمی، کد/تاریخ را دوباره زیر فوتر نبرد. */
@media print {
  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 0 24mm 8mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-header {
    position: relative !important;
    flex: 0 0 34mm !important;
    height: 34mm !important;
    min-height: 34mm !important;
    margin: 0 !important;
    padding: 0 !important;
    visibility: visible !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead > .quality-paper-head {
    position: relative !important;
    flex: 0 0 34mm !important;
    min-height: 34mm !important;
    margin: 0 !important;
    padding: 0 0 5mm !important;
    border-bottom: 0 !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead .quality-page-info {
    position: static !important;
    order: 98 !important;
    flex: 0 0 5mm !important;
    width: 100% !important;
    height: 5mm !important;
    min-height: 5mm !important;
    margin: auto 0 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4mm !important;
    border: 0 !important;
    background: #fff !important;
    color: #a0aab1 !important;
    font-size: 8px !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    visibility: visible !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead .quality-official-footer {
    position: static !important;
    order: 99 !important;
    flex: 0 0 7mm !important;
    width: auto !important;
    min-height: 7mm !important;
    height: 7mm !important;
    margin: 0 -11mm 0 -1mm !important;
    padding: 2mm 0 0 !important;
    box-sizing: border-box !important;
    display: grid !important;
    visibility: visible !important;
    border-top: .35mm solid #f15a24 !important;
  }

  body.printing-quality .quality-preview-wrap .quality-paper.has-letterhead .quality-page-info > span {
    display: block !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
}

/* قرارداد نهایی چاپ رسید تحویل چک: A4 عمودی، یک برگهٔ واقعی و بدون اثر A5. */
@page afv-crm-check-receipt-a4 { size: A4 portrait; margin: 0; }

@media screen {
  html body #modal-root .check-receipt-v3-wrap {
    width: min(100%, 210mm) !important;
    max-width: 210mm !important;
    margin: 0 auto !important;
    overflow-x: auto !important;
  }
}

@media print {
  html:has(body.printing-check-receipt),
  body.printing-check-receipt {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  body.printing-check-receipt > #modal-root,
  body.printing-check-receipt > #modal-root > .modal-backdrop,
  body.printing-check-receipt > #modal-root > .modal-backdrop > .modal-card,
  body.printing-check-receipt #modal-root .modal-body,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-v3 {
    page: afv-crm-check-receipt-a4 !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-v3-table {
    page-break-inside: auto !important;
    break-inside: auto !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-v3-table tr,
  body.printing-check-receipt #modal-root .check-receipt-v3-receiver,
  body.printing-check-receipt #modal-root .check-receipt-v3-images,
  body.printing-check-receipt #modal-root .check-receipt-v3-note {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}

/* آخرین قفل چاپ نامه: wrapper آزاد است و هر برگهٔ نامه یک صفحهٔ مستقل A4 می‌سازد. */
@page afv-letter-final-a4-portrait { size: A4 portrait; margin: 0; }
@page afv-letter-final-a4-landscape { size: A4 landscape; margin: 0; }

/* فیکس نهایی پیش‌فاکتور و رسید تحویل؛ بعد از قواعد مالی و قبل از wrapper نامه. */
@page afv-document-a4-final { size: A4 portrait; margin: 0; }
@media print {
  html:has(body.printing-invoice), html:has(body.printing-receipt),
  body.printing-invoice, body.printing-receipt,
  body.printing-invoice > #modal-root, body.printing-receipt > #modal-root,
  body.printing-invoice #modal-root .modal-backdrop,
  body.printing-receipt #modal-root .modal-backdrop,
  body.printing-invoice #modal-root .modal-card,
  body.printing-receipt #modal-root .modal-card,
  body.printing-invoice #modal-root .modal-body,
  body.printing-receipt #modal-root .modal-body {
    width: 210mm !important; min-width: 210mm !important; max-width: 210mm !important;
    height: auto !important; min-height: 0 !important; max-height: none !important;
    margin: 0 !important; padding: 0 !important; overflow: visible !important;
    position: static !important; display: block !important; background: #fff !important;
    box-shadow: none !important;
  }
  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap {
    width: 210mm !important; min-width: 210mm !important; max-width: 210mm !important;
    height: auto !important; min-height: 0 !important; max-height: none !important;
    margin: 0 !important; padding: 0 !important; overflow: visible !important;
    position: static !important; display: block !important; background: #fff !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    page: afv-document-a4-final !important;
    width: 210mm !important; min-width: 210mm !important; max-width: 210mm !important;
    height: 297mm !important; min-height: 297mm !important; max-height: 297mm !important;
    margin: 0 !important; padding: 34mm 24mm 23mm 14mm !important;
    box-sizing: border-box !important; overflow: hidden !important; position: relative !important;
    background: #fff !important; box-shadow: none !important;
    page-break-before: auto !important; page-break-after: always !important;
    page-break-inside: avoid !important; break-before: auto !important;
    break-after: page !important; break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper:last-of-type,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper:last-of-type {
    page-break-after: auto !important; break-after: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-content {
    display: block !important; width: 100% !important; height: auto !important;
    min-height: 0 !important; max-height: none !important; margin: 0 !important;
    padding: 0 !important; overflow: visible !important; position: relative !important;
    box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-head,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head {
    width: 100% !important; min-height: 30mm !important; height: auto !important;
    margin: 0 !important; padding: 0 0 4mm !important; border-bottom: 0 !important;
    box-sizing: border-box !important; break-inside: avoid !important; page-break-inside: avoid !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-head { padding-top: 0 !important; }
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesigned-content {
    display: block !important; width: 100% !important; height: auto !important;
    min-height: 0 !important; max-height: none !important; margin: 0 !important;
    padding: 0 !important; overflow: visible !important; position: relative !important;
    z-index: 2 !important; box-sizing: border-box !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesign-head,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesign-related,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesign-parties,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesign-section-title {
    break-inside: avoid !important; page-break-inside: avoid !important;
  }
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesign-items-section {
    width: 100% !important; margin-left: 0 !important; margin-right: 0 !important;
    overflow: visible !important; break-inside: auto !important; page-break-inside: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table {
    width: 100% !important; margin: 0 !important; border-collapse: collapse !important;
    break-inside: auto !important; page-break-inside: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table thead,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table thead { display: table-header-group !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table tr,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table tr {
    break-inside: avoid !important; page-break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table th,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-table td,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table th,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-items-table td {
    padding-top: 2mm !important; padding-bottom: 2mm !important;
    font-size: 8pt !important; line-height: 1.3 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-party-section,
  body.printing-invoice #modal-root .invoice-preview .invoice-summary-grid,
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-meta-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-party-grid,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-total-strip,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-note,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-confirmation,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-customer-ack,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid {
    break-inside: avoid !important; page-break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-signature-band,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-signature-grid { margin-top: 6mm !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper-footer { display: none !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    position: absolute !important; inset: 0 !important; z-index: 3 !important; pointer-events: none !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-side-rule { border-left: 0 !important; width: 0 !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-footer {
    position: absolute !important; right: 13mm !important; bottom: 8mm !important; left: 13mm !important;
    z-index: 4 !important; width: auto !important; min-height: 7mm !important; margin: 0 !important;
    padding-top: 2mm !important; border-top: .35mm solid #f15a24 !important;
    background: #fff !important; box-sizing: border-box !important;
  }
  /* هر article یک برگهٔ واقعی است؛ سربرگ را به جریان همان برگه برمی‌گردانیم تا
     در صفحات میانی هم لوگو و فوتر حذف یا به صفحهٔ قبلی منتقل نشوند. */
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    display: flex !important; flex-direction: column !important; align-items: stretch !important;
    padding: 34mm 24mm 23mm 14mm !important; box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    display: contents !important; position: static !important; inset: auto !important;
    width: auto !important; height: auto !important; min-height: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-logo {
    position: absolute !important; top: 8mm !important; right: 13mm !important;
    z-index: 5 !important; visibility: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-side-rule {
    position: absolute !important; top: 34mm !important; right: 14mm !important;
    bottom: 31mm !important; z-index: 4 !important; visibility: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-footer {
    position: relative !important; top: auto !important; right: auto !important;
    bottom: auto !important; left: auto !important; order: 99 !important;
    flex: 0 0 7mm !important; width: auto !important; min-height: 7mm !important;
    margin: auto 0 0 !important; z-index: 5 !important; display: grid !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesigned-content {
    order: 1 !important; flex: 1 1 auto !important; min-height: 0 !important;
  }
  /* عناصر رسمی با position:fixed در Chromium روی هر صفحهٔ چاپ تکرار می‌شوند؛
     این کار جلوی حذف سربرگ/فوتر در صفحهٔ دوم و صفحات میانی را می‌گیرد. */
  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    display: block !important; position: static !important; inset: auto !important;
    flex: 0 0 0 !important; width: 0 !important; height: 0 !important;
    min-height: 0 !important; overflow: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-logo {
    position: fixed !important; top: 8mm !important; right: 13mm !important;
    z-index: 20 !important; visibility: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-side-rule {
    position: fixed !important; top: 34mm !important; right: 14mm !important;
    bottom: 31mm !important; z-index: 19 !important; visibility: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-native-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-footer {
    position: fixed !important; top: auto !important; right: 13mm !important;
    bottom: 8mm !important; left: 13mm !important; order: initial !important;
    width: auto !important; min-height: 7mm !important; margin: 0 !important;
    z-index: 21 !important; display: grid !important;
  }
  /* صفحه‌بندی JS سربرگ را به عناصر مستقیم هر article تبدیل می‌کند؛ این عناصر
     در جریان flex همان برگه هستند و دیگر به‌صورت fragment از صفحهٔ قبلی جدا نمی‌شوند. */
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    height: auto !important; min-height: 297mm !important; max-height: none !important;
    padding: 0 24mm 8mm 14mm !important; overflow: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-logo {
    position: relative !important; inset: auto !important; order: 0 !important;
    flex: 0 0 25mm !important; width: 100% !important; height: 25mm !important;
    min-height: 25mm !important; display: flex !important; align-items: flex-start !important;
    justify-content: flex-end !important; direction: ltr !important; padding-top: 8mm !important;
    box-sizing: border-box !important; z-index: 5 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-logo img,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-logo img {
    display: block !important; width: 30mm !important; height: auto !important;
    max-width: 30mm !important; margin: 0 !important; object-fit: contain !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-side-rule {
    position: absolute !important; top: 34mm !important; right: 14mm !important;
    bottom: 31mm !important; left: auto !important; width: 11mm !important;
    border-left: 0 !important; border-right: .35mm solid #f15a24 !important;
    z-index: 4 !important; visibility: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer {
    position: absolute !important; top: auto !important; right: 13mm !important;
    bottom: 8mm !important; left: 13mm !important; order: initial !important;
    width: auto !important; min-height: 7mm !important; height: 7mm !important;
    margin: 0 !important; padding-top: 2mm !important; box-sizing: border-box !important;
    display: grid !important; z-index: 5 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer {
    grid-template-columns: max-content max-content max-content minmax(0, 1fr) !important;
    grid-template-rows: 1fr !important; align-items: center !important;
    gap: 0 5mm !important; direction: ltr !important; white-space: nowrap !important;
    font-size: 7.2pt !important; line-height: 1.2 !important; color: #43515a !important;
    border-top: .35mm solid #f15a24 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer > .invoice-footer-website,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer > .invoice-footer-website {
    grid-column: 1 !important; grid-row: 1 !important; display: block !important;
    color: #f15a24 !important; font-weight: 800 !important; text-align: left !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer > .invoice-footer-contacts,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer > .invoice-footer-contacts {
    grid-column: 2 / span 2 !important; grid-row: 1 !important; display: inline-flex !important;
    align-items: center !important; gap: 4mm !important; direction: ltr !important;
    white-space: nowrap !important; color: #f15a24 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer > .invoice-footer-address,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer > .invoice-footer-address {
    grid-column: 4 !important; grid-row: 1 !important; display: block !important;
    min-width: 0 !important; overflow: hidden !important; text-overflow: ellipsis !important;
    direction: rtl !important; text-align: right !important; white-space: nowrap !important;
  }
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-phone,
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-fax,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-phone,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-fax {
    display: inline-flex !important; align-items: center !important; gap: 1mm !important;
    direction: ltr !important; white-space: nowrap !important; color: #f15a24 !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    page-break-after: auto !important; break-after: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-paper + .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper + .receipt-paper {
    page-break-before: always !important; break-before: page !important;
  }
  body.printing-invoice #modal-root .invoice-preview .invoice-page-count { font-size: 9pt !important; }
  body.printing-invoice #modal-root .invoice-preview .invoice-page-count::after { content: none !important; }
}
@media print {
  /* داشبورد پنهان باید از layout خارج شود؛ visibility:hidden ارتفاع آن را حفظ می‌کند. */
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #app,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #auth-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #toast-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #telephony-root {
    display: none !important;
    visibility: hidden !important;
  }

  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) > #modal-root > .modal-backdrop > .modal-card,
  body:is(.printing-invoice, .printing-letter, .printing-letter-horizontal, .printing-receipt, .printing-check-receipt, .printing-quality, .printing-technical-report) #modal-root .modal-body {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
    box-shadow: none !important;
    visibility: visible !important;
  }

  /* بدنه و ریشهٔ چاپ نباید ارتفاع یک برگه را روی کل نامه قفل کنند؛ هر article خودش یک صفحه است. */
  html:has(body.printing-letter),
  body.printing-letter {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  html:has(body.printing-letter-horizontal),
  body.printing-letter-horizontal {
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  body.printing-letter .modal-backdrop,
  body.printing-letter .modal-card,
  body.printing-letter .modal-body,
  body.printing-letter .letter-preview,
  body.printing-letter .letter-preview-wrap,
  body.printing-letter-horizontal .modal-backdrop,
  body.printing-letter-horizontal .modal-card,
  body.printing-letter-horizontal .modal-body,
  body.printing-letter-horizontal .letter-preview,
  body.printing-letter-horizontal .letter-preview-wrap {
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  body.printing-letter .letter-preview-wrap,
  body.printing-letter-horizontal .letter-preview-wrap {
    display: block !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) {
    page: afv-letter-final-a4-portrait !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper:not(.letterhead-horizontal):last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal {
    page: afv-letter-final-a4-landscape !important;
    width: 297mm !important;
    min-width: 297mm !important;
    max-width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letterhead-horizontal:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-letter .letter-page-counter,
  body.printing-letter-horizontal .letter-page-counter {
    display: inline !important;
    font-size: 10px !important;
    direction: rtl !important;
    unicode-bidi: plaintext !important;
  }
  body.printing-letter .letter-page-counter::after,
  body.printing-letter-horizontal .letter-page-counter::after {
    content: none !important;
  }
}

/* END-OF-FILE ANCHOR: stable margin layer */

/* لایهٔ نهایی واقعی؛ این قواعد بعد از تمام overrideهای قبلی اعمال می‌شوند. */
@page afv-document-a4-locked { size: A4 portrait; margin: 0; }

@media screen, print {
  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    box-sizing: border-box !important;
    position: relative !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead {
    display: block !important;
    padding: 0 !important;
  }

  #modal-root .invoice-preview .invoice-paper.has-letterhead > .invoice-paper-content,
  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead > .receipt-redesigned-content,
  #modal-root .check-receipt-print-wrap .check-receipt-paper.has-letterhead > .check-receipt-v3-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    z-index: 2 !important;
  }

  #modal-root .receipt-preview-wrap .receipt-paper.has-letterhead:not(:has(> .receipt-redesigned-content)) {
    padding: 34mm 24mm 19mm 14mm !important;
  }

  /* سربرگ نسبت به خود برگه است؛ نه نسبت به wrapper یا صفحهٔ چاپ قبلی. */
  #modal-root .invoice-preview .invoice-paper .invoice-native-letterhead,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-letterhead,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-letterhead,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-letterhead {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    pointer-events: none !important;
    z-index: 20 !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-logo,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-logo,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-logo,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-logo,
  #modal-root .invoice-preview .print-flow-logo,
  #modal-root .receipt-preview-wrap .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-width: 30mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    z-index: 21 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-preview .print-flow-logo img,
  #modal-root .receipt-preview-wrap .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    object-fit: contain !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-side-rule,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-side-rule,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-side-rule,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-side-rule,
  #modal-root .invoice-preview .print-flow-side-rule,
  #modal-root .receipt-preview-wrap .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border-left: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 20 !important;
    visibility: visible !important;
  }

  #modal-root .invoice-preview .invoice-paper .invoice-native-footer,
  #modal-root .receipt-preview-wrap .receipt-paper .invoice-native-footer,
  #modal-root .check-receipt-print-wrap .check-receipt-paper .invoice-native-footer,
  #modal-root .technical-preview-wrap .technical-paper .invoice-native-footer,
  #modal-root .invoice-preview .print-flow-footer,
  #modal-root .receipt-preview-wrap .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    display: grid !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }

  /* گزارش QC: کد و تاریخ سه میلی‌متر بالاتر از خط نارنجی قرار می‌گیرند. */
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0 24mm 8mm 14mm !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-header,
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-paper-head {
    flex: 0 0 34mm !important;
    height: 34mm !important;
    min-height: 34mm !important;
    max-height: 34mm !important;
    box-sizing: border-box !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-page-info {
    order: 98 !important;
    flex: 0 0 5mm !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: auto 0 3mm !important;
    box-sizing: border-box !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-footer {
    order: 99 !important;
    flex: 0 0 7mm !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 -11mm 0 -1mm !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
  }
  #modal-root .quality-preview-wrap .quality-paper.has-letterhead::before {
    top: 34mm !important;
    bottom: 15mm !important;
  }

  /* گزارش فنی و نامه نیز پیش از فوتر فضای امن دارند. */
  #modal-root .technical-preview-wrap .technical-paper.has-letterhead {
    display: block !important;
    padding: 34mm 24mm 19mm 14mm !important;
  }
  #modal-root .technical-preview-wrap .technical-paper.has-letterhead > .technical-paper-footer {
    position: absolute !important;
    right: 24mm !important;
    bottom: 15mm !important;
    left: 14mm !important;
    width: auto !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: 0 !important;
    padding-top: 0 !important;
    box-sizing: border-box !important;
  }
  #modal-root .letter-preview-wrap .letter-paper:not(.letterhead-horizontal) > .letter-document {
    position: absolute !important;
    top: 49mm !important;
    right: 25mm !important;
    bottom: 22mm !important;
    left: 25mm !important;
    min-height: 0 !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  #modal-root .invoice-preview .invoice-paper,
  #modal-root .receipt-preview-wrap .receipt-paper,
  #modal-root .check-receipt-print-wrap .check-receipt-paper,
  #modal-root .quality-preview-wrap .quality-paper,
  #modal-root .technical-preview-wrap .technical-paper {
    page: afv-document-a4-locked !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    page-break-after: always !important;
  }
  #modal-root .invoice-preview .invoice-paper:last-child,
  #modal-root .receipt-preview-wrap .receipt-paper:last-child,
  #modal-root .check-receipt-print-wrap .check-receipt-paper:last-child,
  #modal-root .quality-preview-wrap .quality-paper:last-child,
  #modal-root .technical-preview-wrap .technical-paper:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}

@media print {
  html:has(body.printing-invoice),
  html:has(body.printing-receipt),
  html:has(body.printing-check-receipt),
  html:has(body.printing-quality),
  html:has(body.printing-technical-report),
  body.printing-invoice,
  body.printing-receipt,
  body.printing-check-receipt,
  body.printing-quality,
  body.printing-technical-report {
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-shadow: none !important;
  }

  /* QC قواعد قدیمیِ absolute را نیز قطعی خنثی می‌کنیم. */
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper.has-letterhead {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 24mm 8mm 14mm !important;
  }
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-page-info {
    position: static !important;
    order: 98 !important;
    flex: 0 0 5mm !important;
    width: 100% !important;
    height: 5mm !important;
    min-height: 5mm !important;
    max-height: 5mm !important;
    margin: auto 0 3mm !important;
  }
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper.has-letterhead > .quality-official-footer {
    position: static !important;
    order: 99 !important;
    flex: 0 0 7mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 -11mm 0 -1mm !important;
  }
}

/* یک شکست صفحه برای هر article کافی است؛ شکست قبل و بعد هم‌زمان، صفحهٔ میانی را ناقص می‌کند. */
@media print {
  body.printing-invoice #modal-root .invoice-preview .invoice-paper + .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper + .receipt-paper,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper + .check-receipt-paper,
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper + .quality-paper,
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper + .technical-paper {
    break-before: auto !important;
    page-break-before: auto !important;
  }
}

/* فوتر مالی باید در جریان داخلی هر برگه باشد تا صفحات میانی نیز حتماً چاپ شوند. */
@media print {
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 34mm 24mm 8mm 14mm !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper > .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper > .receipt-redesigned-content {
    position: relative !important;
    inset: auto !important;
    flex: 0 0 244mm !important;
    width: 100% !important;
    height: 244mm !important;
    min-height: 244mm !important;
    max-height: 244mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    order: 1 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-width: 30mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    flex: none !important;
    order: initial !important;
    z-index: 21 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border-left: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 20 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer {
    position: relative !important;
    inset: auto !important;
    flex: 0 0 7mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 4mm 0 0 !important;
    padding-top: 2mm !important;
    box-sizing: border-box !important;
    display: grid !important;
    order: 99 !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-native-letterhead,
  body.printing-receipt #modal-root .receipt-preview-wrap .invoice-native-letterhead {
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    flex: none !important;
    order: initial !important;
  }
}

/* فوتر بدون position شناور: تضمین رندر شدن در هر صفحهٔ میانی Chromium. */
@media print {
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 24mm 8mm 14mm !important;
    overflow: hidden !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-logo {
    position: static !important;
    flex: 0 0 34mm !important;
    width: 100% !important;
    height: 34mm !important;
    min-height: 34mm !important;
    max-height: 34mm !important;
    padding: 8mm 0 0 !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: flex-start !important;
    justify-content: flex-end !important;
    order: 0 !important;
    z-index: 2 !important;
    visibility: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-logo img,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper > .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-redesigned-content {
    position: static !important;
    flex: 0 0 244mm !important;
    width: 100% !important;
    height: 244mm !important;
    min-height: 244mm !important;
    max-height: 244mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    order: 1 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer {
    position: static !important;
    flex: 0 0 7mm !important;
    width: 100% !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 4mm 0 0 !important;
    padding: 2mm 0 0 !important;
    box-sizing: border-box !important;
    display: grid !important;
    order: 2 !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 2 !important;
    visibility: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-side-rule {
    display: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper::after,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper::after {
    content: "" !important;
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    width: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    z-index: 1 !important;
    pointer-events: none !important;
  }
}

/* Chromium در صفحهٔ میانی با لایه‌های fragment‌شده مشکل paint دارد؛ هر برگهٔ
   مالی را به یک compositing layer مستقل تبدیل می‌کنیم تا سربرگ و فوتر آن حذف نشوند. */
@media print {
  body.printing-invoice #modal-root .invoice-preview .invoice-paper,
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper {
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* پیوست نامه: بعد از برگهٔ اصلی، A4 مستقل و بدون تکرار سربرگ رسمی. */
.letter-preview-wrap .letter-paper.letter-attachment-page {
  box-sizing: border-box !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: #fff !important;
  background-image: none !important;
  box-shadow: none !important;
  position: relative !important;
}

/* نامه صادره باید دقیقاً از همان سربرگ تمیز و بدون QR پیش‌فاکتور استفاده کند.
   این بلوک عمداً در انتهای فایل است تا overrideهای قدیمی letter-paper نتوانند
   تصویر سربرگ را مخفی یا آن را به پس‌زمینهٔ قدیمی تبدیل کنند. */
html body #modal-root .letter-preview-wrap > .letter-paper.has-letterhead {
  position: relative !important;
  width: 210mm !important;
  min-width: 210mm !important;
  max-width: 210mm !important;
  height: 297mm !important;
  min-height: 297mm !important;
  max-height: 297mm !important;
  margin: 0 auto !important;
  padding: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  background: #fff !important;
  background-image: none !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper.has-letterhead > .official-letterhead-image {
  display: block !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: fill !important;
  object-position: center top !important;
  visibility: visible !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta {
  position: absolute !important;
  top: 12mm !important;
  left: 14mm !important;
  z-index: 2 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 1mm !important;
  width: max-content !important;
  max-width: 52mm !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #18242c !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 10pt !important;
  line-height: 1.35 !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta > div {
  display: grid !important;
  grid-template-columns: 34mm max-content !important;
  grid-template-areas: "value label" !important;
  align-items: baseline !important;
  justify-content: start !important;
  width: max-content !important;
  max-width: 52mm !important;
  gap: 3mm !important;
  direction: ltr !important;
  white-space: nowrap !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta strong,
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta span {
  margin: 0 !important;
  white-space: nowrap !important;
  font-weight: 400 !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta strong {
  grid-area: label !important;
  display: block !important;
  text-align: right !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-meta.official-document-meta span {
  grid-area: value !important;
  display: block !important;
  width: 34mm !important;
  min-width: 34mm !important;
  max-width: 34mm !important;
  text-align: left !important;
  direction: ltr !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-document {
  position: relative !important;
  z-index: 1 !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 49mm 22mm 34mm !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-document .letter-basmala {
  margin: 0 !important;
}
html body #modal-root .letter-preview-wrap > .letter-paper > .letter-document .letter-recipient {
  margin-top: 15mm !important;
}
@media print {
  html body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.has-letterhead > .official-letterhead-image {
    display: block !important;
    visibility: visible !important;
  }
}
.letter-preview-wrap .letter-paper.letter-attachment-page.letterhead-horizontal {
  width: 297mm !important;
  min-width: 297mm !important;
  max-width: 297mm !important;
  height: 210mm !important;
  min-height: 210mm !important;
  max-height: 210mm !important;
}
.letter-attachment-page > .official-letterhead-image,
.letter-attachment-page > .invoice-native-letterhead,
.letter-attachment-page > .letter-meta,
.letter-attachment-page > .letter-print-page-footer {
  display: none !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-body {
  position: absolute !important;
  top: 18mm !important;
  right: 18mm !important;
  bottom: 18mm !important;
  left: 18mm !important;
  box-sizing: border-box !important;
  width: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  background: #fff !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-kicker {
  display: block !important;
  flex: 0 0 auto !important;
  color: #a84e2b !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 9pt !important;
  font-weight: 700 !important;
  line-height: 1.4 !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-body h1 {
  flex: 0 0 auto !important;
  max-width: 100% !important;
  margin: 3mm 0 5mm !important;
  color: #182530 !important;
  font-family: 'BTitr','BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 12pt !important;
  line-height: 1.5 !important;
  overflow-wrap: anywhere !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-content-frame {
  box-sizing: border-box !important;
  flex: 0 0 188mm !important;
  width: 100% !important;
  height: 188mm !important;
  min-height: 0 !important;
  max-height: 188mm !important;
  margin: 0 !important;
  padding: 3mm !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
  border: 1px solid #dfe7eb !important;
  border-radius: 3mm !important;
  background: #fbfcfd !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-visual {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-pdf-frame {
  flex-basis: 188mm !important;
  height: 188mm !important;
  min-height: 0 !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-embed {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-file-frame {
  flex-basis: 65mm !important;
  height: 65mm !important;
  max-height: 65mm !important;
  flex-direction: column !important;
  gap: 3mm !important;
  text-align: center !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-card {
  flex: 0 0 auto !important;
  box-sizing: border-box !important;
  width: 100% !important;
  margin: 5mm 0 0 !important;
  padding: 4mm 5mm !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 1.5mm !important;
  border: 1px solid #f0d7c9 !important;
  border-radius: 2.5mm !important;
  background: #fffaf7 !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-card strong { color: #a84e2b !important; font-size: 9pt !important; }
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-card span { color: #26323a !important; font-size: 9pt !important; font-weight: 700 !important; overflow-wrap: anywhere !important; }
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-card small { color: #7e8d96 !important; font-size: 8pt !important; }
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-body > p {
  flex: 0 0 auto !important;
  max-width: 100% !important;
  margin: 3mm 0 0 !important;
  color: #687985 !important;
  font-family: 'BNazanin','B Nazanin','Tahoma',sans-serif !important;
  font-size: 8pt !important;
  line-height: 1.5 !important;
}
@media print {
  body.printing-letter .letter-preview-wrap .letter-paper.letter-attachment-page,
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letter-attachment-page {
    page-break-before: auto !important;
    break-before: auto !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper.letter-attachment-page:last-child,
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letter-attachment-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-letter .letter-preview-wrap .letter-paper.letter-attachment-page:not(.letterhead-horizontal) {
    page: afv-letter-final-a4-portrait !important;
  }
  body.printing-letter-horizontal .letter-preview-wrap .letter-paper.letter-attachment-page.letterhead-horizontal {
    page: afv-letter-final-a4-landscape !important;
  }
  .letter-preview-wrap .letter-attachment-page .letter-attachment-open { display: none !important; }
}

/* آخرین قفل صفحه‌بندی: عناصر غیرسندی نباید صفحهٔ پایانی بسازند و شکست بعد
   از آخرین برگه باید مستقل از وجود نودهای پنهان یا footer مودال باشد. */
@media print {
  body.printing-invoice #modal-root .invoice-preview .invoice-paper:not(:has(~ .invoice-paper)),
  body.printing-receipt #modal-root .receipt-preview-wrap .receipt-paper:not(:has(~ .receipt-paper)),
  body.printing-check-receipt #modal-root .check-receipt-print-wrap .check-receipt-paper:not(:has(~ .check-receipt-paper)),
  body.printing-quality #modal-root .quality-preview-wrap .quality-paper:not(:has(~ .quality-paper)),
  body.printing-technical-report #modal-root .technical-preview-wrap .technical-paper:not(:has(~ .technical-paper)),
  body.printing-letter #modal-root .letter-preview-wrap .letter-paper:not(:has(~ .letter-paper)),
  body.printing-letter-horizontal #modal-root .letter-preview-wrap .letter-paper:not(:has(~ .letter-paper)) {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > :not(.invoice-paper),
  body.printing-receipt #modal-root .receipt-preview-wrap > :not(.receipt-paper),
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > :not(.check-receipt-paper),
  body.printing-quality #modal-root .quality-preview-wrap > :not(.quality-paper),
  body.printing-technical-report #modal-root .technical-preview-wrap > :not(.technical-paper),
  body.printing-letter #modal-root .letter-preview-wrap > :not(.letter-paper),
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > :not(.letter-paper) {
    display: none !important;
    visibility: hidden !important;
  }
}

/* قفل نهایی چاپ: آخرین صفحه با کلاس صریح مشخص می‌شود تا Firefox و Chromium
   به عناصر پنهان یا :last-child صفحهٔ سفید اضافه نکنند. */
@media print {
  body.printing-invoice #modal-root .invoice-preview > .print-non-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-non-page,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-non-page,
  body.printing-quality #modal-root .quality-preview-wrap > .print-non-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-non-page,
  body.printing-letter #modal-root .letter-preview-wrap > .print-non-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-non-page {
    display: none !important;
    visibility: hidden !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-page-last,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-page-last,
  body.printing-quality #modal-root .quality-preview-wrap > .print-page-last,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-page-last,
  body.printing-letter #modal-root .letter-preview-wrap > .print-page-last,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .print-page:not(.print-page-first),
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-page:not(.print-page-first),
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-page:not(.print-page-first),
  body.printing-quality #modal-root .quality-preview-wrap > .print-page:not(.print-page-first),
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-page:not(.print-page-first),
  body.printing-letter #modal-root .letter-preview-wrap > .print-page:not(.print-page-first),
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-page:not(.print-page-first) {
    break-before: auto !important;
    page-break-before: auto !important;
  }
}

/* قفل نهایی این نسخه: پیوست فقط خود فایل است و فوتر/مهر داخل محدودهٔ امن A4 می‌مانند. */
.letter-preview-wrap .letter-attachment-page .letter-attachment-page-body.letter-attachment-document-only {
  top: 13mm !important;
  right: 13mm !important;
  bottom: 13mm !important;
  left: 13mm !important;
  padding: 0 !important;
  display: flex !important;
  align-items: stretch !important;
  justify-content: center !important;
  overflow: hidden !important;
  background: #fff !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-content-frame {
  flex: 1 1 auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: #fff !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-visual,
.letter-preview-wrap .letter-attachment-page .letter-attachment-embed,
.letter-preview-wrap .letter-attachment-page .letter-attachment-pdf-canvas,
.letter-preview-wrap .letter-attachment-page .letter-attachment-pdf-image {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  border: 0 !important;
}
.letter-preview-wrap .letter-attachment-page .letter-attachment-file-frame {
  flex: 1 1 auto !important;
  height: auto !important;
  max-height: none !important;
}

/* همهٔ شماره‌های فوتر پیش‌فاکتور و رسید دقیقاً هم‌اندازهٔ URL باشند. */
html body #modal-root .invoice-native-letterhead .invoice-native-footer,
html body #modal-root .invoice-native-letterhead .invoice-native-footer > *,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-phone *,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-fax *,
html body #modal-root .invoice-native-letterhead .invoice-native-footer .invoice-footer-website {
  font-size: 7.5pt !important;
  line-height: 1.35 !important;
}
html body #modal-root .invoice-native-letterhead .invoice-native-footer {
  right: 13mm !important;
  bottom: 8mm !important;
  left: 13mm !important;
  overflow: visible !important;
  box-sizing: border-box !important;
}
html body #modal-root .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature,
html body #modal-root .invoice-preview .invoice-paper.has-letterhead .invoice-seller-signature .invoice-signature-assets,
html body #modal-root .invoice-preview .invoice-paper.has-letterhead .invoice-stamp-image,
html body #modal-root .invoice-preview .invoice-paper.has-letterhead .invoice-signature-image,
html body #modal-root .invoice-preview .invoice-paper.has-letterhead .invoice-paper-signature-band {
  overflow: visible !important;
}

@media print {
  /* هر مقاله دقیقاً یک برگ است؛ فقط آخرین برگ پایان شکست صفحه ندارد. */
  body.printing-invoice #modal-root .invoice-preview > .print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-page,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-page,
  body.printing-quality #modal-root .quality-preview-wrap > .print-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-page,
  body.printing-letter #modal-root .letter-preview-wrap > .print-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-page {
    break-before: auto !important;
    page-break-before: auto !important;
    break-after: page !important;
    page-break-after: always !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-page-last,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-page-last,
  body.printing-quality #modal-root .quality-preview-wrap > .print-page-last,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-page-last,
  body.printing-letter #modal-root .letter-preview-wrap > .print-page-last,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }
  body.printing-letter #modal-root .letter-preview-wrap .letter-attachment-page .letter-attachment-content-frame,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap .letter-attachment-page .letter-attachment-content-frame {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  body.printing-letter #modal-root .letter-preview-wrap .letter-attachment-page .letter-attachment-pdf-image,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap .letter-attachment-page .letter-attachment-pdf-image {
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    border: 0 !important;
  }
}

/* قفل نهایی صفحه‌بندی و امضا برای Firefox. */
@media print {
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page {
    display: block !important;
    position: relative !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-before: auto !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page:not(.print-page-last),
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page:not(.print-page-last) {
    page-break-after: always !important;
    break-after: page !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page-last {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .receipt-redesigned-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table tbody {
    height: 100% !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 21 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo img,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 20 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-footer {
    position: absolute !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding: 2mm 0 0 !important;
    display: grid !important;
    visibility: visible !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band {
    position: absolute !important;
    right: auto !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    max-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    z-index: 23 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-seller-signature {
    width: 88mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-signature-assets {
    width: 100% !important;
    height: 25mm !important;
    min-height: 25mm !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4mm !important;
    overflow: visible !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-signature-image {
    width: 44mm !important;
    height: 20mm !important;
    max-width: 44mm !important;
    max-height: 20mm !important;
    object-fit: contain !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last > .print-flow-signature-band .invoice-stamp-image {
    width: 25mm !important;
    height: 25mm !important;
    max-width: 25mm !important;
    max-height: 25mm !important;
    object-fit: contain !important;
  }
}

/* یک لایهٔ چاپ نهایی و یکسان برای خروجی همهٔ اسناد در Firefox و Chromium. */
@page afv-document-a4-locked { size: A4 portrait; margin: 0; }
@page afv-document-a4-landscape-locked { size: A4 landscape; margin: 0; }

@media print {
  html,
  body {
    width: 210mm !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  #modal-root,
  #modal-root .modal-backdrop,
  #modal-root .modal-card,
  #modal-root .modal-body {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 210mm !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    transform: none !important;
  }

  #modal-root .modal-header,
  #modal-root .modal-footer,
  #modal-root .modal-close,
  #modal-root .print-mode-note,
  #modal-root .document-relation,
  #modal-root .document-relation-wrap,
  #modal-root .invoice-screen-only,
  #modal-root .quality-print-mode-note,
  #modal-root .technical-print-mode-note,
  #modal-root .letter-screen-only {
    display: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap,
  body.printing-letter #modal-root .letter-preview-wrap,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap {
    position: static !important;
    display: block !important;
    width: 210mm !important;
    min-width: 0 !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    transform: none !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .check-receipt-paper.print-page,
  body.printing-quality #modal-root .quality-preview-wrap > .quality-paper.print-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page,
  body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page:not(.letterhead-horizontal),
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page:not(.letterhead-horizontal) {
    page: afv-document-a4-locked !important;
    display: block !important;
    position: relative !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 296.5mm !important;
    min-height: 296.5mm !important;
    max-height: 296.5mm !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    box-shadow: none !important;
    background: #fff !important;
    break-before: auto !important;
    page-break-before: auto !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    page-break-after: always !important;
  }

  body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page.letterhead-horizontal,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page.letterhead-horizontal {
    page: afv-document-a4-landscape-locked !important;
    width: 296.5mm !important;
    min-width: 296.5mm !important;
    max-width: 296.5mm !important;
    height: 209.5mm !important;
    min-height: 209.5mm !important;
    max-height: 209.5mm !important;
  }

  body.printing-letter #modal-root .letter-preview-wrap > .letter-attachment-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-attachment-page {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page-last,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .check-receipt-paper.print-page-last,
  body.printing-quality #modal-root .quality-preview-wrap > .quality-paper.print-page-last,
  body.printing-technical-report #modal-root .technical-preview-wrap > .technical-paper.print-page-last,
  body.printing-letter #modal-root .letter-preview-wrap > .letter-paper.print-page-last,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .letter-paper.print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .print-non-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-non-page,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-non-page,
  body.printing-quality #modal-root .quality-preview-wrap > .print-non-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-non-page,
  body.printing-letter #modal-root .letter-preview-wrap > .print-non-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-non-page {
    display: none !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content.print-page-has-signature {
    bottom: 61mm !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-head,
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-parties-row,
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-document-section-title,
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-summary-grid {
    flex: 0 0 auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table {
    flex: 1 1 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 18mm !important;
    max-height: none !important;
    margin: 0 !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content > .invoice-paper-table tbody {
    height: 100% !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-paper-meta {
    width: 52mm !important;
    min-width: 52mm !important;
    max-width: 52mm !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-meta-row {
    grid-template-columns: 16mm minmax(0, 1fr) !important;
    min-width: 0 !important;
    gap: 1.5mm !important;
  }

  body.printing-invoice #modal-root .invoice-preview .invoice-meta-row strong {
    min-width: 0 !important;
    max-width: 34mm !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    text-align: left !important;
    font-size: 8.5pt !important;
    line-height: 1.2 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 21 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    width: 11mm !important;
    height: auto !important;
    border: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    visibility: visible !important;
    z-index: 20 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding: 1.5mm 0 0 !important;
    display: grid !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    visibility: visible !important;
    z-index: 22 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-address,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-address,
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-contacts,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-contacts,
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-website,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-website,
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-phone,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-phone,
  body.printing-invoice #modal-root .invoice-preview .print-flow-footer .invoice-footer-fax,
  body.printing-receipt #modal-root .receipt-preview-wrap .print-flow-footer .invoice-footer-fax {
    font-size: 7pt !important;
    line-height: 1.1 !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-signature-band {
    position: absolute !important;
    right: auto !important;
    bottom: 18mm !important;
    left: 14mm !important;
    width: 132mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    max-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    z-index: 23 !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-signature-band .invoice-seller-signature {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    width: 132mm !important;
    height: 42mm !important;
    min-height: 42mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-signature-band .invoice-signature-assets {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 4mm !important;
    width: 128mm !important;
    height: 34mm !important;
    min-height: 34mm !important;
    overflow: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-signature-band .invoice-signature-person {
    flex: 0 0 68mm !important;
    width: 68mm !important;
    min-width: 0 !important;
    overflow: visible !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-signature-band .invoice-signature-image {
    display: block !important;
    width: 64mm !important;
    height: 25mm !important;
    max-width: 64mm !important;
    max-height: 25mm !important;
    margin: 0 !important;
    object-fit: contain !important;
    object-position: left center !important;
  }

  body.printing-invoice #modal-root .invoice-preview .print-flow-signature-band .invoice-stamp-image {
    display: block !important;
    flex: 0 0 30mm !important;
    width: 30mm !important;
    height: 30mm !important;
    max-width: 30mm !important;
    max-height: 30mm !important;
    margin: 0 !important;
    object-fit: contain !important;
  }
}

/* قفل نهایی چاپ برای Firefox: هر صفحهٔ تولیدشده مستقل از fragmentهای قبلی است. */
@media print {
  /* عناصر رابط، مثل پیام «حالت چاپ»، نباید یک صفحهٔ اضافه بسازند. */
  body.printing-invoice #modal-root .invoice-preview > .print-non-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .print-non-page,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap > .print-non-page,
  body.printing-quality #modal-root .quality-preview-wrap > .print-non-page,
  body.printing-technical-report #modal-root .technical-preview-wrap > .print-non-page,
  body.printing-letter #modal-root .letter-preview-wrap > .print-non-page,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap > .print-non-page {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview,
  body.printing-receipt #modal-root .receipt-preview-wrap,
  body.printing-check-receipt #modal-root .check-receipt-print-wrap,
  body.printing-quality #modal-root .quality-preview-wrap,
  body.printing-technical-report #modal-root .technical-preview-wrap,
  body.printing-letter #modal-root .letter-preview-wrap,
  body.printing-letter-horizontal #modal-root .letter-preview-wrap {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  body.printing-check-receipt #modal-root .check-receipt-print-wrap {
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    position: static !important;
    display: block !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    break-before: auto !important;
    break-after: avoid-page !important;
    page-break-before: auto !important;
    page-break-after: avoid !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page {
    height: 296mm !important;
    min-height: 296mm !important;
    max-height: 296mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page-last {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page {
    display: block !important;
    position: relative !important;
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    height: 296mm !important;
    min-height: 296mm !important;
    max-height: 296mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-before: auto !important;
    page-break-inside: avoid !important;
    break-before: auto !important;
    break-inside: avoid !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page:not(.print-page-last),
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page:not(.print-page-last) {
    page-break-after: always !important;
    break-after: page !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page-last,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page-last {
    page-break-after: auto !important;
    break-after: auto !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .invoice-paper-content,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .receipt-redesigned-content {
    position: absolute !important;
    top: 34mm !important;
    right: 24mm !important;
    bottom: 19mm !important;
    left: 14mm !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo {
    position: absolute !important;
    top: 8mm !important;
    right: 13mm !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 21 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-logo img,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-logo img {
    display: block !important;
    width: 30mm !important;
    max-width: 30mm !important;
    height: auto !important;
    margin: 0 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-side-rule,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-side-rule {
    position: absolute !important;
    top: 34mm !important;
    right: 14mm !important;
    bottom: 15mm !important;
    left: auto !important;
    width: 11mm !important;
    height: auto !important;
    border: 0 !important;
    border-right: .35mm solid #f15a24 !important;
    display: block !important;
    visibility: visible !important;
    z-index: 20 !important;
  }
  body.printing-invoice #modal-root .invoice-preview > .invoice-paper.print-page > .print-flow-footer,
  body.printing-receipt #modal-root .receipt-preview-wrap > .receipt-paper.print-page > .print-flow-footer {
    position: absolute !important;
    top: auto !important;
    right: 13mm !important;
    bottom: 8mm !important;
    left: 13mm !important;
    width: auto !important;
    height: 7mm !important;
    min-height: 7mm !important;
    max-height: 7mm !important;
    margin: 0 !important;
    padding: 2mm 0 0 !important;
    display: grid !important;
    visibility: visible !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    border-top: .35mm solid #f15a24 !important;
    background: #fff !important;
    z-index: 22 !important;
  }
}
