@media print {
  body { 
    -webkit-print-color-adjust: exact; 
    print-color-adjust: exact; 
    font-family: 'Noto Serif Bengali', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
  }
  
  .no-print, .delete-btn, .add-row-btn, #discount-type { 
    display: none !important; 
  }
  
  thead th:last-child, tbody td:last-child { 
    display: none !important; 
  }
  
  /* Main wrapper for A5 */
  .invoice-wrapper {
    width: 100% !important;
    max-width: 132mm !important;
    margin: 0 auto !important;
    padding: 5mm !important;
    box-shadow: none !important;
    border: none !important;
    font-size: 9px !important;
  }
  
  /* Input fields styling for print - ensures values are visible */
  input[type="text"], 
  input[type="tel"], 
  input[type="number"], 
  input[type="email"],
  select,
  textarea {
    border: none !important; 
    background: transparent !important; 
    box-shadow: none !important;
    color: #000 !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    print-color-adjust: exact !important;
    -webkit-print-color-adjust: exact !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  /* Header section compact */
  .header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    margin-bottom: 6px !important;
    padding-bottom: 4px !important;
    border-bottom: 1.5px solid #000 !important;
  }
  
  .header img {
    max-height: 30px !important;
    width: auto !important;
    margin-right: 6px !important;
  }
  
  .company-info h1 {
    font-size: 14px !important;
    margin: 0 !important;
    font-weight: bold !important;
  }
  
  .company-info p {
    font-size: 8px !important;
    margin: 1px 0 !important;
    line-height: 1.2 !important;
  }
  
  .header-right {
    text-align: right !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    align-items: flex-end !important;
  }
  
  /* Cash memo title - compact */
  .cash-memo { 
    padding: 2px 10px 2px 4px !important; 
    margin: 0 !important; 
    letter-spacing: 0 !important; 
    font-size: 11px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important; 
    border: 1.5px solid #000 !important;
    border-radius: 3px !important;
    background: #f0f0f0 !important;
    font-weight: 600 !important;
    text-indent: 0 !important;
  }
  
  .date-section, .invoice-number {
    font-size: 8px !important;
    margin: 1px 0 !important;
  }
  
  .date-value, .invoice-value {
    font-size: 9px !important;
    font-weight: 600 !important;
  }
  
  /* Customer info - ultra compact with underlines */
  .customer-info { 
    display: block !important; 
    padding: 3px 4px !important; 
    background: transparent !important; 
    border: none !important; 
    border-radius: 0 !important;
    margin-bottom: 4px !important;
  }
  
  .customer-row { 
    display: flex !important; 
    gap: 8px !important; 
    width: 100% !important; 
    margin-bottom: 3px !important; 
  }
  
  .customer-row.row-2 { 
    margin-bottom: 0 !important; 
  }
  
  .customer-field { 
    display: flex !important; 
    align-items: center !important; 
    gap: 3px !important; 
    font-size: 8px !important; 
    flex: 1 1 0 !important; 
  }
  
  .customer-field.address-field { 
    flex: 1 1 100% !important; 
  }
  
  .customer-field .field-label { 
    font-size: 8px !important; 
    font-weight: 600 !important; 
    min-width: 35px !important;
    color: #000 !important;
    text-align: left !important;
  }
  
  .customer-field .customer-input { 
    flex: 1 1 auto !important; 
    font-size: 8px !important; 
    padding: 0 2px !important; 
    line-height: 1.2 !important; 
    border: none !important; 
    border-bottom: 0.5px solid #000 !important; 
    border-radius: 0 !important;
    background: transparent !important;
    color: #000 !important;
  }
  
  /* Tagline - very compact */
  .tagline {
    font-size: 7px !important;
    margin: 2px 0 4px 0 !important;
    padding: 2px 3px !important;
    line-height: 1.2 !important;
    background: #f8f9fa !important;
    border-left: 2px solid #3498db !important;
  }
  
  /* Table styling - optimized for many rows */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 3px 0 !important;
  }
  
  thead {
    background: #e8e8e8 !important;
  }
  
  thead th {
    padding: 2px 3px !important;
    font-size: 8px !important;
    border: 0.5px solid #999 !important;
    font-weight: 600 !important;
    background: #e0e0e0 !important;
    color: #000 !important;
  }
  
  tbody td {
    padding: 1px 2px !important;
    font-size: 8px !important;
    border: 0.5px solid #ccc !important;
    line-height: 1.2 !important;
  }
  
  tbody td input {
    font-size: 8px !important;
    line-height: 1.2 !important;
  }
  
  tbody td.amount {
    text-align: right !important;
    padding-right: 3px !important;
    font-weight: 500 !important;
  }
  
  /* Totals section - compact and visible */
  .totals-table {
    width: 100% !important;
    max-width: 50mm !important;
    margin: 4px 0 4px auto !important;
    border-collapse: collapse !important;
  }
  
  .totals-table td {
    padding: 2px 4px !important;
    font-size: 8px !important;
    border: 0.5px solid #ccc !important;
    letter-spacing: 0 !important;
  }
  
  .totals-table tr:last-child td {
    background: #333 !important;
    color: white !important;
    font-weight: bold !important;
    font-size: 9px !important;
    border: 1px solid #000 !important;
  }
  
  .totals-table .label {
    text-align: left !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
  }
  
  .totals-table .value {
    text-align: right !important;
    font-weight: 600 !important;
  }
  
  /* Force calculation spans to be visible - CRITICAL FIX */
  #subtotal, #grand-total, #discount-amount, #discount-applied, #total-words {
    color: #000 !important;
    font-weight: 600 !important;
    font-size: 8px !important;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    letter-spacing: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Ensure spans inside value cells are visible */
  .totals-table .value span {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #000 !important;
  }
  
  /* Ensure parent value cells don't hide content */
  .totals-table .value {
    display: table-cell !important;
    visibility: visible !important;
  }
  
  /* Strong tag should not interfere with display */
  .totals-table .value strong {
    display: inline !important;
    visibility: visible !important;
    font-weight: bold !important;
  }
  
  .totals-table tr:last-child #grand-total {
    color: white !important;
    font-size: 9px !important;
    display: inline-block !important;
    visibility: visible !important;
  }
  
  /* Ensure total words is visible */
  .amount-in-words #total-words {
    display: inline !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #000 !important;
    font-weight: 600 !important;
  }
  
  /* Discount field styling */
  #discount {
    display: none !important;
  }
  
  #discount-applied { 
    font-size: 7px !important;
    color: #000 !important;
    display: inline !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin-left: 2px !important;
  }
  
  .discount-flex {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 2px !important;
    visibility: visible !important;
  }
  
  .discount-flex * {
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Amount in words - compact without icon */
  .amount-in-words {
    font-size: 8px !important;
    margin: 3px 0 !important;
    padding: 2px 4px !important;
    background: #f0f8ff !important;
    border-left: 2px solid #3498db !important;
    font-weight: 600 !important;
    display: block !important;
    visibility: visible !important;
    color: #000 !important;
  }
  
  .amount-in-words::before {
    display: none !important;
  }
  
  .amount-in-words * {
    visibility: visible !important;
    opacity: 1 !important;
    display: inline !important;
  }
  
  /* Footer section - minimal space */
  .footer-section {
    margin-top: 8mm !important;
    padding-top: 4px !important;
    border-top: 0.5px solid #666 !important;
  }

  .warning-notice {
    text-align: center !important;
    color: #dc3545 !important;
    font-weight: 600 !important;
    font-size: 7px !important;
    font-style: italic !important;
    margin-top: 3px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .signature-container {
    display: flex !important;
    justify-content: space-between !important;
    gap: 10mm !important;
  }

  .signature-box {
    flex: 1 !important;
    text-align: center !important;
  }

  .signature-line {
    margin-top: 12mm !important;
    border-top: 0.5px solid #000 !important;
    width: 70% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .signature-label {
    font-size: 8px !important;
    font-weight: 600 !important;
    margin-top: 2px !important;
  }  /* A5 page size (half of A4) in portrait mode - CORRECTED */
  @page { 
    size: A5 portrait; /* Standard A5 size */
    margin: 5mm;
  }
  
  /* Alternative explicit A5 dimensions if needed */
  @page {
    size: 148mm 210mm; /* Explicit A5 dimensions */
    margin: 5mm;
  }
  
  /* Hide scrollbars */
  * {
    overflow: visible !important;
  }
  
  /* Ensure all text is black for better printing */
  * {
    color: #000 !important;
  }
  
  /* Exception for white text on dark backgrounds */
  .totals-table tr:last-child td,
  .totals-table tr:last-child td * {
    color: white !important;
  }
}