/** @license For full copyright and license information, please see the LICENSE.md file. */

/*
 * Ammonly Authentication Interactive Controls, Popover Dock, Segmented OTP & NIST Meter.
 * Uses :has(), :user-invalid, @starting-style, tabular-nums, and WCAG 2.2 target sizes.
 * Zero !important declarations.
 */

.auth-tier-chip-mobile {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: color-mix(in oklch, var(--auth-accent) 14%, transparent);
  border: 1px solid color-mix(in oklch, var(--auth-accent) 30%, transparent);
  color: var(--auth-text);
}

@media (min-width: 992px) {
  .auth-tier-chip-mobile {
    display: none;
  }
}

/* Input Groups & Relational :has() Focus / Validation */
.auth-field-shell {
  display: flex;
  align-items: stretch;
  border-radius: 0.75rem;
  border: 1px solid var(--auth-border);
  background-color: var(--auth-input-bg);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
  overflow: hidden;
}

.auth-field-shell:has(.form-control:focus-visible) {
  border-color: var(--auth-accent);
  box-shadow: 0 0 0 3px var(--auth-ring);
}

.auth-field-shell:has(.form-control:user-invalid) {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.16);
}

.auth-field-shell__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-inline: 0.875rem 0.25rem;
  color: var(--auth-text-muted);
  font-size: 1rem;
}

.auth-field-shell .form-control {
  border: 0;
  background: transparent;
  color: var(--auth-text);
  font-size: 0.9375rem;
  padding: 0.7rem 0.75rem;
  box-shadow: none;
  min-height: 2.875rem;
}

.auth-field-shell .form-control:focus {
  box-shadow: none;
  outline: none;
}

.auth-field-shell .form-control::placeholder {
  color: color-mix(in oklch, var(--auth-text-muted) 72%, transparent);
}

.auth-field-shell input:-webkit-autofill,
.auth-field-shell input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--auth-text);
  caret-color: var(--auth-text);
  -webkit-box-shadow: 0 0 0 1000px var(--auth-surface-elevated) inset;
  box-shadow: 0 0 0 1000px var(--auth-surface-elevated) inset;
}

.auth-link-accent {
  color: var(--auth-accent);
  text-decoration: none;
  transition: opacity 0.15s ease;
}

html[data-bs-theme="dark"] .auth-link-accent {
  color: color-mix(in oklch, var(--auth-accent) 68%, #ffffff);
}

.auth-link-accent:hover {
  opacity: 0.82;
  text-decoration: underline;
}

.auth-password-toggle {
  border: 0;
  border-inline-start: 1px solid var(--auth-border);
  background: transparent;
  color: var(--auth-text-muted);
  padding-inline: 0.875rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.auth-password-toggle:hover {
  color: var(--auth-text);
  background: color-mix(in oklch, var(--auth-accent) 10%, transparent);
}

.auth-password-toggle:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: -2px;
}

/* CapsLock Live Indicator */
.auth-capslock-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #78350f;
  background: #fef3c7;
  border: 1px solid rgba(245, 158, 11, 0.32);
}

html[data-bs-theme="dark"] .auth-capslock-badge {
  color: #fde68a;
  background: #451a03;
}

.auth-capslock-badge[hidden] {
  display: none;
}

