/* ═══════════════════════════════════════════
   WIDGET AGENTE IA — Materia Gris
   widget.css v1.1.0
═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Ubuntu+Sans:wght@300;400;500;600&family=Ubuntu+Sans+Mono&display=swap');

:root {
    --mg-azul:          #0047AB;
    --mg-azul-oscuro:   #003380;
    --mg-fondo:         #F5F7FA;
    --mg-texto:         #333333;
    --radio:            16px;
    --sombra:           0 8px 32px rgba(0,71,171,0.18);
}

/* ── CONTENEDOR DEL BOTÓN FLOTANTE ──────── */
/* Wrapper externo para poder posicionar la notificación sin que se corte */

#mg-chat-wrapper {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 62px;
    height: 62px;
    z-index: 9998;
}

/* ── BOTÓN FLOTANTE ─────────────────────── */

#mg-chat-btn {
    position: absolute;
    inset: 0;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,71,171,0.25), 0 1px 4px rgba(0,0,0,0.1);
    padding: 0;
    overflow: hidden;
    transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mg-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 28px rgba(0,71,171,0.35);
}

#mg-chat-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Pulso animado */
#mg-chat-btn::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(0,71,171,0.3);
    animation: mg-pulso 2.5s ease-in-out infinite;
}

@keyframes mg-pulso {
    0%, 100% { transform: scale(1);    opacity: 0.6; }
    50%       { transform: scale(1.12); opacity: 0;   }
}

/* ── NOTIFICACIÓN ROJA ──────────────────── */
/* Fuera del botón para que nunca se corte */

#mg-chat-notif {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #e53935;
    border-radius: 50%;
    border: 2.5px solid white;
    font-size: 10px;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Ubuntu Sans', sans-serif;
    z-index: 1;
    pointer-events: none;
}

/* ── VENTANA DE CHAT ────────────────────── */

#mg-chat-window {
    position: fixed;
    bottom: 104px;
    right: 28px;
    width: 360px;
    max-height: 520px;
    background: #ffffff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(.34,1.56,.64,1);
    font-family: 'Ubuntu Sans', sans-serif;
}

#mg-chat-window.abierto {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── ENCABEZADO ─────────────────────────── */

#mg-chat-header {
    background: var(--mg-azul);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

#mg-chat-header img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}

.mg-header-info    { flex: 1; min-width: 0; }

.mg-header-nombre  {
    font-size: 0.88rem;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.2;
}

.mg-header-estado {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.75);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.mg-header-estado::before {
    content: '';
    width: 7px;
    height: 7px;
    background: #4cde80;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

#mg-chat-cerrar {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

#mg-chat-cerrar:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

/* ── ÁREA DE MENSAJES ───────────────────── */

#mg-chat-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--mg-fondo);
    scroll-behavior: smooth;
}

#mg-chat-mensajes::-webkit-scrollbar       { width: 4px; }
#mg-chat-mensajes::-webkit-scrollbar-track { background: transparent; }
#mg-chat-mensajes::-webkit-scrollbar-thumb { background: #d0d5e8; border-radius: 4px; }

/* ── BURBUJAS ───────────────────────────── */

.mg-burbuja {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.83rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: mg-aparecer 0.2s ease;
}

@keyframes mg-aparecer {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.mg-burbuja.agente {
    background: #ffffff;
    color: var(--mg-texto);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.mg-burbuja.usuario {
    background: var(--mg-azul);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.mg-burbuja a { color: inherit; text-decoration: underline; opacity: 0.9; }

/* ── TYPING INDICATOR ───────────────────── */

.mg-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: white;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    animation: mg-aparecer 0.2s ease;
}

.mg-typing span {
    width: 7px;
    height: 7px;
    background: #b0b8d0;
    border-radius: 50%;
    animation: mg-bounce 1.2s ease-in-out infinite;
}

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

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

/* ── INPUT AREA ─────────────────────────── */

#mg-chat-input-area {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid #eef0f7;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

#mg-chat-input {
    flex: 1;
    border: 1.5px solid #e0e4f0;
    border-radius: 12px;
    padding: 9px 13px;
    font-size: 0.82rem;
    font-family: 'Ubuntu Sans', sans-serif;
    color: var(--mg-texto);
    background: var(--mg-fondo);
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 38px;
    max-height: 100px;
    line-height: 1.4;
}

#mg-chat-input:focus        { border-color: var(--mg-azul); }
#mg-chat-input::placeholder { color: #aab0c8; }

#mg-chat-enviar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--mg-azul);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

#mg-chat-enviar:hover  { background: var(--mg-azul-oscuro); }
#mg-chat-enviar:active { transform: scale(0.93); }

#mg-chat-enviar svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ── FOOTER ─────────────────────────────── */

#mg-chat-footer {
    text-align: center;
    font-size: 0.65rem;
    color: #bbb;
    padding: 6px 0 8px;
    background: #ffffff;
    font-family: 'Ubuntu Sans Mono', monospace;
    flex-shrink: 0;
}

/* ── RESPONSIVE MÓVIL ───────────────────── */

@media (max-width: 420px) {
    #mg-chat-window {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-height: 85vh;
        border-radius: var(--radio) var(--radio) 0 0;
    }
    #mg-chat-wrapper { bottom: 20px; right: 20px; }
}
