/* ==========================================================================
   LIA — asistente de la intranet: botón flotante + panel con orbe de voz
   ========================================================================== */

.lia,
.lia-launcher {
    --lia-verde: #04463a;
    --lia-verde-hi: #0b6b58;
    --lia-menta: #3fbf9a;
    --lia-naranja: #CF7606;
    --lia-naranja-hi: #e28a17;
    --lia-crema: #fbf6ec;
    --lia-tinta: #0f2c26;
    --lia-tinta-suave: rgba(15, 44, 38, .62);
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* --- Botón flotante ------------------------------------------------------- */

.lia-launcher,
.lia-burbuja {
    /* altura del botón: por encima del rótulo de la app activa y del ticker */
    --lia-abajo: calc(var(--gutter) + 130px);
}

.lia-launcher {
    position: fixed;
    right: calc(var(--gutter) + 6px);
    bottom: var(--lia-abajo);
    z-index: 94;
    display: flex;
    align-items: center;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 999px;
    background: rgba(255, 255, 255, .12);
    backdrop-filter: blur(10px);
    cursor: pointer;
    box-shadow: 0 10px 34px rgba(0, 0, 0, .28), 0 0 0 0 rgba(226, 138, 23, .5);
    animation: lia-llamado 3.2s ease-out infinite;
    transition: transform .3s var(--ease), background .3s;
}

.lia-launcher:hover,
.lia-launcher:focus-visible { transform: scale(1.08); background: rgba(4, 70, 58, .6); }

html.boot .lia-launcher,
html.lia-abierta .lia-launcher,
html.boot .lia-burbuja,
html.lia-abierta .lia-burbuja { opacity: 0; pointer-events: none; }

/* mensaje de bienvenida junto al orbe */
.lia-burbuja {
    position: fixed;
    right: calc(var(--gutter) + 6px + 64px + 14px);
    bottom: calc(var(--lia-abajo) + 4px);
    z-index: 94;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    max-width: 250px;
    padding: 12px 10px 12px 16px;
    border-radius: 18px 18px 4px 18px;
    background: #fff;
    color: #0f2c26;
    font: 400 15px/1.4 var(--sans);
    letter-spacing: 0;
    text-transform: none;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .3);
    cursor: pointer;
    transform-origin: 100% 100%;
    animation: lia-burbuja-entra .6s var(--ease) both, lia-burbuja-flota 4s ease-in-out .6s infinite;
    transition: opacity .3s;
}

