<?php
session_start();

// Hardcoded admin credentials for simplicity. In production, use database & hashing.
$admin_username = 'admin';
$admin_password = 'password123';

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = $_POST['username'] ?? '';
    $password = $_POST['password'] ?? '';
    
    if ($username === $admin_username && $password === $admin_password) {
        $_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 - Land Vista</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        body { background-color: var(--primary); display: flex; align-items: center; justify-content: center; height: 100vh; }
        .login-box {
            background: white;
            padding: 40px;
            border-radius: 8px;
            width: 100%;
            max-width: 400px;
            box-shadow: var(--shadow-lg);
            text-align: center;
        }
        .form-control {
            width: 100%; padding: 12px; margin-bottom: 20px;
            border: 1px solid var(--border); border-radius: 4px;
        }
        .btn-block { width: 100%; padding: 12px; }
        .error { color: #e74c3c; margin-bottom: 20px; font-weight: bold; }
    </style>
</head>
<body>
    <div class="login-box">
        <h2 style="font-family: var(--font-heading); color: var(--primary); margin-bottom: 30px;">Admin Access</h2>
        <?php if ($error): ?>
            <div class="error"><?php echo htmlspecialchars($error); ?></div>
        <?php endif; ?>
        <form method="POST" action="login.php">
            <input type="text" name="username" class="form-control" placeholder="Username (admin)" required>
            <input type="password" name="password" class="form-control" placeholder="Password (password123)" required>
            <button type="submit" class="btn btn-primary btn-block">Log In</button>
        </form>
        <div style="margin-top: 20px;">
            <a href="index.php" style="color: var(--text-light); text-decoration: underline;">Back to Website</a>
        </div>
    </div>
</body>
</html>
