/**
 * Mobile Auth CSS
 *
 * Optimizes login, signup, and auth modals for mobile:
 * - Full-screen modals on mobile
 * - 16px font inputs to prevent iOS zoom
 * - 48px minimum touch targets
 * - Safe area padding for notched phones
 */

/* ==========================================================================
   Auth Modal - Full Screen on Mobile
   ========================================================================== */

@media (max-width: 768px) {
    /* Make auth modal full screen */
    #authModal .modal-content {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100% !important;
        width: 100% !important;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
        padding-top: calc(20px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Hide overlay on mobile - full screen modal */
    #authModal .modal-overlay {
        display: none;
    }

    /* Larger close button */
    #authModal .modal-close,
    .auth-modal .modal-close {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        font-size: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        z-index: var(--z-dropdown, 100);
    }

    /* Adjust top padding for close button */
    #authModal .modal-content > div:first-of-type,
    #loginForm,
    #signupForm,
    #forgotPasswordForm {
        padding-top: 40px;
    }
}

/* ==========================================================================
   Auth Form Inputs - Mobile Optimized
   ========================================================================== */

@media (max-width: 768px) {
    /* Prevent iOS zoom on focus - must be 16px minimum */
    /* ET-26428 (2026-09-22): this rule is for TEXT inputs. Applied to the
       consent checkboxes it stripped their native appearance and stretched
       them to 145x44 with 14px padding, so on iOS the box drew nothing and
       a tap toggled an invisible state: "the checkboxes are not working". */
    .terminal-input,
    .terminal-form input:not([type="checkbox"]):not([type="radio"]),
    .auth-form input:not([type="checkbox"]):not([type="radio"]),
    #authModal input:not([type="checkbox"]):not([type="radio"]),
    .form-group input:not([type="checkbox"]):not([type="radio"]) {
        font-size: 16px !important;
        min-height: 48px;
        padding: 14px 16px;
        border-radius: var(--panel-radius);
        -webkit-appearance: none;
        appearance: none;
        width: 100%;
        box-sizing: border-box;
        max-width: 100%;
    }

    /* Checkboxes keep the platform's native control: a 22px box the OS draws
       (accent-color from the markup), no padding, no stretch. The label that
       wraps each one is the 44px touch target. */
    .terminal-form input[type="checkbox"],
    .auth-form input[type="checkbox"],
    #authModal input[type="checkbox"],
    .form-group input[type="checkbox"] {
        -webkit-appearance: checkbox;
        appearance: auto;
        width: 22px;
        height: 22px;
        min-width: 22px;
        min-height: 22px;
        max-width: 22px;
        padding: 0;
        margin: 2px 0 0;
        flex-shrink: 0;
        border-radius: 4px;
    }

    /* Form labels */
    .form-label,
    .form-group label {
        font-size: 13px;
        margin-bottom: 8px;
    }

    /* Form groups */
    .form-group {
        margin-bottom: 16px;
    }

    /* Full width form on mobile */
    .terminal-form,
    .auth-form {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================================================
   Auth Buttons - Touch Target Sizes
   ========================================================================== */

@media (max-width: 768px) {
    /* Primary auth buttons */
    .terminal-btn,
    .auth-btn,
    #authModal button[type="submit"],
    .wallet-btn {
        min-height: 52px;
        font-size: 15px;
        font-weight: 600;
        padding: 14px 24px;
        border-radius: var(--panel-radius);
        width: 100%;
        box-sizing: border-box;
        max-width: 100%;
    }

    /* Button active state feedback */
    .terminal-btn:active,
    .auth-btn:active,
    .wallet-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* Link buttons - increase touch area */
    #switchToSignup,
    #switchToLogin,
    #switchToForgot,
    #backToLogin,
    .auth-links a {
        display: inline-block;
        padding: 12px 16px;
        margin: -12px -16px;
        min-height: 44px;
        line-height: 20px;
    }

    /* Forgot password link */
    a[href="/forgot-password"] {
        display: inline-block;
        padding: 12px;
        min-height: 44px;
    }
}

/* ==========================================================================
   Auth Page (login.html, signup.html) - Mobile Layout
   ========================================================================== */

@media (max-width: 768px) {
    .auth-container {
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        min-height: 100vh;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }

    .auth-card {
        padding: 24px 20px;
        border-radius: 20px;
        max-width: 100%;
        width: 100%;
    }

    .auth-logo {
        margin-bottom: 24px;
    }

    .auth-logo a {
        font-size: 20px;
    }

    .auth-title {
        font-size: 18px;
        margin-bottom: 24px;
    }

    .auth-form {
        gap: 16px;
    }

    .auth-divider {
        margin: 16px 0;
    }

    .auth-links {
        margin-top: 20px;
        font-size: 14px;
        padding: 8px 0;
    }

    /* Error/Success messages */
    .error-message,
    .success-message {
        padding: 14px;
        font-size: 14px;
        border-radius: 10px;
        margin-bottom: 16px;
    }
}

/* ==========================================================================
   Password Visibility Toggle
   ========================================================================== */

@media (max-width: 768px) {
    .password-toggle {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: rgba(255, 255, 255, 0.5);
        cursor: pointer;
    }

    .form-group.password-field {
        position: relative;
    }

    .form-group.password-field input {
        padding-right: 56px;
    }
}

/* ==========================================================================
   Social/Wallet Login Buttons
   ========================================================================== */

@media (max-width: 768px) {
    .wallet-btn,
    .social-login-btn {
        min-height: 52px;
        padding: 14px 20px;
        font-size: 15px;
        gap: 12px;
        border-radius: var(--panel-radius);
    }

    .wallet-btn svg,
    .social-login-btn svg,
    .wallet-btn img,
    .social-login-btn img {
        width: 24px;
        height: 24px;
    }
}

/* ==========================================================================
   Keyboard Handling
   ========================================================================== */

@media (max-width: 768px) {
    /* The card is scrolled into view by the browser on focus (scroll-margin
       below). NEVER re-lay the container out while an input is focused
       (the old focus-time padding/justify rule on this container): on
       a phone the tap on "Sign In" blurs the field first, the card jumped
       24px up before the click landed, and the tap hit the card beside the
       button - no request was sent at any width <= 480px (2026-10-21,
       ET-32214). Pinned by tests/test_auth_mobile_no_focus_layout_shift.py. */
    .auth-card {
        scroll-margin-top: 20px;
    }
}

/* ==========================================================================
   Loading States
   ========================================================================== */

@media (max-width: 768px) {
    .auth-btn:disabled,
    .terminal-btn:disabled {
        opacity: 0.7;
    }

    .auth-btn.loading,
    .terminal-btn.loading {
        position: relative;
        color: transparent;
    }

    .auth-btn.loading::after,
    .terminal-btn.loading::after {
        content: '';
        position: absolute;
        width: 20px;
        height: 20px;
        top: 50%;
        left: 50%;
        margin: -10px 0 0 -10px;
        border: 2px solid rgba(255, 255, 255, 0.3);
        border-top-color: var(--text-heading, #ffffff);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

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

/* ==========================================================================
   Signup Form Specific
   ========================================================================== */

@media (max-width: 768px) {
    /* Password strength indicator */
    .password-strength {
        margin-top: 8px;
        font-size: 12px;
    }

    .password-strength-bar {
        height: 4px;
        border-radius: 2px;
        margin-top: 4px;
    }

    /* Terms checkbox */
    .terms-checkbox {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        padding: 12px 0;
    }

    .terms-checkbox input[type="checkbox"] {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        margin: 0;
        flex-shrink: 0;
    }

    .terms-checkbox label {
        font-size: 13px;
        line-height: 1.5;
        padding-top: 2px;
    }
}

/* ==========================================================================
   Accessibility - Focus States
   ========================================================================== */

@media (max-width: 768px) {
    /* Clear focus indicators for touch */
    .auth-form input:focus,
    .terminal-form input:focus,
    #authModal input:focus {
        outline: none;
        border-color: var(--accent-cyan, #00cfff);
        box-shadow: 0 0 0 3px rgba(0, 207, 255, 0.2);
    }

    /* Button focus */
    .auth-btn:focus,
    .terminal-btn:focus,
    .wallet-btn:focus {
        outline: none;
        box-shadow: 0 0 0 3px rgba(0, 207, 255, 0.3);
    }
}



/* ============================================ */
/* MOBILE FIXES (Auto-generated)               */
/* ============================================ */


/* Fix: ISSUE-001 - Login Button Touch Target Too Small
 * Ensure touch target meets iOS HIG minimum (44x44px)
 */
@media (max-width: 768px) {
    button[type="submit"], .login-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 12px;
        /* Ensure clickable area is large enough */
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

button[type="submit"], .login-btn { cursor: pointer; }



/* ============================================ */
/* MOBILE FIXES (Auto-generated)               */
/* ============================================ */


/* Fix: ISSUE-002 - Email Input Font Size Causes iOS Zoom
 * Prevent iOS zoom on input focus (min 16px font)
 */
@media (max-width: 768px) {
    input[type="email"], input[type="password"] {
        font-size: 16px !important;
        /* Prevent iOS zoom */
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
}

