<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Password - Credora Microfinance</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <style>
        :root {
            --primary-green: #198754;
            --primary-yellow: #ffc107;
            --green-light: #38ef7d;
            --green-dark: #11998e;
            --yellow-light: #ffda6a;
            --text-dark: #333;
            --text-light: #6c757d;
            --white: #fff;
        }

        body {
            min-height: 100vh;
            margin: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .login-container {
            background: var(--white);
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            overflow: hidden;
            width: 100%;
            max-width: 600px;
            display: flex;
            flex-direction: column;
            min-height: auto;
        }

        .login-image {
            background: linear-gradient(135deg, var(--primary-green) 0%, var(--green-dark) 100%);
            padding: 30px 40px;
            text-align: center;
            color: white;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            position: relative;
            overflow: hidden;
        }

        .login-image::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 100%;
            height: 200%;
            background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
            transform: rotate(45deg);
        }

        .brand-section {
            position: relative;
            z-index: 2;
        }

        .brand-logo {
            width: 160px;
            height: 160px;
            background: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 10px;
            box-shadow: none;
            overflow: hidden;
            border-radius: 50%;
            padding: 15px;
            position: relative;
        }

        .brand-logo img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }

        .brand-text {
            font-size: 2.5rem;
            font-weight: 800;
            margin-bottom: 15px;
            letter-spacing: 3px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .tagline {
            font-size: 1.3rem;
            margin-bottom: 40px;
            opacity: 0.9;
            font-weight: 300;
        }

        .features-list {
            text-align: left;
            margin: 40px 0;
        }

        .feature-item {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
            font-size: 1.1rem;
        }

        .feature-item i {
            color: var(--primary-yellow);
            margin-right: 15px;
            font-size: 1.3rem;
        }

        .contact-info {
            margin-top: 50px;
            font-size: 0.95rem;
            opacity: 0.9;
            position: relative;
            z-index: 2;
        }

        .login-form {
            padding: 60px 50px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            background: var(--white);
        }

        .form-control {
            border: 2px solid #e9ecef;
            border-radius: 12px;
            padding: 15px 20px;
            font-size: 1rem;
            transition: all 0.3s ease;
        }

        .form-control:focus {
            border-color: var(--primary-green);
            box-shadow: 0 0 0 0.3rem rgba(25, 135, 84, 0.15);
        }

        .input-group-text {
            border: 2px solid #e9ecef;
            background-color: #f8f9fa;
        }

        .input-group .form-control {
            border-left: none;
        }

        .input-group .form-control:focus {
            border-left: none;
        }

        .btn-login {
            background: linear-gradient(135deg, var(--primary-green) 0%, var(--green-dark) 100%);
            border: none;
            padding: 15px;
            font-weight: 600;
            letter-spacing: 0.5px;
            color: var(--white);
            border-radius: 12px;
            font-size: 1.1rem;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(25, 135, 84, 0.3);
        }

        .btn-login:hover:not(:disabled) {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(25, 135, 84, 0.4);
        }

        .btn-login:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .form-check-input:checked {
            background-color: var(--primary-green);
            border-color: var(--primary-green);
        }

        .login-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .login-title {
            font-size: 2.2rem;
            font-weight: 700;
            color: var(--primary-green);
            margin-bottom: 10px;
        }

        .login-subtitle {
            color: var(--text-light);
            font-size: 1.1rem;
        }

        .password-strength {
            height: 5px;
            border-radius: 5px;
            margin-top: 8px;
            background-color: #e9ecef;
            overflow: hidden;
        }

        .password-strength-bar {
            height: 100%;
            width: 0%;
            transition: all 0.3s ease;
        }

        .password-requirements {
            font-size: 0.85rem;
            color: var(--text-light);
            margin-top: 10px;
        }

        .requirement {
            display: flex;
            align-items: center;
            margin-bottom: 5px;
            transition: all 0.3s ease;
        }

        .requirement i {
            font-size: 0.7rem;
            margin-right: 8px;
            width: 12px;
        }

        .requirement.met {
            color: var(--primary-green);
        }

        .requirement.met i {
            color: var(--primary-green);
        }

        .alert {
            border-radius: 12px;
            padding: 15px 20px;
        }

        .alert ul {
            padding-left: 20px;
            margin-bottom: 0;
        }

        /* Mobile responsiveness */
        @media (max-width: 576px) {
            body {
                padding: 10px;
            }

            .login-container {
                border-radius: 15px;
            }

            .login-image {
                padding: 30px 20px;
            }

            .login-form {
                padding: 30px 20px;
            }

            .brand-text {
                font-size: 2rem;
            }

            .login-title {
                font-size: 2rem;
            }

            .brand-logo {
                width: 140px;
                height: 140px;
                padding: 12px;
            }

            .tagline {
                font-size: 1.1rem;
                margin-bottom: 20px;
            }

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

            .form-control {
                padding: 12px 15px;
            }

            .btn-login {
                padding: 12px;
            }

            .password-requirements {
                font-size: 0.8rem;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <!-- Branding Section -->
        <div class="login-image">
            <div class="brand-section">
                <div class="brand-logo">
                    <img src="{{ asset('images/melsoft-logo.jpg') }}" alt="Melsoft Logo">
                </div>

                <div class="brand-text">CREDORA</div>
                <div class="tagline">Easy, Efficient, Empowering</div>
            </div>
        </div>

        <!-- Reset Password Form -->
        <div class="login-form">
            <div class="login-header">
                <h1 class="login-title">Set New Password</h1>
                <p class="login-subtitle">Create your new password</p>
            </div>

            @if (session('message'))
                <div class="alert alert-info border-0 shadow-sm alert-dismissible fade show" role="alert">
                    <i class="fas fa-info-circle me-2"></i>{{ session('message') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            @endif

            @if ($errors->any())
                <div class="alert alert-danger border-0 shadow-sm alert-dismissible fade show" role="alert">
                    <i class="fas fa-exclamation-circle me-2"></i>
                    <ul class="mb-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            @endif

            <form method="POST" action="{{ route('password.update') }}" id="resetPasswordForm">
                @csrf
                <input type="hidden" name="token" value="{{ $token }}">
                <input type="hidden" name="email" value="{{ $email ?? old('email') }}">

                <div class="mb-4">
                    <label class="form-label fw-semibold text-dark">New Password</label>
                    <div class="input-group">
                        <span class="input-group-text bg-light border-end-0">
                            <i class="fas fa-lock text-muted"></i>
                        </span>
                        <input type="password" name="password" id="password" class="form-control border-start-0" required placeholder="Enter new password">
                        <button type="button" class="input-group-text bg-light toggle-password" data-target="password">
                            <i class="fas fa-eye text-muted"></i>
                        </button>
                    </div>
                    <div class="password-strength mt-2">
                        <div class="password-strength-bar" id="passwordStrengthBar"></div>
                    </div>
                    <div class="password-requirements">
                        <div class="requirement" id="lengthReq">
                            <i class="fas fa-circle"></i>
                            <span>At least 8 characters</span>
                        </div>
                        <div class="requirement" id="uppercaseReq">
                            <i class="fas fa-circle"></i>
                            <span>One uppercase letter</span>
                        </div>
                        <div class="requirement" id="lowercaseReq">
                            <i class="fas fa-circle"></i>
                            <span>One lowercase letter</span>
                        </div>
                        <div class="requirement" id="numberReq">
                            <i class="fas fa-circle"></i>
                            <span>One number</span>
                        </div>
                    </div>
                </div>

                <div class="mb-4">
                    <label class="form-label fw-semibold text-dark">Confirm Password</label>
                    <div class="input-group">
                        <span class="input-group-text bg-light border-end-0">
                            <i class="fas fa-lock text-muted"></i>
                        </span>
                        <input type="password" name="password_confirmation" id="confirmPassword" class="form-control border-start-0" required placeholder="Confirm new password">
                        <button type="button" class="input-group-text bg-light toggle-password" data-target="confirmPassword">
                            <i class="fas fa-eye text-muted"></i>
                        </button>
                    </div>
                    <div id="passwordMatch" class="mt-2" style="display: none;">
                        <small class="text-success"><i class="fas fa-check-circle me-1"></i>Passwords match</small>
                    </div>
                    <div id="passwordMismatch" class="mt-2" style="display: none;">
                        <small class="text-danger"><i class="fas fa-times-circle me-1"></i>Passwords do not match</small>
                    </div>
                </div>

                <button type="submit" class="btn btn-login btn-lg w-100 mb-3" id="submitBtn" disabled>
                    <i class="fas fa-key me-2"></i>Reset Password
                </button>

                <div class="text-center">
                    <a href="{{ route('login') }}" class="text-decoration-none text-primary">
                        <i class="fas fa-arrow-left me-1"></i>Back to Login
                    </a>
                </div>

                <div class="text-center mt-4 pt-3 border-top">
                    <small class="text-muted">&copy; {{ date('Y') }} Melsoft (Pvt) Ltd. All rights reserved.</small>
                </div>
            </form>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const passwordInput = document.getElementById('password');
            const confirmPasswordInput = document.getElementById('confirmPassword');
            const passwordStrengthBar = document.getElementById('passwordStrengthBar');
            const submitBtn = document.getElementById('submitBtn');

            // Password strength checker
            passwordInput.addEventListener('input', function() {
                const password = this.value;
                let strength = 0;

                // Check password requirements
                const hasLength = password.length >= 8;
                const hasUppercase = /[A-Z]/.test(password);
                const hasLowercase = /[a-z]/.test(password);
                const hasNumber = /[0-9]/.test(password);

                // Update requirement indicators
                updateRequirement('lengthReq', hasLength);
                updateRequirement('uppercaseReq', hasUppercase);
                updateRequirement('lowercaseReq', hasLowercase);
                updateRequirement('numberReq', hasNumber);

                // Calculate strength
                if (hasLength) strength += 25;
                if (hasUppercase) strength += 25;
                if (hasLowercase) strength += 25;
                if (hasNumber) strength += 25;

                // Update strength bar
                passwordStrengthBar.style.width = strength + '%';

                if (strength < 50) {
                    passwordStrengthBar.style.backgroundColor = '#dc3545';
                } else if (strength < 75) {
                    passwordStrengthBar.style.backgroundColor = '#ffc107';
                } else {
                    passwordStrengthBar.style.backgroundColor = '#198754';
                }

                validateForm();
            });

            // Confirm password checker
            confirmPasswordInput.addEventListener('input', function() {
                validatePasswordMatch();
                validateForm();
            });

            // Toggle password visibility
            document.querySelectorAll('.toggle-password').forEach(button => {
                button.addEventListener('click', function() {
                    const targetId = this.getAttribute('data-target');
                    const targetInput = document.getElementById(targetId);
                    const icon = this.querySelector('i');

                    if (targetInput.type === 'password') {
                        targetInput.type = 'text';
                        icon.classList.remove('fa-eye');
                        icon.classList.add('fa-eye-slash');
                    } else {
                        targetInput.type = 'password';
                        icon.classList.remove('fa-eye-slash');
                        icon.classList.add('fa-eye');
                    }
                });
            });

            function updateRequirement(elementId, met) {
                const element = document.getElementById(elementId);
                if (met) {
                    element.classList.add('met');
                    element.querySelector('i').className = 'fas fa-check-circle';
                } else {
                    element.classList.remove('met');
                    element.querySelector('i').className = 'fas fa-circle';
                }
            }

            function validatePasswordMatch() {
                const password = passwordInput.value;
                const confirmPassword = confirmPasswordInput.value;
                const matchElement = document.getElementById('passwordMatch');
                const mismatchElement = document.getElementById('passwordMismatch');

                if (confirmPassword === '') {
                    matchElement.style.display = 'none';
                    mismatchElement.style.display = 'none';
                    return;
                }

                if (password === confirmPassword) {
                    matchElement.style.display = 'block';
                    mismatchElement.style.display = 'none';
                } else {
                    matchElement.style.display = 'none';
                    mismatchElement.style.display = 'block';
                }
            }

            function validateForm() {
                const password = passwordInput.value;
                const confirmPassword = confirmPasswordInput.value;

                // Check if password meets all requirements
                const hasLength = password.length >= 8;
                const hasUppercase = /[A-Z]/.test(password);
                const hasLowercase = /[a-z]/.test(password);
                const hasNumber = /[0-9]/.test(password);
                const passwordsMatch = password === confirmPassword;

                // Enable/disable submit button
                if (hasLength && hasUppercase && hasLowercase && hasNumber && passwordsMatch) {
                    submitBtn.disabled = false;
                } else {
                    submitBtn.disabled = true;
                }
            }

            // Initial validation
            validateForm();
        });
    </script>
</body>
</html>
