/* ============================================
   AI Chatbot Widget - Complete Stylesheet
   ============================================ */

/* Widget Container */
#ai-chatbot-widget {
    position: fixed;
    bottom: 90px;
    right: 25px;
    z-index: 200000;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Toggle Button */
#chatbot-toggle {
    width: 65px;
    height: 65px;
    border: none;
    border-radius: 50%;
    position: relative;
    z-index: 9999;
    background: linear-gradient(135deg, var(--chat-primary, #6366f1), #ec4899) !important;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: chatbotFloat 3.5s ease-in-out infinite,
        chatbotPulseWave 2.5s ease-out infinite !important;
}

#chatbot-toggle i {
    position: relative;
    z-index: 10;
    animation: micWobble 4s infinite;
}

/* 
 * Pulse-ring and pulse-wave-layer are inside a <button>.
 * Browsers clip transform:scale() children of <button> elements
 * even with overflow:visible. Hide them and use box-shadow instead.
 */
.pulse-ring,
.pulse-wave-layer {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
}

/* ============================================
   Keyframe Animations
   ============================================ */

/* Gentle floating bounce */
@keyframes chatbotFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* 
 * Multi-ring expanding box-shadow pulse.
 * box-shadow is NEVER clipped by overflow:hidden on any ancestor.
 * 3 concentric rings: indigo → pink → teal
 */
@keyframes chatbotPulseWave {
    0% {
        box-shadow:
            0 8px 25px rgba(0, 0, 0, 0.25),
            0 0 0 0px rgba(99, 102, 241, 0.7),
            0 0 0 0px rgba(236, 72, 153, 0.5),
            0 0 0 0px rgba(20, 184, 166, 0.35);
    }

    70% {
        box-shadow:
            0 8px 25px rgba(0, 0, 0, 0.25),
            0 0 0 18px rgba(99, 102, 241, 0.15),
            0 0 0 32px rgba(236, 72, 153, 0.08),
            0 0 0 46px rgba(20, 184, 166, 0.02);
    }

    100% {
        box-shadow:
            0 8px 25px rgba(0, 0, 0, 0.25),
            0 0 0 22px rgba(99, 102, 241, 0),
            0 0 0 40px rgba(236, 72, 153, 0),
            0 0 0 55px rgba(20, 184, 166, 0);
    }
}

/* Microphone icon wobble */
@keyframes micWobble {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    10% {
        transform: scale(1.1) rotate(-10deg);
    }

    20% {
        transform: scale(1.1) rotate(10deg);
    }

    30% {
        transform: scale(1.1) rotate(-10deg);
    }

    40% {
        transform: scale(1) rotate(0deg);
    }
}

/* ============================================
   Hover State
   ============================================ */
#chatbot-toggle:hover {
    animation: pulse-wave 1s infinite linear alternate;
    transform: scale(1.15) translateY(-5px) !important;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4),
        0 0 40px rgba(236, 72, 153, 0.5) !important;
}

/* ============================================
   Chatbot Open State
   ============================================ */
.ai-chatbot-open #chatbot-toggle {
    animation: none !important;
    background: #475569 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
}

.ai-chatbot-open #chatbot-toggle i {
    animation: none !important;
    transform: rotate(180deg);
}

/* ============================================
   Chat Window
   ============================================ */
#chatbot-window {
    position: absolute;
    bottom: 0px;
    right: 0;
    width: 380px;
    height: 480px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    transform-origin: bottom right;
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
}

.ai-chatbot-open #chatbot-window {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ============================================
   Chat Elements
   ============================================ */
.chatbot-avatar {
    width: 40px;
    height: 40px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}

#chatbot-messages {
    flex-grow: 1;
    background: #f8fafc;
}

.message-content {
    max-width: 85%;
    line-height: 1.5;
}

.ai-message .message-content {
    color: #1e293b;
    border-bottom-left-radius: 4px !important;
}

.user-message {
    display: flex;
    justify-content: flex-end;
}

