/* VAPI Hybrid Chat Widget Styles */

:root {
    --vapi-primary: #6366f1;
    --vapi-secondary: #f8fafc;
    --vapi-text: #1e293b;
    --vapi-user-msg-bg: #6366f1;
    --vapi-user-msg-text: #ffffff;
    --vapi-assistant-msg-bg: #f1f5f9;
    --vapi-assistant-msg-text: #1e293b;
    --vapi-input-bg: #ffffff;
    --vapi-input-border: #e2e8f0;
    --vapi-header-bg: #6366f1;
    --vapi-header-text: #ffffff;
    --vapi-border-radius: 12px;
    --vapi-font-family: system-ui, -apple-system, sans-serif;
    --vapi-font-size: 14px;
    --vapi-animation-speed: 300ms;
    --vapi-widget-width: 380px;
    --vapi-widget-height: 550px;
    --vapi-launcher-size: 60px;
    --vapi-launcher-color: #6366f1;
}

/* Launcher Button */
.vapi-chat-launcher {
    position: fixed;
    width: var(--vapi-launcher-size);
    height: var(--vapi-launcher-size);
    border-radius: 50%;
    background: var(--vapi-launcher-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: transform var(--vapi-animation-speed) ease, box-shadow var(--vapi-animation-speed) ease;
    z-index: calc(var(--vapi-z-index, 9999) - 1);
}

.vapi-chat-launcher:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.vapi-chat-launcher:active {
    transform: scale(0.95);
}

.launcher-icon {
    width: 28px;
    height: 28px;
    color: white;
    position: relative;
}

.launcher-icon svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: opacity var(--vapi-animation-speed) ease, transform var(--vapi-animation-speed) ease;
}

.vapi-chat-widget.open .launcher-icon .icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.vapi-chat-widget.open .launcher-icon .icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

.launcher-icon .icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

/* Pulse Animation */
.launcher-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--vapi-launcher-color);
    opacity: 0;
    z-index: -1;
}

.vapi-chat-launcher.pulse-active .launcher-pulse {
    animation: vapi-pulse 2s infinite;
}

@keyframes vapi-pulse {
    0% {
        transform: scale(1);
        opacity: 0.4;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Notification Badge */
.launcher-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
}

/* Chat Container */
.vapi-chat-container {
    position: fixed;
    width: var(--vapi-widget-width);
    height: var(--vapi-widget-height);
    background: var(--vapi-secondary);
    border-radius: var(--vapi-border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.9) translateY(20px);
    transition: opacity var(--vapi-animation-speed) ease, 
                visibility var(--vapi-animation-speed) ease,
                transform var(--vapi-animation-speed) ease;
    z-index: var(--vapi-z-index, 9999);
}

.vapi-chat-widget.open .vapi-chat-container {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Header */
.chat-header {
    background: var(--vapi-header-bg);
    color: var(--vapi-header-text);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    position: relative;
}

.status-indicator::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #22c55e;
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(2);
        opacity: 0;
    }
}

.status-indicator.disconnected {
    background: #ef4444;
}

.status-indicator.speaking {
    background: #f59e0b;
}

.header-title {
    font-weight: 600;
    font-size: 16px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--vapi-header-text);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--vapi-animation-speed) ease;
}

.header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.header-actions button svg {
    width: 18px;
    height: 18px;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.welcome-message {
    background: var(--vapi-assistant-msg-bg);
    color: var(--vapi-assistant-msg-text);
    padding: 12px 16px;
    border-radius: 12px 12px 12px 4px;
    font-size: var(--vapi-font-size);
    line-height: 1.5;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: var(--vapi-font-size);
    line-height: 1.5;
    word-wrap: break-word;
    animation: message-appear var(--vapi-animation-speed) ease;
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: var(--vapi-user-msg-bg);
    color: var(--vapi-user-msg-text);
    border-radius: 12px 12px 4px 12px;
    align-self: flex-end;
}

.message.assistant {
    background: var(--vapi-assistant-msg-bg);
    color: var(--vapi-assistant-msg-text);
    border-radius: 12px 12px 12px 4px;
    align-self: flex-start;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--vapi-assistant-msg-bg);
    border-radius: 12px 12px 12px 4px;
    align-self: flex-start;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--vapi-text);
    border-radius: 50%;
    opacity: 0.4;
    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.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Voice Status */
.voice-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(90deg, var(--vapi-primary) 0%, transparent 100%);
    border-top: 1px solid var(--vapi-input-border);
}

.volume-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 20px;
}

.volume-bars span {
    width: 4px;
    background: var(--vapi-primary);
    border-radius: 2px;
    animation: volume-bar 0.5s infinite ease-in-out alternate;
}

