﻿/* ===== Base Print Styles ===== */
@media print {
    /* Reset everything for printing */
    body, html {
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        width: 100% !important;
        background: white !important;
        font-family: Arial, sans-serif !important;
    }

        /* Hide everything except print area */
        body * {
            visibility: hidden;
            margin: 0 !important;
            padding: 0 !important;
        }

    .print-area, .print-area * {
        visibility: visible;
    }

    /* Force print area to take full width */
    .print-area {
        position: absolute !important;
        top: -40px !important;
        left: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        page-break-before: avoid !important;
        page-break-after: avoid !important;
    }

    /* Print color adjustments */
    * {
        -webkit-print-color-adjust: exact !important;
        color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Remove all decorations */
    .card, .shadow-sm, .border-0, .rounded {
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        background: transparent !important;
    }

    /* Hide non-essential elements */
    .card-header, .no-print {
        display: none !important;
    }
}

/* ===== Paper Size Definitions ===== */
/* A4 (210 × 297 mm) with 10mm margins */
.paper-a4 {
    width: 190mm; /* 210 - 20mm */
    min-height: 277mm; /* 297 - 20mm */
    margin: 10mm auto;
    padding: 0;
    background: white;
}

/* A5 (148 × 210 mm) with 5mm margins */
.paper-a5 {
    width: 138mm; /* 148 - 10mm */
    min-height: 200mm; /* 210 - 10mm */
    margin: 5mm auto;
    padding: 0;
    background: white;
}

/* Thermal 2 inch (58mm) */
.paper-2inch {
    width: 56mm; /* 58 - 2mm */
    min-height: auto;
    margin: 1mm auto;
    padding: 0;
    background: white;
}

/* Thermal 3 inch (80mm) */
.paper-3inch {
    width: 78mm; /* 80 - 2mm */
    min-height: auto;
    margin: 1mm auto;
    padding: 0;
    background: white;
}

/* Thermal 4 inch (110mm) */
.paper-4inch {
    width: 108mm; /* 110 - 2mm */
    min-height: auto;
    margin: 1mm auto;
    padding: 0;
    background: white;
}

/* ===== Print-specific Paper Sizes ===== */
@media print {
    @page {
        size: auto;
        margin: 0mm;
        marks: none;
    }

    .paper-a4 {
        width: 190mm !important;
        min-height: 277mm !important;
        margin: 10mm auto !important;
        padding: 0 !important;
    }

    .paper-a5 {
        width: 138mm !important;
        min-height: 200mm !important;
        margin: 5mm auto !important;
        padding: 0 !important;
    }

    .paper-2inch {
        width: 56mm !important;
        min-height: auto !important;
        margin: 1mm auto !important;
        padding: 0 !important;
    }

    .paper-3inch {
        width: 78mm !important;
        min-height: auto !important;
        margin: 1mm auto !important;
        padding: 0 !important;
    }

    .paper-4inch {
        width: 108mm !important;
        min-height: auto !important;
        margin: 1mm auto !important;
        padding: 0 !important;
    }
}

/* ===== Thermal Printer Styles ===== */
.thermal-invoice {
    font-family: monospace !important;
    font-size: 10px !important;
    line-height: 1.2;
    width: 100%;
}

    .thermal-invoice table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 9px !important;
    }

    .thermal-invoice th,
    .thermal-invoice td {
        padding: 2px !important;
        border: none !important;
        border-bottom: 1px dashed #ccc !important;
    }

    .thermal-invoice .border-bottom {
        border-bottom: 1px dashed #000 !important;
    }

/* ===== Regular Invoice Styles ===== */
.regular-invoice {
    font-family: Arial, sans-serif !important;
}

    /* Ensure tables maintain their layout */
    .regular-invoice table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    .regular-invoice th,
    .regular-invoice td {
        padding: 5px !important;
    }

    /* Maintain borders in print */
    .regular-invoice .border-top {
        border-top: 1px solid #dee2e6 !important;
    }

    .regular-invoice .border-bottom {
        border-bottom: 1px solid #dee2e6 !important;
    }

/* ===== Print Utility Classes ===== */
.no-print {
    display: none !important;
}

.print-only {
    display: none;
}

@media print {
    .d-flex {
        display: none !important;
    }

    .col-lg-4 {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .no-print {
        display: none !important;
    }

    /* Ensure images print properly */
    img {
        max-width: 60px !important;
        height: 60px !important;
    }

    /* Force background colors to print */
    .bg-white, .bg-light {
        background-color: white !important;
        -webkit-print-color-adjust: exact;
    }

    /* Maintain padding in print */
    .p-4 {
        padding: 1.5rem !important;
    }

    /* Maintain margins in print */
    .my-1 {
        margin-top: 0.25rem !important;
        margin-bottom: 0.25rem !important;
    }

    /* Fix for Java print service */
    br {
        line-height: 1 !important;
        height: auto !important;
    }

    /* Ensure proper alignment */
    .text-right {
        text-align: right !important;
    }

    .text-center {
        text-align: center !important;
    }

    /* Maintain font weights */
    .font-weight-bold {
        font-weight: bold !important;
    }
}

/* ===== Force visibility of all elements in print area ===== */
@media print {
    .print-area * {
        visibility: visible !important;
    }

    .print-area table * {
        visibility: visible !important;
    }

    .print-area tr,
    .print-area td,
    .print-area th {
        visibility: visible !important;
    }
}

/* ===== Ensure proper spacing in thermal print ===== */
@media print {
    .thermal-invoice tr {
        page-break-inside: avoid !important;
    }

    .thermal-invoice td {
        padding: 1px 0 !important;
    }
}

/* ===== Fix for dashed borders in print ===== */
@media print {
    .thermal-invoice tr {
        -webkit-print-color-adjust: exact;
    }

    .thermal-invoice td {
        -webkit-print-color-adjust: exact;
    }
}
