/* Chatbot Variables */
:root {
    --chat-primary: var(--primary-red, #800000);
    --chat-accent: var(--accent-gold, #D4AF37);
    --chat-bg: #ffffff;
    --chat-text: #333333;
    --chat-bg-msg-bot: #f1f1f1;
    --chat-bg-msg-user: var(--primary-red, #800000);
    --chat-text-user: #ffffff;
}

/* Floating Action Button (FAB) */
.chat-fab {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 64px;
    height: 64px;
    padding: 0;
    background-color: var(--chat-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(196, 18, 48, 0.45);
    z-index: 1000;
    font-family: inherit;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    border: 2px solid var(--chat-accent);
    animation: fabPulse 2.6s infinite;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 24px rgba(196, 18, 48, 0.6);
}

.chat-fab i {
    font-size: 26px;
}

.chat-fab-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--chat-accent);
    color: #7a0014;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

@keyframes fabPulse {
    0% { box-shadow: 0 6px 18px rgba(196, 18, 48, 0.45), 0 0 0 0 rgba(196, 18, 48, 0.45); }
    70% { box-shadow: 0 6px 18px rgba(196, 18, 48, 0.45), 0 0 0 16px rgba(196, 18, 48, 0); }
    100% { box-shadow: 0 6px 18px rgba(196, 18, 48, 0.45), 0 0 0 0 rgba(196, 18, 48, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-fab { animation: none; }
}

/* Chat Window Container */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 380px;
    height: 550px;
    max-height: 80vh;
    background-color: var(--chat-bg);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    display: none; /* Hidden by default */
    flex-direction: column;
    z-index: 1001;
    overflow: hidden;
    animation: slideInUp 0.4s ease forwards;
    border: 1px solid #eee;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, #500000 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--chat-accent);
}

.chat-title h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
}

.chat-title span {
    font-size: 0.8rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-title span::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background-color: #00ff00;
    border-radius: 50%;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.2s;
}
.chat-close:hover {
    transform: rotate(90deg);
}

/* Messages Area */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: #fafafa;
    scroll-behavior: smooth;
}

/* Scrollbar styling */
.chat-body::-webkit-scrollbar {
    width: 6px;
}
.chat-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.chat-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Message Bubbles */
.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.bot-msg {
    align-self: flex-start;
    background-color: var(--chat-bg-msg-bot);
    color: var(--chat-text);
    border-top-left-radius: 2px;
    border: 1px solid #e0e0e0;
}

.user-msg {
    align-self: flex-end;
    background-color: var(--chat-bg-msg-user);
    color: var(--chat-text-user);
    border-top-right-radius: 2px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Typing Indicator */
.typing {
    display: none;
    align-self: flex-start;
    background-color: #f1f1f1;
    padding: 10px 15px;
    border-radius: 12px;
    border-top-left-radius: 2px;
    font-style: italic;
    color: #888;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.typing span {
    display: inline-block;
    width: 5px;
    height: 5px;
    background-color: #aaa;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
    margin-left: 2px;
}
.typing span:nth-child(1) { animation-delay: 0s; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input Area */
.chat-footer {
    padding: 15px;
    background-color: white;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.3s;
}
.chat-input:focus {
    border-color: var(--chat-primary);
}

.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--chat-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}
.chat-send:hover {
    background-color: #600000;
}

/* Quick Replies / Chips (Optional) */
.chat-chips {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    padding: 12px 15px 14px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 15px;
    scrollbar-width: thin;
    scrollbar-color: rgba(196, 18, 48, 0.45) transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    cursor: grab;
}
.chat-chips.dragging {
    cursor: grabbing;
    scroll-snap-type: none;
    user-select: none;
}
.chat-chips::-webkit-scrollbar {
    height: 6px;
}
.chat-chips::-webkit-scrollbar-track {
    background: transparent;
}
.chat-chips::-webkit-scrollbar-thumb {
    background: rgba(196, 18, 48, 0.35);
    border-radius: 999px;
}

.chip {
    flex: 0 0 auto;
    min-height: 38px;
    background: #fff;
    border: 1px solid var(--chat-primary);
    color: var(--chat-primary);
    padding: 7px 15px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    scroll-snap-align: start;
    transition: all 0.2s;
}
.chip:hover {
    background: var(--chat-primary);
    color: white;
    transform: translateY(-1px);
}

/* Responsive: pantalla completa en móvil */
@media (max-width: 600px) {
    .chat-window {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-footer {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }

    .chat-fab {
        bottom: 18px;
        right: 18px;
        width: 58px;
        height: 58px;
    }

    .chat-fab i { font-size: 24px; }
}
