/*
 * Estilos del chatbot AIDA Bot
 * Los colores se controlan con CSS custom properties definidas inline en el HTML
 * para que sean configurables desde el panel de admin sin regenerar CSS.
 */

/* ──────────────────────────────────────────────
   Variables y contenedor principal
   ────────────────────────────────────────────── */

#aida-bot-container {
    /* Valores por defecto (se sobreescriben con los del admin vía inline style) */
    --aida-primary:   #D6FF00; /* NosoloWebs yellow */
    --aida-secondary: #1D1D1D; /* NosoloWebs black */
    --aida-on-primary: #1D1D1D;
    --aida-on-secondary: #ffffff;
    --aida-gray-1: #EAEAEA;
    --aida-gray-2: #9C9C9C;

    /* Variables internas fijas */
    --aida-radius:    16px;
    --aida-sombra:    0 8px 32px rgba(0, 0, 0, 0.18);
    --aida-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --aida-ancho:     360px;
    --aida-alto-max:  520px;
    --aida-z:         999999;

    position: fixed;
    z-index: var(--aida-z);
    font-family: var(--aida-font);
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#aida-bot-container *,
#aida-bot-container *::before,
#aida-bot-container *::after {
    box-sizing: inherit;
}

/* ──────────────────────────────────────────────
   Posicionamiento
   ────────────────────────────────────────────── */

#aida-bot-container.aida-posicion-bottom-right {
    bottom: 24px;
    right:  24px;
}

#aida-bot-container.aida-posicion-bottom-left {
    bottom: 24px;
    left:   24px;
}

/* ──────────────────────────────────────────────
   Botón burbuja flotante
   ────────────────────────────────────────────── */

#aida-bubble-btn {
    position: relative;
    width:  56px;
    height: 56px;
    border-radius: var(--aida-bubble-radius, 15px);
    background: var(--aida-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--aida-sombra);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 10px;
    outline-offset: 3px;
    overflow: hidden;
}

#aida-bubble-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

#aida-bubble-btn:active {
    transform: scale(0.96);
}

#aida-bubble-btn svg {
    width:  100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

#aida-bubble-btn .aida-icono-custom {
    width:  100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Punto rojo de novedad */
.aida-bubble-punto {
    position: absolute;
    top:   3px;
    right: 3px;
    width:  12px;
    height: 12px;
    background: #ff3b30;
    border-radius: 50%;
    border: 2px solid white;
    display: none; /* El JS lo muestra cuando hay mensajes nuevos */
}

/* ──────────────────────────────────────────────
   Ventana del chat
   ────────────────────────────────────────────── */

#aida-chat-window {
    position: absolute;
    bottom: 68px; /* Por encima del botón burbuja */
    width: var(--aida-ancho);
    max-height: var(--aida-alto-max);
    background: #ffffff;
    border-radius: var(--aida-radius);
    box-shadow: var(--aida-sombra);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Animación de entrada */
    transform-origin: bottom center;
    animation: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Posicionamiento de la ventana según lado */
.aida-posicion-bottom-right #aida-chat-window {
    right: 0;
}

.aida-posicion-bottom-left #aida-chat-window {
    left: 0;
}

/* Estado hidden (el atributo [hidden] oculta el elemento,
   pero también añadimos la transición de salida) */
#aida-chat-window[hidden] {
    display: none;
}

