@media print {
    @page {
        size: A4 landscape;
        margin: 0.5cm;
    }

    html,
    body {
        width: 100%;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body > :not(#homeworkSchedulePrint):not(#customSchedulePrint):not(#seating-plan-print-section) {
        display: none !important;
    }

    #homeworkSchedulePrint,
    #customSchedulePrint,
    #seating-plan-print-section {
        position: static !important;
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        box-sizing: border-box !important;
    }

    #homeworkSchedulePrint:not(.active-print),
    #customSchedulePrint:not(.active-print) {
        display: none !important;
    }

    #homeworkSchedulePrint,
    #customSchedulePrint,
    #homeworkSchedulePrint > div,
    #customSchedulePrint > div {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        break-inside: auto !important;
        page-break-inside: auto !important;
    }

    #homeworkSchedulePrint *,
    #customSchedulePrint *,
    #seating-plan-print-section * {
        box-sizing: border-box !important;
    }

    #homeworkSchedulePrint h2,
    #homeworkSchedulePrint h3,
    #customSchedulePrint h3 {
        display: block !important;
        margin: 0 0 0.25cm !important;
        padding: 0 !important;
        text-align: center !important;
        font-size: 12px !important;
        font-weight: 800 !important;
        page-break-after: avoid !important;
    }

    #homeworkSchedulePrint table,
    #customSchedulePrint table {
        display: table !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border: 2px solid #000 !important;
        border-collapse: collapse !important;
        table-layout: fixed !important;
        font-size: 8px !important;
        empty-cells: show !important;
        page-break-inside: auto !important;
    }

    #homeworkSchedulePrint thead,
    #customSchedulePrint thead {
        display: table-header-group !important;
        break-inside: avoid !important;
    }

    #homeworkSchedulePrint tbody,
    #customSchedulePrint tbody {
        display: table-row-group !important;
    }

    #homeworkSchedulePrint tr,
    #customSchedulePrint tr {
        display: table-row !important;
        height: var(--schedule-row-height, 25px) !important;
        page-break-inside: avoid !important;
    }

    #homeworkSchedulePrint th,
    #homeworkSchedulePrint td,
    #customSchedulePrint th,
    #customSchedulePrint td {
        display: table-cell !important;
        position: static !important;
        min-width: 0 !important;
        max-width: none !important;
        min-height: 0 !important;
        height: var(--schedule-row-height, 25px) !important;
        padding: 2px !important;
        border: 1px solid #000 !important;
        overflow: hidden !important;
        vertical-align: middle !important;
    }

    #homeworkSchedulePrint th,
    #customSchedulePrint th {
        border-width: 2px !important;
        background: #e5e7eb !important;
        font-weight: 800 !important;
    }

    #homeworkSchedulePrint th:first-child {
        white-space: normal !important;
        overflow-wrap: anywhere !important;
    }

    #homeworkSchedulePrint th:first-child,
    #homeworkSchedulePrint td:first-child {
        width: 4% !important;
        text-align: center !important;
        font-weight: 700 !important;
    }

    #customSchedulePrint th:first-child,
    #customSchedulePrint td:first-child {
        width: 8.75% !important;
        text-align: center !important;
        white-space: nowrap !important;
        font-weight: 700 !important;
    }

    #homeworkSchedulePrint th:nth-child(2),
    #homeworkSchedulePrint td:nth-child(2) {
        width: 26% !important;
        padding-left: 4px !important;
        text-align: left !important;
        white-space: normal !important;
        overflow-wrap: anywhere !important;
        font-weight: 700 !important;
    }

    #customSchedulePrint th:nth-child(2),
    #customSchedulePrint td:nth-child(2) {
        width: 16.25% !important;
        padding-left: 4px !important;
        text-align: left !important;
        white-space: normal !important;
        font-weight: 700 !important;
    }

    #homeworkSchedulePrint th:not(:first-child):not(:nth-child(2)),
    #customSchedulePrint th:not(:first-child):not(:nth-child(2)) {
        height: 115px !important;
        text-align: center !important;
    }

    #homeworkSchedulePrint .rotated-header,
    #customSchedulePrint .rotated-header {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        /* A percentage height in a rotated table header can resolve against
           the full printed table and move the text below the student rows. */
        height: 105px !important;
        width: max-content !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 2px !important;
        writing-mode: vertical-rl !important;
        text-orientation: mixed !important;
        transform: rotate(180deg) !important;
        white-space: nowrap !important;
        font-size: 7px !important;
        line-height: 1.1 !important;
    }

    #homeworkSchedulePrint .header-line,
    #customSchedulePrint .header-line {
        display: block !important;
    }

    #homeworkSchedulePrint .cols-6-10 td,
    #customSchedulePrint.cols-6-10 td,
    #homeworkSchedulePrint .rows-16-30 td,
    #customSchedulePrint.rows-16-30 td {
        font-size: 8px !important;
    }

    #homeworkSchedulePrint .cols-11-15 td,
    #customSchedulePrint.cols-11-15 td,
    #homeworkSchedulePrint .rows-31-plus td,
    #customSchedulePrint.rows-31-plus td {
        font-size: 7px !important;
    }

    #homeworkSchedulePrint .cols-16-20 td,
    #customSchedulePrint.cols-16-20 td {
        padding: 1px !important;
        font-size: 6.5px !important;
    }

    #homeworkSchedulePrint tbody td:first-child,
    #homeworkSchedulePrint tbody td:nth-child(2) {
        font-size: 9px !important;
    }

    #homeworkSchedulePrint > div:not(:last-child) {
        page-break-after: always !important;
    }


}

