<!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>Administration — <?= htmlspecialchars(Setting::get('site_name', '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-img {
            max-height: 44px;
            max-width: 220px;
            object-fit: contain;
        }

        .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: 24px;
            text-align: center;
        }

        .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: 12px 14px;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            font-size: 14px;
            color: #1e293b;
            background: #f8fafc;
            transition: border-color 0.2s, box-shadow 0.2s;
            outline: none;
        }

        .form-group input::placeholder {
            color: #94a3b8;
        }

        .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>
    <?php
        $siteName = Setting::get('site_name', 'TubePress');
        $siteLogo = Setting::get('site_logo', '');
    ?>
    <div class="login-wrapper">
        <div class="login-logo">
            <?php if ($siteLogo): ?>
                <img src="/uploads/branding/<?= htmlspecialchars($siteLogo) ?>" alt="<?= htmlspecialchars($siteName) ?>" class="login-logo-img">
            <?php else: ?>
                <div class="brand">Tube<span>Press</span></div>
            <?php endif; ?>
            <p>Administration Panel</p>
        </div>

        <div class="login-card">
            <h2>Sign In</h2>

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

            <form method="POST" action="<?= htmlspecialchars(AdminController::loginUrl()) ?>">
                <?= Router::csrfField() ?>

                <div class="form-group">
                    <label for="email">Email address</label>
                    <input type="email" id="email" name="email" required autofocus
                           placeholder="admin@example.com"
                           value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
                </div>

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

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

        <div class="login-footer">
            <a href="/">Back to site</a>
        </div>
    </div>
</body>
</html>
