/* ==========================================================================
   JARVIS ELECTORAL — Estilos (tablet vertical, tema cyberpunk azul-rojo)
   ========================================================================== */

:root {
    /* Marca */
    --fondo: #020814;
    --fondo-2: #04263a;               /* azul petróleo del degradado */
    --cian: #00b8ff;
    --cian-claro: #00e5ff;
    --rojo: #ff2a2a;
    --texto: #d8f3ff;
    --texto-2: rgba(216, 243, 255, .72);
    --texto-3: rgba(216, 243, 255, .5);

    /* Superficies */
    --superficie: rgba(4, 20, 34, .74);   /* tarjetas (sobre el fondo: ~#07131f) */
    --superficie-solida: #07131f;
    --borde: rgba(0, 184, 255, .85);
    --sombra-cian: 0 0 18px rgba(0, 184, 255, .35);
    --rejilla: rgba(216, 243, 255, .12);

    /* Series de gráficos (validadas para fondo oscuro y daltonismo) */
    --serie-1: #0092d0;
    --serie-2: #e5323f;
    --serie-3: #9468e0;
    --serie-4: #b8820f;

    /* Tipografía */
    --fuente-titulo: 'Orbitron', 'Segoe UI', system-ui, sans-serif;
    --fuente-texto: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;

    /* Medidas */
    --tactil: 48px;
    --alto-avatar: min(52dvh, 95vw);
    --asa-cajon: 52px;
    --seguro-arriba: env(safe-area-inset-top, 0px);
    --seguro-abajo: env(safe-area-inset-bottom, 0px);
    --seguro-izq: env(safe-area-inset-left, 0px);
    --seguro-der: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: radial-gradient(ellipse 120% 80% at 50% 35%, var(--fondo-2) 0%, #031423 40%, var(--fondo) 75%);
    background-color: var(--fondo);
    color: var(--texto);
    font-family: var(--fuente-texto);
    font-size: 18px;
    font-weight: 500;
    user-select: none;
    -webkit-user-select: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--cian-claro); outline-offset: 3px; }

/* --------------------------------------------------------------------------
   Fondo animado
   -------------------------------------------------------------------------- */
#fondo {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Estructura
   -------------------------------------------------------------------------- */
.app {
    position: relative;
    z-index: 1;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: calc(var(--seguro-arriba) + 8px) calc(var(--seguro-der) + 16px)
             calc(var(--seguro-abajo) + 12px) calc(var(--seguro-izq) + 16px);
}

.barra {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--tactil);
}
.marca {
    font-family: var(--fuente-titulo);
    font-weight: 700;
    letter-spacing: .35em;
    color: var(--cian-claro);
    text-shadow: 0 0 10px var(--cian);
    font-size: 1.05rem;
}
.marca small {
    display: block;
    font-size: .55rem;
    letter-spacing: .5em;
    color: var(--texto-3);
    text-shadow: none;
}
.barra .acciones { display: flex; gap: 8px; }

.escenario {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: gap .3s;
}

/* --------------------------------------------------------------------------
   Avatar y estados
   -------------------------------------------------------------------------- */
.avatar-wrap {
    position: relative;
    height: var(--alto-avatar);
    aspect-ratio: 400 / 480;
    max-width: 90vw;
    display: grid;
    place-items: center;
    transition: height .35s ease;
}
/* ==========================================================================
   Holograma: rostro fotográfico sobre fondo negro que se funde con la escena
   ========================================================================== */
