/* =========================================================
   Pantalla de acceso
   Solo la carga layouts/guest.php. Usa los tokens de app.css,
   asi que los colores de Ajustes > Identidad llegan aqui solos.

   La idea: el formulario es una pieza de tela blanca cosida
   sobre la foto. La puntada (.auth-seam) es la firma de la
   pantalla y se "cose" una sola vez al cargar, puntada por
   puntada (steps). Es lo unico decorativo que hay.
   ========================================================= */

.auth-body {
    margin: 0;
    min-height: 100vh;
    /* Base oscura: mientras llega la foto no hay destello blanco. */
    background: var(--ink-deep);
    color: var(--text);
    font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.auth {
    --overlap: 24px;
    --sew-ease: cubic-bezier(.16, 1, .3, 1);
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ── La imagen ─────────────────────────────────────────── */

.auth-media {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    background: var(--ink-deep);
    color: #fff;
}

.auth-media-photo {
    position: absolute;
    inset: 0;
    z-index: -2;
    /* La foto se asienta al abrir: llega un poco cerca y retrocede. */
    animation: auth-settle 1.6s var(--sew-ease) both;
}

.auth-media-photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 45%;
    /* --mx / --my los mueve login.js con el puntero (-1..1). Sin JS valen 0. */
    transform: translate3d(calc(var(--mx, 0) * -14px), calc(var(--my, 0) * -10px), 0) scale(1.06);
    transition: transform 1.2s var(--sew-ease);
    will-change: transform;
}

@keyframes auth-settle {
    from { transform: scale(1.07); opacity: .4; }
    to   { transform: none; opacity: 1; }
}

/* El velo se apoya abajo (donde va el texto) y arriba (donde va la hora).
   El centro de la foto queda limpio. Sale del oscuro de la marca, no de
   un negro neutro, para que la foto y el sistema hablen el mismo tono. */
.auth-media-scrim {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--ink-deep) 42%, transparent) 0%,
        color-mix(in srgb, var(--ink-deep) 0%, transparent) 20%,
        color-mix(in srgb, var(--ink-deep) 0%, transparent) 42%,
        color-mix(in srgb, var(--ink-deep) 58%, transparent) 72%,
        color-mix(in srgb, var(--ink-deep) 90%, transparent) 100%);
}

.auth-media-clock {
    position: absolute;
    top: clamp(1.5rem, 3vw, 2.5rem);
    left: clamp(1.75rem, 4vw, 4rem);
    margin: 0;
    font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
    font-size: .8125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: .01em;
    color: rgba(255, 255, 255, .9);
    text-shadow: 0 1px 8px color-mix(in srgb, var(--ink-deep) 70%, transparent);
}

.auth-media-clock:empty { display: none; }

.auth-media-content {
    position: absolute;
    left: clamp(1.75rem, 4vw, 4rem);
    right: calc(var(--overlap) + clamp(2.5rem, 5vw, 5rem));
    bottom: clamp(2rem, 5vw, 4.5rem);
}

/* El isotipo es marino + cian: sobre el velo oscuro el marino se perderia,
   asi que va en su propia placa blanca. */
.auth-media-logo {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 30px color-mix(in srgb, var(--ink-deep) 45%, transparent);
}

.auth-media-logo img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.auth-media-name {
    margin: 1.25rem 0 0;
    max-width: 16ch;
    font-size: clamp(2.25rem, 3.4vw, 3.5rem);
    font-weight: 600;
    line-height: 1.04;
    letter-spacing: -.03em;
    text-wrap: balance;
    text-shadow: 0 2px 18px color-mix(in srgb, var(--ink-deep) 45%, transparent);
}

.auth-media-lead {
    margin: .85rem 0 0;
    max-width: 38ch;
    font-size: 1.0625rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, .88);
    text-wrap: pretty;
}

/* ── La costura ────────────────────────────────────────── */

