<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Setec App Manager — Login</title>
    <link rel="icon" type="image/svg+xml" href="/static/img/favicon.svg">
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body class="login-page">
    <div class="login-card">
        <img src="/static/img/logo.svg" alt="Setec" style="width:80px;margin:0 auto 1rem;display:block">
        <h1>SETEC</h1>
        <p class="subtitle">App Manager</p>
        <form id="loginForm" method="POST" action="/login">
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" id="username" name="username" required autofocus>
            </div>
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" id="password" name="password" required>
            </div>
            <button type="submit" class="btn btn-primary">Login</button>
            <div id="error" class="error-msg" style="display:none"></div>
        </form>
    </div>
    <script>
    document.getElementById('loginForm').addEventListener('submit', async (e) => {
        e.preventDefault();
        const res = await fetch('/login', {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({
                username: document.getElementById('username').value,
                password: document.getElementById('password').value
            })
        });
        if (res.ok) {
            window.location.href = '/';
        } else {
            const err = document.getElementById('error');
            err.textContent = 'Invalid credentials';
            err.style.display = 'block';
        }
    });
    </script>
</body>
</html>
