/* =========================================================
   SITISE INVOICE MANAGER - INVOICE DOCUMENT & PRINT VIEW
   ========================================================= */

.invoice-preview-wrapper {
  background: #ffffff;
  color: #12203a;
  border-radius: var(--radius-md);
  padding: 2.5rem;
  max-width: 800px;
  margin: 0 auto;
  box-shadow: 0 10px 25px rgba(18, 9, 7, 0.15);
  font-family: var(--font-family-base);
  position: relative;
}

.inv-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 2rem;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 2rem;
}

.inv-doc-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  margin-bottom: 0.75rem;
}

.inv-doc-company-info {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: #64748b;
  max-width: 320px;
}

.inv-doc-company-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: #120907;
  margin-bottom: 0.25rem;
}

.inv-doc-meta {
  text-align: right;
}

.inv-doc-title {
  font-family: var(--font-family-display);
  font-size: 2rem;
  font-weight: 800;
  color: #2092d9;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.inv-doc-number {
  font-size: 1.125rem;
  font-weight: 600;
  color: #12203a;
  margin-bottom: 0.75rem;
}

.inv-doc-meta-table {
  font-size: 0.8125rem;
  margin-left: auto;
}

.inv-doc-meta-table td {
  padding: 0.2rem 0.5rem;
}

.inv-doc-meta-table td:first-child {
  color: #64748b;
  font-weight: 500;
  text-align: right;
}

.inv-doc-meta-table td:last-child {
  color: #120907;
  font-weight: 600;
  text-align: left;
}

/* Bill To / Recipient */
.inv-doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2.25rem;
}

.inv-party-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 1.25rem;
}

.inv-party-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #2092d9;
  margin-bottom: 0.5rem;
}

.inv-party-name {
  font-size: 1rem;
  font-weight: 700;
  color: #120907;
  margin-bottom: 0.25rem;
}

.inv-party-detail {
  font-size: 0.8125rem;
  color: #64748b;
  line-height: 1.5;
}

/* Document Items Table */
.inv-doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2rem;
}

.inv-doc-table th {
  background: #f1f5f9;
  color: #12203a;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #cbd5e1;
  text-align: left;
}

.inv-doc-table th:last-child,
.inv-doc-table td:last-child {
  text-align: right;
}

.inv-doc-table th:nth-child(2),
.inv-doc-table td:nth-child(2),
.inv-doc-table th:nth-child(3),
.inv-doc-table td:nth-child(3),
.inv-doc-table th:nth-child(4),
.inv-doc-table td:nth-child(4) {
  text-align: center;
}

.inv-doc-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.875rem;
  color: #12203a;
  vertical-align: top;
}

.inv-item-name {
  font-weight: 600;
  color: #120907;
  margin-bottom: 0.2rem;
}

.inv-item-desc {
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.4;
}

/* Totals Summary */
.inv-doc-bottom {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.75rem;
}

.inv-doc-notes {
  flex: 1;
  font-size: 0.8125rem;
  color: #64748b;
}

.inv-notes-block {
  margin-bottom: 0.875rem;
}

.inv-notes-title {
  font-weight: 600;
  color: #12203a;
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
}

.inv-doc-totals {
  width: 280px;
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.875rem;
  color: #64748b;
}

.inv-total-row.grand-total {
  border-top: 2px solid #120907;
  margin-top: 0.5rem;
  padding-top: 0.65rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: #120907;
}

.inv-total-row.paid-row {
  color: #059669;
  font-weight: 600;
}

.inv-total-row.balance-row {
  background: #f8fafc;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-xs);
  font-weight: 700;
  color: #2092d9;
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* Payment & QR Section */
.inv-doc-pay-banner {
  background: #f0f9ff;
  border: 1px dashed #2092d9;
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.inv-qr-img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  background: #ffffff;
  padding: 4px;
  border-radius: var(--radius-xs);
  border: 1px solid #cbd5e1;
  display: block;
}

.inv-pay-info {
  flex: 1;
}

.inv-pay-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #145687;
  margin-bottom: 0.25rem;
}

.inv-pay-info p {
  font-size: 0.8125rem;
  color: #475569;
  line-height: 1.4;
}

/* =========================================================
   PERFECT LETTER / A4 PRINT STYLES
   Ensures ONLY the invoice document prints on 1 clean sheet
   ========================================================= */
@page {
  size: letter portrait;
  margin: 8mm 10mm;
}

@media print {
  /* Hide all top-level children of body EXCEPT the invoice detail modal */
  body > *:not(#modal-invoice-detail) {
    display: none !important;
  }

  /* Explicitly hide every other modal */
  .modal-overlay:not(#modal-invoice-detail) {
    display: none !important;
    visibility: hidden !important;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  /* Show ONLY modal-invoice-detail cleanly */
  body > #modal-invoice-detail {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* Hide modal chrome (header, footer, buttons) */
  #modal-invoice-detail .modal-header,
  #modal-invoice-detail .modal-footer,
  #modal-invoice-detail .modal-close-btn,
  .btn {
    display: none !important;
  }

  #modal-invoice-detail .modal-dialog {
    display: block !important;
    transform: none !important;
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #modal-invoice-detail .modal-body {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  #printable-invoice-doc {
    display: block !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  /* Keep colors and backgrounds sharp in print */
  .inv-doc-table th {
    background: #f1f5f9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .inv-party-card {
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .inv-doc-pay-banner {
    background: #f0f9ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .inv-qr-img {
    display: block !important;
    max-width: 90px !important;
    max-height: 90px !important;
  }

  /* Avoid page breaks inside invoice elements */
  .inv-doc-header,
  .inv-doc-parties,
  .inv-doc-table,
  .inv-doc-totals,
  .inv-doc-pay-banner {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
