/* ═════════════════════════════════════════════════════════════
   POS Receipt & Invoice Print Styles
   Optimized for:
   - Desktop: 80mm (3-inch) thermal POS printer
   - Mobile:  58mm (2-inch) Bluetooth thermal printer
   - Also supports A4/A5 regular invoices
   ═════════════════════════════════════════════════════════════ */

/* ===== Base Print Styles ===== */
@media print {
    /* Force page to start at very top with NO margins */
    @page {
        size: auto;
        margin: 0mm !important;
        padding: 0 !important;
        marks: none;
    }

    /* Reset everything for printing */
    body, html {
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        width: 100% !important;
        background: white !important;
    }

    /* Hide everything except print area - using display:none instead of visibility:hidden to avoid gaps */
    body > *:not(.print-area):not(:has(.print-area)) {
        display: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    /* Hide non-essential elements */
    .card-header,
    .no-print,
    .modal-header,
    .modal-footer,
    .pos-mobile-topbar,
    .pos-products-panel,
    .pop-header,
    .pop-footer,
    nav,
    aside,
    header,
    footer,
    .sidebar,
    .navbar,
    .offcanvas,
    .modal-backdrop {
        display: none !important;
    }

    /* Position print area at the very top - NO extra spacing */
    .print-area {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        z-index: 99999 !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;
    }
}

/* ===== Paper Size Definitions ===== */
/* A4 (210 x 297 mm) with 10mm margins */
.paper-a4 {
    width: 190mm;
    min-height: 277mm;
    margin: 10mm auto;
    padding: 0;
    background: white;
}

/* A5 (148 x 210 mm) with 5mm margins */
.paper-a5 {
    width: 138mm;
    min-height: 200mm;
    margin: 5mm auto;
    padding: 0;
    background: white;
}

/* Thermal 2 inch (58mm) - mobile Bluetooth printer */
.paper-2inch {
    width: 48mm;
    min-height: auto;
    margin: 0 auto;
    padding: 0;
    background: white;
}

/* Thermal 3 inch (80mm) - desktop POS printer */
.paper-3inch {
    width: 72mm;
    min-height: auto;
    margin: 0 auto;
    padding: 0;
    background: white;
}

/* Thermal 4 inch (110mm) */
.paper-4inch {
    width: 100mm;
    min-height: auto;
    margin: 0 auto;
    padding: 0;
    background: white;
}

/* ===== Print-specific Paper Sizes ===== */
@media print {
    .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: 48mm !important;
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .paper-3inch {
        width: 72mm !important;
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .paper-4inch {
        width: 100mm !important;
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* ===== Thermal Printer Styles ===== */
.thermal-invoice {
    font-size: 14px !important;
    line-height: 1.35;
    width: 100%;
}

.thermal-invoice .rcpt-shell,
.thermal-invoice .rcpt {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif !important;
}

.thermal-invoice table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 13px !important;
}

.thermal-invoice th,
.thermal-invoice td {
    padding: 3px 2px !important;
    border: none !important;
    border-bottom: 1px dashed #000 !important;
}

.thermal-invoice .border-bottom {
    border-bottom: 1px dashed #000 !important;
}

/* ═══════════════════════════════════════════════════════════
   Professional Receipt (.rcpt) — blended POS style:
   purple banner + teal section bars + yellow accent stripe
   ═══════════════════════════════════════════════════════════ */
.rcpt-shell {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    max-width: 320px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #c4b8f0;
    border-radius: 0 10px 10px 0;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(44, 95, 95, 0.08), 0 2px 8px rgba(108, 92, 231, 0.12);
}

.rcpt-shell-accent {
    width: 11px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #ffd60a 0%, #ffc107 55%, #e6a800 100%);
    border-right: 2px solid #5b4fcf;
}

.rcpt {
    flex: 1;
    min-width: 0;
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.38;
    color: #1a1530;
    background: #fff;
    padding: 8px 10px 12px;
    max-width: none;
    margin: 0;
    position: relative;
}

/* subtle PAID-style watermark (screen + print-friendly grey) */
.rcpt::after {
    content: "";
    position: absolute;
    inset: 38% 4% auto;
    height: 22%;
    pointer-events: none;
    background: linear-gradient(135deg, transparent 42%, rgba(46, 196, 182, 0.06) 50%, transparent 58%);
    z-index: 0;
}

.rcpt > * {
    position: relative;
    z-index: 1;
}

.rcpt-copy-label {
    text-align: center;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 6px 4px;
    margin: -8px -10px 8px;
    color: #fff;
    background: linear-gradient(90deg, #2c5f5f 0%, #1e4545 100%);
}

.rcpt-title-band {
    text-align: right;
    margin: 0 -10px 10px;
    padding: 10px 12px 12px;
    background: linear-gradient(115deg, #6c5ce7 0%, #5b4fcf 45%, #4834a3 100%);
    color: #fff;
    border-bottom: 3px solid #ffd60a;
}

.rcpt-title-main {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    line-height: 1.15;
}

.rcpt-title-shop {
    margin-top: 4px;
    font-size: 15px;
    font-weight: 600;
    opacity: 0.95;
    letter-spacing: 0.02em;
}

.rcpt-header {
    text-align: center;
    padding-bottom: 6px;
}

.rcpt-logo {
    height: 48px;
    max-width: 78%;
    display: block;
    margin: 0 auto 6px auto;
}

.rcpt-company {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 4px;
    color: #2c5f5f;
    word-wrap: break-word;
}

.rcpt-addr {
    font-size: 13px;
    color: #3d3558;
    line-height: 1.35;
}

.rcpt-meta-muted {
    font-size: 12px;
    color: #6b6280;
    margin-top: 2px;
}

.rcpt-dash {
    border-bottom: 1px dashed #a89fd4;
    margin: 6px 0;
}

.rcpt-dash-double {
    border-bottom: 2px solid #e8e4f7;
    margin: 6px 0;
}

.rcpt-transaction-head {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #fff;
    background: #2c5f5f;
    margin: 0 -10px;
    padding: 6px 12px;
}

.rcpt-info {
    padding: 8px 0 4px;
    font-size: 14px;
}

.rcpt-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid #eef0f2;
}

.rcpt-row span:first-child {
    color: #4a4463;
    font-weight: 700;
    flex-shrink: 0;
}

.rcpt-row span:last-child {
    font-weight: 600;
    text-align: right;
    color: #1a1530;
    word-break: break-word;
}

.rcpt-soldto-bar {
    margin-top: 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #fff;
    background: #6c5ce7;
    padding: 5px 8px;
    margin-left: -10px;
    margin-right: -10px;
    padding-left: 18px;
}

.rcpt-soldto-value {
    font-size: 14px;
    font-weight: 600;
    color: #2c5f5f;
    padding: 6px 0 2px;
    border-bottom: 1px solid #d4e8e8;
}

.rcpt-items-head {
    display: flex;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(90deg, #5b4fcf 0%, #4834a3 100%);
    margin: 0 -10px;
    padding: 8px 10px;
}

.rcpt-items-head-line {
    height: 2px;
    background: #ffd60a;
    margin: 0 -10px 4px;
}

.rcpt-items-body {
    margin-bottom: 2px;
}

.rcpt-item {
    display: flex;
    padding: 6px 4px;
    font-size: 14px;
    border-bottom: 1px solid #eceaf5;
    background: #fff;
}

.rcpt-items-body .rcpt-item:nth-child(even) {
    background: #f7f5fc;
}

.rcpt-col-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 6px;
    font-weight: 600;
    color: #2a2440;
}

.rcpt-col-qty {
    width: 32px;
    text-align: center;
    flex-shrink: 0;
    font-weight: 700;
    color: #5b4fcf;
}

.rcpt-col-price {
    width: 78px;
    text-align: right;
    flex-shrink: 0;
    font-weight: 700;
    color: #1a1530;
}

.rcpt-totals {
    padding: 8px 0 4px;
}

.rcpt-total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 2px;
    font-size: 14px;
    font-weight: 600;
    color: #3d3558;
}

.rcpt-tax-rate-row span:first-child {
    color: #c0392b;
    font-weight: 700;
}

.rcpt-grand-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 10px 12px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(90deg, #6c5ce7 0%, #4834a3 100%);
    border-radius: 4px;
    box-shadow: 0 3px 0 #ffd60a;
}

.rcpt-grand-currency {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #c8f5e0;
}

.rcpt-payment {
    padding: 6px 0 4px;
    font-size: 14px;
}

.rcpt-ref {
    font-size: 13px;
    color: #4a4463;
    text-align: center;
    padding: 3px 0;
    font-weight: 500;
}

.rcpt-barcode {
    text-align: center;
    padding: 8px 0 6px;
}

.rcpt-barcode svg {
    max-width: 80%;
    height: 44px;
}

.rcpt-footer {
    text-align: center;
    padding-top: 10px;
    padding-bottom: 8px;
    border-top: 1px solid #e8e4f7;
    margin-top: 6px;
}

.rcpt-footer-note {
    font-size: 12px;
    color: #4a4463;
    margin-bottom: 6px;
    line-height: 1.4;
    text-align: left;
}

.rcpt-thankyou {
    font-size: 17px;
    font-weight: 800;
    font-style: italic;
    letter-spacing: 0.04em;
    color: #5b4fcf;
    margin-top: 6px;
}

.rcpt-comeback {
    font-size: 12px;
    color: #6b6280;
    margin-top: 6px;
    line-height: 1.45;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.rcpt-footer-space {
    height: 6px;
}

.rcpt-dev-credit {
    font-size: 7px;
    line-height: 1.1;
    color: #8a8499;
    letter-spacing: 0;
    padding: 2px 0 0;
    margin-top: 0;
    border-top: 0;
    text-align: center;
}

/* ─── Print overrides for receipt - DESKTOP 80mm thermal ───
     KEY FIX: Font sizes are NOW LARGE ENOUGH to read on thermal paper.
     Previous sizes (10-12px) were too small for thermal printers.
     80mm thermal printers need 14-22px fonts for readability.
   ─────────────────────────────────────────────────────────── */
@media print {
    .rcpt-shell {
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .rcpt {
        padding: 6px 8px 10px !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
        font-size: 15px !important;
    }

    .rcpt-title-main {
        font-size: 17px !important;
    }

    .rcpt-title-shop {
        font-size: 14px !important;
    }

    .rcpt-company {
        font-size: 17px !important;
    }

    .rcpt-addr {
        font-size: 13px !important;
    }

    .rcpt-copy-label {
        font-size: 13px !important;
    }

    .rcpt-info {
        font-size: 14px !important;
    }

    .rcpt-items-head {
        font-size: 11px !important;
    }

    .rcpt-item {
        font-size: 14px !important;
    }

    .rcpt-total-row {
        font-size: 14px !important;
    }

    .rcpt-grand-bar {
        font-size: 14px !important;
        padding: 8px 10px !important;
    }

    .rcpt-grand-currency {
        font-size: 17px !important;
    }

    .rcpt-payment {
        font-size: 14px !important;
    }

    .rcpt-ref {
        font-size: 13px !important;
    }

    .rcpt-thankyou {
        font-size: 16px !important;
    }

    .rcpt-comeback {
        font-size: 11px !important;
    }

    .rcpt-footer-note {
        font-size: 11px !important;
    }

    .rcpt-dev-credit {
        font-size: 6px !important;
        line-height: 1.05 !important;
    }

    .rcpt-barcode svg {
        height: 44px !important;
    }

    .rcpt-logo {
        max-width: 55mm !important;
        height: 44px !important;
    }
}

/* ===== Regular Invoice Styles ===== */
.regular-invoice {
    font-family: Arial, sans-serif !important;
}

.regular-invoice table {
    width: 100% !important;
    border-collapse: collapse !important;
}

.regular-invoice th,
.regular-invoice td {
    padding: 5px !important;
}

.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 must remain visible on screen; hide only when printing */
.print-only {
    display: none;
}

@media print {
    .print-only {
        display: block !important;
    }

    .no-print {
        display: none !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 background colors to print */
    .bg-white, .bg-light {
        background-color: white !important;
        -webkit-print-color-adjust: exact;
    }
}

/* ===== Force visibility of all elements in print area ===== */
@media print {
    .print-area,
    .print-area *,
    .print-area table *,
    .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;
        -webkit-print-color-adjust: exact;
    }

    .thermal-invoice td {
        padding: 2px 1px !important;
        -webkit-print-color-adjust: exact;
    }
}