/* Primary Submit CTA & Loading Lock */
.auth-submit-btn {
  min-height: 2.875rem;
  border-radius: 0.75rem;
  border: 0;
  background: linear-gradient(135deg, var(--auth-accent), var(--auth-accent-alt));
  color: var(--auth-accent-ink);
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 10px 24px -8px color-mix(in oklch, var(--auth-accent) 55%, transparent);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.auth-submit-btn:hover {
  filter: brightness(1.06);
  color: var(--auth-accent-ink);
  transform: translateY(-1px);
}

.auth-submit-btn:focus-visible { outline: 3px solid var(--auth-ring); outline-offset: 2px; }
.auth-submit-btn[aria-busy="true"] { opacity: 0.86; pointer-events: none; }

.auth-passkey-btn {
  min-height: 2.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--auth-border);
  background: var(--auth-surface);
  color: var(--auth-text);
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.auth-passkey-btn:hover { border-color: var(--auth-border-strong); background: var(--auth-surface-elevated); }
.auth-passkey-btn:focus-visible { outline: 2px solid var(--auth-accent); outline-offset: 2px; }
.auth-passkey-btn[aria-busy="true"] { opacity: 0.72; pointer-events: none; }

/* Native HTML5 Popover Workspace Settings Panel */
.auth-prefs-popover {
  margin: 0;
  inset: auto;
  width: min(22rem, calc(100vw - 1.5rem));
  padding: 1.125rem;
  border-radius: 1rem;
  border: 1px solid var(--auth-border-strong);
  background: var(--auth-surface-elevated);
  color: var(--auth-text);
  box-shadow: var(--auth-shadow);
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    overlay 0.18s ease allow-discrete,
    display 0.18s ease allow-discrete;
}

.auth-prefs-popover:popover-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

@starting-style {
  .auth-prefs-popover:popover-open {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
}

.auth-ui-mode-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.375rem;
  padding: 0.25rem;
  border-radius: 0.75rem;
  background: color-mix(in oklch, var(--auth-canvas) 82%, transparent);
  border: 1px solid var(--auth-border);
}

.auth-ui-mode-btn {
  min-height: 2.375rem;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--auth-text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-check:checked + .auth-ui-mode-btn {
  background: var(--auth-surface-elevated);
  color: var(--auth-text);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.btn-check:focus-visible + .auth-ui-mode-btn {
  outline: 2px solid var(--auth-accent);
}

.auth-font-group .btn.is-active {
  background: color-mix(in oklch, var(--auth-accent) 18%, var(--auth-surface-elevated));
  border-color: var(--auth-border-strong);
  color: var(--auth-text);
}

/* Segmented 6-Digit MFA OTP Slots */
.auth-otp-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}

.auth-otp-slot {
  width: 100%;
  height: 3.35rem;
  border-radius: 0.75rem;
  border: 1.5px solid var(--auth-border);
  background: var(--auth-input-bg);
  color: var(--auth-text);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.auth-otp-slot:focus-visible {
  outline: 2px solid var(--auth-accent);
  outline-offset: 2px;
  border-color: var(--auth-accent);
  box-shadow: 0 0 0 3px var(--auth-ring);
  transform: translateY(-1px);
}

[data-mfa-container][data-mfa-mode="backup"] .auth-otp-totp-pane,
[data-mfa-container][data-mfa-mode="totp"] .auth-otp-backup-pane { display: none; }

/* NIST Password Strength Meter & Requirements */
.auth-strength-meter { margin-top: 0.625rem; }

.auth-strength-meter__track {
  height: 0.375rem;
  border-radius: 999px;
  background: color-mix(in oklch, var(--auth-text-muted) 22%, transparent);
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.auth-strength-meter__bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.24s ease, background-color 0.24s ease;
}

.auth-strength-meter__bar--weak { width: 25%; background-color: #ef4444; }
.auth-strength-meter__bar--fair { width: 50%; background-color: #f59e0b; }
.auth-strength-meter__bar--good { width: 75%; background-color: #0ea5e9; }
.auth-strength-meter__bar--strong { width: 100%; background-color: #10b981; }

.auth-req-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--auth-text-muted);
}

.auth-req-list__item { display: flex; align-items: center; gap: 0.45rem; }
.auth-req-list__item--valid { color: #047857; font-weight: 600; }
html[data-bs-theme="dark"] .auth-req-list__item--valid { color: #6ee7b7; }

/* Lockout Live SVG Timer */
.auth-lockout-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  border-radius: 1rem;
  background: color-mix(in oklch, var(--auth-canvas) 80%, transparent);
  border: 1px solid var(--auth-border);
}

.auth-lockout-ring {
  width: 3.5rem;
  height: 3.5rem;
  transform: rotate(-90deg);
  flex-shrink: 0;
}

.auth-lockout-ring__track {
  fill: none;
  stroke: color-mix(in oklch, var(--auth-text-muted) 20%, transparent);
  stroke-width: 4;
}

.auth-lockout-ring__progress {
  fill: none;
  stroke: var(--auth-accent);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s linear;
}

.auth-lockout-clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.1;
}

@media (pointer: coarse) {
  .auth-dock-btn, .auth-ui-mode-btn, .auth-password-toggle, .auth-passkey-btn, .auth-otp-slot { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .auth-dock-btn, .auth-submit-btn, .auth-passkey-btn, .auth-prefs-popover,
  .auth-otp-slot, .auth-strength-meter__bar, .auth-lockout-ring__progress { transition: none; }
}
