<?php 
require 'vendors/fungsi/fungsi.php'; 
$login_failed = false;
if (isset($_POST['daftar'])) {
  $proses_login = $proses->login();
  if ($proses_login === false) {
    $login_failed = true;
  }
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Toko Mastor — Masuk</title>
  <meta name="description" content="Masuk ke sistem POS Kasir Kita — manajemen toko dan kasir modern.">
  <link rel="icon" type="image/png" href="vendors/img/logo_kasir_kita.png">
  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <!-- Premium Design System -->
  <link rel="stylesheet" href="vendors/custom_modern.css">
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  <style>
    body {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: var(--bg-main);
      padding: 20px;
    }

    /* Background dots pattern */
    body::before {
      content: '';
      position: fixed;
      inset: 0;
      background-image: radial-gradient(var(--border) 1px, transparent 1px);
      background-size: 24px 24px;
      opacity: 0.6;
      pointer-events: none;
      z-index: 0;
    }

    .login-wrap {
      position: relative;
      z-index: 1;
      width: 100%;
      max-width: 480px;
    }

    .login-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 28px;
      padding: 52px 48px 48px;
      box-shadow: var(--shadow-md);
      position: relative;
      overflow: hidden;
    }

    .login-card::before {
      content: '';
      position: absolute;
      top: 0; left: 0;
      width: 4px; height: 100%;
      background: linear-gradient(180deg, var(--primary) 0%, var(--primary-muted) 100%);
    }

    .login-logo-wrap {
      text-align: center;
      margin-bottom: 28px;
    }

    .login-logo {
      width: 72px;
      height: 72px;
      border-radius: 18px;
      object-fit: cover;
      border: 2px solid var(--border);
      margin-bottom: 18px;
      display: inline-block;
    }

    .login-title {
      font-size: 2rem;
      font-weight: 800;
      color: var(--primary);
      letter-spacing: -0.03em;
      margin: 0 0 4px;
      font-family: 'Plus Jakarta Sans', sans-serif;
    }

    .login-subtitle {
      font-size: 0.95rem;
      color: var(--text-muted);
      font-weight: 500;
      margin: 0;
    }

    .login-form-group {
      margin-bottom: 18px;
    }

    .login-form-group label {
      display: block;
      font-size: 0.78rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--text-secondary);
      margin-bottom: 6px;
    }

    .login-input {
      width: 100%;
      padding: 14px 18px;
      border: 1px solid var(--border);
      border-radius: 14px;
      background: var(--surface-2);
      font-family: 'Plus Jakarta Sans', sans-serif;
      font-size: 1rem;
      color: var(--text-main);
      transition: all 0.2s ease;
      box-shadow: none;
      outline: none;
    }

    .login-input:focus {
      background: var(--surface);
      border-color: var(--accent);
      box-shadow: 0 0 0 3px rgba(245, 184, 0, 0.15);
    }

    .login-input::placeholder { color: var(--text-muted); }

    .btn-login {
      display: block;
      width: 100%;
      padding: 16px;
      background: var(--primary);
      color: #FFFFFF;
      border: none;
      border-radius: 14px;
      font-family: 'Plus Jakarta Sans', sans-serif;
      font-size: 1.05rem;
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
      letter-spacing: 0.01em;
      margin-top: 8px;
    }

    .btn-login:hover {
      background: var(--primary-light);
      transform: translateY(-1px);
      box-shadow: 0 6px 20px rgba(26, 58, 42, 0.25);
    }

    .login-footer {
      text-align: center;
      margin-top: 20px;
      font-size: 0.75rem;
      color: var(--text-muted);
    }
  </style>
</head>
<body>
  <div class="login-wrap">
    <div class="login-card">

      <div class="login-logo-wrap">
        <img src="vendors/img/logo_kasir_kita.png" class="login-logo" alt="Toko Mastor">
        <h1 class="login-title">TOKO MASTOR</h1>
        <p class="login-subtitle">Sistem POS &amp; Manajemen Toko</p>
      </div>

      <form action="" method="post" autocomplete="off">
        <div class="login-form-group">
          <label for="login-username">Username</label>
          <input
            id="login-username"
            class="login-input"
            type="text"
            name="user"
            required
            autofocus
            placeholder="Masukkan username"
          >
        </div>

        <div class="login-form-group">
          <label for="login-password">Password</label>
          <input
            id="login-password"
            class="login-input"
            type="password"
            name="pass"
            required
            placeholder="Masukkan password"
          >
        </div>

        <button class="btn-login" type="submit" name="daftar">
          Masuk ke Sistem
        </button>

      </form>

      <div class="login-footer">
        andrian doni &copy; <?= date('Y') ?> &mdash; Semua hak dilindungi
      </div>

    </div>
  </div>

  <?php if ($login_failed): ?>
  <script>
    Swal.fire({
      icon: 'error',
      title: 'Akses Ditolak',
      text: 'Username atau password yang Anda masukkan salah.',
      confirmButtonColor: 'var(--primary)',
      confirmButtonText: 'Coba Lagi',
      background: 'var(--surface)',
      color: 'var(--text-main)',
      customClass: {
        popup: 'swal2-custom-popup'
      }
    });
  </script>
  <?php endif; ?>
</body>
</html>

