<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Sign in</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>
    :root {
      --bg: #f6f7fb;
      --card: #ffffff;
      --text: #222;
      --muted: #6b7280;
      --primary: #2b7cff;
      --danger: #e53935;
      --border: #e5e7eb;
      --radius: 12px;
    }

    * { box-sizing: border-box; }
    html, body { height: 100%; }
    body {
      margin: 0;
      font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
      background: var(--bg);
      color: var(--text);
      display: grid;
      place-items: center;
      padding: 16px;
    }

    .card {
      width: 100%;
      max-width: 360px;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: 0 10px 25px rgba(0,0,0,.06);
      padding: 24px;
    }

    h1 {
      font-size: 20px;
      margin: 0 0 4px;
      text-align: center;
    }
    p.sub {
      margin: 0 0 16px;
      text-align: center;
      color: var(--muted);
      font-size: 14px;
    }

    label {
      display: block;
      font-size: 13px;
      margin: 12px 0 6px;
      color: var(--muted);
    }

    input[type="email"],
    input[type="password"],
    input[type="text"] {
      width: 100%;
      padding: 10px 12px;
      border: 1px solid var(--border);
      border-radius: 10px;
      font-size: 14px;
      outline: none;
      background: #fff;
    }
    input:focus {
      border-color: #c7d2fe;
      box-shadow: 0 0 0 4px rgba(59,130,246,.12);
    }

    .row {
      display: flex;
      gap: 8px;
      align-items: center;
    }

    .btn {
      width: 100%;
      margin-top: 14px;
      padding: 10px 12px;
      border: 0;
      border-radius: 10px;
      background: var(--primary);
      color: #fff;
      font-weight: 600;
      cursor: pointer;
      font-size: 14px;
    }
    .btn:disabled { opacity: .7; cursor: not-allowed; }

    .err {
      margin-top: 12px;
      color: var(--danger);
      font-size: 13px;
      text-align: center;
    }

    .foot {
      margin-top: 14px;
      font-size: 12px;
      color: var(--muted);
      text-align: center;
    }

    .pw-wrap {
      position: relative;
    }
    .pw-toggle {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 12px;
      color: var(--muted);
      background: transparent;
      border: 0;
      cursor: pointer;
      padding: 4px 6px;
    }
  </style>
</head>
<body>
  <form class="card" method="post" action="/login" autocomplete="on" novalidate>
    <h1>Sign in</h1>
    <p class="sub">Use your email and password</p>

    <label for="email">Email</label>
    <input
      id="email"
      name="email"
      type="email"
      placeholder="admin@example.com"
      autocomplete="email"
      required
      autofocus
    />

    <label for="password">Password</label>
    <div class="pw-wrap">
      <input
        id="password"
        name="password"
        type="password"
        placeholder="••••••••"
        autocomplete="current-password"
        required
      />
      <button type="button" class="pw-toggle" aria-label="Show password" id="togglePw">Show</button>
    </div>

    <button class="btn" type="submit">Login</button>

    {% if error %}
      <div class="err">{{ error }}</div>
    {% endif %}

    <div class="foot">You’ll be redirected based on your role.</div>
  </form>

  <script>
    // Password show/hide toggle
    (function () {
      const pw = document.getElementById('password');
      const btn = document.getElementById('togglePw');
      btn.addEventListener('click', function () {
        const isPw = pw.type === 'password';
        pw.type = isPw ? 'text' : 'password';
        btn.textContent = isPw ? 'Hide' : 'Show';
        btn.setAttribute('aria-label', isPw ? 'Hide password' : 'Show password');
      });
    }());
  </script>
</body>
</html>
