/**
 * LOGIN.CSS — macOS Glassmorphism (≥768px) + iOS Native (<768px)
 * Multi-factor: username → auth-method → biometric / otp / pin
 * Compatible with core.css variables
 */

/* ============================================
   CUSTOM PROPERTIES (login-scope only)
   ============================================ */
:root {
    --login-card-bg:          rgba(255, 255, 255, 0.92);
    --login-card-border:      rgba(0, 0, 0, 0.08);
    --login-card-radius:      20px;
    --login-card-shadow:      0 32px 64px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(0, 0, 0, 0.08);
    --login-glow-color:       rgba(0, 122, 255, 0.18);
    --login-page-bg:          transparent;

    --otp-box-size:           52px;
    --otp-box-radius:         12px;
    --otp-box-border:         1.5px solid var(--color-border);
    --otp-box-border-focus:   1.5px solid var(--color-primary);

    --method-btn-bg:          rgba(255, 255, 255, 0.7);
    --method-btn-border:      rgba(0, 0, 0, 0.09);
    --method-btn-hover-bg:    rgba(0, 122, 255, 0.07);
    --method-btn-hover-border:var(--color-primary);

    --bio-icon-color:         var(--color-primary);
    --bio-ring-color:         rgba(0, 122, 255, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        --login-card-bg:      rgba(28, 28, 30, 0.85);
        --login-card-border:  rgba(255, 255, 255, 0.12);
        --login-card-shadow:  0 32px 64px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.3);
        --login-glow-color:   rgba(0, 122, 255, 0.22);
        --login-page-bg:      transparent;

        --method-btn-bg:      rgba(44, 44, 46, 0.85);
        --method-btn-border:  rgba(255, 255, 255, 0.1);
        --method-btn-hover-bg:rgba(0, 122, 255, 0.12);
    }
}


/* Evita scroll a nivel html/body en la página de login */
html:has(body.login-page) {
    height: 100dvh;
    overflow: hidden;
}

/* Previene doble-tap zoom en toda la página de login */
.login-page,
.login-page button,
.login-page a,
.login-page input {
    touch-action: manipulation;
}

/* Mobile: pseudo-element fixed (iOS no soporta background-attachment:fixed) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image: url('../img/ios.png');
    background-size: cover;
    background-position: center;
}
/* Desktop: wallpaper directo en .login-page — más confiable que body o body::before en PC */
@media (min-width: 768px) {
    body::before {
        content: none;
    }
    .login-page {
        background-image: url('../img/monterrey.png') !important;
        background-size: cover !important;
        background-position: center !important;
        background-attachment: fixed !important;
    }
}

/* ============================================
   PAGE (DESKTOP ≥768px)
   ============================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    background: var(--login-page-bg);
    padding: 16px var(--spacing-lg);
    position: relative;
    overflow: hidden;
}

/* Glow ambiental detrás de la card */
.login-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse 60% 50% at 50% 45%, var(--login-glow-color), transparent 70%);
    opacity: 0.7;
}


/* ============================================
   CARD CONTAINER (DESKTOP)
   ============================================ */
.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;

    /* Glassmorphism transparente — wallpaper visible detrás */
    background: transparent;
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border: 1px solid var(--login-card-border);
    border-radius: var(--login-card-radius);
    box-shadow: var(--login-card-shadow);

    animation: cardAppear 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
    max-height: calc(100dvh - 32px);
    overflow: hidden;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* ============================================
   FASES
   ============================================ */
.login-phase {
    padding: 16px 28px;
    animation: phaseIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.login-phase.hidden {
    display: none !important;
}

@keyframes phaseIn {
    from { opacity: 0; transform: translateX(12px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Fases con back-button necesitan header diferente */
.phase-header {
    margin-bottom: var(--spacing-xl);
    text-align: center;
}


/* ============================================
   HEADER
   ============================================ */
.login-header {
    margin-bottom: 12px;
    text-align: center;
}

/* Logo */
.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    color: var(--color-primary);
}

.login-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    margin-bottom: var(--spacing-xs);
    letter-spacing: -0.4px;
    line-height: 1.2;
}

.login-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: 0;
    font-weight: var(--font-weight-normal);
}

/* Back button */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: var(--spacing-xs) 0;
    margin-bottom: var(--spacing-md);
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: opacity var(--transition-fast);
    text-decoration: none;
}

