/* MyFoodApp - Authentication & Form Validation Styles */
/* Consolidated: auth.css + validation.css */
/* Created: Asset Consolidation Phase */

/* ===================================
   AUTHENTICATION PAGES
   =================================== */

/* Single-page auth design - but keep main header */
.auth-page {
    overflow-x: hidden; /* Prevent horizontal scroll */
    /* Keep the normal body padding for header */
}

/* Keep the main header visible on auth pages */
/* Remove the header hiding rules */

/* Remove any header-related spacing */
.auth-page * {
    box-sizing: border-box;
}

.auth-container {
    min-height: calc(100vh - 90px); /* Account for header height */
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); /* Beautiful gradient background */
    padding: 2rem 1rem; /* More top/bottom padding to account for header */
    /* Remove overflow hidden to allow scrolling if needed */
}

.auth-card {
    background: white;
    padding: 2rem; /* Restore normal padding */
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px; /* Smaller for mobile-first */
    text-align: center;
    position: relative;
    z-index: 10; /* Above header */
}

/* Remove auth card header and body sections - use simple card */
.auth-title {
    font-family: 'Montserrat', sans-serif; /* Match main site header font */
    color: #333; /* Dark text on white background */
    margin-bottom: 0.5rem;
    font-size: 2rem;
    font-weight: 700;
}

.auth-subtitle {
    font-family: 'Open Sans', sans-serif; /* Match main site body font */
    color: #666; /* Gray text */
    margin-bottom: 2rem;
    font-size: 1rem;
}

.auth-logo {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.auth-form {
    text-align: left;
}

/* ===================================
   FORM COMPONENTS - AUTH OVERRIDES
   =================================== */

/* Note: These components extend the base definitions from app-core.css */
/* Intentional overrides for authentication-specific styling */

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #333;
    font-weight: 600;
    font-family: 'Open Sans', sans-serif; /* Match main site font */
}

.relative-container {
    position: relative;
    display: block;
    overflow: visible; /* Ensure nothing gets clipped */
    isolation: isolate; /* Create new stacking context to prevent icon bleeding */
    /* Ensure stable positioning for icons */
    min-height: 48px; /* Match input field height */
    /* Prevent height changes that can affect icon positioning */
    height: auto;
    /* Force stable container behavior */
    box-sizing: border-box;
}

/* Auth forms - scoped to prevent conflicts with core/admin */
.auth-form .form-control,
.auth-container .form-control {
    width: 100%;
    padding: 14px 20px 14px 55px; /* Increased left padding for better icon spacing */
    border: 2px solid #e1e5e9;
    border-radius: 12px;
    font-size: 16px; /* Prevent zoom on iOS */
    font-family: 'Open Sans', sans-serif;
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.2s;
    box-sizing: border-box;
    -webkit-appearance: none; /* Remove iOS styling */
    -moz-appearance: none; /* Remove Firefox styling */
    appearance: none;
    position: relative;
    z-index: 1;
}

/* Ensure password fields have consistent padding */
.auth-form input[type="password"].form-control,
.auth-container input[type="password"].form-control {
    padding: 14px 20px 14px 55px !important;
}

.auth-form .form-control:focus,
.auth-container .form-control:focus {
    border-color: #2c2c2c;
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 44, 44, 0.1);
    transform: translateY(-1px); /* Subtle lift effect */
}

/* Consolidated form icon positioning rule */
.form-icon {
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    bottom: auto !important; /* Prevent bottom conflicts */
    transform: translateY(-50%) !important;
    color: #999;
    font-size: 1.1rem;
    pointer-events: none !important;
    z-index: 10 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 20px !important;
    height: 20px !important;
    line-height: 1 !important;
    /* Prevent JavaScript interference */
    transition: none !important;
}

/* Ensure consistent icon positioning across all form contexts */
.auth-form .form-icon,
.auth-container .form-icon,
.form-row .form-icon,
.relative-container .form-icon {
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
    pointer-events: none !important;
    /* Ensure consistent emoji rendering */
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    text-align: center;
    vertical-align: middle;
}

