/* chatbot.css
  Styling for the sitewide AI chatbot widget.
*/

:root {
    --chat-accent-color: #3B82F6;
    --chat-bg-color: #1F2937;
    --chat-text-color: #F9FAFB;
    --chat-border-color: #4B5563;
    --chat-bot-bubble: #374151;
    --chat-user-bubble: var(--chat-accent-color);
}

/* --- 1. The Launcher Icon --- */
#chat-widget-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--chat-accent-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    /* [FIX] z-index must be HIGHER than the container */
    z-index: 9999;
    transform: scale(0) translateY(50px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, box-shadow 0.2s ease;
}

#chat-widget-icon.visible {
    transform: scale(1) translateY(0);
    opacity: 1;
}

#chat-widget-icon:hover {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: scale(1.05);
}

#chat-widget-bot-icon,
#chat-widget-close-icon {
    position: absolute;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Style for the BOT icon (<img>) */
#chat-widget-bot-icon {
    width: 32px;
    height: 32px;
    transform: scale(1);
    opacity: 1;
}

/* Style for the CLOSE icon (<svg>) */
#chat-widget-close-icon {
    width: 28px;
    height: 28px;
    color: white;
    transform: scale(0);
    opacity: 0;
}

/* --- Toggling visibility --- */
#chat-widget-icon.open #chat-widget-bot-icon {
    transform: scale(0);
    opacity: 0;
}

#chat-widget-icon.open #chat-widget-close-icon {
    transform: scale(1);
    opacity: 1;
}
/* --- 2. The "Feel free to ask" Bubble --- */
#chat-widget-bubble {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background-color: var(--chat-bg-color);
    color: var(--chat-text-color);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--chat-border-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 14px;
    font-weight: 500;
    z-index: 9997;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: 0.5s;
}

#chat-widget-bubble.visible {
    opacity: 1;
    transform: translateY(0);
}

#chat-widget-bubble.hidden {
    opacity: 0 !important;
    transform: translateY(10px) !important;
    pointer-events: none;
}

/* --- 3. The Chat Container --- */
#chat-widget-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    max-width: calc(100% - 40px);
    height: 450px;
    max-height: calc(100% - 110px);
    background-color: var(--chat-bg-color);
    border: 1px solid var(--chat-border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    /* [FIX] z-index must be LOWER than the icon */
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    transform-origin: bottom right;
    visibility: hidden;
}

#chat-widget-container.visible {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
}

/* --- 4. Chat Header --- */
.chat-widget-header {
    padding: 16px;
    border-bottom: 1px solid var(--chat-border-color);
    background-color: var(--chat-bot-bubble);
}

.chat-widget-header h3 {
    color: var(--chat-text-color);
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* [FIX] This rule sizes the logo inside the header */
.chat-widget-header h3 img {
    width: 28px;
    height: 28px;
    border-radius: 4px;
}

.chat-widget-header .status-dot {
    width: 8px;
    height: 8px;
    background-color: #34D399; /* Green */
    border-radius: 50%;
}

/* --- 5. Chat History --- */
#chat-widget-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    display: flex;
    flex-direction: column;
}

.chat-message p {
    padding: 10px 14px;
    border-radius: 18px;
    max-width: 85%;
    word-wrap: break-word;
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Bot Message */
.chat-message.bot {
    align-items: flex-start;
}
.chat-message.bot p {
    background-color: var(--chat-bot-bubble);
    color: var(--chat-text-color);
    border-bottom-left-radius: 4px;
}

/* User Message */
.chat-message.user {
    align-items: flex-end;
}
.chat-message.user p {
    background-color: var(--chat-user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Typing Indicator */
.chat-message.typing {
    align-items: flex-start;
}
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background-color: var(--chat-bot-bubble);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #9CA3AF;
    border-radius: 50%;
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.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); }
    30% { transform: translateY(-4px); }
}

/* --- 6. Chat Input Form --- */
#chat-widget-form {
    display: flex;
    padding: 12px;
    border-top: 1px solid var(--chat-border-color);
    gap: 8px;
}

#chat-widget-input {
    flex-grow: 1;
    border: 1px solid var(--chat-border-color);
    background-color: #111827;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--chat-text-color);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    resize: none;
    height: 44px;
    box-sizing: border-box;
}
#chat-widget-input:focus {
    outline: none;
    border-color: var(--chat-accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

#chat-widget-send {
    height: 44px;
    width: 44px;
    border: none;
    background-color: var(--chat-accent-color);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
}
#chat-widget-send:hover {
    background-color: #2563EB;
}
#chat-widget-send svg {
    width: 20px;
    height: 20px;
}

#chat-widget-send:disabled {
    background-color: var(--chat-border-color);
    cursor: not-allowed;
}

/* --- MOBILE CHAT WIDGET FIX (FULL SCREEN & TOP-RIGHT BUTTON) --- */

/* 1. Defines the button, but hides it on desktop */
#chat-widget-header-close {
    display: none; 
    background: none;
    border: none;
    color: var(--label-color, #9CA3AF);
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

@media (max-width: 768px) {
    /* 2. Show the new header close button on mobile */
    #chat-widget-header-close {
        display: block;
    }

    /* 3. Hide the original floating close button on mobile */
    #chat-widget-icon.open {
        display: none !important;
    }

    #chat-widget-container.visible {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        transform-origin: bottom right !important;
    }

    /* 5. Adjust header layout for the TOP-RIGHT button */
    #chat-widget-container.visible .chat-widget-header {
        padding: 15px 15px 15px 20px; /* Padding for left-aligned title */
        display: flex;
        justify-content: space-between; /* This pushes the button to the right */
        align-items: center;
    }

    /* 6. Adjust main chat layout */
    #chat-widget-container.visible #chat-widget-history {
        flex-grow: 1;
        height: auto;
    }
    #chat-widget-container.visible #chat-widget-form {
        flex-shrink: 0;
    }
}