.volume-bars span:nth-child(1) { animation-delay: 0s; height: 8px; }
.volume-bars span:nth-child(2) { animation-delay: 0.1s; height: 16px; }
.volume-bars span:nth-child(3) { animation-delay: 0.2s; height: 12px; }
.volume-bars span:nth-child(4) { animation-delay: 0.3s; height: 18px; }
.volume-bars span:nth-child(5) { animation-delay: 0.4s; height: 10px; }

@keyframes volume-bar {
    from {
        opacity: 0.5;
        transform: scaleY(0.5);
    }
    to {
        opacity: 1;
        transform: scaleY(1);
    }
}

.status-text {
    font-size: 13px;
    color: var(--vapi-text);
    font-weight: 500;
}

/* Input Area */
.chat-input-area {
    padding: 15px 20px;
    border-top: 1px solid var(--vapi-input-border);
    background: var(--vapi-secondary);
    flex-shrink: 0;
}

.text-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--vapi-input-border);
    border-radius: 24px;
    background: var(--vapi-input-bg);
    font-size: var(--vapi-font-size);
    font-family: var(--vapi-font-family);
    outline: none;
    transition: border-color var(--vapi-animation-speed) ease, box-shadow var(--vapi-animation-speed) ease;
}

.chat-input:focus {
    border-color: var(--vapi-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--vapi-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--vapi-animation-speed) ease, background var(--vapi-animation-speed) ease;
}

.send-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* Voice Controls */
.voice-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 12px;
}

.mic-btn,
.end-call-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--vapi-animation-speed) ease, box-shadow var(--vapi-animation-speed) ease;
}

.mic-btn {
    background: var(--vapi-primary);
    color: white;
}

.mic-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.mic-btn.recording {
    background: #ef4444;
    animation: recording-pulse 1.5s infinite;
}

@keyframes recording-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
}

.end-call-btn {
    background: #ef4444;
    color: white;
}

.end-call-btn:hover {
    transform: scale(1.05);
    background: #dc2626;
}

.mic-btn svg,
.end-call-btn svg {
    width: 24px;
    height: 24px;
}

.mic-btn .icon-stop {
    display: none;
}

.mic-btn.recording .icon-mic {
    display: none;
}

.mic-btn.recording .icon-stop {
    display: block;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Position Variants */
.vapi-chat-widget.position-bottom-right .vapi-chat-launcher {
    bottom: var(--vapi-distance-bottom, 20px);
    right: var(--vapi-distance-side, 20px);
}

.vapi-chat-widget.position-bottom-right .vapi-chat-container {
    bottom: calc(var(--vapi-distance-bottom, 20px) + var(--vapi-launcher-size) + 10px);
    right: var(--vapi-distance-side, 20px);
}

.vapi-chat-widget.position-bottom-left .vapi-chat-launcher {
    bottom: var(--vapi-distance-bottom, 20px);
    left: var(--vapi-distance-side, 20px);
}

.vapi-chat-widget.position-bottom-left .vapi-chat-container {
    bottom: calc(var(--vapi-distance-bottom, 20px) + var(--vapi-launcher-size) + 10px);
    left: var(--vapi-distance-side, 20px);
}

.vapi-chat-widget.position-bottom-center .vapi-chat-launcher {
    bottom: var(--vapi-distance-bottom, 20px);
    left: 50%;
    transform: translateX(-50%);
}

.vapi-chat-widget.position-bottom-center .vapi-chat-container {
    bottom: calc(var(--vapi-distance-bottom, 20px) + var(--vapi-launcher-size) + 10px);
    left: 50%;
    transform: translateX(-50%) scale(0.9) translateY(20px);
}

.vapi-chat-widget.position-bottom-center.open .vapi-chat-container {
    transform: translateX(-50%) scale(1) translateY(0);
}

/* Box Shadow Variants */
.vapi-chat-container.shadow-light {
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.vapi-chat-container.shadow-medium {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.vapi-chat-container.shadow-heavy {
    box-shadow: 0 15px 60px rgba(0, 0, 0, 0.2);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .vapi-chat-container {
        width: calc(100vw - 40px);
        height: calc(100vh - 140px);
        bottom: calc(var(--vapi-distance-bottom, 20px) + var(--vapi-launcher-size) + 10px) !important;
        left: 20px !important;
        right: 20px !important;
    }
    
    .vapi-chat-widget.position-bottom-center .vapi-chat-container {
        transform: translateX(0) scale(0.9) translateY(20px);
        left: 20px !important;
        right: 20px !important;
    }
    
    .vapi-chat-widget.position-bottom-center.open .vapi-chat-container {
        transform: translateX(0) scale(1) translateY(0);
    }
}

/* Hidden state for minimized launcher */
.vapi-chat-widget.minimized .vapi-chat-launcher {
    display: none;
}
