/* AI Chat Assistant Styles */

/* ============================================================
   Widget Container
   ============================================================ */
#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000; /* Above mobile bar (9999) and WA modal */
    font-family: 'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ============================================================
   Chat Bubble Button
   ============================================================ */
.ai-chat-bubble {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: #000000;
    border: 3px solid #F5B900;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(245, 185, 0, 0.45);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.2s;
    color: #F5B900;
    animation: pulse-glow 2.5s ease-in-out infinite;
}

.ai-bubble-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #F5B900;
    line-height: 1;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(245, 185, 0, 0.4);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 6px 32px rgba(245, 185, 0, 0.65);
        transform: scale(1.06);
    }
}

.ai-chat-bubble:hover {
    transform: scale(1.12) !important;
    box-shadow: 0 8px 32px rgba(245, 185, 0, 0.75) !important;
    background: #111111;
    animation-play-state: paused;
}

/* Hide bubble when chat is open */
.ai-chat-bubble.active {
    display: none;
}

.ai-chat-bubble svg {
    width: 30px;
    height: 30px;
}

/* ============================================================
   Chat Window
   ============================================================ */
.ai-chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 580px;
    max-height: calc(100vh - 40px);
    background: #1a1a1a;
    border: 2px solid #F5B900;
    border-radius: 20px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(245, 185, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10001; /* Must be above the bubble */
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   Chat Header
   ============================================================ */
.ai-chat-header {
    position: relative;
    background: #000000;
    border-bottom: 2px solid #F5B900;
    color: #F5B900;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* Gold gradient top-border accent */
.ai-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #F5B900 0%, #FFD700 50%, #F5B900 100%);
    z-index: 1;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Online indicator dot */
.ai-status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
    animation: blink-dot 2s ease-in-out infinite;
    flex-shrink: 0;
}

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

.ai-chat-close {
    background: rgba(245, 185, 0, 0.08);
    border: 2px solid rgba(245, 185, 0, 0.5);
    color: #F5B900;
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

.ai-chat-close:hover {
    background: #F5B900;
    color: #000000;
    transform: rotate(90deg);
    border-color: #F5B900;
}

/* ============================================================
   Messages Container
   ============================================================ */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: rgba(245, 185, 0, 0.07);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(245, 185, 0, 0.5);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #F5B900;
}

/* ============================================================
   Message Bubbles
   ============================================================ */
.ai-message,
.user-message {
    display: flex;
    animation: fadeInUp 0.25s ease both;
}

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

.ai-message {
    justify-content: flex-start;
}

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

.ai-message-content,
.user-message-content {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.6;
    font-size: 14px;
    font-weight: 500;
}

.ai-message-content {
    background: rgba(245, 185, 0, 0.12);
    color: #f0f0f0;
    border: 1px solid rgba(245, 185, 0, 0.25);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.user-message-content {
    background: #F5B900;
    color: #000000;
    border-bottom-right-radius: 4px;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(245, 185, 0, 0.35);
}

/* First (welcome) message gets a gold border highlight */
.ai-message:first-child .ai-message-content {
    background: rgba(245, 185, 0, 0.18);
    border: 1.5px solid rgba(245, 185, 0, 0.5);
    font-weight: 600;
}

/* AI Markdown list rendering */
.ai-message-content .ai-list {
    margin: 8px 0 4px 0;
    padding-left: 20px;
    list-style: disc;
}

.ai-message-content .ai-list li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.ai-message-content code {
    background: rgba(245, 185, 0, 0.15);
    border: 1px solid rgba(245, 185, 0, 0.25);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
    font-family: 'Courier New', Courier, monospace;
}

/* ============================================================
   Loading / Typing Indicator
   ============================================================ */
.ai-message.loading .ai-message-content {
    padding: 14px 18px;
    background: rgba(245, 185, 0, 0.08);
    border: 1px solid rgba(245, 185, 0, 0.15);
}

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 2px 0;
    align-items: center;
}

.typing-indicator span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #F5B900;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* "Still thinking..." text shown after TIMEOUT_WARN_MS */
.ai-thinking-note {
    display: block;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 8px;
    font-style: italic;
}

/* ============================================================
   Input Area
   ============================================================ */
.ai-chat-input-wrapper {
    padding: 14px 16px;
    background: #000000;
    border-top: 2px solid #F5B900;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    border: 2px solid rgba(245, 185, 0, 0.25);
    background: #1a1a1a;
    color: #ffffff;
    border-radius: 22px;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 500;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
}

.ai-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.ai-chat-input:focus {
    outline: none;
    border-color: #F5B900;
    background: #222222;
    box-shadow: 0 0 0 3px rgba(245, 185, 0, 0.12);
}

.ai-chat-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #F5B900;
    border: none;
    color: #000000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(245, 185, 0, 0.35);
}

.ai-chat-send:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(245, 185, 0, 0.55);
    background: #FFD700;
}

.ai-chat-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
    background: rgba(245, 185, 0, 0.3);
    box-shadow: none;
}

.ai-chat-send svg {
    width: 20px;
    height: 20px;
    transform: translateX(1px); /* Optical centering of send icon */
}

/* ============================================================
   Error Message
   ============================================================ */
.error-message {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    font-weight: 600;
    animation: fadeInUp 0.25s ease both;
}

/* ============================================================
   Mobile Responsive
   - On mobile the site has a sticky .mobile-bottom-bar (~60px tall).
   - The chat bubble is placed above it. The chat window must also
     clear it so content isn't hidden behind the bar.
   ============================================================ */
@media (max-width: 480px) {
    /* Push widget above the mobile bottom bar */
    #ai-chat-widget {
        bottom: 80px;  /* mobile-bottom-bar height (~60px) + 20px gap */
        right: 14px;
    }

    .ai-chat-bubble {
        width: 58px;
        height: 58px;
    }

    .ai-chat-bubble svg {
        width: 26px;
        height: 26px;
    }

    .ai-bubble-label {
        font-size: 8px;
    }

    /* Chat window fills the screen above the mobile bar */
    .ai-chat-window {
        position: fixed;
        bottom: 80px;   /* clear the mobile-bottom-bar */
        right: 10px;
        left: 10px;
        width: auto;
        height: calc(100vh - 160px); /* viewport minus top gap and bottom bar */
        max-height: calc(100vh - 160px);
        border-radius: 16px;
    }
}

/* Very small screens (< 360px) */
@media (max-width: 360px) {
    .ai-chat-window {
        right: 6px;
        left: 6px;
    }
}
