/**
 * Invoice & receipt print protection
 * Keeps all invoices/receipts in light mode for preview and printing,
 * regardless of application dark mode or browser "Background graphics" setting.
 */

/* ── Screen: invoice preview areas stay light in dark mode ── */
body.dark-mode .invoice-print-light,
body.dark-mode #receipt_section,
body.dark-mode #invoice_content,
body.dark-mode #pos_invoice_preview_content,
body.dark-mode #installment_section,
body.dark-mode #pos_invoice_preview_modal .modal-content,
body.dark-mode #pos_invoice_preview_modal .modal-header,
body.dark-mode #pos_invoice_preview_modal .modal-body,
body.dark-mode #pos_invoice_preview_modal .modal-footer {
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    color: #000000 !important;
    color-scheme: light;
}

body.dark-mode #pos_invoice_preview_modal .modal-header,
body.dark-mode #pos_invoice_preview_modal .modal-footer {
    border-color: #dee2e6 !important;
}

body.dark-mode #pos_invoice_preview_modal .modal-title,
body.dark-mode #pos_invoice_preview_modal .close,
body.dark-mode #pos_invoice_preview_modal .btn {
    color: #000000 !important;
}

body.dark-mode .invoice-print-light *,
body.dark-mode #receipt_section *,
body.dark-mode #invoice_content *,
body.dark-mode #pos_invoice_preview_content *,
body.dark-mode #installment_section * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-scheme: light;
}

body.dark-mode .invoice-print-light table,
body.dark-mode #receipt_section table,
body.dark-mode #invoice_content table,
body.dark-mode #pos_invoice_preview_content table,
body.dark-mode .invoice-print-light .table,
body.dark-mode #receipt_section .table,
body.dark-mode #invoice_content .table,
body.dark-mode #pos_invoice_preview_content .table {
    background-color: #ffffff !important;
    color: #000000 !important;
}

body.dark-mode .invoice-print-light table td,
body.dark-mode .invoice-print-light table th,
body.dark-mode .invoice-print-light table tr,
body.dark-mode #receipt_section table td,
body.dark-mode #receipt_section table th,
body.dark-mode #receipt_section table tr,
body.dark-mode #invoice_content table td,
body.dark-mode #invoice_content table th,
body.dark-mode #invoice_content table tr,
body.dark-mode #pos_invoice_preview_content table td,
body.dark-mode #pos_invoice_preview_content table th,
body.dark-mode #pos_invoice_preview_content table tr,
body.dark-mode .invoice-print-light .table > thead > tr > th,
body.dark-mode .invoice-print-light .table > thead > tr > td,
body.dark-mode .invoice-print-light .table > tbody > tr > td,
body.dark-mode .invoice-print-light .table > tbody > tr > th,
body.dark-mode #receipt_section .table > thead > tr > th,
body.dark-mode #receipt_section .table > thead > tr > td,
body.dark-mode #receipt_section .table > tbody > tr > td,
body.dark-mode #receipt_section .table > tbody > tr > th,
body.dark-mode #invoice_content .table > thead > tr > th,
body.dark-mode #invoice_content .table > thead > tr > td,
body.dark-mode #invoice_content .table > tbody > tr > td,
body.dark-mode #invoice_content .table > tbody > tr > th,
body.dark-mode #pos_invoice_preview_content .table > thead > tr > th,
body.dark-mode #pos_invoice_preview_content .table > thead > tr > td,
body.dark-mode #pos_invoice_preview_content .table > tbody > tr > td,
body.dark-mode #pos_invoice_preview_content .table > tbody > tr > th {
    background-color: #ffffff !important;
    background-image: none !important;
    color: #000000 !important;
    border-color: #dee2e6 !important;
}

