/* Variables para facilitar el mantenimiento */
:root {
    --ai-primary: #2563eb; /* Azul corporativo elegante */
    --ai-primary-hover: #1d4ed8;
    --ai-bg-glass: rgba(255, 255, 255, 0.85); /* Un poco más opaco para legibilidad */
    --ai-border-glass: rgba(255, 255, 255, 0.6);
    --ai-shadow: 0 10px 40px -10px rgba(0,0,0,0.2);
    --ai-text-main: #0f172a;
    --ai-text-muted: #64748b;
}

#ai-chat-widget {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    box-sizing: border-box;
}

#ai-chat-widget * {
    box-sizing: border-box;
}

/* Botón flotante */
#ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-primary), #3b82f6);
    color: white;
    border: none;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    position: absolute;
    bottom: 0;
    right: 0;
}

#ai-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
}

/* Contenedor del chat (Glassmorphism premium) */
#ai-chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--ai-bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--ai-border-glass);
    border-radius: 20px;
    box-shadow: var(--ai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
    opacity: 1;
    transform: scale(1);
}

#ai-chat-container.ai-chat-hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/* Cabecera */
.ai-chat-header {
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.6);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--ai-text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-status {
    width: 10px;
    height: 10px;
    background-color: #10b981; /* Verde esmeralda (Online) */
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

#ai-chat-close {
    background: none;
    border: none;
    color: var(--ai-text-muted);
    cursor: pointer;
    font-size: 18px;
    transition: color 0.2s, transform 0.2s;
    padding: 4px;
}

#ai-chat-close:hover {
    color: var(--ai-text-main);
    transform: scale(1.1);
}

/* Área de mensajes */
#ai-chat-messages {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: rgba(248, 250, 252, 0.5);
}

/* Custom Scrollbar */
#ai-chat-messages::-webkit-scrollbar { width: 6px; }
#ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ai-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

/* Burbujas de mensajes */
.ai-message {
    max-width: 85%;
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message-bot {
    align-self: flex-start;
    background: white;
    color: var(--ai-text-main);
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}

.ai-message-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--ai-primary), #3b82f6);
    color: white;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.25);
}

/* Animación de "Tipificando..." */
.ai-typing {
    display: flex;
    gap: 5px;
    padding: 16px 18px;
    align-items: center;
}
.ai-typing span {
    width: 6px;
    height: 6px;
    background: var(--ai-text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.ai-typing span:nth-child(1) { animation-delay: -0.32s; }
.ai-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Área de input */
.ai-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    gap: 10px;
    border-radius: 0 0 20px 20px;
}

#ai-chat-input {
    flex: 1;
    padding: 14px 18px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    background: #f8fafc;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    color: var(--ai-text-main);
}

#ai-chat-input:focus {
    border-color: var(--ai-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#ai-chat-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--ai-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

#ai-chat-send:hover {
    background: var(--ai-primary-hover);
    transform: scale(1.05);
}
#ai-chat-send:active { transform: scale(0.95); }
