<?php

// ini_set('display_errors',1);
session_start();
include "opendb.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $conn->real_escape_string($_POST['username']);
    $password = $conn->real_escape_string($_POST['password']);

    $sql = "SELECT * FROM admin WHERE username='$username' AND password=MD5('$password')";
    $result = $conn->query($sql);

    if ($result->num_rows == 1) {
        $_SESSION['admin'] = $username;
        header("Location: dashboard/index.php");
        exit;
    } else {
        $error = "Invalid username or password!";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Admin Login</title>
    <style>
        /* Global styles */
        body {
            font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #347d90, #1e4d5e);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        /* Login box */
        .login-box {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(12px);
            padding: 40px 30px;
            border-radius: 12px;
            width: 320px;
            text-align: center;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
        }

        .login-box h2 {
            margin-bottom: 20px;
            color: #fff;
            font-size: 24px;
        }
        
        .login-box .username,
        .login-box .password {
            margin-bottom: 15px; /* spacing between fields */
            text-align: left; /* ensures consistency */
        }
        
        /* Input fields */
        .login-box input[type="text"],
        .login-box input[type="password"] {
            width: 100%;
            padding: 12px;
            border: none;
            outline: none;
            border-radius: 8px;
            font-size: 14px;
            background: rgba(255, 255, 255, 0.9);
            box-sizing: border-box; /* ensures padding doesn’t break width */
            display: block; /* makes inputs stack */
        }

        /* Input fields */
        .login-box input {
            width: 100%;
            padding: 12px;
            margin: 10px 0;
            border: none;
            outline: none;
            border-radius: 8px;
            font-size: 14px;
        }

        .login-box input[type="text"],
        .login-box input[type="password"] {
            background: rgba(255, 255, 255, 0.8);
        }

        /* Button */
        .login-box button {
            width: 100%;
            padding: 12px;
            background: #c1d799;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            color: #2f4050;
            transition: 0.3s;
        }

        .login-box button:hover {
            background: #a9c37c;
        }

        /* Error message */
        .error {
            color: #ff4d4d;
            margin-bottom: 15px;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="login-box">
    <h2>Admin Login</h2>
    <?php if (!empty($error)) echo "<p class='error'>$error</p>"; ?>
    <form method="post">
        <div class="username">
            <input type="text" name="username" placeholder="Username" required>
        </div>
        <div class="password">
            <input type="password" name="password" placeholder="Password" required>
        </div>
        <button type="submit">Login</button>
    </form>
</div>
</body>
</html>