:root {
    /* Posición de ojos y boca en avatar.png (en % del ancho/alto). Ajustar si cambia la imagen.
       Avatar anterior (avatar_circuitos.png): ojos 28.4% / 71.4% / 47.7%; boca 51% / 80.7% / ancho 38%. */
    --ojo-izq-x: 44%;
    --ojo-der-x: 77.5%;
    --ojo-y: 45.3%;
    --ojo-tam: 9%;
    --boca-x: 60.4%;
    --boca-y: 68.1%;        /* línea entre los labios */
    --boca-ancho: 25%;
    --hud: var(--cian);                 /* color de los anillos según estado */
    --mascara-rostro: radial-gradient(ellipse 48% 60% at 51% 47%, #000 62%, rgba(0, 0, 0, .6) 82%, transparent 99%);
}
body[data-estado="escuchando"], body[data-estado="error"] { --hud: var(--rojo); }

.escenario { position: relative; }
.avatar-wrap.es-foto { aspect-ratio: 409 / 612; }
.avatar-wrap.es-foto .anillo { display: none; }

/* Grupo del rostro: se funde en modo "screen" (el negro de la foto desaparece) y flota en 3D */
.rostro {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    animation: flotar 9s ease-in-out infinite;
    will-change: transform;
}
.es-foto .rostro {
    mix-blend-mode: screen;
    -webkit-mask-image: var(--mascara-rostro);
    mask-image: var(--mascara-rostro);
}
/* Orden de capas dentro del rostro: foto (0) < interior de la boca (1) < mandíbula (2) < ojos y líneas (3) < escaneo (4) */
.rostro .avatar { position: absolute; inset: 0; z-index: 0; }
.avatar-wrap.es-foto .avatar {
    filter: brightness(1.05) contrast(1.3) saturate(1.15);   /* el contraste hunde el fondo a negro puro */
    animation: holo-parpadeo 7s infinite;
}
body[data-estado="hablando"] .rostro { animation: asentir 2.8s ease-in-out infinite; }
body[data-estado="escuchando"] .rostro { animation: atender 4s ease-in-out infinite; }

/* Boca: la mandíbula (labio inferior y mentón) baja según --ap (0 cerrada, 1 abierta), que mueve hud.js */
.boca-interior {
    position: absolute;
    left: var(--boca-x);
    top: var(--boca-y);
    width: var(--boca-ancho);
    height: calc(.4% + var(--ap, 0) * 2.4%);
    transform: translate(-50%, -18%);
    z-index: 1;
    border-radius: 50%;
    /* cavidad: negra al centro, se disuelve hacia las comisuras */
    background: radial-gradient(ellipse 50% 50% at 50% 45%, #000 0 45%, rgba(0, 4, 10, .92) 62%, rgba(0, 10, 20, .5) 80%, transparent 100%);
    opacity: min(1, calc(var(--ap, 0) * 5));
}
.mandibula {
    position: absolute;
    inset: 0;
    z-index: 2;
    transform: translateY(calc(var(--ap, 0) * 2%));
    /* solo la zona bajo la línea de los labios, con bordes suaves a los lados y abajo */
    -webkit-mask-image: linear-gradient(to bottom, transparent calc(var(--boca-y) - .4%), #000 calc(var(--boca-y) + .4%)),
                        radial-gradient(ellipse calc(var(--boca-ancho) * .72) 12% at var(--boca-x) calc(var(--boca-y) + 8%), #000 55%, transparent 100%);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(to bottom, transparent calc(var(--boca-y) - .4%), #000 calc(var(--boca-y) + .4%)),
                radial-gradient(ellipse calc(var(--boca-ancho) * .72) 12% at var(--boca-x) calc(var(--boca-y) + 8%), #000 55%, transparent 100%);
    mask-composite: intersect;
}

@keyframes flotar {
    0%, 100% { transform: perspective(900px) translateY(0)     rotateX(0)       rotateY(0); }
    25%      { transform: perspective(900px) translateY(-.6%)  rotateX(-1deg)   rotateY(2.2deg); }
    50%      { transform: perspective(900px) translateY(-1.1%) rotateX(1.4deg)  rotateY(0); }
    75%      { transform: perspective(900px) translateY(-.4%)  rotateX(0)       rotateY(-2.2deg); }
}
@keyframes asentir {
    0%, 100% { transform: perspective(900px) translateY(0)    rotateX(0)      rotateY(0); }
    20%      { transform: perspective(900px) translateY(.4%)  rotateX(2.4deg) rotateY(1deg); }
    45%      { transform: perspective(900px) translateY(-.3%) rotateX(-1deg)  rotateY(-1.4deg); }
    70%      { transform: perspective(900px) translateY(.3%)  rotateX(1.8deg) rotateY(1.2deg); }
}
@keyframes atender {
    0%, 100% { transform: perspective(900px) translateY(-.4%) rotateX(-1.6deg) rotateY(0) scale(1.01); }
    50%      { transform: perspective(900px) translateY(-.7%) rotateX(-2deg)   rotateY(.8deg) scale(1.015); }
}
/* Estados sobre la foto: se combinan con el parpadeo holográfico */
body[data-estado="reposo"] .es-foto .avatar { animation: holo-parpadeo 7s infinite, respirar-foto 4.5s ease-in-out infinite; }
body[data-estado="pensando"] .es-foto .avatar { animation: holo-parpadeo 7s infinite, pulso-foto 2.4s ease-in-out infinite; }
body[data-estado="hablando"] .es-foto .avatar { animation: holo-parpadeo 7s infinite, habla-foto .36s ease-in-out infinite alternate; }
body[data-estado="escuchando"] .es-foto .avatar { filter: brightness(1.12) contrast(1.3) saturate(1.2) drop-shadow(0 0 18px rgba(255, 42, 42, .45)); }

@keyframes respirar-foto {
    0%, 100% { filter: brightness(1.02) contrast(1.3) saturate(1.1); }
    50%      { filter: brightness(1.2) contrast(1.3) saturate(1.25) drop-shadow(0 0 16px rgba(0, 184, 255, .35)); }
}
@keyframes pulso-foto {
    0%, 100% { transform: scale(1);     filter: brightness(1.05) contrast(1.3); }
    50%      { transform: scale(1.012); filter: brightness(1.28) contrast(1.3) drop-shadow(0 0 20px rgba(0, 229, 255, .45)); }
}
@keyframes habla-foto {
    from { transform: scale(1);     filter: brightness(1.06) contrast(1.3); }
    to   { transform: scale(1.018); filter: brightness(1.3) contrast(1.3) drop-shadow(0 0 22px rgba(0, 229, 255, .55)); }
}

.lineas-holo {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom, rgba(0, 229, 255, .07) 0 1px, transparent 1px 4px);
    mix-blend-mode: screen;
    animation: lineas-desplazar 9s linear infinite;
}
.escaneo {
    position: absolute;
    left: 12%;
    right: 12%;
    top: 8%;
    height: 2px;
    z-index: 4;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--cian-claro), transparent);
    box-shadow: 0 0 14px 3px rgba(0, 229, 255, .55);
    opacity: 0;
    animation: escaneo-reposo 9s ease-in-out infinite;
}

/* Ojos: cian natural; rojos al escuchar o en error */
.ojo {
    position: absolute;
    top: var(--ojo-y);
    width: var(--ojo-tam);
    aspect-ratio: 1;
    z-index: 3;
    pointer-events: none;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(255, 60, 60, .95) 0 18%, rgba(255, 42, 42, .45) 34%, transparent 68%);
    mix-blend-mode: color;
    opacity: 0;
    transition: opacity .35s;
}
.ojo-izq { left: var(--ojo-izq-x); }
.ojo-der { left: var(--ojo-der-x); }
.ojo::after {                                 /* destello rojo que sí ilumina */
    content: "";
    position: absolute;
    inset: 30%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 90, 90, .9), transparent 70%);
    mix-blend-mode: screen;
}
body[data-estado="escuchando"] .ojo { opacity: 1; }
body[data-estado="error"] .ojo { opacity: 1; animation: parpadeo-ojo .5s steps(2, jump-none) infinite; }
body[data-estado="pensando"] .ojo { opacity: .35; }