/* Specific fix for password field icons in form rows */
.form-row .form-group .relative-container .form-icon {
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 999 !important;
}

/* Ultra-specific fix for register.php password field icon positioning */
.auth-form .form-row .form-group:first-child .relative-container .form-icon,
.auth-form .form-row .form-group input[type="password"] + .form-icon,
.auth-form input#password ~ .form-icon,
input[name="password"] + .form-icon,
input[id="password"] + .form-icon {
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    bottom: auto !important; /* Force bottom to auto to prevent conflicts */
    transform: translateY(-50%) !important;
    z-index: 1000 !important;
    pointer-events: none !important;
    /* Ensure icon stays perfectly aligned regardless of dynamic content */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 20px !important;
    height: 20px !important;
    line-height: 1 !important;
    /* Prevent any JavaScript from overriding these styles */
    transition: none !important;
}

/* Force padding for password fields */
.auth-form input[type="password"]#password,
.auth-form input[name="password"] {
    padding-left: 55px !important;
}

/* Override any JavaScript-applied styles */
.auth-form .form-icon[style],
.auth-container .form-icon[style],
.form-row .form-icon[style],
.relative-container .form-icon[style] {
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    z-index: 1000 !important;
    /* Force override any inline styles set by JavaScript */
    transition: none !important;
    width: 20px !important;
    height: 20px !important;
    line-height: 1 !important;
}

/* Browser-specific fixes for emoji positioning */
.form-icon {
    -webkit-font-feature-settings: "liga" off;
    font-feature-settings: "liga" off;
    font-variant-ligatures: none;
    text-rendering: optimizeLegibility;
    /* CRITICAL: Lock position to prevent JavaScript interference */
    position: absolute !important;
    left: 16px !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    /* Create a new stacking context to prevent interference */
    contain: layout style;
}

.btn-auth {
    width: 100%;
    padding: 16px 40px;
    background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    color: white;
    border: none;
    border-radius: 25px; /* Fully rounded for modern look */
    font-size: 16px; /* Prevent zoom on iOS */
    font-weight: 600;
    font-family: 'Open Sans', sans-serif;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    position: relative;
    overflow: hidden;
    min-height: 48px; /* Minimum touch target for mobile */
    -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight */
}

.btn-auth::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.btn-auth:hover::before {
    left: 100%;
}

