<?php
require_once __DIR__ . '/core/auth.php';

if (usuario_logado()) {
    header('Location: dashboard.php');
    exit;
}

$erro = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $usuario = trim($_POST['usuario'] ?? '');
    $senha = $_POST['senha'] ?? '';
    $r = tentar_login($usuario, $senha);
    if ($r['ok']) {
        header('Location: dashboard.php');
        exit;
    }
    $erro = $r['msg'];
}
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>COBRANEX — Login</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
  body{
    background:#0a0a12;
    background-image:
      radial-gradient(circle at 15% 20%, rgba(168,85,247,0.18), transparent 40%),
      radial-gradient(circle at 85% 80%, rgba(34,211,238,0.16), transparent 40%),
      radial-gradient(circle at 50% 50%, rgba(59,130,246,0.10), transparent 60%);
  }
  .neon-border{
    border:1px solid rgba(168,85,247,0.4);
    box-shadow: 0 0 20px rgba(168,85,247,0.25), 0 0 60px rgba(34,211,238,0.08) inset;
  }
  .neon-text{
    text-shadow: 0 0 8px rgba(34,211,238,0.75), 0 0 20px rgba(168,85,247,0.5);
  }
  .glow-input:focus{
    box-shadow: 0 0 0 2px rgba(59,130,246,0.6), 0 0 20px rgba(168,85,247,0.4);
  }
</style>
</head>
<body class="min-h-screen flex items-center justify-center text-slate-200 font-sans">

  <div class="w-full max-w-sm mx-4">
    <div class="text-center mb-8">
      <h1 class="text-2xl sm:text-3xl font-black tracking-widest text-transparent bg-clip-text bg-gradient-to-r from-purple-400 via-cyan-400 to-blue-400 neon-text">
        COBRANEX
      </h1>
      <p class="text-xs text-slate-500 mt-1 tracking-wide">GESTÃO DE COBRANÇAS &amp; NOTIFICAÇÕES</p>
    </div>

    <form method="POST" class="bg-slate-900/70 backdrop-blur rounded-2xl p-8 neon-border space-y-5">
      <?php if ($erro): ?>
        <div class="bg-blue-950/60 border border-blue-500/50 text-cyan-300 text-sm rounded-lg px-4 py-2">
          <?= htmlspecialchars($erro) ?>
        </div>
      <?php endif; ?>

      <div>
        <label class="block text-xs uppercase tracking-wider text-purple-300 mb-1">Usuário</label>
        <input type="text" name="usuario" required autofocus
          class="glow-input w-full bg-slate-950/80 border border-slate-700 rounded-lg px-4 py-3 outline-none transition text-slate-100 placeholder-slate-600"
          placeholder="Seu usuário">
      </div>

      <div>
        <label class="block text-xs uppercase tracking-wider text-purple-300 mb-1">Senha</label>
        <input type="password" name="senha" required
          class="glow-input w-full bg-slate-950/80 border border-slate-700 rounded-lg px-4 py-3 outline-none transition text-slate-100 placeholder-slate-600"
          placeholder="••••••••">
      </div>

      <button type="submit"
        class="w-full py-3 rounded-lg font-bold tracking-wide text-white bg-gradient-to-r from-purple-600 via-cyan-500 to-blue-600 hover:brightness-110 transition shadow-lg shadow-blue-900/40">
        ENTRAR
      </button>
    </form>

    <p class="text-center text-slate-600 text-xs mt-6">© <?= date('Y') ?> Nexus Panel · Todos os direitos reservados</p>
  </div>

</body>
</html>
