<?php
session_start();
if (isset($_SESSION['admin_logged_in'])) {
    header("Location: admin.php");
    exit;
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $user = $_POST['username'] ?? '';
    $pass = $_POST['password'] ?? '';
    // Replace these credentials with your admin credentials
    if ($user === 'Admin' && $pass === 'crc123') {
        $_SESSION['admin_logged_in'] = true;
        header("Location: admin.php");
        exit;
    } else {
        $error = 'Invalid username or password';
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        body {
            font-family: 'Inter', sans-serif;
        }
    </style>
</head>

<body class="bg-gray-50 flex items-center justify-center min-h-screen">
    <div class="w-full max-w-sm bg-white p-6 rounded-2xl shadow space-y-6">
        <img src="crc.png" style="width: 10em;margin-left: auto;margin-right: auto; background: transparent;" alt="Logo">
        <?php if ($error): ?>
            <p class="text-red-600 text-sm text-center"><?= $error ?></p>
        <?php endif; ?>
        <form method="POST" class="space-y-4">
            <input type="text" name="username" placeholder="Username" required
                class="w-full border rounded p-3 focus:ring focus:ring-blue-300" />
            <input type="password" name="password" placeholder="Password" required
                class="w-full border rounded p-3 focus:ring focus:ring-blue-300" />
            <button type="submit"
                class="w-full bg-black text-white py-3 rounded-lg font-semibold hover:bg-gray-800 shadow">
                Login
            </button>
            <br>
            <hr><br>
            <div class="flex justify-center items-center">
            <img src="logo.png" style="width: 6em;" alt="Logo">
            <a href="https://www.elegantwork.co.za" target="_blank"
                class="text-black py-3 rounded-lg font-semibold ml-4 text-1xl" style="font-size: 0.8em;">Developed & hosted by Elegant Work Group (Pty) Ltd</a>
    </div>
    </form>
    </div>
</body>

</html>