/* عزيمة — WhatsApp-first sign-in and registration: live number check, the password step that opens
 * only when it is needed, the six-box code entry and the resend countdown. Colours come from the
 * portal tokens, so day and night themes follow. */

/* Grid rows never shrink below zero, so collapsed steps cannot cancel the form gap with a
 * negative margin: in these forms each block carries its own top spacing instead. */
.auth-form.phone-auth {
  gap: 0;
}
.phone-auth > .field + .field {
  margin-top: 16px;
}
.auth-form.phone-auth > .wa-submit {
  margin-top: 22px;
}

/* ---------- Live mark at the end of the phone input ---------- */
.wa-indicator {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  left: 12px;
  pointer-events: none;
}
.wa-indicator > *,
.wa-status-icon > * {
  grid-area: 1 / 1;
  opacity: 0;
  transform: scale(0.55) rotate(-25deg);
  transition:
    opacity 0.25s ease,
    transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.wa-indicator .icon {
  width: 20px;
  height: 20px;
}
.wa-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: wa-spin 0.75s linear infinite;
}
.phone-auth[data-wa-state="checking"] .wa-spinner,
.phone-auth[data-wa-state="whatsapp"] .wa-mark,
.phone-auth[data-wa-state="registered"] .wa-status-icon .wa-known,
.phone-auth[data-wa-state="registered"] .wa-indicator .wa-alt,
.phone-auth:is([data-wa-state="none"], [data-wa-state="unknown"], [data-wa-state="invalid"]) .wa-alt {
  opacity: 1;
  transform: none;
}
.phone-auth[data-wa-state="whatsapp"] .wa-indicator,
.phone-auth[data-wa-state="whatsapp"] .wa-status {
  color: var(--green);
}
.phone-auth[data-wa-state="none"] .wa-indicator {
  color: var(--amber);
}
.phone-auth[data-wa-state="invalid"] .wa-indicator {
  color: var(--red);
}
.phone-auth[data-wa-state="registered"] .wa-indicator {
  color: var(--blue);
}
.phone-auth[data-wa-state="registered"] #f-phone {
  border-color: rgb(169 198 230 / 50%);
}
.phone-auth #f-phone {
  transition:
    border-color 0.3s,
    box-shadow 0.3s,
    background 0.2s;
}
.phone-auth[data-wa-state="whatsapp"] #f-phone {
  border-color: rgb(147 211 169 / 55%);
  box-shadow: 0 0 0 4px rgb(147 211 169 / 10%);
}
.phone-auth[data-wa-state="none"] #f-phone {
  border-color: rgb(240 196 110 / 45%);
}

/* ---------- Status line under the number ---------- */
.wa-status {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  max-height: 0;
  margin-top: 0;
  padding: 0 12px;
  overflow: hidden;
  border: 0 solid transparent;
  border-radius: var(--r);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
  opacity: 0;
  transition:
    max-height 0.4s var(--ease),
    margin 0.4s var(--ease),
    padding 0.4s var(--ease),
    opacity 0.3s ease,
    background 0.35s,
    border-color 0.35s,
    color 0.35s;
}
.phone-auth:not([data-wa-state="idle"]) .wa-status {
  border-width: 1px;
  max-height: 96px;
  margin-top: 10px;
  padding: 10px 12px;
  opacity: 1;
}
.phone-auth[data-wa-state="checking"] .wa-status,
.phone-auth[data-wa-state="unknown"] .wa-status {
  border-color: var(--line-soft);
  background: var(--line-soft);
}
.phone-auth[data-wa-state="whatsapp"] .wa-status {
  border-color: rgb(147 211 169 / 22%);
  background: var(--green-bg);
}
.phone-auth[data-wa-state="none"] .wa-status {
  border-color: rgb(240 196 110 / 24%);
  background: var(--amber-bg);
  color: var(--amber);
}
.phone-auth[data-wa-state="invalid"] .wa-status {
  border-color: rgb(242 167 156 / 24%);
  background: var(--red-bg);
  color: var(--red);
}
/* Already registered: not an error, a way forward. */
.phone-auth[data-wa-state="registered"] .wa-status {
  border-color: rgb(169 198 230 / 24%);
  background: var(--blue-bg);
  color: var(--blue);
}
.wa-status-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgb(255 255 255 / 5%);
}
.wa-status-icon .icon {
  width: 17px;
  height: 17px;
}
.wa-status-icon .wa-spinner {
  width: 15px;
  height: 15px;
}
/* A ripple the moment the number is found on WhatsApp. */
.wa-status-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.phone-auth[data-wa-state="whatsapp"] .wa-status-icon::after {
  animation: wa-ring 1.4s var(--ease) 0.1s 2;
}
.phone-auth[data-wa-state="checking"] .wa-status-text {
  animation: wa-breathe 1.4s ease-in-out infinite;
}
.is-swapping {
  animation: wa-swap 0.38s var(--ease) both;
}

/* ---------- Backup-password note (registration on WhatsApp) ---------- */
.wa-backup-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-height: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.7;
  opacity: 0;
  transition:
    max-height 0.4s var(--ease),
    margin 0.4s var(--ease),
    opacity 0.3s ease;
}
.wa-backup-note .icon {
  width: 16px;
  height: 16px;
  margin-top: 3px;
  color: var(--gold);
}
.phone-auth[data-wa-state="whatsapp"] .wa-backup-note,
.wa-backup-note.is-static {
  max-height: 80px;
  margin-top: 10px;
  opacity: 1;
}
.wa-backup-note.is-static {
  margin-top: 0;
}

