/* MTG Proxy Generator - Print Stylesheet */

@media print {
    /* Hide all WordPress admin elements, menus, sidebars, headers, footers and the UI settings panels */
    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 12pt;
        width: 210mm;
        height: auto !important;
        overflow: visible !important;
    }

    /* Hide standard WP elements */
    #adminmenuwrap,
    #adminmenuback,
    #wpadminbar,
    #wpfooter,
    .wrap h1,
    .wrap p,
    .mtg-pg-app,
    .mtg-pg-app-frontend,
    #wpcontent,
    header,
    footer,
    sidebar,
    nav {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Override WP main content area margins for full page print */
    #wpcontent {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Reveal the print-specific workspace */
    #mtg-proxy-gen-print-area {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 210mm;
        margin: 0;
        padding: 0;
    }

    /* Page Setup */
    @page {
        size: A4 portrait;
        margin: 0;
    }

    /* Page container representing a single sheet of A4 */
    .mtg-pg-print-page {
        width: 210mm;
        height: 297mm;
        box-sizing: border-box;
        
        /* Padding to center a 3x3 grid of cards on A4:
           - 3 cards x 63.5mm = 190.5mm. Remainder = 210mm - 190.5mm = 19.5mm -> 9.75mm margins
           - 3 cards x 88.9mm = 266.7mm. Remainder = 297mm - 266.7mm = 30.3mm -> 15.15mm margins
        */
        padding-top: 15.15mm;
        padding-bottom: 15.15mm;
        padding-left: 9.75mm;
        padding-right: 9.75mm;
        
        /* Page break rules */
        page-break-after: always;
        page-break-inside: avoid;
        break-inside: avoid;
        display: grid !important;
        grid-template-columns: repeat(3, 63.5mm);
        grid-template-rows: repeat(3, 88.9mm);
        align-content: start;
        justify-content: start;
        
        /* Clean slate for printing */
        background: #ffffff !important;
        box-shadow: none !important;
        margin: 0 !important;
        border: none !important;
        overflow: hidden;
    }

    /* Last page doesn't necessarily need a page break, but it's safe to have */
    .mtg-pg-print-page:last-child {
        page-break-after: avoid;
        break-after: avoid;
    }

    /* Proxy Card Styles for Printing */
    .mtg-pg-print-card {
        width: 63.5mm;
        height: 88.9mm;
        box-sizing: border-box;
        background: #ffffff !important;
        color: #000000 !important;
        padding: 4mm;
        display: flex !important;
        flex-direction: column;
        justify-content: space-between;
        font-family: 'Inter', system-ui, -apple-system, sans-serif;
        overflow: hidden;
        position: relative;
    }

    /* Cutting Line configurations */
    .mtg-pg-print-card.cut-borders {
        border: 0.15mm dashed #555555 !important;
    }

    .mtg-pg-print-card.cut-solid {
        border: 0.15mm solid #333333 !important;
    }

    /* If no borders, we can still print crop/cut marks at corners of the page,
       or just leave a very faint hairline border that won't show after cutting */
    .mtg-pg-print-card.cut-none {
        border: 0.05mm solid #eeeeee !important; /* extremely faint helper border */
    }

    /* Card Header Area */
    .mtg-pg-print-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 0.25mm solid #000000;
        padding-bottom: 1mm;
        margin-bottom: 1.5mm;
    }

    .mtg-pg-print-card-name {
        font-size: 9.5pt;
        font-weight: 700;
        margin: 0;
        padding: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 75%;
    }

    .mtg-pg-print-card-mana {
        font-size: 8.5pt;
        font-weight: 700;
        text-align: right;
    }

    /* Card Type Line */
    .mtg-pg-print-card-type {
        font-size: 8pt;
        font-weight: 700;
        font-style: italic;
        border-bottom: 0.25mm solid #000000;
        padding-bottom: 1mm;
        margin-bottom: 1.5mm;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Card Rules Text Box */
    .mtg-pg-print-card-text {
        font-size: 8pt; /* Default font size, adjusted dynamically by JS if overflow occurs */
        line-height: 1.35;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        white-space: pre-wrap;
        margin-bottom: 1.5mm;
        text-align: left;
        overflow: hidden;
    }

    /* Power/Toughness indicator */
    .mtg-pg-print-card-pt {
        align-self: flex-end;
        font-size: 9pt;
        font-weight: 700;
        border: 0.25mm solid #000000;
        padding: 0.5mm 1.5mm;
        border-radius: 1mm;
        background: #ffffff !important;
        line-height: 1;
        min-width: 6mm;
        text-align: center;
    }
}
