/* Invoice page footer — pinned to bottom of sheet (screen) and every printed page */
:root {
    --inv-footer-reserve: 36px;
    --erp-print-page-margin-top: 12mm;
    --erp-print-page-margin-bottom: 14mm;
    /* Bottom of the page content area — Chrome pushes a fixed box hanging below it onto the
       next page, so the footer stays inside and the flow reserves room for it instead. */
    --erp-print-footer-bottom: 0mm;
}

.gd1-sheet,
.gd2-sheet,
.gd3-sheet,
.inv-sheet,
.erp-print-root .inv-sheet,
.erp-print-root .gd1-sheet,
.erp-print-root .gd2-sheet,
.erp-print-root .gd3-sheet {
    position: relative;
    box-sizing: border-box;
    padding-bottom: var(--inv-footer-reserve, 36px);
}

/* Template editor + live preview: A4 page height so fixed footer sits at page bottom */
.inv-preview .inv-sheet,
.inv-preview .gd1-sheet,
.inv-preview .gd2-sheet,
.inv-preview .gd3-sheet {
    min-height: 297mm;
}

/* Per-layout bottom reserve when fixed footer is enabled */
.inv-sheet:has(.inv-page-footer--strip.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--strip.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--strip.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--strip.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 36px;
}

.inv-sheet:has(.inv-page-footer--signature.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--signature.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--signature.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--signature.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 84px;
}

.inv-sheet:has(.inv-page-footer--brand.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--brand.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--brand.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--brand.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 56px;
}

.inv-sheet:has(.inv-page-footer--contact.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--contact.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--contact.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--contact.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 64px;
}

.inv-sheet:has(.inv-page-footer--custom.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--custom.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--custom.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--custom.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 48px;
}

.inv-sheet:has(.inv-page-footer--minimal.inv-page-footer--fixed-print),
.gd1-sheet:has(.inv-page-footer--minimal.inv-page-footer--fixed-print),
.gd2-sheet:has(.inv-page-footer--minimal.inv-page-footer--fixed-print),
.gd3-sheet:has(.inv-page-footer--minimal.inv-page-footer--fixed-print) {
    --inv-footer-reserve: 26px;
}

/* Minimal footer: page number only, no divider rule */
.inv-page-footer--minimal.inv-page-footer--fixed-print,
.erp-print-document-footer.inv-page-footer--minimal.inv-page-footer--fixed-print {
    border-top: none !important;
    padding: 2px 12px !important;
}

/* Thin strip footer — less vertical reserve */
.inv-page-footer--strip.inv-page-footer--fixed-print,
.erp-print-document-footer.inv-page-footer--strip.inv-page-footer--fixed-print {
    padding: 5px 12mm 4mm !important;
}

/* Screen: clip host off-screen (never display:none — breaks Chrome print preview) */
@media screen {
    #erp-print-fixed-footer-host {
        position: fixed !important;
        left: -10000px !important;
        top: 0 !important;
        width: 210mm !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }
}