@media screen and (max-width: 768px) {
    #schedulePreview table,
    #customSchedulePreview table {
        min-width: 720px;
    }
}


/* Keep the print document measurable before opening the print dialog. */
@page seating-plan {
    size: A4 portrait;
    margin: 10mm;
}

#seating-plan-print-section {
    page: seating-plan;
    display: grid !important;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 4mm;
    width: 190mm !important;
    max-width: 100% !important;
    /* Leave 1 mm for browser rounding at the bottom of portrait A4. */
    height: 276mm !important;
    margin: 0 !important;
    color: #17212b !important;
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.25;
    break-inside: avoid;
}

#seating-plan-print-section * {
    min-width: 0;
    min-height: 0;
    box-shadow: none !important;
    text-shadow: none !important;
    transform: none !important;
}

.seating-sheet-header {
    padding-bottom: 3mm;
    border-bottom: 1.5pt solid #243746;
}

.seating-sheet-label {
    margin: 0 0 2mm;
    font-size: 8pt;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #52616c;
}

.seating-sheet-title {
    margin: 0 0 3mm;
    color: #17212b;
    font-size: var(--seat-title-font);
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.seating-sheet-meta {
    display: flex;
    align-items: baseline;
    gap: 8mm;
    font-size: 9pt;
}

.seating-sheet-meta-item {
    display: flex;
    align-items: baseline;
    gap: 2mm;
}

.seating-sheet-meta-item span {
    color: #52616c;
}

.seating-sheet-front {
    display: grid;
    justify-items: center;
    gap: 3mm;
}

.seating-sheet-board {
    width: 75%;
    padding: 2mm;
    border: 1pt solid #52616c;
    border-bottom: 2pt solid #243746;
    text-align: center;
    font-size: 8pt;
    font-weight: 700;
    letter-spacing: 1px;
}

.seating-sheet-teacher {
    padding: 2mm 8mm;
    border: 0.75pt solid #81909a;
    text-align: center;
    font-size: 8pt;
    font-weight: 700;
}

.seating-sheet-desks {
    display: grid;
    grid-template-columns: repeat(var(--seat-cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--seat-rows), minmax(0, 1fr));
    gap: var(--seat-gap);
}

.seating-sheet-desk {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    border: 0.75pt solid #52616c;
    break-inside: avoid;
}

.seating-sheet-desk-label {
    padding: var(--seat-label-padding, 1mm) 2mm;
    border-bottom: 0.5pt solid #a5afb7;
    background: #eef1f3 !important;
    color: #354653;
    font-size: 7pt;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-align: center;
}

.seating-sheet-seats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.seating-sheet-seat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--seat-content-gap, 1mm);
    padding: var(--seat-padding, 1mm);
    text-align: center;
}

.seating-sheet-seat + .seating-sheet-seat {
    border-left: 0.5pt solid #a5afb7;
}

.seating-sheet-student-no {
    font-size: var(--seat-number-font, 7pt);
    color: #52616c;
    line-height: 1.1;
}

.seating-sheet-student-name {
    font-size: var(--seat-font);
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.seating-sheet-empty {
    font-size: 7pt;
    color: #65747f;
    letter-spacing: 1px;
}

.seating-sheet-footer {
    display: flex;
    justify-content: space-between;
    gap: 4mm;
    padding-top: 2mm;
    border-top: 0.5pt solid #a5afb7;
    font-size: 7pt;
    color: #52616c;
}

@media screen {
    #seating-plan-print-section {
        position: fixed !important;
        left: -10000px;
        top: 0;
        visibility: hidden;
        pointer-events: none;
        width: 190mm !important;
        max-width: none !important;
    }
}
