<?php
session_start();
require_once(__DIR__ . "/../config/db.php");

$error = "";

// Already logged in
if (isset($_SESSION['student_id'])) {
    header("Location: /rs_lab/student/lei_dashboard.php");
    exit;
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {

    $roll = trim($_POST['roll'] ?? '');
    $name = trim($_POST['name'] ?? '');

    if ($roll === "" || $name === "") {
        $error = "Student name and roll number required";
    } else {

        // OPTIONAL: DB check (simple demo login)
        // If you already have students table, later improve pannalaam

        $_SESSION['student_id']   = $roll;
        $_SESSION['student_name'] = $name;

        header("Location: /rs_lab/student/lei_dashboard.php");
        exit;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Student Login | RS Learning Lab</title>
    <style>
        body{
            background:radial-gradient(circle at top,#020617,#0f172a);
            font-family:Arial;
            color:#e5e7eb;
        }
        .box{
            width:400px;
            margin:100px auto;
            background:#020617;
            padding:30px;
            border-radius:16px;
            box-shadow:0 0 40px rgba(11,140,159,.35);
        }
        input,button{
            width:100%;
            padding:12px;
            margin-top:12px;
            border-radius:10px;
            border:none;
            background:#0f172a;
            color:#fff;
        }
        button{
            background:linear-gradient(135deg,#2563eb,#22c55e);
            font-weight:bold;
            cursor:pointer;
        }
        .err{
            color:#f87171;
            text-align:center;
        }
    </style>
</head>
<body>

<div class="box">
    <h2>Student Login</h2>

    <?php if ($error): ?>
        <p class="err"><?= htmlspecialchars($error) ?></p>
    <?php endif; ?>

    <form method="POST">
        <input type="text" name="name" placeholder="Student Name">
        <input type="text" name="roll" placeholder="Roll Number">
        <button type="submit">Login</button>
    </form>
</div>

</body>
</html>