<?php 
session_start();
include "../includes/config.php"; 
?>

<?php
if ($_POST) {
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $pass = md5($_POST['password']);

    $check = $conn->query("SELECT * FROM admins WHERE email='$email' AND password='$pass'");
    if ($check && $check->num_rows > 0) {
        $admin = $check->fetch_assoc();
        $_SESSION['admin_id'] = $admin['id'];
        $_SESSION['admin_name'] = $admin['name'];
        $_SESSION['admin_email'] = $admin['email'];
        header("Location: ../index.php");
        exit;
    } else {
        $error = "Invalid email or password";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login - First Choice</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        min-height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .login-box {
        background: white;
        padding: 40px;
        border-radius: 10px;
        box-shadow: 0 10px 25px rgba(0,0,0,0.2);
        width: 100%;
        max-width: 400px;
    }
    .login-box h3 {
        text-align: center;
        margin-bottom: 30px;
        color: #333;
        font-weight: 600;
    }
    .form-control {
        border: 1px solid #ddd;
        border-radius: 5px;
        padding: 10px 15px;
        margin-bottom: 15px;
        font-size: 14px;
    }
    .form-control:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
    }
    .btn-dark {
        background-color: #667eea;
        border: none;
        padding: 10px;
        font-weight: 600;
        width: 100%;
        margin-top: 10px;
    }
    .btn-dark:hover {
        background-color: #764ba2;
    }
    .alert {
        margin-bottom: 20px;
    }
</style>
</head>
<body>

<div class="login-box">
    <h3>First Choice Admin</h3>
    <?php if (isset($error)): ?>
        <div class="alert alert-danger" role="alert">
            <?= $error ?>
        </div>
    <?php endif; ?>
    
    <form method="post">
        <input type="email" name="email" class="form-control" placeholder="Email" required>
        <input type="password" name="password" class="form-control" placeholder="Password" required>
        <button class="btn btn-dark">Login</button>
    </form>
    
    <hr>
    <small class="text-muted d-block text-center">Demo: admin@firstchoice.com / admin123</small>
</div>

</body>
</html>
