/* Efectos de SIGS, adaptados de los recursos de Moxen.

   Cinco piezas, cada una con su script en public/js:
     · Sacudida (sacudida.js): el campo con error tiembla y se ve.
     · RUT (rut.js): el RUT se escribe con puntos y guion solo y el dígito
       verificador se revisa mientras se escribe.
     · Deshacer (deshacer.js): quitar algo deja unos segundos para
       arrepentirse, en vez de una ventana de confirmación.
     · Cascada (cascada.js): del bruto al líquido, de lo vendido al
       resultado, en barras que bajan hasta el total.
     · Guía (guia.js): el recorrido de bienvenida por el menú.

   De Moxen se tomó el movimiento (resortes, el anillo que se vacía, el velo
   con su hueco); los colores, la letra y los radios son los de SIGS. Todo se
   apaga con «reducir movimiento» del sistema. */

:root {
    --efecto-curva: cubic-bezier(.22, 1, .36, 1);
    --efecto-rebote: cubic-bezier(.34, 1.56, .64, 1);
    --efecto-bien: #16a34a;
    --efecto-mal: #dc3545;
}

/* ── Sacudida ────────────────────────────────────────────────────────────
   El error que ya se corrigió se retira: el aviso rojo se pliega en vez de
   quedarse diciendo algo que ya no es cierto. */
.invalid-feedback.sacudida-resuelto {
    animation: sacudida-pliega .28s var(--efecto-curva) forwards;
    overflow: hidden;
}
@keyframes sacudida-pliega {
    to { opacity: 0; max-height: 0; margin-top: 0; }
}

/* ── RUT ─────────────────────────────────────────────────────────────────
   El campo deja sitio a la derecha para la marca: ✓ si el dígito calza, un
   aviso rojo si no. La marca está dentro del campo, así no corre el resto
   del formulario. */
