<?php
session_start();
include "../db.php";

if($_POST){

$user=$_POST['username'];
$pass=md5($_POST['password']);

$q=$conn->query("SELECT * FROM admin WHERE username='$user' AND password='$pass'");

if($q->num_rows>0){

$_SESSION['admin']="yes";
header("location:dashboard.php");

}else{

$error="Invalid Login";

}

}
?>

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Admin Login</title>

<style>

/* GLOBAL */

body{
margin:0;
font-family:Arial;
background:#009688;
display:flex;
align-items:center;
justify-content:center;
height:100vh;
}

/* LOGIN CARD */

.login-card{
background:white;
padding:30px;
border-radius:10px;
box-shadow:0 4px 15px rgba(0,0,0,0.2);
width:100%;
max-width:360px;
}

/* TITLE */

.login-title{
text-align:center;
font-size:22px;
margin-bottom:20px;
color:#009688;
font-weight:bold;
}

/* FORM */

form{
display:flex;
flex-direction:column;
gap:12px;
}

label{
font-size:14px;
font-weight:bold;
}

/* INPUT */

input{
padding:10px;
border:1px solid #ddd;
border-radius:6px;
font-size:14px;
}

/* BUTTON */

button{
background:#009688;
color:white;
border:none;
padding:10px;
border-radius:6px;
font-size:15px;
cursor:pointer;
margin-top:5px;
}

button:hover{
background:#00796b;
}

/* ERROR */

.error{
color:red;
text-align:center;
font-size:13px;
margin-bottom:10px;
}

</style>

</head>

<body>

<div class="login-card">

<div class="login-title">Admin Login</div>

<?php if(isset($error)){ ?>
<div class="error"><?php echo $error ?></div>
<?php } ?>

<form method="post">

<label>Username</label>
<input name="username" required>

<label>Password</label>
<input type="password" name="password" required>

<button type="submit">Login</button>

</form>

</div>

</body>
</html>