/**
 * AdventuriQ ChatBot Widget - Standalone
 * Version: 2.0.0
 * For: Gamifier Integration
 * Colors: AdventuriQ brand (#FF6B35 orange, #4A5859 dark gray)
 */

#adventuriq-chatbot {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
}

/* === Toggle Button === */
#aq-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

#aq-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(255, 107, 53, 0.5);
}

#aq-chat-toggle:active {
    transform: scale(0.95);
}

#aq-chat-toggle svg {
    color: white;
    width: 28px;
    height: 28px;
}

#aq-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #E63946;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
}

/* === Chat Window === */
#aq-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#aq-chat-window.open {
    display: flex;
}

/* === Header === */
#aq-chat-header {
    background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aq-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aq-chat-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

#aq-chat-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

.aq-chat-status {
    font-size: 13px;
    opacity: 0.9;
    display: block;
}

#aq-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

#aq-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

#aq-chat-close svg {
    color: white;
}

/* === Messages === */
#aq-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #F5F7FA;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#aq-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#aq-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#aq-chat-messages::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 3px;
}

.aq-chat-msg {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    line-height: 1.5;
    font-size: 15px;
    word-wrap: break-word;
    animation: aqMsgSlide 0.2s ease-out;
}

@keyframes aqMsgSlide {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.aq-msg-user {
    background: #FF6B35;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.aq-msg-bot {
    background: white;
    color: #2D3748;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.aq-msg-error {
    background: #FFF5F5;
    color: #C53030;
    border-left: 3px solid #FC8181;
}

/* === Typing === */
.aq-typing {
    display: flex;
    gap: 6px;
    padding: 16px;
    align-items: center;
}

.aq-typing span {
    width: 8px;
    height: 8px;
    background: #A0AEC0;
    border-radius: 50%;
    animation: aqBounce 1.4s infinite ease-in-out;
}

.aq-typing span:nth-child(1) { animation-delay: 0s; }
.aq-typing span:nth-child(2) { animation-delay: 0.2s; }
.aq-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aqBounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-8px); }
}

/* === Input === */
#aq-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #E2E8F0;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

#aq-chat-input {
    flex: 1;
    border: 1px solid #CBD5E0;
    border-radius: 16px;
    padding: 12px 18px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    box-sizing: border-box;
    line-height: 1.4;
    min-height: 44px;
    max-height: 200px;
    overflow-y: auto;
    resize: none;
}

#aq-chat-input:focus {
    border-color: #FF6B35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

#aq-chat-input:disabled {
    background: #F7FAFC;
    cursor: not-allowed;
}

#aq-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF6B35 0%, #F7931E 100%);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

#aq-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

#aq-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#aq-chat-send svg {
    color: white;
}

/* === Responsive === */
@media (max-width: 480px) {
    #adventuriq-chatbot {
        bottom: 10px;
        right: 10px;
    }

    #aq-chat-window {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 80px;
        width: auto;
        height: auto;
        max-width: none;
        max-height: none;
        border-radius: 12px;
    }

    @supports (height: 1dvh) {
        #aq-chat-window {
            top: auto;
            bottom: 80px;
            height: calc(100dvh - 90px);
            max-height: calc(100dvh - 90px);
        }
    }

    #aq-chat-toggle {
        width: 52px;
        height: 52px;
    }

    #aq-chat-header { padding: 12px 16px; }
    .aq-chat-avatar { width: 36px; height: 36px; font-size: 20px; }
    #aq-chat-header h3 { font-size: 15px; }
    #aq-chat-messages { padding: 12px; min-height: 0; }
    .aq-chat-msg { font-size: 14px; padding: 10px 14px; max-width: 90%; }
    #aq-chat-input-area { padding: 10px 12px; }
    #aq-chat-input { padding: 10px 14px; font-size: 16px; }
    #aq-chat-send { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