.rut-campo { position: relative; display: block; }
.rut-campo > .form-control { padding-right: 7.5rem; }
.rut-marca {
    position: absolute;
    top: 50%;
    right: .6rem;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .15rem .5rem .15rem .35rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
    translate: 0 -50%;
    opacity: 0;
    scale: .85;
    transition: opacity .2s, scale .35s var(--efecto-rebote), background-color .25s, color .25s;
}
.rut-marca svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.rut-marca[data-estado="falta"] { opacity: 1; scale: 1; background: #eef1f6; color: var(--sigs-texto-muted, #5b6675); }
.rut-marca[data-estado="bien"] { opacity: 1; scale: 1; background: #dcf5e6; color: #166534; }
.rut-marca[data-estado="mal"] { opacity: 1; scale: 1; background: #fde2e2; color: #b42318; }
.rut-marca .rut-visto, .rut-marca .rut-cruz { display: none; }
.rut-marca[data-estado="bien"] .rut-visto { display: block; }
.rut-marca[data-estado="mal"] .rut-cruz { display: block; }
/* el ✓ se dibuja y un anillo sale de la marca, como en Dígito de Moxen */
.rut-marca[data-estado="bien"] .rut-visto path { stroke-dasharray: 1; animation: rut-traza .4s var(--efecto-curva) both; }
@keyframes rut-traza { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.rut-marca::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 0 2px var(--efecto-bien);
    opacity: 0;
    pointer-events: none;
}
.rut-marca.rut-onda::after { animation: rut-onda .7s var(--efecto-curva); }
@keyframes rut-onda { 0% { opacity: .6; scale: 1; } 100% { opacity: 0; scale: 1.6; } }
.rut-campo > .form-control.rut-bien { border-color: #86d3a2; }
.rut-campo > .form-control.rut-mal { border-color: #f1a7a7; }

/* ── Deshacer ────────────────────────────────────────────────────────────
   El aviso de abajo: oscuro sobre la pantalla clara para que se note sin
   tapar nada, con el anillo que se vacía segundo a segundo. */
.deshacer-aviso {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 1085;
    display: flex;
    align-items: center;
    gap: .85rem;
    max-width: calc(100vw - 32px);
    padding: .5rem .5rem .5rem .6rem;
    border-radius: 18px;
    background: rgba(17, 24, 39, .94);
    color: #f8fafc;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .3), 0 12px 28px -8px rgba(15, 23, 42, .45), 0 30px 60px -20px rgba(15, 23, 42, .5);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    backdrop-filter: blur(14px) saturate(1.4);
    translate: -50% 140%;
    scale: .92;
    opacity: 0;
    visibility: hidden;
    transition: translate .45s var(--efecto-curva), scale .45s var(--efecto-curva), opacity .25s, visibility 0s .45s;
}
.deshacer-aviso.is-visible {
    translate: -50% 0;
    scale: 1;
    opacity: 1;
    visibility: visible;
    transition: translate .55s var(--efecto-rebote), scale .55s var(--efecto-rebote), opacity .2s, visibility 0s;
}
.deshacer-aviso.is-latido { animation: deshacer-latido .4s var(--efecto-rebote); }
@keyframes deshacer-latido { 40% { scale: .95; } }

.deshacer-reloj { position: relative; flex: none; width: 40px; height: 40px; }
.deshacer-reloj svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.deshacer-pista { fill: none; stroke: rgba(255, 255, 255, .16); stroke-width: 3; }
.deshacer-marca { stroke: rgba(255, 255, 255, .4); stroke-width: 1.3; stroke-linecap: round; transition: opacity .3s; }
.deshacer-arco { fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; transition: stroke .3s, stroke-dashoffset .1s linear; }
.deshacer-visto {
    fill: none;
    stroke: #4ade80;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1 2;
    stroke-dashoffset: 1;
    opacity: 0;
}
.deshacer-cifra {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 50%;
    font-size: .95rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.deshacer-cifra span { grid-area: 1 / 1; }
.deshacer-cifra .is-entra { animation: deshacer-rueda .35s var(--efecto-curva); }
@keyframes deshacer-rueda { from { translate: 0 90%; opacity: 0; } }

.deshacer-texto { display: grid; gap: 1px; min-width: 0; }
.deshacer-titulo { font-size: .875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deshacer-estado { font-size: .78rem; color: rgba(248, 250, 252, .66); white-space: nowrap; }
.deshacer-tecla {
    padding: .15rem .4rem;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 6px;
    background: none;
    color: rgba(248, 250, 252, .66);
    font-family: inherit;
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.3;
    transition: opacity .25s;
}
.deshacer-boton {
    flex: none;
    padding: .55rem 1rem;
    border: 0;
    border-radius: 12px;
    background: #fff;
    color: #111827;
    font-size: .875rem;
    font-weight: 700;
    cursor: pointer;
    transition: scale .35s var(--efecto-rebote), opacity .25s;
}
.deshacer-boton:active { scale: .94; transition-duration: .1s; }
.deshacer-boton:focus-visible { outline: 2px solid #93c5fd; outline-offset: 3px; }

/* restaurado: el arco se vuelve verde, se dibuja el ✓ y el botón se retira */
.deshacer-aviso.is-hecho .deshacer-arco { stroke: #4ade80; }
.deshacer-aviso.is-hecho .deshacer-marca,
.deshacer-aviso.is-hecho .deshacer-cifra { opacity: 0; }
.deshacer-aviso.is-hecho .deshacer-visto { opacity: 1; animation: deshacer-traza .42s .12s var(--efecto-curva) both; }
@keyframes deshacer-traza { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.deshacer-aviso.is-hecho .deshacer-tecla,
.deshacer-aviso.is-hecho .deshacer-boton { opacity: 0; pointer-events: none; }
@media (hover: none), (max-width: 575.98px) { .deshacer-tecla { display: none; } }

/* lo que se quitó se va hacia el lado y, al deshacer, vuelve con un brillo */
.deshacer-vuelve { animation: deshacer-vuelve .9s var(--efecto-curva); }
@keyframes deshacer-vuelve {
    0% { opacity: 0; translate: -12px 0; background-color: var(--sigs-acento-suave, #eef4ff); }
    45% { opacity: 1; translate: 0 0; background-color: var(--sigs-acento-suave, #eef4ff); }
}

/* ── Cascada ─────────────────────────────────────────────────────────────
   Las barras: el punto de partida y el total en azul (el total, lleno); lo
   que resta, en rojo suave; lo que suma, en verde suave. */
.cascada { position: relative; width: 100%; min-height: 200px; }
.cascada svg { display: block; width: 100%; height: auto; overflow: visible; }
.cascada text { font-family: inherit; fill: var(--sigs-oscuro, #111827); }
.cascada__barra rect { transition: opacity .25s; }
.cascada__barra--inicio rect { fill: #c9dafc; stroke: #2563eb; }
.cascada__barra--resta rect { fill: #f8cfcd; stroke: #c2413a; }
.cascada__barra--suma rect { fill: #cdeedb; stroke: #1f8a4c; }
.cascada__barra--total rect { fill: #2563eb; stroke: #1d4ed8; }
.cascada__barra--negativo rect { fill: #e5484d; stroke: #b42318; }
.cascada__barra rect { stroke-width: 1; }
.cascada__monto { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cascada__barra--resta .cascada__monto { fill: #b42318; }
.cascada__parte { font-size: 11px; fill: var(--sigs-texto-muted, #5b6675) !important; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity .2s; }
.cascada__rotulo { font-size: 12px; fill: var(--sigs-texto-muted, #5b6675) !important; }
.cascada__union { stroke: #9aa5b8; stroke-width: 1; stroke-dasharray: 3 3; transition: opacity .35s; }
.cascada__cero { stroke: #c7cfdb; stroke-width: 1; }
/* al pasar por una barra, las demás se atenúan y aparece su parte del total */
.cascada.is-foco .cascada__barra:not(.is-activa) rect { opacity: .35; }
.cascada__barra.is-activa .cascada__parte { opacity: 1; }
.cascada__barra { cursor: default; outline: none; }
.cascada__barra:focus-visible rect { stroke-width: 2.5; }

/* ── Guía ────────────────────────────────────────────────────────────────
   Un velo oscuro con un hueco sobre lo que se explica; el hueco y el globo
   viajan de un paso a otro con un resorte (guia.js). */
.guia { position: fixed; inset: 0; z-index: 1090; pointer-events: none; }
.guia.is-abierta { pointer-events: auto; }
.guia.is-oculta { visibility: hidden; }
.guia__velo { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; overflow: hidden; transition: opacity .5s var(--efecto-curva); }
.guia.is-abierta .guia__velo { opacity: 1; transition-duration: .35s; }
.guia__sombra { fill: rgba(15, 23, 42, .62); fill-rule: evenodd; }
.guia__anillo, .guia__pulso { fill: none; stroke: rgba(255, 255, 255, .95); stroke-width: 1.5; }

.guia__globo {
    position: absolute;
    left: 0;
    top: 0;
    outline: none;
    opacity: 0;
    scale: .92;
    transition: opacity .25s, scale .35s var(--efecto-curva);
}
.guia.is-abierta .guia__globo { opacity: 1; scale: 1; transition: opacity .3s .08s, scale .5s .08s var(--efecto-curva); }
.guia__caja {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: var(--sigs-radio, 14px);
    background: #fff;
    color: var(--sigs-oscuro, #111827);
    box-shadow: 0 30px 70px -18px rgba(15, 23, 42, .5), 0 0 0 1px rgba(15, 23, 42, .06);
}
.guia__flecha { position: absolute; left: 0; top: 0; width: 14px; height: 14px; border-radius: 3px; background: #fff; }
.guia__flecha.is-cambia { animation: guia-asoma .32s var(--efecto-curva); }
@keyframes guia-asoma { from { opacity: 0; } }

.guia__cabeza { position: absolute; top: 15px; left: 18px; right: 16px; display: flex; align-items: center; justify-content: space-between; }
.guia__cuenta { display: inline-flex; font-size: .74rem; font-weight: 600; color: var(--sigs-texto-muted, #5b6675); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.guia__n { display: inline-block; overflow: hidden; height: 1.2em; line-height: 1.2em; }
.guia__n span { display: block; }
.guia__n.is-sube span { animation: guia-cifra .45s var(--efecto-curva); }
.guia__n.is-baja span { animation: guia-cifra-baja .45s var(--efecto-curva); }
@keyframes guia-cifra { from { translate: 0 100%; opacity: 0; } }
@keyframes guia-cifra-baja { from { translate: 0 -100%; opacity: 0; } }
.guia__puntos { display: flex; gap: 5px; }
.guia__puntos i { width: 6px; height: 6px; border-radius: 3px; background: #dbe2ec; transition: width .45s var(--efecto-curva), background-color .3s; }
.guia__puntos i.is-hecho { background: #93b4f5; }
.guia__puntos i.is-actual { width: 20px; background: var(--sigs-acento, #2563eb); }

.guia__texto { position: absolute; top: 40px; left: 18px; }
.guia__texto h2 { margin: 0 0 6px; font-size: 1rem; font-weight: 700; line-height: 1.3; color: var(--sigs-oscuro, #111827); }
.guia__texto p { margin: 0; font-size: .85rem; line-height: 1.55; color: var(--sigs-texto-muted, #5b6675); }
.guia__texto.is-entra { animation: guia-entra .5s .12s var(--efecto-curva) backwards; }
.guia__texto.is-sale { animation: guia-sale .14s ease-in forwards; pointer-events: none; }
@keyframes guia-entra { from { opacity: 0; translate: calc(var(--guia-dir, 1) * 14px) 0; } }
@keyframes guia-sale { to { opacity: 0; translate: calc(var(--guia-dir, 1) * -10px) 0; } }
/* la medida: igual que el texto, invisible, para saber cuánto ocupará */
.guia__mide { position: fixed; left: 0; top: 0; visibility: hidden; width: max-content; max-width: var(--guia-max, 300px); pointer-events: none; }

.guia__pie { position: absolute; left: 10px; right: 12px; bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.guia__botones { display: flex; gap: 6px; }
.guia__globo button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: none;
    color: var(--sigs-oscuro, #111827);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .2s, color .2s, border-color .2s, opacity .2s, translate .2s var(--efecto-curva);
}
.guia__globo .guia__saltar { padding: 0 8px; color: var(--sigs-texto-muted, #5b6675); font-weight: 500; }
.guia__globo .guia__saltar:hover { color: var(--sigs-oscuro, #111827); }
.guia__globo .guia__atras { border-color: var(--sigs-borde, #e3e8f0); }
.guia__globo .guia__atras:hover { background: #f4f6fa; }
.guia__globo .guia__atras:disabled { opacity: .4; cursor: default; background: none; }
.guia__globo .guia__sigue { padding: 0 12px 0 14px; background: var(--sigs-acento, #2563eb); color: #fff; }
.guia__globo .guia__sigue:hover { translate: 1px 0; }
.guia__sigue svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.guia__sigue .guia__ok { display: none; }
.guia__sigue.is-ultimo .guia__ir { display: none; }
.guia__sigue.is-ultimo .guia__ok { display: block; }
.guia__globo .guia__sigue.is-hecho { background: var(--efecto-bien); }
.guia__sigue.is-hecho .guia__ok path { animation: rut-traza .4s var(--efecto-curva) both; }
.guia__globo button:focus-visible { outline: 2px solid var(--sigs-acento, #2563eb); outline-offset: 2px; }
.guia__oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
    .invalid-feedback.sacudida-resuelto { animation-duration: .01s; }
    .rut-marca, .deshacer-aviso, .deshacer-aviso.is-visible { transition-duration: .01s; }
    .rut-marca .rut-visto path, .rut-marca.rut-onda::after,
    .deshacer-aviso.is-latido, .deshacer-cifra .is-entra, .deshacer-vuelve,
    .deshacer-aviso.is-hecho .deshacer-visto { animation-duration: .01s; animation-delay: 0s; }
    .guia__velo, .guia__globo, .guia.is-abierta .guia__velo, .guia.is-abierta .guia__globo { transition-duration: .12s; transition-delay: 0s; scale: 1; }
    .guia__texto.is-entra, .guia__texto.is-sale, .guia__n span, .guia__flecha.is-cambia { animation-duration: .12s; animation-delay: 0s; }
}
