/* ==========================================================================
   Pantalla de acceso (login)
   ==========================================================================

   Se carga SOLO desde `layouts/auth-master`, después de
   `style.bundle.css -> tokens.css -> primitives.css`, y se publica con
   `npm run dev` (webpack lo descubre por glob, no hay que registrarlo).

   Estructura: dos columnas en escritorio. A la izquierda una columna de marca
   de color plano; a la derecha la tarjeta con el formulario. Por debajo de
   992px la columna desaparece y la marca pasa al encabezado de la tarjeta.

   Todo valor sale de los tokens de `tokens.css` salvo la paleta de la columna
   de marca (ver el bloque de abajo, con los contrastes medidos).

   Movimiento: los halos del panel y la entrada de la tarjeta son CSS puro
   (solo `transform`/`opacity`), sin JS ni peticiones. Ver las secciones 1 y 6.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Paleta de la columna de marca.
   Es una superficie de identidad, no un componente del tema: se mantiene
   igual en claro y oscuro, como un logotipo, para que el texto blanco encima
   cumpla contraste en los dos temas.

   Contrastes medidos sobre #312e81:
     blanco   (#ffffff) 11.42:1
     tenue    (#c7d2fe)  7.66:1
   -------------------------------------------------------------------------- */
.auth-page {
    --auth-brand-bg: #312e81;
    --auth-brand-text: #ffffff;
    --auth-brand-muted: #c7d2fe;
    --auth-brand-border: rgba(255, 255, 255, .18);
    --auth-brand-surface: rgba(255, 255, 255, .1);
    /* Ancho físico, no en rem: Metronic fija la raíz en 13px y una tarjeta de
       27.5rem salía de 358px (demasiado estrecha para dos campos cómodos). */
    --auth-card-width: 440px;
}

body.auth-page {
    background-color: var(--bs-body-bg);
    background-image: none;
}

.auth-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ==========================================================================
   1. Columna de marca (solo escritorio)
   ========================================================================== */
.auth-aside {
    position: relative;
    overflow: hidden;
    /* Contexto de apilado propio: los halos y la rejilla vividos dentro. */
    isolation: isolate;
    display: none;
}

@media (min-width: 992px) {
    .auth-aside {
        display: flex;
        width: 44%;
        max-width: 560px;
        background-color: var(--auth-brand-bg);
        color: var(--auth-brand-text);
    }
}

.auth-aside__inner {
    /* Por encima de las capas decorativas. */
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--ds-space-10);
    width: 100%;
    padding: clamp(2rem, 5vw, 4rem);
}

.auth-aside__content {
    max-width: 30rem;
    /* Centra el bloque en el espacio libre bajo la marca en lugar de
       empujarlo contra el borde inferior (space-between con dos hijos). */
    margin-block: auto;
}

.auth-aside__title {
    margin: 0 0 var(--ds-space-4);
    font-size: clamp(1.625rem, 2.4vw, 2.125rem);
    font-weight: var(--ds-font-weight-semibold);
    line-height: 1.25;
    letter-spacing: -.02em;
    color: var(--auth-brand-text);
}

.auth-aside__text {
    margin: 0 0 var(--ds-space-8);
    font-size: var(--ds-font-size-md);
    line-height: var(--ds-line-height-base);
    color: var(--auth-brand-muted);
}

.auth-aside__list {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.auth-aside__list li {
    display: flex;
    align-items: flex-start;
    gap: var(--ds-space-3);
    font-size: var(--ds-font-size-md);
    line-height: var(--ds-line-height-base);
    color: var(--auth-brand-text);
}

.auth-aside__list i {
    margin-top: .0625rem;
    font-size: 1.125rem;
    color: var(--auth-brand-muted);
}

/* --------------------------------------------------------------------------
   Halos y textura del panel de marca (capas decorativas).

   Coste: tres `<span>` con un `radial-gradient` cada uno y una animación de
   `transform` (se compone en la GPU, no repinta). La rejilla es un
   `background-image` de puntos: estática, se pinta una vez.

   A propósito NO se usa `filter: blur()` ni se animan `background-position`,
   `box-shadow` o `filter`: eso obliga a repintar el panel entero en cada frame
   y es justo lo que hace pesadas estas animaciones. Los halos ya son suaves
   porque el gradiente cae a `transparent`.
   -------------------------------------------------------------------------- */
.auth-aside__decor {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.auth-glow {
    position: absolute;
    display: block;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, var(--auth-glow-color) 0%, transparent 68%);
    will-change: transform;
}

.auth-glow--one {
    --auth-glow-color: rgba(129, 140, 248, .45);
    top: -13rem;
    right: -11rem;
    width: 30rem;
    height: 30rem;
    animation: auth-drift-a 34s ease-in-out infinite alternate;
}

.auth-glow--two {
    --auth-glow-color: rgba(91, 91, 214, .42);
    bottom: -14rem;
    left: -10rem;
    width: 30rem;
    height: 30rem;
    animation: auth-drift-b 46s ease-in-out infinite alternate;
}

.auth-glow--three {
    --auth-glow-color: rgba(167, 139, 250, .26);
    top: 34%;
    left: 24%;
    width: 24rem;
    height: 24rem;
    animation: auth-drift-c 58s ease-in-out infinite alternate;
}

@keyframes auth-drift-a {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(-2.75rem, 2.25rem, 0); }
}