.auth-seam {
    position: absolute;
    top: 0;
    bottom: 0;
    /* Corre por la foto, a un dedo del borde de la pieza blanca. */
    right: calc(var(--overlap) + 12px);
    width: 2px;
    border-radius: 2px;
    background: repeating-linear-gradient(180deg,
        rgba(255, 255, 255, .92) 0 9px,
        transparent 9px 17px);
    filter: drop-shadow(0 1px 2px color-mix(in srgb, var(--ink-deep) 60%, transparent));
    /* 64 pasos: se ve aparecer puntada a puntada, no deslizarse. */
    animation: auth-sew-down 1.5s steps(64, end) .35s both;
}

@keyframes auth-sew-down {
    from { clip-path: inset(0 0 100% 0); }
    to   { clip-path: inset(0 0 0 0); }
}

/* ── El panel ──────────────────────────────────────────── */

.auth-panel {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: minmax(0, 1fr);
    background: var(--surface-strong);
}

.auth-panel-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-width: 0;
    font-size: .9375rem;
    font-weight: 600;
    color: var(--text);
}

.auth-panel-brand img {
    flex: none;
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.auth-panel-brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-panel-body {
    align-self: center;
    justify-self: center;
    width: 100%;
    max-width: 23rem;
}

.auth-title {
    margin: 0;
    font-size: 2.125rem;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -.025em;
    color: var(--text);
    text-wrap: balance;
}

.auth-lead {
    margin: .6rem 0 1.75rem;
    font-size: .9375rem;
    line-height: 1.55;
    color: var(--text-2);
    text-wrap: pretty;
}

/* ── Avisos ────────────────────────────────────────────── */

.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    margin: 0 0 1.25rem;
    padding: .75rem .85rem;
    border-radius: 8px;
    font-size: .875rem;
    line-height: 1.45;
    animation: auth-pop .32s var(--sew-ease);
}

.auth-alert svg {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: .05rem;
    fill: currentColor;
}

.auth-alert-danger { background: var(--danger-soft); color: var(--danger); }
.auth-alert-ok { background: var(--success-soft); color: var(--success); }

/* ── Formulario ────────────────────────────────────────── */

.auth-form {
    display: grid;
    gap: 1.1rem;
}

.auth-field {
    display: grid;
    gap: .45rem;
}

.auth-field label {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text-2);
}

.auth-field input {
    box-sizing: border-box;
    width: 100%;
    height: 48px;
    padding: 0 .95rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--surface-sunk);
    color: var(--text);
    font: inherit;
    font-size: .9375rem;
    transition: background-color .18s ease, border-color .18s ease;
}

.auth-field input::placeholder { color: var(--muted); opacity: 1; }

.auth-field input:hover {
    background: color-mix(in srgb, var(--surface-sunk) 92%, var(--text));
}

.auth-field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--line-strong);
    background: var(--surface-strong);
}

/* El autocompletado del navegador pinta su propio amarillo/azul. */
.auth-field input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 40px var(--surface-sunk) inset;
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
}

.auth-input-wrap { position: relative; }
.auth-input-wrap input { padding-right: 3.1rem; }

.auth-peek {
    position: absolute;
    top: 50%;
    right: 6px;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transform: translateY(-50%);
    transition: color .15s ease, background-color .15s ease;
}

.auth-peek:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.auth-peek:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.auth-peek svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.auth-peek .auth-peek-hide,
.auth-peek[aria-pressed="true"] .auth-peek-show { display: none; }
.auth-peek[aria-pressed="true"] .auth-peek-hide { display: block; }

.auth-hint {
    margin: 0;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--warn);
}

.auth-hint[hidden] { display: none; }

.auth-captcha { animation: auth-pop .32s var(--sew-ease); }

.auth-attempts {
    display: grid;
    gap: .45rem;
    margin: 0;
    font-size: .8125rem;
    line-height: 1.45;
    color: var(--warn);
}

.auth-attempts-bar {
    display: flex;
    gap: 4px;
}

