<?php
require ("dbconnect.php");

$msg = "";
if(isset($_POST['submit'])){
    $email = mysqli_real_escape_string($con, $_POST['email']);   
    $password = mysqli_real_escape_string($con, $_POST['password']);

    $sql = "SELECT * FROM admin_users WHERE email = '$email' AND password = '$password'";
    $res = mysqli_query($con, $sql);
    $count = mysqli_num_rows($res);

    if($count > 0){
        session_start();
        $_SESSION['ADMIN_LOGIN'] = 'yes';
        $_SESSION['ADMIN_EMAIL'] = $email;
        header("location: dashboard.php");
        die();
    } else {
        $msg = "Please enter valid 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>
<link rel="stylesheet" href="../css1/bootstrap.css" />
<link rel="stylesheet" href="../css1/font-awesome.min.css" />
<style>
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');

  /* Reset and base */
  * {
    box-sizing: border-box;
  }
  body, html {
    margin: 0; padding: 0; height: 100%;
    font-family: 'Poppins', sans-serif;
    background: url('admin.jpg') no-repeat center center fixed;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /* Overlay to darken background */
  body::before {
    content: "";
    position: fixed;
    top:0; left:0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.55);
    z-index: 0;
  }

  /* Login Container */
  .login-container {
    position: relative;
    background: rgba(255 255 255 / 0.12);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border-radius: 20px;
    max-width: 400px;
    width: 90%;
    padding: 40px 30px 35px;
    color: white;
    z-index: 1;
    text-align: center;
  }

  /* Company Logo and Name */
  .logo-container {
    margin-bottom: 30px;
  }

  .logo-container img {
    max-width: 100px;
    height: auto;
    margin-bottom: 12px;
  }

  .company-name {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 2px;
    color: #ffd700; /* Gold-ish */
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.7);
  }

  /* Title */
  .login-container h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 25px;
    letter-spacing: 1px;
    color: #f0f0f0;
  }

  /* Form inputs */
  .form-group {
    margin-bottom: 18px;
    text-align: left;
  }
  .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #e0e0e0;
  }
  .form-group input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    outline: none;
    transition: box-shadow 0.3s ease;
    background: rgba(255 255 255 / 0.85);
    color: #222;
  }
  .form-group input:focus {
    box-shadow: 0 0 10px 2px #ffd700;
    background: #fff;
  }

  /* Icons inside labels */
  label i {
    margin-right: 8px;
    color: #ffd700;
  }

  /* Submit button */
  .btn-primary {
    width: 100%;
    padding: 14px 0;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, #ffd700, #ffbb00);
    border: none;
    color: #222;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.8);
    transition: background 0.3s ease, transform 0.25s ease;
  }
  .btn-primary:hover,
  .btn-primary:focus {
    background: linear-gradient(135deg, #ffbb00, #e6ac00);
    transform: scale(1.05);
    outline: none;
  }

  /* Error message */
  .text-danger {
    margin-top: 20px;
    font-weight: 600;
    font-size: 16px;
    color: #ff5555;
    min-height: 24px;
  }

  /* Responsive */
  @media (max-width: 480px) {
    .login-container {
      padding: 30px 20px 30px;
    }
    .company-name {
      font-size: 22px;
    }
    .login-container h2 {
      font-size: 20px;
    }
    .btn-primary {
      font-size: 16px;
      padding: 12px 0;
    }
  }
</style>
</head>
<body>
  <div class="login-container" role="main" aria-label="Admin Login Form">
    <div class="logo-container">
      <!-- Replace the src with your company logo URL -->
      <img src="logo.png" alt="Company Logo" />
      <div class="company-name" aria-label="Company Name">FALAK ENTERPRISES</div>
    </div>

    <h2>Admin Login</h2>

    <form action="" method="post" novalidate>
      <div class="form-group">
        <label for="email"><i class="fa fa-user fa-fw"></i>Email *</label>
        <input
          type="email"
          name="email"
          id="email"
          class="form-control"
          placeholder="admin@example.com"
          required
          autocomplete="username"
        />
      </div>
      <div class="form-group">
        <label for="password"><i class="fa fa-lock fa-fw"></i>Password *</label>
        <input
          type="password"
          name="password"
          id="password"
          class="form-control"
          placeholder="Enter your password"
          required
          autocomplete="current-password"
        />
      </div>
      <div class="form-group">
        <button type="submit" name="submit" class="btn btn-primary" aria-label="Login to admin panel">Login</button>
      </div>
    </form>

    <div class="text-danger" role="alert" aria-live="assertive"><?php echo $msg ?></div>
  </div>
</body>
</html>
