<?php
session_start();
require_once __DIR__ . '/config.php';
ensure_schema();
$error='';
if($_SERVER['REQUEST_METHOD']==='POST'){
  $u=trim($_POST['username']??'');
  $p=$_POST['password']??'';
  $st=db()->prepare("SELECT * FROM users WHERE username=? AND role='admin' LIMIT 1");
  $st->execute([$u]);
  $user=$st->fetch();
  if(!$user || !password_verify($p,$user['password'])) $error='Giriş başarısız';
  else { $_SESSION['user_id']=(int)$user['id']; $_SESSION['username']=$user['username']; $_SESSION['role']='admin'; header("Location: ".BASE_URL."/admin_requests.php"); exit; }
}
?>
<!doctype html><html lang="tr"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo h(APP_NAME); ?> • Admin Login</title>
<link rel="stylesheet" href="<?php echo h(BASE_URL); ?>/assets/css/app.css"></head>
<body class="frameGlow"><div class="bgDots"></div><div class="network"></div>
<div style="max-width:560px;margin:8vh auto;padding:24px;position:relative;z-index:2">
  <div class="card">
    <div class="cardHeader">
      <div class="cardTitle"><span class="ico"></span><div><div style="font-weight:950;font-size:18px"><?php echo h(APP_NAME); ?></div><div style="color:rgba(155,176,208,.85);font-size:12px"><?php echo h(APP_SUB); ?></div></div></div>
      <span class="badge teal">USER</span>
    </div>
    <div class="body">
      <?php if($error): ?><span class="badge warn" style="display:inline-flex;margin-bottom:12px"><?php echo h($error); ?></span><?php endif; ?>
      <form method="post" autocomplete="off">
        <div class="field" style="margin-bottom:12px"><label>Kullanıcı</label><input class="input" name="username" value="<?php echo h($_POST['username']??'demo'); ?>" required></div>
        <div class="field" style="margin-bottom:14px"><label>Şifre</label><input class="input" type="password" name="password" value="<?php echo h($_POST['password']??'123456'); ?>" required></div>
        <button class="bigBtn" type="submit">GİRİŞ</button>
      </form>
      <div class="note">Demo: <b>demo</b> / <b>123456</b></div>
    </div>
  </div>
</div>
</body></html>
