document.addEventListener("DOMContentLoaded", () => {

  document.querySelectorAll(".lock-btn").forEach(btn => {
    btn.addEventListener("click", () => {
      const row = btn.closest("tr");

      // Alle Zeilen sperren
      document.querySelectorAll("tr").forEach(r => {
        r.querySelectorAll("input").forEach(i => i.disabled = true);
        const save = r.querySelector(".save-btn");
        if (save) save.disabled = true;
      });

      // Aktuelle Zeile entsperren
      row.querySelectorAll("input").forEach(i => i.disabled = false);
      row.querySelector(".save-btn").disabled = false;

      // Button ändern
      btn.textContent = "🔒";
      btn.title = "Bearbeitung gesperrt";

      // Fokus
      const firstInput = row.querySelector("input");
      if (firstInput) firstInput.focus();
    });
  });

});
