<?php
require_once __DIR__ . '/includes/auth.php';

if (admin_user()) { header('Location: /admin/index.php'); exit; }

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = trim($_POST['email'] ?? '');
    $password = $_POST['password'] ?? '';
    if (admin_login($email, $password)) {
        header('Location: /admin/index.php');
        exit;
    }
    $error = 'Invalid email or password.';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin Login | Kigali Yacu Properties</title>
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="/assets/css/fonts.css">
<link rel="stylesheet" href="/assets/css/variables.css">
<link rel="stylesheet" href="/assets/css/base.css">
<link rel="stylesheet" href="/assets/css/components.css">
<link rel="stylesheet" href="/assets/css/utilities.css">
</head>
<body style="background:var(--color-black);min-height:100vh;display:flex;align-items:center;justify-content:center;">
<div class="form-card" style="width:100%;max-width:400px;">
  <div class="brand" style="justify-content:center;margin-bottom:var(--space-6);">
    <span class="brand-mark">KY</span>
    <span class="brand-name">Kigali Yacu<small>Properties Admin</small></span>
  </div>
  <?php if ($error): ?><div class="form-error mb-4"><?= e($error) ?></div><?php endif; ?>
  <form method="post">
    <div class="field mb-4">
      <label for="email">Email</label>
      <input type="email" id="email" name="email" required autofocus>
    </div>
    <div class="field mb-5">
      <label for="password">Password</label>
      <input type="password" id="password" name="password" required>
    </div>
    <button type="submit" class="btn btn-primary btn-block">Log In</button>
  </form>
</div>
</body>
</html>