.user-message .message-content {
    color: white !important;
    border-bottom-right-radius: 4px !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Voice Widget Redesign Styles (Multi-State)
   ============================================ */

/* Base container modifications */
#voice-visualizer.state-idle .suggestion-pills { display: flex !important; }
#voice-visualizer.state-idle .live-transcription-area { display: none !important; }
#voice-visualizer.state-idle .bottom-controls { display: none !important; }

#voice-visualizer:not(.state-idle) .suggestion-pills { display: none !important; }
#voice-visualizer:not(.state-idle) .live-transcription-area { display: flex !important; }
#voice-visualizer:not(.state-idle) .bottom-controls { display: flex !important; }

/* Status Pill */
.voice-top-status .status-pill {
    transition: all 0.3s ease;
}

/* Central Circle */
.ai-avatar-circle {
    position: relative;
    width: 75px;
    height: 75px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #10b981, #0ea5e9);
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.4);
    z-index: 2;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

/* State-specific colors */
#voice-visualizer.state-listening .ai-avatar-circle {
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
}

#voice-visualizer.state-speaking .ai-avatar-circle {
    background: linear-gradient(135deg, #10b981, #34d399);
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.5);
}

#voice-visualizer.state-idle .ai-avatar-circle {
    background: linear-gradient(135deg, #475569, #64748b);
    box-shadow: 0 0 20px rgba(71, 85, 105, 0.4);
}

#voice-visualizer.state-thinking .ai-avatar-circle {
    background: transparent;
    box-shadow: none;
}

/* Wave Bars */
.waveform-container {
    gap: 4px;
}
.wave-bar {
    width: 6px;
    border-radius: 6px;
    background-color: #475569;
    height: 40px;
    margin: 0;
    transform: scaleY(0.2);
    transition: background-color 0.3s ease;
    will-change: transform;
}

/* Animated wave states */
#voice-visualizer.state-listening .wave-bar {
    background-color: #3b82f6; /* Blue for user speaking */
    animation: waveAnim 1s ease-in-out infinite alternate;
}

#voice-visualizer.state-speaking .wave-bar {
    background-color: #10b981; /* Green for AI speaking */
    animation: waveAnim 0.8s ease-in-out infinite alternate;
}

#voice-visualizer.state-idle .wave-bar {
    background-color: #475569; /* Grey */
    animation: none;
    transform: scaleY(0.15);
}

#voice-visualizer.state-thinking .wave-bar {
    opacity: 0;
}

/* Randomize animation delays for wave effect */
.wave-bar:nth-child(1) { animation-delay: -0.4s; }
.wave-bar:nth-child(2) { animation-delay: -0.2s; }
.wave-bar:nth-child(3) { animation-delay: -0.6s; }
.wave-bar:nth-child(4) { animation-delay: -0.1s; }
.wave-bar:nth-child(5) { animation-delay: -0.5s; }
.wave-bar:nth-child(6) { animation-delay: -0.3s; }
.wave-bar:nth-child(7) { animation-delay: -0.7s; }
.wave-bar:nth-child(8) { animation-delay: -0.2s; }
.wave-bar:nth-child(9) { animation-delay: -0.8s; }
.wave-bar:nth-child(10) { animation-delay: -0.1s; }
.wave-bar:nth-child(11) { animation-delay: -0.5s; }
.wave-bar:nth-child(12) { animation-delay: -0.3s; }
.wave-bar:nth-child(13) { animation-delay: -0.6s; }
.wave-bar:nth-child(14) { animation-delay: -0.2s; }
.wave-bar:nth-child(15) { animation-delay: -0.4s; }
.wave-bar:nth-child(16) { animation-delay: -0.7s; }

@keyframes waveAnim {
    0% { transform: scaleY(0.15); }
    100% { transform: scaleY(1); }
}

/* Thinking Spinner Dots */
.thinking-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.thinking-dot {
    width: 10px;
    height: 10px;
    background-color: #3b82f6;
    border-radius: 50%;
    animation: dotPulse 1.4s infinite ease-in-out both;
}
.thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Suggestion Pills */
.suggestion-pills button:hover {
    background: rgba(255,255,255,0.1);
    color: white !important;
}

/* Transcription Chat Bubbles */
.live-transcription-history {
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.t-bubble {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.t-bubble .t-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.t-bubble.user .t-icon {
    background-color: #3b82f6;
}

.t-bubble.ai .t-icon {
    background-color: #10b981;
}

.t-bubble-content {
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    padding: 8px 12px;
    flex-grow: 1;
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Hide scrollbar for Live Transcription */
.live-transcription-area::-webkit-scrollbar {
    display: none;
}
.live-transcription-area {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Utility Classes */
.letter-spacing-1 { letter-spacing: 1px; }
.uppercase { text-transform: uppercase; }

/* Responsive */
@media (max-width: 500px) {
    #chatbot-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: -60px;
        right: 0px;
    }
}