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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST["username"];
    $password = $_POST["password"];

    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $result = $conn->query($sql);

    if ($result->num_rows == 1) {
        $row = $result->fetch_assoc();
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['username'] = $row['username'];
        $_SESSION['role'] = $row['role'];
        header("Location: allsettings.php");
    } else {
        $error = "نام کاربری یا رمز اشتباه است!";
    }
}
?>
<header>
    
</header>
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>ورود</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="login-box">
  <h2>ورود به سیستم</h2>
  <form method="post">
    <input type="text" name="username" placeholder="نام کاربری" required><br>
    <input type="password" name="password" placeholder="رمز عبور" required><br>
    <button type="submit">ورود</button>
    <a href="forgot_password.php" style="
    display:block;
    margin-top:15px;
    font-size:14px;
    color:#2980b9;
    text-decoration:none;
">
فراموشی رمز عبور؟
</a>

  </form>
  <?php if(isset($error)) echo "<p class='error'>$error</p>"; ?>
</div>
</body>
</html>


<style type="text/css">
  @import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;600&display=swap');

body {
  font-family: 'Vazirmatn', sans-serif;
  background: linear-gradient(135deg, #2980b9, #6dd5fa, #ffffff);
  background-size: 400% 400%;
  animation: gradientMove 12s ease infinite;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  direction: rtl;
  margin: 0;
}

@keyframes gradientMove {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-box {
  background: #ffffff;
  padding: 40px 35px;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  text-align: center;
  width: 350px;
}

.login-box h2 {
  margin-bottom: 25px;
  color: #333;
  font-size: 22px;
  font-weight: 600;
}

.login-box input[type="text"],
.login-box input[type="password"] {
  width: 100%;
  padding: 12px 15px;
  margin: 10px 0;
  border: 1px solid #ccc;
  border-radius: 10px;
  font-size: 15px;
  transition: all 0.3s ease;
}

.login-box input[type="text"]:focus,
.login-box input[type="password"]:focus {
  border-color: #3498db;
  outline: none;
  box-shadow: 0 0 6px rgba(52,152,219,0.5);
}

.login-box button {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  background: linear-gradient(90deg, #3498db, #2ecc71);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.4s ease, transform 0.2s ease;
}

.login-box button:hover {
  background: linear-gradient(90deg, #2ecc71, #3498db);
  transform: scale(1.03);
}

.error {
  margin-top: 15px;
  color: #e74c3c;
  font-weight: 600;
  font-size: 14px;
}

  
</style>