/* Sign-in code page, step 2 (the code comes by email and, when it is switched on, WhatsApp): the countdown ring, the
   six code boxes, where the code went, and every state (waiting, wrong code, expired, locked, success). */

/* ---------- step 2: the code ---------- */

#code-form {
  --ring-color: var(--brand);
  --time-color: var(--ink);
  --track-color: #e3e9f3;
}

#code-form[data-urgency='warn'] {
  --ring-color: #d97706;
  --time-color: #a44a06;
}

#code-form[data-urgency='danger'],
#code-form[data-phase='expired'],
#code-form[data-phase='locked'] {
  --ring-color: #dc2626;
  --time-color: var(--danger);
}

#code-form[data-phase='expired'],
#code-form[data-phase='locked'] {
  --track-color: #fbd3ce;
}

#code-form[data-phase='success'] {
  --ring-color: #16a34a;
  --time-color: var(--ok);
}

.ring {
  position: relative;
  flex: none;
  width: 5.5rem;
  height: 5.5rem;
  margin: 0.9rem auto 0;
}

.ring > svg {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}

.ring-track {
  stroke: var(--track-color);
  transition: stroke 0.4s;
}

.ring-arc {
  stroke: var(--ring-color);
  stroke-dasharray: 100 100;
  transition: opacity 0.3s, stroke 0.4s;
}

.ring-wait {
  stroke: var(--brand);
  stroke-dasharray: 26 74;
  opacity: 0;
  transition: opacity 0.3s;
}

.ring-spin {
  transform-origin: 50px 50px;
}

.panel.is-active[data-phase='sending'] .ring-spin {
  animation: spin 1.15s linear infinite;
}

.ring-dot {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.ring-dot i {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 0.75rem;
  height: 0.75rem;
  margin: -0.375rem 0 0 -0.375rem;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--ring-color);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.35);
  transition: background-color 0.4s;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.ring-mail {
  grid-area: 1 / 1;
  width: 2.1rem;
  height: 2.1rem;
  fill: none;
  stroke: var(--brand);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.3s;
}

.panel.is-active[data-phase='sending'] .ring-mail {
  animation: mail-bob 1.4s ease-in-out infinite;
}

@keyframes mail-bob {
  0%, 100% { transform: translate3d(0, 0.12rem, 0); }
  50% { transform: translate3d(0, -0.18rem, 0); }
}

.ring-check {
  grid-area: 1 / 1;
  width: 2.6rem;
  height: 2.6rem;
  fill: none;
  stroke: var(--ring-color);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.ring-check path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.ring-time {
  grid-area: 1 / 1;
  font: 600 1.375rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--time-color);
  opacity: 0;
  transition: opacity 0.3s, color 0.3s;
}

[data-phase='sending'] .ring-wait {
  opacity: 1;
}

[data-phase='sending'] .ring-arc,
[data-phase='sending'] .ring-dot,
[data-phase='success'] .ring-dot,
[data-phase='expired'] .ring-arc,
[data-phase='expired'] .ring-dot,
[data-phase='locked'] .ring-arc,
[data-phase='locked'] .ring-dot {
  opacity: 0;
}

[data-phase='success'] .ring-mail,
[data-phase='success'] .ring-time {
  opacity: 0;
  transition-duration: 0.1s;
}

[data-phase='success'] .ring-check {
  opacity: 1;
}

[data-phase='success'] .ring-check path {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.5s 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-phase='ready'] .ring-time,
[data-phase='verifying'] .ring-time,
[data-phase='expired'] .ring-time,
[data-phase='locked'] .ring-time {
  opacity: 1;
}

[data-phase='ready'] .ring-mail,
[data-phase='verifying'] .ring-mail,
[data-phase='expired'] .ring-mail,
[data-phase='locked'] .ring-mail {
  opacity: 0;
}

[data-phase='sending'] .resend,
[data-phase='sending'] .tiny,
[data-phase='sending'] .back {
  opacity: 0.5;
}

/* While the code is on its way, and again once it is accepted, the main content sits a little lower, in the middle of the card,
   instead of leaving an empty band under it. It glides back up when the code screen is ready. (Whole-pixel offsets, so text stays crisp.) */
#code-form {
  --sink: 40px;
}

#code-form > .ring,
#code-form > .title,
#code-form > .lede,
#code-form > .otp,
#code-form > .status {
  transition: transform 0.4s var(--ease-out);
}

#code-form[data-phase='sending'] > .ring,
#code-form[data-phase='sending'] > .title,
#code-form[data-phase='sending'] > .lede,
#code-form[data-phase='sending'] > .otp,
#code-form[data-phase='sending'] > .status,
#code-form[data-phase='success'] > .ring,
#code-form[data-phase='success'] > .title,
#code-form[data-phase='success'] > .lede,
#code-form[data-phase='success'] > .otp,
#code-form[data-phase='success'] > .status {
  transform: translateY(var(--sink));
}

