/* ========================================
   Audibukz AI Assistant — Chatbot Widget
   Glassmorphism + Premium Animations
   ======================================== */

/* ── Chatbot Toggle Button ── */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 90px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary, #F97066);
    color: #fff;
    box-shadow: 0 4px 24px rgba(249, 112, 102, 0.4), 0 0 0 3px rgba(249, 112, 102, 0.12);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    animation: chatbot-pulse 3s ease-in-out infinite;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.chatbot-toggle:hover {
    transform: scale(1.12) rotate(-5deg);
    box-shadow: 0 6px 32px rgba(249, 112, 102, 0.55), 0 0 0 5px rgba(249, 112, 102, 0.15);
}

.chatbot-toggle:active { transform: scale(0.95); }

.chatbot-toggle svg {
    width: 26px;
    height: 26px;
    transition: transform 0.4s ease;
    color: #fff;
    stroke: #fff;
}

.chatbot-toggle.active svg { transform: rotate(90deg); }

@keyframes chatbot-pulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(249, 112, 102, 0.4), 0 0 0 3px rgba(249, 112, 102, 0.12); }
    50% { box-shadow: 0 4px 32px rgba(249, 112, 102, 0.55), 0 0 0 6px rgba(249, 112, 102, 0.2); }
}

/* ── Chatbot Window ── */
.chatbot-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    left: auto;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--bg-secondary, #12121a);
    border: 1px solid var(--border, #1e293b);
    border-radius: 20px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(249, 112, 102, 0.1);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

[data-theme="light"] .chatbot-window {
    background: #ffffff;
    border-color: #e7e0d5;
    box-shadow: 0 20px 60px rgba(120, 80, 40, 0.15), 0 0 0 1px rgba(232, 89, 12, 0.08);
}

/* ── Header ── */
.chatbot-header {
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, rgba(249, 112, 102, 0.15), rgba(249, 112, 102, 0.05));
    border-bottom: 1px solid var(--border, #1e293b);
    flex-shrink: 0;
}

[data-theme="light"] .chatbot-header {
    background: linear-gradient(135deg, rgba(249, 112, 102, 0.08), rgba(249, 112, 102, 0.03));
    border-bottom-color: #e7e0d5;
}

/* Simple text avatar instead of SVG icon */
.chatbot-avatar-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--accent-primary, #F97066);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    font-family: var(--font-heading, 'Outfit', sans-serif);
    letter-spacing: -0.5px;
}

.chatbot-header-info { flex: 1; }
.chatbot-header-info h4 {
    font-family: var(--font-heading, 'Outfit', sans-serif);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    margin: 0;
    line-height: 1.3;
}

.chatbot-header-info span {
    font-size: 0.72rem;
    color: #22c55e;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-header-info span::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    animation: online-blink 1.5s ease-in-out infinite;
}

@keyframes online-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Close Button — Large Touch Target for Mobile ── */
.chatbot-close {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 10px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary, #94a3b8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    padding: 0;
    position: relative;
    z-index: 10;
}

.chatbot-close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    pointer-events: none;
}

.chatbot-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.chatbot-close:active {
    background: rgba(239, 68, 68, 0.25);
    color: #ef4444;
    transform: scale(0.92);
}

[data-theme="light"] .chatbot-close { background: rgba(0, 0, 0, 0.05); }
[data-theme="light"] .chatbot-close:hover { background: rgba(239, 68, 68, 0.1); color: #dc2626; }

/* ── Messages Area ── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-light, #2d3748);
    border-radius: 2px;
}

/* ── Message Bubbles ── */
.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: msg-slide-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes msg-slide-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg.bot { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }

/* ── Simple Text Avatars (no SVG icons) ── */
.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-heading, 'Outfit', sans-serif);
    color: #fff;
}

