/* ==========================================================================
   Bill Maker - A4 Print Stylesheet
   ========================================================================== */

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

@media print {
  html, body {
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide entire application chrome and editor */
  .app-header,
  .editor-panel,
  .preview-toolbar,
  .modal-overlay,
  #toast-container,
  button,
  .no-print {
    display: none !important;
  }

  /* Expand container and preview area */
  .app-container {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .preview-panel {
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  .invoice-sheet-wrapper {
    transform: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Standard A4 sheet container for print - page margins handled cleanly with margin:0 */
  .invoice-sheet {
    width: 210mm !important;
    height: auto !important;
    min-height: auto !important;
    display: block !important;
    box-shadow: none !important;
    margin: 0 auto !important;
    padding: 12mm 14mm 14mm 14mm !important;
    background: #ffffff !important;
    border: none !important;
    box-sizing: border-box !important;
  }

  /* Ensure colors and fills print properly */
  .sheet-table th {
    background-color: #1a365d !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .totals-table tr.grand-total-row {
    background-color: #c9daf8 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Repeating Table Headers & Spacing Footers across multiple pages */
  .sheet-table {
    page-break-inside: auto !important;
    width: 100% !important;
  }

  .sheet-table thead {
    display: table-header-group !important;
  }

  .print-top-spacer-row {
    display: table-row !important;
  }

  .print-top-spacer-row th {
    height: 12mm !important;
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    line-height: 0 !important;
  }

  .print-top-spacer-row div {
    height: 12mm !important;
    min-height: 12mm !important;
  }

  .sheet-table tfoot {
    display: table-footer-group !important;
  }

  /* Zero out the tfoot spacer - we don't need extra bottom-page breathing room when
     the summary group flows naturally right after the table */
  .sheet-table-print-spacer td {
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    line-height: 0 !important;
    font-size: 0 !important;
  }

  .sheet-table-print-spacer td div,
  .sheet-table-print-spacer td * {
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    display: none !important;
  }

  .sheet-table tr {
    page-break-inside: avoid !important;
    page-break-after: auto !important;
  }

  .sheet-table td, 
  .sheet-table th {
    border-color: #000000 !important;
  }

  /* Keep meta, totals, and footer together */
  .sheet-header {
    page-break-inside: avoid !important;
  }

  .sheet-meta-wrapper {
    page-break-inside: avoid !important;
    margin-bottom: 0 !important;
  }

  /* Summary Group (Totals + Footer) kept intact during pagination */
  .sheet-summary-group {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-top: 8px !important;
    padding-top: 0 !important;
  }

  .sheet-totals-section {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .sheet-footer-section {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-top: 14px !important;
  }
}
