/**
 * UNIVERSAL PRINT FIX CSS
 * ========================================
 * Comprehensive print stylesheet for all invoice/document pages
 * Ensures proper printing across all browsers (Chrome, Edge, Firefox)
 * Version: 2.0
 * Last Updated: 2026-07-28
 */

/* ========================================
   PRINT MEDIA QUERY - All print-specific styles
   ======================================== */
@media print {
    
    /* ========================================
       PAGE SETUP - Critical for A4 sizing
       ======================================== */
    @page {
        size: A4 portrait;
        margin: 10mm 12mm;
    }
    
    /* ========================================
       HTML & BODY RESET
       ======================================== */
    html {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        background: white;
    }
    
    body {
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        color: #000 !important;
        font-size: 9pt !important;
        line-height: 1.35 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
        overflow: visible !important;
    }
    
    * {
        box-sizing: border-box !important;
    }
    
    /* ========================================
       HIDE SCREEN-ONLY ELEMENTS
       ======================================== */
    .no-print,
    .print-actions,
    .invoice-actions,
    .toolbar,
    .btn-group,
    .btn,
    button,
    nav,
    aside,
    .navbar,
    .sidebar,
    .app-header,
    .app-sidebar,
    .screen-card,
    .modal,
    .alert,
    .breadcrumb,
    .pagination,
    header:not(.invoice-header):not(.doc-header),
    footer:not(.invoice-footer):not(.doc-footer),
    [class*="action"]:not([class*="transaction"]),
    [class*="toolbar"],
    [data-print="hide"],
    .d-print-none {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* ========================================
       CONTAINER NORMALIZATION
       ======================================== */
    .container,
    .container-fluid,
    .content-wrapper,
    .main-content,
    .invoice-shell,
    .invoice-container,
    .invoice-paper,
    .page-container,
    .print-container,
    .document-container,
    .wrap,
    .page,
    .receipt,
    .card,
    .card-body {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
        background: white !important;
        overflow: visible !important;
    }
    
    /* ========================================
       INVOICE DOCUMENT BORDERS
       ======================================== */
    .invoice,
    .invoice-document,
    .receipt {
        border: 2px solid #000 !important;
        padding: 5mm !important;
    }
    
    /* ========================================
       TABLE STYLES - Critical for proper rendering
       ======================================== */
    table {
        width: 100% !important;
        max-width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto !important;
        border: 1px solid #000 !important;
    }
    
    .table,
    .data-table,
    .invoice-table,
    .items-table,
    .tax-table,
    .dispatch-table,
    .eway-table,
    .payment-table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto !important;
    }
    
    /* Table Headers */
    thead {
        display: table-header-group !important;
        page-break-inside: avoid !important;
        page-break-after: avoid !important;
    }
    
    thead th {
        background: #f3f4f6 !important;
        border: 1px solid #000 !important;
        padding: 4mm 2mm !important;
        text-align: center !important;
        font-weight: 700 !important;
        font-size: 8pt !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Table Body */
    tbody {
        display: table-row-group !important;
    }
    
    tbody tr {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }
    
    tbody td {
        border: 1px solid #000 !important;
        padding: 3mm 2mm !important;
        vertical-align: top !important;
        font-size: 8.5pt !important;
    }
    
    /* Table Footer */
    tfoot {
        display: table-footer-group !important;
        page-break-inside: avoid !important;
    }
    
    tfoot td {
        border: 1px solid #000 !important;
        padding: 3mm 2mm !important;
        font-weight: 700 !important;
    }
    
    /* ========================================
       BORDERS FOR SECTIONS
       ======================================== */
    .invoice-section,
    .irn-block,
    .party-meta-grid,
    .party-grid,
    .meta-grid,
    .amount-balance-grid,
    .summary-grid,
    .words-balance,
    .footer-grid,
    .bank-sign,
    .irn-line,
    .top-title,
    .head {
        page-break-inside: avoid !important;
        border: 1px solid #000 !important;
    }
    
    /* Internal borders */
    .party-column,
    .seller-buyer,
    .column,
    .summary-left,
    .summary-note,
    .words,
    .declaration {
        border-right: 1px solid #000 !important;
    }
    
    .meta-cell {
        border-right: 1px solid #000 !important;
        border-bottom: 1px solid #000 !important;
        padding: 2mm !important;
    }
    
    .qr-box {
        border-left: 1px solid #000 !important;
    }
    
    /* ========================================
       TYPOGRAPHY
       ======================================== */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
        margin: 2mm 0 !important;
        color: #000 !important;
    }
    
    p {
        margin: 1mm 0 !important;
        orphans: 3 !important;
        widows: 3 !important;
    }
    
    .bold,
    .fw-bold,
    .font-weight-bold,
    strong,
    b {
        font-weight: 700 !important;
    }
    
    /* Text Alignment */
    .text-center,
    .center {
        text-align: center !important;
    }
    
    .text-right,
    .right {
        text-align: right !important;
    }
    
    .text-left {
        text-align: left !important;
    }
    
    /* ========================================
       IMAGES & MEDIA
       ======================================== */
    img,
    svg {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid !important;
    }
    
    .company-logo,
    .logo,
    .logo img {
        max-width: 30mm !important;
        max-height: 15mm !important;
        object-fit: contain !important;
    }
    
    .qr-code,
    .qr-box img {
        width: 25mm !important;
        height: 25mm !important;
        object-fit: contain !important;
    }
    
    /* ========================================
       PAGE BREAK CONTROL
       ======================================== */
    .page-break,
    .page-break-before {
        page-break-before: always !important;
        break-before: page !important;
    }
    
    .page-break-after {
        page-break-after: always !important;
        break-after: page !important;
    }
    
    .no-page-break,
    .avoid-page-break,
    .keep-together {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
    
    /* Sections that should stay together */
    .signature-section,
    .signature,
    .bank-details,
    .bank,
    .terms-section,
    .terms-block,
    .summary-section,
    .totals-section,
    .invoice-summary,
    .tax-summary,
    .amount-box,
    .info-grid,
    .info-card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
    
    /* ========================================
       COLORS & BACKGROUNDS
       ======================================== */
    .highlight,
    thead th,
    .table-header,
    thead,
    .info-card,
    .amount-box {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    /* Keep specific backgrounds */
    .bg-success,
    .bg-primary,
    .bg-danger,
    .bg-warning {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* ========================================
       LINKS
       ======================================== */
    a {
        text-decoration: none !important;
        color: inherit !important;
    }
    
    a[href]:after {
        content: none !important;
    }
    
    /* ========================================
       SPACING & LAYOUT
       ======================================== */
    .mb-0 { margin-bottom: 0 !important; }
    .mt-0 { margin-top: 0 !important; }
    .p-0 { padding: 0 !important; }
    .m-0 { margin: 0 !important; }
    
    /* Remove excessive spacing */
    br {
        line-height: 1.2 !important;
    }
    
    /* ========================================
       GRID & FLEX LAYOUTS
       ======================================== */
    .row,
    [class*="grid"],
    .d-flex,
    .flex {
        page-break-inside: avoid !important;
    }
    
    .col,
    [class*="col-"] {
        float: none !important;
        width: auto !important;
    }
    
    /* ========================================
       OVERFLOW & VISIBILITY
       ======================================== */
    * {
        overflow: visible !important;
    }
    
    .table-responsive {
        overflow: visible !important;
    }
    
    /* ========================================
       MISC UTILITIES
       ======================================== */
    .nowrap {
        white-space: nowrap !important;
    }
    
    .wrap {
        overflow-wrap: break-word !important;
        word-break: break-word !important;
    }
    
    /* Amount styling */
    .amount,
    .total-amount,
    [class*="amount"] {
        font-weight: 700 !important;
        font-family: 'Courier New', monospace !important;
    }
    
    /* Status badges */
    .status-badge,
    .badge {
        border: 1px solid #000 !important;
        padding: 1mm 2mm !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* ========================================
       FOOTER
       ======================================== */
    .invoice-footer,
    .doc-footer,
    .footer {
        page-break-inside: avoid !important;
        border-top: 1px solid #000 !important;
        margin-top: 5mm !important;
        padding-top: 3mm !important;
    }
    
    /* Computer-generated note */
    .computer-note,
    .footer p {
        font-size: 7pt !important;
        color: #666 !important;
        text-align: center !important;
    }
}

/* ========================================
   SCREEN PREVIEW (Optional)
   ======================================== */
@media screen {
    .print-preview {
        max-width: 210mm;
        margin: 20px auto;
        padding: 10mm;
        background: white;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}
