<?php 
session_start();
$error = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST["username"];
    $password = $_POST["password"];

    $admin_user = "admin";
    $admin_pass = "hesed123";

    if ($username === $admin_user && $password === $admin_pass) {
        $_SESSION["admin_logged_in"] = true;
        header("Location: dashboard.php");
        exit();
    } else {
        $error = "Invalid login details.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Admin Login</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        html, body {
            height: 100%;
            width: 100%;
            font-family: Arial, sans-serif;
            background: #fff;
        }
        .container {
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 0 10px; /* small horizontal padding on very narrow screens */
        }
        .login-box {
            width: 100%;
            max-width: 480px;
            padding: 30px;
            border-radius: 8px;
            background: #ffffff;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            /* Removed scale zoom for better mobile */
        }
        .login-box h2 {
            margin-bottom: 18px;
            text-align: center;
            font-size: 28px;
            color: #333;
        }
        .login-box input {
            width: 100%;
            padding: 14px;
            margin-bottom: 16px;
            border: 1px solid #ccc;
            border-radius: 6px;
            font-size: 16px;
        }
        .btn {
            width: 100%;
            padding: 14px;
            background: #007bff;
            color: #fff;
            border: none;
            font-size: 16px;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .btn:hover {
            background: #0056b3;
        }
        .error {
            color: red;
            font-size: 15px;
            text-align: center;
            margin-top: 10px;
        }

        /* Responsive adjustments */
        @media (max-width: 480px) {
            .login-box {
                padding: 20px;
                box-shadow: none;
                border-radius: 0;
            }
            .login-box h2 {
                font-size: 24px;
                margin-bottom: 15px;
            }
            .login-box input {
                padding: 12px;
                font-size: 14px;
            }
            .btn {
                padding: 12px;
                font-size: 14px;
            }
        }
    </style>
</head>
<body>

<div class="container">
    <form method="post" class="login-box" novalidate>
        <h2>Admin Login</h2>
        <input type="text" name="username" placeholder="Username" required autocomplete="username" />
        <input type="password" name="password" placeholder="Password" required autocomplete="current-password" />
        <button class="btn" type="submit">Login</button>
        <?php if ($error): ?>
            <div class="error"><?= htmlspecialchars($error) ?></div>
        <?php endif; ?>
    </form>
</div>

</body>
</html>
