/* CHAT DE AYUDA
   Burbuja abajo a la derecha y ventanita de chat. Sin librerías.
   Capas: la cabecera es sticky con z-index 100 y el visor de capturas
   va con 200; el chat queda en medio (150) para no tapar una captura
   ampliada. */

.chat-burbuja {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 150;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background-color: #2d5a3d;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.chat-burbuja:hover {
    background-color: #1e3d2a;
    transform: scale(1.05);
}

.chat-burbuja:focus-visible,
.chat-cerrar:focus-visible,
.chat-enviar:focus-visible,
.chat-abrir-enlace:focus-visible {
    outline: 3px solid #2d5a3d;
    outline-offset: 3px;
}

.chat-burbuja svg {
    width: 28px;
    height: 28px;
}

.chat-ventana {
    position: fixed;
    right: 20px;
    bottom: 92px;
    z-index: 150;
    width: 370px;
    height: min(580px, calc(100vh - 120px));
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-ventana[hidden] {
    display: none;
}

/* La web da a todos los párrafos margen y letra grande: aquí no. */
.chat-ventana p {
    margin: 0;
    font-size: inherit;
}

/* Cabecera verde */
.chat-cabecera {
    background-color: #2d5a3d;
    color: #ffffff;
    padding: 14px 12px 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-cabecera-textos {
    flex: 1;
    min-width: 0;
}

.chat-ventana .chat-titulo {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

.chat-ventana .chat-subtitulo {
    font-size: 0.8rem;
    opacity: 0.85;
}

.chat-cerrar {
    background: none;
    border: none;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
}

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

/* Aviso de privacidad */
.chat-ventana .chat-aviso {
    background-color: #f5f9f6;
    border-bottom: 1px solid #d8e6dc;
    color: #505050;
    font-size: 0.78rem;
    line-height: 1.45;
    padding: 10px 16px;
}
/* Mensajes */
.chat-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: #ffffff;
    /* Para que offsetTop de cada mensaje se mida desde aquí (chat.js
       deja la pregunta arriba al llegar la respuesta). */
    position: relative;
}

.chat-mensaje {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.92rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.chat-ventana .chat-mensaje p + p {
    margin-top: 6px;
}

.chat-mensaje-asistente {
    align-self: flex-start;
    background-color: #f0f4f1;
    color: #2c2c2c;
    border-bottom-left-radius: 4px;
}

.chat-mensaje-visitante {
    align-self: flex-end;
    background-color: #2d5a3d;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-mensaje-asistente a:not(.chat-boton-whatsapp):not(.chat-boton-derivar) {
    color: #2d5a3d;
    font-weight: 600;
    text-decoration: underline;
}

.chat-boton-whatsapp,
.chat-boton-derivar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    background-color: #ffffff;
    border: 1px solid #2d5a3d;
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #2d5a3d;
    text-decoration: none;
}

.chat-boton-whatsapp:hover,
.chat-boton-derivar:hover {
    background-color: #2d5a3d;
    color: #ffffff;
}

/* Pie: caja de escribir */
.chat-pie {
    border-top: 1px solid #e5e5e5;
    padding: 12px;
}

.chat-formulario {
    display: flex;
    gap: 8px;
}

.chat-entrada {
    flex: 1;
    min-width: 0;
    border: 1px solid #d0d0d0;
    border-radius: 999px;
    padding: 10px 16px;
    font: inherit;
    font-size: 16px; /* 16px: así el iPhone no hace zoom al escribir */
    color: #2c2c2c;
}

.chat-entrada:focus {
    outline: none;
    border-color: #2d5a3d;
    box-shadow: 0 0 0 2px #d8e6dc;
}

.chat-enviar {
    flex: none;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background-color: #2d5a3d;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-enviar:hover {
    background-color: #1e3d2a;
}

.chat-enviar svg {
    width: 20px;
    height: 20px;
}

/* ¿Te he resuelto la duda? Centrado, entre mensaje y mensaje. */
.chat-valoracion {
    align-self: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 8px;
    text-align: center;
    font-size: 0.82rem;
    color: #606060;
    margin: 0 0 4px;
}

.chat-valoracion-pregunta {
    width: 100%;
}

.chat-valoracion.contestada {
    margin-bottom: -4px;
}

.chat-valoracion button {
    background-color: #ffffff;
    border: 1px solid #2d5a3d;
    border-radius: 999px;
    padding: 6px 16px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: #2d5a3d;
    cursor: pointer;
}

.chat-valoracion button:hover {
    background-color: #2d5a3d;
    color: #ffffff;
}

.chat-valoracion button:focus-visible {
    outline: 3px solid #2d5a3d;
    outline-offset: 2px;
}

/* «Escribiendo…»: tres puntos mientras llega la respuesta. */
.chat-escribiendo {
    display: flex;
    gap: 4px;
    padding: 14px 16px;
}

.chat-escribiendo span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #2d5a3d;
    opacity: 0.35;
    animation: chat-punto 1.2s infinite ease-in-out;
}

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

@keyframes chat-punto {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-escribiendo span { animation: none; opacity: 0.6; }
}

.chat-entrada:disabled,
.chat-enviar:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* Línea en la sección Contacto */
.chat-contacto {
    margin-top: 12px;
}

.chat-abrir-enlace {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-weight: 600;
    color: #2d5a3d;
    text-decoration: underline;
    cursor: pointer;
}

.chat-abrir-enlace:hover {
    color: #1e3d2a;
}

/* MÓVIL: la ventanita ocupa casi toda la pantalla y la burbuja se esconde
   mientras está abierta. */
@media (max-width: 640px) {
    .chat-burbuja {
        right: 16px;
        bottom: 16px;
        width: 56px;
        height: 56px;
    }

    .chat-ventana {
        right: 8px;
        left: 8px;
        top: 8px;
        bottom: 8px;
        width: auto;
        height: auto;
        border-radius: 14px;
    }

    .chat-abierto .chat-burbuja {
        display: none;
    }
}