/* ---------- Password step that opens only when needed ---------- */
.reveal {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  opacity: 0;
  transition:
    grid-template-rows 0.5s var(--ease),
    margin 0.5s var(--ease),
    opacity 0.35s ease;
}
.reveal[data-open] {
  grid-template-rows: 1fr;
  margin-top: 16px;
  opacity: 1;
}
.reveal-inner {
  display: grid;
  gap: 16px;
  min-height: 0;
  /* Room for the focus ring, which overflow would clip. */
  margin: -5px;
  padding: 5px;
  overflow: hidden;
}
/* Closed, the step takes no room at all: no ring padding, no border. */
.reveal:not([data-open]) .reveal-inner {
  margin: 0;
  padding: 0;
}
.reveal[data-open] .reveal-inner > * {
  animation: wa-rise 0.5s var(--ease) both;
}
.reveal[data-open] .reveal-inner > :nth-child(2) {
  animation-delay: 0.07s;
}
.reveal .forgot-link {
  margin: -6px 0 0;
}

/* ---------- Submit button follows the step ---------- */
.wa-submit {
  transition:
    box-shadow 0.35s,
    transform 0.2s,
    filter 0.2s;
}
.wa-submit-label {
  display: inline-block;
}
.wa-submit .wa-submit-wa,
.phone-auth[data-wa-state="whatsapp"] .wa-submit .wa-submit-go {
  display: none;
}
.phone-auth[data-wa-state="whatsapp"] .wa-submit .wa-submit-wa {
  display: inline-block;
  animation: wa-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.phone-auth[data-wa-state="whatsapp"] .wa-submit {
  box-shadow:
    0 1px 0 rgb(255 255 255 / 45%) inset,
    0 14px 32px -14px rgb(147 211 169 / 70%);
}

/* ---------- Code screen ---------- */
.auth-icon.wa-pulse {
  position: relative;
  border-color: rgb(147 211 169 / 40%);
  background: var(--green-bg);
  color: var(--green);
}
.auth-icon.wa-pulse .icon {
  width: 26px;
  height: 26px;
}
.auth-icon.wa-pulse::before,
.auth-icon.wa-pulse::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid rgb(147 211 169 / 50%);
  border-radius: 50%;
  animation: wa-ring 2.6s var(--ease) infinite;
}
.auth-icon.wa-pulse::after {
  animation-delay: 1.3s;
}
.wa-phone {
  color: var(--gold-soft);
  font-weight: 600;
  white-space: nowrap;
}

.otp {
  position: relative;
}
.otp-cells {
  display: none;
}
.otp.is-enhanced .otp-cells {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  direction: ltr;
}
/* The real input stays on top, invisible, so typing, paste and one-time-code autofill land in it. */
.otp.is-enhanced .otp-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  min-height: 0;
  height: 100%;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  letter-spacing: 0;
  text-indent: -9999px;
  cursor: text;
}
.otp.is-enhanced .otp-input::selection {
  background: transparent;
}
.otp-cell {
  display: grid;
  place-items: center;
  height: 62px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--field);
  color: var(--gold-soft);
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition:
    border-color 0.2s,
    box-shadow 0.2s,
    color 0.3s,
    background 0.3s;
}
.otp-input:focus + .otp-cells .otp-cell.is-next {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px var(--gold-glow);
}
.otp-input:focus + .otp-cells .otp-cell.is-next:empty::after {
  content: "";
  width: 2px;
  height: 26px;
  border-radius: 2px;
  background: var(--gold);
  animation: wa-caret 1s steps(1) infinite;
}
.otp-cell.is-filled {
  border-color: rgb(220 180 110 / 55%);
  animation: wa-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.otp.is-complete .otp-cell {
  border-color: rgb(147 211 169 / 60%);
  background: var(--green-bg);
  color: var(--green);
  box-shadow: none;
}
.has-error .otp.is-enhanced .otp-cell {
  border-color: rgb(242 167 156 / 65%);
  background: rgb(242 167 156 / 6%);
}
.otp.is-shaking .otp-cells {
  animation: wa-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
.code-resend .text-link:disabled {
  background: none;
  color: var(--text-3);
  text-decoration: none;
  cursor: default;
  opacity: 0.7;
}
.code-resend.is-ready .text-link {
  animation: wa-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.code-resend-wait {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
  .otp.is-enhanced .otp-cells {
    gap: 6px;
  }
  .otp-cell {
    height: 54px;
    font-size: 23px;
  }
}

@keyframes wa-spin {
  to { transform: rotate(360deg); }
}
@keyframes wa-ring {
  from { transform: scale(1); opacity: 0.85; }
  to { transform: scale(1.75); opacity: 0; }
}
@keyframes wa-breathe {
  50% { opacity: 0.55; }
}
@keyframes wa-swap {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
@keyframes wa-rise {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}
@keyframes wa-pop {
  from { transform: scale(0.82); }
  to { transform: scale(1); }
}
@keyframes wa-caret {
  50% { opacity: 0; }
}
@keyframes wa-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  .wa-status,
  .wa-backup-note,
  .reveal,
  .wa-indicator > *,
  .wa-status-icon > * {
    transition: none;
  }
  .reveal[data-open] .reveal-inner > *,
  .is-swapping,
  .otp-cell.is-filled,
  .otp.is-shaking .otp-cells,
  .code-resend.is-ready .text-link,
  .phone-auth[data-wa-state="whatsapp"] .wa-submit .wa-submit-wa,
  .phone-auth[data-wa-state="whatsapp"] .wa-status-icon::after,
  .phone-auth[data-wa-state="checking"] .wa-status-text,
  .auth-icon.wa-pulse::before,
  .auth-icon.wa-pulse::after {
    animation: none;
  }
}
