<?php
require_once __DIR__ . '/../app/auth.php';
$error = null;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $u = trim($_POST['username'] ?? '');
  $p = trim($_POST['password'] ?? '');
  if (login_user($u, $p)) {
    header("Location: /dashboard.php");
    exit;
  }
  $error = "Invalid login";
}
?>
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <title>Jellyfin Reseller Panel</title>
  <style>
    body{font-family:system-ui;margin:0;display:grid;place-items:center;min-height:100vh;background:#0b1220;color:#e6e6e6}
    .card{width:min(420px,92vw);background:#111a2e;border:1px solid #233055;border-radius:16px;padding:22px}
    input{width:100%;padding:12px;border-radius:12px;border:1px solid #2a3a66;background:#0b1220;color:#fff;margin:8px 0}
    button{width:100%;padding:12px;border-radius:12px;border:0;background:#3b82f6;color:#fff;font-weight:600;cursor:pointer}
    .err{background:#2a1220;border:1px solid #6b2142;padding:10px;border-radius:12px;margin-bottom:10px}
    .muted{opacity:.75;font-size:13px}
  </style>
</head>
<body>
  <div class="card">
    <h2 style="margin:0 0 8px 0;">Reseller Panel</h2>
    <div class="muted">Login to manage resellers, credits, and Jellyfin users.</div>
    <div style="height:14px"></div>
    <?php if ($error): ?><div class="err"><?= htmlspecialchars($error) ?></div><?php endif; ?>
    <form method="post">
      <input name="username" placeholder="Username" autocomplete="username" required />
      <input name="password" placeholder="Password" type="password" autocomplete="current-password" required />
      <button type="submit">Sign in</button>
    </form>
  </div>
</body>
</html>
