{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - HAVEN GRAZURI INVESTMENT LIMITED</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        :root {
            --primary: #0A3D62;
            --secondary: #3C9EBD;
            --background: #FFFFFF;
            --success: #2ECC71;
            --error: #E74C3C;
        }
        
        .bg-primary { background-color: var(--primary); }
        .bg-secondary { background-color: var(--secondary); }
        .bg-success { background-color: var(--success); }
        .bg-error { background-color: var(--error); }
        
        .text-primary { color: var(--primary); }
        .text-secondary { color: var(--secondary); }
        .text-success { color: var(--success); }
        .text-error { color: var(--error); }
        
        .border-primary { border-color: var(--primary); }
        .border-secondary { border-color: var(--secondary); }
        
        /* Disable autocomplete styling */
        input:-webkit-autofill,
        input:-webkit-autofill:hover,
        input:-webkit-autofill:focus,
        input:-webkit-autofill:active {
            -webkit-box-shadow: 0 0 0 30px white inset !important;
            -webkit-text-fill-color: #374151 !important;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
    <div class="max-w-md w-full space-y-8">
        <!-- Logo and Header -->
        <div class="text-center">
            <div class="mx-auto mb-6">
                <img src="{% static 'images/grazuri-logo.jpg' %}" alt="Haven Grazuri Investment Limited Logo" class="h-32 w-auto mx-auto object-contain">
            </div>
            <h2 class="text-3xl font-bold text-gray-900">HAVEN GRAZURI INVESTMENT LIMITED</h2>
            <p class="mt-2 text-sm text-gray-600">Sign in to your account</p>
        </div>

        <!-- Login Form -->
        <div class="bg-white py-8 px-6 shadow-lg rounded-lg">
            <!-- Error Messages -->
            {% if form.errors %}
            <div class="mb-4 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
                        </svg>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm font-medium">
                            {% if form.username.errors %}
                                Email or username is required.
                            {% elif form.password.errors %}
                                Password is required.
                            {% else %}
                                Invalid credentials. Please try again.
                            {% endif %}
                        </p>
                    </div>
                </div>
            </div>
            {% endif %}

            <!-- Messages -->
            {% if messages %}
                {% for message in messages %}
                    <div class="mb-4 {% if message.tags == 'error' %}bg-red-100 border border-red-400 text-red-700{% else %}bg-green-100 border border-green-400 text-green-700{% endif %} px-4 py-3 rounded relative">
                        <p class="text-sm">{{ message }}</p>
                    </div>
                {% endfor %}
            {% endif %}

            <form id="login-form" action="{% url 'users:login' %}" method="post" class="space-y-6">
                {% csrf_token %}
                
                <!-- Email/Username Field -->
                <div>
                    <label for="id_username" class="block text-sm font-medium text-gray-700">
                        Email Address or Username
                    </label>
                    <div class="mt-1">
                        <input id="id_username" name="username" type="text" required 
                               class="appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-primary focus:border-primary focus:z-10 sm:text-sm"
                               placeholder="Enter your email or username">
                    </div>
                </div>

                <!-- Password Field -->
                <div>
                    <label for="id_password" class="block text-sm font-medium text-gray-700">
                        Password
                    </label>
                    <div class="mt-1">
                        <input id="id_password" name="password" type="password" required 
                               class="appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-primary focus:border-primary focus:z-10 sm:text-sm"
                               placeholder="Enter your password">
                    </div>
                </div>

                <!-- Remember Me -->
                <div class="flex items-center justify-between">
                    <div class="flex items-center">
                        <input id="remember_me" name="remember_me" type="checkbox" 
                               class="h-4 w-4 text-primary focus:ring-primary border-gray-300 rounded">
                        <label for="remember_me" class="ml-2 block text-sm text-gray-900">
                            Remember me
                        </label>
                    </div>

                    <div class="text-sm">
                        <a href="{% url 'users:password_reset' %}" class="font-medium text-secondary hover:text-primary">
                            Forgot your password?
                        </a>
                    </div>
                </div>

                <!-- Submit Button -->
                <div>
                    <button type="submit" id="submit-btn"
                            class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-primary hover:bg-opacity-90 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary transition-colors">
                        <span class="absolute left-0 inset-y-0 flex items-center pl-3">
                            <svg class="h-5 w-5 text-white group-hover:text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                            </svg>
                        </span>
                        Sign in
                    </button>
                </div>
            </form>

            <!-- Additional Options -->
            <div class="mt-6">
                <div class="relative">
                    <div class="absolute inset-0 flex items-center">
                        <div class="w-full border-t border-gray-300"></div>
                    </div>
                    <div class="relative flex justify-center text-sm">
                        <span class="px-2 bg-white text-gray-500">Need Help?</span>
                    </div>
                </div>

                <div class="mt-4 text-center">
                    <p class="text-sm text-gray-600">
                        Contact support at 
                        <a href="mailto:info@havengrazuri.co.ke" class="font-medium text-secondary hover:text-primary">
                            info@havengrazuri.co.ke
                        </a>
                    </p>
                </div>
            </div>
        </div>

        <!-- Footer -->
        <div class="text-center">
            <p class="text-xs text-gray-500">
                © 2025 HAVEN GRAZURI INVESTMENT LIMITED. All rights reserved.
            </p>
        </div>
    </div>

    <script>
        // Simple loading state for submit button
        document.addEventListener('DOMContentLoaded', function() {
            const form = document.getElementById('login-form');
            const submitBtn = document.getElementById('submit-btn');
            
            if (form && submitBtn) {
                form.addEventListener('submit', function() {
                    submitBtn.disabled = true;
                    submitBtn.innerHTML = 'Signing in...';
                });
            }
        });
    </script>
</body>
</html>