/*
  Sign-in, two-step verification and Security settings (auth_views.py), shared by the staff Workbench and the
  client portal. Builds on app.css's tokens (Plus Jakarta Sans, navy / warm cream / green). Text colors here are
  the AA-passing variants from the onboarding prototype (muted .70, darker green/amber/red for text on tints).
  Everything is scoped under .ck-auth so no other page changes.
*/
.ck-auth {
  --a-text-muted: rgba(18, 38, 63, 0.70);
  --a-green-text: #2a7a43;
  --a-amber-text: #8a5b14;
  --a-red-text: #a0394c;
  --a-card: #fffdf9;
  --a-focus: 0 0 0 3px var(--c-bg, #faf7f2), 0 0 0 5px var(--c-navy, #0c3a5e);
  width: 100%;
  font-family: var(--font-body);
  color: var(--c-text);
}
/* `hidden` must win over the display rules below (cards, panels and fields are toggled by auth.js). */
.ck-auth [hidden] { display: none !important; }
/* Headings get focus programmatically (tabindex="-1") so screen readers announce a new step; no focus box for that. */
.ck-auth [tabindex="-1"]:focus { outline: none; box-shadow: none; }
.ck-auth-wrap { display: flex; justify-content: center; padding: clamp(1.25rem, 4vw, 3rem) 1rem; }
.ck-auth-card {
  width: min(100%, 30rem);
  background: var(--a-card);
  border: 1px solid var(--c-border);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-sm);
  padding: clamp(1.25rem, 4vw, 2.25rem);
  display: grid;
  gap: var(--s-4);
}
.ck-auth-card--wide { width: min(100%, 44rem); }
.ck-auth-tag {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--c-navy); background: rgba(141, 207, 155, .25); padding: 4px 10px; border-radius: 999px;
}
.ck-auth-icon {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(141, 207, 155, .3); color: var(--a-green-text);
}
.ck-auth-icon--warn { background: var(--c-amber-subtle); color: var(--a-amber-text); }
.ck-auth-icon svg { width: 26px; height: 26px; }
.ck-auth h1 { font-size: clamp(1.45rem, 1.15rem + 1.2vw, 1.9rem); font-weight: 800; letter-spacing: -0.025em; margin: 0; }
.ck-auth h2 { font-size: 1.125rem; font-weight: 800; margin: 0; }
.ck-auth p { color: var(--a-text-muted); margin: 0; }
.ck-auth p strong { color: var(--c-text); }
.ck-auth-lede { font-size: 1rem; }
.ck-auth-small { font-size: .875rem; }

.ck-auth-field { display: grid; gap: 6px; text-align: left; }
.ck-auth-field label, .ck-auth-legend { font-size: .875rem; font-weight: 700; color: var(--c-text); }
.ck-auth-hint { font-size: .75rem; color: var(--a-text-muted); }
.ck-auth-input {
  width: 100%; min-height: 48px; padding: .7rem .9rem; border-radius: .875rem;
  border: 1.5px solid var(--c-border-mid); background: #fff; font-size: 1rem; color: var(--c-text);
  transition: border-color var(--tx), box-shadow var(--tx);
}
.ck-auth-input:hover { border-color: rgba(12, 58, 94, .32); }
.ck-auth-input:focus { outline: none; border-color: var(--c-navy); box-shadow: 0 0 0 3px rgba(12, 58, 94, .32); }
.ck-auth-input[aria-invalid="true"] { border-color: var(--c-red); }
.ck-auth-input--code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .08em; }
.ck-auth-pw { position: relative; }
.ck-auth-pw .ck-auth-input { padding-right: 84px; }
.ck-auth-pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 36px; padding: 0 12px;
  border-radius: 8px; border: 0; background: var(--c-surface-2); font-weight: 700; font-size: 13px; cursor: pointer;
}