/* Visor ovalado: 150% x 115% del avatar, rodea toda la cabeza sin tocarla.
   Los óvalos usan pathLength="1000", así los guiones fluyen con stroke-dashoffset sin saltos. */
.hud {
    position: absolute;
    width: 150%;
    height: 115%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    color: var(--hud);
    transition: color .4s;
}
.hud-linea { fill: none; stroke: currentColor; stroke-opacity: .3; stroke-width: 1; }
.hud-marcas line { stroke: currentColor; stroke-opacity: .5; stroke-width: 1.3; }
.hud-rotulo { fill: currentColor; fill-opacity: .6; font-family: var(--fuente-titulo); font-size: 10px; letter-spacing: 3.5px; }
.hud-arcos {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.6;
    stroke-opacity: .85;
    stroke-dasharray: 60 15 10 15 110 40;       /* suma 250: divide 1000 */
    filter: drop-shadow(0 0 5px currentColor);
    animation: flujo-250 34s linear infinite;
}
.hud-acento {
    fill: none;
    stroke: var(--rojo);
    stroke-width: 4;
    stroke-dasharray: 14 486;                    /* suma 500 */
    stroke-linecap: round;
    filter: drop-shadow(0 0 6px var(--rojo));
    animation: flujo-500 9s linear infinite reverse;
}
.hud-puntos {
    fill: none;
    stroke: currentColor;
    stroke-opacity: .5;
    stroke-width: 1.6;
    stroke-dasharray: 1 4;                       /* suma 5 */
    animation: flujo-50 22s linear infinite reverse;
}
body[data-estado="pensando"] .hud-arcos  { animation-duration: 4s; }
body[data-estado="pensando"] .hud-acento { animation-duration: 1.6s; }
body[data-estado="escuchando"] .hud-arcos { animation-duration: 10s; stroke-opacity: 1; }
body[data-estado="hablando"] .hud-arcos { animation-duration: 16s; }

@keyframes flujo-250 { to { stroke-dashoffset: -250; } }
@keyframes flujo-500 { to { stroke-dashoffset: -500; } }
@keyframes flujo-50  { to { stroke-dashoffset: -50; } }

body[data-estado="pensando"] .escaneo { animation: escaneo-continuo 2.2s ease-in-out infinite alternate; }
body[data-estado="error"] .avatar-wrap.es-foto .avatar { animation: parpadeo .5s steps(2, jump-none) infinite; }

/* Onda de voz */
.onda {
    width: min(70vw, 460px);
    height: 44px;
    display: block;
    margin-top: -6px;
}

/* Lecturas laterales del visor (datos reales de la sesión) */
.lectura {
    position: absolute;
    top: 2%;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-family: var(--fuente-titulo);
    font-size: .72rem;
    letter-spacing: .12em;
    color: var(--texto);
    z-index: 2;
}
.lectura div { padding-left: 10px; border-left: 2px solid rgba(0, 184, 255, .55); }
.lectura small {
    display: block;
    font-size: .52rem;
    letter-spacing: .3em;
    color: var(--texto-3);
    margin-bottom: 3px;
}
.lectura-izq { left: 0; }
.lectura-der { right: 0; text-align: right; }
.lectura-der div { padding-left: 0; padding-right: 10px; border-left: 0; border-right: 2px solid rgba(0, 184, 255, .55); }
body.cajon-abierto .lectura { display: none; }
@media (max-width: 640px) { .lectura { display: none; } }

