(function () {
  function bindPwToggles() {
    document.querySelectorAll('.pw-eye').forEach(function (btn) {
      const id = btn.getAttribute('data-target');
      const input = document.getElementById(id);
      if (!input) return;

      btn.addEventListener('click', function (e) {
        e.preventDefault();
        const wrap = btn.closest('.pw-wrap');
        const show = input.type === 'password';
        input.type = show ? 'text' : 'password';
        if (wrap) wrap.classList.toggle('is-show', show);
        btn.setAttribute('aria-label', show ? 'Hide password' : 'Show password');
      });
    });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', bindPwToggles);
  } else {
    bindPwToggles();
  }
})();
