<?php require_once 'config.php'; ?>
<?php
if (is_logged_in()) {
    header('Location: /admin/');
    exit;
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $user = trim($_POST['username'] ?? '');
    $pass = trim($_POST['password'] ?? '');
    if (check_auth($user, $pass)) {
        $_SESSION['admin_logged_in'] = true;
        header('Location: /admin/');
        exit;
    } else {
        $error = '用户名或密码错误';
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后台登录 - 集途教育</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family: -apple-system, 'Segoe UI', sans-serif; background:#f5f7fa; min-height:100vh; display:flex; align-items:center; justify-content:center; }
.login-box { background:#fff; border-radius:12px; box-shadow:0 4px 24px rgba(0,0,0,0.1); padding:40px; width:380px; }
.login-box h1 { font-size:22px; color:#1a1a2e; margin-bottom:8px; }
.login-box p { color:#666; font-size:14px; margin-bottom:28px; }
.form-group { margin-bottom:18px; }
.form-group label { display:block; font-size:13px; color:#333; margin-bottom:6px; font-weight:500; }
.form-group input { width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:15px; outline:none; transition:border 0.2s; }
.form-group input:focus { border-color:#e63946; }
.btn { width:100%; padding:12px; background:#e63946; color:#fff; border:none; border-radius:8px; font-size:15px; font-weight:500; cursor:pointer; transition:background 0.2s; }
.btn:hover { background:#c1121c; }
.error { color:#e63946; font-size:13px; margin-bottom:12px; text-align:center; }
.brand { text-align:center; margin-bottom:24px; }
.brand span { color:#e63946; font-size:28px; }
</style>
</head>
<body>
<div class="login-box">
  <div class="brand"><span>GETTO EDU</span><br>管理后台</div>
  <?php if ($error): ?><div class="error"><?php echo htmlspecialchars($error); ?></div><?php endif; ?>
  <form method="post">
    <div class="form-group">
      <label>用户名</label>
      <input type="text" name="username" required autofocus>
    </div>
    <div class="form-group">
      <label>密码</label>
      <input type="password" name="password" required>
    </div>
    <button class="btn" type="submit">登 录</button>
  </form>
</div>
</body>
</html>