/* Reloj (columna izquierda del visor, bajo el modelo) */
.reloj #hudHora {
    display: block;
    font-size: 1.05rem;
    letter-spacing: .12em;
    font-variant-numeric: tabular-nums;
    color: var(--cian-claro);
    text-shadow: 0 0 8px rgba(0, 184, 255, .6);
}
.lectura .reloj-fecha { margin: 3px 0 0; }

@keyframes holo-parpadeo {
    0%, 91%, 93.5%, 100% { opacity: 1; }
    92%   { opacity: .78; }
    93%   { opacity: .92; }
}
@keyframes lineas-desplazar { to { background-position: 0 120px; } }
@keyframes escaneo-reposo {
    0%   { top: 8%;  opacity: 0; }
    3%   { opacity: .9; }
    22%  { top: 88%; opacity: .9; }
    25%, 100% { top: 88%; opacity: 0; }
}
@keyframes escaneo-continuo {
    from { top: 10%; opacity: .95; }
    to   { top: 86%; opacity: .95; }
}
@keyframes parpadeo-ojo { 0% { opacity: 1; } 100% { opacity: .2; } }

/* Marco del visor en las tarjetas: esquinas iluminadas */
.tarjeta::before, .tarjeta::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    pointer-events: none;
    border: 2px solid var(--cian-claro);
    filter: drop-shadow(0 0 4px var(--cian));
}
.tarjeta::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.tarjeta::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }

/* Botón de palabra de activación: encendido = escucha continua */
#btnActivacion[aria-pressed="true"] {
    border-color: var(--cian-claro);
    color: var(--cian-claro);
    background: rgba(0, 229, 255, .15);
    animation: activacion-pulso 2.4s ease-in-out infinite;
}
@keyframes activacion-pulso {
    0%, 100% { box-shadow: 0 0 6px rgba(0, 229, 255, .3); }
    50%      { box-shadow: 0 0 18px rgba(0, 229, 255, .75); }
}

/* Anillo punteado giratorio alrededor del botón de hablar */
.btn-hablar { position: relative; }
.btn-hablar::before {
    content: "";
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    border: 1px dashed rgba(0, 229, 255, .6);
    animation: girar 16s linear infinite;
}
body[data-estado="escuchando"] .btn-hablar::before { border-color: var(--rojo); animation-duration: 3s; }

/* Viñeta: oscurece los bordes para dar profundidad */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(ellipse 85% 75% at 50% 42%, transparent 55%, rgba(0, 0, 0, .55) 100%);
}

body.cajon-abierto .escenario { justify-content: flex-start; }
body.cajon-abierto .avatar-wrap { height: 15dvh; }
body.cajon-abierto .subtitulos,
body.cajon-abierto .estado-texto { visibility: hidden; }

.avatar {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 16px rgba(0, 184, 255, .55));
    position: relative;
    z-index: 2;
    pointer-events: none;
}

.halo, .anillo {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}
.halo {
    inset: 4% -2%;
    z-index: 1;
    background: radial-gradient(closest-side, rgba(0, 184, 255, .16), transparent 70%);
    transition: background .4s, box-shadow .4s;
}
.anillo {
    inset: -3% -8%;
    z-index: 1;
    border: 3px solid transparent;
    border-top-color: var(--cian-claro);
    border-right-color: rgba(0, 229, 255, .45);
    border-bottom-color: rgba(255, 42, 42, .55);
    filter: drop-shadow(0 0 6px var(--cian));
    opacity: 0;
    transition: opacity .3s;
}

.estado-texto {
    font-family: var(--fuente-titulo);
    font-size: .7rem;
    letter-spacing: .4em;
    color: var(--texto-3);
    min-height: 1em;
}

/* Reposo: brillo cian suave */
body[data-estado="reposo"] .avatar { animation: respirar 4.5s ease-in-out infinite; }

/* Escuchando: halo rojo intenso */
body[data-estado="escuchando"] .halo {
    background: radial-gradient(closest-side, rgba(255, 42, 42, .38), transparent 72%);
    animation: halo-rojo 1.1s ease-in-out infinite;
}
body[data-estado="escuchando"] .avatar { filter: drop-shadow(0 0 22px rgba(255, 42, 42, .6)); }
body[data-estado="escuchando"] .estado-texto { color: var(--rojo); }

/* Pensando: pulso lento + anillo giratorio */
body[data-estado="pensando"] .avatar { animation: pulso-lento 2.4s ease-in-out infinite; }
body[data-estado="pensando"] .anillo { opacity: 1; animation: girar 2.2s linear infinite; }
body[data-estado="pensando"] .estado-texto { color: var(--cian-claro); }

/* Hablando: pulso rápido */
body[data-estado="hablando"] .avatar { animation: pulso-rapido .38s ease-in-out infinite alternate; }
body[data-estado="hablando"] .halo { background: radial-gradient(closest-side, rgba(0, 229, 255, .3), transparent 72%); }

