<?php
$error = $_SESSION['admin_login_error'] ?? '';
unset($_SESSION['admin_login_error']);
$accessParam = defined('ADMIN_ACCESS_PARAM') ? ADMIN_ACCESS_PARAM : 'key';
$accessValue = isset($_GET[$accessParam]) ? $_GET[$accessParam] : (defined('ADMIN_ACCESS_SECRET') ? ADMIN_ACCESS_SECRET : '');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin Login</title>
    <style>
        * { box-sizing: border-box; }
        body { font-family: system-ui, -apple-system, sans-serif; margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #1a1a2e; color: #eee; }
        .box { width: 100%; max-width: 360px; padding: 2rem; background: #16213e; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
        h1 { margin: 0 0 1.5rem; font-size: 1.5rem; text-align: center; }
        label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: #a0a0a0; }
        input[type=text], input[type=password] { width: 100%; padding: 0.6rem 0.75rem; margin-bottom: 1rem; border: 1px solid #0f3460; border-radius: 6px; background: #0f3460; color: #fff; font-size: 1rem; }
        input:focus { outline: none; border-color: #e94560; }
        button { width: 100%; padding: 0.75rem; background: #e94560; color: #fff; border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; }
        button:hover { background: #c73e54; }
        .error { background: #c73e54; color: #fff; padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
    </style>
</head>
<body>
    <div class="box">
        <h1>Admin Login</h1>
        <?php if ($error): ?>
            <div class="error"><?= htmlspecialchars($error) ?></div>
        <?php endif; ?>
        <form method="post" action="/admin/login<?= admin_access_query_string() ?>">
            <?php if ($accessValue !== ''): ?>
            <input type="hidden" name="<?= htmlspecialchars($accessParam) ?>" value="<?= htmlspecialchars($accessValue) ?>">
            <?php endif; ?>
            <label>Username</label>
            <input type="text" name="username" required autocomplete="username" value="">
            <label>Password</label>
            <input type="password" name="password" required autocomplete="current-password">
            <button type="submit">Login</button>
        </form>
    </div>
</body>
</html>
