/**
 * Auth Pages Styles
 * Shared styles for authentication pages: login, register, forgot-password, reset-password
 * Load order: base.css (optional), auth.css, Google Fonts
 */

/* CSS Reset - included here since auth pages don't load base.css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ========================================
   Auth Checking State - Hide content until auth is determined
   Prevents flash of login form for already-authenticated users
   ======================================== */
/* Auth reveal - instant transition to prevent stutter when auth completes */
.brand-panel,
.login-panel,
.register-panel,
.forgot-panel,
.reset-panel {
    /* No transition - show immediately when auth-checking is removed */
}

body.auth-checking .brand-panel,
body.auth-checking .login-panel,
body.auth-checking .register-panel,
body.auth-checking .forgot-panel,
body.auth-checking .reset-panel {
    opacity: 0;
    visibility: hidden;
}

body.auth-checking::after {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: auth-spinner 0.8s linear infinite;
}

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

/* Auth page body */
body.page--login,
body.page--register,
body.page--forgot-password,
body.page--reset-password {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    display: flex;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    overflow: hidden;
}

/* ========================================
   Left Panel - Branding
   ======================================== */
.brand-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 60px;
    position: relative;
    overflow: hidden;
}

.brand-panel::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 70%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 70% 30%, rgba(16, 185, 129, 0.08) 0%, transparent 50%);
    animation: auth-pulse 15s ease-in-out infinite;
}

@keyframes auth-pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.brand-content {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 500px;
}

.brand-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}

.brand-logo {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #3b82f6 0%, #10b981 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 40px rgba(59, 130, 246, 0.3);
    flex-shrink: 0;
}

.brand-logo svg {
    width: 44px;
    height: 44px;
    fill: white;
}

.brand-title {
    font-size: 5rem;
    font-weight: 700;
    color: white;
    margin: 0;
    letter-spacing: -0.02em;
    text-align: left;
}

.brand-tagline {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--accent-primary, #60a5fa);
    margin-bottom: 12px;
    letter-spacing: 0.02em;
}

.brand-subtitle {
    font-size: 1.125rem;
    color: var(--text-muted, #94a3b8);
    line-height: 1.6;
    margin-bottom: 48px;
}

.brand-features {
    display: inline-flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary, #cbd5e1);
    font-size: 0.95rem;
}

.feature-icon {
    width: 20px;
    height: 20px;
    fill: var(--color-success, #10b981);
    flex-shrink: 0;
}

/* ========================================
   Right Panel - Form Container
   ======================================== */
.login-panel,
.register-panel,
.form-panel {
    flex: 0 0 45%;
    min-width: 320px;
    max-width: 520px;
    min-height: 100vh;
    background: var(--bg-primary, white);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px;
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.3);
}

.register-panel {
    flex: 0 0 48%;
    max-width: 560px;
    padding: 32px 40px;
    overflow-y: auto;
}

/* ========================================
   Form Headers
   ======================================== */
.login-header,
.register-header,
.form-header {
    margin-bottom: 40px;
}

.register-header,
.form-header {
    margin-bottom: 32px;
}

.login-header h1,
.register-header h1,
.form-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    margin-bottom: 8px;
}

.form-header h1 {
    margin-bottom: 12px;
}

