/* ========================================================================
   ZENCODE MOBILE SCROLL OVERRIDES

   Keep future phone and mobile-landscape changes in this file. The main
   workspace CSS is intentionally left untouched.
   ======================================================================== */

/* Phones: let the workspace become a normal document-length interface.
   The editor and assistant retain useful working heights, while the browser
   can scroll past the preview/guest bars and all the way to the footer. */
@media (max-width: 768px) {
    html body #ai_app_root {
        display: block !important;
        height: auto !important;
        min-height: 100dvh !important;
        max-height: none !important;
        overflow: visible !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }

    body #ai_app_root .zencode-main-wrapper {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        min-height: 100dvh !important;
        max-height: none !important;
        overflow: visible !important;
        align-self: auto !important;
    }

    body #ai_app_root .main-layout {
        flex: 1 0 auto !important;
        grid-template-columns: minmax(0, 1fr) !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .content-area {
        display: grid !important;
        grid-template-rows: auto auto !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .panels-container {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .code-editor-panel {
        flex: 0 0 clamp(340px, 55dvh, 520px) !important;
        height: clamp(340px, 55dvh, 520px) !important;
        min-height: 340px !important;
        max-height: none !important;
        overflow: hidden !important;
    }

    body #ai_app_root .chat-panel {
        position: relative !important;
        flex: 0 0 auto !important;
        height: auto !important;
        min-height: clamp(560px, 75dvh, 760px) !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .chat-messages {
        flex: 1 1 auto !important;
        min-height: 300px !important;
        max-height: none !important;
        margin-bottom: 0 !important;
        padding-bottom: 1rem !important;
        overflow-y: visible !important;
    }

    body #ai_app_root .chat-input-container {
        position: static !important;
        inset: auto !important;
        transform: none !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding-bottom: max(0.7rem, env(safe-area-inset-bottom)) !important;
    }

    body #ai_app_root .app-footer {
        position: static !important;
        flex: 0 0 auto !important;
        margin: 0 !important;
    }
}

/* Portrait only: the workspace deliberately uses page scrolling, so the
   progress card must follow the viewport rather than its tall content area.
   Keep mobile landscape and larger screens exactly as they were. */
@media (orientation: portrait) and (max-width: 500px) {
    html body #ai_app_root #footer-progress-bar {
        position: fixed !important;
        top: auto !important;
        bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
        left: calc(0.75rem + env(safe-area-inset-left, 0px)) !important;
        right: calc(0.75rem + env(safe-area-inset-right, 0px)) !important;
        width: auto !important;
        max-height: calc(100dvh - 1.5rem - env(safe-area-inset-bottom, 0px)) !important;
        overflow-y: auto !important;
        z-index: 1000 !important;
    }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 600px) {
    html body #ai_app_root {
        height: 100% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        overflow: hidden !important;
        padding-bottom: 0 !important;
    }

    body #ai_app_root .zencode-main-wrapper {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        overflow-x: hidden !important;
        overflow-y: scroll !important;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        padding-bottom: 0 !important;
    }

    body #ai_app_root .main-layout,
    body #ai_app_root .content-area,
    body #ai_app_root .panels-container {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .content-area,
    body #ai_app_root .panels-container {
        display: flex !important;
        flex-direction: column !important;
    }

    body #ai_app_root .code-editor-panel {
        flex: 0 0 320px !important;
        height: 320px !important;
        min-height: 320px !important;
        max-height: none !important;
        overflow: hidden !important;
    }

    body #ai_app_root .chat-panel {
        position: relative !important;
        flex: 0 0 auto !important;
        height: auto !important;
        min-height: 360px !important;
        max-height: none !important;
        overflow: visible !important;
    }

    body #ai_app_root .chat-messages {
        flex: 1 1 auto !important;
        min-height: 220px !important;
        margin-bottom: 0 !important;
        padding: 0.8rem !important;
        overflow-y: auto !important;
    }

    body #ai_app_root .chat-input-container {
        position: static !important;
        inset: auto !important;
        transform: none !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0.7rem 0.75rem !important;
        display: flex !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        gap: 0.55rem !important;
    }

    body #ai_app_root .chat-input-container > #chat-input {
        flex: 1 1 auto !important;
        width: auto !important;
        min-width: 0 !important;
        min-height: 48px !important;
        max-height: 76px !important;
    }

    body #ai_app_root .chat-input-container > .voice-button,
    body #ai_app_root .chat-input-container > .send-button {
        flex: 0 0 auto !important;
        min-height: 48px !important;
    }

    body #ai_app_root .app-footer {
        flex: 0 0 auto !important;
        margin: 0 !important;
        padding-bottom: 0.5rem !important;
    }
}
