{% extends "layout.html" %}

{% block content %}
<div class="content">
    <div class="auth-container">
        <div class="auth-card">
            <h2 class="auth-title">Reset Password</h2>
            
            <p class="auth-subtitle">
                Enter your new password below.
            </p>
            
            <form method="POST" class="auth-form">
                <div class="form-group">
                    <label for="password">New Password</label>
                    <input type="password" 
                           id="password" 
                           name="password" 
                           class="form-control" 
                           placeholder="Enter new password"
                           required 
                           autofocus>
                    <div id="password-strength" class="password-strength-meter"></div>
                </div>
                
                <div class="form-group">
                    <label for="confirm_password">Confirm Password</label>
                    <input type="password" 
                           id="confirm_password" 
                           name="confirm_password" 
                           class="form-control" 
                           placeholder="Confirm new password"
                           required>
                </div>
                
                <!-- Password requirements -->
                <div class="password-requirements">
                    <p class="requirements-title">Password must contain:</p>
                    <ul id="password-requirements-list">
                        <li id="req-length">At least 8 characters</li>
                        <li id="req-uppercase">One uppercase letter</li>
                        <li id="req-lowercase">One lowercase letter</li>
                        <li id="req-number">One number</li>
                        <li id="req-special">One special character</li>
                    </ul>
                </div>
                
                <button type="submit" class="btn btn-primary btn-block">Reset Password</button>
                
                <div class="auth-links">
                    <a href="{{ url_for('login') }}">Back to Login</a>
                </div>
            </form>
        </div>
    </div>
</div>

<style>
    .auth-container {
        min-height: calc(100vh - 200px);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 2rem;
    }
    
    .auth-card {
        background: white;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        padding: 2.5rem;
        width: 100%;
        max-width: 400px;
    }
    
    .auth-title {
        text-align: center;
        margin-bottom: 0.5rem;
        color: var(--primary-color);
    }
    
    .auth-subtitle {
        text-align: center;
        color: #666;
        margin-bottom: 2rem;
        line-height: 1.5;
    }
    
    .auth-form .form-group {
        margin-bottom: 1.5rem;
    }
    
    .auth-form label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        color: #333;
    }
    
    .auth-form .form-control {
        width: 100%;
        padding: 0.75rem;
        border: 1px solid #ddd;
        border-radius: 6px;
        font-size: 1rem;
        transition: border-color 0.2s;
    }
    
    .auth-form .form-control:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }
    
    .password-strength-meter {
        margin-top: 0.5rem;
        height: 4px;
        background: #e0e0e0;
        border-radius: 2px;
        overflow: hidden;
        transition: all 0.3s ease;
    }
    
    .password-strength-meter.weak {
        background: #ff4444;
    }
    
    .password-strength-meter.fair {
        background: #ffaa00;
    }
    
    .password-strength-meter.good {
        background: #00aa00;
    }
    
    .password-strength-meter.strong {
        background: #008800;
    }
    
    .password-requirements {
        background: #f8f9fa;
        border: 1px solid #e9ecef;
        border-radius: 6px;
        padding: 1rem;
        margin-bottom: 1.5rem;
        font-size: 0.875rem;
    }
    
    .requirements-title {
        margin: 0 0 0.5rem 0;
        font-weight: 500;
        color: #495057;
    }
    
    #password-requirements-list {
        margin: 0;
        padding-left: 1.25rem;
        color: #6c757d;
    }
    
    #password-requirements-list li {
        margin-bottom: 0.25rem;
        position: relative;
    }
    
    #password-requirements-list li.valid {
        color: #28a745;
    }
    
    #password-requirements-list li.valid::before {
        content: "✓ ";
        position: absolute;
        left: -1.25rem;
        font-weight: bold;
    }
    
    .btn-block {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
        font-weight: 500;
        margin-bottom: 1rem;
    }
    
    .auth-links {
        text-align: center;
        margin-top: 1.5rem;
    }
    
    .auth-links a {
        color: var(--primary-color);
        text-decoration: none;
        font-size: 0.875rem;
    }
    
    .auth-links a:hover {
        text-decoration: underline;
    }
    
    /* Mobile optimization */
    @media (max-width: 768px) {
        .auth-container {
            padding: 1rem;
            min-height: calc(100vh - 140px);
        }
        
        .auth-card {
            padding: 1.5rem;
        }
        
        .auth-title {
            font-size: 1.5rem;
        }
        
        .auth-subtitle {
            font-size: 0.875rem;
        }
        
        .password-requirements {
            font-size: 0.8125rem;
        }
    }
</style>

<script>
    // Password strength validation
    document.addEventListener('DOMContentLoaded', function() {
        const passwordInput = document.getElementById('password');
        const confirmInput = document.getElementById('confirm_password');
        const strengthMeter = document.getElementById('password-strength');
        
        // Requirement elements
        const reqLength = document.getElementById('req-length');
        const reqUppercase = document.getElementById('req-uppercase');
        const reqLowercase = document.getElementById('req-lowercase');
        const reqNumber = document.getElementById('req-number');
        const reqSpecial = document.getElementById('req-special');
        
        passwordInput.addEventListener('input', function() {
            const password = this.value;
            
            // Check each requirement
            const hasLength = password.length >= 8;
            const hasUppercase = /[A-Z]/.test(password);
            const hasLowercase = /[a-z]/.test(password);
            const hasNumber = /[0-9]/.test(password);
            const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(password);
            
            // Update requirement indicators
            reqLength.classList.toggle('valid', hasLength);
            reqUppercase.classList.toggle('valid', hasUppercase);
            reqLowercase.classList.toggle('valid', hasLowercase);
            reqNumber.classList.toggle('valid', hasNumber);
            reqSpecial.classList.toggle('valid', hasSpecial);
            
            // Calculate strength
            let strength = 0;
            if (hasLength) strength++;
            if (hasUppercase) strength++;
            if (hasLowercase) strength++;
            if (hasNumber) strength++;
            if (hasSpecial) strength++;
            
            // Update strength meter
            strengthMeter.className = 'password-strength-meter';
            if (password.length === 0) {
                strengthMeter.className = 'password-strength-meter';
            } else if (strength <= 2) {
                strengthMeter.className = 'password-strength-meter weak';
            } else if (strength === 3) {
                strengthMeter.className = 'password-strength-meter fair';
            } else if (strength === 4) {
                strengthMeter.className = 'password-strength-meter good';
            } else {
                strengthMeter.className = 'password-strength-meter strong';
            }
        });
        
        // Real-time password match validation
        confirmInput.addEventListener('input', function() {
            if (passwordInput.value && this.value) {
                if (passwordInput.value !== this.value) {
                    this.setCustomValidity('Passwords do not match');
                } else {
                    this.setCustomValidity('');
                }
            }
        });
    });
</script>
{% endblock %}