.btn-back:hover {
    opacity: 0.7;
}

.btn-back:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Phase header layout: back-btn left + title centered */
.phase-header {
    display: grid;
    grid-template-rows: auto auto auto;
    text-align: center;
}

.phase-header .btn-back {
    justify-self: start;
    margin-bottom: var(--spacing-sm);
}

.phase-header .login-title {
    margin-bottom: var(--spacing-xs);
}


/* ============================================
   FORMULARIOS
   ============================================ */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.login-form .form-group {
    margin-bottom: var(--spacing-md);
}

/* Spinner inline dentro del botón */
.spin-svg {
    width: 20px;
    height: 20px;
    animation: spinAnim 0.8s linear infinite;
    display: block;
}

@keyframes spinAnim {
    to { transform: rotate(360deg); }
}

.btn-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}


/* ============================================
   MÉTODOS DE AUTENTICACIÓN
   ============================================ */
.auth-methods {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.auth-method-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-md);
    padding: 14px var(--spacing-lg);
    border: 1px solid var(--method-btn-border);
    border-radius: var(--border-radius-lg);
    background: var(--method-btn-bg);
    text-align: left;
    cursor: pointer;
    transition:
        background var(--transition-base),
        border-color var(--transition-base),
        transform 120ms ease,
        box-shadow var(--transition-base);
    min-height: 64px;
    width: 100%;
}

.auth-method-btn:hover:not(:disabled) {
    background: var(--method-btn-hover-bg);
    border-color: var(--method-btn-hover-border);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.1);
}

.auth-method-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.auth-method-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

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

/* Icono del método */
.method-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 122, 255, 0.1);
    border-radius: 10px;
    color: var(--color-primary);
}

.method-icon-svg {
    width: 22px;
    height: 22px;
}

.method-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.method-name {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    font-size: var(--font-size-base);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.method-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.method-chevron {
    flex-shrink: 0;
    color: var(--color-text-tertiary);
    opacity: 0.6;
}


/* ============================================
   BIOMÉTRICA
   ============================================ */
.biometric-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xl);
    padding-top: var(--spacing-md);
}

/* Visual del ícono */
.biometric-visual {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.biometric-ring {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: var(--bio-ring-color);
    animation: bioRing 2.4s ease-in-out infinite;
}

@keyframes bioRing {
    0%, 100% { transform: scale(0.92); opacity: 0.5; }
    50%       { transform: scale(1.05); opacity: 1; }
}

.biometric-icon {
    position: relative;
    z-index: 1;
    width: 72px;
    height: 72px;
    color: var(--bio-icon-color);
    animation: bioPulse 2.4s ease-in-out infinite;
}

@keyframes bioPulse {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50%       { opacity: 1;    transform: scale(1.04); }
}

/* Línea de scan dentro del SVG */
.biometric-icon.scanning .biometric-scan-line {
    animation: scanLine 1.6s ease-in-out infinite;
    opacity: 1 !important;
}

@keyframes scanLine {
    0%   { transform: translateY(-28px); opacity: 0; }
    15%  { opacity: 1; }
    85%  { opacity: 1; }
    100% { transform: translateY(28px);  opacity: 0; }
}

/* Estado: verificando */
.biometric-icon.verifying {
    animation: bioVerify 0.6s linear infinite;
}

@keyframes bioVerify {
    to { transform: rotate(10deg) scale(1.02); }
}

/* Estado: éxito */
.biometric-icon.success {
    color: var(--color-success);
    animation: bioSuccess 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes bioSuccess {
    to { transform: scale(1.15); }
}

.biometric-instruction {
    text-align: center;
    padding: 0 var(--spacing-md);
}

.biometric-instruction p {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin: 0;
}

/* Status loading */
.biometric-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    text-align: center;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2.5px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spinAnim 0.9s linear infinite;
}

#biometric-status-text {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin: 0;
}


/* ============================================
   OTP — 6 CAJAS INDIVIDUALES
   ============================================ */
.otp-boxes {
    display: flex;
    flex-direction: row;
    gap: 8px;
    justify-content: center;
    margin-top: var(--spacing-sm);
}