/* Error: parpadeo rojo */
body[data-estado="error"] .avatar { animation: parpadeo .5s steps(2, jump-none) infinite; }
body[data-estado="error"] .estado-texto { color: var(--rojo); }

@keyframes respirar {
    0%, 100% { filter: drop-shadow(0 0 12px rgba(0, 184, 255, .4)); }
    50%      { filter: drop-shadow(0 0 26px rgba(0, 229, 255, .75)); }
}
@keyframes halo-rojo {
    0%, 100% { transform: scale(1);    opacity: .75; }
    50%      { transform: scale(1.06); opacity: 1; }
}
@keyframes pulso-lento {
    0%, 100% { transform: scale(1);     filter: drop-shadow(0 0 14px rgba(0, 184, 255, .45)); }
    50%      { transform: scale(1.015); filter: drop-shadow(0 0 24px rgba(0, 229, 255, .7)); }
}
@keyframes pulso-rapido {
    from { transform: scale(1);     filter: drop-shadow(0 0 14px rgba(0, 229, 255, .55)); }
    to   { transform: scale(1.025); filter: drop-shadow(0 0 30px rgba(0, 229, 255, .9)); }
}
@keyframes girar { to { transform: rotate(360deg); } }
@keyframes parpadeo {
    0%   { filter: drop-shadow(0 0 26px rgba(255, 42, 42, .95)); }
    100% { filter: drop-shadow(0 0 4px rgba(255, 42, 42, .2)); }
}

@media (prefers-reduced-motion: reduce) {
    .avatar, .halo, .anillo { animation-duration: 0s !important; animation-iteration-count: 1 !important; }
}

/* --------------------------------------------------------------------------
   Subtítulos
   -------------------------------------------------------------------------- */
.subtitulos {
    width: 100%;
    max-width: 760px;
    text-align: center;
    max-height: 22dvh;
    overflow-y: auto;
    scrollbar-width: none;
}
.sub-usuario {
    margin: 0 0 6px;
    color: var(--texto-2);
    font-size: 1rem;
    font-style: italic;
    min-height: 1.3em;
}
.sub-usuario.parcial { color: var(--texto-3); }
.sub-jarvis {
    margin: 0;
    font-size: 1.3rem;
    line-height: 1.35;
    font-weight: 600;
    user-select: text;
    -webkit-user-select: text;
}

/* --------------------------------------------------------------------------
   Controles
   -------------------------------------------------------------------------- */
.controles {
    position: relative;
    z-index: 6;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    padding-top: 10px;
}
.fila-botones {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
}

.btn-circ {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid rgba(0, 184, 255, .6);
    background: rgba(0, 184, 255, .07);
    display: grid;
    place-items: center;
    transition: background .15s, box-shadow .15s;
}
.btn-circ svg { width: 26px; height: 26px; }
.btn-circ:active { background: rgba(0, 229, 255, .22); box-shadow: var(--sombra-cian); }
.btn-circ[aria-pressed="true"] { border-color: var(--rojo); color: var(--rojo); }
.btn-circ:disabled { opacity: .35; cursor: default; }

.btn-chico { width: var(--tactil); height: var(--tactil); }
.btn-chico svg { width: 22px; height: 22px; }

.btn-hablar {
    width: 104px;
    height: 104px;
    border-radius: 50%;
    border: 2px solid var(--cian-claro);
    background: radial-gradient(circle, rgba(0, 229, 255, .22), rgba(0, 184, 255, .05) 70%);
    box-shadow: 0 0 22px rgba(0, 184, 255, .45), inset 0 0 18px rgba(0, 229, 255, .25);
    display: grid;
    place-items: center;
    transition: transform .12s, box-shadow .2s, border-color .2s;
}
.btn-hablar svg { width: 44px; height: 44px; }
.btn-hablar:active { transform: scale(.96); }
body[data-estado="escuchando"] .btn-hablar {
    border-color: var(--rojo);
    color: var(--rojo);
    box-shadow: 0 0 30px rgba(255, 42, 42, .6), inset 0 0 18px rgba(255, 42, 42, .3);
}
.btn-hablar:disabled { opacity: .4; }

.entrada {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 760px;
}
.entrada input {
    flex: 1;
    min-width: 0;
    height: var(--tactil);
    padding: 0 16px;
    border-radius: 24px;
    border: 1px solid rgba(0, 184, 255, .45);
    background: rgba(2, 8, 20, .6);
    font-size: 1.05rem;
    user-select: text;
    -webkit-user-select: text;
}
.entrada input::placeholder { color: var(--texto-3); }
.entrada input:focus { outline: none; border-color: var(--cian-claro); box-shadow: var(--sombra-cian); }

/* --------------------------------------------------------------------------
   Cajón inferior de resultados
   -------------------------------------------------------------------------- */
/* El cajón se apoya justo encima de los controles (--alto-controles lo mide app.js),
   así el botón de hablar y el campo de texto siguen visibles con los resultados abiertos. */
