<?php
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
    header("location: main.php");
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: linear-gradient(135deg, #0f172a, #1e293b);
            font-family: 'Inter', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            overflow: hidden;
        }
        
        .login-container {
            background: rgba(30, 41, 59, 0.7);
            backdrop-filter: blur(15px);
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
            width: 100%;
            max-width: 400px;
            text-align: center;
            border: 1px solid rgba(255, 255, 255, 0.1);
            position: relative;
            z-index: 10;
        }
        
        .title {
            font-size: 2.5rem;
            font-weight: 800;
            background: linear-gradient(90deg, #22d3ee, #0ea5e9);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-bottom: 2rem;
            letter-spacing: -0.5px;
        }
        
        .input-field {
            width: 100%;
            padding: 14px;
            margin-bottom: 20px;
            background: rgba(15, 23, 42, 0.7);
            border: 2px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            color: #e2e8f0;
            font-size: 1rem;
            transition: all 0.3s ease;
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
        }
        
        .input-field:focus {
            outline: none;
            border-color: #22d3ee;
            box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
        }
        
        .btn {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #0ea5e9, #22d3ee);
            color: white;
            font-size: 1.1rem;
            font-weight: 600;
            border-radius: 12px;
            border: none;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
        }
        
        .forgot-password {
            font-size: 0.9rem;
            color: #94a3b8;
            text-decoration: none;
            margin-top: 15px;
            display: block;
            transition: color 0.3s ease;
        }
        
        .forgot-password:hover {
            color: #22d3ee;
        }
        
        .social-icons {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-top: 25px;
        }
        
        .social-icons a {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(15, 23, 42, 0.7);
            color: #22d3ee;
            font-size: 1.3rem;
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .social-icons a:hover {
            transform: translateY(-5px);
            background: linear-gradient(135deg, #0ea5e9, #22d3ee);
            color: white;
            box-shadow: 0 5px 15px rgba(14, 165, 233, 0.4);
        }
        
        footer {
            margin-top: 25px;
            font-size: 0.85rem;
            color: #64748b;
        }
        
        .error-message {
            background: rgba(220, 38, 38, 0.2);
            border: 1px solid rgba(220, 38, 38, 0.3);
            border-radius: 8px;
            padding: 10px;
            margin-bottom: 20px;
            font-size: 0.9rem;
        }
        
        .particles {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
        }
        
        .particle {
            position: absolute;
            border-radius: 50%;
            background: linear-gradient(135deg, #22d3ee, #0ea5e9);
            opacity: 0.2;
            animation: float 15s infinite linear;
        }
        
        @keyframes float {
            0% {
                transform: translateY(0) translateX(0) rotate(0deg);
                opacity: 0.2;
            }
            100% {
                transform: translateY(-100vh) translateX(100px) rotate(360deg);
                opacity: 0;
            }
        }
    </style>
</head>
<body>
    <div class="particles" id="particles"></div>
    
    <div class="login-container">
        <h1 class="title">ADMIN PANEL</h1>

        <?php if (isset($_GET['error'])): ?>
            <div class="error-message">
                <i class="fas fa-exclamation-circle mr-2"></i><?= htmlspecialchars($_GET['error']) ?>
            </div>
        <?php endif; ?>

        <form action="authenticate.php" method="post">
            <div class="relative mb-6">
                <i class="fas fa-user absolute left-4 top-1/2 transform -translate-y-1/2 text-slate-400"></i>
                <input class="input-field pl-12" type="text" name="username" placeholder="Username" required>
            </div>
            
            <div class="relative mb-6">
                <i class="fas fa-lock absolute left-4 top-1/2 transform -translate-y-1/2 text-slate-400"></i>
                <input class="input-field pl-12" type="password" name="password" placeholder="Password" required>
            </div>

            <button class="btn" type="submit">
                <i class="fas fa-sign-in-alt mr-2"></i> SIGN IN
            </button>

            <a href="https://telegram.me/codexgaunt/" class="forgot-password">
                <i class="fas fa-key mr-1"></i> Forgot Password?
            </a>
        </form>

        <div class="social-icons">
            <a href="https://telegram.me/codexgaunt/"><i class="fab fa-telegram"></i></a>
            <a href="https://telegram.me/codexgaunt/"><i class="fab fa-whatsapp"></i></a>
            <a href="https://telegram.me/codexgaunt/"><i class="fab fa-discord"></i></a>
        </div>

        <footer>
            &copy; <?= date("Y") ?> DexWEBS. All rights reserved.
        </footer>
    </div>
    
    <script>
        // Create animated particles
        const container = document.getElementById('particles');
        const particleCount = 20;
        
        for (let i = 0; i < particleCount; i++) {
            const particle = document.createElement('div');
            particle.classList.add('particle');
            
            // Random size (3px to 8px)
            const size = Math.random() * 5 + 3;
            particle.style.width = `${size}px`;
            particle.style.height = `${size}px`;
            
            // Random position
            particle.style.left = `${Math.random() * 100}%`;
            particle.style.top = `${Math.random() * 100}%`;
            
            // Random animation duration (10s to 20s)
            const duration = Math.random() * 10 + 10;
            particle.style.animation = `float ${duration}s infinite linear`;
            
            // Random delay
            particle.style.animationDelay = `${Math.random() * 5}s`;
            
            container.appendChild(particle);
        }
    </script>
</body>
</html>