/*
    File: [plugin-dir]/css/print.css
    Version: 7.9.5 - FINAL BREAK FIX: Uses float/display block to force page separation.
*/

@media print {
    /* --- 0. CRITICAL RESET: Remove all browser/printer margins from paper edges --- */
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        min-height: initial !important; 
        max-height: initial !important;
        overflow: visible !important;
    }
    
    /* --- 1. Global Visibility Reset --- */
    
    /* Hide the parent page content only if it interferes (keeps the body visible for the pop-up content) */
    body > :not(.gfcg-card-wrapper) { 
        /* This is safe since batch print injects .gfcg-card-wrapper directly into the new pop-up body */
        display: none !important;
        visibility: hidden !important; 
    }
    
    /* Make the entire card wrapper and its contents visible with max priority */
    .gfcg-card-wrapper,
    .gfcg-card-wrapper * { 
        visibility: visible !important; 
        opacity: 1 !important;
        z-index: 99999 !important; 
    }
    
    /* --- 2. Layout and Page Separation (CRITICAL FOR BATCH PRINT) --- */

    .gfcg-card-wrapper { 
        position: relative !important; 
        left: 0 !important;
        top: 0 !important;
        
        /* CRITICAL: Force the element to be a strong block container for print context */
        display: block !important;
        float: none !important; 
        clear: both !important; /* Ensure separation from previous elements */
        
        /* Set specific mm dimensions */
        width: 92mm !important; 
        height: 127mm !important; 
        
        /* CRITICAL FIX: Force a page break after every card */
        page-break-after: always !important; 
        page-break-inside: avoid !important; /* Prevent card content from splitting */
        
        background-color: white !important; 
        border: none !important; 
        margin: 5mm auto 0 auto !important; /* Centers card and adds slight buffer from page edge */
        padding: 0 !important;
        overflow: hidden; 
    }
    
    /* Last card on the page should not force an extra blank page */
    .gfcg-card-wrapper:last-child {
        page-break-after: auto !important;
    }

    /* Target the HTML fallback DIV to remove the background image */
    #gfcg-card-html.gfcg-print-no-bg {
        background-image: none !important; 
        background-color: white !important;
    }

    /* Hide the saved WebP image if it exists */
    .gfcg-print-no-bg .gfcg-final-card {
        display: none !important; 
        visibility: hidden !important;
    }
    
    /* Revert positioning for the content layers back to Absolute */
    .gfcg-card-wrapper > div {
        position: absolute !important; 
        
        background: transparent !important;
        color: black !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.2 !important;
        transform: none !important; 
    }

    /* Final visibility reset for the body to enable printing */
    body {
        visibility: visible !important; 
        display: block !important;
    }
}