<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="noindex, nofollow">
    <title>Two-Factor Authentication — TubePress</title>
    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #f1f5f9;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 24px;
            color: #1e293b;
        }

        .login-wrapper {
            width: 100%;
            max-width: 420px;
        }

        .login-logo {
            text-align: center;
            margin-bottom: 32px;
        }

        .login-logo .brand {
            font-size: 32px;
            font-weight: 800;
            letter-spacing: -0.5px;
            color: #1e293b;
        }

        .login-logo .brand span {
            color: #6366f1;
        }

        .login-logo p {
            font-size: 13px;
            color: #94a3b8;
            margin-top: 6px;
        }

        .login-card {
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 16px;
            padding: 36px;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
        }

        .login-card h2 {
            font-size: 20px;
            font-weight: 700;
            color: #1e293b;
            margin-bottom: 8px;
            text-align: center;
        }

        .login-card .subtitle {
            font-size: 13px;
            color: #94a3b8;
            text-align: center;
            margin-bottom: 24px;
        }

        .alert {
            padding: 12px 16px;
            border-radius: 10px;
            font-size: 13px;
            margin-bottom: 20px;
            line-height: 1.5;
        }

        .alert-error {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: #dc2626;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: #475569;
            margin-bottom: 6px;
        }

        .form-group input {
            width: 100%;
            padding: 14px;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            font-size: 24px;
            font-family: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
            color: #1e293b;
            background: #f8fafc;
            text-align: center;
            letter-spacing: 0.5em;
            transition: border-color 0.2s, box-shadow 0.2s;
            outline: none;
        }

        .form-group input::placeholder {
            color: #cbd5e1;
            letter-spacing: 0.3em;
        }

        .form-group input:focus {
            border-color: #6366f1;
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
            background: #ffffff;
        }

        .btn-login {
            width: 100%;
            padding: 13px 20px;
            background: #6366f1;
            color: #fff;
            font-size: 14px;
            font-weight: 600;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            transition: background 0.2s, transform 0.1s;
            margin-top: 4px;
        }

        .btn-login:hover {
            background: #4f46e5;
        }

        .btn-login:active {
            transform: scale(0.98);
        }

        .login-footer {
            text-align: center;
            margin-top: 24px;
            font-size: 12px;
            color: #94a3b8;
        }

        .login-footer a {
            color: #6366f1;
            text-decoration: none;
        }

        .login-footer a:hover {
            color: #4f46e5;
        }
    </style>
</head>
<body>
    <div class="login-wrapper">
        <div class="login-logo">
            <div class="brand">Tube<span>Press</span></div>
            <p>Administration Panel</p>
        </div>

        <div class="login-card">
            <h2>Two-Factor Authentication</h2>
            <p class="subtitle">Enter the 6-digit code from your authenticator app</p>

            <?php if (!empty($error)): ?>
                <div class="alert alert-error"><?= htmlspecialchars($error) ?></div>
            <?php endif; ?>

            <form method="POST" action="<?= htmlspecialchars(AdminController::loginUrl() . '/2fa') ?>">
                <?= Router::csrfField() ?>

                <div class="form-group">
                    <label for="code">Verification code</label>
                    <input type="text" id="code" name="code" required autofocus
                           maxlength="6" pattern="\d{6}" inputmode="numeric" autocomplete="one-time-code"
                           placeholder="000000">
                </div>

                <button type="submit" class="btn-login">Verify</button>
            </form>
        </div>

        <div class="login-footer">
            <a href="<?= htmlspecialchars(AdminController::loginUrl() . '/logout') ?>">Sign out</a>
        </div>
    </div>

    <script>
    document.getElementById('code').addEventListener('input', function() {
        this.value = this.value.replace(/\D/g, '');
        if (this.value.length === 6) {
            this.closest('form').submit();
        }
    });
    </script>
</body>
</html>
