/* =============================================================================
 * MENU SAAS — Pantallas de acceso (login y registro)
 * =============================================================================
 *
 * POR QUÉ EXISTE ESTA HOJA
 * ------------------------
 * Las pantallas de acceso usaban `app.css`, que es el CSS del *esqueleto* técnico
 * (paleta oscura azul-gris con acento cian). El resto del producto —el sitio
 * público y el panel— usa una identidad cálida y clara (rosa carmesí sobre
 * blanco). Resultado: entrar a `/login` parecía entrar a otra aplicación, y el
 * registro no tenía ni estilos ni etiquetas en los campos.
 *
 * Esta hoja declara los tokens de la identidad pública y los componentes del
 * acceso. Metodología: BEM con prefijo `auth-` (una sola metodología, como el
 * resto del proyecto), capas: tokens → base de la pantalla → componentes.
 *
 * Contraste medido con la fórmula de WCAG 2.1 (sRGB), sobre #ffffff salvo donde
 * se indica:
 *   ink #0f172a ......................... 17.85:1
 *   ink-soft #334155 .................... 10.35:1
 *   muted #64748b ........................ 4.76:1  (4.55:1 sobre el fondo #f8fafc)
 *   primary #be123c ...................... 6.29:1
 *   danger #b91c1c ....................... 6.47:1  (5.91:1 sobre #fef2f2)
 *   success #15803d ...................... 5.02:1  (4.79:1 sobre #f0fdf4)
 *   blanco sobre el botón #be123c ........ 6.29:1
 *   blanco sobre el botón ocupado #9f1239  8.02:1
 *   blanco sobre el degradado #881337 .... 9.57:1
 *   blanco al 92 % sobre la marca ........ 5.74:1
 * Todos ≥ 4.5:1. El foco es un anillo de 2 px con offset (nunca `outline: none`)
 * y todos los controles tienen 44 px de alto mínimo (WCAG 2.1 · 2.5.5).
 * ============================================================================= */

/* ── 1. Tokens de la identidad de acceso ─────────────────────────────────── */
.auth-shell {
    --auth-primary: #be123c;
    --auth-primary-strong: #881337;
    --auth-primary-soft: #fff1f2;
    --auth-ink: #0f172a;
    --auth-ink-soft: #334155;
    --auth-muted: #64748b;
    --auth-border: #e2e8f0;
    --auth-border-strong: #cbd5e1;
    --auth-bg: #f8fafc;
    --auth-surface: #ffffff;
    --auth-danger: #b91c1c;
    --auth-danger-soft: #fef2f2;
    --auth-success: #15803d;
    --auth-success-soft: #f0fdf4;
    --auth-radius-lg: 20px;
    --auth-radius: 12px;
    --auth-radius-sm: 10px;
    --auth-shadow: 0 24px 60px -28px rgba(15, 23, 42, .35);
    --auth-shadow-field: 0 1px 2px rgba(15, 23, 42, .04);
    --auth-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --auth-space-1: .35rem;
    --auth-space-2: .6rem;
    --auth-space-3: 1rem;
    --auth-space-4: 1.5rem;
    --auth-space-5: 2rem;
    --auth-target: 44px;
    --auth-dur: .18s;
    --auth-ease: cubic-bezier(.2, .7, .3, 1);
}

/* ── 2. Base de la pantalla ──────────────────────────────────────────────── */
/* `body.auth-page` gana a la regla `body` de app.css (paleta oscura y centrado
   flex), que es lo que antes teñía de azul estas dos pantallas. La clase la pone
   `views/layout.php` solo en /login y /register. */
body.auth-page {
    display: block;
    padding: 0;
    background: #f8fafc;
    color: #0f172a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.auth-shell {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--auth-bg);
    color: var(--auth-ink);
    font-family: var(--auth-font);
    line-height: 1.55;
}

/* ── 3. Panel de marca (izquierda en escritorio, cabecera en móvil) ──────── */
.auth-brand {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: var(--auth-space-4);
    padding: var(--auth-space-5) var(--auth-space-4);
    color: #ffffff;
    background: linear-gradient(150deg, var(--auth-primary-strong) 0%, var(--auth-primary) 55%, #9f1239 100%);
}

/* Dos halos suaves dan profundidad sin cargar ninguna imagen. */
.auth-brand::before,
.auth-brand::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.auth-brand::before {
    width: 22rem;
    height: 22rem;
    top: -8rem;
    right: -8rem;
    background: radial-gradient(circle, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 70%);
}

.auth-brand::after {
    width: 18rem;
    height: 18rem;
    bottom: -7rem;
    left: -6rem;
    background: radial-gradient(circle, rgba(255, 255, 255, .14), rgba(255, 255, 255, 0) 70%);
}

.auth-brand > * {
    position: relative; /* por encima de los halos */
}

.auth-brand__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .28);
    backdrop-filter: blur(2px);
}

.auth-brand__name {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -.01em;
}