@keyframes auth-drift-b {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(2.5rem, -2rem, 0); }
}

@keyframes auth-drift-c {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(1.75rem, 1.5rem, 0); }
}

/* Rejilla de puntos sobre los halos. La máscara la desvanece en el centro y
   deja el borde limpio; va como `::after` para no añadir otro nodo al HTML. */
.auth-aside::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background-image: radial-gradient(rgba(255, 255, 255, .16) 1px, transparent 1px);
    background-size: 22px 22px;
    opacity: .4;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse at 28% 30%, #000 0%, transparent 78%);
    mask-image: radial-gradient(ellipse at 28% 30%, #000 0%, transparent 78%);
}

/* ==========================================================================
   2. Marca
   ========================================================================== */
.auth-brand,
.auth-card-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-3);
}

.auth-card-brand {
    display: flex;
    margin-bottom: var(--ds-space-8);
}

.auth-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--ds-touch-target);
    height: var(--ds-touch-target);
    border: 1px solid var(--auth-brand-border);
    border-radius: var(--ds-radius-md);
    background-color: var(--auth-brand-surface);
    color: var(--auth-brand-text);
}

/* Pictograma vectorial de la marca. */
.auth-brand-mark__svg {
    display: block;
    width: 22px;
    height: 22px;
}

.auth-brand-name {
    font-size: 1.25rem;
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: -.01em;
    color: var(--auth-brand-text);
    white-space: nowrap;
}

/* Dentro de la tarjeta la marca va sobre la superficie del tema, no sobre la
   columna de color: usa el acento. */
.auth-card-brand .auth-brand-mark {
    border-color: var(--ds-accent-border);
    background-color: var(--ds-accent-soft);
    color: var(--ds-accent-text);
}

.auth-card-brand .auth-brand-name {
    color: var(--ds-text-heading);
}

/* ==========================================================================
   3. Columna del formulario y tarjeta
   ========================================================================== */
.auth-main {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    padding: clamp(1.25rem, 4vw, 3rem);
}

.auth-main__inner {
    width: 100%;
    max-width: var(--auth-card-width);
}

.auth-card {
    background-color: var(--ds-surface-card);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-md);
}

.auth-card__body {
    padding: clamp(1.5rem, 4vw, 2.5rem);
}

.auth-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--ds-space-3);
    padding: var(--ds-space-4) clamp(1.5rem, 4vw, 2.5rem);
    border-top: 1px solid var(--ds-border);
}

.auth-copyright {
    margin: 0;
    font-size: var(--ds-font-size-base);
    color: var(--ds-text-subtle);
}

/* ==========================================================================
   4. Formulario
   ========================================================================== */
.auth-heading {
    margin-bottom: var(--ds-space-6);
}

.auth-heading__title {
    margin: 0 0 var(--ds-space-2);
    font-size: 1.75rem;
    font-weight: var(--ds-font-weight-bold);
    line-height: var(--ds-line-height-tight);
    letter-spacing: -.02em;
    color: var(--ds-text-heading);
}

.auth-heading__text {
    margin: 0;
    font-size: var(--ds-font-size-md);
    line-height: var(--ds-line-height-base);
    color: var(--ds-text-muted);
}

.auth-field {
    margin-bottom: var(--ds-space-5);
}

/* Área de toque de 44px: los campos son el único sitio donde se escribe. */
.auth-field .form-control {
    min-height: var(--ds-touch-target);
}

.auth-field__error {
    display: block;
    margin-top: var(--ds-space-2);
    font-size: var(--ds-font-size-base);
    line-height: var(--ds-line-height-base);
    color: var(--ds-danger-text);
}

/* Sin mensaje no ocupa espacio: el Blade lo deja realmente vacío (sin
   espacios en blanco) cuando no hay error. */
.auth-field__error:empty {
    display: none;
}

/* El tema pinta una exclamación DENTRO del campo inválido y reserva 42px a la
   derecha. Aquí el mensaje va debajo del campo y, en la contraseña, ese icono
   se monta sobre el botón de ver. Se retira el icono y se devuelve el relleno
   normal (el de la contraseña se conserva para su botón). */
.auth-field .form-control.is-invalid {
    padding-right: 1rem;
    background-image: none;
}

