/* Jeilo, el asistente virtual de ProSVial (docs/asistente.md). Sin dependencias. */

#jeilo {
    --j-amarillo: #FBC002;
    --j-tinta: #0F172A;
    --j-fondo: #ffffff;
    --j-lienzo: #f4f6f9;
    --j-texto: #0f172a;
    --j-suave: #64748b;
    --j-borde: rgb(15 23 42 / .09);
    --j-abajo: 22px;
    /* Alto de la barra superior: el chat abierto nunca sube por encima de
       ella, así su X siempre queda a la vista. */
    --j-arriba: calc(76px + env(safe-area-inset-top));
    position: fixed;
    right: 22px;
    bottom: var(--j-abajo);
    /* Panel: sobre la barra inferior (30) y bajo la hoja del menú (40-41),
       que así nunca queda tapada. */
    z-index: 35;
    font-family: 'Inter Variable', Inter, ui-sans-serif, system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--j-texto);
}

.dark #jeilo,
#jeilo[data-tema='oscuro'] {
    --j-fondo: #1b1f27;
    --j-lienzo: #12151b;
    --j-texto: #e8edf3;
    --j-suave: #94a3b8;
    --j-borde: rgb(255 255 255 / .09);
}

/* Web: sobre la cabecera fija (90) solo mientras el chat está abierto; cerrado
   queda a la altura del botón de WhatsApp. La cabecera mide ~84 px. */
#jeilo[data-panel='web'] { z-index: 60; --j-arriba: calc(92px + env(safe-area-inset-top)); }
#jeilo[data-panel='web'].jeilo--abierto { z-index: 95; }

/* Panel, portal y demo: la barra de pestañas inferior existe hasta 1024 px
   (celular y iPad). Jeilo va por encima de ella (60 px más el margen de
   seguridad del iPhone), sin tapar el botón «Menú» de la derecha. */
@media (max-width: 1023.98px) {
    #jeilo:not([data-panel='web']) { --j-abajo: calc(74px + env(safe-area-inset-bottom)); right: 14px; }
}

@media (max-width: 767px) {
    #jeilo { right: 12px; }
    #jeilo .jeilo-lanzador { width: 50px; height: 50px; }
}

#jeilo *, #jeilo *::before, #jeilo *::after { box-sizing: border-box; }
#jeilo svg { display: block; width: 100%; height: 100%; }
#jeilo [hidden] { display: none !important; }

/* --- Lanzador ------------------------------------------------------------ */

.jeilo-lanzador {
    position: relative;
    width: 60px;
    height: 60px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--j-amarillo);
    box-shadow: 0 10px 28px rgb(15 23 42 / .28), 0 0 0 4px rgb(251 192 2 / .22);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.jeilo-lanzador:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 32px rgb(15 23 42 / .32), 0 0 0 6px rgb(251 192 2 / .25); }
.jeilo-lanzador:focus-visible { outline: 3px solid var(--j-tinta); outline-offset: 3px; }
.jeilo-lanzador__avatar { display: block; width: 100%; height: 100%; }
.jeilo--abierto .jeilo-lanzador { transform: scale(.92); }

.jeilo-lanzador__punto {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 13px;
    height: 13px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #22c55e;
}

.jeilo-lanzador__punto::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgb(34 197 94 / .55);
    animation: jeilo-pulso 2.4s infinite;
}

@keyframes jeilo-pulso {
    0% { box-shadow: 0 0 0 0 rgb(34 197 94 / .55); }
    70% { box-shadow: 0 0 0 9px rgb(34 197 94 / 0); }
    100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); }
}

/* Parpadeo del avatar. */
.jeilo-ojos { transform-origin: 32px 33px; animation: jeilo-parpadeo 5s infinite; }

@keyframes jeilo-parpadeo {
    0%, 92%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(.1); }
}

/* --- Saludo discreto ------------------------------------------------------- */

.jeilo-aviso {
    position: absolute;
    right: 4px;
    bottom: 74px;
    width: 236px;
    padding: 12px 34px 12px 14px;
    border-radius: 14px 14px 4px 14px;
    background: var(--j-fondo);
    border: 1px solid var(--j-borde);
    box-shadow: 0 12px 30px rgb(15 23 42 / .16);
    cursor: pointer;
    animation: jeilo-entrar .35s ease both;
}

.jeilo-aviso p { margin: 0; font-size: 13px; color: var(--j-texto); }
.jeilo-aviso__cerrar { position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; padding: 3px; border: 0; background: none; color: var(--j-suave); cursor: pointer; }

