/* ==============================================================================
   Dhanalakshmi Crackers - Multi-Format Invoice Print Stylesheet
   Supports A4 Full Page, 80mm Thermal Receipt, and 58mm Thermal Receipt
   Bulletproof Cross-Browser Printing (Eliminates Modal Displacements & Blank Gaps)
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Outfit:wght@600;700;800;900&display=swap');

/* ==============================================================================
   A4 Professional Invoice Layout
   ============================================================================== */
.invoice-print-container.format-a4,
.invoice-paper.format-a4,
.invoice-paper {
  background: #ffffff;
  color: #0f172a;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  font-family: 'Plus Jakarta Sans', sans-serif;
  line-height: 1.4;
  box-sizing: border-box;
  width: 100%;
  max-width: 820px;
  padding: 2.25rem;
  border-radius: 12px;
  position: relative;
}

/* Header Section */
.a4-inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  gap: 1.5rem;
}

.a4-brand-col {
  flex: 1;
}

.a4-brand-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.a4-brand-logo {
  font-size: 2.2rem;
  line-height: 1;
}

.a4-brand-img {
  max-height: 55px;
  width: auto;
  border-radius: 6px;
}

.a4-brand-name {
  font-family: 'Outfit', sans-serif;
  font-size: 1.65rem;
  font-weight: 800;
  color: #b91c1c;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-transform: uppercase;
}

.a4-brand-tagline {
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.35rem;
}

.a4-brand-meta {
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.45;
}

.a4-meta-col {
  text-align: right;
  min-width: 240px;
}

.a4-doc-type-badge {
  display: inline-block;
  background: #1e293b;
  color: #ffffff;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0.3rem 0.85rem;
  border-radius: 6px;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.a4-inv-num {
  font-family: 'Outfit', sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 0.2rem;
}

.a4-inv-date {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.a4-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
}

.a4-status-paid {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.a4-status-unpaid {
  background: #ffedd5;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

/* Two-column Customer & Invoice Details */
.a4-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.a4-info-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.a4-card-heading {
  font-size: 0.72rem;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.25rem;
}

.a4-cust-name {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 0.2rem;
}

.a4-cust-line {
  font-size: 0.82rem;
  color: #334155;
  margin-bottom: 0.15rem;
  line-height: 1.35;
}

/* Professional Products Table */
.a4-table-wrap {
  margin-bottom: 1.25rem;
}

.a4-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.a4-table th {
  background: #0f172a;
  color: #ffffff;
  padding: 0.6rem 0.75rem;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid #0f172a;
}

.a4-table td {
  padding: 0.65rem 0.75rem;
  border: 1px solid #e2e8f0;
  color: #1e293b;
}

.a4-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.a4-item-name {
  font-weight: 600;
  color: #0f172a;
}

.a4-item-sku {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 1px;
}

/* Totals and Bank/Words section */
.a4-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.a4-summary-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.a4-words-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.a4-words-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.a4-words-val {
  font-size: 0.85rem;
  font-weight: 700;
  color: #0f172a;
  font-style: italic;
}

.a4-payment-meta {
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.4;
}

.a4-summary-right {
  width: 320px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.a4-calc-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.35rem 0;
  color: #475569;
}

.a4-calc-discount {
  color: #16a34a;
  font-weight: 600;
}

.a4-calc-grand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 2px solid #0f172a;
  margin-top: 0.4rem;
  padding-top: 0.6rem;
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  color: #b91c1c;
}

/* Footer Section */
.a4-inv-footer {
  border-top: 1px dashed #cbd5e1;
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
}

.a4-terms-col {
  flex: 1;
  font-size: 0.74rem;
  color: #64748b;
  line-height: 1.45;
}

.a4-sign-col {
  text-align: center;
  width: 200px;
}

.a4-sign-space {
  height: 45px;
  border-bottom: 1px solid #94a3b8;
  margin-bottom: 0.35rem;
}

.a4-sign-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #0f172a;
}

.a4-sign-sub {
  font-size: 0.68rem;
  color: #64748b;
}

/* ==============================================================================
   Thermal Receipts Preview (80mm and 58mm)
   ============================================================================== */
.invoice-print-container.format-80mm {
  width: 80mm;
  max-width: 80mm;
  padding: 5mm 3.5mm 16mm 3.5mm;
  font-family: 'Courier Prime', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.35;
  color: #000000;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  margin: 0 auto;
  background: #ffffff;
}

.invoice-print-container.format-58mm {
  width: 58mm;
  max-width: 58mm;
  padding: 4mm 2mm 14mm 2mm;
  font-family: 'Courier Prime', 'Consolas', monospace;
  font-size: 9.5px;
  line-height: 1.3;
  color: #000000;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  margin: 0 auto;
  background: #ffffff;
}

/* Shared Thermal Layout Rules */
.thermal-center {
  text-align: center;
  margin-bottom: 6px;
}

.thermal-shop-name {
  font-weight: 800;
  font-size: 14px;
  text-transform: uppercase;
  margin-bottom: 3px;
  letter-spacing: 0.5px;
}

.format-58mm .thermal-shop-name {
  font-size: 12px;
}

.thermal-meta {
  font-size: 10px;
  line-height: 1.3;
  margin-bottom: 2px;
}

.format-58mm .thermal-meta {
  font-size: 8.5px;
}

.thermal-divider {
  border-top: 1px dashed #000000;
  margin: 5px 0;
}

.thermal-double-divider {
  border-top: 2px solid #000000;
  margin: 6px 0;
}

.thermal-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0;
}

