/* ==========================================================================
   Chat flotante con el asistente virtual. Sigue la paleta del sitio (main.css):
   fondo claro, morado de marca y las mismas tipografías.
   --chat-accent es el color del boton flotante: lo pone chat.php con el negro del sitio.
   ========================================================================== */

.ec-chat {
    --chat-bg: var(--color-white, #ffffff);
    --chat-surface: #f6f6f8;
    --chat-line: rgba(29, 28, 28, 0.12);
    --chat-text: var(--color-texto, #1d1c1c);
    --chat-muted: #6b6672;
    --chat-ivory: var(--color-texto, #1d1c1c);
    --chat-lilac: var(--color-texto, #1d1c1c);
    --chat-sparkle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0c.6 7 5 11.4 12 12-7 .6-11.4 5-12 12-.6-7-5-11.4-12-12 7-.6 11.4-5 12-12z' fill='%23000'/%3E%3C/svg%3E");

    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1040;
    font-family: var(--font-body, Georgia, 'Times New Roman', serif);
    font-weight: 400;
}

.ec-chat [hidden] { display: none !important; }

/* ---------- Botón flotante ---------- */
.ec-chat__launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    background: var(--chat-accent);
    color: #fff;
    box-shadow: 0 10px 28px rgba(29, 28, 28, 0.25);
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.ec-chat__launcher:hover { transform: translateY(-2px); }
.ec-chat__launcher-icon { font-size: 1.55rem; line-height: 1; }

/* Halo suave que invita a abrir el chat (se detiene al abrirlo) */
.ec-chat__launcher::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 50%;
    border: 1px solid var(--chat-accent);
    animation: ecChatHalo 3s ease-out infinite;
    pointer-events: none;
}

.ec-chat.is-open .ec-chat__launcher::before { animation: none; opacity: 0; }

@keyframes ecChatHalo {
    0% { transform: scale(1); opacity: 0.7; }
    70%, 100% { transform: scale(1.45); opacity: 0; }
}

/* ---------- Burbuja de bienvenida ---------- */
.ec-chat__teaser {
    position: absolute;
    right: 0;
    bottom: 74px;
    display: flex;
    align-items: flex-start;
    gap: 0.25rem;
    width: max-content;
    max-width: 240px;
    padding: 0.7rem 0.5rem 0.7rem 1rem;
    border: 1px solid var(--chat-line);
    border-radius: 14px 14px 4px 14px;
    background: var(--chat-surface);
    box-shadow: 0 10px 28px rgba(29, 28, 28, 0.18);
    animation: ecChatIn 0.35s ease both;
}

.ec-chat__teaser-text {
    padding: 0;
    border: 0;
    background: none;
    color: var(--chat-text);
    font: inherit;
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
}

.ec-chat__teaser-close {
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--chat-muted);
    cursor: pointer;
}

.ec-chat__teaser-close:hover { color: var(--chat-ivory); }

/* ---------- Ventana ---------- */
.ec-chat__panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 380px;
    height: min(600px, calc(100vh - 120px));
    border: 1px solid var(--chat-line);
    border-radius: 20px;
    background: var(--chat-bg);
    box-shadow: 0 10px 60px rgba(29, 28, 28, 0.18);
    overflow: hidden;
    color: var(--chat-text);
    animation: ecChatIn 0.25s ease both;
}

@keyframes ecChatIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.ec-chat__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0.75rem 1rem 1.1rem;
    border-bottom: 1px solid var(--chat-line);
}

.ec-chat__avatar {
    position: relative;
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(29, 28, 28, 0.12);
    background: #f6f6f8;
}

.ec-chat__avatar::after {
    content: '';
    position: absolute;
    inset: 11px;
    background: var(--chat-lilac);
    -webkit-mask: var(--chat-sparkle) center / contain no-repeat;
    mask: var(--chat-sparkle) center / contain no-repeat;
}

.ec-chat__heading { flex: 1; min-width: 0; }

.ec-chat__title {
    margin: 0;
    font-family: var(--font-title, Georgia, 'Times New Roman', serif);
    font-size: 1.15rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--chat-ivory);
}

.ec-chat__status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.1rem 0 0;
    font-size: 0.78rem;
    color: var(--chat-muted);
}

.ec-chat__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6fcf97;
}

.ec-chat__icon-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--chat-muted);
    font-size: 1.1rem;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.ec-chat__icon-btn:hover,
.ec-chat__icon-btn:focus-visible { background: rgba(29, 28, 28, 0.06); color: var(--chat-ivory); }
.ec-chat__icon-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Mensajes ---------- */
.ec-chat__messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 1.1rem 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(29, 28, 28, 0.2) transparent;
}

.ec-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    animation: ecChatIn 0.2s ease both;
}

.ec-msg--bot { align-self: flex-start; }
.ec-msg--user { align-self: flex-end; align-items: flex-end; }

