<?php
require 'config.php';
if ($_SERVER['REQUEST_METHOD']==='POST') {
  $user = $_POST['user'];
  $pass = md5($_POST['pass']);
  $stmt=$pdo->prepare('SELECT * FROM users WHERE username=? AND password=?');
  $stmt->execute([$user,$pass]);
  if($stmt->fetch()){ $_SESSION['user']=$user; header('Location: index.php'); exit; }
  else $error='❌ اسم المستخدم أو كلمة المرور غير صحيحة';
}
?>
<!doctype html>
<html lang="ar" dir="rtl">
<head><meta charset="utf-8"><title>تسجيل الدخول</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"></head>
<body class="bg-light d-flex align-items-center" style="height:100vh">
<div class="container text-center">
  <div class="card p-4 mx-auto" style="max-width:400px">
    <h4 class="mb-3">🔐 تسجيل الدخول</h4>
    <?php if(!empty($error)): ?><div class="alert alert-danger"><?=$error?></div><?php endif; ?>
    <form method="post">
      <input name="user" class="form-control mb-2" placeholder="اسم المستخدم" required>
      <input name="pass" type="password" class="form-control mb-3" placeholder="كلمة المرور" required>
      <button class="btn btn-primary w-100">دخول</button>
    </form>
  </div>
</div>
</body></html>
