/* --- CHAT WIDGET STYLES --- */
:root {
    --chat-primary: #4d7ef5;
    --chat-bg: #ffffff;
    --chat-text: #333333;
    --chat-border: #e0e0e0;
}

[data-theme="dark"] {
    --chat-bg: #1e1e24;
    --chat-text: #f0f0f0;
    --chat-border: #333333;
}

/* 1. Floating Button */
.chat-widget-toggle {
    position: fixed;
    bottom: 40px;
    right: 40px;
    width: 60px;
    height: 60px;
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease;
    animation: chatPulse 2s infinite;

    /* Initial State for Drift */
    transform: translateY(100px);
    opacity: 0;
}

.chat-widget-toggle.float-visible {
    transform: translateY(0);
    opacity: 1;
}

@keyframes chatPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(77, 126, 245, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(77, 126, 245, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(77, 126, 245, 0);
    }
}

.chat-widget-toggle:hover {
    transform: scale(1.1);
    animation: none;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    display: none;
    /* Hidden by default */
}

.chat-preview-bubble {
    position: absolute;
    right: 75px;
    /* Move to the LEFT of the icon (icon width 60px + gap) */
    top: 50%;
    transform: translateY(-50%) scale(0.8);
    opacity: 0;

    /* Sizing & Layout */
    width: max-content;
    max-width: 280px;
    padding: 12px 18px;

    /* Aesthetics */
    background: linear-gradient(135deg, #ffffff, #f8f9fa);
    color: #2c3e50;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;

    /* Shape */
    border-radius: 12px;
    border-top-right-radius: 2px;
    /* Point towards icon */

    /* Depth */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);

    /* Behavior */
    display: none;
    /* Controlled by JS */
    z-index: 9998;
    pointer-events: none;
    /* Let clicks pass through if needed, but usually we want to click it to open */
    cursor: pointer;

    /* Animation */
    animation: bubbleSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Arrow pointing to the right */
.chat-preview-bubble::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -6px;
    margin-top: -6px;
    border-width: 6px 0 6px 8px;
    border-style: solid;
    border-color: transparent transparent transparent #fff;
    filter: drop-shadow(1px 0 0 rgba(0, 0, 0, 0.05));
}

[data-theme="dark"] .chat-preview-bubble {
    background: #2b2b36;
    color: #ecf0f1;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chat-preview-bubble::after {
    border-color: transparent transparent transparent #2b2b36;
}

@keyframes bubbleSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-10px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0) scale(1);
    }
}

@media (max-width: 480px) {
    .chat-widget-toggle {
        bottom: 20px;
        right: 20px;
    }
}

/* 2. Chat Window Container */
.chat-window {
    position: fixed;
    bottom: 110px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    /* Animation state */
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    pointer-events: none;
    transition: all 0.3s ease;
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* 3. Header */
.chat-header {
    background: var(--chat-primary);
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-close {
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.8;
}

.chat-close:hover {
    opacity: 1;
}

/* 4. Messages Area */
.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--chat-bg);
}

/* Message Bubbles */
.chat-msg {
    max-width: 80%;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-msg.admin {
    align-self: flex-start;
    background: #f1f2f6;
    color: #333;
    border-bottom-left-radius: 2px;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--chat-primary);
    color: white;
    border-bottom-right-radius: 2px;
}

[data-theme="dark"] .chat-msg.admin {
    background: #2b2b36;
    color: #eee;
}

/* 5. Input Area */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 0.5rem;
    background: var(--chat-bg);
}

.chat-input-area input {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--chat-border);
    background: var(--card-bg, #fff);
    /* Fallback */
    color: var(--chat-text);
    outline: none;
    font-family: inherit;
}

[data-theme="dark"] .chat-input-area input {
    background: #2b2b36;
    border-color: #444;
}

.chat-send-btn {
    background: var(--chat-primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}