<?php
require_once 'config.php';

if (isset($_GET['logout'])) {
    session_destroy(); header('Location: login.php'); exit;
}

if (isset($_SESSION['logged_in'])) {
    header('Location: index.php'); exit;
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($_POST['username'] === ADMIN_USER && $_POST['password'] === ADMIN_PASS) {
        $_SESSION['logged_in'] = true;
        $_SESSION['login_time'] = time();
        header('Location: index.php'); exit;
    }
    $error = 'Kullanıcı adı veya şifre hatalı!';
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UA Changer — Giriş</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;background:#0A0E1A;color:#F0F4FF;min-height:100vh;display:flex;align-items:center;justify-content:center}
.login-box{background:#111827;border:1px solid #1E2D45;border-radius:16px;padding:40px;width:100%;max-width:380px}
.logo{text-align:center;margin-bottom:28px}
.logo .icon{font-size:40px;display:block;margin-bottom:8px}
.logo .brand{color:#00D4FF;font-size:11px;font-weight:700;letter-spacing:2px}
.logo h1{font-size:20px;font-weight:700;margin-top:4px}
.form-group{margin-bottom:16px}
.form-group label{display:block;color:#7B8DB0;font-size:12px;font-weight:600;margin-bottom:6px}
.form-group input{width:100%;background:#0A0E1A;border:1px solid #1E2D45;color:#F0F4FF;padding:11px 14px;border-radius:8px;font-size:14px;outline:none}
.form-group input:focus{border-color:#00D4FF}
.btn{width:100%;padding:12px;background:#00D4FF;color:#0A0E1A;border:none;border-radius:8px;font-size:14px;font-weight:700;cursor:pointer;letter-spacing:.5px;margin-top:8px}
.btn:hover{background:#0099BB}
.error{background:#2B0D0D;border:1px solid #FF4757;color:#FF4757;padding:10px 14px;border-radius:8px;font-size:13px;margin-bottom:16px}
.footer{text-align:center;margin-top:20px;color:#3D4F6E;font-size:12px}
.footer a{color:#7B8DB0;text-decoration:none}
</style>
</head>
<body>
<div class="login-box">
    <div class="logo">
        <span class="icon">⚡</span>
        <div class="brand">UA CHANGER</div>
        <h1>Lisans Paneli</h1>
    </div>
    <?php if ($error): ?>
    <div class="error">❌ <?= htmlspecialchars($error) ?></div>
    <?php endif; ?>
    <form method="POST">
        <div class="form-group">
            <label>KULLANICI ADI</label>
            <input type="text" name="username" autofocus placeholder="admin">
        </div>
        <div class="form-group">
            <label>ŞİFRE</label>
            <input type="password" name="password" placeholder="••••••••">
        </div>
        <button type="submit" class="btn">GİRİŞ YAP →</button>
    </form>
    <div class="footer">
        <a href="https://t.me/enployer" target="_blank">✈ @enployer</a>
    </div>
</div>
</body>
</html>
