<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login — <?= esc($app_name ?? 'FT Teluk Betung') ?></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
body { background: #0f172a; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; }
.login-card .card { border: 0; border-radius: 1rem; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.login-card .card-header {
    background: #1e293b; border-radius: 1rem 1rem 0 0 !important;
    text-align: center; padding: 2rem 1.5rem 1.25rem; border-bottom: 1px solid #334155;
}
.login-card .card-header .app-icon {
    width: 52px; height: 52px; background: #3b82f6; border-radius: .75rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; color: #fff; margin: 0 auto 1rem;
}
.login-card .card-header h5 { color: #f8fafc; font-weight: 700; margin: 0 0 .25rem; }
.login-card .card-header small { color: #64748b; }
.login-card .card-body { padding: 1.75rem 1.5rem 1.5rem; }
.form-control { background: #1e293b; border: 1px solid #334155; color: #f1f5f9; }
.form-control:focus { background: #1e293b; border-color: #3b82f6; color: #f1f5f9; box-shadow: 0 0 0 .2rem rgba(59,130,246,.25); }
.form-control::placeholder { color: #64748b; }
.form-label { color: #94a3b8; font-size: .85rem; font-weight: 500; }
</style>
</head>
<body>
<div class="login-card">
    <div class="card bg-dark text-white">
        <div class="card-header">
            <div class="app-icon"><i class="bi bi-database-fill"></i></div>
            <h5><?= esc($app_name ?? 'FT Teluk Betung') ?></h5>
            <small>Data Manager</small>
        </div>
        <div class="card-body" style="background:#0f172a; border-radius:0 0 1rem 1rem;">
            <?php if ($error ?? null): ?>
            <div class="alert alert-danger py-2 mb-3" style="font-size:.85rem;">
                <i class="bi bi-exclamation-circle me-1"></i> <?= esc($error) ?>
            </div>
            <?php endif; ?>

            <form action="<?= base_url('login') ?>" method="POST">
                <?= csrf_field() ?>
                <div class="mb-3">
                    <label class="form-label">Username</label>
                    <div class="input-group">
                        <span class="input-group-text bg-dark border-secondary text-secondary"><i class="bi bi-person"></i></span>
                        <input type="text" name="username" class="form-control" placeholder="Masukkan username" value="<?= esc(old('username')) ?>" required autofocus>
                    </div>
                </div>
                <div class="mb-4">
                    <label class="form-label">Password</label>
                    <div class="input-group">
                        <span class="input-group-text bg-dark border-secondary text-secondary"><i class="bi bi-lock"></i></span>
                        <input type="password" name="password" id="passwordInput" class="form-control" placeholder="Masukkan password" required>
                        <button type="button" class="btn btn-outline-secondary border-secondary" onclick="togglePwd()">
                            <i class="bi bi-eye" id="eyeIcon"></i>
                        </button>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary w-100 fw-semibold">
                    <i class="bi bi-box-arrow-in-right me-1"></i> Login
                </button>
            </form>
        </div>
    </div>
</div>
<script>
function togglePwd() {
    const inp = document.getElementById('passwordInput');
    const ico = document.getElementById('eyeIcon');
    if (inp.type === 'password') { inp.type = 'text'; ico.className = 'bi bi-eye-slash'; }
    else { inp.type = 'password'; ico.className = 'bi bi-eye'; }
}
</script>
</body>
</html>