.auth-password .form-control.is-invalid {
    padding-right: 3.25rem;
}

/* --- Contraseña: campo + botón de visibilidad ---------------------------- */
.auth-password {
    position: relative;
}

.auth-password .form-control {
    padding-right: 3.25rem;
}

.auth-password__toggle {
    position: absolute;
    top: 50%;
    right: .125rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--ds-touch-target);
    height: var(--ds-touch-target);
    padding: 0;
    border: 0;
    border-radius: var(--ds-radius-sm);
    background-color: transparent;
    color: var(--ds-text-muted);
    cursor: pointer;
    transform: translateY(-50%);
    transition: color .15s ease, background-color .15s ease;
}

/* Mismo caso que la marca: el `<i>` del botón trae el gris del tema y no
   hereda el color del botón, que es el que cumple contraste. */
.auth-password__toggle i {
    color: inherit;
}

.auth-password__toggle:hover {
    background-color: var(--ds-surface-muted);
    color: var(--ds-text);
}

/* Foco visible propio: el botón no recibe el estilo de `.form-control:focus`
   y el foco del navegador queda tapado por el borde del campo. */
.auth-password__toggle:focus-visible {
    outline: 2px solid var(--ds-accent);
    outline-offset: 2px;
}

.auth-help {
    margin: 0 0 var(--ds-space-6);
    font-size: var(--ds-font-size-base);
    line-height: var(--ds-line-height-base);
    color: var(--ds-text-muted);
}

.auth-submit {
    min-height: var(--ds-touch-target);
    font-weight: var(--ds-font-weight-semibold);
}

/* --- Resumen de errores -------------------------------------------------- */
.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--ds-space-3);
    margin-bottom: var(--ds-space-5);
}

.auth-alert:focus {
    outline: none;
}

.auth-alert__title {
    margin: 0 0 .125rem;
    font-weight: var(--ds-font-weight-semibold);
}

.auth-alert__text {
    margin: 0;
    font-size: var(--ds-font-size-base);
    line-height: var(--ds-line-height-base);
}

/* ==========================================================================
   5. Pie: idioma + copyright
   ========================================================================== */
.auth-lang {
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    font-size: var(--ds-font-size-base);
    color: var(--ds-text-muted);
}

.auth-lang__label {
    white-space: nowrap;
}

/* El foco del enlace del menú debe verse también sobre fondo claro. */
.auth-lang .dropdown-item:focus-visible,
.auth-card__footer .btn:focus-visible {
    outline: 2px solid var(--ds-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   6. Entrada de la pantalla
   Se declara SOLO dentro de `prefers-reduced-motion: no-preference`: si el
   usuario pidió menos movimiento, ninguna regla aplica y el contenido se ve
   desde el primer frame (la regla base no define `opacity`, así que nunca
   queda oculto por una animación que no llega a correr).
   ========================================================================== */
@media (prefers-reduced-motion: no-preference) {
    .auth-card {
        animation: auth-rise .4s cubic-bezier(.22, .61, .36, 1) both;
    }

    /* El escalonado se limita al contenido del formulario: encabezado, campos,
       ayuda y acción. El pie, la marca y la alerta NO se escalonan (la alerta
       además aparece después, cuando el JS o el servidor marcan un error), así
       que nada se queda "llegando tarde" ni parpadea al enviar. */
    .auth-heading,
    .auth-field,
    .auth-help,
    .auth-submit {
        animation: auth-fade-up .36s cubic-bezier(.22, .61, .36, 1) both;
    }

    .auth-alert {
        animation: auth-fade-up .3s cubic-bezier(.22, .61, .36, 1) both;
    }

    .auth-form > .auth-field:nth-of-type(1) {
        animation-delay: .08s;
    }

    .auth-form > .auth-field:nth-of-type(2) {
        animation-delay: .12s;
    }

    .auth-help {
        animation-delay: .16s;
    }

    .auth-submit {
        animation-delay: .2s;
    }

    .auth-heading {
        animation-delay: .04s;
    }

    .auth-brand,
    .auth-aside__content {
        animation: auth-fade-up .5s cubic-bezier(.22, .61, .36, 1) both;
    }

    .auth-aside__content {
        animation-delay: .08s;
    }
}

@keyframes auth-rise {
    from {
        opacity: 0;
        transform: translate3d(0, 14px, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes auth-fade-up {
    from {
        opacity: 0;
        transform: translate3d(0, 8px, 0);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* ==========================================================================
   7. Movimiento reducido
   Las transiciones son de color; igualmente se anulan por respeto a la
   preferencia del sistema. Los halos se quedan quietos (pero visibles).
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .auth-password__toggle {
        transition: none;
    }

    .auth-glow {
        animation: none;
    }
}