body.dark-mode .invoice-print-light h1,
body.dark-mode .invoice-print-light h2,
body.dark-mode .invoice-print-light h3,
body.dark-mode .invoice-print-light h4,
body.dark-mode .invoice-print-light h5,
body.dark-mode .invoice-print-light h6,
body.dark-mode .invoice-print-light p,
body.dark-mode .invoice-print-light span,
body.dark-mode .invoice-print-light small,
body.dark-mode .invoice-print-light label,
body.dark-mode .invoice-print-light div,
body.dark-mode .invoice-print-light b,
body.dark-mode .invoice-print-light strong,
body.dark-mode .invoice-print-light li,
body.dark-mode .invoice-print-light .row,
body.dark-mode .invoice-print-light [class*="col-"],
body.dark-mode .invoice-print-light .invoice-info,
body.dark-mode .invoice-print-light .invoice-col,
body.dark-mode #receipt_section h1,
body.dark-mode #receipt_section h2,
body.dark-mode #receipt_section h3,
body.dark-mode #receipt_section h4,
body.dark-mode #receipt_section p,
body.dark-mode #receipt_section span,
body.dark-mode #receipt_section small,
body.dark-mode #receipt_section div,
body.dark-mode #receipt_section b,
body.dark-mode #receipt_section strong,
body.dark-mode #receipt_section .row,
body.dark-mode #receipt_section [class*="col-"],
body.dark-mode #invoice_content h1,
body.dark-mode #invoice_content h2,
body.dark-mode #invoice_content h3,
body.dark-mode #invoice_content p,
body.dark-mode #invoice_content span,
body.dark-mode #invoice_content small,
body.dark-mode #invoice_content div,
body.dark-mode #invoice_content b,
body.dark-mode #invoice_content strong,
body.dark-mode #invoice_content .row,
body.dark-mode #invoice_content [class*="col-"],
body.dark-mode #pos_invoice_preview_content h1,
body.dark-mode #pos_invoice_preview_content h2,
body.dark-mode #pos_invoice_preview_content h3,
body.dark-mode #pos_invoice_preview_content p,
body.dark-mode #pos_invoice_preview_content span,
body.dark-mode #pos_invoice_preview_content small,
body.dark-mode #pos_invoice_preview_content div,
body.dark-mode #pos_invoice_preview_content b,
body.dark-mode #pos_invoice_preview_content strong,
body.dark-mode #pos_invoice_preview_content .row,
body.dark-mode #pos_invoice_preview_content [class*="col-"] {
    background-color: #ffffff !important;
    background-image: none !important;
    color: #000000 !important;
}

body.dark-mode .invoice-print-light .text-muted,
body.dark-mode .invoice-print-light .text-muted-imp,
body.dark-mode #receipt_section .text-muted,
body.dark-mode #receipt_section .text-muted-imp,
body.dark-mode #invoice_content .text-muted,
body.dark-mode #invoice_content .text-muted-imp,
body.dark-mode #pos_invoice_preview_content .text-muted,
body.dark-mode #pos_invoice_preview_content .text-muted-imp {
    color: #6c757d !important;
}

body.dark-mode .invoice-print-light a,
body.dark-mode #receipt_section a,
body.dark-mode #invoice_content a,
body.dark-mode #pos_invoice_preview_content a,
body.dark-mode #installment_section a {
    color: #000000 !important;
}

body.dark-mode .invoice-print-light .bg-light-blue-active,
body.dark-mode #receipt_section .bg-light-blue-active,
body.dark-mode #invoice_content .bg-light-blue-active,
body.dark-mode #pos_invoice_preview_content .bg-light-blue-active,
body.dark-mode #installment_section .bg-light-blue-active {
    background-color: #3c8dbc !important;
    color: #ffffff !important;
}

