/* ============================================
   Mobile AI Widgets Optimization
   ============================================ */

/* Mobile Button Group Container */
#mobile-ai-widgets-group {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999999;
    display: none;
}

/* Mobile: Show button group, hide individual buttons */
@media (max-width: 768px) {
    /* Hide all individual AI widget buttons on mobile visually, but keep them accessible for click events */
    #ghost-chat-button,
    #relationship-mapper-button,
    #briefing-button,
    #ai-ds-button {
        position: absolute !important;
        left: -9999px !important;
        opacity: 0 !important;
        pointer-events: auto !important; /* Keep clickable for mobile menu */
        visibility: hidden !important;
        width: 1px !important;
        height: 1px !important;
    }
    
    /* Show only the purple Expert Consultation button - Positioned LEFT of black button */
    #expert-consultation-widget {
        display: block !important;
        visibility: visible !important;
        bottom: 20px; /* At bottom of screen */
        left: auto;
        right: 91px; /* 56px (button width) + 20px (right margin) + 15px (gap) = 91px from right */
        z-index: 99999999;
    }
    
    /* Mobile AI Widgets Group - Show on mobile, positioned RIGHT (where purple button was) */
    #mobile-ai-widgets-group {
        display: block;
        bottom: 20px; /* Same height as purple button */
        left: auto;
        right: 20px; /* Right position where purple button was */
        z-index: 99999999;
    }
    
    /* Mobile Menu Button - Same size as purple Expert Consultation button */
    #mobile-ai-menu-button {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        max-width: 56px !important;
        max-height: 56px !important;
        border-radius: 28px !important;
        background: linear-gradient(135deg, #2d3436 0%, #1a1a1a 50%, #000000 100%);
        border: none;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        position: relative;
        z-index: 99999998;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    #mobile-ai-menu-button.active {
        transform: rotate(45deg);
        background: linear-gradient(135deg, #666 0%, #444 50%, #222 100%);
    }
    
    #mobile-ai-menu-button svg {
        width: 28px;
        height: 28px;
        filter: brightness(0) invert(1);
    }
    
    /* Mobile Menu Items Container */
    #mobile-ai-menu-items {
        position: absolute;
        bottom: 70px;
        left: 0;
        right: auto;
        display: none;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    
    #mobile-ai-menu-items.open {
        display: flex;
    }
    
    /* Mobile Menu Item Buttons */
    .mobile-ai-menu-item {
        width: 56px;
        height: 56px;
        border-radius: 28px;
        background: linear-gradient(135deg, #2d3436 0%, #1a1a1a 50%, #000000 100%);
        border: none;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        opacity: 0;
        transform: translateY(20px);
        animation: slideUpMobile 0.3s ease forwards;
    }
    
    .mobile-ai-menu-item:nth-child(1) {
        animation-delay: 0.05s;
    }
    
    .mobile-ai-menu-item:nth-child(2) {
        animation-delay: 0.1s;
    }
    
    .mobile-ai-menu-item:nth-child(3) {
        animation-delay: 0.15s;
    }
    
    .mobile-ai-menu-item:nth-child(4) {
        animation-delay: 0.2s;
    }
    
    @keyframes slideUpMobile {
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .mobile-ai-menu-item img,
    .mobile-ai-menu-item svg {
        width: 28px;
        height: 28px;
        filter: brightness(0) invert(1);
    }
    
    .mobile-ai-menu-item:hover {
        transform: scale(1.1);
    }
    
    /* Force fullscreen mode for all AI widgets on mobile */
    #ghost-chat-container.open,
    #ghost-chat-container.is-open {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        transform: none !important;
        z-index: 2147483647 !important;
        position: fixed !important;
        display: flex !important;
    }
    
    #relationship-mapper-panel.open,
    #relationship-mapper-panel.is-open {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 2147483647 !important;
        position: fixed !important;
        display: flex !important;
    }
    
    #briefing-panel.open,
    #briefing-panel.is-open {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 2147483647 !important;
        position: fixed !important;
        display: flex !important;
    }
    
    #ai-ds-panel.open,
    #ai-ds-panel.is-open {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 2147483647 !important;
        position: fixed !important;
        display: flex !important;
    }
    
    #expert-consultation-panel.open {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 2147483647 !important;
        position: fixed !important;
        display: flex !important;
    }
    
    /* Hide resize buttons on mobile */
    .ghost-chat-resize-btn,
    .relationship-mapper-resize-btn,
    .briefing-resize-btn,
    .ai-ds-resize-btn {
        display: none !important;
    }
    
    /* Adjust Expert Consultation button size on mobile */
    #expert-consultation-button {
        width: 56px;
        height: 56px;
        border-radius: 28px;
    }
    
    #expert-consultation-button svg {
        width: 28px;
        height: 28px;
    }

    /* HIDE BUTTONS WHEN NAVIGATION IS OPEN */
    body:has(.gh-navigation.is-open) #mobile-ai-widgets-group,
    body:has(.gh-navigation.is-open) #expert-consultation-widget {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* HIDE BUTTONS WHEN ANY PANEL IS OPEN */
    body:has(#ghost-chat-container.open) #mobile-ai-widgets-group,
    body:has(#ghost-chat-container.is-open) #mobile-ai-widgets-group,
    body:has(#ghost-chat-container.open) #expert-consultation-widget,
    body:has(#ghost-chat-container.is-open) #expert-consultation-widget,
    body:has(#relationship-mapper-panel.open) #mobile-ai-widgets-group,
    body:has(#relationship-mapper-panel.is-open) #mobile-ai-widgets-group,
    body:has(#relationship-mapper-panel.open) #expert-consultation-widget,
    body:has(#relationship-mapper-panel.is-open) #expert-consultation-widget,
    body:has(#briefing-panel.open) #mobile-ai-widgets-group,
    body:has(#briefing-panel.is-open) #mobile-ai-widgets-group,
    body:has(#briefing-panel.open) #expert-consultation-widget,
    body:has(#briefing-panel.is-open) #expert-consultation-widget,
    body:has(#ai-ds-panel.open) #mobile-ai-widgets-group,
    body:has(#ai-ds-panel.is-open) #mobile-ai-widgets-group,
    body:has(#ai-ds-panel.open) #expert-consultation-widget,
    body:has(#ai-ds-panel.is-open) #expert-consultation-widget,
    body:has(#expert-consultation-panel.open) #mobile-ai-widgets-group,
    body:has(#expert-consultation-panel.is-open) #mobile-ai-widgets-group,
    body:has(#expert-consultation-panel.open) #expert-consultation-widget,
    body:has(#expert-consultation-panel.is-open) #expert-consultation-widget {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    #mobile-ai-widgets-group {
        bottom: 15px; /* At bottom of screen */
        left: auto;
        right: 15px; /* Right position where purple button was */
    }
    
    #expert-consultation-widget {
        bottom: 15px; /* At bottom of screen */
        left: auto;
        right: 87px; /* 52px (button width) + 15px (right margin) + 15px (gap) + 5px (adjustment) = 87px from right */
    }
    
    /* Very small screens - Match Expert Consultation button size */
    #mobile-ai-menu-button,
    .mobile-ai-menu-item {
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        min-height: 52px !important;
        max-width: 52px !important;
        max-height: 52px !important;
        border-radius: 26px !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    #mobile-ai-menu-button svg,
    .mobile-ai-menu-item img,
    .mobile-ai-menu-item svg {
        width: 24px !important;
        height: 24px !important;
    }
}