/* KPД branded mobile surface. Loaded after Element's theme CSS. */
:root[data-kpd-mobile] {
    --kpd-mobile-accent: #135f9c;
    --kpd-mobile-accent-strong: #0d4b7c;
    --kpd-mobile-surface: #f7f9fc;
    --kpd-mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 720px), (display-mode: standalone) {
    html,
    body,
    #matrixchat {
        min-height: 100%;
        min-height: 100dvh;
        width: 100%;
        overflow: hidden;
    }

    body {
        background: var(--kpd-mobile-surface);
        overscroll-behavior-y: none;
        -webkit-tap-highlight-color: color-mix(in srgb, var(--kpd-mobile-accent) 20%, transparent);
    }

    #matrixchat {
        padding-bottom: var(--kpd-mobile-safe-bottom);
        box-sizing: border-box;
    }

    /* Keep touch targets usable without changing the desktop component tree. */
    button,
    [role="button"],
    a {
        touch-action: manipulation;
    }

    .mx_RoomHeader button,
    .mx_MessageComposer button,
    .mx_LeftPanel button,
    .mx_SpacePanel button,
    .mx_Dialog button,
    .mx_Dialog [role="button"] {
        min-height: 40px;
    }

    /* Prevent mobile browsers from zooming focused form controls. */
    input,
    textarea,
    select {
        font-size: 16px;
    }

    /* Let the room timeline and composer consume the viewport, not the page. */
    [data-testid="room-view"],
    .mx_RoomView,
    .mx_RoomView_body,
    .mx_RoomView_timeline,
    .mx_RoomView_scrollheader {
        min-height: 0;
    }

    .mx_RoomView_body,
    .mx_RoomView_timeline {
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .mx_CompoundRoomHeader,
    .mx_RoomHeader,
    .mx_SearchBox {
        min-height: 48px;
    }

    .mx_SearchBox input,
    .mx_SearchBox_textinput {
        min-height: 40px;
        border-radius: 12px;
    }

    .mx_Dialog_wrapper,
    .mx_Dialog,
    .mx_Dialog_fixedWidth {
        max-width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
    }

    .mx_Dialog_wrapper {
        margin: 12px;
    }

    .mx_UserView_tile,
    .mx_RoomList .mx_RoomTile,
    .mx_InviteTile {
        min-height: 52px;
    }

    /* Compact the persistent navigation while retaining Element's own controls. */
    .mx_LeftPanel {
        max-width: min(88vw, 360px);
    }

    .mx_MessageComposer {
        padding-bottom: max(8px, var(--kpd-mobile-safe-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    :root[data-kpd-mobile] *,
    :root[data-kpd-mobile] *::before,
    :root[data-kpd-mobile] *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
