<?php
require_once 'config.inc.php';
if(!empty($_SESSION['admin_id'])) redirect('index.php');
$error='';
if($_SERVER['REQUEST_METHOD']==='POST'){
 check_csrf();
 $u=trim($_POST['username']??''); $p=$_POST['password']??'';
 $st=db()->prepare("SELECT id,username,password_hash,full_name FROM admins WHERE username=? LIMIT 1");
 $st->bind_param("s",$u);$st->execute();$a=$st->get_result()->fetch_assoc();
 if($a && password_verify($p,$a['password_hash'])){
   session_regenerate_id(true);$_SESSION['admin_id']=$a['id'];$_SESSION['admin_name']=$a['full_name'];redirect('index.php');
 }
 $error='Invalid username or password.';
}
?>
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Admin Login</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>body{min-height:100vh;display:grid;place-items:center;background:linear-gradient(135deg,#101827,#5146e5)}.box{width:min(420px,92vw);background:white;border-radius:20px;padding:35px;box-shadow:0 25px 60px #0004}.ico{font-size:38px;color:#5146e5;text-align:center}</style></head>
<body><div class="box"><div class="ico">📱</div><h3 class="text-center">Phone Display Manager</h3><p class="text-center text-secondary">Administrator Login</p>
<?php if($error):?><div class="alert alert-danger"><?=e($error)?></div><?php endif;?>
<form method="post"><input type="hidden" name="csrf" value="<?=e(csrf())?>">
<input class="form-control mb-3" name="username" placeholder="Username" required>
<input class="form-control mb-4" type="password" name="password" placeholder="Password" required>
<button class="btn btn-primary w-100">Sign In</button></form></div></body></html>