[data-phase='success'] .resend,
[data-phase='success'] .tiny,
[data-phase='success'] .back {
  visibility: hidden;
}

[data-phase='expired'] .resend,
[data-phase='expired'] .tiny,
[data-phase='expired'] .lede-note,
[data-phase='locked'] .resend,
[data-phase='locked'] .tiny,
[data-phase='locked'] .lede-note {
  display: none;
}

/* Where the code went: one small pill per place it really went (WhatsApp shows only the last two digits of the number). The pills
   share one row when they fit; a long email address is cut with "..." so a pill is never taller than one line. */
.lede-dest {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 0.4rem;
  margin: 0.5rem 0 0.1rem;
}

.dest {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  max-width: 100%;
  padding: 0.22rem 0.7rem 0.22rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  font-size: 0.8125rem;
  line-height: 1.3;
  color: var(--muted);
}

.dest svg {
  flex: none;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dest-whatsapp svg {
  color: var(--ok);
}

.dest-email svg {
  color: var(--brand);
}

/* The place's name ("WhatsApp" / "Email") is for screen readers; on screen the icon and the value are enough, and the pills fit on one row. */
.dest-name {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.dest strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.otp {
  position: relative;
  margin-top: 1rem;
}

.tiles {
  display: flex;
  justify-content: center;
  gap: clamp(0.3rem, 1.8vw, 0.5rem);
  perspective: 40rem;
  transition: opacity 0.25s;
}

.tile {
  position: relative;
  flex: 1 1 0;
  max-width: 3.25rem;
  aspect-ratio: 52 / 60;
  display: grid;
  place-items: center;
  border: 1px solid var(--field-line);
  border-radius: 0.625rem;
  background: #fff;
  transition: border-color 0.15s, background-color 0.2s, box-shadow 0.15s;
}

.tiles[data-len='6'] .tile:nth-child(3) {
  margin-right: clamp(0.15rem, 1.2vw, 0.5rem);
}

.tile::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 1.6rem;
  margin: -0.8rem 0 0 -1px;
  border-radius: 2px;
  background: var(--brand);
  opacity: 0;
}

.digit {
  font: 600 1.75rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transform-origin: 50% 60%;
}

.tile.is-filled {
  border-color: #5f86d8;
  background: var(--brand-tint);
}

.tile.is-active {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 1px var(--brand), 0 0 0 4px var(--brand-halo);
}

.tile.is-active.is-filled {
  background: var(--brand-tint);
}

.tile.is-active:not(.is-filled)::before {
  animation: blink 1.05s steps(1) infinite;
}

.tile.is-error {
  border-color: var(--danger);
  background: var(--danger-bg);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.14);
}

.tile.is-error .digit {
  color: var(--danger);
}

.tile.is-ok {
  border-color: #22a35a;
  background: var(--ok-bg);
  box-shadow: none;
}

.tile.is-ok .digit {
  color: var(--ok-text);
}

.tiles.is-busy .tile {
  animation: wave 0.9s ease-in-out infinite;
  animation-delay: calc(var(--n) * 80ms);
}

.tiles.is-off {
  opacity: 0.55;
}

.tiles.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.otp-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  font-size: 1rem;
  text-align: center;
  cursor: text;
}

.otp-input::selection {
  background: transparent;
}

.otp-input:disabled {
  cursor: default;
}

@keyframes blink {
  50% { opacity: 0; }
  0%, 100% { opacity: 1; }
}

@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

@keyframes wave {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(0, -0.22rem, 0); }
}

.status {
  display: grid;
  place-items: center;
  min-height: 2.4rem;
  margin-top: 0.75rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
  color: var(--text);
}

.status.is-error {
  border-color: var(--danger-line);
  background: var(--danger-bg);
  color: var(--danger-text);
  font-weight: 500;
}

.status.is-ok {
  border-color: var(--ok-line);
  background: var(--ok-bg);
  color: var(--ok-text);
  font-weight: 500;
}

.status.is-info {
  color: #1b3a7a;
}

.status-count {
  display: block;
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.status-count:empty {
  display: none;
}

.code-actions .btn-primary {
  margin-top: 0.75rem;
}

.resend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  margin-top: 0.15rem;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.2;
}

.tiny {
  margin: 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
}

.back {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.3rem;
  color: var(--muted);
  text-decoration: none;
}

.back svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back:hover:not(:disabled) {
  color: var(--brand-press);
  text-decoration: underline;
}

.back:disabled {
  color: #6b7a90;
}
