

.nav-backdrop { display: none; }
.nav-drawer-head { display: none; }
.schedule-filters-toggle { display: none !important; }


@media (max-width: 900px) {
    :root {
        --header-height: 52px;
        --control-height: 42px;
        --drawer-w: min(320px, 92vw);
    }

    header {
        padding: 0 10px 0 6px;
        gap: 8px;
        z-index: 1100;
    }
    .header-brand { gap: 6px; min-width: 0; }
    .mobile-menu-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        min-width: 44px;
        height: 44px;
        border: 0;
        border-radius: 12px;
        color: #fff;
        background: rgba(255,255,255,.16);
        font-size: 1.25rem;
        cursor: pointer;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }
    #title {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
    }
    .brand-name { display: none; }
    .header-brand > svg { display: none; }
    #header-user-name { display: none; }


    #sidebar_right { display: none !important; }
    #sidebar_left {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--drawer-w);
        z-index: 1200;
        padding: 0;
        margin: 0;
        background: var(--surface);
        border-right: 1px solid var(--border);
        box-shadow: 16px 0 40px rgba(0,0,0,.22);
        transform: translateX(-105%);
        transition: transform .22s ease;
        overflow: hidden;
        pointer-events: none;
        visibility: hidden;
    }
    #sidebar_left.mobile-open {
        transform: translateX(0);
        pointer-events: auto;
        visibility: visible;
    }
    .nav-drawer-head {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        flex-shrink: 0;
        height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 12px 0 16px;
        border-bottom: 1px solid var(--border);
        background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
        color: #fff;
        font-weight: 700;
        font-size: 1.05rem;
    }
    .nav-drawer-close {
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 12px;
        background: rgba(255,255,255,.16);
        color: #fff;
        font-size: 1.6rem;
        line-height: 1;
        cursor: pointer;
    }
    #sidebar_left > nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding: 10px 10px calc(16px + env(safe-area-inset-bottom, 0px));
        gap: 2px;
    }
    #sidebar_left nav a {
        min-height: 48px;
        padding: 12px 14px;
        font-size: 1.05rem;
        border-radius: 10px;
        -webkit-tap-highlight-color: transparent;
    }

    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1150;
        background: rgba(10, 24, 16, .48);
        border: 0;
        padding: 0;
        margin: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .nav-backdrop[hidden] { display: none !important; }
    body.nav-open { overflow: hidden; }

    #content {
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 10px;
        overflow-x: hidden;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    #content > .table-wrap,
    #content > .dashboard-scroll,
    #content > .att-work,
    #content > .dir-layout,
    #content > .entity-form-page,
    #content > .cur-editor,
    #content > .form-page-scroll,
    #content > .scroll-panel,
    #content > .lessons-att-list {
        flex: 0 0 auto !important;
        min-height: 0;
        max-height: none !important;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    #content > .table-wrap { min-height: 120px; }

    /*#content > .schedule-board,
    #content > #calendar-root {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }*/
    #content > .page-bar {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 5;
        margin-top: 4px;
        padding: 6px 8px;
        background: color-mix(in srgb, var(--bg) 92%, transparent);
        backdrop-filter: blur(6px);
        border-top: 1px solid var(--border);
        border-radius: 10px 10px 0 0;
    }
    .page-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 6px 8px;
        font-size: .75rem;
    }
    .page-bar .page-count {
        flex: 1 1 100%;
        text-align: center;
        line-height: 1.2;
        order: -1;
    }
    .page-bar .page-jump {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        white-space: nowrap;
    }
    .page-bar button,
    .page-bar .btn,
    .page-bar .btn-secondary,
    .page-bar .btn-sm {
        min-height: 32px !important;
        height: 32px !important;
        width: 36px;
        min-width: 36px;
        padding: 0 !important;
        font-size: .95rem;
    }
    .page-bar input[type="number"] {
        width: 3rem;
        min-width: 0;
        min-height: 32px !important;
        height: 32px !important;
        padding: 0 4px !important;
        font-size: .85rem;
        field-sizing: fixed !important;
    }


    .filters > label,
    .filters > label:has(input),
    .filters > label:has(select),
    .filters > label.filter-combo,
    .filters > label.filter-grow {
        flex: 1 1 calc(50% - 8px);
        min-width: min(100%, 140px);
        max-width: none;
    }
    .filters.filters-combos > label.filter-grow { flex: 1 1 100%; }
    .filters select,
    .filters input:not([type="checkbox"]),
    .page-toolbar select,
    .page-toolbar input:not([type="checkbox"]) {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        field-sizing: fixed !important;
        min-height: var(--control-height);
    }
    .filters > button,
    .toolbar-add {
        margin-left: 0 !important;
        min-height: 42px;
    }

    .table-wrap { -webkit-overflow-scrolling: touch; }
    .table-wrap > table, .data-table { min-width: 640px; }

    .dir-layout { grid-template-columns: 1fr; }
    .dir-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-height: none;
        gap: 4px;
    }
    .dir-nav-btn { flex: 0 0 auto; white-space: nowrap; min-height: 42px; }

    .dashboard-grid, .dash-row, .dash-row-3 { grid-template-columns: 1fr !important; }

    button:not(.page-bar button), .btn:not(.page-bar *), .btn-secondary:not(.page-bar *) { min-height: 42px; }
    .btn-sm { min-height: 36px; }


    .schedule-filters-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 100%;
        order: 5;
    }
    .schedule-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: stretch;
    }
    .schedule-toolbar .toolbar-left > #btn-today { display: none; }
    .schedule-toolbar .toolbar-left {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    .schedule-toolbar .toolbar-left > .view-switch {
        width: 100%;
        display: flex;
        flex: none;
    }
    .schedule-toolbar .view-switch {
        height: auto !important;
        width: 100% !important;
    }
    .schedule-toolbar .view-switch .view-btn {
        flex: 1 1 0;
        min-width: 0;
        height: 42px !important;
        min-height: 42px;
        padding: 0 2px !important;
        font-size: .86rem !important;
        white-space: nowrap;
    }
    .schedule-toolbar .toolbar-left > .period-nav {
        width: 100%;
        display: flex;
        align-items: end;
        gap: 4px;
    }
    .schedule-toolbar .period-nav > #btn-prev,
    .schedule-toolbar .period-nav > #btn-next {
        width: 44px;
        min-width: 44px;
        height: 44px;
        padding: 0;
        font-size: 1.35rem;
    }
    .schedule-toolbar .period-label {
        flex: 1 1 auto !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 44px;
        padding: 0 4px !important;
        font-size: .82rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .schedule-toolbar .btn-calendar {
        width: 44px;
        min-width: 44px;
        height: 44px;
        padding: 0;
    }


    .schedule-toolbar .toolbar-right {
        display: none;
        width: 100%;
        margin-left: 0 !important;
        flex-direction: column;
        gap: 8px;
        padding: 10px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        order: 6;
    }
    .schedule-toolbar.filters-open .toolbar-right {
        display: flex;
    }
    .schedule-toolbar .toolbar-field,
    .schedule-toolbar .toolbar-field-combo {
        width: 100%;
        max-width: none;
        flex: none;
    }
    .schedule-toolbar .toolbar-field select,
    .schedule-toolbar .toolbar-combo .select-fio-input,
    .schedule-toolbar .toolbar-combo input[type="search"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        field-sizing: fixed !important;
        min-height: 42px;
    }
    .schedule-toolbar #btn-add {
        width: 100%;
        order: 7;
        min-height: 44px;
    }

    .schedule-board-header { display: none !important; }

    .schedule-list {
        padding: 8px;
        gap: 8px;
        background: var(--bg);
        -webkit-overflow-scrolling: touch;
    }
    .schedule-pair-block { margin: 0; }
    .schedule-pair-sep {
        margin: 4px 0;
        border-radius: 10px;
        border: 1px solid var(--border);
    }

    .schedule-row {
        display: grid !important;
        grid-template-columns: 66px minmax(0, 1fr) !important;
        grid-template-rows: auto auto auto auto !important;
        gap: 2px 12px !important;
        align-items: start !important;
        margin: 0;
        padding: 12px !important;
        background: var(--surface);
        border: 1px solid var(--border) !important;
        border-radius: 14px !important;
        box-shadow: 0 1px 3px rgba(0,0,0,.05);
    }
    .schedule-row .schedule-time {
        grid-column: 1;
        grid-row: 1 / span 4;
        justify-content: flex-start;
        padding-top: 2px;
    }
    .schedule-row .schedule-group {
        grid-column: 2;
        grid-row: 1;
        font-weight: 700;
        font-size: .98rem;
    }
    .schedule-row .schedule-subject {
        grid-column: 2;
        grid-row: 2;
        font-size: .92rem;
        line-height: 1.35;
        color: var(--text);
    }
    .schedule-row .schedule-cabinet {
        grid-column: 2;
        grid-row: 3;
        display: block !important;
        font-size: .84rem;
        color: var(--text-muted);
        margin-top: 4px;
    }
    .schedule-row .schedule-teacher {
        grid-column: 2;
        grid-row: 4;
        display: block !important;
        font-size: .84rem;
        color: var(--text-muted);
    }
    .schedule-cabinet::before {
        content: "Каб. ";
        font-weight: 650;
        color: var(--text-muted);
    }
    .schedule-cabinet > div,
    .schedule-teacher > div {
        display: inline;
        margin-right: 4px;
    }

    .schedule-day-sep {
        border-radius: 10px;
        margin-top: 4px;
    }
}