.ck-auth-otp { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
.ck-auth-otp-boxes { display: flex; gap: 8px; flex-wrap: nowrap; }
.ck-auth-otp-boxes input {
  width: 52px; height: 60px; text-align: center; font-size: 24px; font-weight: 800; border-radius: .875rem;
  border: 1.5px solid var(--c-border-mid); background: #fff; color: var(--c-text);
  font-variant-numeric: tabular-nums; min-width: 0;
}
.ck-auth-otp-boxes input:focus { outline: none; border-color: var(--c-navy); box-shadow: 0 0 0 3px rgba(12, 58, 94, .32); }
.ck-auth-otp[data-invalid="true"] .ck-auth-otp-boxes input { border-color: var(--c-red); }
.ck-auth-otp-sep { align-self: center; color: var(--a-text-muted); font-weight: 800; }

.ck-auth-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  padding: .8rem 1.5rem; border-radius: 999px; border: 1.5px solid transparent; cursor: pointer;
  font-size: .9rem; font-weight: 700; letter-spacing: -0.01em; text-decoration: none;
  transition: background var(--tx), color var(--tx), border-color var(--tx), transform var(--tx);
}
.ck-auth-btn--primary { background: var(--c-accent-mid); color: var(--c-navy-dark); }
.ck-auth-btn--primary:hover:not(:disabled) { background: var(--a-green-text); color: #fff; transform: translateY(-1px); }
.ck-auth-btn--navy { background: var(--c-navy); color: var(--c-inverse); }
.ck-auth-btn--navy:hover:not(:disabled) { background: var(--c-navy-dark); }
.ck-auth-btn--outline { background: transparent; color: var(--c-navy); border-color: var(--c-border-mid); }
.ck-auth-btn--outline:hover:not(:disabled) { background: rgba(255, 255, 255, .7); border-color: rgba(12, 58, 94, .3); }
.ck-auth-btn--danger { background: transparent; color: var(--a-red-text); border-color: rgba(192, 69, 90, .4); }
.ck-auth-btn--block { width: 100%; }
.ck-auth-btn:disabled, .ck-auth-btn[aria-disabled="true"] { background: var(--c-surface-2); color: var(--a-text-muted); cursor: not-allowed; transform: none; border-color: transparent; }
.ck-auth-link {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: .875rem; font-weight: 700;
  color: var(--c-navy); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(12, 58, 94, .35);
  min-height: 24px;
}
.ck-auth-link:hover { text-decoration-color: currentColor; }
.ck-auth-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.ck-auth-spin {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: ck-auth-spin .8s linear infinite;
}
@keyframes ck-auth-spin { to { transform: rotate(360deg); } }

.ck-auth :focus-visible { outline: 3px solid var(--c-navy); outline-offset: 3px; }
.ck-auth-input:focus-visible, .ck-auth-otp-boxes input:focus-visible { outline-offset: 1px; }

.ck-auth-alert {
  display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: 1rem; border: 1px solid;
  font-size: .875rem; color: var(--c-text); text-align: left;
}
.ck-auth-alert[hidden] { display: none; }
.ck-auth-alert strong { display: block; }
.ck-auth-alert svg { flex-shrink: 0; width: 20px; height: 20px; margin-top: 1px; }
.ck-auth-alert--error { background: #fbecee; border-color: rgba(192, 69, 90, .3); }
.ck-auth-alert--error svg { color: var(--a-red-text); }
.ck-auth-alert--warn { background: #fbf2e3; border-color: rgba(201, 138, 43, .35); }
.ck-auth-alert--warn svg { color: var(--a-amber-text); }
.ck-auth-alert--ok { background: #edf7ef; border-color: rgba(58, 155, 86, .3); }
.ck-auth-alert--ok svg { color: var(--a-green-text); }
.ck-auth-alert--info { background: rgba(12, 58, 94, .05); border-color: rgba(12, 58, 94, .15); }
.ck-auth-alert--info svg { color: var(--c-navy); }

.ck-auth-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-4); counter-reset: ck-step; }
.ck-auth-steps > li { display: grid; grid-template-columns: 32px 1fr; gap: var(--s-3); align-items: start; }
.ck-auth-steps > li::before {
  counter-increment: ck-step; content: counter(ck-step); width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--c-navy); color: var(--c-inverse); font-weight: 800; font-size: 14px;
}
.ck-auth-steps h2 { font-size: 1rem; margin-bottom: 4px; }
.ck-auth-qr {
  display: flex; gap: var(--s-4); align-items: center; flex-wrap: wrap; padding: var(--s-4);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 1rem;
}
.ck-auth-qr .mfa-qr-svg { width: 168px; height: 168px; border-radius: 8px; background: #fff; flex-shrink: 0; }
/* Wraps below the QR code when there's no room beside it (phones), instead of squeezing to one letter wide. */
.ck-auth-qr-key { display: grid; gap: 6px; min-width: 0; flex: 1 1 13rem; }
.ck-auth-key {
  font-family: ui-monospace, Menlo, monospace; font-size: .95rem; font-weight: 700; color: var(--c-text);
  background: #fff; border: 1px dashed var(--c-border-mid); border-radius: .5rem; padding: 6px 10px;
  word-break: break-all; user-select: all;
}

.ck-auth-codes {
  list-style: none; margin: 0; padding: var(--s-4); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px; background: #fff; border: 1px solid var(--c-border-mid); border-radius: 1rem;
  font-family: ui-monospace, Menlo, monospace; font-size: 1rem; font-weight: 700; color: var(--c-text);
}
.ck-auth-codes li { padding: 4px 0; letter-spacing: .04em; }
.ck-auth-check { display: flex; gap: var(--s-3); align-items: flex-start; font-size: .875rem; line-height: 1.5; cursor: pointer; color: var(--c-text); }
.ck-auth-check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--c-navy); flex-shrink: 0; cursor: pointer; }

