/* ==============================================
   CHATBOT WIDGET - Floating Help Chat
   ============================================== */

/* --- Chatbot Toggle Button (floating) --- */
.chatbot-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 1050;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--purple-gradient, linear-gradient(135deg, #209aa2 0%, #205b5f 100%));
    color: #fff;
    font-size: 1.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(32, 154, 162, 0.4);
    transition: transform 0.25s cubic-bezier(.4,2,.6,1), box-shadow 0.25s;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(32, 154, 162, 0.5);
}

.chatbot-toggle .chatbot-icon-open,
.chatbot-toggle .chatbot-icon-close {
    position: absolute;
    transition: opacity 0.25s, transform 0.25s;
}

.chatbot-toggle .chatbot-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.7);
}

.chatbot-toggle.active .chatbot-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.7);
}

.chatbot-toggle.active .chatbot-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse animation for first-time attention */
.chatbot-toggle:not(.active)::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--purple-primary, #209aa2);
    animation: chatbot-pulse 2s ease-out infinite;
    pointer-events: none;
}

@keyframes chatbot-pulse {
    0% { opacity: 0.7; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.5); }
}

.chatbot-toggle.interacted::after {
    display: none;
}

/* RTL positioning */
html[dir="rtl"] .chatbot-toggle {
    right: auto;
    left: 28px;
}

/* --- Chat Window --- */
.chatbot-window {
    position: fixed;
    bottom: 96px;
    right: 28px;
    z-index: 1049;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 130px);
    background: var(--bg-card, #fff);
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(.4,0,.2,1), transform 0.3s cubic-bezier(.4,0,.2,1);
}

.chatbot-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

html[dir="rtl"] .chatbot-window {
    right: auto;
    left: 28px;
}

/* --- Chat Header --- */
.chatbot-header {
    background: var(--purple-gradient, linear-gradient(135deg, #209aa2 0%, #205b5f 100%));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
}

.chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.chatbot-header-name {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
    line-height: 1.3;
}

.chatbot-header-status {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 5px;
}

.chatbot-header-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
}

/* --- Chat Messages Area --- */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-color, #e0e0e0);
    border-radius: 10px;
}

/* Message bubbles */
.chatbot-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: chatbot-msg-in 0.3s ease-out;
}

@keyframes chatbot-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chatbot-msg.bot {
    align-self: flex-start;
}

.chatbot-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chatbot-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--purple-gradient, linear-gradient(135deg, #209aa2 0%, #205b5f 100%));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #fff;
    flex-shrink: 0;
    margin-top: 2px;
}

.chatbot-msg.user .chatbot-msg-avatar {
    background: var(--brand-orange, #e78a56);
}

.chatbot-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.55;
    white-space: pre-line;
    word-wrap: break-word;
}

.chatbot-msg.bot .chatbot-msg-bubble {
    background: var(--bg-body, #f8fafb);
    color: var(--text-primary, #1a2e35);
    border-bottom-left-radius: 4px;
}

html[dir="rtl"] .chatbot-msg.bot .chatbot-msg-bubble {
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.chatbot-msg.user .chatbot-msg-bubble {
    background: var(--purple-gradient, linear-gradient(135deg, #209aa2 0%, #205b5f 100%));
    color: #fff;
    border-bottom-right-radius: 4px;
}

html[dir="rtl"] .chatbot-msg.user .chatbot-msg-bubble {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    align-items: center;
}

.chatbot-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted, #999);
    animation: chatbot-typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes chatbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Quick Replies */
.chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 0;
}

.chatbot-quick-reply {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--purple-primary, #209aa2);
    background: transparent;
    color: var(--purple-primary, #209aa2);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chatbot-quick-reply:hover {
    background: var(--purple-primary, #209aa2);
    color: #fff;
}

/* --- Chat Input --- */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #e8ecef);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: var(--bg-card, #fff);
}

.chatbot-input {
    flex: 1;
    border: 1.5px solid var(--border-color, #e8ecef);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 0.88rem;
    background: var(--bg-body, #f8fafb);
    color: var(--text-primary, #1a2e35);
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: var(--purple-primary, #209aa2);
}

.chatbot-input::placeholder {
    color: var(--text-muted, #999);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--purple-gradient, linear-gradient(135deg, #209aa2 0%, #205b5f 100%));
    color: #fff;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chatbot-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 10px rgba(32, 154, 162, 0.35);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* RTL send icon flip */
html[dir="rtl"] .chatbot-send-btn i {
    transform: scaleX(-1);
}

/* --- Responsive --- */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    html[dir="rtl"] .chatbot-window {
        left: 0;
        right: 0;
    }

    .chatbot-toggle {
        bottom: 20px;
        right: 20px;
    }

    html[dir="rtl"] .chatbot-toggle {
        right: auto;
        left: 20px;
    }
}

/* Dark theme support */
[data-theme="dark"] .chatbot-window {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .chatbot-msg.bot .chatbot-msg-bubble {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .chatbot-input {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

[data-theme="dark"] .chatbot-quick-reply {
    border-color: var(--purple-light, #86b7ba);
    color: var(--purple-light, #86b7ba);
}

[data-theme="dark"] .chatbot-quick-reply:hover {
    background: var(--purple-primary, #209aa2);
    color: #fff;
    border-color: var(--purple-primary, #209aa2);
}
