/* =========================================================
   PREMIUM QR CODES — INVOICE MAKER
   MOBILE LIVE PREVIEW FIT
   Desktop / print document dimensions remain unchanged.
   ========================================================= */

.invoice-preview-column,
.invoice-paper-stage {
    min-width: 0;
    max-width: 100%;
}


/*
 * Only the on-screen mobile preview is visually scaled.
 * Do not apply this during print/export.
 */
@media screen and (max-width: 900px) {

    .invoice-preview-column {
        position: static !important;
        top: auto !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }


    .invoice-preview-toolbar {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }


    .invoice-paper-stage {
        position: relative;
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;

        overflow: hidden !important;

        box-sizing: border-box;
    }


    /*
     * JS supplies:
     *
     * --invoice-preview-scale
     * --invoice-preview-height
     *
     * We scale the visual document instead of changing
     * its actual A4/Letter layout width.
     */
    .invoice-paper-stage.is-mobile-preview-scaled {
        height:
            var(
                --invoice-preview-height,
                auto
            ) !important;
    }


    .invoice-paper-stage.is-mobile-preview-scaled
    #invoicePreview {

        transform:
            scale(
                var(
                    --invoice-preview-scale,
                    1
                )
            ) !important;

        transform-origin:
            top left !important;

        margin-left: 0 !important;
        margin-right: 0 !important;
    }

}


/* Smaller phones */
@media screen and (max-width: 520px) {

    .invoice-preview-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }


    .invoice-preview-toolbar > div {
        min-width: 0;
        flex: 1 1 auto;
    }


    .invoice-preview-badge {
        flex: 0 0 auto;
        white-space: nowrap;
    }

}


/* =========================================================
   R12M2 — TRUE A4 MOBILE CANVAS
   Keep the invoice document at A4 desktop dimensions and
   scale the complete visual sheet to the phone viewport.
   Screen preview only — never print/export.
   ========================================================= */

@media screen and (max-width: 900px) {

    /*
     * A4 = 210 mm = approximately 793.7 CSS px at 96 dpi.
     *
     * The invoice must retain this natural layout width.
     * The JS scaler then fits the whole canvas into the
     * available mobile preview area.
     */
    .invoice-paper-stage #invoicePreview {
        width: 210mm !important;
        min-width: 210mm !important;
        max-width: none !important;

        box-sizing: border-box !important;

        flex: none !important;

        transform-origin: top left !important;
    }


    /*
     * Prevent mobile viewport rules from breaking individual
     * words inside the fixed A4 preview.
     */
    .invoice-paper-stage #invoicePreview
    .invoice-document-title h2,

    .invoice-paper-stage #invoicePreview
    .invoice-document-title strong,

    .invoice-paper-stage #invoicePreview
    .invoice-document-company {

        word-break: normal !important;
        overflow-wrap: normal !important;
    }


    .invoice-paper-stage #invoicePreview
    .invoice-document-title h2 {

        white-space: nowrap !important;
    }


    /*
     * The A4 table must use the full invoice canvas rather
     * than shrinking to the phone width.
     */
    .invoice-paper-stage #invoicePreview
    .invoice-document-table-wrap {

        width: 100% !important;
        max-width: none !important;

        overflow: visible !important;
    }


    .invoice-paper-stage #invoicePreview
    .invoice-document-table {

        width: 100% !important;
        max-width: none !important;
    }


    /*
     * Prevent stage centering/margins from shifting the
     * transformed canvas outside the visible mobile area.
     */
    .invoice-paper-stage.is-mobile-preview-scaled
    #invoicePreview {

        margin:
            0 !important;

        transform:
            scale(
                var(
                    --invoice-preview-scale,
                    1
                )
            ) !important;

        transform-origin:
            top left !important;
    }

}