/* Screen: absolute at bottom of invoice sheet */
.inv-page-footer--fixed-print,
.erp-print-document-footer.inv-page-footer--fixed-print {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    margin-top: 0 !important;
    padding: 8px 12px 6px !important;
    border-top: 1px solid #cbd5e1 !important;
    /* --inv-footer-bg comes from the template's footer background setting. */
    background: var(--inv-footer-bg, #fff) !important;
    z-index: 5 !important;
    box-sizing: border-box !important;
}

.inv-page-footer--signature.inv-page-footer--fixed-print,
.inv-page-footer--brand.inv-page-footer--fixed-print,
.inv-page-footer--contact.inv-page-footer--fixed-print {
    padding: 8px 12px 8px !important;
}

@media print {
    /*
     * Host is a static wrapper on body; only the footer child is position:fixed.
     * It is kept between prints so a repeat preview always has a footer, so it only counts as
     * live while the engine has it mounted — otherwise it would print on unrelated documents.
     */
    #erp-print-fixed-footer-host,
    .erp-print-fixed-footer-slot {
        display: none !important;
    }

    body.erp-fixed-footer-mounted #erp-print-fixed-footer-host,
    body.erp-fixed-footer-mounted .erp-print-fixed-footer-slot {
        display: block !important;
        visibility: visible !important;
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        z-index: 2147483647 !important;
        box-sizing: border-box !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    #erp-print-fixed-footer-host > .erp-print-footer-clone,
    #erp-print-fixed-footer-host > .inv-page-footer,
    #erp-print-fixed-footer-host > .erp-print-document-footer,
    body.voucher-print-mode #erp-print-fixed-footer-host > .erp-print-footer-clone,
    body.voucher-print-mode #erp-print-fixed-footer-host > .inv-page-footer,
    body.voucher-print-mode #erp-print-fixed-footer-host > .erp-print-document-footer,
    body.invoice-details-print #erp-print-fixed-footer-host > .erp-print-footer-clone,
    body.invoice-details-print #erp-print-fixed-footer-host > .inv-page-footer,
    body.invoice-details-print #erp-print-fixed-footer-host > .erp-print-document-footer,
    body.erp-print-active #erp-print-fixed-footer-host > .erp-print-footer-clone,
    body.erp-print-active #erp-print-fixed-footer-host > .inv-page-footer,
    body.erp-print-active #erp-print-fixed-footer-host > .erp-print-document-footer {
        display: block !important;
        visibility: visible !important;
        position: fixed !important;
        bottom: var(--erp-print-footer-bottom, 0mm) !important;
        left: 12mm !important;
        right: 12mm !important;
        width: auto !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        z-index: 2147483647 !important;
        background: var(--inv-footer-bg, #fff) !important;
        border-top: 1px solid #cbd5e1 !important;
        padding: 5px 0 4px !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    #erp-print-fixed-footer-host > .inv-page-footer--strip,
    #erp-print-fixed-footer-host > .erp-print-document-footer.inv-page-footer--strip {
        padding: 5px 0 4px !important;
    }

    #erp-print-fixed-footer-host > .inv-page-footer--minimal,
    #erp-print-fixed-footer-host > .erp-print-document-footer.inv-page-footer--minimal {
        border-top: none !important;
        padding: 2px 0 !important;
    }

    /* Clone is outside #printable-form, so hide every in-document footer to avoid a duplicate. */
    body.erp-fixed-footer-mounted #printable-form .erp-print-document-footer,
    body.erp-fixed-footer-mounted .erp-print-root .erp-print-document-footer,
    body.erp-fixed-footer-mounted #printable-form .erp-print-footer-inline-skip {
        display: none !important;
        visibility: hidden !important;
    }

    #erp-print-fixed-footer-host .inv-page-footer__strip {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    #erp-print-fixed-footer-host .erp-print-page-label-screen {
        display: none !important;
    }

    #erp-print-fixed-footer-host .erp-print-page-label {
        display: inline-block !important;
        visibility: visible !important;
    }

  /* Fallback when footer stays inside sheet (no body mount) */
    body.invoice-details-print .inv-page-footer--fixed-print,
    body.invoice-details-print .erp-print-document-footer.inv-page-footer--fixed-print,
    body.voucher-print-mode .inv-page-footer--fixed-print,
    body.voucher-print-mode .erp-print-document-footer.inv-page-footer--fixed-print,
    body.erp-print-active .inv-page-footer--fixed-print,
    body.erp-print-active .erp-print-document-footer.inv-page-footer--fixed-print,
    #printable-form .gd1-sheet > .inv-page-footer--fixed-print,
    #printable-form .gd2-sheet > .inv-page-footer--fixed-print,
    #printable-form .gd3-sheet > .inv-page-footer--fixed-print,
    #printable-form .inv-sheet > .inv-page-footer--fixed-print {
        position: fixed !important;
        bottom: var(--erp-print-footer-bottom, 0mm) !important;
        left: 12mm !important;
        right: 12mm !important;
        width: auto !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        z-index: 2147483647 !important;
        print-color-adjust: exact !important;
        -webkit-print-color-adjust: exact !important;
        background: var(--inv-footer-bg, #fff) !important;
        display: block !important;
        visibility: visible !important;
        border-top: 1px solid #cbd5e1 !important;
    }

    .erp-print-footer-inline-hidden {
        display: none !important;
        visibility: hidden !important;
    }

    .inv-page-footer--fixed-print .erp-print-page-label-screen,
    #erp-print-fixed-footer-host .erp-print-page-label-screen {
        display: none !important;
    }

    .inv-page-footer--fixed-print .erp-print-page-label,
    #erp-print-fixed-footer-host .erp-print-page-label {
        display: inline-block !important;
        visibility: visible !important;
    }

    /*
     * Reserve bottom space so content does not print under the fixed footer.
     */
    body.invoice-details-print .gd1-sheet,
    body.invoice-details-print .gd2-sheet,
    body.invoice-details-print .gd3-sheet,
    body.invoice-details-print .inv-sheet,
    body.voucher-print-mode .gd1-sheet,
    body.voucher-print-mode .gd2-sheet,
    body.voucher-print-mode .gd3-sheet,
    body.voucher-print-mode .inv-sheet,
    body.erp-print-active .gd1-sheet,
    body.erp-print-active .gd2-sheet,
    body.erp-print-active .gd3-sheet,
    body.erp-print-active .inv-sheet {
        padding-bottom: var(--inv-footer-reserve, 36px) !important;
        overflow: visible !important;
    }
}
