<x-guest-layout>
    
    <div class="min-h-screen w-full bg-gradient-to-br from-gray-50 via-white to-gray-100 dark:from-gray-900 dark:via-gray-800 dark:to-gray-900 p-4 sm:p-6 md:p-8 flex items-center justify-center">

        <div class="w-full max-w-md animate-fadeIn">

            <div class="relative bg-white dark:bg-gray-800 rounded-3xl shadow-xl p-8 border border-gray-100 dark:border-gray-700">

                <div class="relative">

                    <!-- Header -->
                    <div class="text-center mb-8 animate-slideDown">
                        <div class="inline-flex items-center justify-center w-16 h-16 mb-4 rounded-full bg-yellow-100 dark:bg-yellow-900/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8 text-yellow-500 dark:text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4" />
                            </svg>
                        </div>
                        <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-2">Welcome back</h1>
                        <p class="text-gray-600 dark:text-gray-400">Please enter your details</p>
                    </div>

                    <!-- Toggle Button -->
                    <div class="mb-6 text-center">
                        <button type="button"
                                onclick="toggleLoginMode()"
                                id="toggleButton"
                                class="text-sm text-yellow-600 hover:text-yellow-700 dark:text-yellow-400 dark:hover:text-yellow-300 underline transition">
                            Login with Recovery Phrase
                        </button>
                    </div>

                    <x-auth-session-status class="mb-4" :status="session('status')" />

                    <!-- Login Form -->
                    <form method="POST" action="{{ route('login') }}" class="space-y-5">
                        @csrf

                        <input type="hidden" name="login_type" id="login_type" value="password">

                        <!-- PASSWORD LOGIN MODE -->
                        <div id="passwordLoginFields">

                            <!-- Login Field -->
                            <div class="space-y-2">
                                <x-input-label for="login" value="UUID or Email" />
                                <input 
                                    id="login"
                                    type="text"
                                    name="login"
                                    value="{{ old('login') }}"
                                    class="w-full py-3 px-4 bg-gray-50 dark:bg-gray-700/50 border-2 border-gray-200 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-yellow-500 focus:border-transparent dark:text-gray-200 text-sm"
                                    placeholder="Enter your UUID or email"
                                />
                                <x-input-error :messages="$errors->get('login')" />
                            </div>

                            <!-- Password Field -->
                            <div class="space-y-2">
                                <x-input-label for="password" value="Password" />
                                <input
                                    id="password"
                                    type="password"
                                    name="password"
                                    class="w-full py-3 px-4 bg-gray-50 dark:bg-gray-700/50 border-2 border-gray-200 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-yellow-500 focus:border-transparent dark:text-gray-200 text-sm"
                                    placeholder="Password ••••••••"
                                />
                                <x-input-error :messages="$errors->get('password')" />
                            </div>

                        </div>

                        <!-- RECOVERY LOGIN MODE -->
                        <div id="recoveryContainer" class="hidden space-y-2">
                            <x-input-label for="recovery_phrase" value="Recovery Phrase" />
                            <textarea
                                id="recovery_phrase"
                                name="recovery_phrase"
                                rows="3"
                                class="w-full py-3 px-4 bg-gray-50 dark:bg-gray-700/50 border-2 border-gray-200 dark:border-gray-600 rounded-xl focus:ring-2 focus:ring-yellow-500 focus:border-transparent dark:text-gray-200 text-sm font-mono"
                                placeholder="Enter your 12-word recovery phrase"
                            ></textarea>
                            <x-input-error :messages="$errors->get('recovery_phrase')" />
                        </div>

                        <!-- Remember -->
                        <div id="rememberContainer" class="flex items-center justify-between pt-2">
                            <label class="flex items-center">
                                <input type="checkbox" name="remember"
                                       class="w-4 h-4 border-2 border-gray-300 rounded text-yellow-500 focus:ring-yellow-500">
                                <span class="ml-2 text-sm text-gray-600 dark:text-gray-400">
                                    Remember me
                                </span>
                            </label>

                            @if (Route::has('password.request'))
                                <a href="{{ route('password.request') }}"
                                   class="text-sm text-yellow-600 hover:underline">
                                    Forgot password?
                                </a>
                            @endif
                        </div>

                        <!-- Submit -->
                        <button
                            type="submit"
                            class="w-full px-4 py-3 mt-6 text-sm font-medium text-white bg-yellow-500 hover:bg-yellow-600 rounded-xl transition">
                            Sign in
                        </button>

                    </form>

                    <!-- Register -->
                    <div class="mt-8 text-center">
                        <p class="text-sm text-gray-600 dark:text-gray-400">
                            Don't have an account?
                            <a href="{{ route('register') }}"
                               class="font-medium text-yellow-600 hover:underline">
                                Create account
                            </a>
                        </p>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <!-- TOGGLE SCRIPT -->
    <script>
        let recoveryMode = false;

        function toggleLoginMode() {
            const passwordFields = document.getElementById('passwordLoginFields');
            const recoveryContainer = document.getElementById('recoveryContainer');
            const rememberContainer = document.getElementById('rememberContainer');
            const loginType = document.getElementById('login_type');
            const toggleButton = document.getElementById('toggleButton');

            recoveryMode = !recoveryMode;

            if (recoveryMode) {
                passwordFields.classList.add('hidden');
                recoveryContainer.classList.remove('hidden');
                rememberContainer.classList.add('hidden');
                loginType.value = 'recovery';
                toggleButton.innerText = 'Login with Password Instead';
            } else {
                passwordFields.classList.remove('hidden');
                recoveryContainer.classList.add('hidden');
                rememberContainer.classList.remove('hidden');
                loginType.value = 'password';
                toggleButton.innerText = 'Login with Recovery Phrase';
            }
        }
    </script>

</x-guest-layout>