/* ── Print: force light output; only receipt height drives pages ── */
@media print {
    :root,
    html,
    html:has(body.dark-mode),
    html:has(body.dark-mode).tw-bg-white,
    html.tw-bg-white,
    body,
    body.dark-mode {
        color-scheme: light only !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        background-image: none !important;
        color: #000000 !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    *,
    *::before,
    *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    html,
    html:has(body.dark-mode),
    html:has(body.dark-mode).tw-bg-white,
    body,
    body.dark-mode,
    body.dark-mode main,
    body.dark-mode #scrollable-container,
    body.dark-mode .content-wrapper,
    body.dark-mode section.content,
    body.dark-mode .thetop,
    body.dark-mode .wrapper,
    main,
    .wrapper,
    .content-wrapper,
    #scrollable-container,
    section.content,
    .thetop {
        background: #ffffff !important;
        background-color: #ffffff !important;
        background-image: none !important;
        color: #000000 !important;
        box-shadow: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /*
     * Remove non-print chrome from layout flow (visibility:hidden still
     * reserves ~100vh POS height and creates blank pages).
     */
    .no-print,
    .modal,
    .modal-backdrop,
    .overlay,
    .sidebar-mobile-overlay,
    #toast-container,
    .pos-header,
    .pos-bottom-bar,
    .pos-quick-actions,
    .pos-quick-actions-panel,
    .pos-quick-actions-tab,
    #pos_invoice_preview_modal,
    .main-sidebar,
    .main-header,
    .tw-dw-drawer-side,
    .page-back-bar,
    .scrolltop {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        position: static !important;
        box-shadow: none !important;
        background: transparent !important;
        background-color: transparent !important;
    }

    /* When printing #receipt_section, drop POS/app chrome that sits beside it */
    body.is-printing #app,
    body.is-printing #scrollable-container,
    body.is-printing .pos-screen,
    body.is-printing .pos-design,
    body.is-printing .pos-wrapper,
    body.is-printing .dreams-pos-row,
    body.is-printing .legacy-pos-chrome-hide {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
    }

    /*
     * Collapse flex shells (thetop / main.tw-flex-1.tw-h-full) so they do not
     * keep a full viewport height and force a blank second page.
     */
    body.is-printing,
    body.is-printing.html,
    html:has(body.is-printing) {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body.is-printing .thetop {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        align-items: flex-start !important;
    }

    body.is-printing .thetop > aside,
    body.is-printing .thetop > .side-bar,
    body.is-printing .thetop > div:not(.print_section):has(.overlay),
    body.is-printing .thetop > div:not(.print_section):has(.sidebar-mobile-overlay),
    body.is-printing .thetop > *:not(main) {
        display: none !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
    }

    body.is-printing main,
    body.is-printing main.tw-flex,
    body.is-printing main.tw-flex-1,
    body.is-printing main.tw-h-full,
    body.lockscreen.is-printing main,
    body.pos-page.is-printing main {
        display: block !important;
        flex: none !important;
        flex-grow: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body.is-printing main > *:not(.print_section):not(#receipt_section):not(#invoice_content):not(#installment_section) {
        display: none !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    /* Only print invoice/receipt content — keep in normal flow */
    .print_section,
    .print_section *,
    #receipt_section,
    #receipt_section *,
    #invoice_content,
    #invoice_content *,
    #installment_section,
    #installment_section *,
    .invoice-print-light,
    .invoice-print-light *,
    .hc-print-area,
    .hc-print-area *,
    .healthcare-module-page,
    .healthcare-module-page *,
    .hms-module-page .content,
    .hms-module-page .content * {
        visibility: visible !important;
    }

    .print_section,
    #receipt_section,
    #invoice_content,
    #installment_section,
    .invoice-print-light,
    .hc-print-area,
    .healthcare-module-page,
    .hms-module-page .content {
        display: block !important;
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
        background-image: none !important;
        color: #000000 !important;
        border: none !important;
        box-shadow: none !important;
        page-break-after: avoid !important;
        break-after: avoid-page !important;
    }

    body.is-printing .print_section,
    body.is-printing #receipt_section,
    body.is-printing #invoice_content,
    body.is-printing #installment_section,
    body.is-printing .invoice-print-light {
        display: block !important;
        visibility: visible !important;
    }

    body.dark-mode .print_section,
    body.dark-mode .print_section *,
    body.dark-mode #receipt_section,
    body.dark-mode #receipt_section *,
    body.dark-mode #invoice_content,
    body.dark-mode #invoice_content *,
    body.dark-mode .invoice-print-light,
    body.dark-mode .invoice-print-light *,
    body.dark-mode #installment_section,
    body.dark-mode #installment_section * {
        background: #ffffff !important;
        background-color: #ffffff !important;
        background-image: none !important;
        color: #000000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    body.dark-mode .print_section table,
    body.dark-mode .print_section table td,
    body.dark-mode .print_section table th,
    body.dark-mode .print_section table tr,
    body.dark-mode #receipt_section table,
    body.dark-mode #receipt_section table td,
    body.dark-mode #receipt_section table th,
    body.dark-mode #receipt_section table tr,
    body.dark-mode #invoice_content table,
    body.dark-mode #invoice_content table td,
    body.dark-mode #invoice_content table th,
    body.dark-mode #invoice_content table tr,
    body.dark-mode .invoice-print-light table,
    body.dark-mode .invoice-print-light table td,
    body.dark-mode .invoice-print-light table th,
    body.dark-mode .invoice-print-light table tr,
    body.dark-mode .print_section .table > thead > tr > th,
    body.dark-mode .print_section .table > thead > tr > td,
    body.dark-mode .print_section .table > tbody > tr > td,
    body.dark-mode .print_section .table > tbody > tr > th,
    body.dark-mode #receipt_section .table > thead > tr > th,
    body.dark-mode #receipt_section .table > thead > tr > td,
    body.dark-mode #receipt_section .table > tbody > tr > td,
    body.dark-mode #receipt_section .table > tbody > tr > th {
        background-color: #ffffff !important;
        color: #000000 !important;
        border-color: #dee2e6 !important;
    }

    body.dark-mode .print_section h1,
    body.dark-mode .print_section h2,
    body.dark-mode .print_section h3,
    body.dark-mode .print_section h4,
    body.dark-mode .print_section h5,
    body.dark-mode .print_section h6,
    body.dark-mode .print_section p,
    body.dark-mode .print_section span,
    body.dark-mode .print_section small,
    body.dark-mode .print_section label,
    body.dark-mode .print_section div,
    body.dark-mode .print_section b,
    body.dark-mode .print_section strong,
    body.dark-mode .print_section .row,
    body.dark-mode .print_section [class*="col-"],
    body.dark-mode #receipt_section h1,
    body.dark-mode #receipt_section h2,
    body.dark-mode #receipt_section h3,
    body.dark-mode #receipt_section p,
    body.dark-mode #receipt_section span,
    body.dark-mode #receipt_section small,
    body.dark-mode #receipt_section div,
    body.dark-mode #receipt_section b,
    body.dark-mode #receipt_section strong,
    body.dark-mode #receipt_section .row,
    body.dark-mode #receipt_section [class*="col-"],
    body.dark-mode #invoice_content h1,
    body.dark-mode #invoice_content h2,
    body.dark-mode #invoice_content h3,
    body.dark-mode #invoice_content p,
    body.dark-mode #invoice_content span,
    body.dark-mode #invoice_content small,
    body.dark-mode #invoice_content div,
    body.dark-mode #invoice_content b,
    body.dark-mode #invoice_content strong {
        background-color: #ffffff !important;
        color: #000000 !important;
    }

    body.dark-mode .print_section .text-muted,
    body.dark-mode .print_section .text-muted-imp,
    body.dark-mode #receipt_section .text-muted,
    body.dark-mode #receipt_section .text-muted-imp,
    body.dark-mode #invoice_content .text-muted,
    body.dark-mode #invoice_content .text-muted-imp {
        color: #6c757d !important;
    }
}
