/**
 * Obliczanki.pl - Print Styles
 *
 * A4 print formatting, hide UI elements, proper page breaks
 * Firefox-compatible page alignment fixes
 *
 * @version 0.2.0
 * @author Michał Głębowski
 */

@media print {
    /* Reset Everything */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* A4 Page Format - Optimized margins */
    @page {
        size: A4 portrait;
        margin: 10mm 15mm 10mm 15mm; /* top right bottom left */
    }

    /* Hide UI Elements */
    .panel-left,
    .panel-header,
    header,
    .actions,
    .actions-top,
    .panel-right h2,
    .panel-footer,
    .btn,
    .noscript-warning {
        display: none !important;
    }

    /* Critical: Reset All Containers */
    html, body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    .container {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    .panel-right {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        background: white !important;
    }

    #previewArea {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        border: none !important;
        background: white !important;
    }

    .worksheet-preview {
        transform: none !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Worksheet Table - Force Page Break Before Each Table */
    .worksheet {
        width: 100%;
        border-collapse: collapse;
        font-family: Arial, Helvetica, sans-serif;
        margin: 0;
        padding: 0;
        page-break-before: always !important;
        break-before: page !important;
        page-break-inside: auto;
        break-inside: auto;
    }

    /* First worksheet should not have page break before */
    .worksheet:first-child {
        page-break-before: auto !important;
        break-before: auto !important;
    }

    /* Table Structure - Explicit Display */
    .worksheet tbody {
        display: table-row-group;
        margin: 0;
        padding: 0;
    }

    .worksheet tr {
        display: table-row;
        page-break-inside: avoid;
        margin: 0;
        padding: 0;
    }

    .worksheet th,
    .worksheet td {
        display: table-cell;
        border: 1px solid #000;
        padding: 12px 10px;
        text-align: left;
        vertical-align: middle;
        overflow: visible;
        word-wrap: break-word;
        max-height: none;
    }

    .worksheet thead {
        display: table-header-group;
    }

    .worksheet thead th {
        background: #f0f0f0;
        font-weight: bold;
        text-align: center;
        font-size: 12pt;
        padding: 10px;
    }

    /* No Grid Mode */
    .worksheet.no-grid th,
    .worksheet.no-grid td {
        border: none !important;
    }

    /* Exercise Cell */
    .exercise {
        min-height: 40px;
        page-break-inside: avoid;
    }

    .exercise .number {
        font-weight: bold;
        margin-right: 10px;
        font-size: 11pt;
        color: #000;
    }

    .exercise .expression {
        font-size: 13pt;
        font-family: 'Courier New', Courier, monospace;
        color: #000;
    }

    /* Landscape Mode Adjustments */
    .worksheet.landscape .exercise .expression {
        font-size: 11pt; /* Slightly smaller for landscape */
    }

    .worksheet.landscape th,
    .worksheet.landscape td {
        padding: 8px 6px; /* Slightly less padding */
    }

    /* Solution Sheet */
    .worksheet.solutions thead th {
        background: #e0e0e0;
    }

    .worksheet.solutions .answer {
        font-weight: bold;
        color: #000;
        /* Removed text-decoration: underline for cleaner appearance */
    }

    /* Ensure UTF-8 Symbol Rendering */
    .operator,
    .expression {
        font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', Arial, sans-serif;
    }

    /* Force Page Breaks - Prevent Orphans/Widows */
    .worksheet {
        orphans: 3;
        widows: 3;
    }

    /* Firefox-Specific Fixes */
    @-moz-document url-prefix() {
        .worksheet {
            margin-top: 0 !important;
            margin-bottom: 0 !important;
        }

        .worksheet tbody {
            margin: 0 !important;
            padding: 0 !important;
        }

        /* Ensure proper table rendering */
        .worksheet {
            display: table !important;
            width: 100% !important;
        }
    }
}
