document.getElementById('signupForm').addEventListener('submit', async (e) => {
  e.preventDefault();
  
  const formData = new FormData(e.target);
  const email = e.target.querySelector('input[type="email"]').value;
  const company_name = e.target.querySelector('input[type="text"]').value;
  const messageEl = document.getElementById('formMessage');

  try {
    const response = await fetch('/api/auth/register', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        email,
        company_name,
        password: 'beta_' + Math.random().toString(36).substring(7),
        tier: 'beta'
      })
    });

    if (response.ok) {
      messageEl.textContent = '✓ Thanks! Check your email to get started.';
      messageEl.className = 'message success';
      e.target.reset();
    } else {
      const error = await response.json();
      messageEl.textContent = '✗ ' + (error.error || 'Signup failed');
      messageEl.className = 'message error';
    }
  } catch (error) {
    messageEl.textContent = '✗ An error occurred. Please try again.';
    messageEl.className = 'message error';
  }
});

// Smooth scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  anchor.addEventListener('click', function(e) {
    e.preventDefault();
    const target = document.querySelector(this.getAttribute('href'));
    if (target) {
      target.scrollIntoView({ behavior: 'smooth' });
    }
  });
});
