<?php
session_start();
$message = "";

// Login logic remains the same
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $inputUser = $_POST['username'] ?? '';
    $inputPass = $_POST['password'] ?? '';

    if (!empty($inputUser) && !empty($inputPass)) {
        if (($handle = fopen("users.csv", "r")) !== FALSE) {
            $authenticated = false;
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                if ($data[0] === $inputUser && $data[1] === $inputPass) {
                    $authenticated = true;
                    break;
                }
            }
            fclose($handle);

            if ($authenticated) {
                $_SESSION['username'] = $inputUser;
                header("Location: dashboard.php");
                exit();
            } else {
                $message = "Invalid Admin Credentials.";
            }
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Access & Resources</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0;
        }

        .login-container {
            background: #fff;
            padding: 40px;
            border-radius: 12px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 350px;
            text-align: center;
        }

        h2 { margin-bottom: 10px; color: #333; }
        .subtitle { color: #888; font-size: 0.85rem; margin-bottom: 25px; display: block; }

        .message {
            background: #ffebee;
            color: #c62828;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
            font-size: 0.9rem;
        }

        .input-group { text-align: left; margin-bottom: 15px; }
        label { display: block; margin-bottom: 5px; color: #666; font-size: 0.9rem; }

        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            box-sizing: border-box;
            transition: border-color 0.3s;
        }

        input:focus { border-color: #667eea; outline: none; }

        input[type="submit"] {
            width: 100%;
            padding: 12px;
            background: #333; /* Darker for Admin look */
            color: white;
            border: none;
            border-radius: 6px;
            font-weight: bold;
            cursor: pointer;
            transition: background 0.3s;
            margin-top: 10px;
        }
        input[type="submit"]:hover { background: #000; }

        /* --- STUDENT DOWNLOAD SECTION --- */
        .student-section {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        
        .download-text {
            display: block;
            font-size: 0.8rem;
            color: #777;
            margin-bottom: 10px;
        }

        .download-btn {
            display: block;
            background: #667eea;
            color: white;
            padding: 12px;
            text-decoration: none;
            border-radius: 6px;
            font-weight: bold;
            font-size: 0.9rem;
            transition: opacity 0.3s;
        }
        .download-btn:hover { opacity: 0.9; }
    </style>
</head>
<body>

<div class="login-container">
    <h2>Admin Portal</h2>
    <span class="subtitle">Management Login</span>
    
    <?php if(!empty($message)): ?>
        <div class="message"><?php echo $message; ?></div>
    <?php endif; ?>

    <form method="post" action="">
        <div class="input-group">
            <label>Username</label>
            <input type="text" name="username" placeholder="Admin User" readonly onfocus="this.removeAttribute('readonly');" autocomplete="off" required>
        </div>
        
        <div class="input-group">
            <label>Password</label>
            <input type="password" name="password" placeholder="••••••••" required>
        </div>
        
        <input type="submit" value="Login to Dashboard">
    </form>

    <div class="student-section">
        <span class="download-text">Students: Get your lab files here</span>
        <a href="mysql.zip" class="download-btn" download>
            📥 Download mysql.zip
        </a>
    </div>
</div>

</body>
</html>