.ec-msg__bubble {
    padding: 0.65rem 0.95rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.ec-msg--bot .ec-msg__bubble {
    border: 1px solid var(--chat-line);
    border-bottom-left-radius: 4px;
    background: var(--chat-surface);
    color: var(--chat-text);
}

.ec-msg--user .ec-msg__bubble {
    border-bottom-right-radius: 4px;
    background: var(--chat-lilac);
    color: #fff;
    white-space: pre-wrap;
}

.ec-msg__bubble p { margin: 0; }
.ec-msg__bubble p + p,
.ec-msg__bubble p + ul,
.ec-msg__bubble ul + p { margin-top: 0.5rem; }
.ec-msg__bubble ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.ec-msg__bubble li { margin-bottom: 0.2rem; }
.ec-msg__bubble strong { font-weight: 500; color: var(--chat-ivory); }
.ec-msg__bubble a { color: var(--accent-color, #9a7bb7); text-underline-offset: 2px; }
.ec-msg__bubble a:hover { color: var(--color-titulos, #803cc1); }

.ec-msg__time {
    margin-top: 0.25rem;
    padding: 0 0.3rem;
    font-size: 0.7rem;
    color: var(--chat-muted);
}

/* Indicador "escribiendo" */
.ec-msg--typing .ec-msg__bubble {
    display: flex;
    gap: 0.3rem;
    padding: 0.85rem 1rem;
}

.ec-msg--typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-lilac);
    animation: ecChatDots 1.2s ease-in-out infinite;
}

.ec-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.ec-msg--typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ecChatDots {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Preguntas sugeridas ---------- */
.ec-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0 1rem 0.85rem;
}

.ec-chat__chip {
    padding: 0.45rem 1rem;
    border: 2px solid rgba(29, 28, 28, 0.2);
    border-radius: 50px;
    background: transparent;
    color: var(--chat-text);
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.ec-chat__chip:hover,
.ec-chat__chip:focus-visible { background: var(--color-black, #1d1c1c); border-color: var(--color-black, #1d1c1c); color: #fff; }

/* ---------- Escribir y grabar ---------- */
.ec-chat__composer,
.ec-chat__recorder {
    display: flex;
    align-items: flex-end;
    gap: 0.35rem;
    margin: 0 0.75rem;
    padding: 0.4rem 0.4rem 0.4rem 0.9rem;
    border: 1px solid var(--chat-line);
    border-radius: 22px;
    background: var(--color-white, #fff);
    transition: border-color 0.2s ease;
}

.ec-chat__composer:focus-within { border-color: var(--chat-lilac); }

.ec-chat__composer textarea {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    padding: 0.5rem 0;
    border: 0;
    background: none;
    color: var(--chat-text);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    outline: none;
}

.ec-chat__composer textarea::placeholder { color: #6b6672; }

.ec-chat__send {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--chat-lilac);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.ec-chat__send:hover { background: var(--chat-ivory); }
.ec-chat__send:disabled { opacity: 0.3; cursor: default; background: var(--chat-ivory); }

.ec-chat__recorder {
    align-items: center;
    padding: 0.45rem 0.45rem 0.45rem 1rem;
    font-size: 0.9rem;
    color: var(--chat-text);
}

.ec-chat__recorder > span:nth-child(2) { flex: 1; }
.ec-chat__recorder strong { font-weight: 500; color: var(--chat-ivory); }

.ec-chat__rec-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #e5484d;
    animation: ecChatBlink 1s ease-in-out infinite;
}

@keyframes ecChatBlink { 50% { opacity: 0.3; } }

.ec-chat__rec-btn {
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--chat-line);
    border-radius: 999px;
    background: none;
    color: var(--chat-text);
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
}

.ec-chat__rec-btn--send { border-color: var(--chat-ivory); background: var(--chat-ivory); color: #1d1c1c; }

.ec-chat__footer {
    margin: 0;
    padding: 0.55rem 1rem 0.7rem;
    font-size: 0.7rem;
    text-align: center;
    color: #6b6672;
}

.ec-chat__footer a { color: #6b6672; }
.ec-chat__footer a:hover { color: var(--chat-ivory); }

/* ---------- Móvil: el chat ocupa la pantalla ---------- */
@media (max-width: 575.98px) {
    .ec-chat { right: 14px; bottom: 14px; }
    .ec-chat__launcher { width: 54px; height: 54px; }
    .ec-chat__teaser { display: none !important; }

    .ec-chat__panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: 100%;
        height: 100dvh;
        border: 0;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Con el chat abierto, el botón flotante y el de WhatsApp no estorban */
    .ec-chat.is-open .ec-chat__launcher { display: none; }
    body:has(.ec-chat.is-open) .whatsapp { display: none; }
    body:has(.ec-chat.is-open) { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .ec-chat *,
    .ec-chat *::before,
    .ec-chat *::after { animation: none !important; transition: none !important; }
}
