/*
 * ALSHOP_AI_HUMAN_MULTI_INTENT_BRAIN_V2_8_0
 *
 * Mobile repair for both assistant layouts that may exist after V2.7.0:
 * 1. the current v204 fixed-grid mobile app (.alshop-ai-*), and
 * 2. the legacy card layout (.alpf-ai-*).
 *
 * The current layout keeps scrolling inside the assistant. The important
 * repair is removing the V2.6 forced message height, which was competing
 * with the product-results row and pushing/clipping the product preview.
 */
@media (max-width: 991.98px) {
    /* Current production mobile layout. */
    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-chat-panel {
        min-width: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root #alpf-ai-messages {
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-mobile-results {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        max-height: min(46dvh, 440px) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch;
        scroll-padding-top: 8px;
        scroll-padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
        scrollbar-gutter: stable;
        box-sizing: border-box !important;
        padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)) !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-mobile-results:empty {
        display: none !important;
        min-height: 0 !important;
        padding: 0 !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product {
        grid-template-columns: 92px minmax(0, 1fr) !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 150px !important;
        max-height: none !important;
        align-items: stretch !important;
        box-sizing: border-box !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-media {
        width: 92px !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 150px !important;
        overflow: hidden !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-media img {
        display: block !important;
        width: 100% !important;
        height: 112px !important;
        max-height: 112px !important;
        object-fit: contain !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-body {
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 150px !important;
        max-height: none !important;
        overflow: visible !important;
        box-sizing: border-box !important;
        padding: 10px 9px !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-title,
    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-reason {
        overflow-wrap: anywhere !important;
        word-break: normal !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-title {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 0 5px !important;
        padding: 2px 0 3px !important;
        overflow: visible !important;
        white-space: normal !important;
        text-overflow: clip !important;
        line-height: 1.42 !important;
        -webkit-box-orient: initial !important;
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-reason {
        -webkit-line-clamp: 3 !important;
        line-height: 1.42 !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-foot {
        width: 100% !important;
        min-width: 0 !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 6px !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-commerce-actions-v230 {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        width: 100% !important;
        min-width: 0 !important;
        gap: 6px !important;
        margin-top: 8px !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-commerce-actions-v230 button,
    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-commerce-actions-v230 a {
        min-width: 0 !important;
        min-height: 40px !important;
        height: auto !important;
        padding: 7px 8px !important;
        white-space: normal !important;
        line-height: 1.25 !important;
        box-sizing: border-box !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root #alpf-ai-form {
        position: relative !important;
        inset: auto !important;
        bottom: auto !important;
        z-index: 120 !important;
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
        background: rgba(255, 255, 255, .99) !important;
    }

    /* Legacy layout fallback. Everything is scoped to the legacy card so it
       cannot override the current fixed-grid mobile application. */
    #alpf-ai-root .alpf-ai-chat-card {
        display: flex !important;
        flex-direction: column !important;
        height: calc(100dvh - 132px - var(--alshop-mobile-nav-height, 64px) - env(safe-area-inset-bottom, 0px)) !important;
        min-height: 430px !important;
        max-height: calc(100dvh - 132px - var(--alshop-mobile-nav-height, 64px) - env(safe-area-inset-bottom, 0px)) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch;
        scroll-padding-top: 68px;
        scroll-padding-bottom: 92px;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-chat-head {
        position: sticky !important;
        top: 0 !important;
        z-index: 110 !important;
        flex: 0 0 auto !important;
        background: rgba(255, 255, 255, .985) !important;
    }

    #alpf-ai-root .alpf-ai-chat-card #alpf-ai-messages {
        flex: 0 0 auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        padding-bottom: 8px !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-results {
        display: grid !important;
        flex: 0 0 auto !important;
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        box-sizing: border-box !important;
        padding: 6px 10px 14px !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product {
        display: grid !important;
        grid-template-columns: 92px minmax(0, 1fr) !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 148px !important;
        max-height: none !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        align-items: stretch !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-media,
    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-body {
        min-width: 0 !important;
        min-height: 148px !important;
        height: auto !important;
        max-height: none !important;
        box-sizing: border-box !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-body {
        overflow: visible !important;
        padding: 10px 9px !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-title,
    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-reason {
        overflow-wrap: anywhere !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-title {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 0 5px !important;
        padding: 2px 0 3px !important;
        overflow: visible !important;
        white-space: normal !important;
        text-overflow: clip !important;
        line-height: 1.42 !important;
        -webkit-box-orient: initial !important;
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
    }

    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product-reason {
        -webkit-line-clamp: 3 !important;
        line-height: 1.42 !important;
    }

    #alpf-ai-root .alpf-ai-chat-card #alpf-ai-form {
        position: sticky !important;
        bottom: 0 !important;
        z-index: 120 !important;
        flex: 0 0 auto !important;
        width: 100% !important;
        margin-top: 0 !important;
        box-sizing: border-box !important;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
        background: rgba(255, 255, 255, .99) !important;
        box-shadow: 0 -9px 20px rgba(15, 23, 42, .08) !important;
    }
}

@media (max-width: 380px) {
    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product,
    #alpf-ai-root .alpf-ai-chat-card .alpf-ai-product {
        grid-template-columns: 82px minmax(0, 1fr) !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-product-media {
        width: 82px !important;
    }

    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-commerce-actions-v230,
    #alpf-ai-root .alpf-ai-chat-card .alshop-ai-commerce-actions-v230 {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 991.98px) and (max-height: 620px) {
    body.alshop-ai-mobile-app-v204 #alpf-ai-root .alshop-ai-mobile-results {
        max-height: 50dvh !important;
    }

    #alpf-ai-root .alpf-ai-chat-card {
        min-height: 340px !important;
    }
}
