<?php
require_once dirname(__DIR__) . '/inc/auth.php';
auth_start();
if (auth_check()) { header('Location: dashboard.php'); exit; }

$err = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $login = trim($_POST['login'] ?? '');
    $pass  = $_POST['pass'] ?? '';
    if (auth_attempt($login, $pass)) { header('Location: dashboard.php'); exit; }
    $err = 'Identifiant ou mot de passe incorrect.';
}
?><!DOCTYPE html>
<html lang="fr"><head><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connexion — Admin <?= e(SITE_NAME) ?></title>
<link rel="stylesheet" href="admin.css">
</head><body>
<div class="login-wrap">
  <form class="login-box" method="post">
    <img src="../assets/logo.png" alt="<?= e(SITE_NAME) ?>">
    <h1>Espace d'administration</h1>
    <label>Identifiant</label>
    <input type="text" name="login" autofocus required>
    <label>Mot de passe</label>
    <input type="password" name="pass" required>
    <button class="btn" type="submit">Se connecter</button>
    <?php if ($err): ?><div class="err"><?= e($err) ?></div><?php endif; ?>
  </form>
</div>
</body></html>
