<?php
session_start();
$config_file = __DIR__ . '/config.json';
$config = is_array($c = json_decode(@file_get_contents($config_file), true)) ? $c : ["user" => "admin", "pass" => "pass123"];
$err = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $u = (string)($_POST['user'] ?? '');
    $p = (string)($_POST['pass'] ?? '');
    if ($u === ($config['user'] ?? 'admin') && $p === ($config['pass'] ?? 'pass123')) {
        $_SESSION['logged_in'] = 1;
        header("Location: index.php");
        exit;
    } else {
        $err = "Invalid username or password";
    }
}
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Neutro Panel | Login</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <style>
    body{background:#0b0e14;color:#fff;font-family:system-ui,Arial,sans-serif;}
    .card{background:#151921;border:1px solid #2d343f;border-radius:12px;}
    .form-control{background:#0b0e14;border:1px solid #2d343f;color:#fff;border-radius:8px;}
    .form-control:focus{background:#000;border-color:#007bff;color:#fff;box-shadow:none;}
  </style>
</head>
<body>
  <div class="container" style="max-width:520px;padding-top:70px;">
    <div class="text-center mb-4">
      <h3 class="mb-1">Neutro Panel</h3>
      <div class="text-muted">Login to manage DNS</div>
    </div>
    <div class="card p-4">
      <?php if($err): ?><div class="alert alert-danger"><?php echo htmlspecialchars($err); ?></div><?php endif; ?>
      <form method="post">
        <div class="form-group">
          <label class="text-muted small">Username</label>
          <input class="form-control" name="user" autocomplete="username" required>
        </div>
        <div class="form-group">
          <label class="text-muted small">Password</label>
          <input class="form-control" type="password" name="pass" autocomplete="current-password" required>
        </div>
        <button class="btn btn-primary btn-block">Login</button>
      </form>
    </div>
    <div class="text-center text-muted small mt-3">
      API endpoint: <span style="color:#00d4ff;">portals.json</span>
    </div>
  </div>
</body>
</html>
