/* Variables CSS personalizables */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --text-color: #333;
    --bg-color: #ffffff;
    --user-message-bg: #667eea;
    --bot-message-bg: #f1f3f4;
    --border-color: #e0e0e0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
}

/* Reset y estilos base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Botón flotante del chat */
.chat-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    z-index: 1000;
    color: white;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Contenedor principal del chat */
.chat-container {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 600px;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px);
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 999;
    overflow: hidden;
}

.chat-container.active {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

/* ESTADO MINIMIZADO (CORREGIDO) */
.chat-container.minimized {
    height: 60px;
    bottom: 30px;
    width: auto;
    min-width: 220px;
    max-width: 300px;
    border-radius: 30px; /* Píldora */
    
    /* Fondo gradiente para destacar */
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    overflow: hidden;
    pointer-events: auto;
}

/* Header cuando está minimizado */
.chat-container.minimized .chat-header {
    background: transparent;
    padding: 0 20px;
    width: 100%;
    height: 100%;
    justify-content: center;
    border-radius: 0;
}

/* Texto blanco al minimizar */
.chat-container.minimized .chat-info h3 {
    color: white !important;
    margin: 0;
    font-size: 15px;
}

/* Elementos a ocultar al minimizar */
.chat-container.minimized .chat-controls,
.chat-container.minimized .status-indicator,
.chat-container.minimized .chat-messages,
.chat-container.minimized .quick-replies,
.chat-container.minimized .chat-input-container {
    display: none !important;
}

/* Header del chat (Normal) */
.chat-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.chat-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: white;
    padding: 4px;
    object-fit: contain;
}

.chat-info {
    flex: 1;
    margin-left: 12px;
}

.chat-info h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.status-indicator {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
}

.status-indicator.online::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    margin-right: 5px;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Área de mensajes */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.message {
    display: flex;
    margin-bottom: 15px;
    animation: slideInUp 0.3s ease;
}

@keyframes slideInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 10px;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    padding: 2px;
    border-radius: 50%;
}

/* CONTENIDO DEL MENSAJE (CORREGIDO COLOR TEXTO) */
.message-content {
    max-width: 70%;
    background: var(--bot-message-bg);
    color: #1f2937 !important; /* Gris oscuro casi negro para legibilidad */
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    font-size: 14px;
    line-height: 1.4;
}

.user-message .message-content {
    background: var(--user-message-bg);
    color: white !important; /* Blanco para el usuario */
}

.message-content p {
    margin: 0;
    word-wrap: break-word;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

/* Opciones rápidas */
.quick-replies {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-reply-btn {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-color);
}

.quick-reply-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* Input del usuario */
.chat-input-container {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 25px;
    padding: 8px 15px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chatInput {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    padding: 5px;
    color: var(--text-color);
}

#chatInput::placeholder {
    color: #999;
}

.send-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 8px;
}

.send-btn:hover {
    background: var(--secondary-color);
    transform: scale(1.1);
}

.send-btn:active {
    transform: scale(0.95);
}

/* Indicador de escritura */
.typing-indicator {
    display: none;
    align-items: center;
    padding: 10px 15px;
    margin-top: 10px;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* Responsive Design */
@media (max-width: 480px) {
    .chat-container {
        width: calc(100vw - 40px);
        right: 20px;
        left: 20px;
        height: 500px;
    }
    .chat-button {
        bottom: 20px;
        right: 20px;
    }
    .message-content {
        max-width: 80%;
    }
}

/* Animaciones adicionales */
.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.scale-in {
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}