.otp-box {
    width: var(--otp-box-size);
    height: var(--otp-box-size);
    border: var(--otp-box-border);
    border-radius: var(--otp-box-radius);
    background: var(--color-background);
    color: var(--color-text);
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    font-family: 'SF Mono', 'Courier New', monospace;
    text-align: center;
    caret-color: var(--color-primary);
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast),
        background var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.otp-box:focus {
    border: var(--otp-box-border-focus);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    background: rgba(0, 122, 255, 0.04);
}

.otp-box.filled {
    border-color: var(--color-primary);
}

.otp-box.error {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
    animation: boxShake 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes boxShake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-4px); }
    40%       { transform: translateX(4px); }
    60%       { transform: translateX(-4px); }
    80%       { transform: translateX(4px); }
}

/* Timer row */
.otp-timer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-background-secondary);
    border-radius: var(--border-radius-md);
    margin: var(--spacing-md) 0;
}

.otp-countdown {
    font-family: 'SF Mono', 'Courier New', monospace;
    font-weight: var(--font-weight-semibold);
    color: var(--color-primary);
    font-size: var(--font-size-sm);
    letter-spacing: 0.5px;
}

.otp-countdown.expiring {
    color: var(--color-danger);
    animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.6; }
}

#otp-resend:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    text-decoration: none;
}

.otp-info {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    margin-top: var(--spacing-sm);
    padding: 0;
}


/* ============================================
   PIN INPUT
   ============================================ */
.pin-input {
    font-family: monospace;
    font-size: var(--font-size-xl);
    letter-spacing: 0.4em;
    text-align: center;
}


/* ============================================
   FOOTER
   ============================================ */
.login-footer {
    margin-top: var(--spacing-md);
    text-align: center;
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--color-border);
}


/* ============================================
   TOAST / NOTIFICACIONES
   ============================================ */
.login-toast {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 9999;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    background: rgba(28, 28, 30, 0.92);
    color: #fff;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.login-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.login-toast.success {
    background: rgba(52, 199, 89, 0.92);
}

.login-toast.error {
    background: rgba(255, 59, 48, 0.92);
}

/* ============================================
   SAFE AREA — todos los tamaños
   ============================================ */
.login-phase {
    padding-top: max(16px, env(safe-area-inset-top, 16px));
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
}

/* ============================================
   ANIMACIONES LANDSCAPE
   ============================================ */
@media (max-height: 600px) and (orientation: landscape) {
    .login-phase {
        padding-top: var(--spacing-lg);
        padding-bottom: var(--spacing-lg);
    }
    .login-header {
        margin-bottom: var(--spacing-md);
    }
    .login-title {
        font-size: var(--font-size-xl);
        margin-bottom: var(--spacing-xs);
    }
    .login-subtitle {
        font-size: var(--font-size-xs);
    }
    .login-logo {
        margin-bottom: var(--spacing-sm);
    }
    .logo-icon {
        width: 40px;
        height: 40px;
    }
    .biometric-visual {
        width: 80px;
        height: 80px;
    }
    .biometric-icon {
        width: 52px;
        height: 52px;
    }
}


/* ============================================
   TABLET (768px – 1023px)
   ============================================ */
@media (min-width: 768px) {
    .login-container {
        min-width: 380px;
    }
}


/* ============================================
   iOS MOBILE (< 768px) — FULL SCREEN NATIVE
   ============================================ */