.auth-brand__tagline {
    margin: 0;
    max-width: 34ch;
    font-size: .98rem;
    color: rgba(255, 255, 255, .92);
}

.auth-brand__points {
    display: grid;
    gap: var(--auth-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.auth-brand__point {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    font-size: .92rem;
    color: rgba(255, 255, 255, .95);
}

.auth-brand__point svg {
    flex: 0 0 auto;
    margin-top: .2rem;
    opacity: .9;
}

.auth-brand__back {
    margin-top: auto;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: var(--auth-target);
    font-size: .9rem;
    font-weight: 600;
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.auth-brand__back:hover { text-decoration-thickness: 2px; }

/* ── 4. Panel del formulario ─────────────────────────────────────────────── */
.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--auth-space-4) var(--auth-space-3);
}

.auth-card {
    width: 100%;
    max-width: 27rem;
    background: var(--auth-surface);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-lg);
    box-shadow: var(--auth-shadow);
    padding: var(--auth-space-4);
}

.auth-card__head {
    margin-bottom: var(--auth-space-3);
}

.auth-card__title {
    margin: 0 0 .3rem;
    font-size: 1.4rem;
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--auth-ink);
}

.auth-card__subtitle {
    margin: 0;
    font-size: .93rem;
    color: var(--auth-muted);
}

/* ── 5. Avisos (éxito / error) ───────────────────────────────────────────── */
.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    margin: 0 0 var(--auth-space-3);
    padding: .7rem .8rem;
    border-radius: var(--auth-radius-sm);
    font-size: .9rem;
    border: 1px solid transparent;
}

.auth-alert__icon {
    flex: 0 0 auto;
    margin-top: .1rem;
}

/* El estado nunca se comunica solo con color: lleva icono y texto. */
.auth-alert--error {
    color: var(--auth-danger);
    background: var(--auth-danger-soft);
    border-color: #fca5a5;
}

.auth-alert--success {
    color: var(--auth-success);
    background: var(--auth-success-soft);
    border-color: #86efac;
}

/* ── 6. Campos ───────────────────────────────────────────────────────────── */
.auth-form {
    display: grid;
    gap: var(--auth-space-3);
    margin: 0;
}

.auth-fieldset {
    display: grid;
    gap: var(--auth-space-3);
    margin: 0;
    padding: 0;
    border: 0;
}

.auth-fieldset__legend {
    padding: 0;
    margin-bottom: .35rem;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--auth-muted);
}

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

.auth-field__label {
    font-size: .875rem;
    font-weight: 600;
    color: var(--auth-ink-soft);
}

.auth-field__req {
    color: var(--auth-primary);
    font-weight: 700;
}

.auth-field__row {
    display: grid;
    gap: .6rem;
    grid-template-columns: 1fr;
}

.auth-field__control {
    min-height: var(--auth-target);
    width: 100%;
    padding: .6rem .75rem;
    font-family: inherit;
    font-size: .95rem;
    color: var(--auth-ink);
    background: var(--auth-surface);
    border: 1px solid var(--auth-border-strong);
    border-radius: var(--auth-radius-sm);
    box-shadow: var(--auth-shadow-field);
    transition: border-color var(--auth-dur) var(--auth-ease),
                box-shadow var(--auth-dur) var(--auth-ease);
}

/* El placeholder es texto y también debe cumplir AA: #94a3b8 daba 2.56:1 y se
   descartó. Aun así la etiqueta siempre está visible, el placeholder es refuerzo. */
.auth-field__control::placeholder {
    color: var(--auth-muted);
    opacity: 1;
}

.auth-field__control:hover {
    border-color: #94a3b8;
}

.auth-field__control:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
    border-color: var(--auth-primary);
}

.auth-field__control:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

/* Estado de error: borde + mensaje con texto (nunca solo color). */
.auth-field--error .auth-field__control {
    border-color: var(--auth-danger);
    background: #fffafa;
}

.auth-field--error .auth-field__control:focus-visible {
    outline-color: var(--auth-danger);
}

.auth-field__hint {
    font-size: .8rem;
    color: var(--auth-muted);
}

.auth-field__error {
    display: flex;
    align-items: flex-start;
    gap: .35rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--auth-danger);
}

/* ── 7. Casilla de términos ──────────────────────────────────────────────── */
.auth-check {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    min-height: var(--auth-target);
    padding-block: .35rem;
    font-size: .88rem;
    color: var(--auth-ink-soft);
    cursor: pointer;
}

.auth-check__control {
    flex: 0 0 auto;
    width: 1.15rem;
    height: 1.15rem;
    margin-top: .15rem;
    accent-color: var(--auth-primary);
    cursor: pointer;
}

.auth-check__control:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 2px;
}

