/* =========================================================================
 * Cloe web - widget de chat de la web publica.
 * Burbuja flotante ENCIMA del boton de subir arriba (scroll-top).
 * Son 2 flotantes: scroll-top (bottom:20px) y Cloe (bottom:80px).
 * ========================================================================= */

.cloe-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 998;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.92);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.25s ease, background 0.2s ease, box-shadow 0.2s ease, bottom 0.3s ease;

    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(20px + env(safe-area-inset-bottom));
}

/* La burbuja "baila" con el boton de subir arriba: por defecto vive ABAJO
   (en la posicion del scroll-top, que empieza oculto) y SUBE encima de el
   cuando el scroll-top aparece (clase .visible). scroll-top y #cloe-btn son
   hermanos en el DOM (scroll-top va antes), asi que basta el combinador ~. */
.scroll-top-btn.visible ~ .cloe-btn {
    bottom: 80px;
    bottom: calc(80px + env(safe-area-inset-bottom));
}

.cloe-btn:hover {
    background: rgba(37, 99, 235, 1);
    transform: translateY(-3px);
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.5);
}

.cloe-btn:active {
    transform: translateY(-1px);
}

/* Cuando el panel esta abierto, ocultamos la burbuja. */
.cloe-btn.cloe-oculto {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* ---- Panel ---- */
.cloe-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 40px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.28);
    display: none;
    flex-direction: column;
    overflow: hidden;

    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(20px + env(safe-area-inset-bottom));
}

.cloe-panel.cloe-abierto {
    display: flex;
}

.cloe-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #2563eb;
    color: #fff;
}

.cloe-panel__title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.cloe-panel__name {
    font-weight: 700;
    font-size: 16px;
}

.cloe-panel__subtitle {
    font-size: 12px;
    opacity: 0.85;
}

.cloe-panel__actions {
    display: flex;
    gap: 4px;
}

.cloe-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease;
}

.cloe-icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.cloe-panel__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cloe-msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.cloe-msg--user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.cloe-msg--bot {
    align-self: flex-start;
    background: #fff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* Contenido del render Markdown ligero del bot (listas y enlaces). */
.cloe-msg--bot ul {
    margin: 4px 0 4px 18px;
    padding: 0;
}

.cloe-msg--bot li {
    margin: 2px 0;
}

.cloe-msg--bot a {
    color: #2563eb;
    text-decoration: underline;
}

.cloe-msg--estado {
    align-self: flex-start;
    background: #eef2ff;
    color: #4338ca;
    font-style: italic;
    font-size: 13px;
}

.cloe-panel__footer {
    border-top: 1px solid #e2e8f0;
    padding: 10px 12px 8px;
    background: #fff;
}

.cloe-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.cloe-input {
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease;
}

.cloe-input:focus {
    border-color: #2563eb;
}

.cloe-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: none;
    border-radius: 12px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.cloe-send:hover {
    background: #1d4ed8;
}

.cloe-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.cloe-panel__aviso {
    margin: 8px 2px 0;
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    line-height: 1.4;
}

.cloe-panel__aviso a {
    color: #64748b;
    text-decoration: underline;
}

/* Indicador de escritura (puntos) */
.cloe-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 1px;
    border-radius: 50%;
    background: #94a3b8;
    animation: cloe-blink 1.2s infinite both;
}

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

@keyframes cloe-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ---- Movil (breakpoint 768px, el de scroll-top) ---- */
@media (max-width: 768px) {
    .cloe-btn {
        width: 42px;
        height: 42px;
        right: calc(15px + env(safe-area-inset-right));
        bottom: calc(15px + env(safe-area-inset-bottom));
    }
    .scroll-top-btn.visible ~ .cloe-btn {
        bottom: calc(68px + env(safe-area-inset-bottom));
    }

    /* Panel a pantalla completa en movil. */
    .cloe-panel {
        right: 0;
        bottom: 0;
        top: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }
}

/* En pantallas muy pequenas el scroll-top se va a right:10px; Cloe lo calca. */
@media (max-width: 480px) {
    .cloe-btn {
        right: calc(10px + env(safe-area-inset-right));
        bottom: calc(10px + env(safe-area-inset-bottom));
    }
    .scroll-top-btn.visible ~ .cloe-btn {
        bottom: calc(63px + env(safe-area-inset-bottom));
    }
}

@supports not (bottom: env(safe-area-inset-bottom)) {
    .cloe-btn { right: 20px; bottom: 20px; }
    .scroll-top-btn.visible ~ .cloe-btn { bottom: 80px; }
    @media (max-width: 768px) {
        .cloe-btn { right: 15px; bottom: 15px; }
        .scroll-top-btn.visible ~ .cloe-btn { bottom: 68px; }
    }
    @media (max-width: 480px) {
        .cloe-btn { right: 10px; bottom: 10px; }
        .scroll-top-btn.visible ~ .cloe-btn { bottom: 63px; }
    }
}