@media (max-width: 767px) {

    /* Override: full bleed, fondo transparente para ver wallpaper */
    .login-page {
        align-items: flex-start;
        justify-content: flex-start;
        background: transparent !important;
        padding: 0;
        height: 100dvh;
        overflow: hidden;
    }

    /* Sin glow en mobile */
    .login-glow {
        display: none;
    }

    /* Card ocupa pantalla completa */
    .login-container {
        max-width: 100%;
        width: 100%;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: transparent;
        animation: none;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Cada fase = pantalla completa, centrada verticalmente */
    .login-phase {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 0 28px;
        padding-top: max(40px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        box-sizing: border-box;
        overflow-y: auto;
    }

    /* Override dark card color → negro puro */
    .login-container,
    .login-page {
        --login-card-bg: #000000;
        --method-btn-bg: rgba(28, 28, 30, 0.95);
        --method-btn-border: rgba(255, 255, 255, 0.12);
    }

    /* Texto blanco sobre negro */
    .login-title {
        color: #ffffff;
        font-size: 28px;
        font-weight: 700;
        letter-spacing: -0.5px;
    }

    .login-subtitle {
        color: rgba(255, 255, 255, 0.55);
    }

    .form-label {
        color: rgba(255, 255, 255, 0.7);
    }

    .form-hint {
        color: rgba(255, 255, 255, 0.4);
    }

    .method-name {
        color: #ffffff;
    }

    .method-hint {
        color: rgba(255, 255, 255, 0.5);
    }

    /* Inputs: fondo oscuro iOS — font-size 16px evita el auto-zoom de Safari */
    .form-input {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
        color: #ffffff;
        min-height: 52px;
        border-radius: 12px;
        font-size: 16px !important;
        -webkit-appearance: none;
    }

    .form-input::placeholder {
        color: rgba(255, 255, 255, 0.3);
    }

    .form-input:focus {
        border-color: var(--color-primary);
        background: rgba(255, 255, 255, 0.1);
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    }

    /* Botón principal: tamaño mínimo 52px */
    .btn-lg {
        min-height: 52px;
        border-radius: 14px;
        font-size: var(--font-size-base);
    }

    /* Login header */
    .login-header {
        margin-bottom: 12px;
    }

    /* Logo */
    .logo-icon {
        width: 44px;
        height: 44px;
    }

    /* Auth method buttons: touch targets */
    .auth-method-btn {
        min-height: 58px;
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.1);
        border-radius: 14px;
    }

    .auth-method-btn:hover:not(:disabled) {
        background: rgba(0, 122, 255, 0.15);
        border-color: var(--color-primary);
    }

    .auth-methods {
        gap: 6px;
        margin-bottom: 10px;
    }

    /* OTP boxes — 6 en una fila en 375px */
    .otp-boxes {
        gap: 6px;
    }

    .otp-box {
        --otp-box-size: 44px;
        width: 44px;
        height: 44px;
        border-radius: 10px;
        font-size: 20px !important;
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
        color: #ffffff;
        appearance: none;
        -webkit-appearance: none;
    }

    .otp-box:focus {
        background: rgba(0, 122, 255, 0.12);
        border-color: var(--color-primary);
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    }

    .otp-box.filled {
        background: rgba(0, 122, 255, 0.1);
    }

    /* Timer row en mobile */
    .otp-timer-row {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 10px;
    }

    .otp-countdown {
        color: var(--color-primary);
    }

    .otp-info {
        color: rgba(255, 255, 255, 0.35);
    }

    /* Biométrica: más compacto */
    .biometric-visual {
        width: 100px;
        height: 100px;
    }

    .biometric-icon {
        width: 60px;
        height: 60px;
    }

    .biometric-instruction p {
        color: rgba(255, 255, 255, 0.6);
    }

    #biometric-status-text {
        color: rgba(255, 255, 255, 0.55);
    }

    /* Back button */
    .btn-back {
        color: var(--color-primary);
        padding: 8px 0;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Footer */
    .login-footer {
        border-top-color: rgba(255, 255, 255, 0.1);
        margin-top: var(--spacing-lg);
        padding-top: var(--spacing-md);
    }

    /* Error messages */
    .error-message {
        background: rgba(255, 59, 48, 0.12);
        border-left-color: var(--color-danger);
        color: #ff6961;
    }

    /* PIN input */
    .pin-input {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
        color: #ffffff;
        font-size: 16px !important;
    }
}


/* ============================================
   iPhone 13 mini (375px) — ajustes finos
   ============================================ */
@media (max-width: 390px) {
    .login-phase {
        padding-left: 20px;
        padding-right: 20px;
        padding-top: max(36px, env(safe-area-inset-top));
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .login-header {
        margin-bottom: 8px;
    }

    .otp-boxes {
        gap: 5px;
    }

    .otp-box {
        width: 40px;
        height: 44px;
        font-size: var(--font-size-base);
    }

    .login-title {
        font-size: 24px;
    }

    .auth-method-btn {
        padding: 10px var(--spacing-sm);
        min-height: 52px;
    }

    .method-name {
        font-size: 14px;
    }

    .method-hint {
        font-size: 11px;
    }

    .auth-methods {
        gap: 4px;
        margin-bottom: 8px;
    }
}
