/* Floating Widget Styles */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10001; /* Higher than mobile-bottom-nav (9999) */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: bottom 0.3s ease;
}

@media (max-width: 767.98px) {
    .ai-chat-widget {
        bottom: 75px; /* Above mobile-bottom-nav (60px) + spacing */
        right: 15px;
        z-index: 100000;
    }
    
    /* Full-screen Mobile Sheet chuẩn PWA di động khi mở chat */
    .ai-chat-widget.expanded {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        z-index: 2147483647 !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }
    
    .ai-chat-widget.expanded .ai-chat-container {
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        display: flex !important;
        flex-direction: column !important;
        box-shadow: none !important;
    }
    
    .ai-chat-widget.expanded .card-header {
        border-radius: 0 !important;
        padding: 12px 16px !important;
        flex-shrink: 0 !important;
        background: #0f172a !important;
    }
    
    .ai-chat-widget.expanded .ai-training-notice {
        flex-shrink: 0 !important;
        padding: 8px 14px !important;
        font-size: 11.5px !important;
    }
    
    .ai-chat-widget.expanded .card-body {
        flex: 1 1 auto !important;
        height: auto !important;
        max-height: none !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    
    .ai-chat-widget.expanded .chat-box {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 14px !important;
    }
    
    .ai-chat-widget.expanded #text-controls {
        flex-shrink: 0 !important;
        padding: 10px 14px !important;
        padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
        background: #ffffff !important;
        border-top: 1px solid #e2e8f0 !important;
    }
    
    .ai-chat-widget.expanded #ai-chat-input {
        font-size: 16px !important; /* Chống tự động zoom trên iOS Safari */
    }
}

/* Toggle Button */
.ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
    border: 1px solid #d97706 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 15px rgba(217, 119, 6, 0.35) !important;
    transition: transform 0.3s, box-shadow 0.3s;
}

.ai-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(217, 119, 6, 0.45) !important;
}

.notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 15px;
    height: 15px;
    background-color: #e74c3c;
    border-radius: 50%;
    border: 2px solid white;
}

/* Chat Container */
.ai-chat-container {
    width: 360px;
    display: none; /* Hidden by default, toggled by JS */
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(217, 119, 6, 0.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
    transition: all 0.3s ease;
}

/* Card Header Brand Gradient */
.ai-chat-container .card-header {
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
    border-bottom: 1px solid #d97706 !important;
    color: #ffffff !important;
    padding: 11px 14px;
    box-shadow: 0 2px 10px rgba(217, 119, 6, 0.2);
}

/* AI Training Notice Banner */
.ai-training-notice {
    background: #fffbeb;
    border-bottom: 1px solid #fef3c7;
    padding: 7px 12px;
    font-size: 11px;
    line-height: 1.35;
    color: #92400e;
}

.ai-training-notice .text-amber {
    color: #d97706;
    font-size: 13px;
    margin-right: 6px;
    flex-shrink: 0;
}

.ai-training-notice .notice-text {
    letter-spacing: -0.1px;
}

#ai-send-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
    border-color: #d97706 !important;
    color: #ffffff !important;
    transition: all 0.2s ease;
}

#ai-send-btn:hover {
    background: linear-gradient(135deg, #d97706, #b45309) !important;
}

/* Collapsed State (Only button visible) */
.ai-chat-widget.collapsed .ai-chat-container {
    display: none;
}
.ai-chat-widget.collapsed .ai-chat-toggle {
    display: flex;
}

/* Expanded State (Container visible, button hidden) */
.ai-chat-widget.expanded .ai-chat-container {
    display: block;
}
.ai-chat-widget.expanded .ai-chat-toggle {
    display: none;
}

/* Fullscreen State */
.ai-chat-widget.fullscreen {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
}

.ai-chat-widget.fullscreen .ai-chat-container {
    width: 100%;
    height: 100%;
    border-radius: 0;
}

.ai-chat-widget.fullscreen .card-body {
    height: calc(100vh - 50px) !important; /* Adjust based on header height */
}

/* Chat Box Styles */
.chat-box {
    background-color: #f8f9fa;
}

.message {
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 80%;
    font-size: 0.9rem;
}

.user-message {
    background-color: #3498db;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 5px;
}

.system-message {
    background-color: #e9ecef;
    color: #333;
    margin-right: auto;
    border-bottom-left-radius: 5px;
}

/* Voice Mode Styles */
.mode-btn {
    border: 1px solid #dee2e6;
    background: white;
    color: #666;
    transition: all 0.3s;
}

.mode-btn.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.mode-btn:not(.active) {
    background-color: white;
    color: #6c757d;
    border-color: #dee2e6;
}

.mic-button:hover {
    transform: scale(1.05);
}

.mic-button:active {
    transform: scale(0.95);
}

.replay-btn {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    margin-left: 8px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.replay-btn:hover {
    opacity: 1;
}

/* Custom Range Slider Styles */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
    opacity: 0.9;
    transition: opacity 0.2s;
}

input[type="range"]:hover {
    opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
}

/* Typing Indicator (3 Dots Animation) */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 10px;
    background-color: #e9ecef;
    border-radius: 18px;
    max-width: 60px;
    margin-right: auto;
    animation: fadeIn 0.3s ease-in;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    margin: 0 2px;
    background-color: #90949c;
    border-radius: 50%;
    display: inline-block;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Bong bóng chào mời chủ động (Proactive Behavioral Bubble) */
.ai-proactive-bubble {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 280px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    padding: 12px 14px;
    cursor: pointer;
    animation: aiBubblePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10002;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ai-proactive-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 28px -5px rgba(0, 0, 0, 0.2);
}
.ai-proactive-bubble::after {
    content: "";
    position: absolute;
    bottom: -8px;
    right: 22px;
    width: 14px;
    height: 14px;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    transform: rotate(45deg);
}
.ai-proactive-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}
.ai-proactive-close:hover {
    color: #ef4444;
    background: #fee2e2;
}
.ai-proactive-body {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.ai-proactive-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}
.ai-proactive-text strong {
    display: block;
    font-size: 13px;
    color: #0f172a;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 2px;
}
.ai-proactive-text p {
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
    margin: 0;
}
@keyframes aiBubblePop {
    0% { opacity: 0; transform: translateY(12px) scale(0.9); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 767.98px) {
    .ai-proactive-bubble {
        width: calc(100vw - 40px);
        max-width: 300px;
        right: 0;
        bottom: 65px;
    }
}
