<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($_POST['username'] === 'Melafex' && $_POST['password'] === 'Think45%') {
        $_SESSION['admin'] = true;
        header('Location: dashboard.php');  // corrected path
        exit();
    }
    $error = "Invalid login!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <style>
        h2{ 
            text-align: center; 
            font-size: 28px;
            padding: 10px;
            color: #dc3545;
        }
        form{
            width: 40%;
            background-color: whitesmoke;
            margin: 20px auto;
            border-radius: 20px;
            padding: 20px;
        }
        input{
            padding: 15px;
            width: 90%;
            margin: 5px auto;
            border-radius: 10px;
            background-color: white;
            border: none;
        }
        button{
            width: 25%;
            padding: 15px;
            border-radius: 10px;
            background-color: #dc3545;
            color: #fff;
            border: none;
            margin: 10px;
        }

        @media screen AND (max-width:500px){
            h2{ 
            text-align: center; 
            font-size: 28px;
            padding: 10px;
            color: #dc3545;
            }
            form{
                width: 90%;
                background-color: whitesmoke;
                margin: 20px auto;
                border-radius: 20px;
                padding: 20px;
            }
            input{
                padding: 15px;
                width: 90%;
                margin: 5px auto;
                border-radius: 10px;
                background-color: white;
                border: none;
            }
            button{
                width: 25%;
                padding: 15px;
                border-radius: 10px;
                background-color: #dc3545;
                color: #fff;
                border: none;
                margin: 10px;
            }
        }
    </style>
</head>
<body>
    <h2>Admin Login</h2>
    <form method="post">
    <?php if (!empty($error)) echo "<p>$error</p>"; ?>
    <input type="text" name="username" placeholder="Username" required><br/>
    <input type="password" name="password" placeholder="Password" required><br/>
    <button type="submit">Login</button>
    </form>
</body>
</html>

