.chat-app {
    display: grid;
    grid-template-columns: var(--chat-sidebar-width) minmax(0, 1fr);
    width: 100%;
    max-width: 100vw;
    height: 100dvh;
    height: 100svh;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
    background: var(--chat-bg-main);
}

.chat-sidebar {
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.chat-main {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        radial-gradient(1200px 500px at 50% -10%, var(--chat-main-glow), transparent 60%),
        var(--chat-bg-main);
}

.chat-workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.chat-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0 16px;
    overflow: hidden;
    min-height: 0;
}

.chat-stage__center {
    width: min(100%, var(--chat-stage-max));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: auto;
    animation: stage-in 420ms var(--chat-transition) both;
}

@keyframes stage-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Desktop collapsed: one column only; sidebar becomes off-canvas */
.chat-app[data-sidebar-open="false"] {
    grid-template-columns: minmax(0, 1fr);
}

.chat-app[data-sidebar-open="false"] .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--chat-sidebar-width);
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    opacity: 0;
    pointer-events: none;
    transition: transform var(--chat-transition), opacity var(--chat-transition);
}

.chat-app[data-sidebar-open="false"] .chat-main {
    grid-column: 1;
    width: 100%;
}

.chat-app[data-sidebar-open="false"] .chat-topbar__menu {
    display: inline-flex;
}

.chat-topbar__menu {
    display: none;
}

.chat-composer-dock {
    flex: 0 0 auto;
    width: min(100%, var(--chat-stage-max));
    margin: 0 auto;
    padding: 4px 16px calc(14px + var(--chat-safe-bottom));
    box-sizing: border-box;
    background: linear-gradient(180deg, transparent, var(--chat-bg-main) 30%);
}

/* ========== Mobile app shell ========== */
@media (max-width: 900px) {
    .chat-app {
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        max-width: 100vw;
        height: 100dvh;
        height: 100svh;
        max-height: 100dvh;
        overflow: hidden;
    }

    .chat-app[data-sidebar-open="false"],
    .chat-app[data-sidebar-open="true"] {
        grid-template-columns: none;
    }

    .chat-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        max-width: 320px;
        height: 100dvh !important;
        z-index: 50;
        transform: translate3d(-105%, 0, 0) !important;
        opacity: 1 !important;
        pointer-events: none;
        transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
        box-shadow: none;
        border-right: 0;
        border-radius: 0 20px 20px 0;
        overflow: hidden;
    }

    .chat-app[data-sidebar-open="true"] .chat-sidebar {
        transform: translate3d(0, 0, 0) !important;
        pointer-events: auto;
        box-shadow: var(--chat-shadow-drawer);
    }

    .chat-app[data-sidebar-open="true"]::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.42);
        backdrop-filter: blur(3px);
        z-index: 45;
    }

    .chat-main {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        width: 100%;
        max-width: 100vw;
        height: 100%;
        min-height: 0;
        max-height: 100%;
        background: var(--chat-bg-main);
        overflow: hidden;
    }

    .chat-topbar__menu {
        display: inline-flex !important;
    }

    .chat-stage {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
        min-height: 0;
        padding: 4px 14px 0;
        overflow: hidden;
    }

    .chat-stage__center {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        min-height: 0;
        gap: 12px;
        align-items: stretch;
        justify-content: center;
        margin: 0;
        padding: 0;
        animation: none;
    }

    .chat-composer-dock {
        flex: 0 0 auto;
        position: relative;
        z-index: 20;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 4px 12px calc(10px + var(--chat-safe-bottom));
        background: linear-gradient(180deg, transparent 0%, var(--chat-bg-main) 36%);
        box-sizing: border-box;
    }
}

@media (max-height: 700px) {
    .chat-stage {
        padding-block: 4px;
    }

    .chat-stage__center {
        gap: 10px;
    }

    .chat-composer-dock {
        padding-top: 2px;
        padding-bottom: calc(8px + var(--chat-safe-bottom));
    }
}

body.voice-open,
body.sidebar-open,
body.ui-modal-open {
    overflow: hidden;
    touch-action: none;
}

.chat-conv.is-busy {
    pointer-events: none;
    opacity: 0.65;
}