.btn-auth:hover {
        padding-left: 55px !important;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    background: linear-gradient(135deg, #1a1a1a 0%, #000000 100%);
}

.btn-auth:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Custom Checkbox Styling for Remember Me */
.checkbox-container {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 1rem 0;
    padding: 0.5rem 0;
}

.checkbox-container input[type="checkbox"] {
    display: none; /* Hide the default checkbox */
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    font-family: 'Open Sans', sans-serif;
    user-select: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: transparent;
    background: white;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.checkbox-container input[type="checkbox"]:checked + .checkbox-label .checkmark {
    background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    border-color: #2c2c2c;
    color: white;
    transform: scale(1.1);
}

.checkbox-container input[type="checkbox"]:checked + .checkbox-label .checkmark::before {
    content: '✓';
}

.checkbox-label:hover .checkmark {
    border-color: #2c2c2c;
    transform: scale(1.05);
}

/* Mobile-specific touch feedback */
@media (hover: none) and (pointer: coarse) {
    .btn-auth:hover {
        transform: none; /* Disable hover effects on touch devices */
    }
    
    .btn-auth:active {
        transform: scale(0.98);
        background: linear-gradient(135deg, #1a1a1a 0%, #000000 100%);
    }
}

/* Tablet and large mobile devices - stack password fields */
@media (max-width: 768px) {
    /* Ensure password fields stack vertically on tablets and mobile */
    .form-row {
        display: block !important;
    }
    
    .form-row .form-group {
        width: 100% !important;
        float: none !important;
        margin-right: 0 !important;
        margin-bottom: 1rem !important;
    }
    
    /* Ensure all form controls are properly sized */
    .form-control {
        width: 100%;
        box-sizing: border-box;
    }
}

/* Mobile-specific form improvements */
@media (max-width: 480px) {
    /* Prevent iOS zoom on input focus */
    .form-control {
        font-size: 16px !important;
        line-height: 1.5;
    }
    
    /* Improve touch targets for mobile */
    .form-control, .btn-auth {
        min-height: 48px; /* iOS and Android recommended minimum */
        border-radius: 8px;
    }
    
    /* Better spacing for thumb navigation */
    .form-group {
        margin-bottom: 20px;
    }
    
    /* Ensure password fields stack vertically and are full-width */
    .form-group {
        width: 100%;
        display: block;
    }
    
    /* Remove any form-row effects on mobile */
    .form-row {
        display: block !important;
        width: 100% !important;
    }
    
    .form-row .form-group {
        width: 100% !important;
        float: none !important;
        margin-right: 0 !important;
        margin-bottom: 1rem !important;
    }
    
    /* Ensure relative containers are full-width */
    .relative-container {
        position: relative;
        width: 100%;
        display: block;
    }
    
    /* Optimize checkbox and radio for touch */
    input[type="checkbox"], input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
        margin-right: 12px;
    }
    
    /* Better link targets for mobile */
    .auth-links a {
        padding: 10px 5px;
        display: inline-block;
        min-height: 44px;
        line-height: 1.4;
    }
}

.auth-links {
    text-align: center;
    margin-top: 2rem;
}

.auth-links a {
    color: #2c2c2c; /* Match main site dark theme */
    text-decoration: none;
    font-weight: 600;
    font-family: 'Open Sans', sans-serif; /* Match main site font */
    transition: all 0.3s ease;
}

.auth-links a:hover {
    color: #1a1a1a; /* Match main site dark hover */
}

.divider {
    margin: 1.5rem 0;
    text-align: center;
    position: relative;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e1e5e9;
}

.divider span {
    background: white;
    padding: 0 1rem;
    color: #666;
}

/* ===================================
   ALERT COMPONENTS - AUTH OVERRIDES
   =================================== */

/* Note: Alert base styles from app-core.css with auth-specific modifications */
.alert {
    padding: 1rem;
    border-radius: 10px; /* AUTH OVERRIDE: Matches form border-radius */
    margin-bottom: 1.5rem; /* AUTH OVERRIDE: More spacing for auth layouts */
    text-align: center; /* AUTH OVERRIDE: Centered text for auth messages */
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.field-error {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.relative-container {
    position: relative;
}

.small-text {
    color: #666;
    font-size: 0.875rem;
    font-family: 'Open Sans', sans-serif; /* Match main site font */
}

.password-strength {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.3s ease;
    min-height: 1rem;
    /* Prevent layout shifts that could affect icon positioning */
    position: relative;
    z-index: 1;
    /* Ensure consistent emoji rendering in feedback */
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    /* Prevent any interaction with positioned icons */
    isolation: isolate;
    /* Force stable layout */
    box-sizing: border-box;
    /* Ensure this doesn't affect parent container size */
    display: block;
    width: 100%;
}

.password-strength.weak {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.password-strength.medium {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.password-strength.strong {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.password-strength:empty {
    display: none;
}

.password-match {
    margin-top: 0.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Ensure each form group in form-row is isolated */
.form-row .form-group {
    position: relative;
    isolation: isolate;
}

.form-row .relative-container {
    position: relative;
    z-index: 1;
}

/* Removed duplicate rule - handled by main .form-icon rule below */

.terms-text {
    font-size: 0.875rem;
    color: #666;
    margin-top: 1rem;
    text-align: center;
}

.terms-text a {
    color: #2c2c2c; /* Match main site dark theme */
    text-decoration: none;
    font-weight: 600;
}

.success-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

/* ===================================
   FORM VALIDATION STYLES
   =================================== */

/* Validation message base styles */

/* Phone validation messages */
.phone-validation-message.success {
    color: #155724;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
}

.phone-validation-message.error {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* Special handling for phone and password fields to prevent icon interference */
input[type="tel"].form-control,
input[type="password"].form-control {
    position: relative;
    z-index: 1;
}

/* Main form icon rule above handles all positioning consistently */

/* Specific fixes for form rows to prevent icon bleeding between fields */
.form-row .relative-container {
    position: relative;
    isolation: isolate; /* Create new stacking context */
}

.form-row .form-group {
    position: relative;
}

/* Handle phone input container conflicts in auth forms */
.auth-form .phone-input-container,
.auth-container .phone-input-container {
    position: relative;
    display: block;
    margin-bottom: 0;
}

.auth-form .phone-prefix,
.auth-container .phone-prefix {
    position: absolute;
    left: 45px !important; /* Move phone prefix to the right of the emoji */
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
    z-index: 5;
    font-weight: 500;
    font-size: 0.9rem;
}

.auth-form .phone-input-container input[type="tel"],
.auth-container .phone-input-container input[type="tel"] {
    padding-left: 75px !important; /* Extra space for both emoji and +1 prefix */
}

/* Postal validation messages */

/* Input field validation states - scoped to auth forms */
.auth-form .form-control.success,
.auth-container .form-control.success {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

.auth-form .form-control.error,
.auth-container .form-control.error {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
    background-color: #fff5f5 !important;
}

/* General validation message styles */
.field-error, .validation-error {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    padding: 0.75rem;
    border-radius: 0.25rem;
    font-weight: 500;
}

/* ===================================
   ANIMATIONS & KEYFRAMES
   =================================== */

/* Note: slideDown animation is defined in app-core.css to avoid duplication */
/* Use the global slideDown keyframe from core for consistent animations */
/* Animation class: Use 'slide-up' or other core animations as needed */

/* ===================================
   RESPONSIVE DESIGN - MOBILE FIRST
   =================================== */

/* Mobile styles (default - most users will be mobile) */
.auth-container {
    padding: 1rem 0.75rem; /* Tight padding for mobile */
}

.auth-card {
    padding: 1.5rem; /* Smaller padding for mobile */
    max-width: 100%; /* Full width on mobile */
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1); /* Lighter shadow for mobile */
}

.auth-title {
    font-size: 1.5rem; /* Smaller title on mobile */
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    font-size: 0.9rem; /* Smaller subtitle on mobile */
    margin-bottom: 1.5rem;
}

.auth-form .form-control,
.auth-container .form-control {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 14px 20px 14px 50px; /* Better touch targets */
    border-radius: 10px; /* Slightly smaller radius for mobile */
}

.btn-auth {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 16px 40px; /* Good touch target */
    border-radius: 25px; /* Less rounded for mobile */
}

.form-group {
    margin-bottom: 1.25rem; /* Tighter spacing on mobile */
}

/* Small phones */
@media (max-width: 375px) {
    .auth-container {
        padding: 0.5rem;
    }
    
    .auth-card {
        padding: 1.25rem;
        border-radius: 15px;
    }
    
    .auth-title {
        font-size: 1.3rem;
    }
    
    .auth-form .form-control,
    .auth-container .form-control {
        padding: 12px 16px 12px 45px;
    }
}

/* Very small screens - stack password fields vertically */
@media (max-width: 320px) {
    .form-row {
        display: block;
    }
    
    .form-row .form-group {
        margin-bottom: 1rem;
    }
}

/* Tablets and larger phones */
@media (min-width: 480px) {
    .auth-card {
        max-width: 420px;
        padding: 2rem;
        border-radius: 20px;
    }
    
    .auth-title {
        font-size: 1.75rem;
    }
    
    .auth-subtitle {
        font-size: 1rem;
    }
}

/* Desktop */
@media (min-width: 768px) {
    .auth-container {
        padding: 2rem;
    }
    
    .auth-card {
        max-width: 450px;
        padding: 2.5rem;
    }
    
    .auth-title {
        font-size: 2rem;
    }
    
    .form-row {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* Large desktop */
@media (min-width: 1024px) {
    .auth-card {
        max-width: 500px;
        padding: 3rem;
    }
}

/* ===================================
   PASSWORD FEEDBACK STYLES
   =================================== */

.password-feedback {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.password-feedback.valid {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.password-feedback.invalid {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.password-match {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.password-match.match {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.password-match.no-match {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}