.lia-burbuja[hidden] { display: none; }
.lia-burbuja p { margin: 0; }
.lia-burbuja strong { color: #04463a; }

/* colita apuntando al orbe */
.lia-burbuja::after {
    content: "";
    position: absolute;
    right: -7px;
    bottom: 10px;
    border: 8px solid transparent;
    border-left-color: #fff;
    border-right: 0;
}

.lia-burbuja__cerrar {
    flex: none;
    display: grid;
    place-items: center;
    width: 24px; height: 24px;
    margin-top: -4px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(15, 44, 38, .5);
    cursor: pointer;
}

.lia-burbuja__cerrar:hover { background: rgba(4, 70, 58, .08); color: #CF7606; }

.lia-burbuja__cerrar svg {
    width: 14px; height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
}

@keyframes lia-burbuja-entra { from { opacity: 0; transform: translateX(12px) scale(.85); } }
@keyframes lia-burbuja-flota { 50% { transform: translateY(-4px); } }

@keyframes lia-llamado {
    0%, 60% { box-shadow: 0 10px 34px rgba(0, 0, 0, .28), 0 0 0 0 rgba(226, 138, 23, .45); }
    100% { box-shadow: 0 10px 34px rgba(0, 0, 0, .28), 0 0 0 18px rgba(226, 138, 23, 0); }
}

/* orbe pequeño: tres manchas de color girando dentro de una esfera de vidrio */
.lia-launcher__orbe {
    position: relative;
    flex: none;
    width: 52px; height: 52px;
    border-radius: 50%;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #fff 0 18%, #dff3ea 60%, #bfe6d7);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .8), inset 0 -6px 14px rgba(4, 70, 58, .35);
}

.lia-launcher__orbe i {
    position: absolute;
    inset: -20%;
    border-radius: 50%;
    filter: blur(7px);
    mix-blend-mode: multiply;
    animation: lia-gira 6s linear infinite;
}

.lia-launcher__orbe i:nth-child(1) { background: radial-gradient(circle at 30% 30%, var(--lia-naranja-hi), transparent 45%); }
.lia-launcher__orbe i:nth-child(2) { background: radial-gradient(circle at 70% 60%, var(--lia-verde-hi), transparent 45%); animation-duration: 8s; animation-direction: reverse; }
.lia-launcher__orbe i:nth-child(3) { background: radial-gradient(circle at 40% 75%, var(--lia-menta), transparent 40%); animation-duration: 5s; }

.lia-launcher__orbe::after {
    content: "";
    position: absolute;
    top: 10%; left: 18%;
    width: 36%; height: 22%;
    border-radius: 50%;
    background: rgba(255, 255, 255, .85);
    filter: blur(2px);
    transform: rotate(-30deg);
}

@keyframes lia-gira { to { transform: rotate(360deg); } }

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

.lia {
    position: fixed;
    inset: 0;
    z-index: 95;
    display: grid;
    grid-template-columns: minmax(320px, 600px) 1fr;
    grid-template-rows: auto 1fr;
    color: var(--lia-tinta);
    font-family: var(--sans);
    letter-spacing: 0;
    text-transform: none;
    opacity: 0;
    transform: scale(.98);
    transition: opacity .35s var(--ease), transform .45s var(--ease);
}

.lia[hidden] { display: none; }
html.lia-abierta .lia { opacity: 1; transform: none; }

.lia__fondo {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(60% 70% at 78% 50%, rgba(63, 191, 154, .22), transparent 70%),
        radial-gradient(40% 50% at 95% 95%, rgba(226, 138, 23, .18), transparent 70%),
        radial-gradient(50% 60% at 0% 0%, rgba(11, 107, 88, .1), transparent 70%),
        var(--lia-crema);
}

.lia__top {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: var(--gutter) var(--gutter) 0;
}

.lia__titulo {
    margin: 0;
    font: 500 13px/1.2 var(--mono);
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--lia-tinta-suave);
}

.lia__titulo b {
    font-weight: 500;
    margin-right: 8px;
    padding: 3px 9px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(120deg, var(--lia-verde), var(--lia-verde-hi));
    letter-spacing: .2em;
}

.lia__acciones { display: flex; gap: 12px; }

.lia__icono {
    display: grid;
    place-items: center;
    width: 48px; height: 48px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: var(--lia-verde);
    box-shadow: 0 6px 20px rgba(15, 44, 38, .1);
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
}

.lia__icono:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(15, 44, 38, .16); }

/* interruptor de manos libres */
.lia__manos {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 18px 0 14px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    color: var(--lia-verde);
    font: 500 14px/1 var(--sans);
    box-shadow: 0 6px 20px rgba(15, 44, 38, .1);
    cursor: pointer;
    transition: background .25s, color .25s, transform .2s;
}

.lia__manos:hover { transform: translateY(-2px); }

.lia__manos[aria-pressed="true"] {
    color: #fff;
    background: linear-gradient(135deg, var(--lia-naranja), var(--lia-naranja-hi));
    animation: lia-escucha 1.6s ease-out infinite;
}

/* punto naranja en el orbe flotante: LIA está atenta a su nombre */
html.lia-manos-libres .lia-launcher::after {
    content: "";
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--lia-naranja-hi);
    box-shadow: 0 0 0 2px #fff;
    animation: lia-escucha 1.6s ease-out infinite;
}
.lia__icono--cerrar { color: var(--lia-naranja); }

.lia svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lia__icono[aria-pressed="true"] .off,
.lia__icono[aria-pressed="false"] .on { display: none; }

/* --- Chat ----------------------------------------------------------------- */

.lia__chat {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 16px;
    min-height: 0;
    padding: 12px var(--gutter) var(--gutter);
}