.cajon {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--alto-controles, 180px);
    z-index: 5;
    height: var(--asa-cajon);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(2, 10, 20, .9);
    border-top: 1px solid var(--borde);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -6px 30px rgba(0, 184, 255, .25);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: height .32s cubic-bezier(.2, .8, .2, 1);
    touch-action: none;
}
.cajon.abierto { height: calc(100dvh - var(--alto-controles, 180px) - var(--seguro-arriba) - 64px - 17dvh); }
.cajon.vacio { display: none; }
.cajon.arrastrando { transition: none; }
body.con-resultados .escenario { margin-bottom: var(--asa-cajon); }

.cajon-asa {
    flex: none;
    height: var(--asa-cajon);
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--fuente-titulo);
    font-size: .7rem;
    letter-spacing: .3em;
    color: var(--texto-2);
}
.cajon-asa::before {
    content: "";
    width: 56px;
    height: 4px;
    border-radius: 2px;
    background: var(--cian);
    box-shadow: 0 0 8px var(--cian);
}
.cajon-contenido {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px calc(var(--seguro-der) + 16px) calc(var(--seguro-abajo) + 20px) calc(var(--seguro-izq) + 16px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    touch-action: pan-y;
}

.resumen {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.35;
    color: var(--texto);
    user-select: text;
    -webkit-user-select: text;
}

/* --------------------------------------------------------------------------
   Tarjetas de panel
   -------------------------------------------------------------------------- */
.tarjeta {
    border: 1px solid var(--borde);
    border-radius: 12px;
    background: var(--superficie);
    box-shadow: var(--sombra-cian);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 14px 16px 12px;
    position: relative;
    user-select: text;
    -webkit-user-select: text;
}
.tarjeta h3 {
    margin: 0 0 10px;
    font-family: var(--fuente-titulo);
    font-size: .9rem;
    font-weight: 500;
    letter-spacing: .08em;
    color: var(--cian-claro);
}
.tarjeta .nota {
    margin: 10px 0 0;
    font-size: .85rem;
    color: var(--texto-3);
}

/* Tabla con scroll horizontal propio */
.tabla-scroll {
    overflow-x: auto;
    max-height: 52dvh;
    overflow-y: auto;
    touch-action: pan-x pan-y;
}
.tabla-scroll table {
    border-collapse: collapse;
    width: 100%;
    font-size: .95rem;
    font-variant-numeric: tabular-nums;
}
.tabla-scroll th, .tabla-scroll td {
    padding: 8px 12px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--rejilla);
}
.tabla-scroll th {
    position: sticky;
    top: 0;
    background: var(--superficie-solida);
    color: var(--texto-2);
    font-weight: 600;
}
.tabla-scroll td.num, .tabla-scroll th.num { text-align: right; }

/* Tarjetas KPI */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.kpi {
    border: 1px solid rgba(0, 184, 255, .35);
    border-radius: 10px;
    padding: 12px;
    background: rgba(0, 184, 255, .05);
}
.kpi .valor {
    font-family: var(--fuente-titulo);
    font-size: 1.6rem;
    color: var(--texto);
    font-variant-numeric: tabular-nums;
}
.kpi .etiqueta { color: var(--texto-2); font-size: .95rem; margin-top: 4px; }

/* Gráficos SVG */
.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; }
.grafico .eje text, .grafico .etq { fill: var(--texto-2); font-size: 13px; font-family: var(--fuente-texto); }
.grafico .valor-etq { fill: var(--texto); font-size: 13px; font-weight: 600; font-family: var(--fuente-texto); }
.grafico .rejilla line { stroke: var(--rejilla); stroke-width: 1; }
.grafico .zona { fill: transparent; }
.leyenda {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin: 0 0 8px;
    font-size: .9rem;
    color: var(--texto-2);
}
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

.tooltip {
    position: absolute;
    z-index: 3;
    pointer-events: none;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(2, 8, 20, .95);
    border: 1px solid rgba(0, 184, 255, .6);
    font-size: .9rem;
    color: var(--texto);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transform: translate(-50%, calc(-100% - 10px));
}
.tooltip[hidden] { display: none; }
.tooltip b { font-weight: 600; color: var(--texto-2); display: block; margin-bottom: 2px; }
.tooltip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }

.btn-texto {
    border: 1px solid rgba(0, 184, 255, .45);
    background: transparent;
    border-radius: 16px;
    padding: 4px 12px;
    min-height: 32px;
    font-size: .85rem;
    color: var(--texto-2);
}
.tarjeta .btn-vista { position: absolute; top: 10px; right: 12px; }

/* --------------------------------------------------------------------------
   Diálogo "Ver consulta"
   -------------------------------------------------------------------------- */
dialog {
    width: min(92vw, 760px);
    max-height: 80dvh;
    border: 1px solid var(--borde);
    border-radius: 14px;
    background: rgba(2, 10, 20, .96);
    color: var(--texto);
    box-shadow: var(--sombra-cian);
    padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px); }
