﻿/* ===== 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;
}

.paper-a4-landscape {
    width: 277mm;
    min-height: 190mm;
    margin: 10mm auto;
    background: white;
}

.paper-a5-landscape {
    width: 200mm;
    min-height: 138mm;
    margin: 5mm auto;
    background: white;
}

/* Thermal 2 inch (58mm) */
.paper-2inch {
    width: 56mm; /* 58 - 2mm */
    min-height: auto;
    margin: 1mm auto;
    padding: 0;
    background: white;
}

/* Thermal 68mm */
.paper-3inch {
    width: 66mm;
    min-height: auto;
    margin: 1mm auto;
    padding: 0;
    background: white;
}

/* Thermal 88mm */
.paper-4inch {
    width: 86mm;
    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-a4-landscape {
        width: 277mm !important;
        min-height: 190mm !important;
        margin: 10mm auto !important;
    }

    .paper-a5-landscape {
        width: 200mm !important;
        min-height: 138mm !important;
        margin: 5mm auto !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%;
}

.invoice-preview {
    transition: width .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.invoice-theme-normal {
    padding: 10mm;
    box-shadow: 0 12px 35px rgba(15, 23, 42, .12);
}

.invoice-theme-tally {
    padding: 8mm;
    border-top: 6px solid #2563eb;
}

.invoice-theme-tally table {
    border-radius: 0 !important;
}

.invoice-theme-vat {
    padding: 9mm;
    border: 2px solid #198754;
    box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 5px #bbf7d0;
}

.invoice-theme-landscape {
    padding: 8mm 12mm;
    border-top: 6px solid #f59e0b;
}

.thermal-theme-compact {
    line-height: 1.05;
}

.thermal-theme-compact th,
.thermal-theme-compact td {
    padding: 1px 0 !important;
}

.thermal-theme-classic {
    border: 1px dashed #111;
    padding: 2mm;
}

.thermal-theme-bold {
    border: 2px solid #111;
    padding: 2mm;
    font-weight: 600;
}

.thermal-theme-bold th,
.thermal-theme-bold td {
    border-bottom: 1px solid #111 !important;
}

    .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;
    }
}
