<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page - Elfit Arabia</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="stylesheet" href="/style.css">
    <style>
        body {
            background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
            background-attachment: fixed;
            color: #f8fafc;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
        }

        .login-container {
            background: linear-gradient(145deg, #1e293b 0%, #334155 100%);
            padding: 2.5rem;
            border-radius: 16px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
            max-width: 420px;
            width: 100%;
            border: 1px solid #475569;
        }

        h2,
        h3 {
            color: #f8fafc;
            font-weight: 700;
        }

        h2 {
            background: linear-gradient(135deg, #60a5fa 0%, #93c5fd 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .form-control {
            background-color: #334155;
            border: 1px solid #475569;
            color: #f8fafc;
            border-radius: 8px;
            padding: 12px 16px;
        }

        .form-control::placeholder {
            color: #94a3b8;
        }

        .form-control:focus {
            background-color: #475569;
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
            color: #f8fafc;
        }

        .btn-primary {
            background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
            border: none;
            font-weight: 600;
            border-radius: 8px;
            padding: 12px 20px;
            transition: all 0.2s ease;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
        }

        .alert {
            background-color: #334155;
            border: 1px solid #475569;
            border-left: 4px solid #3b82f6;
            color: #f8fafc;
            border-radius: 8px;
        }

        .form-label {
            color: #cbd5e1;
            font-weight: 500;
        }

        .login-link {
            text-align: center;
            margin-top: 1.5rem;
            color: #94a3b8;
        }

        .login-link a {
            color: #60a5fa;
            text-decoration: none;
            font-weight: 600;
            transition: color 0.2s ease;
        }

        .login-link a:hover {
            color: #93c5fd;
            text-decoration: underline;
        }

        .divider {
            display: flex;
            align-items: center;
            margin: 1.5rem 0;
        }

        .divider::before,
        .divider::after {
            content: '';
            flex: 1;
            border-bottom: 1px solid #475569;
        }

        .divider span {
            padding: 0 1rem;
            color: #94a3b8;
            font-size: 0.9rem;
        }
    </style>
</head>

<body>
    <div class="login-container">
        <h2 class="text-center mb-4"><i class="fas fa-building me-2"></i>Elfit Arabia</h2>
        <p class="text-center text-muted mb-4">B2B Procurement Portal</p>

        <!-- Flash Messages -->
        <% const messages=getFlashedMessages(); %>
            <% if (messages && messages.length> 0) { %>
                <% messages.forEach(function(message) { %>
                    <div class="alert alert-info" role="alert">
                        <i class="fas fa-info-circle me-2"></i>
                        <%= message %>
                    </div>
                    <% }); %>
                        <% } %>

                            <!-- Email Form -->
                            <form method="POST" class="mb-4">
                                <div class="mb-3">
                                    <label for="identifier" class="form-label"><i class="fas fa-envelope me-1"></i>
                                        Email</label>
                                    <input type="text" name="identifier" id="identifier" class="form-control"
                                        value="<%= identifier || '' %>" placeholder="Enter your email address" required>
                                </div>
                                <button type="submit" class="btn btn-primary w-100">
                                    <i class="fas fa-paper-plane me-1"></i> Send OTP
                                </button>
                            </form>

                            <% if (show_otp_section) { %>
                                <div class="divider"><span>OTP Sent</span></div>
                                <h3 class="text-center mb-3"><i class="fas fa-key me-2"></i>Enter OTP</h3>
                                <form method="POST">
                                    <div class="mb-3">
                                        <label for="otp" class="form-label">One-Time Password</label>
                                        <input type="text" name="otp" id="otp" class="form-control"
                                            placeholder="Enter the OTP sent to your email" required>
                                    </div>
                                    <button type="submit" class="btn btn-primary w-100">
                                        <i class="fas fa-check me-1"></i> Verify OTP
                                    </button>
                                </form>
                                <% } %>

                                    <p class="login-link">New to this website? <a href="/register"><i
                                                class="fas fa-user-plus me-1"></i>Register</a></p>
    </div>

    <script>
        setTimeout(function () {
            const flashMessages = document.querySelectorAll('.alert');
            flashMessages.forEach(msg => msg.remove());
        }, 5000);
    </script>
</body>

</html>