function sendMoney() {
  const recipient = document.getElementById("recipient").value.trim();
  const amount = Number(document.getElementById("amount").value);
  const note = document.getElementById("note").value.trim();

  const sender = JSON.parse(localStorage.getItem("flowpesa_onboarding"));

  if (!sender || sender.account_status !== "active") {
    alert("Session expired.");
    return;
  }

  if (sender.kyc_level < 2) {
    alert("Complete ID verification to send money.");
    return;
  }

  if (!recipient) {
    alert("Enter a recipient.");
    return;
  }

  if (!amount || amount < 1000) {
    alert("Minimum send amount is UGX 1,000.");
    return;
  }

  // ---- MOCK BALANCE ----
  let senderBalance = 50000; // later from API

  if (amount > senderBalance) {
    alert("Insufficient balance.");
    return;
  }

  if (
    recipient === sender.phone ||
    recipient.toLowerCase() === sender.nickname?.toLowerCase()
  ) {
    alert("You cannot send money to yourself.");
    return;
  }

  // ---- LEDGER SIMULATION ----
  const txOut = {
    type: "send",
    direction: "debit",
    amount,
    reference: "Sent to " + recipient,
    status: "success",
    date: "Just now"
  };

  const txIn = {
    type: "receive",
    direction: "credit",
    amount,
    reference: "Received from " + (sender.nickname || sender.first_name),
    status: "success",
    date: "Just now"
  };

  let txs = JSON.parse(localStorage.getItem("flowpesa_transactions")) || [];
  txs.unshift(txOut);
  localStorage.setItem("flowpesa_transactions", JSON.stringify(txs));

  alert("Money sent successfully.");

  window.location.href = "transactions.html";
}
