<?php
// admin/login_admin.php
session_start();
if (isset($_SESSION['admin_id'])) {
    header('Location: dashboard.php');
    exit;
}

$error_message = $_SESSION['error_message'] ?? '';$error_message = $_SESSION['error_message'] ?? '';
unset($_SESSION['error_message']);
?>
<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Admin Login</title>

  <!-- Bootstrap & Icons -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" rel="stylesheet">
  <link href="styles/login_admin.css" rel="stylesheet">
  <link rel="shortcut icon" href="/assets/favicon.ico">

  <style>
    /* ---------- Fireflies Effect ---------- */
    :root {
      --neon: #ff0033; 
    }
    .firefly {
      position: fixed;
      width: 8px;
      height: 8px;
      border-radius: 50%;
      pointer-events: none;
      background: radial-gradient(circle, var(--neon) 0%, transparent 60%);
      filter: drop-shadow(0 0 6px var(--neon));
      animation: move 12s linear infinite, shine 3s ease-in-out infinite alternate;
    }
    .firefly::after {
      content: "";
      position: absolute;
      inset: -6px;
      border-radius: 50%;
      background: radial-gradient(circle, rgba(255,0,51,0.4) 0%, rgba(255,0,51,0) 70%);
      filter: blur(4px);
    }
    @keyframes move {
      to { transform: translate(150px, -120px) rotate(360deg) scale(1.2); }
    }
    @keyframes shine {
      0%, 100% { opacity: 0.9; }
      50%      { opacity: 0.3; }
    }
  </style>
</head>

<body class="login-bg d-flex align-items-center justify-content-center position-relative">
  <?php
  // Generar luciérnagas en el fondo
  for ($i = 0; $i < 40; $i++):
    $top    = rand(0, 100);
    $left   = rand(0, 100);
    $d1     = rand(10, 18);
    $d2     = rand(2, 5);
    $del1   = rand(0, 40) / 10;
    $del2   = rand(0, 30) / 10;
  ?>
    <div class="firefly"
         style="
           top: <?= $top ?>vh;
           left: <?= $left ?>vw;
           animation-duration: <?= $d1 ?>s, <?= $d2 ?>s;
           animation-delay: -<?= $del1 ?>s, -<?= $del2 ?>s;
         ">
    </div>
  <?php endfor; ?>

  <main class="container">
    <div class="row justify-content-center">
      <div class="col-11 col-sm-9 col-md-7 col-lg-5 col-xl-4">
        <div class="card neon-box text-white">
          <div class="card-body text-center p-4">

            <img src="assets/logo.png" alt="Logo Admin" class="mb-3 logo">
            <h2 class="fw-bold mb-4">
              <i class="fas fa-user-shield me-2"></i> Admin Login
            </h2>

            <?php if ($error_message): ?>
              <div class="alert alert-danger py-2 small">
                <i class="fas fa-exclamation-triangle me-1"></i> <?= $error_message ?>
              </div>
            <?php endif; ?>

            <form action="procesa_admin_login.php" method="POST" class="text-start needs-validation" novalidate>
              <div class="mb-3">
                <label class="form-label small"><i class="fas fa-user me-1"></i> Usuario</label>
                <input name="username" class="form-control bg-dark text-white" placeholder="Tu usuario" required>
              </div>

              <div class="mb-4">
                <label class="form-label small"><i class="fas fa-key me-1"></i> Contraseña</label>
                <input type="password" name="password" class="form-control bg-dark text-white" placeholder="••••••••" required>
              </div>

              <button class="btn btn-neon w-100">
                <i class="fas fa-sign-in-alt me-2"></i> Ingresar
              </button>
            </form>

            <div class="small mt-3">
              <a href="forgot_password.php" class="link-light text-decoration-none">
                ¿Olvidaste tu contraseña?
              </a>
            </div>

          </div>
        </div>
      </div>
    </div>
  </main>

  <!-- Bootstrap JS -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