.thermal-table th {
  border-bottom: 1px dashed #000000;
  padding: 3px 0;
  font-weight: 700;
  font-size: 10px;
}

.format-58mm .thermal-table th {
  font-size: 8.5px;
}

.thermal-table td {
  padding: 2.5px 0;
  vertical-align: top;
}

.thermal-table .text-right {
  text-align: right;
}

.thermal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.thermal-bold {
  font-weight: 700;
}

.thermal-item-title {
  font-weight: 700;
  word-break: break-word;
}

.thermal-item-sub {
  font-size: 8.5px;
  color: #222;
}

.format-58mm .thermal-item-sub {
  font-size: 7.5px;
}

.thermal-qr-box {
  text-align: center;
  margin: 8px 0;
}

.thermal-qr-img {
  width: 90px;
  height: 90px;
  display: block;
  margin: 0 auto;
}

.format-58mm .thermal-qr-img {
  width: 75px;
  height: 75px;
}

.thermal-footer {
  text-align: center;
  margin-top: 8px;
  font-size: 9.5px;
  line-height: 1.35;
}

.format-58mm .thermal-footer {
  font-size: 8px;
}

/* Format Switcher Bar (Screen Toolbar) */
.invoice-format-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #ffffff;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.format-bar-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #4b5563;
}

.format-pills {
  display: inline-flex;
  gap: 0.4rem;
  background: #f3f4f6;
  padding: 3px;
  border-radius: 8px;
  flex-wrap: wrap;
}

.format-pill {
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #374151;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.format-pill:hover {
  background: rgba(255, 255, 255, 0.7);
  color: #111827;
}

.format-pill.active {
  background: #b91c1c;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(185, 28, 28, 0.25);
  font-weight: 700;
}

/* ==============================================================================
   Print Media Directives (@media print)
   Bulletproof isolation - guarantees ZERO blank top gaps or modal displacements
   ============================================================================== */
@media print {
  /* 1. Global Reset: Remove all screen styling constraints */
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* 2. Hide all page chrome, headers, footers, buttons */
  .site-header,
  .site-footer,
  .admin-sidebar,
  .admin-topbar,
  .admin-mobile-bottom-nav,
  .invoice-toolbar,
  .invoice-format-bar,
  .print-controls,
  .toast-container,
  button,
  .btn,
  .no-print,
  .modal-close,
  .modal-header,
  .modal-footer {
    display: none !important;
  }

  /* 3. Dissolve Modals completely during print if printing from modal */
  .modal-overlay {
    position: static !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    z-index: auto !important;
  }

  .modal-content,
  .modal-body {
    position: static !important;
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  .admin-main {
    margin-left: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }

  /* 4. Root Print Wrapper (Guarantees top 0, left 0, zero gap) */
  body.printing-in-progress > *:not(#cleanPrintRoot) {
    display: none !important;
  }

  body.printing-in-progress #cleanPrintRoot {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  /* 5. A4 Full Page Rules */
  body.print-mode-a4 {
    background: #ffffff !important;
  }

  @page {
    margin: 8mm;
    size: auto;
  }

  body.print-mode-a4 #cleanPrintRoot,
  body.print-mode-a4 #printableInvoice,
  body.print-mode-a4 #invoiceContentToPrint {
    position: static !important;
    width: 100% !important;
    max-width: 210mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
  }

  /* 6. 80mm Thermal Rules */
  body.print-mode-80mm {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.print-mode-80mm @page {
    size: 80mm auto;
    margin: 0;
  }

  body.print-mode-80mm #cleanPrintRoot,
  body.print-mode-80mm #printableInvoice,
  body.print-mode-80mm #invoiceContentToPrint {
    position: static !important;
    width: 76mm !important;
    max-width: 76mm !important;
    margin: 0 auto !important;
    padding: 2mm 1.5mm 16mm 1.5mm !important;
    box-shadow: none !important;
    border: none !important;
    font-family: 'Courier Prime', 'Consolas', monospace !important;
    font-size: 11px !important;
    line-height: 1.35 !important;
  }

  /* 7. 58mm Thermal Rules */
  body.print-mode-58mm {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.print-mode-58mm @page {
    size: 58mm auto;
    margin: 0;
  }

  body.print-mode-58mm #cleanPrintRoot,
  body.print-mode-58mm #printableInvoice,
  body.print-mode-58mm #invoiceContentToPrint {
    position: static !important;
    width: 52mm !important;
    max-width: 52mm !important;
    margin: 0 auto !important;
    padding: 2mm 1mm 15mm 1mm !important;
    box-shadow: none !important;
    border: none !important;
    font-family: 'Courier Prime', 'Consolas', monospace !important;
    font-size: 9.5px !important;
    line-height: 1.25 !important;
  }
}
