<?php
$a = random_int(2, 15);
$b = random_int(2, 15);
$_SESSION['security_expected'] = $a + $b;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In · Hammerhead Workspace</title>
<link rel="stylesheet" href="/assets/css/app.css">
<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">
</head>
<body>
<div class="login-wrap">
  <div class="abstract-shape shape-1"></div>
  <div class="abstract-shape shape-2"></div>
  <div class="abstract-shape shape-3"></div>
  <div class="dot-grid"></div>
  <div class="login-hero">
    <div class="workflow-layer">
      <svg viewBox="0 0 600 700" xmlns="http://www.w3.org/2000/svg">
        <path d="M60,70 C160,45 220,110 320,90 C420,70 460,130 560,110" stroke="#4f6ef7" stroke-width="1.5" fill="none" stroke-dasharray="4 6"/>
        <path d="M80,610 C180,590 240,640 340,615 C440,590 480,640 570,620" stroke="#5b9bf5" stroke-width="1.5" fill="none" stroke-dasharray="4 6"/>
      </svg>
    </div>
    <div class="ghost-card gc-1"><div class="gc-bar" style="width:55%;"></div><div class="gc-bar"></div><div class="gc-bar"></div></div>
    <div class="ghost-card gc-2"><div class="gc-bar" style="width:40%;"></div><div class="gc-bar"></div></div>

    <div class="brand-row">
      <span class="badge-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2l8 3v6c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V5l8-3z"/><path d="M9 12l2 2 4-4"/></svg>
      </span>
      <span class="eyebrow">HAMMERHEAD PROTECTION INC.</span>
    </div>
    <h1>Workforce Operations<span class="accent-line">Platform</span></h1>
    <p>
      One secure workspace to manage teams, department-wise projections, projects, access control, and performance insights.
    </p>
    <div class="feature-strip">
      <span>🔒 Role-Based Access</span>
      <span>🏢 Department-Wise Projections</span>
      <span>📊 Live KPI Tracking</span>
    </div>
  </div>
  <div class="login-panel">
    <div class="login-card">
      <div class="logo-row"><img src="/assets/img/hh_logo.png" alt="Hammerhead Security"></div>
      <h2>Welcome Back</h2>
      <div class="sub">Sign in to your Hammerhead Workspace</div>

      <?php if (!empty($success)): ?>
        <div class="alert alert-success"><?= htmlspecialchars($success) ?></div>
      <?php endif; ?>
      <?php if (!empty($error)): ?>
        <div class="alert alert-error"><?= htmlspecialchars($error) ?></div>
      <?php endif; ?>

      <form method="POST" action="/login">
        <div class="field">
          <label>Username</label>
          <div class="input-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 3.5-6 8-6s8 2 8 6"/></svg>
            <input type="text" name="username" required autocomplete="username" placeholder="Enter your username">
          </div>
        </div>
        <div class="field">
          <label>Password</label>
          <div class="input-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/></svg>
            <input type="password" name="password" id="passwordInput" required autocomplete="current-password" placeholder="Enter your password">
            <button type="button" class="toggle-pass" onclick="togglePassword()" aria-label="Show password">
              <svg id="eyeIcon" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7-11-7-11-7z"/><circle cx="12" cy="12" r="3"/></svg>
            </button>
          </div>
        </div>
        <div class="verify-row">
          <span class="verify-label">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2l8 3v6c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V5l8-3z"/></svg>
            Verify
          </span>
          <span class="verify-eq"><?= $a ?> + <?= $b ?> =</span>
          <input type="text" name="security_answer" required placeholder="?" autocomplete="off">
        </div>
        <div class="remember-row">
          <label><input type="checkbox" name="remember_me" value="1"> Remember me</label>
          <a href="/forgot-password" class="forgot-inline">Forgot your password?</a>
        </div>
        <button type="submit" class="btn">Sign In <span>→</span></button>
      </form>
      <div class="footer-note">© <?= date('Y') ?> Hammerhead Protection Inc. Authorized Access Only</div>
    </div>
  </div>
</div>
<script>
function togglePassword(){
  const input = document.getElementById('passwordInput');
  input.type = input.type === 'password' ? 'text' : 'password';
}
</script>
</body>
</html>
