<?php
require_once '../includes/config.php';

if (isAdmin()) { header('Location: /volker/admin/'); exit; }

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = trim($_POST['username'] ?? '');
    $password = $_POST['password'] ?? '';

    try {
        $stmt = db()->prepare("SELECT * FROM vs_admins WHERE username=?");
        $stmt->execute([$username]);
        $admin = $stmt->fetch(PDO::FETCH_ASSOC);

        if ($admin && password_verify($password, $admin['password'])) {
            $_SESSION['vs_admin'] = $admin['id'];
            $_SESSION['vs_admin_name'] = $admin['username'];
            header('Location: /volker/admin/');
            exit;
        } else {
            $error = 'Kullanıcı adı veya şifre hatalı.';
        }
    } catch(Exception $e) {
        $error = 'Bağlantı hatası.';
    }
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Admin Girişi — VOLKER SAVUNMA</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;900&display=swap" rel="stylesheet">
<style>
*{margin:0;padding:0;box-sizing:border-box;}
body{font-family:'Inter',sans-serif;background:#0a0a0a;color:#fff;min-height:100vh;display:flex;align-items:center;justify-content:center;}
.login-box{width:100%;max-width:400px;padding:24px;}
.login-logo{text-align:center;margin-bottom:40px;}
.login-logo-icon{width:56px;height:56px;background:#e02020;clip-path:polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%);display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:900;margin:0 auto 14px;}
.login-logo h1{font-size:20px;font-weight:900;letter-spacing:0.08em;}
.login-logo p{font-size:11px;color:#e02020;letter-spacing:0.2em;text-transform:uppercase;margin-top:4px;}
.login-card{background:#111;border:1px solid rgba(255,255,255,0.06);border-radius:12px;padding:36px;}
.login-card h2{font-size:17px;font-weight:700;margin-bottom:24px;}
.form-group{display:flex;flex-direction:column;gap:6px;margin-bottom:16px;}
.form-group label{font-size:11px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:#888;}
.form-group input{background:#1a1a1a;border:1px solid rgba(255,255,255,0.08);border-radius:6px;padding:12px 14px;color:#fff;font-size:14px;outline:none;transition:all 0.2s;}
.form-group input:focus{border-color:#e02020;box-shadow:0 0 0 3px rgba(224,32,32,0.1);}
.btn-login{width:100%;padding:14px;background:#e02020;color:#fff;border:none;border-radius:6px;font-size:13px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;cursor:pointer;margin-top:8px;transition:all 0.2s;}
.btn-login:hover{background:#b51a1a;}
.error{background:rgba(224,32,32,0.1);border:1px solid rgba(224,32,32,0.3);color:#e02020;padding:12px;border-radius:6px;font-size:13px;margin-bottom:16px;}
.back-link{text-align:center;margin-top:20px;font-size:12px;color:#555;}
.back-link a{color:#888;transition:color 0.2s;}
.back-link a:hover{color:#e02020;}
</style>
</head>
<body>
<div class="login-box">
    <div class="login-logo">
        <div class="login-logo-icon">V</div>
        <h1>VOLKER SAVUNMA</h1>
        <p>Admin Paneli</p>
    </div>
    <div class="login-card">
        <h2>Giriş Yapın</h2>
        <?php if ($error): ?><div class="error"><?= clean($error) ?></div><?php endif; ?>
        <form method="POST">
            <div class="form-group">
                <label>Kullanıcı Adı</label>
                <input type="text" name="username" required autofocus value="<?= clean($_POST['username'] ?? '') ?>">
            </div>
            <div class="form-group">
                <label>Şifre</label>
                <input type="password" name="password" required>
            </div>
            <button type="submit" class="btn-login">Giriş Yap</button>
        </form>
    </div>
    <div class="back-link"><a href="/volker/">← Siteye Dön</a></div>
</div>
</body>
</html>