.ck-auth-divider { border: 0; border-top: 1px solid var(--c-border); margin: var(--s-2) 0; }
.ck-auth-foot { font-size: .8rem; color: var(--a-text-muted); text-align: center; }
.ck-auth-foot a { color: var(--c-navy); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* Security settings */
.ck-sec { display: grid; gap: var(--s-5); max-width: 760px; }
.ck-sec-card {
  background: var(--a-card); border: 1px solid var(--c-border); border-radius: 1.5rem; padding: clamp(1.1rem, 3vw, 1.5rem);
  box-shadow: var(--shadow-xs); display: grid; gap: var(--s-3);
}
.ck-sec-head { display: flex; justify-content: space-between; gap: var(--s-3); align-items: flex-start; flex-wrap: wrap; }
.ck-sec-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.ck-sec-chip--on { background: rgba(141, 207, 155, .18); color: var(--a-green-text); }
.ck-sec-chip--off { background: var(--c-surface-2); color: var(--a-text-muted); }
.ck-sec-chip--warn { background: var(--c-amber-subtle); color: var(--a-amber-text); }
.ck-sec-dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .875rem; margin: 0; }
.ck-sec-dl dt { color: var(--a-text-muted); font-weight: 600; }
.ck-sec-dl dd { margin: 0; font-weight: 700; }
.ck-sec-panel[hidden] { display: none; }
.ck-sec-panel { display: grid; gap: var(--s-3); padding: var(--s-4); border-radius: 1rem; background: var(--c-surface); border: 1px solid var(--c-border); }

@media (max-width: 480px) {
  .ck-auth-card { border-radius: 1.25rem; }
  .ck-auth-otp-boxes { gap: 5px; }
  .ck-auth-otp-boxes input { width: 100%; height: 54px; font-size: 22px; }
  .ck-auth-otp-sep { display: none; }
  .ck-auth-codes { grid-template-columns: 1fr; }
  .ck-auth-actions .ck-auth-btn { flex: 1 1 auto; }
  .ck-auth-qr { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .ck-auth *, .ck-auth *::before, .ck-auth *::after { transition: none !important; animation: none !important; }
}
