:root {
    --chatbot-primario: #0A1931;
    --chatbot-acento: #FF6B35;
    --chatbot-acento-hover: #e55a2e;
    --chatbot-fondo-claro: #F0F2F5;
    --chatbot-texto-claro: #ffffff;
    --chatbot-texto-oscuro: #333;
    --chatbot-borde: #ddd;
    --chatbot-input-borde: #ccc;
    --chatbot-fondo-ai: #E9ECEF;
    --chatbot-fondo-ventana: #ffffff;
}

body.dark-mode {
    --chatbot-primario: #242831;
    --chatbot-acento: #FF7A45;
    --chatbot-acento-hover: #ff6b35;
    --chatbot-fondo-claro: #1A1D24;
    --chatbot-texto-claro: #ffffff;
    --chatbot-texto-oscuro: #EAEAEA;
    --chatbot-borde: #3a4150;
    --chatbot-input-borde: #3a4150;
    --chatbot-fondo-ai: #2f3542;
    --chatbot-fondo-ventana: #242831;
}

/* --- Botón para abrir el chat --- */
#chatbot-trigger {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    background-color: var(--chatbot-acento);
    color: var(--chatbot-texto-claro);
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 9998;
    transition: transform 0.2s ease-out, background-color 0.2s ease;
}

#chatbot-trigger:hover {
    transform: scale(1.1);
    background-color: var(--chatbot-acento-hover);
}

/* --- Contenedor principal del Chat --- */
#chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 90%;
    max-width: 400px;
    height: 70vh;
    max-height: 600px;
    background-color: var(--chatbot-fondo-ventana);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s, background-color 0.3s ease;
}

#chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* --- Cabecera del Chat --- */
.chatbot-header {
    background-color: var(--chatbot-primario);
    color: var(--chatbot-texto-claro);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

#chatbot-close-btn {
    background: none;
    border: none;
    color: var(--chatbot-texto-claro);
    font-size: 1.5rem;
    cursor: pointer;
}

/* --- Área de Mensajes --- */
#chatbot-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    background-color: var(--chatbot-fondo-claro);
    transition: background-color 0.3s ease;
}

.chatbot-message {
    padding: 0.7rem 1rem;
    border-radius: 18px;
    margin-bottom: 0.75rem;
    max-width: 80%;
    line-height: 1.4;
}

.user-message {
    background-color: var(--chatbot-acento);
    color: var(--chatbot-texto-claro);
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.ai-message {
    background-color: var(--chatbot-fondo-ai);
    color: var(--chatbot-texto-oscuro);
    border-bottom-left-radius: 4px;
    margin-right: auto;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Estilos para contenido formateado en mensajes de la IA --- */
.ai-message p {
    margin: 0 0 0.5rem 0; /* Espacio inferior para cada párrafo */
}
.ai-message p:last-child {
    margin-bottom: 0; /* Evita doble espaciado al final del mensaje */
}
.ai-message strong {
    color: var(--chatbot-acento);
    font-weight: 600;
}
.ai-message ul,
.ai-message ol {
    margin: 0.5rem 0;
    padding-left: 20px; /* Sangría para la lista */
}
.ai-message li {
    margin-bottom: 0.35rem; /* Espacio entre elementos de la lista */
}
.ai-message li:last-child {
    margin-bottom: 0;
}

/* --- "Escribiendo..." Indicador --- */
#typing-indicator {
    display: none;
    align-items: center;
    padding: 0.7rem 1rem;
}

#typing-indicator .dot {
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #aaa;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
#typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
#typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}


/* --- Formulario de entrada --- */
.chatbot-input-form {
    display: flex;
    padding: 0.75rem;
    border-top: 1px solid var(--chatbot-borde);
    background-color: var(--chatbot-fondo-ventana);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#chatbot-input {
    flex-grow: 1;
    border: 1px solid var(--chatbot-input-borde);
    border-radius: 20px;
    padding: 0.7rem 1rem;
    font-size: 1rem;
    margin-right: 0.5rem;
    background-color: var(--chatbot-fondo-claro);
    color: var(--chatbot-texto-oscuro);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

#chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-acento);
}

#chatbot-send-btn {
    border: none;
    background-color: var(--chatbot-acento);
    color: var(--chatbot-texto-claro);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#chatbot-send-btn:hover {
    background-color: var(--chatbot-acento-hover);
}

/* --- Responsivo --- */
@media (max-width: 480px) {
    #chatbot-window {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    #chatbot-trigger {
        bottom: 15px;
        right: 15px;
    }
}