/* Two-step verification's own pieces (two-step.js), on top of utils.js's modal
   (.sm-modal, branding.css). Loaded by the sign-in page, the set-password page and
   the settings page. */

/* The device chooser opens over the sign-in step: this one steps aside meanwhile.
   .sm-modal-overlay is display:flex, which would otherwise beat [hidden]. */
.ts-overlay[hidden] { display: none; }

.ts-label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 8px; }
.ts-hint { font-size: 12.5px; margin: 0 0 8px; }
.ts-err { min-height: 1.2em; margin: 6px 0 12px; font-size: 13.5px; color: var(--status-risk, #ff8a80); }

/* ---- The code, a digit to a box (2026-11-04) -------------------------------------
   One real input (#ts-code) lies over the row of boxes, invisible: it takes the typing,
   pasting, the phone's suggested code and password managers, and the boxes only draw
   what it holds (two-step.js, wireCode). Three and three, the way authenticator apps
   show the code. The states are classes on .ts-otp: ts-full (six in), ts-busy
   (checking), ts-wrong (refused: red, and a shake), ts-ok (accepted: green), ts-all
   (all of it selected, so the next digit types over it). */
.ts-otp { position: relative; margin: 0 0 4px; }
/* See-through rather than opacity 0: password managers skip a field they take to be
   hidden, and this one has to take the code they fill in. */
.ts-otp-input {
  position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; padding: 0;
  border: 0; outline: 0; box-shadow: none; background: transparent;
  color: transparent; -webkit-text-fill-color: transparent; caret-color: transparent;
  /* 16px or more, or iOS zooms the page in when it takes focus. */
  font-size: 16px; letter-spacing: -0.5em; cursor: text;
}
.ts-otp-input::selection { background: transparent; }
/* Whatever a page does to its inputs (the sign-in page's focus ring, login.css), this one
   draws nothing: the boxes show the focus. */
.ts-otp .ts-otp-input,
.ts-otp .ts-otp-input:focus,
.ts-otp .ts-otp-input:focus-visible {
  border: 0; outline: 0; box-shadow: none; background: transparent; border-radius: 0;
}
/* The browser's autofill colour would paint over the boxes: hold it off. */
.ts-otp-input:-webkit-autofill { transition: background-color 0s 99999s; }
.ts-otp-input:autofill { transition: background-color 0s 99999s; }
.ts-otp-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.ts-otp-dash {
  flex: 0 0 auto; width: 10px; height: 2px; margin: 0 3px; border-radius: 2px;
  background: var(--text-dim); opacity: 0.5;
}
.ts-slot {
  flex: 0 1 50px; min-width: 0; height: clamp(50px, 15vw, 60px); box-sizing: border-box;
  display: grid; place-items: center;
  border: 1.5px solid var(--border); border-radius: 14px;
  background: color-mix(in srgb, var(--text) 5%, transparent);
  color: var(--text); font-size: 26px; font-weight: 600; line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
/* Each digit drops into its box. */
.ts-slot b { font-weight: inherit; animation: ts-digit-in 0.28s var(--sm-ease-out, ease-out) backwards; }
.ts-slot.ts-filled {
  border-color: color-mix(in srgb, var(--gold) 45%, var(--border));
  background: color-mix(in srgb, var(--gold) 8%, transparent);
}
/* The box the next digit goes in: lit, with a blinking caret while it's empty. */
.ts-slot.ts-here {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 22%, transparent);
}
.ts-slot.ts-here:empty::after {
  content: ""; width: 2px; height: 26px; border-radius: 1px; background: var(--gold);
  animation: ts-caret 1.1s steps(1) infinite;
}
.ts-otp.ts-all .ts-slot.ts-filled {
  border-color: var(--gold); background: color-mix(in srgb, var(--gold) 26%, transparent);
}
/* Six in: a small wave runs along the row. */
.ts-otp.ts-full .ts-slot { animation: ts-wave 0.5s var(--sm-ease-out, ease-out) backwards; animation-delay: calc(var(--i, 0) * 45ms); }
/* Checking: the boxes breathe, one after the other. */
.ts-otp.ts-busy .ts-slot { animation: ts-think 1s ease-in-out infinite; animation-delay: calc(var(--i, 0) * 90ms); }
/* Refused: red, and a shake, until the next keystroke. */
.ts-otp.ts-wrong .ts-otp-row,
.ts-recovery.ts-wrong,
.ts-modal .sm-modal-input.ts-wrong { animation: ts-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
/* After the selected look, which it beats: the code is selected again after a refusal. */
.ts-otp.ts-wrong .ts-slot,
.ts-otp.ts-wrong .ts-slot.ts-filled {
  animation: none;
  border-color: var(--status-risk, #ff8a80);
  background: color-mix(in srgb, var(--status-risk, #ff8a80) 12%, transparent);
  box-shadow: none;
}
/* Accepted: green, and the wave again, before the next step. */
.ts-otp.ts-ok .ts-slot,
.ts-otp.ts-ok .ts-slot.ts-filled {
  border-color: var(--status-good, #5fd3a4);
  background: color-mix(in srgb, var(--status-good, #5fd3a4) 18%, transparent);
  box-shadow: none;
  animation: ts-ok 0.5s var(--sm-ease-out, ease-out) backwards; animation-delay: calc(var(--i, 0) * 45ms);
}
.ts-otp.ts-ok .ts-slot::after { display: none; }

/* A recovery code: one wide field, set like the printed codes. */
.ts-recovery {
  height: 54px; margin-bottom: 4px; text-align: center; font-size: 20px; letter-spacing: 0.14em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.ts-recovery::placeholder { color: var(--text-dim); opacity: 0.45; }

@keyframes ts-digit-in { from { opacity: 0; transform: translateY(10px) scale(0.6); } }
@keyframes ts-caret { 50% { opacity: 0; } }
@keyframes ts-wave { 40% { transform: translateY(-5px); } }
@keyframes ts-ok { 45% { transform: translateY(-4px) scale(1.06); } }
@keyframes ts-think { 50% { opacity: 0.45; } }
@keyframes ts-shake {
  15%, 85% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(5px); }
  45%, 55% { transform: translateX(-7px); }
}

/* Each step slides in as the last one goes (one dialog, its contents replaced). */
.ts-modal > :not(form),
.ts-form > * { animation: ts-step-in 0.4s var(--sm-ease-out, ease-out) backwards; }
.ts-form > :nth-child(2) { animation-delay: 0.04s; }
.ts-form > :nth-child(3) { animation-delay: 0.08s; }
.ts-form > :nth-child(4) { animation-delay: 0.12s; }
.ts-form > :nth-child(n+5) { animation-delay: 0.16s; }
@keyframes ts-step-in { from { opacity: 0; transform: translateY(8px); } }

/* The QR code is drawn dark on white (api/routes/mfa.py): a scanner needs the contrast
   in every theme, so the frame is white too. */
.ts-qr {
  display: block; width: 220px; height: 220px; margin: 0 auto 14px;
  background: #fff; border-radius: 12px; image-rendering: pixelated;
}
.ts-key { margin: 0 0 16px; font-size: 13.5px; }
.ts-key summary { cursor: pointer; color: var(--gold); font-weight: 600; }
.ts-key p { margin: 8px 0 0; font-size: 13px; }
.ts-keytext code, .ts-codes code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 15px;
  letter-spacing: 1px; color: var(--text); user-select: all;
}

.ts-codes {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 18px;
  margin: 0 0 14px; padding: 12px 16px 12px 34px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04);
}
.ts-row { display: flex; gap: 10px; margin: 0 0 14px; }
.ts-small, .ts-link {
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--gold);
}
.ts-small { padding: 7px 14px; border-radius: 10px; border: 1px solid var(--border); background: none; }
.ts-small:hover { border-color: var(--gold); }
.ts-link { padding: 0; border: none; background: none; text-decoration: underline; text-underline-offset: 3px; }
.ts-switch { margin: 0 0 16px; }
.ts-check { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-size: 14px; cursor: pointer; }
/* The checkbox itself is .sm-check (branding.css) — shared by every page. */

/* ---- The settings card (account.html; two-step.js, card) ----------------------------
   Its state as a badge beside the heading, what that means under it, and once it's on,
   the recovery codes and the phone as rows with a button each. The heading rules are
   (0,2,1), after shell.css, so they outrank the professional density's bare h3. */
.ts-head { display: flex; align-items: flex-start; gap: 12px 16px; flex-wrap: wrap; }
.ts-icon {
  flex: 0 0 auto; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-wash); color: var(--accent-ink);
}
.ts-icon svg { width: 20px; height: 20px; }
.ts-headtext { flex: 1 1 260px; min-width: 0; }
.ts-card .ts-headtext h3 {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 0;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1.35; letter-spacing: normal;
  color: var(--ink);
}
.ts-card .ts-headtext .ch { margin: 3px 0 0; max-width: 62ch; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.ts-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
}
.ts-badge:empty { display: none; }
.ts-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ts-badge.ts-on { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.ts-badge.ts-todo { background: var(--accent-wash); color: var(--accent-ink); }
.ts-badge.ts-off { background: color-mix(in srgb, var(--ink) 9%, transparent); color: var(--muted); }
.ts-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.ts-actions:empty { display: none; }
.ts-parts { margin: 16px 0 0 56px; border: 1px solid var(--line); border-radius: 12px; }
.ts-parts:empty { display: none; }
.ts-part { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; padding: 14px 16px; }
.ts-part + .ts-part { border-top: 1px solid var(--line); }
.ts-part > div { flex: 1 1 240px; min-width: 0; }
.ts-part-lab { font-size: 14px; font-weight: 600; color: var(--ink); }
.ts-part-desc { margin-top: 2px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.ts-part.ts-warn .ts-part-desc { color: var(--accent-ink); font-weight: 600; }
.ts-card #ts-status { margin: 12px 0 0 56px; }
.ts-card #ts-status:empty { display: none; }
@media (max-width: 560px) {
  .ts-parts, .ts-card #ts-status { margin-left: 0; }
}

@media (max-width: 420px) {
  .ts-codes { grid-template-columns: 1fr; }
  .ts-otp-row { gap: 6px; }
}

/* Motion off (the OS setting, or the account's own, data-motion): nothing moves; the
   colours still say what happened, and the caret stays lit. */
@media (prefers-reduced-motion: reduce) {
  .ts-slot b, .ts-otp .ts-slot, .ts-otp .ts-otp-row, .ts-recovery, .ts-modal .sm-modal-input,
  .ts-slot.ts-here:empty::after, .ts-modal > :not(form), .ts-form > * { animation: none !important; }
}
:root[data-motion="off"] .ts-slot b, :root[data-motion="off"] .ts-otp .ts-slot,
:root[data-motion="off"] .ts-otp .ts-otp-row, :root[data-motion="off"] .ts-recovery,
:root[data-motion="off"] .ts-modal .sm-modal-input, :root[data-motion="off"] .ts-slot.ts-here:empty::after,
:root[data-motion="off"] .ts-modal > :not(form), :root[data-motion="off"] .ts-form > * { animation: none !important; }