.bot-avatar {
    background: var(--accent-primary, #F97066);
    color: #fff;
}

.user-avatar {
    background: var(--bg-elevated, #2a2a3e);
}

.user-avatar svg {
    stroke: var(--text-secondary, #94a3b8);
}

[data-theme="light"] .user-avatar {
    background: #e8e3db;
}

[data-theme="light"] .user-avatar svg {
    stroke: #57534e;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.84rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.chat-msg.bot .chat-bubble {
    background: var(--bg-elevated, #1a1a2e);
    color: var(--text-primary, #f1f5f9);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border, #1e293b);
}

[data-theme="light"] .chat-msg.bot .chat-bubble {
    background: #f0ebe3;
    border-color: #e7e0d5;
    color: #1a1523;
}

.chat-msg.user .chat-bubble {
    background: var(--accent-primary, #F97066);
    color: #fff;
    border-bottom-right-radius: 4px;
    border: none;
}

.chat-bubble strong,
.chat-bubble b {
    color: var(--accent-primary, #f97316);
    font-weight: 600;
}
.chat-msg.user .chat-bubble strong,
.chat-msg.user .chat-bubble b {
    color: #fde68a;
}

/* ── Typing Cursor ── */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent-primary, #F97066);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.6s steps(2) infinite;
}

@keyframes cursor-blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}

/* ── Quick Action Chips ── */
.chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.chat-quick-btn {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border, #1e293b);
    background: var(--bg-elevated, #1a1a2e);
    color: var(--text-secondary, #94a3b8);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.chat-quick-btn:hover {
    background: var(--accent-primary, #F97066);
    color: #fff;
    border-color: transparent;
    transform: translateY(-1px);
}

.chat-quick-btn:active {
    background: var(--accent-primary, #F97066);
    color: #fff;
    border-color: transparent;
    transform: scale(0.96);
}

[data-theme="light"] .chat-quick-btn {
    background: #ffffff;
    border-color: #e7e0d5;
    color: #57534e;
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 2px;
    align-items: center;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-primary, #F97066);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ── Input Area ── */
.chatbot-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--border, #1e293b);
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--bg-secondary, #12121a);
    flex-shrink: 0;
}

[data-theme="light"] .chatbot-input-area {
    background: #ffffff;
    border-top-color: #e7e0d5;
}

.chatbot-input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border, #1e293b);
    background: var(--bg-primary, #0a0a0f);
    color: var(--text-primary, #f1f5f9);
    font-size: 0.84rem;
    font-family: var(--font-body, 'Inter', sans-serif);
    transition: border-color 0.2s ease;
    outline: none;
}

.chatbot-input:focus { border-color: var(--accent-primary, #F97066); }
.chatbot-input::placeholder { color: var(--text-muted, #64748b); }

[data-theme="light"] .chatbot-input {
    background: #faf7f2;
    border-color: #e7e0d5;
    color: #1a1523;
}

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--accent-primary, #F97066);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.chatbot-send svg {
    width: 18px;
    height: 18px;
    stroke: #fff;
    color: #fff;
}

.chatbot-send:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(249, 112, 102, 0.35); }
.chatbot-send:active { transform: scale(0.95); }

/* ── Responsive ── */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 80px;
        left: 8px;
        right: 8px;
        width: auto;
        left: auto;
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        border-radius: 16px;
    }

    /* Larger close button on small screens */
    .chatbot-close {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    .chatbot-close svg {
        width: 18px;
        height: 18px;
    }
}

/* Positioning the Chatbot Toggle */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 90px; /* Next to theme toggle on desktop */
    left: auto;
    width: 52px;
    height: 52px;
}

body.player-active .chatbot-toggle { bottom: 88px; }
body.player-active .chatbot-window { bottom: 156px; max-height: calc(100vh - 180px); }

/* Mobile Positioning: Next to Navigation Bar */
@media (max-width: 768px) {
    .chatbot-toggle {
        bottom: auto;
        top: 14px;
        right: 56px; /* Next to hamburger menu */
        left: auto;
        width: 40px;
        height: 40px;
        box-shadow: 0 2px 10px rgba(249, 112, 102, 0.3);
        animation: none; /* Disable pulse on mobile navbar */
    }
    
    .chatbot-toggle svg {
        width: 20px;
        height: 20px;
    }
    
    body.player-active .chatbot-toggle {
        /* Keep it at top even when player is active on mobile */
        bottom: auto;
        top: 14px;
    }
    
    .chatbot-window {
        bottom: 20px;
        top: 70px;
        right: 8px;
        left: 8px;
        height: auto;
        max-height: none;
    }
    
    body.player-active .chatbot-window { 
        bottom: 100px;
        top: 70px;
        max-height: none;
    }

    /* Bigger close button touch area on mobile */
    .chatbot-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 12px;
    }

    .chatbot-close svg {
        width: 20px;
        height: 20px;
        stroke-width: 3;
    }
}
