/* Let the document scroll, rather than nesting a viewport-height body. */
body {
    height: auto;
    overflow: visible;
}

.card-content {
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: none;
}

.card-content :where(form, .form-container, .form-field, .form-group, .filter-group) {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.review-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    width: 100%;
}

.review-container .file-preview {
    flex: 1;
    width: 50%;
    min-width: 0;
}

.review-container .review-form {
    flex: 0 0 360px;
    min-width: 0;
}

.review-form :is(input, select, textarea) {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.review-form .user-info-card,
.review-form .form-control-plaintext {
    box-sizing: border-box;
}

.home-container :is(.center-content, .left-sidebar, .right-sidebar),
.class-content,
.class-summary,
.lesson-list,
.table-wrap,
.calendar-scroll {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.tab-home,
.tab-home-content,
.tab-home-pane,
.tab-home-sub,
.tab-home-sub-content,
.tab-home-sub-pane {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.lesson-days {
    display: none;
}

.class-filters {
    width: 100%;
}

.class-filters > summary {
    display: none;
}

/* These controls must also wrap at tablet widths and in narrow panels. */
.students-header,
.students-tabs {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 8px;
}

.students-tabs > * {
    max-width: 100%;
}

/* Shared restore dialog also works on pages without cancellation controls. */
.restore-lesson-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.restore-lesson-modal .modal-content {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    width: 50vw;
    margin: 10vh auto;
    overflow: visible;
}

:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid #6b3fa0;
    outline-offset: 2px;
}

:is(.event-content, .help-content) {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

:is(.event-content, .help-content) :is(img, video, iframe) {
    max-width: 100%;
    height: auto;
}

:is(.event-content, .help-content) figure {
    max-width: 100%;
    margin-inline: 0;
    box-sizing: border-box;
}

.card-content :is(.event-content, .help-content) figure.table {
    display: block;
}

.calendar-scroll {
    width: 100%;
    overflow-x: auto;
}

.calendar-surface {
    min-width: 1050px;
}

.login-form,
.survey-form {
    width: 100%;
    box-sizing: border-box;
}

:is(.form-field, .filter-group, .survey-form, .login-form) :is(input, select, textarea),
.attendance-grade-select,
.points-input {
    box-sizing: border-box;
    max-width: 100%;
}

.form-field :is(input, select, textarea) {
    width: 100%;
}

.form-field input:is([type="checkbox"], [type="radio"]) {
    width: auto;
}

.form-field textarea {
    min-height: 5rem;
    resize: vertical;
}

.select2-container {
    max-width: 100%;
}

/* Keep wide data tables scrollable inside their panels. */
.card-content,
.card-content > *,
.event-info,
.students-container {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.event-actions-panel {
    flex-shrink: 0;
}

@media (max-width: 1100px) {
    .mobile-site-header {
        flex-direction: column;
        width: 95%;
        box-sizing: border-box;
        margin: 16px auto 0;
        padding: 12px;
        border-radius: 16px 16px 0 0;
        background: #fbf5f8;
        gap: 12px;
    }

    .mobile-header-top,
    .mobile-account {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-width: 0;
    }

    .mobile-brand {
        flex-shrink: 0;
    }

    .mobile-account {
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .mobile-account-details {
        min-width: 0;
        text-align: right;
        font-size: 14px;
        overflow-wrap: break-word;
    }

    .mobile-header-search,
    .mobile-semester {
        width: 100%;
        min-width: 0;
    }

    .mobile-semester select {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        margin-top: 6px;
        font-size: 16px;
    }

    .mobile-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }

    .mobile-navigation summary {
        cursor: pointer;
        padding: 12px;
        border: 1px solid #c9c5d3;
        border-radius: 8px;
        color: #6b3fa0;
        font: 600 16px "Segoe UI", sans-serif;
    }

    .mobile-navigation[open] summary {
        margin-bottom: 8px;
    }

    .mobile-nav .btn {
        font-size: 16px;
        margin: 0;
        padding: 10px 12px;
    }

    .mobile-site-header > .ctr-p-5-50 {
        width: 100%;
        padding: 5px 0;
    }

    .home-container {
        flex-direction: column;
        gap: 16px;
    }

    .home-container > :is(.left-sidebar, .center-content, .right-sidebar) {
        flex: auto;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        min-height: 0;
        overflow: visible;
        box-sizing: border-box;
    }
}

@media (max-width: 768px) {
    .card-content .ctr-flex:has(> .btn),
    .card-content .ctr-flex:has(> form > .btn),
    .modal .ctr-flex:has(> .btn) {
        flex-wrap: wrap;
        gap: 8px;
    }

    .lessons-header,
    .class-header,
    .actions-header,
    .card-content .section-header,
    .card-content .ctr-content-space-between:has(> :is(h1, h2, h3, label)) {
        flex-wrap: wrap;
        gap: 8px;
    }

    .lessons-header > :is(h3, h4),
    .card-content .ctr-content-space-between > :is(h1, h2, h3, label) {
        flex-basis: 100%;
        min-width: 0;
    }

    .card-content .ctr-grid-col-220 {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    }

    .card-content .ctr-grid > * {
        min-width: 0;
    }

    .form-field :is(.hg-list, .course-list) label {
        display: flex;
        align-items: flex-start;
        max-width: 100%;
        white-space: normal;
    }

    .review-container {
        flex-direction: column;
        gap: 12px;
    }

    .review-container > :is(.review-form, .file-preview) {
        flex: none;
        width: 100%;
        max-width: 100%;
    }

    .card,
    .mobile-site-header {
        width: calc(100% - 16px);
    }

    .mobile-site-header {
        padding: 10px;
        gap: 8px;
    }

    .mobile-header-top {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
    }

    .mobile-brand {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
    }

    .mobile-brand img {
        display: block;
        width: 48px;
        height: 48px;
    }

    .mobile-header-top .mobile-account {
        display: contents;
    }

    .mobile-account-details {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        text-align: left;
        line-height: 1.4;
    }

    .mobile-account > form {
        grid-column: 2;
        grid-row: 1;
    }

    .card-content > .page-title:empty {
        display: none;
    }

    .page-heading .page-title {
        margin: 8px 0 12px;
    }

    .class-filters > summary {
        display: list-item;
        padding: 12px;
        min-height: 44px;
        box-sizing: border-box;
        border: 1px solid #c9c5d3;
        border-radius: 8px;
        color: #6b3fa0;
        cursor: pointer;
        font: 600 16px "Segoe UI", sans-serif;
    }

    .class-filters[open] > summary {
        margin-bottom: 8px;
    }

    .classes-grid {
        margin-top: 12px;
        gap: 12px;
    }

    .class-content {
        margin-bottom: 0;
    }

    .class-content > .info-block {
        margin: 0;
    }

    .class-info .class-title {
        display: block;
        font-size: 1.05rem;
        line-height: 1.4;
        margin: 0 0 8px;
    }

    .class-info .class-title::before {
        display: none;
    }

    .class-info .class-teacher-label {
        display: block;
        margin-bottom: 4px;
        font-weight: 600;
    }

    .class-info .class-details {
        margin: 12px 0 0;
    }

    .class-info .detail-item.inline {
        display: block;
    }

    .class-info .detail-item.inline .detail-label {
        display: block;
        margin-bottom: 4px;
    }

    .card-content .class-actions-panel.info-block {
        padding: 0;
        margin: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
        gap: 8px;
        align-items: stretch;
        justify-content: flex-start;
    }

    .class-actions-panel > .ctr-column {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .class-actions-panel.info-block::before {
        display: none;
    }

    .class-actions-panel > .ctr-column:first-child {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
        gap: 8px;
    }

    .class-actions-panel .btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        margin: 0;
    }

    .card-content .signup-classes > .class-card {
        padding: 0;
    }

    .filter-grid {
        gap: 10px;
    }

    :is(.filter-group, .form-field) :is(input, select, textarea) {
        padding: 6px 8px;
    }

    .extra-points-input input[type="number"],
    .points-table .points-input {
        width: 6rem;
        padding: 6px 8px;
    }

    .points-table .points-comment-cell textarea {
        max-width: min(20rem, calc(100vw - 64px));
    }

    .home-container > :is(.left-sidebar, .right-sidebar) {
        padding: 12px;
    }

    .lesson-table {
        display: none;
    }

    .lesson-days {
        display: block;
    }

    .lesson-day-heading {
        margin: 16px 0 8px;
        font-size: 1rem;
    }

    .lesson-day-card {
        padding: 12px;
        margin-bottom: 12px;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        background: #fff;
    }

    .lesson-day-card h4,
    .lesson-day-card p {
        margin: 8px 0;
    }

    .lesson-day-time {
        font-weight: 600;
    }

    .lesson-day-actions {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .class-content,
    .class-summary,
    .page-heading {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        width: 100%;
    }

    .class-actions-panel,
    .event-actions-panel,
    .event-actions-panel > .ctr-w-150 {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .page-heading > .ctr-flex,
    .date-navigation,
    .duration-buttons,
    .pagination,
    .form-actions,
    .table-form-actions,
    .students-tabs,
    .tab-home-cal-controls,
    .tab-home-cal-left,
    .tab-home-cal-views {
        flex-wrap: wrap;
        gap: 8px;
    }

    .table-form-actions {
        padding: 12px 0;
    }

    .table-form-actions > .btn {
        flex: 1 1 9rem;
        margin: 0;
        text-align: center;
        overflow-wrap: normal;
        word-break: normal;
    }

    .page-heading .btn,
    .date-navigation > *,
    .students-tabs > * {
        max-width: 100%;
    }

    .card-content :is(.info-block, .info-card) {
        padding: 10px;
        min-width: 0;
    }

    .card-content .info-block {
        overflow: visible;
    }

    .table-wrap > table {
        min-width: 40rem;
    }

    .card-content :is(.btn, .action-btn, .student-tab, .student-action-tab,
        .tab-home-tab, .tab-home-sub-tab, .tab-home-cal-btn, .tab-home-cal-view,
        .tab-home-cal-emoji, .submit-btn),
    .mobile-site-header :is(.btn, summary),
    .modal .btn {
        min-width: 44px;
        min-height: 44px;
        max-width: 100%;
        padding: 10px 12px;
        box-sizing: border-box;
        white-space: normal;
        flex-shrink: 0;
        word-break: normal;
        overflow-wrap: break-word;
        hyphens: none;
    }

    .card-content :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea),
    .mobile-site-header .search-input,
    .modal :is(input, select, textarea),
    .select2-search__field {
        font-size: 16px;
    }

    .card-content :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select),
    .select2-container .select2-selection,
    .mobile-site-header .search-input {
        min-height: 44px;
    }

    .survey-form :is(.question-header, .option-item label) {
        gap: 8px;
    }

    .survey-form .question-header {
        flex-wrap: wrap;
    }

    .survey-form .question-required {
        margin-left: 0;
    }

    .survey-form .option-item label {
        min-height: 44px;
        box-sizing: border-box;
    }

    .survey-form input:is([type="checkbox"], [type="radio"]) {
        flex-shrink: 0;
    }

    .messages-container {
        right: 16px;
        width: calc(100% - 32px);
        overflow-wrap: break-word;
    }

    body .modal {
        top: var(--mobile-viewport-top, 0px);
        height: var(--mobile-viewport-height, 100dvh);
        box-sizing: border-box;
        overflow-y: auto;
        padding: 16px 0;
    }

    body .modal .modal-content {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        animation: none;
        width: calc(100% - 32px);
        max-width: none;
        margin: 0 auto;
        padding: 12px;
        box-sizing: border-box;
        overflow: visible;
        overflow-wrap: break-word;
    }

    body .modal .modal-content > :is(form, div) {
        max-height: none;
        overflow: visible;
    }

    body .modal .select2-results__options {
        max-height: min(200px, 35dvh) !important;
    }

    .calendar-surface {
        min-width: 1400px;
    }

    .calendar-surface .tab-home-cal-cell {
        min-height: 90px;
        padding: 6px;
    }

    .calendar-surface :is(.day-num, .tab-home-cal-item, .tab-home-cal-name, .tab-home-cal-emoji) {
        font-size: 14px;
    }

    .calendar-surface .tab-home-cal-name {
        max-width: none;
        white-space: normal;
    }

    .calendar-surface .tab-home-cal-item {
        flex-direction: column;
        align-items: stretch;
        padding: 4px;
    }

    .calendar-surface .tab-home-cal-list {
        margin-left: 0;
        list-style: none;
    }
    .card-content {
        padding: 12px 8px;
    }

    .header-main {
        font-size: 1.4rem;
        overflow-wrap: break-word;
    }

    .card-content .ctr-sm {
        padding: 12px 8px;
        box-sizing: border-box;
    }

    .event-layout,
    .event-heading {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .event-actions-panel {
        width: 100%;
    }

    .event-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 8px;
    }

    .event-actions .btn {
        margin: 0;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .event-actions .btn,
    .mobile-account .btn,
    .extra-points-form .btn,
    .students-tabs .student-tab {
        min-height: 44px;
        box-sizing: border-box;
    }

    .mobile-account .btn,
    .extra-points-form .btn {
        padding: 12px 16px;
    }

    .event-content img {
        max-width: 100%;
        height: auto;
    }

    .students-header,
    .students-tabs {
        flex-wrap: wrap;
        gap: 8px;
    }

    .students-tabs {
        width: 100%;
    }

    .students-tabs .student-tab {
        flex: 1 1 140px;
        width: auto;
        padding: 12px;
    }

    .students-container table {
        min-width: 640px;
    }

    .table-wrap {
        width: 100%;
        max-width: 100%;
    }

    .form-field :is(input, select, textarea),
    .extra-points-input :is(input, textarea) {
        font-size: 16px;
    }

    .card-footer,
    .help_info {
        padding: 12px;
        overflow-wrap: break-word;
    }
}