.auth-check a,
.auth-help a {
    color: var(--auth-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-check--error {
    color: var(--auth-danger);
}

/* ── 8. Botón principal ──────────────────────────────────────────────────── */
.auth-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    width: 100%;
    min-height: var(--auth-target);
    padding: .7rem 1rem;
    font-family: inherit;
    font-size: .98rem;
    font-weight: 700;
    color: #ffffff;
    background: var(--auth-primary);
    border: 1px solid transparent;
    border-radius: var(--auth-radius-sm);
    box-shadow: 0 10px 20px -12px rgba(190, 18, 60, .8);
    cursor: pointer;
    transition: background-color var(--auth-dur) var(--auth-ease),
                transform var(--auth-dur) var(--auth-ease),
                box-shadow var(--auth-dur) var(--auth-ease);
}

.auth-submit:hover {
    background: var(--auth-primary-strong);
}

.auth-submit:active {
    transform: translateY(1px);
    box-shadow: 0 4px 10px -8px rgba(190, 18, 60, .9);
}

.auth-submit:focus-visible {
    outline: 2px solid var(--auth-ink);
    outline-offset: 2px;
}

/* Estado de envío: lo activa `auth.js` mientras el formulario viaja. */
.auth-submit[aria-disabled="true"],
.auth-submit[data-busy="true"] {
    background: #9f1239;
    cursor: progress;
}

.auth-submit[aria-disabled="true"] .auth-submit__spinner,
.auth-submit[data-busy="true"] .auth-submit__spinner {
    display: inline-block;
}

.auth-submit__spinner {
    display: none;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: auth-spin .8s linear infinite;
}

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

/* ── 9. Pie del formulario ───────────────────────────────────────────────── */
.auth-help {
    margin: var(--auth-space-3) 0 0;
    font-size: .88rem;
    color: var(--auth-muted);
    text-align: center;
}

.auth-help--debug {
    margin-top: var(--auth-space-2);
    padding: .5rem .6rem;
    border: 1px dashed var(--auth-border-strong);
    border-radius: var(--auth-radius-sm);
    font-size: .8rem;
    background: var(--auth-bg);
}

.auth-help code {
    font-size: .82em;
    padding: .1em .35em;
    border-radius: 4px;
    background: #f1f5f9;
    color: var(--auth-ink-soft);
}

.auth-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .25rem .5rem;
    margin: var(--auth-space-3) 0 0;
    padding-top: var(--auth-space-2);
    border-top: 1px solid var(--auth-border);
    font-size: .8rem;
    color: var(--auth-muted);
}

.auth-meta a {
    color: var(--auth-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-meta a:hover { color: var(--auth-ink-soft); }

/* ── Acciones secundarias de la verificación en dos pasos ─────────────────
 * El reto 2FA necesita acciones que no compitan con el botón principal: reenviar
 * el código y cancelar. Se pintan como enlaces con área táctil suficiente
 * (WCAG 2.5.5) y en columna para que no se confundan entre sí. */
.auth-secondary-actions {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin-top: var(--auth-space-3);
}

.auth-inline-form {
    margin: 0;
}

.auth-link-button {
    width: 100%;
    min-height: 2.5rem;
    padding: .45rem .5rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--auth-ink-soft);
    font: inherit;
    font-size: .85rem;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.auth-link-button:hover:not(:disabled) {
    background: #f1f5f9;
}

.auth-link-button:focus-visible {
    outline: 2px solid var(--auth-ink-soft);
    outline-offset: 2px;
}

.auth-link-button:disabled {
    color: var(--auth-muted);
    text-decoration: none;
    cursor: not-allowed;
}

/* ── 10. Escritorio: dos paneles ─────────────────────────────────────────── */
@media (min-width: 900px) {
    .auth-shell {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .auth-brand {
        justify-content: center;
        padding: clamp(2rem, 4vw, 4rem);
    }

    .auth-brand__name { font-size: 1.6rem; }
    .auth-brand__tagline { font-size: 1.05rem; }

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

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

    /* Nombre y apellidos comparten fila cuando hay espacio. */
    .auth-field__row--2 {
        grid-template-columns: 1fr 1fr;
    }
}

/* En móvil el panel de marca es una cabecera compacta: sin puntos ni halos
   grandes, para que el formulario quede alto y visible sin desplazarse. */
@media (max-width: 899px) {
    .auth-brand {
        gap: var(--auth-space-2);
        padding: var(--auth-space-4) var(--auth-space-3);
        text-align: center;
        align-items: center;
    }

    .auth-brand__tagline { font-size: .9rem; }

    .auth-brand__points { display: none; }

    .auth-brand__back {
        margin-top: var(--auth-space-2);
        font-size: .85rem;
    }

    .auth-panel {
        padding: var(--auth-space-3) var(--auth-space-3) var(--auth-space-5);
    }

    .auth-card {
        border-radius: var(--auth-radius-lg);
        box-shadow: 0 12px 30px -20px rgba(15, 23, 42, .35);
        margin-top: calc(var(--auth-space-4) * -1);
    }
}

/* ── 11. Movimiento reducido ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .auth-field__control,
    .auth-submit {
        transition: none;
    }

    .auth-submit:active {
        transform: none;
    }

    .auth-submit__spinner {
        animation: none;
    }
}
