/* ==========================================================================
   Password strength — a meter, tips and an optional checklist under a
   password field, plus show / hide, "passwords match" and a Caps Lock warning.

   <input class="form-control" type="password" autocomplete="new-password"
          data-moey-strength data-moey-rules="12,upper,lower,number,symbol" data-moey-toggle>
   <input class="form-control" type="password" data-moey-match="#password" data-moey-toggle>

   data-moey-strength-min="3"    the form won't send a weaker one (0–4)
   data-moey-strength-avoid="#email, #name"   counts using those as weak
   data-moey-toggle              an eye button to show the password (any password field)
   Event: moey:strength (detail: { score, label, hint, rules }). Moey.strength('text') scores any text.
   ========================================================================== */

.strength {
  --mo-strength: var(--mo-gray-solid);
  --mo-strength-text: var(--mo-fg-3);
  display: grid;
  gap: .375rem;
  margin-top: .5rem;
  font-size: .8125rem;
}
.strength[data-score="0"] { --mo-strength: var(--mo-red-solid); --mo-strength-text: var(--mo-red-fg); }
.strength[data-score="1"] { --mo-strength: var(--mo-orange-solid); --mo-strength-text: var(--mo-orange-fg); }
.strength[data-score="2"] { --mo-strength: var(--mo-amber-solid); --mo-strength-text: var(--mo-amber-fg); }
.strength[data-score="3"] { --mo-strength: var(--mo-teal-solid); --mo-strength-text: var(--mo-teal-fg); }
.strength[data-score="4"] { --mo-strength: var(--mo-green-solid); --mo-strength-text: var(--mo-green-fg); }

.strength-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; }
.strength-bar > span {
  height: .25rem;
  background: color-mix(in oklab, var(--mo-fg-body) 12%, transparent);
  border-radius: 99px;
}
.strength-bar > span.is-on { background: var(--mo-strength); }
@media (prefers-reduced-motion: no-preference) { .strength-bar > span { transition: background-color .2s ease; } }

.strength-text { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; min-height: 1.25rem; }
.strength-label { font-weight: var(--mo-font-weight-semibold, 600); color: var(--mo-strength-text); }
.strength-hint { color: var(--mo-fg-3); }
.strength:not([data-score]) .strength-text { visibility: hidden; }

/* The checklist */
.strength-rules {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: .25rem 1rem;
  padding: 0;
  margin: .125rem 0 0;
  list-style: none;
  color: var(--mo-fg-3);
}
.strength-rules > li { display: flex; gap: .5rem; align-items: center; }
.strength-rules > li::before {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  content: "";
  background: currentColor;
  opacity: .5;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='8'/%3E%3C/svg%3E") center / 100% no-repeat;
}
.strength-rules > li.is-met { color: var(--mo-green-fg); }
.strength-rules > li.is-met::before {
  opacity: 1;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m8 12.5 2.75 2.75L16 10'/%3E%3C/svg%3E");
}

/* Caps Lock is on */
.caps-hint { display: flex; gap: .375rem; align-items: center; margin-top: .375rem; font-size: .8125rem; color: var(--mo-amber-fg); }
.caps-hint[hidden] { display: none; }
.caps-hint > svg, .password-toggle > svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.password-toggle > .icon-hide { display: none; }
.password-toggle[aria-pressed="true"] > .icon-show { display: none; }
.password-toggle[aria-pressed="true"] > .icon-hide { display: block; }
