<?php
session_start();
include "db.php";

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

$error = "";

if(isset($_POST['login'])){
    $username = $baglan->real_escape_string($_POST['username']);
    $password = $_POST['password'];

    $result = $baglan->query("SELECT * FROM users WHERE username='$username' LIMIT 1");

    if($user = $result->fetch_assoc()){
        if(password_verify($password, $user['password'])){
            $_SESSION['user_id'] = $user['id'];
            $_SESSION['username'] = $user['username'];

            addLog($baglan, "Giriş Yapıldı", "Kullanıcı: $username");

            header("Location: index.php");
            exit;
        }
    }

    $error = "Kullanıcı adı veya şifre hatalı.";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Giriş</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
/* ================= GENEL ================= */
*{
    box-sizing:border-box;
}

body{
    margin:0;
    min-height:100vh;
    background:linear-gradient(135deg,#020617,#020617,#0f172a);
    display:flex;
    align-items:center;
    justify-content:center;
    font-family:Segoe UI,Arial;
    color:white;
}

/* ================= LOGIN BOX ================= */
.login-box{
    background:rgba(15,23,42,0.92);
    padding:32px;
    border-radius:18px;
    width:360px;
    box-shadow:0 0 24px rgba(56,189,248,0.35);
    border:1px solid #1e293b;
}

.login-box h2{
    text-align:center;
    color:#38bdf8;
    margin-bottom:20px;
    font-size:22px;
}

/* ================= INPUT ================= */
input{
    width:100%;
    padding:14px;
    margin:10px 0;
    border-radius:12px;
    border:1px solid #334155;
    background:#020617;
    color:white;
    font-size:15px;
}

input:focus{
    outline:none;
    border-color:#38bdf8;
    box-shadow:0 0 12px rgba(56,189,248,0.4);
}

/* ================= BUTTON ================= */
button{
    width:100%;
    padding:14px;
    margin-top:14px;
    background:linear-gradient(135deg,#0ea5e9,#38bdf8);
    color:white;
    border:none;
    border-radius:14px;
    font-weight:bold;
    font-size:16px;
    cursor:pointer;
    box-shadow:0 0 16px rgba(56,189,248,0.6);
}

button:hover{
    opacity:0.95;
}

/* ================= ERROR ================= */
.error{
    background:#450a0a;
    color:#fecaca;
    padding:12px;
    border-radius:12px;
    margin-bottom:12px;
    text-align:center;
}

/* ================================================= */
/* ================== MOBİL ÖZEL =================== */
/* ================================================= */

@media (max-width: 768px){

    body{
        padding:20px;
    }

    .login-box{
        width:100%;
        max-width:420px;
        padding:28px;
        border-radius:22px;
        box-shadow:0 0 32px rgba(56,189,248,0.55);
    }

    .login-box h2{
        font-size:26px;
        margin-bottom:26px;
    }

    input{
        padding:16px;
        font-size:16px;
        border-radius:16px;
    }

    button{
        padding:16px;
        font-size:17px;
        border-radius:18px;
    }
}
</style>

</head>
<body>

<div class="login-box">

    <h2>🗡 Item Panel Giriş</h2>

    <?php if($error): ?>
        <div class="error"><?= htmlspecialchars($error) ?></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 name="login">Giriş Yap</button>
    </form>

</div>

</body>
</html>
