<?php
/**
 * Branch Admin — Login View
 *
 * Standalone login form for branch admin authentication.
 * Posts to $bp/branch/login with branch_code and password.
 * "Branch Admin Panel" branding.
 *
 * Login uses branch_code (e.g. GMBR01) + password (e.g. 123456)
 */
$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>Branch Admin Login | Gmind Institute</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 {
            margin: 0;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #0d47a1 0%, #1565c0 50%, #1976d2 100%);
            font-family: 'Inter', sans-serif;
        }
        .branch-login-container {
            width: 100%;
            max-width: 420px;
            padding: 20px;
        }
        .branch-login-card {
            background: #fff;
            border-radius: 16px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            padding: 40px;
        }
        .branch-login-logo {
            text-align: center;
            margin-bottom: 32px;
        }
        .branch-login-logo h1 {
            font-family: 'Poppins', sans-serif;
            font-size: 28px;
            font-weight: 700;
            color: #0d47a1;
            margin: 0;
        }
        .branch-login-logo .logo-sub {
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: 3px;
            color: #ff9800;
            font-weight: 600;
        }
        .branch-login-logo .logo-badge {
            display: inline-block;
            background: #ff9800;
            color: #1a1a2e;
            font-size: 10px;
            font-weight: 700;
            padding: 3px 8px;
            border-radius: 4px;
            margin-top: 8px;
        }
        .branch-login-field {
            margin-bottom: 20px;
        }
        .branch-login-field label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: #333;
            margin-bottom: 6px;
        }
        .branch-login-field input {
            width: 100%;
            padding: 12px 14px;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.2s;
            box-sizing: border-box;
        }
        .branch-login-field input:focus {
            outline: none;
            border-color: #1565c0;
        }
        .branch-login-field .field-hint {
            font-size: 12px;
            color: #888;
            margin-top: 4px;
        }
        .branch-login-btn {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #0d47a1, #1565c0);
            color: #fff;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.1s, box-shadow 0.2s;
        }
        .branch-login-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(13,71,161,0.4);
        }
        .branch-login-btn:active {
            transform: translateY(0);
        }
        .branch-login-alert {
            padding: 12px 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 14px;
        }
        .branch-login-alert-error {
            background: #fde8e8;
            color: #c0392b;
            border: 1px solid #f5c6c6;
        }
        .branch-login-alert-success {
            background: #e8f5e9;
            color: #27ae60;
            border: 1px solid #c8e6c9;
        }
        .branch-login-back {
            text-align: center;
            margin-top: 20px;
        }
        .branch-login-back a {
            color: #fff;
            text-decoration: none;
            font-size: 14px;
            opacity: 0.8;
        }
        .branch-login-back a:hover {
            opacity: 1;
            text-decoration: underline;
        }
        .branch-login-alt {
            text-align: center;
            margin-top: 16px;
            padding-top: 16px;
            border-top: 1px solid #eee;
        }
        .branch-login-alt a {
            color: #1565c0;
            text-decoration: none;
            font-size: 13px;
            font-weight: 500;
        }
        .branch-login-alt a:hover {
            text-decoration: underline;
        }
        @media (max-width: 480px) {
            .branch-login-card {
                padding: 28px 20px;
            }
        }
    </style>
</head>
<body>
    <div class="branch-login-container">
        <div class="branch-login-card">
            <div class="branch-login-logo">
                <h1>GMIND</h1>
                <div class="logo-sub">Institute</div>
                <div class="logo-badge">Branch Admin Panel</div>
            </div>

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

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

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

                <div class="branch-login-field">
                    <label for="branch_code">Branch Code</label>
                    <input type="text" name="branch_code" id="branch_code" required
                           placeholder="e.g. GMBR01"
                           value="<?= htmlspecialchars($_POST['branch_code'] ?? '', ENT_QUOTES, 'UTF-8') ?>"
                           autocomplete="username" autofocus
                           style="text-transform: uppercase;">
                    <div class="field-hint">Enter your branch code (e.g. GMBR01)</div>
                </div>

                <div class="branch-login-field">
                    <label for="password">Password</label>
                    <input type="password" name="password" id="password" required
                           placeholder="Enter your password"
                           autocomplete="current-password">
                </div>

                <button type="submit" class="branch-login-btn">Sign In</button>
            </form>

            <div class="branch-login-alt">
                <a href="<?= $bp ?>/admin/login">Admin Login &rarr;</a>
            </div>
        </div>

        <div class="branch-login-back">
            <a href="<?= $bp ?>/">&larr; Back to Website</a>
        </div>
    </div>
</body>
</html>
