/* ===========================================================
   mfa.css — the ring, and the one moment it is allowed to move.

   COLOUR IS RESERVED FOR THE VERDICT. Everything here is one
   ice-white until a code is accepted or refused. Those two states
   are the only place green and red appear in this component's
   life, which is what makes them mean something — a tinted focus
   ring or a coloured hover would spend it.

   The ring is DOTTED because a solid circle at this size and
   weight reads as a loading spinner, and a spinner during
   authentication says "waiting" when the truth is "your turn".
   =========================================================== */

.otpring {
  --ice: #dceaff;
  --ok:  #2ee6a8;
  --bad: #ff4d6a;
  --slot: 74px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.orbit {
  position: relative;
  width: 340px; height: 240px;
  display: flex; align-items: center; justify-content: center;
}

.orbit__ring {
  position: absolute; inset: 50% auto auto 50%;
  width: 210px; height: 210px;
  transform: translate(-50%, -50%);
  overflow: visible;
}
.orbit__path {
  fill: none;
  stroke: color-mix(in srgb, var(--ice) 22%, transparent);
  /* Dotted on purpose: a solid ring at this size reads as a
     loading spinner. */
  stroke-dasharray: 2 8;
  stroke-width: 1.5;
  stroke-linecap: round;
}

/* The point the slots collapse onto. Never drawn — it exists so
   the rotation has a centre that is a real element with a real
   box, rather than a number computed twice and drifting apart. */
.orbit__hub {
  position: absolute; left: 50%; top: 50%;
  width: 1px; height: 1px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Each slot is placed by rotating out along the ring and then
   un-rotating itself, so the box stays upright while its POSITION
   follows the circle. Two transforms, no trigonometry in JS. */
.slot {
  position: absolute; left: 50%; top: 50%;
  width: var(--slot); height: var(--slot);
  margin: calc(var(--slot) / -2) 0 0 calc(var(--slot) / -2);
  transform: rotate(var(--a)) translate(0, -105px) rotate(calc(-1 * var(--a)));
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--ice) 16%, transparent);
  background: #14161c;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  display: grid; place-items: center;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.slot input {
  width: 100%; height: 100%;
  background: none; border: 0; outline: 0;
  text-align: center;
  font: 500 30px/1 'Sora', system-ui, sans-serif;
  color: var(--ice);
  caret-color: color-mix(in srgb, var(--ice) 55%, transparent);
  border-radius: inherit;
}
.slot input::-webkit-outer-spin-button,
.slot input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Focus is brightness, not hue — see the header. */
.slot:focus-within {
  border-color: color-mix(in srgb, var(--ice) 46%, transparent);
  background: #191c23;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5),
              0 0 0 1px color-mix(in srgb, var(--ice) 18%, transparent);
}

/* ---- the two moments colour is allowed ---- */
.otpring.is-ok .slot {
  border-color: color-mix(in srgb, var(--ok) 55%, transparent);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45),
              0 0 0 1px color-mix(in srgb, var(--ok) 30%, transparent);
}
.otpring.is-ok .slot input { color: var(--ok); }
.otpring.is-ok .orbit__path { stroke: color-mix(in srgb, var(--ok) 40%, transparent); }

.otpring.is-bad .slot {
  border-color: color-mix(in srgb, var(--bad) 55%, transparent);
  animation: otp-nudge .3s ease;
}
.otpring.is-bad .slot input { color: var(--bad); }

@keyframes otp-nudge {
  0%, 100% { margin-left: calc(var(--slot) / -2); }
  25%      { margin-left: calc(var(--slot) / -2 - 4px); }
  75%      { margin-left: calc(var(--slot) / -2 + 4px); }
}

.otpring.is-busy { opacity: .7; pointer-events: none; }

.otpring__status {
  margin: 0; min-height: 1.2em;
  font-size: 12.5px; letter-spacing: .01em;
  color: color-mix(in srgb, var(--ice) 55%, transparent);
}
.otpring.is-ok  .otpring__status { color: var(--ok); }
.otpring.is-bad .otpring__status { color: var(--bad); }

/* A person who has asked not to be moved is not celebrated at.
   The verdict still arrives — it just arrives as colour. */
@media (prefers-reduced-motion: reduce) {
  .slot { transition: none; }
  .otpring.is-bad .slot { animation: none; }
}

/* Narrow: the ring stops being the point and the row takes over.
   A 340px orbit on a 360px phone leaves the slots touching the
   edges, and a code you cannot type is worse than one without a
   flourish. */
@media (max-width: 420px) {
  .orbit { width: 100%; height: auto; padding: 8px 0; flex-wrap: wrap; gap: 8px; }
  .orbit__ring, .orbit__hub { display: none; }
  .slot {
    position: static; margin: 0; transform: none;
    width: 46px; height: 56px; border-radius: 12px;
  }
  .slot input { font-size: 22px; }
  .otpring.is-bad .slot { animation: none; }
}

/* ===========================================================
   The two screens the ring sits on.

   These follow the modal's own palette rather than the ring's:
   the ring is a moment, and this is a form around it. The one
   thing given real weight is the SECRET — because half the people
   who fail to enrol are reading this screen on the phone that was
   supposed to scan the QR code, and the typed key is their only
   way through.
   =========================================================== */

