<?php
/**
 * Branch Admin Login View
 *
 * Standalone login page (not wrapped in layout).
 * Teal-themed to distinguish from /admin/login (navy) and /super-admin/login (purple).
 *
 * Accepts either branch_code (e.g. GMBR01) OR email as login_id.
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($title ?? 'Branch Admin Login', ENT_QUOTES, 'UTF-8') ?> | Gmind Branch</title>
    <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=Poppins:wght@600;700&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= $bp ?>/css/admin.css">
    <style>
        body { background: linear-gradient(135deg, #0d3b3b 0%, #072525 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
        .ba-login-card { background: #fff; border-radius: 16px; max-width: 460px; width: 100%; box-shadow: 0 20px 60px rgba(22, 160, 133, 0.3); overflow: hidden; }
        .ba-login-header { background: linear-gradient(135deg, #16a085, #117a65); color: #fff; padding: 32px 28px; text-align: center; }
        .ba-login-header h1 { margin: 0; font-size: 1.6rem; font-family: 'Poppins', sans-serif; font-weight: 700; }
        .ba-login-header p { margin: 6px 0 0; opacity: 0.85; font-size: 0.9rem; }
        .ba-login-body { padding: 32px 28px; }
        .ba-login-body label { display: block; font-size: 0.85rem; font-weight: 600; color: #0d3b3b; margin-bottom: 6px; }
        .ba-login-body input { width: 100%; padding: 12px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.95rem; transition: border-color 0.2s; box-sizing: border-box; }
        .ba-login-body input:focus { border-color: #16a085; outline: none; box-shadow: 0 0 0 3px rgba(22, 160, 133, 0.1); }
        .ba-login-body button { width: 100%; padding: 14px; background: linear-gradient(135deg, #16a085, #117a65); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; font-family: 'Poppins', sans-serif; transition: transform 0.2s, box-shadow 0.2s; margin-top: 8px; }
        .ba-login-body button:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(22, 160, 133, 0.4); }
        .ba-login-footer { text-align: center; margin-top: 18px; padding-top: 18px; border-top: 1px solid #eee; font-size: 0.85rem; }
        .ba-login-footer a { color: #16a085; text-decoration: none; }
        .ba-login-footer a:hover { text-decoration: underline; }
        .ba-login-badge { display: inline-block; background: rgba(255,255,255,0.2); color: #fff; padding: 4px 14px; border-radius: 50px; font-size: 0.75rem; font-weight: 600; margin-top: 10px; letter-spacing: 0.5px; }
        .ba-login-alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 0.88rem; }
        .ba-login-alert-error { background: #fff5f5; color: #c0392b; border: 1px solid #f5c6cb; }
        .ba-login-alert-success { background: #eafaf1; color: #1e7e34; border: 1px solid #c3e6cb; }
        .ba-form-group { margin-bottom: 18px; }
        .ba-hint { font-size: 0.78rem; color: #999; margin-top: 4px; }
    </style>
</head>
<body>
    <div class="ba-login-card">
        <div class="ba-login-header">
            <h1>GMIND INSTITUTE</h1>
            <p>Branch Admin Panel</p>
            <span class="ba-login-badge">BRANCH LOGIN</span>
        </div>

        <div class="ba-login-body">
            <?php if (!empty($flash_error)): ?>
                <div class="ba-login-alert ba-login-alert-error"><?= htmlspecialchars($flash_error, ENT_QUOTES, 'UTF-8') ?></div>
            <?php endif; ?>
            <?php if (!empty($flash_success)): ?>
                <div class="ba-login-alert ba-login-alert-success"><?= htmlspecialchars($flash_success, ENT_QUOTES, 'UTF-8') ?></div>
            <?php endif; ?>

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

                <div class="ba-form-group">
                    <label for="login_id">Branch Code or Email</label>
                    <input type="text" id="login_id" name="login_id" placeholder="GMBR01 or branch@gmindinstitute.in" required autofocus
                           value="<?= htmlspecialchars($_POST['login_id'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
                    <div class="ba-hint">Enter your branch code (e.g. GMBR01) or the email registered with your account.</div>
                </div>

                <div class="ba-form-group">
                    <label for="password">Password</label>
                    <input type="password" id="password" name="password" placeholder="Enter your password" required>
                </div>

                <button type="submit">Sign In to Branch Panel</button>
            </form>

            <div class="ba-login-footer">
                <a href="<?= $bp ?>/branch/register">Apply for a New Franchise &rarr;</a>
                <br><br>
                <a href="<?= $bp ?>/super-admin/login">Super Admin Login</a>
                <span style="margin: 0 8px; color: #999;">|</span>
                <a href="<?= $bp ?>/admin/login">Website Admin</a>
                <br><br>
                <a href="<?= $bp ?>/" style="color:#999;">Back to Website</a>
            </div>
        </div>
    </div>
</body>
</html>