.auth-attempts-bar i {
    width: 18px;
    height: 4px;
    border-radius: 2px;
    background: var(--warn-soft);
}

.auth-attempts-bar i.is-left { background: var(--warn); }

/* ── Boton ─────────────────────────────────────────────── */

.auth-submit {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    width: 100%;
    height: 50px;
    margin-top: .4rem;
    border: 0;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-size: .9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .18s ease, box-shadow .18s ease, transform .12s ease;
}

.auth-submit:hover {
    background: var(--brand-strong);
    box-shadow: 0 12px 26px rgba(var(--brand-rgb), .3);
}

.auth-submit:active { transform: translateY(1px); }
.auth-submit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.auth-submit-arrow {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s var(--sew-ease);
}

.auth-submit:hover .auth-submit-arrow { transform: translateX(3px); }

.auth-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin .7s linear infinite;
}

/* Enviando: un clic mas no manda la clave dos veces ni suma un fallo de mas. */
.auth-submit[aria-busy="true"] {
    pointer-events: none;
    background: var(--brand-strong);
}

.auth-submit[aria-busy="true"] .auth-spinner { display: block; }
.auth-submit[aria-busy="true"] .auth-submit-arrow { display: none; }

.auth-foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    margin: 0;
    font-size: .8125rem;
    color: var(--muted);
    text-align: center;
}

