<?php
require_once __DIR__ . '/../config.php';
if (!empty($_SESSION['admin_logged_in'])) {
  header('Location: index.php');
  exit;
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  if (admin_login((string) ($_POST['username'] ?? ''), (string) ($_POST['password'] ?? ''))) {
    header('Location: index.php');
    exit;
  }
  $error = 'Login failed.';
}
?>
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Admin Login</title><link rel="stylesheet" href="../assets/css/style.css"></head>
<body>
<div class="site-shell" style="max-width:520px;padding-top:60px">
  <div class="card">
    <h2>Admin Login</h2>
    <?php if ($error): ?><div class="banner danger"><?= esc($error) ?></div><?php endif; ?>
    <form method="post">
      <label>Username</label><input type="text" name="username" required>
      <label>Password</label><input type="password" name="password" required>
      <div class="toolbar"><button type="submit">Log In</button></div>
    </form>
    <p class="meta">Default login is admin / admin. Change the password hash from Site Control after first login.</p>
  </div>
</div>
</body></html>
