<?php
require_once "../config/db.php";
session_start();

if ($_POST) {
    $stmt = $pdo->prepare("SELECT * FROM Utilisateur WHERE login=?");
    $stmt->execute([$_POST['login']]);
    $user = $stmt->fetch();

    if ($user && password_verify($_POST['password'], $user['mot_de_passe'])) {
        $_SESSION['user'] = $user;
        header("Location: ../dashboard.php");
        exit;
    }
    $error = "Identifiants incorrects";
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Connexion – Salle Colvert</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">
<style>
body{
    font-family:'Poppins',sans-serif;
    background:url("../assets/img/colvert_sport.jpg") center/cover no-repeat;
    height:100vh;
}
.overlay{position:absolute;inset:0;background:rgba(0,0,0,0.6);}
.card{border-radius:20px;}
</style>
</head>
<body>
<div class="overlay"></div>
<div class="d-flex justify-content-center align-items-center vh-100 position-relative">
<form method="post" class="card p-4 shadow-lg" style="width:380px;">
<h3 class="text-center mb-3">🔐 Connexion</h3>
<?php if(isset($error)): ?><div class="alert alert-danger"><?= $error ?></div><?php endif; ?>
<input class="form-control mb-3" name="login" placeholder="Login" required>
<input class="form-control mb-3" type="password" name="password" placeholder="Mot de passe" required>
<button class="btn btn-success w-100 py-2">Se connecter</button>
</form>
</div>
</body>
</html>