.auth-foot svg {
    flex: none;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@keyframes auth-pop {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

/* ── Escritorio: 70 / 30 ───────────────────────────────── */

@media (min-width: 992px) {
    .auth {
        /* El 30% nunca baja de 380px: en una laptop de 1024 el formulario
           seguiria siendo comodo aunque le toque algo mas de su parte. */
        grid-template-columns: minmax(0, 7fr) minmax(380px, 3fr);
    }

    .auth-media {
        /* Se mete por debajo de la pieza blanca lo que esta solapa. */
        margin-right: calc(var(--overlap) * -1);
    }

    .auth-panel {
        border-radius: var(--overlap) 0 0 var(--overlap);
        box-shadow: -24px 0 60px color-mix(in srgb, var(--ink-deep) 30%, transparent);
        padding: clamp(1.75rem, 2.6vw, 2.75rem) clamp(1.75rem, 3vw, 3.25rem);
        /* La pieza entra desde la derecha mientras se cose la puntada. */
        animation: auth-panel-in .7s var(--sew-ease) both;
    }

    @keyframes auth-panel-in {
        from { transform: translateX(18px); opacity: .5; }
        to   { transform: none; opacity: 1; }
    }
}

@media (min-width: 1600px) {
    .auth-title { font-size: 2.5rem; }
}

/* ── Movil y tableta: portada + hoja ───────────────────── */

@media (max-width: 991.98px) {
    /* La hoja desplaza, no el documento: desaparecen el rebote elastico y el
       vaiven de la barra de direcciones, que delatan que es un navegador. */
    html { height: 100%; }

    .auth-body {
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .auth {
        height: 100dvh;
        min-height: 0;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .auth-media {
        display: grid;
        place-items: end center;
        /* La foto es la protagonista tambien aqui: la hoja solo necesita el
           alto del formulario, y con 34% sobraba blanco bajo el boton. */
        min-height: 40svh;
        padding: calc(env(safe-area-inset-top) + 1.5rem) 1.5rem calc(var(--overlap) + 2.4rem);
    }

    .auth-media-photo img {
        transform: scale(1.04);
        transition: none;
    }

    .auth-media-clock { display: none; }

    .auth-media-content {
        position: static;
        display: grid;
        justify-items: center;
        text-align: center;
    }

    .auth-media-logo {
        width: 52px;
        height: 52px;
        border-radius: 13px;
    }

    .auth-media-logo img { width: 38px; height: 38px; }

    .auth-media-name {
        margin-top: .7rem;
        max-width: 20ch;
        font-size: clamp(1.4rem, 6.4vw, 1.75rem);
    }

    .auth-media-lead {
        margin-top: .3rem;
        font-size: .875rem;
        max-width: 32ch;
    }

    /* La costura se tiende de lado a lado justo sobre el borde de la hoja. */
    .auth-seam {
        top: auto;
        right: 18px;
        left: 18px;
        bottom: calc(var(--overlap) + 12px);
        width: auto;
        height: 2px;
        background: repeating-linear-gradient(90deg,
            rgba(255, 255, 255, .92) 0 9px,
            transparent 9px 17px);
        animation: auth-sew-across 1.1s steps(40, end) .45s both;
    }

    @keyframes auth-sew-across {
        from { clip-path: inset(0 100% 0 0); }
        to   { clip-path: inset(0 0 0 0); }
    }

    .auth-panel {
        margin-top: calc(var(--overlap) * -1);
        border-radius: var(--overlap) var(--overlap) 0 0;
        box-shadow: 0 -14px 34px color-mix(in srgb, var(--ink-deep) 28%, transparent);
        /* Columna flex y no rejilla: con aviso + verificacion + intentos el
           formulario es mas alto que la hoja, y una fila 1fr lo aplastaba y
           dejaba el pie encima. Asi nada encoge y la hoja desplaza. */
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: 1.9rem 1.4rem calc(1.25rem + max(env(safe-area-inset-bottom), .5rem));
        padding-left: max(1.4rem, env(safe-area-inset-left));
        padding-right: max(1.4rem, env(safe-area-inset-right));
        animation: auth-sheet-in .55s var(--sew-ease) both;
    }

    @keyframes auth-sheet-in {
        from { transform: translateY(5%); opacity: .6; }
        to   { transform: none; opacity: 1; }
    }

    /* La portada ya dice de quien es el sistema. */
    .auth-panel-brand { display: none; }

    .auth-panel-body {
        flex: none;
        align-self: center;
        max-width: 25rem;
    }

    /* Al fondo si sobra alto; detras del formulario si no. */
    .auth-foot {
        flex: none;
        margin-top: auto;
        padding-top: 1.75rem;
    }

    .auth-title { font-size: 1.625rem; }
    .auth-lead { margin-bottom: 1.4rem; }

    /* 16px: por debajo, iOS hace zoom al enfocar el campo. */
    .auth-field input { font-size: 1rem; }
}

/* Con aviso, verificacion o intentos el formulario crece y el boton se iba
   por debajo del borde. Esos estados llegan siempre con la pagina recien
   cargada (POST -> redirect -> GET), asi que la portada cede el sitio desde el
   primer pintado, sin saltos. */
@media (max-width: 991.98px) {
    .auth:has(.auth-alert, .auth-captcha, .auth-attempts) .auth-media {
        min-height: 0;
        padding-top: calc(env(safe-area-inset-top) + 1.1rem);
    }

    .auth:has(.auth-alert, .auth-captcha, .auth-attempts) .auth-media-lead { display: none; }
}

/* Tableta en vertical: sobra alto, la foto se queda con casi la mitad. */
@media (min-width: 600px) and (max-width: 991.98px) and (min-height: 900px) {
    .auth-media { min-height: 48svh; }
    .auth-media-name { font-size: 2.25rem; }
    .auth-media-lead { font-size: 1rem; }
}

/* Telefonos bajos o en horizontal: la portada cede el sitio. */
@media (max-width: 991.98px) and (max-height: 680px) {
    .auth-media { min-height: 0; padding-top: calc(env(safe-area-inset-top) + 1.1rem); }
    .auth-media-lead { display: none; }
    .auth-media-logo { width: 44px; height: 44px; border-radius: 11px; }
    .auth-media-logo img { width: 32px; height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
    .auth-media-photo,
    .auth-seam,
    .auth-panel,
    .auth-alert,
    .auth-captcha {
        animation: none !important;
    }

    .auth-media-photo img {
        transform: scale(1.04) !important;
        transition: none;
    }

    .auth-submit,
    .auth-submit-arrow { transition: none; }
}
