/* Chatbot Variables inheriting from main site if possible, else defaults */
:root {
    --chat-primary: #0077dd;
    --chat-bg: #ffffff;
    --chat-header-bg: #002244;
    --chat-text: #333333;
    --chat-msg-bg: #f1f3f5;
    --chat-user-msg-bg: #0077dd;
    --chat-radius: 12px;
    --chat-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
}

/* Chatbot Container */
.chatbot-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
    font-family: 'Inter', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Toggle Button (The floating bubble) */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    background: var(--chat-primary);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 119, 221, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    outline: none;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    background: var(--chat-header-bg);
}

.chat-toggle-btn i {
    color: white;
    font-size: 24px;
    transition: transform 0.3s ease;
}

/* Chat Window */
.chat-window {
    width: 350px;
    height: 500px;
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    /* Hidden by default */
    visibility: hidden;
}

/* Active State for Window */
.chatbot-container.active .chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
    visibility: visible;
}

.chatbot-container.active .chat-toggle-btn i {
    transform: rotate(180deg);
    /* Rotate icon when open if using xmark check */
}

/* Header */
.chat-header {
    background: var(--chat-header-bg);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
}

.chat-header h3 i {
    color: #00bbee;
    /* accent cyan */
}

.close-chat {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
}

.close-chat:hover {
    color: white;
}

/* Chat Body (Messages) */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.msg-bot {
    align-self: flex-start;
    background: white;
    color: var(--chat-text);
    border-radius: 15px 15px 15px 2px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border: 1px solid #e0e0e0;
}

.msg-user {
    align-self: flex-end;
    background: var(--chat-user-msg-bg);
    color: white;
    border-radius: 15px 15px 2px 15px;
    box-shadow: 0 2px 8px rgba(0, 119, 221, 0.2);
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 15px;
    background: white;
    border-radius: 15px;
    width: fit-content;
    display: none;
    /* hidden by default */
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #ccc;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Chat Options / Input Area */
.chat-input-area {
    padding: 10px;
    background: white;
    border-top: 1px solid #eee;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.chat-option-btn {
    background: white;
    border: 1px solid var(--chat-primary);
    color: var(--chat-primary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.chat-option-btn:hover {
    background: var(--chat-primary);
    color: white;
}

/* Images in Chat */
.chat-image-card {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.chat-image-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.chat-image-caption {
    padding: 8px;
    background: white;
    font-size: 0.8rem;
    color: #666;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .chat-window {
        width: 100vw;
        height: 100vh;
        margin-bottom: 0;
        border-radius: 0;
        position: fixed;
        bottom: 0;
        right: 0;
        top: 0;
        left: 0;
    }

    .chatbot-container {
        padding: 0;
        bottom: 20px;
        right: 20px;
    }

    .chatbot-container.active {
        bottom: 0;
        right: 0;
        z-index: 10000;
    }

    /* .chat-toggle-btn stays default */
}

/* RTL Support for Chatbot */
html[dir="rtl"] .chatbot-container {
    right: auto;
    left: 30px;
    /* align-items: flex-end; is default, which maps to Left in RTL */
}

html[dir="rtl"] .chat-window {
    transform-origin: bottom left;
}

html[dir="rtl"] .chat-header h3 {
    flex-direction: row-reverse;
}

html[dir="rtl"] .chat-header h3 i {
    margin-left: 0;
    margin-right: 10px;
    /* spacing fix for reversed icon */
}

html[dir="rtl"] .msg-bot {
    border-radius: 15px 15px 2px 15px;
    /* Flip corner */
}

html[dir="rtl"] .msg-user {
    border-radius: 15px 15px 15px 2px;
    /* Flip corner */
}

html[dir="rtl"] .chat-input-area {
    direction: rtl;
}

/* Mobile RTL */
@media (max-width: 480px) {
    html[dir="rtl"] .chatbot-container {
        left: 20px;
        right: auto;
    }
}