/* ==========================================================================
   Burbuja de chat con IA (`js/chat.js`, `chat/mensaje.php`).

   REEMPLAZA AL BOTON FLOTANTE DE WHATSAPP, que vivia como un `<style>` suelto
   adentro de `sistema/pie.php` y era el unico CSS del sitio fuera de `css/`.
   El acceso a WhatsApp no se perdio: esta adentro del panel, en el pie, que es
   donde sirve — cuando el asistente no alcanza.

   NO DEPENDE DE BOOTSTRAP NI DEL THEME a proposito. El widget se dibuja arriba
   de cualquier pagina del sitio, incluidas las del theme con sus `!important`,
   asi que todo lo que necesita esta declarado aca y con clases propias. Los
   colores salen de las variables de abajo: son los del theme (`styles-red.css`)
   copiados, no importados, porque el theme no expone ninguna.
   ========================================================================== */

.chat-widget {
    --chat-primario: #f83f2a;
    --chat-primario-oscuro: #d92e1b;
    --chat-oscuro: #232323;
    --chat-borde: #e4e4e4;
    --chat-fondo: #ffffff;
    --chat-gris: #f4f4f4;
}

/* --------------------------------------------------------------------------
   El boton flotante.
   -------------------------------------------------------------------------- */

.chat-burbuja {
    position: fixed;
    right: 15px;
    bottom: 15px;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background-color: var(--chat-primario);
    color: #fff;
    font-size: 26px;
    line-height: 60px;
    text-align: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
    cursor: pointer;
    z-index: 100;
    padding: 0;
    transition: transform .15s ease, background-color .15s ease;
}

.chat-burbuja:hover,
.chat-burbuja:focus {
    background-color: var(--chat-primario-oscuro);
    transform: scale(1.05);
    outline: none;
}

/* Con el panel abierto el boton sobra y encima tapa el campo de texto en
   pantallas chicas. */
.chat-widget.abierto .chat-burbuja {
    display: none;
}

/* --------------------------------------------------------------------------
   El panel.
   -------------------------------------------------------------------------- */

.chat-panel {
    position: fixed;
    right: 15px;
    bottom: 15px;
    width: 370px;
    max-width: calc(100vw - 30px);
    height: 540px;
    max-height: calc(100vh - 30px);
    display: none;
    flex-direction: column;
    background: var(--chat-fondo);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .28);
    overflow: hidden;
    z-index: 101;
    font-size: 14px;
    line-height: 1.5;
    color: var(--chat-oscuro);
}

.chat-widget.abierto .chat-panel {
    display: flex;
}

.chat-cabecera {
    background: var(--chat-primario);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.chat-cabecera h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.chat-cabecera p {
    margin: 2px 0 0;
    font-size: 11px;
    opacity: .85;
}

.chat-cerrar {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    opacity: .85;
}

.chat-cerrar:hover,
.chat-cerrar:focus {
    opacity: 1;
    outline: none;
}

/* --------------------------------------------------------------------------
   Los mensajes.
   -------------------------------------------------------------------------- */

.chat-cuerpo {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    background: var(--chat-gris);
}

.chat-msg {
    max-width: 85%;
    margin-bottom: 10px;
    padding: 9px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-msg.ellos {
    background: #fff;
    border: 1px solid var(--chat-borde);
    border-bottom-left-radius: 3px;
}

.chat-msg.yo {
    background: var(--chat-primario);
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 3px;
}

.chat-msg.error {
    background: #fff4f2;
    border: 1px solid #f6c8c0;
    color: #8c2a1a;
}

.chat-msg a {
    color: inherit;
    text-decoration: underline;
}

.chat-msg.ellos a {
    color: var(--chat-primario);
}

/* Los tres puntitos mientras el modelo piensa. */
.chat-puntos {
    display: inline-block;
    width: 34px;
}

.chat-puntos span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 3px;
    border-radius: 50%;
    background: #b5b5b5;
    animation: chat-latido 1.2s infinite ease-in-out;
}

.chat-puntos span:nth-child(2) {
    animation-delay: .15s;
}

.chat-puntos span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes chat-latido {
    0%, 60%, 100% { opacity: .25; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

/* Quien pidio menos animacion no tiene por que ver los puntitos saltando. */
@media (prefers-reduced-motion: reduce) {
    .chat-puntos span { animation: none; opacity: .5; }
    .chat-burbuja     { transition: none; }
}

/* --------------------------------------------------------------------------
   El pie: escribir, enviar y la salida a WhatsApp.
   -------------------------------------------------------------------------- */

.chat-pie {
    flex: 0 0 auto;
    border-top: 1px solid var(--chat-borde);
    background: #fff;
    padding: 10px 12px;
}

.chat-fila {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-texto {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid var(--chat-borde);
    border-radius: 18px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 96px;
    color: var(--chat-oscuro);
}

.chat-texto:focus {
    outline: none;
    border-color: var(--chat-primario);
}

.chat-enviar {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--chat-primario);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

.chat-enviar:hover:not(:disabled) {
    background: var(--chat-primario-oscuro);
}

.chat-enviar:disabled {
    opacity: .45;
    cursor: default;
}

.chat-avisos {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    font-size: 11px;
    color: #8a8a8a;
}

.chat-avisos a {
    color: #25d366;
    text-decoration: none;
    white-space: nowrap;
    font-weight: 600;
}

.chat-avisos a:hover {
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Celulares: el panel ocupa la pantalla. Un panel de 370px flotando sobre una
   pantalla de 360px se sale por los dos lados.
   -------------------------------------------------------------------------- */

@media (max-width: 480px) {
    .chat-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
}