.lia__mensajes {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 4px 8px;
    scrollbar-width: thin;
    mask-image: linear-gradient(transparent, #000 40px);
}

.lia__msg {
    max-width: 88%;
    margin: 0;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 17px;
    line-height: 1.5;
    white-space: pre-line;
    overflow-wrap: anywhere;
    animation: lia-entra .45s var(--ease) both;
}

.lia__msg--lia {
    align-self: flex-start;
    background: rgba(255, 255, 255, .9);
    border-top-left-radius: 6px;
    box-shadow: 0 6px 22px rgba(15, 44, 38, .07);
}

.lia__msg--yo {
    align-self: flex-end;
    color: #fff;
    background: linear-gradient(135deg, var(--lia-verde), var(--lia-verde-hi));
    border-top-right-radius: 6px;
    box-shadow: 0 8px 22px rgba(4, 70, 58, .25);
}

.lia__msg--error { background: #fff4e6; color: #8a4b00; }
.lia__msg a { color: var(--lia-naranja); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.lia__msg--yo a { color: #ffd08a; }

/* puntos mientras LIA piensa */
.lia__msg--pensando { display: flex; gap: 6px; padding: 18px 20px; }
.lia__msg--pensando i {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--lia-verde-hi);
    animation: lia-punto 1.1s ease-in-out infinite;
}
.lia__msg--pensando i:nth-child(2) { animation-delay: .15s; background: var(--lia-menta); }
.lia__msg--pensando i:nth-child(3) { animation-delay: .3s; background: var(--lia-naranja-hi); }

@keyframes lia-punto { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-6px); opacity: 1; } }
@keyframes lia-entra { from { opacity: 0; transform: translateY(10px); } }

.lia__chips { display: flex; flex-wrap: wrap; gap: 8px; }
.lia__chips[hidden] { display: none; }

.lia__chips button {
    padding: 9px 14px;
    border: 1px solid rgba(4, 70, 58, .18);
    border-radius: 999px;
    background: rgba(255, 255, 255, .7);
    color: var(--lia-verde);
    font: 500 14px/1.2 var(--sans);
    cursor: pointer;
    transition: background .2s, border-color .2s;
}

.lia__chips button:hover { background: #fff; border-color: var(--lia-naranja-hi); }

.lia__form {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 0 1.5px rgba(4, 70, 58, .12), 0 14px 40px rgba(63, 191, 154, .28);
    transition: box-shadow .3s;
}

.lia__form:focus-within {
    box-shadow: 0 0 0 2px var(--lia-naranja-hi), 0 14px 44px rgba(226, 138, 23, .3);
}

.lia__form input {
    flex: 1;
    min-width: 0;
    padding: 12px 6px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--lia-tinta);
    font: 400 17px/1.2 var(--sans);
}

.lia__form input::placeholder { color: rgba(15, 44, 38, .45); }

.lia__mic,
.lia__enviar {
    display: grid;
    place-items: center;
    flex: none;
    width: 46px; height: 46px;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: background .2s, color .2s, transform .2s;
}

.lia__mic { background: transparent; color: var(--lia-verde); }
.lia__mic:hover { background: rgba(4, 70, 58, .08); }

.lia__mic[aria-pressed="true"] {
    color: #fff;
    background: var(--lia-naranja);
    animation: lia-escucha 1.2s ease-out infinite;
}

@keyframes lia-escucha { from { box-shadow: 0 0 0 0 rgba(207, 118, 6, .5); } to { box-shadow: 0 0 0 14px rgba(207, 118, 6, 0); } }

.lia__enviar { color: #fff; background: linear-gradient(135deg, var(--lia-verde), var(--lia-verde-hi)); }
.lia__enviar:hover { transform: scale(1.05); }
.lia__enviar:disabled { opacity: .45; cursor: default; transform: none; }

.lia__aviso {
    margin: 0;
    text-align: center;
    font-size: 13px;
    color: var(--lia-tinta-suave);
}

/* --- Orbe ----------------------------------------------------------------- */

.lia__escena {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
}

.lia__orbe {
    width: min(100%, 78vh);
    aspect-ratio: 1;
    cursor: pointer;
    /* el halo se desvanece antes del borde del lienzo: nunca se ve cortado */
    -webkit-mask-image: radial-gradient(closest-side, #000 82%, transparent);
    mask-image: radial-gradient(closest-side, #000 82%, transparent);
}

.lia__estado {
    position: absolute;
    bottom: calc(var(--gutter) + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .7);
    font: 500 12px/1 var(--mono);
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--lia-verde);
    pointer-events: none;
}

/* --- Celular: orbe arriba, chat abajo ------------------------------------- */

@media (max-width: 820px) {
    .lia { grid-template-columns: 1fr; grid-template-rows: auto minmax(150px, 34vh) 1fr; }
    .lia__escena { grid-row: 2; }
    .lia__chat { grid-row: 3; padding-top: 0; }
    .lia__orbe { width: auto; height: 100%; }
    .lia__estado { bottom: 0; }
    .lia__msg { font-size: 16px; }
    .lia__icono { width: 42px; height: 42px; }
    .lia__empresa { display: none; }
    .lia__manos { height: 42px; padding: 0 12px; }
    .lia__manos span { display: none; }
    .lia-launcher,
    .lia-burbuja { --lia-abajo: calc(var(--gutter) + 150px); }
    .lia-burbuja { max-width: 232px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .lia-launcher,
    .lia-burbuja,
    .lia-launcher__orbe i { animation: none; }
}
