document.getElementById("nameForm").addEventListener("submit", function (e) {
  e.preventDefault();

  const firstName = document.getElementById("firstName").value.trim();
  const lastName  = document.getElementById("lastName").value.trim();
  const nickname  = document.getElementById("nickname").value.trim();

  if (!firstName || !lastName) {
    alert("Please enter your first and last name.");
    return;
  }

  // Temporary storage until account is fully created
  const userProfile = {
    first_name: firstName,
    last_name: lastName,
    nickname: nickname || firstName,
    step: "name_completed"
  };

  localStorage.setItem("flowpesa_onboarding", JSON.stringify(userProfile));

  // Move to phone verification step
  window.location.href = "phone-verification.html";
});
