/* ==========================================================
   COMMANDS.PHP — DEDICATED MOBILE SIMULATOR DRAWER FIX
   Loaded AFTER commands.css • Zero impact on Desktop (> 1080px)
========================================================== */
@media (max-width: 1080px) {
    html,
    body.commands-page {
        overflow-x: clip !important;
        max-width: 100% !important;
    }

    body.commands-page .cmd-main {
        z-index: auto !important;
        max-width: 100% !important;
    }

    body.commands-page .cmd-hero-card,
    body.commands-page .cmd-controls-card,
    body.commands-page .cmd-workspace,
    body.commands-page .cmd-list-col {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* Hide mobile Live Preview drawer completely until explicitly opened */
    body.commands-page #cmdSimDrawer {
        position: fixed !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        padding: 12px 10px max(12px, env(safe-area-inset-bottom)) !important;
        z-index: 1200 !important;
        display: flex !important;
        align-items: flex-end !important;
        justify-content: center !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transform: translateY(28px) !important;
        transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s ease !important;
        overflow: hidden !important;
    }

    body.commands-page #cmdSimDrawer.sg-sim-open {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: translateY(0) !important;
    }

    body.commands-page #cmdSimDrawer #cmdSimBackdrop {
        position: fixed !important;
        inset: 0 !important;
        z-index: 1 !important;
        display: block !important;
        background: rgba(6, 3, 22, 0.78) !important;
        backdrop-filter: blur(6px) !important;
        -webkit-backdrop-filter: blur(6px) !important;
        pointer-events: auto !important;
    }

    body.commands-page #cmdSimDrawer .cmd-sim-shell {
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        z-index: 2 !important;
        width: 100% !important;
        max-width: 520px !important;
        max-height: calc(100dvh - 24px) !important;
        height: auto !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        border-radius: 18px !important;
        box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85) !important;
        pointer-events: auto !important;
    }

    body.commands-page #cmdSimDrawer .cmd-sim-header,
    body.commands-page #cmdSimDrawer .cmd-slash-picker,
    body.commands-page #cmdSimDrawer .cmd-sim-footer {
        flex-shrink: 0 !important;
    }

    body.commands-page #cmdSimDrawer .cmd-sim-close-mobile {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
        z-index: 6 !important;
        pointer-events: auto !important;
        cursor: pointer !important;
    }

    body.commands-page #cmdSimDrawer .cmd-dc-stage {
        flex: 1 1 auto !important;
        min-height: 150px !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    body.commands-page #cmdSimDrawer .cmd-sim-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
    }

    /* Lock background page scroll ONLY while the mobile preview is open */
    body.commands-page.sg-cmd-sim-locked {
        overflow: hidden !important;
    }

    /* Floating Live Preview button: visible when closed, hidden cleanly when open */
    body.commands-page #cmdMobileSimFab {
        z-index: 950 !important;
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease !important;
    }

    body.commands-page.sg-cmd-sim-locked #cmdMobileSimFab {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        transform: translateY(20px) scale(0.92) !important;
    }
}
