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

.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;
  }
}

@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;
  }
}

/* سربرگ رسمی از همان فایل تصویری در پیش‌نمایش و چاپ استفاده می‌شود. */
.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;
}

@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;
  }
}

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