/* ── Password strength meter (shared by base.html and standalone pages) ── */
function _pwStrengthLevel(pw) {
var score = 0;
if (pw.length >= 8) score++;
if (pw.length >= 12) score++;
if (/[A-Z]/.test(pw)) score++;
if (/[0-9]/.test(pw)) score++;
if (/[^A-Za-z0-9]/.test(pw)) score++;
var map = ['pw-weak','pw-weak','pw-fair','pw-strong','pw-great','pw-great'];
var lbl = ['Weak','Weak','Fair','Strong','Very strong','Very strong'];
return { cls: map[score], label: lbl[score] };
}
function attachPasswordStrength(inputId, fillId, labelId) {
var input = document.getElementById(inputId);
var fill = document.getElementById(fillId);
var lbl = document.getElementById(labelId);
if (!input || !fill || !lbl) return;
input.addEventListener('input', function() {
if (!this.value) {
fill.className = 'pw-strength-fill';
lbl.className = 'pw-strength-label';
lbl.textContent = '';
return;
}
var r = _pwStrengthLevel(this.value);
fill.className = 'pw-strength-fill ' + r.cls;
lbl.className = 'pw-strength-label ' + r.cls;
lbl.textContent = r.label;
});
}