<?php
/**
 * Login Page — Gmind Institute
 *
 * Clean login form with email, password, CSRF token,
 * forgot password link, and registration link.
 *
 * Expected PHP variables:
 *   $csrfToken   — CSRF token string
 *   $errors      — array of validation errors (optional)
 *   $old         — array of old input values (optional)
 */

$errors    = $errors    ?? [];
$old       = $old       ?? [];
$csrfToken = $csrfToken ?? '';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Gmind Institute — Student Login">
    <title>Login — Gmind Institute</title>

    <!-- Favicon -->
    <link rel="icon" type="image/png" href="<?= asset('/images/favicon.png') ?>">

    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=Poppins:wght@600;700&display=swap" rel="stylesheet">

    <!-- Main Stylesheet -->
    <link rel="stylesheet" href="<?= asset('/css/style.css') ?>">
</head>
<body class="auth-body">

    <div class="auth-container">
        <!-- Branding -->
        <div class="auth-brand">
            <a href="<?= url('/') ?>" aria-label="Gmind Institute — Home">
                <span class="logo-text">GMIND</span>
                <span class="logo-subtext">INSTITUTE</span>
            </a>
        </div>

        <div class="auth-card">
            <h1>Welcome Back</h1>
            <p class="auth-subtitle">Login to your student account</p>

            <?php if (!empty($errors)): ?>
            <div class="alert alert-error" role="alert">
                <?php foreach ($errors as $error): ?>
                <p><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></p>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>

            <form method="POST" action="<?= url('/login') ?>" class="auth-form" novalidate>
                <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8') ?>">

                <div class="form-group">
                    <label for="email">Email Address</label>
                    <div class="input-icon-wrapper">
                        <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>
                        <input type="email" id="email" name="email" required placeholder="Enter your email" value="<?= htmlspecialchars($old['email'] ?? '', ENT_QUOTES, 'UTF-8') ?>" autocomplete="email">
                    </div>
                </div>

                <div class="form-group">
                    <label for="password">Password</label>
                    <div class="input-icon-wrapper">
                        <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg>
                        <input type="password" id="password" name="password" required placeholder="Enter your password" autocomplete="current-password">
                    </div>
                </div>

                <button type="submit" class="btn-primary btn-submit">Login</button>
            </form>

            <div class="auth-links">
                <a href="<?= url('/forgot-password') ?>" class="auth-link">Forgot Password?</a>
                <p>Don't have an account? <a href="<?= url('/register') ?>" class="auth-link">Register</a></p>
            </div>
        </div>

        <div class="auth-back">
            <a href="<?= url('/') ?>">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 18 9 12 15 6"/></svg>
                Back to Website
            </a>
        </div>
    </div>

</body>
</html>