.dlg-cab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rejilla);
    font-family: var(--fuente-titulo);
    font-size: .85rem;
    letter-spacing: .15em;
    color: var(--cian-claro);
}
.dlg-cuerpo { padding: 16px; overflow-y: auto; max-height: calc(80dvh - 70px); }
.dlg-cuerpo pre {
    margin: 0 0 12px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(0, 184, 255, .06);
    border: 1px solid rgba(0, 184, 255, .25);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: .85rem;
    user-select: text;
    -webkit-user-select: text;
}

/* Selector de voz */
.voz-nota { margin: 0 0 14px; color: var(--texto-2); }
.voz-campo { display: block; margin-bottom: 6px; font-family: var(--fuente-titulo); font-size: .65rem; letter-spacing: .25em; color: var(--texto-3); }
.voz-select {
    width: 100%;
    min-height: var(--tactil);
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 184, 255, .5);
    background: rgba(2, 8, 20, .9);
    color: var(--texto);
    font: inherit;
}
.voz-deslizador { margin-top: 16px; display: flex; gap: 8px; align-items: baseline; }
.voz-deslizador span { font-family: var(--fuente-texto); letter-spacing: 0; font-size: .8rem; color: var(--texto-3); }
.voz-deslizador output { margin-left: auto; color: var(--cian-claro); letter-spacing: .1em; }
.voz-rango { width: 100%; height: var(--tactil); accent-color: var(--cian); }
.voz-acciones { margin: 12px 0; }
.voz-acciones .btn-texto { min-height: 40px; padding: 6px 18px; }
.voz-ayuda { margin: 0; font-size: .9rem; color: var(--texto-3); }
.voz-ayuda b { color: var(--texto-2); }

/* --------------------------------------------------------------------------
   Avisos (instalación, errores de voz)
   -------------------------------------------------------------------------- */
.aviso {
    position: fixed;
    left: 50%;
    top: calc(var(--seguro-arriba) + 64px);
    transform: translateX(-50%);
    z-index: 10;
    max-width: min(92vw, 560px);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--borde);
    background: rgba(2, 10, 20, .95);
    box-shadow: var(--sombra-cian);
    display: flex;
    gap: 12px;
    align-items: center;
}
.aviso.error { border-color: var(--rojo); box-shadow: 0 0 18px rgba(255, 42, 42, .35); }
.aviso[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */
body.pagina-login { overflow-y: auto; }

/* Rostro a la izquierda y panel a la derecha; en vertical, apilados */
.acceso {
    position: relative;
    z-index: 1;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(24px, 7vw, 120px);
    padding: calc(var(--seguro-arriba) + 20px) calc(var(--seguro-der) + 16px) calc(var(--seguro-abajo) + 20px) calc(var(--seguro-izq) + 16px);
}
.acceso-rostro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}
.acceso-rostro .avatar-wrap { height: min(62dvh, 38vw); }
.acceso-estado {
    font-family: var(--fuente-titulo);
    font-size: .78rem;
    letter-spacing: .45em;
    color: var(--cian-claro);
    text-shadow: 0 0 10px rgba(0, 184, 255, .7);
    animation: estado-latido 2.4s ease-in-out infinite;
}
body[data-estado="error"] .acceso-estado { color: var(--rojo); text-shadow: 0 0 10px rgba(255, 42, 42, .7); }
@keyframes estado-latido { 50% { opacity: .55; } }

@media (orientation: portrait), (max-width: 860px) {
    .acceso { flex-direction: column; gap: 14px; }
    .acceso-rostro { gap: 10px; }
    .acceso-rostro .avatar-wrap { height: min(30dvh, 58vw); }
}

/* Panel del teclado */
.panel-acceso {
    position: relative;
    width: min(92vw, 410px);
    padding: 22px 24px 16px;
    border: 1px solid rgba(0, 184, 255, .55);
    border-radius: 14px;
    background:
        linear-gradient(180deg, rgba(0, 229, 255, .07), transparent 90px),
        linear-gradient(160deg, rgba(4, 32, 52, .78), rgba(2, 10, 20, .88));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 0 34px rgba(0, 184, 255, .22), inset 0 0 30px rgba(0, 184, 255, .06);
    overflow: hidden;
}
.panel-acceso::before, .panel-acceso::after {        /* esquinas iluminadas del visor */
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    border: 2px solid var(--cian-claro);
    filter: drop-shadow(0 0 5px var(--cian));
    pointer-events: none;
}
.panel-acceso::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.panel-acceso::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }

.panel-cab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(0, 184, 255, .2);
}
.panel-cab .marca { font-size: .95rem; }
.panel-sello {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid rgba(0, 229, 255, .45);
    border-radius: 20px;
    font-family: var(--fuente-titulo);
    font-size: .58rem;
    letter-spacing: .25em;
    color: var(--cian-claro);
}
.panel-sello svg { width: 14px; height: 14px; }

.panel-titulo {
    margin: 18px 0 12px;
    text-align: center;
    font-family: var(--fuente-titulo);
    font-size: .68rem;
    letter-spacing: .38em;
    color: var(--texto-2);
}

