/* =====================================================
   Chatbot PsicoEduca: globo sobre WhatsApp + chat privado
   ===================================================== */

.chatbot-root {
    font-family: var(--font-body, 'Source Sans 3', 'Segoe UI', sans-serif);
}

/* ---------- Globo flotante (encima del botón de WhatsApp) ---------- */

.chatbot-bubble {
    position: fixed;
    bottom: 106px;
    right: 30px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--navy-blue) 0%, var(--navy-blue-light) 100%);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1150;
    box-shadow: 0 10px 24px rgba(22, 44, 82, 0.45);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chatbot-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 14px 30px rgba(22, 44, 82, 0.55);
}

.chatbot-bubble-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--orange);
    border: 2px solid #FFFFFF;
    animation: chatbot-pulso 2s ease-in-out infinite;
}

.chatbot-bubble.chatbot-leido .chatbot-bubble-dot {
    display: none;
}

.chatbot-bubble.chatbot-con-pendiente .chatbot-bubble-dot {
    display: block;
}

@keyframes chatbot-pulso {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.75; }
}

.chatbot-bubble-tip {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%);
    background: #FFFFFF;
    color: var(--navy-blue);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-heading, 'Libre Franklin', sans-serif);
    padding: 7px 12px;
    border-radius: 10px 10px 10px 2px;
    white-space: nowrap;
    box-shadow: 0 6px 18px rgba(15, 30, 60, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease 0.3s;
}

.chatbot-bubble:hover .chatbot-bubble-tip,
.chatbot-bubble:focus-visible .chatbot-bubble-tip {
    opacity: 1;
}

/* ---------- Panel del chat: cajón lateral integrado ---------- */
/* Se abre dentro de la propia web (estilo YouTube Studio): el
   panel ocupa el lateral derecho a pantalla completa y la
   página se adapta reduciendo su ancho (body.chatbot-abierto). */

.chatbot-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 100vw);
    height: 100vh;
    height: 100dvh;
    max-height: none;
    display: flex;
    flex-direction: column;
    background: #FFFFFF;
    border-radius: 0;
    border-left: 1px solid rgba(15, 30, 60, 0.10);
    box-shadow: -16px 0 44px rgba(15, 30, 60, 0.16);
    overflow: hidden;
    z-index: 1160;
    animation: chatbot-entra-lado 0.62s cubic-bezier(0.16, 1, 0.3, 1);
}

.chatbot-panel[hidden] {
    display: none;
}

@keyframes chatbot-entra-lado {
    from { opacity: 0; transform: translateX(70px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes chatbot-entra {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chatbot-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--navy-blue) 0%, var(--navy-blue-light) 100%);
    color: #FFFFFF;
    flex-shrink: 0;
}

.chatbot-head-ava {
    position: relative;
    flex-shrink: 0;
}

.chatbot-head-ava img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: contain;
    background: #FFFFFF;
    padding: 4px;
    box-sizing: border-box;
    border: 2px solid rgba(255, 255, 255, 0.65);
    display: block;
}

.chatbot-head-estado {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #2ecc71;
    border: 2px solid var(--navy-blue);
}

