:root {
    --ai-primary-color: #4f46e5;
    --ai-text-color: #1f2937;
    --ai-bg-color: #ffffff;
    --ai-bubble-size: 60px;
    --ai-offset-x: 20px;
    --ai-offset-y: 20px;
}

/* Chat Bubble */
#ai-chat-bubble {
    position: fixed;
    bottom: var(--ai-offset-y);
    right: var(--ai-offset-x);
    width: var(--ai-bubble-size);
    height: var(--ai-bubble-size);
    background-color: var(--ai-primary-color);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999;
    animation: ai-bubble-glow 1.8s ease-in-out infinite;
}

#ai-chat-bubble::before,
#ai-chat-bubble::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(79, 70, 229, 0.45);
    opacity: 0;
    pointer-events: none;
}

#ai-chat-bubble::before {
    animation: ai-radio-signal 2s ease-out infinite;
}

#ai-chat-bubble::after {
    animation: ai-radio-signal 2s ease-out 1s infinite;
}

#ai-chat-bubble:hover {
    transform: scale(1.1);
}

#ai-chat-bubble svg {
    color: white;
    width: 32px;
    height: 32px;
}

.ai-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background-color: #ef4444;
    color: #ffffff;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px #f9fafb;
    transform: scale(1);
    opacity: 1;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.ai-chat-badge.ai-chat-badge-hidden {
    opacity: 0;
    transform: scale(0.6);
}

/* Chat Window */
#ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 550px;
    max-height: 80vh;
    background-color: var(--ai-bg-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 9999;
    border: 1px solid rgba(0,0,0,0.05);
}

#ai-chat-bubble.ai-pos-bottom-left {
    bottom: var(--ai-offset-y);
    left: var(--ai-offset-x);
    right: auto;
}

#ai-chat-window.ai-pos-bottom-left {
    bottom: 90px;
    left: 20px;
    right: auto;
}

#ai-chat-bubble.ai-pos-right-middle {
    top: calc(50% - var(--ai-bubble-size) / 2 + var(--ai-offset-y));
    bottom: auto;
    right: var(--ai-offset-x);
}

#ai-chat-window.ai-pos-right-middle {
    top: calc(50% - 275px);
    bottom: auto;
    right: 20px;
}

#ai-chat-window.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Header */
.ai-chat-header {
    background-color: var(--ai-primary-color);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-title {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-logo {
    width: 28px;
    height: 28px;
    border-radius: 9999px;
    object-fit: cover;
    background-color: #e5e7eb;
    flex-shrink: 0;
}

.ai-close-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    opacity: 0.9;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 9999px;
    background-color: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.ai-close-btn:hover {
    opacity: 1;
    background-color: #fee2e2;
    box-shadow: 0 2px 4px rgba(0,0,0,0.18);
    transform: translateY(-0.5px);
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: #f9fafb;
    scroll-behavior: smooth;
}

.ai-quick-questions {
    padding: 0 20px 12px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background-color: #f9fafb;
}

.ai-quick-question-btn {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 9999px;
    border: 1px solid #e5e7eb;
    background-color: #ffffff;
    color: #374151;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ai-quick-question-btn:hover {
    background-color: var(--ai-primary-color);
    color: #ffffff;
    border-color: var(--ai-primary-color);
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    animation: fadeIn 0.3s ease;
}

@keyframes ai-bubble-glow {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    50% {
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
    }
}

@keyframes ai-radio-signal {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    70% {
        transform: scale(1.6);
        opacity: 0;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message.user {
    align-self: flex-end;
    background-color: var(--ai-primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message.assistant {
    align-self: flex-start;
    background-color: white;
    color: var(--ai-text-color);
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Markdown Styles inside bubbles */
.ai-message p { margin-bottom: 8px; }
.ai-message p:last-child { margin-bottom: 0; }
.ai-message ul, .ai-message ol { margin-left: 20px; margin-bottom: 8px; }
.ai-message code { 
    background: rgba(0,0,0,0.1); 
    padding: 2px 4px; 
    border-radius: 4px; 
    font-family: monospace; 
    font-size: 0.9em;
}
.ai-message pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.ai-message pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}
.ai-message a {
    text-decoration: underline;
    color: inherit;
}

/* Input Area */
.ai-chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 100px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.ai-chat-input:focus {
    border-color: var(--ai-primary-color);
    ring: 2px solid var(--ai-primary-color);
}

.ai-send-btn {
    background-color: var(--ai-primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
}

.ai-send-btn:hover {
    opacity: 0.9;
}

.ai-send-btn:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    #ai-chat-window,
    #ai-chat-window.ai-pos-bottom-left,
    #ai-chat-window.ai-pos-right-middle {
        top: 16px;
        bottom: 16px;
        right: 12px;
        left: 12px;
        width: auto;
        height: auto;
        max-height: calc(100% - 32px);
        border-radius: 14px;
    }
}