/* Animación al abrir */
@keyframes aida-abrir {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(12px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#aida-chat-window.aida-visible {
    animation: aida-abrir 0.22s ease forwards;
}

/* ──────────────────────────────────────────────
   Cabecera del chat
   ────────────────────────────────────────────── */

#aida-chat-header {
    background: var(--aida-secondary);
    color: var(--aida-on-secondary);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aida-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aida-header-avatar {
    width:  36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.aida-header-avatar svg,
.aida-header-avatar img {
    width:  28px;
    height: 28px;
    object-fit: contain;
}

.aida-header-nombre {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.aida-header-estado {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.aida-estado-punto {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}

.aida-header-acciones {
    display: flex;
    align-items: center;
    gap: 4px;
}

.aida-header-acciones button {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--aida-on-secondary);
    opacity: 0.75;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.aida-header-acciones button:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* ──────────────────────────────────────────────
   Zona de mensajes
   ────────────────────────────────────────────── */

#aida-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

/* Scrollbar fina y discreta */
#aida-mensajes::-webkit-scrollbar {
    width: 4px;
}
#aida-mensajes::-webkit-scrollbar-track {
    background: transparent;
}
#aida-mensajes::-webkit-scrollbar-thumb {
    background: var(--aida-gray-2);
    border-radius: 4px;
}

/* ──────────────────────────────────────────────
   Burbujas de mensaje
   ────────────────────────────────────────────── */

.aida-mensaje {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: aida-mensaje-entrada 0.2s ease;
}

@keyframes aida-mensaje-entrada {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Mensajes del usuario (derecha, color primario) */
.aida-mensaje-user {
    background: var(--aida-primary);
    color: var(--aida-on-primary);
    margin-left: auto;
    border-radius: 16px 16px 4px 16px;
}

/* Mensajes del bot (izquierda, gris claro) */
.aida-mensaje-assistant {
    background: var(--aida-gray-1);
    color: var(--aida-secondary);
    margin-right: auto;
    border-radius: 16px 16px 16px 4px;
}

/* Mensajes de error */
.aida-mensaje-error {
    background: #fff0f0;
    color: #c0392b;
    border: 1px solid #fcc;
    margin-right: auto;
    border-radius: 16px 16px 16px 4px;
    font-size: 13px;
}

/* ──────────────────────────────────────────────
   Indicador "escribiendo..."
   ────────────────────────────────────────────── */

#aida-typing {
    padding: 8px 16px 4px;
    flex-shrink: 0;
}

.aida-typing-burbuja {
    background: var(--aida-gray-1);
    border-radius: 16px 16px 16px 4px;
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.aida-typing-punto {
    width: 7px;
    height: 7px;
    background: var(--aida-gray-2);
    border-radius: 50%;
    animation: aida-typing-bounce 1.2s infinite ease-in-out;
}

.aida-typing-punto:nth-child(2) { animation-delay: 0.2s; }
.aida-typing-punto:nth-child(3) { animation-delay: 0.4s; }

@keyframes aida-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-5px); }
}

/* ──────────────────────────────────────────────
   Área de input
   ────────────────────────────────────────────── */

#aida-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 12px 12px 16px;
    border-top: 1px solid var(--aida-gray-1);
    flex-shrink: 0;
    background: #ffffff;
}

#aida-input-mensaje {
    flex: 1;
    border: 1px solid var(--aida-gray-1);
    border-radius: 20px;
    padding: 9px 14px;
    font-family: var(--aida-font);
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    overflow-y: hidden;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s ease;
    background: var(--aida-gray-1);
    color: var(--aida-secondary);
}

#aida-input-mensaje:focus {
    border-color: var(--aida-primary);
    background: white;
    overflow-y: auto;
}

#aida-input-mensaje::placeholder {
    color: var(--aida-gray-2);
}

#aida-enviar-btn {
    width:  38px;
    height: 38px;
    border-radius: 50%;
    background: var(--aida-primary);
    border: none;
    cursor: pointer;
    color: var(--aida-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
    padding: 0;
}

#aida-enviar-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.05);
}

#aida-enviar-btn:active:not(:disabled) {
    transform: scale(0.95);
}

#aida-enviar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ──────────────────────────────────────────────
   Pie del chat
   ────────────────────────────────────────────── */

#aida-chat-footer {
    text-align: center;
    font-size: 11px;
    color: var(--aida-gray-2);
    padding: 6px 12px 8px;
    border-top: 1px solid #f0f0f0;
    background: white;
    flex-shrink: 0;
}

.aida-footer-sep {
    margin: 0 4px;
    color: var(--aida-gray-1);
}

.aida-footer-link {
    color: var(--aida-gray-2);
    text-decoration: none;
    transition: color 0.15s ease;
}

.aida-footer-link:hover {
    color: var(--aida-primary);
    text-decoration: underline;
}

/* ──────────────────────────────────────────────
   Responsive: móvil
   ────────────────────────────────────────────── */

@media (max-width: 480px) {
    #aida-bot-container.aida-posicion-bottom-right,
    #aida-bot-container.aida-posicion-bottom-left {
        bottom: 16px;
        right:  16px;
        left:   16px;
    }

    #aida-chat-window {
        width: 100%;
        max-height: 75vh;
        bottom: 72px;
        right: 0;
        left: 0;
        border-radius: 16px 16px 12px 12px;
    }

    .aida-posicion-bottom-left #aida-chat-window {
        left: 0;
        right: 0;
    }
}
