<?php
declare(strict_types=1);
require __DIR__ . '/config.php';
session_start();

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = trim((string)($_POST['username'] ?? ''));
    $password = (string)($_POST['password'] ?? '');

    if ($username === ADMIN_USERNAME && password_verify($password, ADMIN_PASSWORD_HASH)) {
        $_SESSION['colorjet_admin_logged_in'] = true;
        header('Location: dashboard.php');
        exit;
    }
    $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">
<title>COLORJET Admin Login</title>
<link rel="stylesheet" href="../assets/css/style.css">
</head>
<body>
<main>
<section class="page-hero">
<div class="container">
<span class="eyebrow">Admin Login</span>
<h1>COLORJET Lead Admin</h1>
<p>Login to view website leads saved by the PHP backend.</p>
</div>
</section>
<section class="section">
<div class="container" style="max-width:560px">
<form class="quote-builder" method="post">
<?php if ($error): ?><div class="security-box"><?= h($error) ?></div><?php endif; ?>
<div class="form-control"><label>Username</label><input name="username" required></div>
<div class="form-control" style="margin-top:14px"><label>Password</label><input type="password" name="password" required></div>
<div class="cta-row" style="margin-top:18px"><button class="btn btn-primary" type="submit">Login</button><a class="btn btn-glass" href="../index.html">Back to Website</a></div>
</form>
</div>
</section>
</main>
</body>
</html>
