<!doctype html>
<html lang="en" data-theme="dark">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login — {{ project_name }} Provisioning</title>
  <script>
    (function() {
      var t = localStorage.getItem("prov-theme");
      if (t) document.documentElement.setAttribute("data-theme", t);
    })();
  </script>
  <link href="/public/css/provisioning.css" rel="stylesheet">
</head>
<body class="bg-base-100 min-h-screen flex items-center justify-center">

<div class="card bg-base-200 shadow-xl w-full max-w-sm">
  <div class="card-body gap-4">
    <div class="text-center">
      <span class="text-3xl">⚙</span>
      <h1 class="text-xl font-bold font-mono mt-1">{{ project_name }}</h1>
      <p class="text-base-content/50 text-sm">Provisioning Daemon</p>
    </div>

    {% if error %}
    <div class="alert alert-error py-2 text-sm">
      <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
          d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
      </svg>
      <span>{{ error }}</span>
    </div>
    {% endif %}

    <form id="login-form" method="post" action="/ui/login" class="flex flex-col gap-3">
      <div class="form-control">
        <label class="label pb-1">
          <span class="label-text text-xs font-mono">Password / Token</span>
        </label>
        <input
          id="password-input"
          type="password"
          name="password"
          class="input input-bordered input-sm font-mono"
          placeholder="••••••••"
          autocomplete="current-password"
          autofocus
          required
        >
      </div>
      <button type="submit" class="btn btn-primary btn-sm mt-1">Sign in</button>
    </form>

    <p class="text-center text-xs text-base-content/30 font-mono">
      JWT token · shared secret · control-center delegation
    </p>
  </div>
</div>

<script>
(function() {
  var KEY    = "prov-auth";
  var TTL_MS = 7 * 24 * 60 * 60 * 1000; // matches server cookie Max-Age=604800

  // Login page being rendered means the server session is dead — clear the hint.
  try { localStorage.removeItem(KEY); } catch(_) {}

  // On submit: record expiry only (no credential stored).
  document.getElementById("login-form").addEventListener("submit", function() {
    try {
      localStorage.setItem(KEY, JSON.stringify({ expires_at: Date.now() + TTL_MS }));
    } catch(_) {}
  });
})();
</script>
</body>
</html>