.mfa-alt {
  display: flex; flex-wrap: wrap; gap: 10px 18px;
  align-items: baseline; justify-content: center;
  margin: 6px 0 2px;
}

/* A link that is a button. Underlined rather than merely coloured,
   because "lost the phone?" has to be findable by somebody who is
   already flustered and possibly cannot distinguish the hue. */
.linkish {
  background: none; border: 0; padding: 0;
  font: inherit; font-size: 12.5px;
  color: color-mix(in srgb, var(--ice, #dceaff) 72%, transparent);
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.linkish:hover { color: var(--ice, #dceaff); }
.linkish:disabled { opacity: .5; cursor: default; text-decoration: none; }

.mfa-hint {
  margin: 6px 0 0;
  font-size: 12px; line-height: 1.5;
  color: color-mix(in srgb, var(--ice, #dceaff) 48%, transparent);
}

/* ---- the recovery-code field ---- */
.mfa-rec {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid color-mix(in srgb, var(--ice, #dceaff) 12%, transparent);
  display: grid; gap: 10px; justify-items: stretch;
}
.mfa-rec input {
  font: 500 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .12em; text-transform: uppercase;
}

/* ---- enrolment ---- */
.mfa-enrol {
  display: grid; grid-template-columns: auto 1fr; gap: 20px;
  align-items: start; margin: 4px 0 18px;
}
.mfa-qr {
  width: 172px; height: 172px;
  display: grid; place-items: center;
  padding: 10px; border-radius: 12px;
  /* White behind it deliberately: a QR code rendered dark-on-dark
     is one a phone camera will not read, and the person has no way
     to know that is why. */
  background: #fff;
}
.mfa-qr svg, .mfa-qr img, .mfa-qr canvas { width: 100%; height: 100%; }
.mfa-qr--none {
  background: color-mix(in srgb, var(--ice, #dceaff) 6%, transparent);
  font-size: 12px; line-height: 1.5; text-align: center; padding: 16px;
  color: color-mix(in srgb, var(--ice, #dceaff) 55%, transparent);
}
.mfa-manual > span {
  display: block; font-size: 12px;
  color: color-mix(in srgb, var(--ice, #dceaff) 55%, transparent);
}

/* The typed key. Monospace, spaced, and selectable in one gesture
   — it is going to be copied by hand into another device. */
.mfa-secret {
  display: block; margin: 8px 0 0; padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ice, #dceaff) 16%, transparent);
  background: #14161c;
  font: 500 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .16em; word-break: break-all;
  user-select: all;
}

/* ---- the codes, once ---- */
.mfa-codes {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 20px;
  margin: 14px 0; padding: 0 0 0 22px;
}
.mfa-codes code {
  font: 500 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em;
}

@media (max-width: 560px) {
  .mfa-enrol { grid-template-columns: 1fr; justify-items: center; }
  .mfa-codes { grid-template-columns: 1fr; }
}

/* ===========================================================
   The administrator's half of the security screen.

   A list of names with no state is a screen that cannot answer
   the only question worth asking before a firm turns the
   requirement on: who is actually protected. So the state is a
   column, in words, and the accounts WITHOUT a factor are the
   ones drawn dimmer — they are the exposure, and a table that
   highlights the safe rows highlights the wrong thing.
   =========================================================== */

.mfa-admin {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid color-mix(in srgb, var(--ice, #dceaff) 12%, transparent);
}

.mfa-switch {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; cursor: pointer;
}
.mfa-switch input { width: 16px; height: 16px; accent-color: var(--ok, #2ee6a8); }

.mfa-roster {
  width: 100%; margin: 14px 0 4px;
  border-collapse: collapse; font-size: 12.5px;
}
.mfa-roster td {
  padding: 9px 10px;
  border-top: 1px solid color-mix(in srgb, var(--ice, #dceaff) 9%, transparent);
  vertical-align: middle;
}
.mfa-roster td:first-child b { display: block; font-weight: 600; }
.mfa-roster td:first-child span {
  display: block; font-size: 11.5px;
  color: color-mix(in srgb, var(--ice, #dceaff) 45%, transparent);
}
.mfa-roster td:last-child { text-align: right; white-space: nowrap; }

/* An account with no second factor is the exposure. Dimming the
   protected rows would draw the eye to the wrong ones. */
.mfa-roster tr.is-off td { color: color-mix(in srgb, var(--ice, #dceaff) 52%, transparent); }
.mfa-roster tr:not(.is-off) td:nth-child(2) { color: var(--ok, #2ee6a8); }

.mfa-clear-why {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  background: color-mix(in srgb, var(--ice, #dceaff) 5%, transparent);
}
.mfa-clear-why .ml-modal-field { flex: 1 1 260px; margin: 0; }
.mfa-cleared { color: var(--ok, #2ee6a8); line-height: 1.5; }

@media (max-width: 560px) {
  .mfa-roster td { display: block; border-top: 0; padding: 4px 0; }
  .mfa-roster tr { display: block; padding: 10px 0;
    border-top: 1px solid color-mix(in srgb, var(--ice, #dceaff) 9%, transparent); }
  .mfa-roster td:last-child { text-align: left; }
}