/* --- Panel ------------------------------------------------------------------ */

.jeilo-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 384px;
    /* Más bajo que antes (620): deja ver la página detrás y nunca pasa la
       barra superior, cualquiera sea la pantalla. */
    height: min(540px, calc(100vh - var(--j-abajo) - 76px - var(--j-arriba) - 8px));
    height: min(540px, calc(100dvh - var(--j-abajo) - 76px - var(--j-arriba) - 8px));
    overflow: hidden;
    border-radius: 20px;
    background: var(--j-lienzo);
    border: 1px solid var(--j-borde);
    box-shadow: 0 24px 60px rgb(15 23 42 / .28);
    opacity: 0;
    transform: translateY(14px) scale(.97);
    transform-origin: bottom right;
    transition: opacity .2s ease, transform .2s ease;
}

.jeilo-panel--abierto { opacity: 1; transform: none; }

@media (max-width: 520px) {
    /* Celular: hoja entre la barra superior y el botón de Jeilo, con la X
       siempre visible y la cabecera de la página a la vista. */
    #jeilo .jeilo-panel {
        position: fixed;
        top: auto;
        left: 10px;
        right: 10px;
        bottom: calc(var(--j-abajo) + 62px);
        width: auto;
        min-height: 0;
        height: min(560px, calc(100vh - var(--j-arriba) - var(--j-abajo) - 70px));
        height: min(560px, calc(100dvh - var(--j-arriba) - var(--j-abajo) - 70px));
    }
}

.jeilo-cabeza {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px 14px 16px;
    color: #fff;
    background: radial-gradient(120% 160% at 100% 0%, rgb(251 192 2 / .3) 0%, transparent 50%), linear-gradient(135deg, #0b1220, #18233d);
    position: relative;
}

.jeilo-cabeza::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--j-amarillo), transparent 75%); }
.jeilo-cabeza__avatar { flex: none; width: 40px; height: 40px; }
.jeilo-cabeza__texto { flex: 1; min-width: 0; display: grid; }
.jeilo-cabeza__texto b { font-size: 15px; letter-spacing: -.01em; }
.jeilo-cabeza__texto span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgb(255 255 255 / .72); }
.jeilo-en-linea { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }

.jeilo-boton { flex: none; width: 32px; height: 32px; padding: 7px; border: 0; border-radius: 9px; background: rgb(255 255 255 / .08); color: #fff; cursor: pointer; transition: background .15s; }
.jeilo-boton:hover { background: rgb(255 255 255 / .18); }
.jeilo-boton:focus-visible { outline: 2px solid var(--j-amarillo); outline-offset: 1px; }

/* --- Mensajes ---------------------------------------------------------------- */

.jeilo-mensajes { flex: 1; overflow-y: auto; padding: 16px 14px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }

.jeilo-fila { display: flex; gap: 8px; margin-bottom: 10px; animation: jeilo-entrar .25s ease both; }
.jeilo-fila--persona { justify-content: flex-end; }
.jeilo-fila__avatar { flex: none; width: 28px; height: 28px; margin-top: 2px; }

.jeilo-burbuja {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 13.5px;
    overflow-wrap: anywhere;
}

.jeilo-fila--jeilo .jeilo-burbuja { background: var(--j-fondo); border: 1px solid var(--j-borde); border-top-left-radius: 5px; box-shadow: 0 1px 2px rgb(15 23 42 / .05); }
.jeilo-fila--persona .jeilo-burbuja { background: var(--j-amarillo); color: #111; border-bottom-right-radius: 5px; white-space: pre-wrap; }

.jeilo-burbuja p { margin: 0 0 7px; }
.jeilo-burbuja p:last-child { margin-bottom: 0; }
.jeilo-burbuja ol, .jeilo-burbuja ul { margin: 2px 0 8px; padding-left: 19px; }
.jeilo-burbuja ol:last-child, .jeilo-burbuja ul:last-child { margin-bottom: 0; }
.jeilo-burbuja li { margin: 3px 0; padding-left: 2px; }
.jeilo-burbuja li::marker { color: #b48600; font-weight: 700; }
.dark #jeilo .jeilo-burbuja li::marker, #jeilo[data-tema='oscuro'] .jeilo-burbuja li::marker { color: var(--j-amarillo); }
.jeilo-burbuja b { font-weight: 700; }

.jeilo-ia { margin: 8px 0 0 !important; font-size: 11px; color: var(--j-suave); }
.jeilo-ia::before { content: 'IA · '; font-weight: 700; color: #7c3aed; }

#jeilo .jeilo-acciones { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }

/* Botón sutil de marca que lleva a lo que describe. Con #jeilo delante para
   ganarle a «#jeilo svg { width: 100% }»: sin eso, la flecha ocupaba todo el
   ancho y el texto quedaba en columna letra por letra. */
#jeilo .jeilo-accion {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    max-width: 100%;
    padding: 4px 8px 4px 10px;
    border-radius: 999px;
    background: rgb(251 192 2 / .22);
    border: 1px solid rgb(251 192 2 / .55);
    color: #5c4700 !important;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    text-decoration: none !important;
    transition: background .15s, transform .15s;
}

#jeilo .jeilo-accion span { overflow: hidden; text-overflow: ellipsis; }
#jeilo .jeilo-accion svg { width: 12px; height: 12px; flex: none; }
#jeilo .jeilo-accion:hover { background: var(--j-amarillo); transform: translateX(1px); }
.dark #jeilo .jeilo-accion, #jeilo[data-tema='oscuro'] .jeilo-accion { background: rgb(251 192 2 / .16); color: var(--j-amarillo) !important; }
.dark #jeilo .jeilo-accion:hover, #jeilo[data-tema='oscuro'] .jeilo-accion:hover { background: var(--j-amarillo); color: #111 !important; }

.jeilo-sugerencias { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 12px 36px; animation: jeilo-entrar .3s ease both; }

.jeilo-chip {
    padding: 4px 9px;
    border: 1px solid rgb(251 192 2 / .7);
    border-radius: 999px;
    background: rgb(251 192 2 / .1);
    color: var(--j-texto);
    font: inherit;
    font-size: 11.5px;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    transition: background .15s, transform .15s;
}

.jeilo-chip:hover { background: rgb(251 192 2 / .28); transform: translateY(-1px); }
.jeilo-chip:focus-visible { outline: 2px solid var(--j-tinta); outline-offset: 1px; }

/* Escribiendo… */
.jeilo-fila--escribiendo .jeilo-burbuja { display: inline-flex; align-items: center; gap: 8px; color: var(--j-suave); font-size: 12px; }
.jeilo-puntos { display: inline-flex; gap: 4px; }
.jeilo-puntos i { width: 7px; height: 7px; border-radius: 50%; background: #b48600; animation: jeilo-punto 1.2s infinite ease-in-out; }
.jeilo-puntos i:nth-child(2) { animation-delay: .15s; }
.jeilo-puntos i:nth-child(3) { animation-delay: .3s; }

@keyframes jeilo-punto {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes jeilo-entrar {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* --- Escribir ---------------------------------------------------------------- */

.jeilo-escribir { display: flex; align-items: flex-end; gap: 8px; margin: 0 12px; padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--j-fondo); border: 1px solid var(--j-borde); }
.jeilo-escribir:focus-within { border-color: var(--j-amarillo); box-shadow: 0 0 0 3px rgb(251 192 2 / .22); }

.jeilo-escribir textarea {
    flex: 1;
    min-height: 22px;
    max-height: 110px;
    padding: 4px 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--j-texto);
    font: inherit;
    font-size: 13.5px;
}

.jeilo-escribir textarea::placeholder { color: var(--j-suave); }

.jeilo-enviar { flex: none; width: 34px; height: 34px; padding: 8px; border: 0; border-radius: 10px; background: var(--j-amarillo); color: #111; cursor: pointer; transition: transform .15s, opacity .15s; }
.jeilo-enviar:hover { transform: scale(1.06); }
.jeilo-escribir--ocupado .jeilo-enviar { opacity: .45; pointer-events: none; }

.jeilo-pie { margin: 6px 12px 10px; font-size: 10.5px; text-align: center; color: var(--j-suave); }

@media (prefers-reduced-motion: reduce) {
    #jeilo *, #jeilo *::before, #jeilo *::after { animation: none !important; transition: none !important; }
}

/* --- En prosvial.com.co -------------------------------------------------------- */

/* La barra inferior de la web aparece desde 1.060 px: Jeilo va por encima. */
@media (max-width: 1060px) {
    #jeilo[data-panel='web'] { --j-abajo: calc(84px + env(safe-area-inset-bottom)); right: 12px; }
}

/* Pantallas bajas (celular acostado): no hay sitio entre la barra superior y
   la inferior, así que el chat abierto se pone por encima de todo, con su X
   arriba a la vista. */
@media (max-height: 560px) {
    #jeilo[data-panel] { --j-arriba: calc(8px + env(safe-area-inset-top)); }
    #jeilo[data-panel].jeilo--abierto { z-index: 100; }
}