@media (max-width: 700px) {
    .filters > label,
    .filters > label:has(input),
    .filters > label:has(select),
    .filters > label.filter-combo,
    .filters > label.filter-grow {
        flex: 1 1 100%;
    }

    .form-grid,
    .entity-form-page .form-grid,
    .lesson-fields,
    .lesson-fields-2 {
        grid-template-columns: 1fr !important;
    }
    .form-grid > [style*="grid-column"],
    .form-grid .span-2 {
        grid-column: 1 / -1 !important;
    }

    .modal {
        align-items: stretch !important;
        padding: 0 !important;
    }
    .modal-card,
    .lesson-modal-card,
    .orders-modal-card,
    .contract-modal,
    .diploma-modal,
    .document-modal,
    .history-modal-card {
        width: 100% !important;
        max-width: none !important;
        max-height: 100dvh !important;
        min-height: 100dvh;
        border-radius: 0 !important;
    }
    .modal-actions,
    .lesson-modal-actions,
    .document-actions {
        position: sticky;
        bottom: 0;
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px !important;
        background: var(--surface);
        border-top: 1px solid var(--border);
    }
    .modal-actions > button,
    .lesson-modal-actions > button {
        flex: 1 1 calc(50% - 8px);
        min-height: 44px;
    }

    html, body {
        height: 100% !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }
    main { overflow: hidden !important; }
    #content {
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
    /*#content > .schedule-board,
    #content > #calendar-root {
        flex: 1 1 auto !important;
        min-height: 40dvh !important;
        overflow: hidden !important;
    }*/

}

@supports (padding: max(0px)) {
    @media (max-width: 900px) {
        header {
            padding-top: env(safe-area-inset-top, 0px);
            height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
        }
    }
}
