#mobile-room-list-toggle,
#mobile-user-menu-button {
    display: none;
}

@media (max-width: 720px), (max-width: 900px) and (pointer: coarse) {
    html,
    body,
    #matrixchat,
    .mx_MatrixChat,
    .mx_MatrixChat_wrapper {
        width: 100%;
        height: 100%;
        height: 100dvh;
        overflow: hidden;
    }

    body.mx-mobile-layout .mx_SpacePanel,
    body.mx-mobile-layout .mx_Separator[aria-label="Click or drag to expand"] {
        display: none !important;
    }

    body.mx-mobile-layout.mobile-room-list-open .mx_SpacePanel {
        display: block !important;
        position: fixed !important;
        z-index: 9300 !important;
        top: max(8px, env(safe-area-inset-top)) !important;
        right: max(10px, env(safe-area-inset-right)) !important;
        left: auto !important;
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        border: 0 !important;
        background: transparent !important;
        overflow: visible !important;
    }

    body.mx-mobile-layout.mobile-room-list-open .mx_SpacePanel > :not(.mx_UserMenu) {
        display: none !important;
    }

    body.mx-mobile-layout.mobile-room-list-open .mx_SpacePanel .mx_UserMenu,
    body.mx-mobile-layout.mobile-room-list-open .mx_SpacePanel .mx_UserMenu > div,
    body.mx-mobile-layout.mobile-room-list-open .mx_SpacePanel [aria-label="User menu"] {
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        margin: 0 !important;
    }

    body.mx-mobile-layout .mobile-room-list-slot {
        display: none !important;
        position: fixed !important;
        inset: 0 !important;
        z-index: 9100 !important;
        width: 100vw !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100dvh !important;
        background: var(--cpd-color-bg-canvas-default, #fff);
    }

    body.mx-mobile-layout.mobile-room-list-open .mobile-room-list-slot {
        display: block !important;
    }

    body.mx-mobile-layout .mobile-room-list-slot > .mx_LeftPanel_panel,
    body.mx-mobile-layout .mobile-room-list-slot .mx_LeftPanel_outerWrapper,
    body.mx-mobile-layout .mobile-room-list-slot .mx_LeftPanel_wrapper,
    body.mx-mobile-layout .mobile-room-list-slot .mx_LeftPanel_wrapper--user,
    body.mx-mobile-layout .mobile-room-list-slot .mx_LeftPanel,
    body.mx-mobile-layout .mobile-room-list-slot .mx_LeftPanel_roomListContainer,
    body.mx-mobile-layout .mobile-room-list-slot .mx_RoomListPanel {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100% !important;
        box-sizing: border-box !important;
    }

    body.mx-mobile-layout .mobile-room-list-slot .mx_RoomListPanel {
        padding-top: max(56px, env(safe-area-inset-top)) !important;
    }

    body.mx-mobile-layout .mobile-room-view-slot,
    body.mx-mobile-layout .mobile-room-view-slot > .mx_LeftPanel_panel,
    body.mx-mobile-layout .mobile-room-view-slot .mx_RoomView_wrapper,
    body.mx-mobile-layout .mobile-room-view-slot .mx_RoomView,
    body.mx-mobile-layout .mobile-room-view-slot .mx_MainSplit,
    body.mx-mobile-layout .mobile-room-view-slot .mx_RoomView_body {
        width: 100vw !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100% !important;
    }

    body.mx-mobile-layout .mobile-room-view-slot {
        display: flex !important;
        flex: 1 1 100% !important;
        height: 100dvh !important;
    }

    body.mx-mobile-layout .mobile-room-view-slot > .mx_LeftPanel_panel {
        height: 100% !important;
    }

    #mobile-room-list-toggle,
    #mobile-user-menu-button {
        position: fixed;
        z-index: 9300;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        border: 1px solid var(--cpd-color-border-interactive-secondary, #c1c7d0);
        border-radius: 6px;
        color: var(--cpd-color-text-primary, #1b1d22);
        background: var(--cpd-color-bg-canvas-default, #fff);
        box-shadow: 0 2px 8px rgb(0 0 0 / 14%);
        font: inherit;
        touch-action: manipulation;
    }

    body.mx-mobile-layout #mobile-room-list-toggle {
        display: flex;
        top: max(8px, env(safe-area-inset-top));
        left: max(8px, env(safe-area-inset-left));
        font-size: 25px;
        line-height: 1;
    }

    body.mx-mobile-layout:not(.mobile-room-list-open) .mx_RoomHeader {
        width: 100% !important;
        min-width: 0 !important;
        height: 64px !important;
        min-height: 64px !important;
        padding-right: max(8px, env(safe-area-inset-right)) !important;
        padding-left: max(60px, calc(env(safe-area-inset-left) + 60px)) !important;
        gap: 4px !important;
        box-sizing: border-box !important;
    }

    body.mx-mobile-layout .mx_RoomHeader > [aria-label="Open room settings"],
    body.mx-mobile-layout .mx_RoomHeader > [aria-label="Threads"],
    body.mx-mobile-layout .mx_RoomHeader > [aria-label="People"],
    body.mx-mobile-layout .mx_RoomHeader > [aria-label="Room info"]:not(.mx_RoomHeader_infoWrapper) {
        display: none !important;
    }

    body.mx-mobile-layout .mx_RoomHeader_infoWrapper {
        flex: 1 1 auto !important;
        width: auto !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    body.mx-mobile-layout .mx_RoomHeader_infoWrapper h1,
    body.mx-mobile-layout .mx_RoomHeader_infoWrapper [title] {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.mx-mobile-layout .mx_RoomHeader > button,
    body.mx-mobile-layout .mx_MessageComposer button,
    body.mx-mobile-layout #mx_ContextualMenu_Container [role="menuitem"] {
        min-width: 40px;
        min-height: 40px;
        touch-action: manipulation;
    }

    body.mx-mobile-layout .mx_RoomView_timeline,
    body.mx-mobile-layout .mx_RoomView_statusArea,
    body.mx-mobile-layout .mx_MessageComposer {
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    body.mx-mobile-layout .mx_MessageComposer {
        padding-right: max(8px, env(safe-area-inset-right)) !important;
        padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
        padding-left: max(8px, env(safe-area-inset-left)) !important;
    }

    body.mx-mobile-layout .mx_EventTile,
    body.mx-mobile-layout .mx_EventTile_line,
    body.mx-mobile-layout .mx_EventTile_content,
    body.mx-mobile-layout .mx_RoomView_MessageList {
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-wrap: anywhere;
    }

    body.mx-mobile-layout .mx_RightPanel {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9200 !important;
        width: 100vw !important;
        min-width: 0 !important;
        max-width: none !important;
        height: 100dvh !important;
    }

    body.mx-mobile-layout #mx_Dialog_Container .mx_Dialog,
    body.mx-mobile-layout #mx_Dialog_StaticContainer .mx_Dialog {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        max-height: calc(100dvh - 24px) !important;
        margin: 12px !important;
        box-sizing: border-box !important;
        overflow: auto;
    }

    body.mx-mobile-layout #mx_ContextualMenu_Container .mx_ContextualMenu {
        max-width: calc(100vw - 16px) !important;
        max-height: calc(100dvh - 16px) !important;
        overflow: auto;
    }
}
