<?php
require_once __DIR__ . '/../src/bootstrap.php';
require_once __DIR__ . '/../src/functions.php';
if (isLoggedIn()) redirect('index.php');
$flash = getFlash();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = trim($_POST['username'] ?? '');
    $password = (string)($_POST['password'] ?? '');
    if (attemptLogin($username, $password)) {
        flash('Giriş başarılı.');
        redirect('index.php');
    }
    flash('Kullanıcı adı veya şifre hatalı.', 'error');
    redirect('login.php');
}
?><!doctype html><html lang="tr"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Giriş</title>
<style>*{box-sizing:border-box}body{margin:0;font-family:Arial,Helvetica,sans-serif;background:#f5f7fb;display:flex;align-items:center;justify-content:center;min-height:100vh;padding:20px}.card{width:100%;max-width:420px;background:#fff;border-radius:18px;box-shadow:0 10px 30px rgba(0,0,0,.08);padding:28px}input{width:100%;padding:12px 14px;border:1px solid #d1d5db;border-radius:12px;margin-bottom:12px}.btn{width:100%;padding:12px 18px;border:0;border-radius:12px;background:#2563eb;color:#fff;font-weight:700;cursor:pointer}.flash{padding:14px 16px;border-radius:12px;margin-bottom:18px;font-size:14px}.flash.error{background:#fee2e2;color:#991b1b}.flash.success{background:#dcfce7;color:#166534}</style></head><body><div class="card"><h1 style="margin-top:0">Mail Paneli Giriş</h1><?php if($flash):?><div class="flash <?= e($flash['type']) ?>"><?= e($flash['message']) ?></div><?php endif; ?><form method="post"><input type="text" name="username" placeholder="Kullanıcı adı" required><input type="password" name="password" placeholder="Şifre" required><button class="btn" type="submit">Giriş Yap</button></form></div></body></html>