.chatbot-head-txt {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.chatbot-head-txt strong {
    font-family: var(--font-heading, 'Libre Franklin', sans-serif);
    font-size: 0.95rem;
    line-height: 1.2;
}

.chatbot-head-txt span {
    font-size: 0.72rem;
    opacity: 0.75;
}

.chatbot-head-btns {
    display: flex;
    gap: 4px;
}

.chatbot-head-btn {
    background: transparent;
    border: none;
    color: #FFFFFF;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.8;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.chatbot-head-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    opacity: 1;
}

/* ---------- Mensajes ---------- */

.chatbot-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: var(--bg-light-gray, #F8F9FA);
    display: flex;
    flex-direction: column;
    gap: 10px;
    overscroll-behavior: contain;
}

.chatbot-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: chatbot-msg-entra 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes chatbot-msg-entra {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tarjetas-enlace de la respuesta: entran en cascada */
.chatbot-enlaces .chatbot-tarjeta {
    animation: chatbot-msg-entra 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chatbot-enlaces .chatbot-tarjeta:nth-child(2) { animation-delay: 0.14s; }
.chatbot-enlaces .chatbot-tarjeta:nth-child(3) { animation-delay: 0.28s; }
.chatbot-enlaces .chatbot-tarjeta:nth-child(4) { animation-delay: 0.42s; }
.chatbot-enlaces .chatbot-tarjeta:nth-child(5) { animation-delay: 0.56s; }

.chatbot-msg-bot { align-self: flex-start; }
.chatbot-msg-user { align-self: flex-end; }

.chatbot-burbuja {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
}

.chatbot-msg-bot .chatbot-burbuja {
    background: #FFFFFF;
    color: var(--text-main, #333);
    border: 1px solid var(--border-color, #E2E8F0);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(15, 30, 60, 0.05);
}

.chatbot-msg-user .chatbot-burbuja {
    background: var(--navy-blue);
    color: #FFFFFF;
    border-top-right-radius: 4px;
}

.chatbot-escribiendo {
    display: inline-flex;
    gap: 5px;
    align-items: center;
}

.chatbot-escribiendo span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--navy-blue);
    opacity: 0.4;
    animation: chatbot-parpadeo 1.2s infinite;
}

.chatbot-escribiendo span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-escribiendo span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-parpadeo {
    0%, 100% { opacity: 0.35; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Tarjetas de resultado con enlace ---------- */

.chatbot-enlaces {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    width: 100%;
}

.chatbot-tarjeta {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: #FFFFFF;
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 12px;
    padding: 10px 34px 10px 12px;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-tarjeta:hover {
    border-color: var(--cyan);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 30, 60, 0.1);
}

.chatbot-tarjeta-cat {
    align-self: flex-start;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--cyan-hover, #049ea3);
    background: rgba(5, 177, 183, 0.1);
    padding: 2px 8px;
    border-radius: 999px;
}

.chatbot-tarjeta-titulo {
    font-weight: 600;
    font-size: 0.86rem;
    color: var(--navy-blue);
    font-family: var(--font-heading, 'Libre Franklin', sans-serif);
}

.chatbot-tarjeta-desc {
    font-size: 0.76rem;
    color: var(--text-muted, #666);
    line-height: 1.35;
}

.chatbot-tarjeta-ir {
    position: absolute;
    right: 12px;
    top: 12px;
    color: var(--orange);
    font-weight: 700;
    font-size: 0.95rem;
}

/* ---------- Sugerencias rápidas ---------- */

.chatbot-sugerencias {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 14px;
    background: #FFFFFF;
    border-top: 1px solid var(--border-color, #E2E8F0);
    flex-shrink: 0;
}

.chatbot-sugerencias[hidden] {
    display: none;
}

.chatbot-chip {
    background: #FFFFFF;
    border: 1px solid var(--border-color, #E2E8F0);
    color: var(--navy-blue);
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chatbot-chip:hover {
    background: var(--navy-blue);
    border-color: var(--navy-blue);
    color: #FFFFFF;
}

/* ---------- Formulario de entrada ---------- */

.chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: #FFFFFF;
    border-top: 1px solid var(--border-color, #E2E8F0);
    flex-shrink: 0;
}

.chatbot-honey {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.chatbot-entrada {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 999px;
    padding: 11px 16px;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-main, #333);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-entrada:focus {
    border-color: var(--navy-blue);
    box-shadow: 0 0 0 3px rgba(22, 44, 82, 0.12);
}

.chatbot-enviar {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--navy-blue);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chatbot-enviar:hover {
    background: var(--cyan-hover, #049ea3);
    transform: scale(1.05);
}

/* ---------- Formulario de contacto (captación) ---------- */

.chatbot-burbuja-contacto {
    border-color: var(--cyan) !important;
}

.chatbot-form-contacto {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chatbot-input-contacto {
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.chatbot-input-contacto:focus {
    border-color: var(--cyan);
}

.chatbot-contacto-btns {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-enviar-contacto {
    border: none;
    border-radius: 999px;
    background: var(--navy-blue);
    color: #FFFFFF;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 9px 18px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chatbot-enviar-contacto:hover {
    background: var(--cyan-hover, #049ea3);
}

.chatbot-omitir-contacto {
    background: transparent;
    border: none;
    color: var(--text-muted, #666);
    font-family: inherit;
    font-size: 0.78rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
}

.chatbot-contacto-error {
    margin: 0;
    color: #c0392b;
    font-size: 0.76rem;
}

/* ---------- Aviso de enlace al navegar ---------- */

.chatbot-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: min(430px, calc(100vw - 40px));
    background: var(--navy-blue);
    color: #FFFFFF;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(15, 30, 60, 0.35);
    animation: chatbot-entra 0.3s ease;
}

.chatbot-toast[hidden] {
    display: none;
}

.chatbot-toast-ico {
    color: var(--orange);
    font-weight: 700;
    flex-shrink: 0;
}

.chatbot-toast-txt {
    flex: 1;
    min-width: 0;
    font-size: 0.84rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-toast-btn {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #FFFFFF;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chatbot-toast-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* ---------- Móvil ---------- */

@media (max-width: 768px) {
    .chatbot-bubble {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        right: 14px;
        width: 54px;
        height: 54px;
    }

    .chatbot-bubble-tip {
        display: none;
    }

    /* En móvil el chat es pantalla completa: no hay sitio para
       reajustar la página como en escritorio */
    .chatbot-panel {
        left: 0;
        right: 0;
        width: auto;
        top: 0;
        bottom: 0;
        height: 100dvh;
        max-height: none;
        border-left: none;
        box-shadow: 0 -10px 40px rgba(15, 30, 60, 0.20);
        animation: chatbot-entra-lado 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .chatbot-toast {
        right: 10px;
        left: 10px;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-bubble-dot { animation: none; }
    .chatbot-panel, .chatbot-toast { animation: none; }
    .chatbot-escribiendo span { animation: none; opacity: 0.7; }
}

/* ---------- Integración con la página (estilo YouTube Studio) ----------
   Con el chat abierto, el contenido de la página y la cabecera fija
   se estrechan para hacerle sitio en vez de quedar tapados. */

body {
    transition: margin-right 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

body.chatbot-abierto {
    margin-right: min(400px, 100vw);
}

body.chatbot-abierto .header {
    width: calc(100% - min(400px, 100vw));
}

/* Los botones flotantes se apartan mientras el chat está abierto */
body.chatbot-abierto .chatbot-bubble,
body.chatbot-abierto .whatsapp-btn {
    transform: translateX(140%);
    opacity: 0;
    pointer-events: none;
}

.chatbot-bubble,
.whatsapp-btn {
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
}

@media (max-width: 768px) {
    body.chatbot-abierto {
        margin-right: 0;
    }

    body.chatbot-abierto .header {
        width: 100%;
    }
}
