/* Keep the existing menu design; let its full content scroll on small screens. */
html body main.frontend-content {
    min-height: max(0px, calc(100dvh - var(--app-header-offset, 64px) - 16px));
}

@media (max-width: 767px) {
    html body .panel-new > nav .box-wrapper .box-item > a {
        height: 100%;
        min-height: 92px;
        aspect-ratio: auto;
    }

    html body .panel-new > nav .salemdos-tile-label {
        flex-shrink: 0;
    }

    html body .profile-screen :is(.profile-phone-row, .profile-face-row, .profile-notifications > .row) > :is(.col-8, .col-9),
    html body .registration-screen .row:has(> .col-3 > .face-id-icon) > .col-9,
    html body .registration-screen .row:has(> .col-4 > [data-push-config]) > .col-8 {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        overflow-wrap: anywhere;
    }

    html body .profile-screen :is(.profile-phone-row, .profile-face-row, .profile-notifications > .row) > :is(.col-3, .col-4),
    html body .registration-screen .row:has(> .col-3 > .face-id-icon) > .col-3,
    html body .registration-screen .row:has(> .col-4 > [data-push-config]) > .col-4 {
        flex: 0 0 auto;
        width: max-content;
        max-width: 100%;
    }

    html body .legacy-rental-workspace > .row > .page-title > .col-7 {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        overflow-wrap: anywhere;
    }

    html body .legacy-rental-workspace > .row > .page-title:has(> .col-7) > .col-2 {
        flex: 0 0 34px;
        max-width: 34px;
        padding-inline: 0;
    }
    html body .panel-new.active {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        scroll-padding-block: 16px 48px;
    }

    html body .panel-new.active > :is(.top, nav, .box-result) {
        flex-shrink: 0;
    }

    html:not(.pwa-standalone) body .panel-new.active {
        overscroll-behavior-y: none;
    }

    html:not(.pwa-standalone) body .panel-new.active > .top {
        position: sticky;
        top: 0;
        z-index: 3;
    }

    html body .panel-new.active > .menu-wrapper {
        display: block;
        flex: 1 0 auto;
        height: auto;
        min-height: 0;
        overflow: visible;
        padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
    }

    html body .panel-new.active > .menu-wrapper > div {
        height: auto;
        margin-bottom: 0;
    }

    html.pwa-standalone body .panel-new.active {
        top: var(--pwa-visible-top, 0px);
        bottom: auto;
        height: var(--pwa-visible-height, 100dvh);
        min-height: 0 !important;
    }

    html.pwa-standalone main.page {
        padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px));
        overflow-wrap: break-word;
    }

    html.pwa-standalone :is(.legacy-popup-panel, .modal-content):not(:where(:is(.legacy-popup, .modal):has(form :is(input:not([type="hidden"]), textarea, select)) *)) {
        max-height: calc(var(--pwa-visible-height, 100dvh) - 32px);
        overflow-y: auto;
        overscroll-behavior-y: contain;
    }

    /* Editable modals follow the visible viewport. Only the form body scrolls. */
    html.pwa-standalone body :is(.legacy-popup:not([hidden]), .modal.show):has(form :is(input:not([type="hidden"]), textarea, select)) {
        --modal-top: var(--pwa-visible-top, 0px);
        --modal-height: var(--pwa-visible-height, 100dvh);
        --modal-bottom-gap: calc(var(--pwa-layout-height, 100dvh) - var(--modal-top) - var(--modal-height));
        position: fixed;
        top: var(--modal-top);
        bottom: auto;
        height: var(--modal-height);
        box-sizing: border-box;
        padding-block: calc(12px + max(0px, env(safe-area-inset-top, 0px) - var(--modal-top)))
            calc(12px + max(0px, env(safe-area-inset-bottom, 0px) - max(0px, var(--modal-bottom-gap))));
        overflow: hidden;
    }

    html.pwa-standalone body .modal.show:has(form :is(input:not([type="hidden"]), textarea, select)) > .modal-dialog {
        display: flex;
        align-items: center;
        min-height: 0;
        height: 100%;
        margin-block: 0;
    }

    html.pwa-standalone .modal.show:has(form :is(input:not([type="hidden"]), textarea, select)) > .modal-dialog::before {
        display: none;
    }

    html.pwa-standalone :is(.legacy-popup, .modal):has(form :is(input:not([type="hidden"]), textarea, select)) :is(.legacy-popup-panel, .modal-content) {
        display: flex;
        flex-direction: column;
        min-height: 0;
        max-height: 100%;
        overflow: hidden;
    }

    html.pwa-standalone :is(.legacy-popup-panel, .modal-content) > form:has(> :is(.legacy-popup-body, .modal-body)):has(:is(input:not([type="hidden"]), textarea, select)) {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1 1 auto;
    }

    html.pwa-standalone :is(.legacy-popup, .modal):has(form :is(input:not([type="hidden"]), textarea, select)) :is(.legacy-popup-header, .modal-header, .legacy-popup-footer, .modal-footer) {
        flex: 0 0 auto;
    }

    html.pwa-standalone :is(.legacy-popup, .modal):has(form :is(input:not([type="hidden"]), textarea, select)) :is(.legacy-popup-body, .modal-body) {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior-y: contain;
    }

    html.pwa-standalone .legacy-popup-body {
        min-height: 0;
        overflow-y: auto;
    }
}

@media (min-width: 768px) and (max-width: 769px) {
    html body .panel-new.active {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        scroll-padding-block: 16px 48px;
    }

    html body .panel-new.active > .menu-wrapper {
        flex: 1 0 auto;
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    html.pwa-standalone body .panel-new.active {
        overscroll-behavior-y: none;
    }

    html.pwa-standalone body .panel-new.active > .top {
        position: sticky;
        top: 0;
        z-index: 3;
    }
}

@media (max-width: 360px) {
    html body .profile-screen {
        padding-inline: 15px;
    }
}