.login-header p,
.register-header p,
.form-header p {
    color: var(--text-muted, #64748b);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* ========================================
   Form Styles
   ======================================== */
.login-form,
.register-form,
.reset-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.register-form {
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.register-form .form-group {
    gap: 6px;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary, #374151);
}

.form-group input {
    padding: 14px 16px;
    border: 2px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: var(--bg-secondary, #f9fafb);
    color: var(--text-primary, #0f172a);
}

.register-form .form-group input {
    padding: 12px 14px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color, #3b82f6);
    background: var(--bg-primary, white);
    box-shadow: 0 0 0 4px var(--color-info-bg-light, rgba(59, 130, 246, 0.1));
}

.form-group input::placeholder {
    color: var(--text-placeholder, #9ca3af);
}

.tos-group {
    margin-top: 12px;
}

.tos-group .checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-primary, #0f172a);
}

.tos-group .checkbox-label input {
    margin-top: 4px;
    flex-shrink: 0;
}

.tos-group .checkbox-text a {
    color: var(--primary-color, #60a5fa);
    text-decoration: underline;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted, #6b7280);
    margin-top: 2px;
}

/* ========================================
   Password Requirements
   ======================================== */
.password-requirements {
    background: var(--bg-secondary, #f8fafc);
    padding: 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color, #e2e8f0);
}

.password-requirements h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary, #475569);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.requirement {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 6px;
}

.requirement:last-child {
    margin-bottom: 0;
}

.requirement-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary, #e2e8f0);
    flex-shrink: 0;
}

.requirement-icon svg {
    width: 10px;
    height: 10px;
    stroke: var(--text-placeholder, #94a3b8);
}

.requirement.met .requirement-icon {
    background: var(--color-success, #10b981);
}

.requirement.met .requirement-icon svg {
    stroke: white;
}

.requirement.met {
    color: var(--color-success, #059669);
}

/* ========================================
   Buttons
   ======================================== */
.btn-primary {
    padding: 16px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    margin-top: 8px;
}

.register-form .btn-primary {
    padding: 14px 24px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading state */
.btn-primary.loading {
    position: relative;
    color: transparent;
}

.btn-primary.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: auth-spin 0.8s linear infinite;
    left: 50%;
    top: 50%;
    margin-left: -10px;
    margin-top: -10px;
}

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

/* ========================================
   Links and Footer
   ======================================== */
.link-button {
    background: none;
    border: none;
    color: var(--primary-color, #3b82f6);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s ease;
}

.link-button:hover {
    color: var(--primary-color-hover, #1d4ed8);
    text-decoration: underline;
}

.login-footer,
.register-footer,
.form-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

.register-footer {
    padding-top: 20px;
}

.login-footer span {
    color: var(--text-placeholder, #d1d5db);
}

/* ========================================
   Error and Success Messages
   ======================================== */
.error-text {
    background: var(--color-danger-bg-light, #fef2f2);
    color: var(--color-danger, #dc2626);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    border: 1px solid var(--color-danger-border, #fecaca);
}

/* For pages using display toggle */
.error-text:not(.visible) {
    display: none;
}

.success-message {
    background: var(--color-success-bg-light, #f0fdf4);
    color: var(--color-success-dark, #166534);
    padding: 32px;
    border-radius: 12px;
    font-size: 0.95rem;
    border: 1px solid var(--color-success-border, #bbf7d0);
    text-align: center;
    display: none;
    max-width: 400px;
    margin: 0 auto;
}

.success-message.visible {
    display: block;
}

.success-message h3 {
    font-size: 1.25rem;
    margin-bottom: 12px;
    color: var(--color-success-darker, #14532d);
    font-weight: 600;
}

.success-message p {
    color: var(--color-success-dark, #166534);
    line-height: 1.6;
    margin-bottom: 24px;
}

.success-message .btn-primary {
    display: inline-block;
    text-decoration: none;
    margin-top: 0;
}

/* Reset password specific */
.invalid-token {
    background: var(--color-danger-bg-light, #fef2f2);
    padding: 24px;
    border-radius: 10px;
    border: 1px solid var(--color-danger-border, #fecaca);
    text-align: center;
    display: none;
}

.invalid-token.visible {
    display: block;
}

.invalid-token h3 {
    font-size: 1.25rem;
    margin-bottom: 12px;
    color: var(--color-danger-dark, #991b1b);
}

.invalid-token p {
    color: var(--color-danger, #dc2626);
    line-height: 1.5;
    margin-bottom: 20px;
}

.invalid-token .link-button {
    display: inline-block;
}

.loading-state {
    text-align: center;
    padding: 40px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color, #e5e7eb);
    border-top-color: var(--primary-color, #3b82f6);
    border-radius: 50%;
    animation: auth-spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

.loading-state p {
    color: var(--text-muted, #64748b);
    font-size: 0.95rem;
}

/* ========================================
   Modal (Org Selection)
   ======================================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--bg-primary, white);
    border-radius: 16px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(0, 0, 0, 0.3));
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    margin-bottom: 8px;
}

.modal-subtitle {
    color: var(--text-muted, #64748b);
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.modal-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-list button {
    padding: 12px 16px;
    border: 2px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    background: var(--bg-primary, white);
    color: var(--text-primary, #0f172a);
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.modal-list button:hover {
    border-color: var(--primary-color, #3b82f6);
    background: var(--color-info-bg-light, #f0f9ff);
}

/* ========================================
   Emulator Notice
   ======================================== */
.emulator-notice {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-warning-bg-light, #fef3c7);
    color: var(--color-warning-dark, #92400e);
    padding: 8px 16px;
    font-size: 0.75rem;
    text-align: center;
}

/* ========================================
   Invite States
   ======================================== */
.invite-state {
    text-align: center;
    padding: 20px 0;
}

.invite-state .loading-spinner {
    margin: 30px auto;
}

.invite-state.is-hidden {
    display: none;
}

/* ========================================
   Utilities
   ======================================== */
.is-hidden {
    display: none;
}

/* ========================================
   Responsive - Both panels always visible
   ======================================== */
@media (max-width: 900px) {
    .brand-panel {
        padding: 32px;
    }

    .brand-title {
        font-size: 3.5rem;
    }

    .brand-tagline {
        font-size: 1.1rem;
    }

    .brand-subtitle {
        font-size: 1rem;
        margin-bottom: 32px;
    }

    .brand-logo {
        width: 70px;
        height: 70px;
    }

    .brand-logo svg {
        width: 38px;
        height: 38px;
    }

    .feature-item {
        font-size: 0.85rem;
    }

    .login-panel,
    .register-panel,
    .form-panel {
        padding: 32px 24px;
    }

    .login-header h1,
    .register-header h1,
    .form-header h1 {
        font-size: 1.5rem;
    }

    .form-group input {
        padding: 12px 14px;
    }

    .btn-primary {
        padding: 14px 20px;
    }
}

@media (max-width: 700px) {
    .brand-panel {
        padding: 24px;
    }

    .brand-title {
        font-size: 2.5rem;
    }

    .brand-tagline {
        font-size: 1rem;
    }

    .brand-subtitle {
        font-size: 0.875rem;
        margin-bottom: 24px;
    }

    .brand-logo {
        width: 60px;
        height: 60px;
    }

    .brand-logo svg {
        width: 32px;
        height: 32px;
    }

    .brand-features {
        gap: 12px;
    }

    .feature-item {
        font-size: 0.8rem;
        gap: 8px;
    }

    .feature-icon {
        width: 16px;
        height: 16px;
    }

    .login-panel,
    .register-panel,
    .form-panel {
        padding: 24px 20px;
    }

    .login-header h1,
    .register-header h1,
    .form-header h1 {
        font-size: 1.25rem;
    }

    .form-group input {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .btn-primary {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
}

/* ========================================
   MOBILE RESPONSIVE - SINGLE COLUMN LAYOUT
   Stack panels vertically, hide branding on mobile
   ======================================== */

@media (max-width: 768px) {
    /* Stack panels vertically */
    body.page--login,
    body.page--register,
    body.page--forgot-password,
    body.page--reset-password {
        flex-direction: column;
        overflow-y: auto;
        min-height: 100vh;
        /* iOS 100vh fix */
        min-height: calc(var(--vh, 1vh) * 100);
    }

    /* Hide branding panel on mobile */
    .brand-panel {
        display: none;
    }

    /* Form panel takes full width */
    .login-panel,
    .register-panel,
    .form-panel {
        flex: 1;
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
        padding: 2rem 1.5rem;
        box-shadow: none;
    }

    .register-panel {
        padding: 1.5rem 1.25rem;
    }

    /* Reduce header sizes */
    .login-header,
    .register-header,
    .form-header {
        margin-bottom: 2rem;
    }

    .login-header h1,
    .register-header h1,
    .form-header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .login-header p,
    .register-header p,
    .form-header p {
        font-size: 0.95rem;
    }

    /* Form adjustments - iOS zoom prevention */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents iOS auto-zoom */
        min-height: 48px;
        padding: 0.875rem 1rem;
    }

    /* Touch-friendly buttons */
    .btn-primary {
        min-height: 48px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    /* Touch-friendly links */
    .link-button {
        min-height: 44px;
        padding: 0.75rem;
        display: inline-flex;
        align-items: center;
    }

    /* Footer adjustments */
    .login-footer,
    .register-footer,
    .form-footer {
        flex-direction: column;
        gap: 1rem;
        padding-top: 1.5rem;
    }

    .login-footer span {
        display: none;
    }

    /* Form row - stack on mobile */
    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Password requirements */
    .password-requirements {
        padding: 1rem;
    }

    .password-requirements h4 {
        font-size: 0.75rem;
    }

    .requirement {
        font-size: 0.8rem;
    }

    /* Modal full-screen on mobile */
    .modal-overlay.visible {
        align-items: flex-end;
    }

    .modal {
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 1.5rem;
        max-height: 80vh;
        overflow-y: auto;
    }

    /* TOS checkbox - larger touch target */
    .tos-group .checkbox-label {
        min-height: 44px;
        padding: 0.5rem 0;
    }

    .tos-group .checkbox-label input {
        width: 22px;
        height: 22px;
        margin-top: 2px;
    }

    /* Error messages */
    .error-text {
        padding: 1rem;
        font-size: 0.875rem;
    }

    /* Success message */
    .success-message {
        padding: 1.5rem;
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .login-panel,
    .register-panel,
    .form-panel {
        padding: 1.5rem 1rem;
    }

    .login-header h1,
    .register-header h1,
    .form-header h1 {
        font-size: 1.375rem;
    }

    .login-header,
    .register-header,
    .form-header {
        margin-bottom: 1.5rem;
    }

    .login-form,
    .register-form,
    .reset-form {
        gap: 1.25rem;
    }

    .modal {
        padding: 1.25rem;
    }
}

/* ========================================
   ACCESSIBILITY - Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .brand-panel::before {
        animation: none;
    }

    .btn-primary.loading::after {
        animation: none;
    }

    .loading-spinner {
        animation: none;
    }

    .btn-primary:hover {
        transform: none;
    }
}