/* Casillas del código */
.celdas { display: flex; justify-content: center; gap: 10px; min-height: 52px; }
.celda {
    width: 40px;
    height: 50px;
    display: grid;
    place-items: center;
    border-radius: 6px 6px 2px 2px;
    background: rgba(0, 184, 255, .06);
    border-bottom: 2px solid rgba(0, 184, 255, .4);
    transition: border-color .15s, background .15s;
}
.celda.llena { background: rgba(0, 184, 255, .12); border-bottom-color: var(--cian); }
.celda.llena::after {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--cian-claro);
    box-shadow: 0 0 10px var(--cian), 0 0 20px rgba(0, 229, 255, .5);
    animation: celda-entra .18s ease-out;
}
.celda.cursor { border-bottom-color: var(--cian-claro); animation: cursor-parpadeo 1s steps(2, jump-none) infinite; }
@keyframes celda-entra { from { transform: scale(0); } }
@keyframes cursor-parpadeo { 50% { border-bottom-color: transparent; } }

.panel-acceso .error {
    min-height: 1.5em;
    margin: 10px 0 8px;
    text-align: center;
    font-family: var(--fuente-titulo);
    font-size: .68rem;
    letter-spacing: .3em;
    color: var(--rojo);
    text-shadow: 0 0 8px rgba(255, 42, 42, .6);
}

/* Teclas con esquinas cortadas */
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tecla {
    --corte: 12px;
    min-height: 62px;
    border: 0;
    display: grid;
    place-items: center;
    font-family: var(--fuente-titulo);
    font-size: 1.55rem;
    color: var(--texto);
    background: linear-gradient(180deg, rgba(0, 184, 255, .16), rgba(0, 184, 255, .04));
    box-shadow: inset 0 0 0 1px rgba(0, 184, 255, .5), inset 0 -12px 18px rgba(0, 0, 0, .25);
    clip-path: polygon(var(--corte) 0, 100% 0, 100% calc(100% - var(--corte)), calc(100% - var(--corte)) 100%, 0 100%, 0 var(--corte));
    transition: background .12s, color .12s, text-shadow .12s;
}
.tecla svg { width: 26px; height: 26px; }
.tecla:hover { background: linear-gradient(180deg, rgba(0, 184, 255, .24), rgba(0, 184, 255, .08)); }
.tecla:active, .tecla.pulsada { animation: tecla-destello .35s ease-out; }
.tecla-sec { color: var(--texto-2); }
.tecla-entrar {
    color: #021018;
    background: linear-gradient(180deg, var(--cian-claro), var(--cian));
    box-shadow: 0 0 18px rgba(0, 229, 255, .45);
}
.tecla-entrar:hover { background: linear-gradient(180deg, #7ff3ff, var(--cian-claro)); }
@keyframes tecla-destello {
    0%   { background: rgba(0, 229, 255, .55); color: #fff; text-shadow: 0 0 12px var(--cian-claro); }
    100% { text-shadow: none; }
}

.panel-pie {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 184, 255, .2);
    font-family: var(--fuente-titulo);
    font-size: .52rem;
    letter-spacing: .22em;
    color: var(--texto-3);
}
.panel-pie span { display: inline-flex; align-items: center; gap: 6px; }
.panel-pie svg { width: 12px; height: 12px; }
#relojAcceso { font-size: .7rem; color: var(--texto-2); letter-spacing: .15em; }

/* Acceso denegado / código corto: sacudida roja */
.panel-acceso.denegado, .panel-acceso.corto { animation: sacudir .45s cubic-bezier(.36, .07, .19, .97); }
.panel-acceso.denegado { border-color: rgba(255, 42, 42, .7); box-shadow: 0 0 34px rgba(255, 42, 42, .25); }
.panel-acceso.denegado .celda { border-bottom-color: rgba(255, 42, 42, .7); }
@keyframes sacudir {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-8px); }
    40%, 60% { transform: translateX(8px); }
}

/* Verificando: haz de escaneo sobre el panel */
.panel-escaneo { position: absolute; inset: 0; pointer-events: none; }
.panel-acceso.verificando .panel-escaneo::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--cian-claro), transparent);
    box-shadow: 0 0 18px 4px rgba(0, 229, 255, .6);
    animation: escaneo-panel .65s ease-in-out forwards;
}
.panel-acceso.verificando .teclado { opacity: .45; pointer-events: none; }
@keyframes escaneo-panel { from { top: 0; } to { top: 100%; } }

.pagina-login[data-estado="error"] .avatar { animation-iteration-count: 6 !important; }

@media (max-height: 700px) and (orientation: landscape) {
    .tecla { min-height: 50px; }
    .panel-titulo { margin: 12px 0 8px; }
}

/* Pantallas bajas (tablet en horizontal o teléfono) */
@media (max-height: 640px) {
    :root { --alto-avatar: 38dvh; }
    .btn-hablar { width: 84px; height: 84px; }
}
