<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Verify OTP — Synergo SSO</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            min-height: 100vh; display: flex; align-items: center; justify-content: center;
            background: #f0f4f8; overflow: hidden; position: relative;
        }
        body::before {
            content: ''; position: fixed; top: -80px; right: -80px;
            width: 280px; height: 280px; background: rgba(59, 130, 246, 0.06);
            border-radius: 50%; z-index: 0;
        }
        body::after {
            content: ''; position: fixed; bottom: -60px; left: -60px;
            width: 220px; height: 220px; background: rgba(59, 130, 246, 0.05);
            border-radius: 50%; z-index: 0;
        }
        .blob-accent { position: fixed; width: 160px; height: 160px; background: rgba(16, 185, 129, 0.05); border-radius: 50%; z-index: 0; }
        .blob-accent-1 { top: 30%; left: -40px; }
        .blob-accent-2 { bottom: 20%; right: 10%; }
        .card {
            position: relative; z-index: 1; background: rgba(255, 255, 255, 0.85);
            backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
            border-radius: 24px; padding: 48px 40px; width: 100%; max-width: 400px;
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.04), 0 10px 40px -4px rgba(0,0,0,0.08);
            border: 1px solid rgba(255,255,255,0.6); animation: cardSlideUp 0.6s ease-out;
        }
        @keyframes cardSlideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
        .illustration-wrapper { text-align: center; margin-bottom: 24px; }
        .illustration-wrapper img { width: 200px; height: auto; animation: floatIllustration 4s ease-in-out infinite; }
        @keyframes floatIllustration { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
        .card h1 { font-size: 26px; font-weight: 700; color: #111827; text-align: center; margin-bottom: 8px; }
        .card .subtitle { font-size: 14px; color: #6b7280; text-align: center; margin-bottom: 32px; line-height: 1.5; }
        .alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 12px 16px; margin-bottom: 20px; font-size: 13px; color: #16a34a; }
        .alert-error { background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; padding: 12px 16px; margin-bottom: 20px; animation: shake 0.4s ease-in-out; }
        @keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
        .alert-error ul { list-style: none; padding: 0; margin: 0; }
        .alert-error li { font-size: 13px; color: #dc2626; display: flex; align-items: center; gap: 6px; }
        .alert-error li::before { content: ''; width: 6px; height: 6px; background: #dc2626; border-radius: 50%; flex-shrink: 0; }

        .otp-inputs { display: flex; gap: 10px; justify-content: center; margin-bottom: 24px; }
        .otp-inputs input {
            width: 48px; height: 56px; text-align: center; font-size: 22px; font-weight: 600;
            font-family: 'Inter', sans-serif; border: 1.5px solid #e5e7eb; border-radius: 12px;
            background: #fff; color: #111827; outline: none; transition: all 0.25s ease;
        }
        .otp-inputs input:focus { border-color: #3b82f6; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1); }

        .btn-submit {
            width: 100%; padding: 14px 24px; background: #2563eb; color: #fff;
            border: none; border-radius: 12px; font-size: 16px; font-weight: 600;
            font-family: 'Inter', sans-serif; cursor: pointer; transition: all 0.3s ease;
        }
        .btn-submit:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: 0 8px 24px -4px rgba(37, 99, 235, 0.4); }
        .btn-submit:active { transform: translateY(0); }
        .card-footer { text-align: center; margin-top: 28px; font-size: 14px; color: #6b7280; }
        .card-footer a { color: #3b82f6; text-decoration: none; font-weight: 500; transition: color 0.2s; }
        .card-footer a:hover { color: #2563eb; }
        .resend-link { text-align: center; margin-top: 16px; font-size: 13px; color: #9ca3af; }
        .resend-link a { color: #3b82f6; text-decoration: none; font-weight: 500; }

        @media (max-width: 480px) {
            .card { margin: 16px; padding: 36px 24px; border-radius: 20px; }
            .illustration-wrapper img { width: 160px; }
            .otp-inputs input { width: 42px; height: 50px; font-size: 20px; }
        }
    </style>
</head>

<body>
    <div class="blob-accent blob-accent-1"></div>
    <div class="blob-accent blob-accent-2"></div>

    <div class="card">
        <div class="illustration-wrapper">
            <img src="{{ asset('images/forgot-password-illustration.png') }}" alt="Verify OTP Illustration">
        </div>

        <h1>Verify OTP</h1>
        <p class="subtitle">Enter the 6-digit OTP code sent to<br><strong>{{ $email ?? '' }}</strong></p>

        @if (session('status'))
            <div class="alert-success">{{ session('status') }}</div>
        @endif

        @if ($errors->any())
            <div class="alert-error">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form method="POST" action="{{ route('password.verify-otp.submit') }}" id="otpForm">
            @csrf
            <input type="hidden" name="email" value="{{ $email ?? '' }}">
            <input type="hidden" name="otp" id="otpHidden">

            <div class="otp-inputs">
                <input type="text" maxlength="1" class="otp-digit" data-index="0" inputmode="numeric" autocomplete="one-time-code" autofocus>
                <input type="text" maxlength="1" class="otp-digit" data-index="1" inputmode="numeric">
                <input type="text" maxlength="1" class="otp-digit" data-index="2" inputmode="numeric">
                <input type="text" maxlength="1" class="otp-digit" data-index="3" inputmode="numeric">
                <input type="text" maxlength="1" class="otp-digit" data-index="4" inputmode="numeric">
                <input type="text" maxlength="1" class="otp-digit" data-index="5" inputmode="numeric">
            </div>

            <button type="submit" class="btn-submit">Verify OTP</button>
        </form>

        <div class="resend-link">
            Didn't receive the code?
            <a href="{{ route('password.forgot') }}">Resend</a>
        </div>

        <div class="card-footer">
            <a href="{{ route('login') }}">← Back to Sign In</a>
        </div>
    </div>

    <script>
        const digits = document.querySelectorAll('.otp-digit');
        const otpHidden = document.getElementById('otpHidden');

        digits.forEach((input, idx) => {
            input.addEventListener('input', (e) => {
                const val = e.target.value;
                if (val && idx < digits.length - 1) digits[idx + 1].focus();
                updateOtpHidden();
            });
            input.addEventListener('keydown', (e) => {
                if (e.key === 'Backspace' && !input.value && idx > 0) {
                    digits[idx - 1].focus();
                }
            });
            input.addEventListener('paste', (e) => {
                e.preventDefault();
                const pasted = (e.clipboardData || window.clipboardData).getData('text').trim();
                if (/^\d{6}$/.test(pasted)) {
                    pasted.split('').forEach((ch, i) => { if (digits[i]) digits[i].value = ch; });
                    digits[5].focus();
                    updateOtpHidden();
                }
            });
        });

        function updateOtpHidden() {
            otpHidden.value = Array.from(digits).map(d => d.value).join('');
        }

        document.getElementById('otpForm').addEventListener('submit', function() {
            updateOtpHidden();
        });
    </script>
</body>

</html>
