/* ==========================================================================
   twofa.css — verificacion en dos pasos (codigo de 6 numeros)
   --------------------------------------------------------------------------
   Se usa en dos contextos:
   - Pantalla del codigo despues del login (views/partials/auth-2fa-page.ejs),
     sobre auth.css: mismos rojos del login (#ff4d4d -> #990000).
   - Activacion y tarjeta de Configuracion dentro del panel (glass.css), que
     tambien tiene tema claro: por eso todo toma las variables del panel
     (--g-*, --accent, --text) con los valores del login como respaldo.
   ========================================================================== */

.tfa-otp,
.tfa-steps,
.tfa-codes-card,
.tfa-settings {
  --tfa-accent: var(--a-red, var(--accent, #ff3947));
  --tfa-accent-deep: var(--a-red-deep, var(--accent-2, #a01a26));
  --tfa-text: var(--a-text, var(--text, #f5f5f5));
  --tfa-muted: var(--a-muted, var(--muted, #a8a8ac));
  --tfa-box-bg: var(--g-input, rgba(255, 255, 255, 0.05));
  --tfa-box-border: var(--g-border-strong, rgba(255, 255, 255, 0.12));
  --tfa-font: var(--a-font, var(--font-body, 'Plus Jakarta Sans', system-ui, sans-serif));
  --tfa-mono: var(--font-mono, 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace);
}

/* Etiqueta solo para lectores de pantalla (auth.css ya la tiene; aca para las pantallas del panel) */
.tfa-otp .auth-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* ======================== CAMPO DE 6 NUMEROS ======================== */
.tfa-otp {
  position: relative;
  width: 100%;
  max-width: 416px;
  margin: 4px auto 14px;
}
.tfa-otp-row { display: flex; align-items: stretch; gap: 8px; }
.tfa-otp-field { position: relative; flex: 1 1 auto; min-width: 0; }

/* Sin JS: un campo normal, grande y centrado */
.tfa-otp-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--tfa-box-border);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--tfa-box-bg);
  color: var(--tfa-text);
  font-family: var(--tfa-mono);
  font-size: 1.6rem;
  letter-spacing: 0.5em;
  text-align: center;
  outline: none;
}
.tfa-otp-input:focus { border-bottom-color: var(--tfa-accent); }
.tfa-otp.is-masked .tfa-otp-input { -webkit-text-security: disc; }
.tfa-otp-boxes { display: none; }

/* Con JS: el input real queda invisible ENCIMA de las casillas (recibe
   teclado, pegar y autocompletado) y las casillas muestran cada numero. */
html.tfa-js .tfa-otp-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px; /* iOS no hace zoom */
  letter-spacing: 0;
  opacity: 0.01;
  cursor: text;
}
html.tfa-js .tfa-otp-input::selection { background: transparent; }

html.tfa-js .tfa-otp-boxes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 14px repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.tfa-otp-box {
  position: relative;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--tfa-box-bg);
  border: 1px solid var(--tfa-box-border);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
  color: var(--tfa-text);
  font-family: var(--tfa-mono);
  font-size: 1.65rem;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.25s ease, transform 0.2s ease, background 0.2s ease;
}
.tfa-otp-box.is-filled {
  border-color: rgba(255, 77, 77, 0.45);
  background: rgba(255, 77, 77, 0.08);
  animation: tfaPop 0.22s ease-out;
}
.tfa-otp.is-focused .tfa-otp-box.is-active {
  border-color: var(--tfa-accent);
  border-bottom-color: var(--tfa-accent);
  box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.18), 0 6px 18px -6px rgba(255, 0, 0, 0.55);
}
.tfa-otp.is-focused .tfa-otp-box.is-active:not(.is-filled)::after {
  content: '';
  width: 2px;
  height: 26px;
  border-radius: 2px;
  background: var(--tfa-accent);
  animation: tfaCaret 1s steps(1) infinite;
}
.tfa-otp.is-complete .tfa-otp-box {
  border-color: rgba(53, 210, 138, 0.55);
  background: rgba(53, 210, 138, 0.08);
}
/* Oculto: un puntito en el centro de la casilla en vez del numero */
.tfa-otp-box.is-dot::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tfa-text);
  box-shadow: 0 0 10px rgba(255, 77, 77, 0.55);
}

/* Ojito: mostrar / ocultar lo que se escribio (solo con JS) */
.tfa-otp-eye {
  flex: 0 0 48px;
  height: 60px;
  display: none;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  background: var(--tfa-box-bg);
  border: 1px solid var(--tfa-box-border);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  color: var(--tfa-muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
html.tfa-js .tfa-otp-eye { display: grid; }
.tfa-otp-eye svg { width: 22px; height: 22px; }
.tfa-otp-eye:hover { color: var(--tfa-text); border-color: rgba(255, 77, 77, 0.45); }
.tfa-otp-eye:focus-visible { outline: none; color: var(--tfa-text); border-color: var(--tfa-accent); box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.22); }
.tfa-otp-eye[aria-pressed="true"] { color: var(--tfa-accent); background: rgba(255, 77, 77, 0.08); border-color: rgba(255, 77, 77, 0.45); }
.tfa-eye-hide { display: none; }
.tfa-otp.is-revealed .tfa-eye-show { display: none; }
.tfa-otp.is-revealed .tfa-eye-hide { display: block; }

.tfa-otp-dash {
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
}

@keyframes tfaPop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
@keyframes tfaCaret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Codigo de respaldo: mayusculas y espaciado para leerlo bien */
.tfa-recovery-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace) !important;
}

.auth-page-2fa .tfa-back { margin-top: 10px; font-size: 0.82rem; }
.tfa-attempts { display: inline-block; margin-left: 4px; color: #ff6b75; white-space: nowrap; }
.auth-page-2fa .tfa-back a { color: var(--a-muted, #bbb); font-weight: 400; }
.auth-page-2fa .tfa-back a:hover { color: var(--a-red, #ff4d4d); }
.auth-page-2fa .auth-card { min-height: 480px; }

/* ======================== ACTIVACION (dentro del panel) ======================== */
.tfa-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.tfa-step { position: relative; margin: 0; }
.tfa-step .wave-section-body { display: flex; flex-direction: column; gap: 10px; }
.tfa-step-num {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--tfa-accent), var(--tfa-accent-deep));
  box-shadow: 0 6px 16px -4px rgba(255, 0, 0, 0.5);
}
.tfa-step-title { margin: 0; font-size: 1.05rem; }
.tfa-step-desc { margin: 0; color: var(--tfa-muted); font-size: 0.88rem; line-height: 1.55; }

.tfa-confirm-form { display: flex; flex-direction: column; gap: 12px; }
.tfa-confirm-form .field { margin: 0; }
.tfa-confirm-form .tfa-otp { margin: 6px 0 0; }
.tfa-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }

/* Aviso "volve a iniciar sesion" */
.tfa-unavailable {
  --tfa-muted: var(--muted, #a8a8ac);
  max-width: 620px;
}
.tfa-unavailable .wave-section-body { display: flex; flex-direction: column; gap: 12px; }
.tfa-unavailable p { margin: 0; color: var(--tfa-muted); line-height: 1.6; }
.tfa-unavailable form { margin: 0; }

/* Codigos de respaldo (se muestran una sola vez) */
.tfa-codes-card .wave-section-body { display: flex; flex-direction: column; gap: 16px; }
.tfa-codes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  counter-reset: tfa;
  max-width: 560px;
}
.tfa-codes li {
  counter-increment: tfa;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--g-subtle, rgba(255, 255, 255, 0.035));
  border: 1px solid var(--g-border, rgba(255, 255, 255, 0.1));
}
.tfa-codes li::before {
  content: counter(tfa);
  font-size: 0.72rem;
  color: var(--tfa-muted);
  min-width: 1.2em;
}
.tfa-codes code {
  font-family: var(--tfa-mono);
  font-size: 1rem;
  letter-spacing: 0.08em;
  color: var(--tfa-text);
}

/* Codigo de seguridad (grande) y bloque de codigos de respaldo */
.tfa-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 20px;
  border-radius: 16px;
  max-width: 560px;
  background: linear-gradient(135deg, rgba(255, 57, 71, 0.16), rgba(160, 26, 38, 0.08));
  border: 1px solid rgba(255, 77, 77, 0.45);
  box-shadow: 0 14px 40px -18px rgba(255, 0, 0, 0.6);
}
.tfa-main-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #ff8080; }
.tfa-main-code {
  font-family: var(--tfa-mono);
  font-size: clamp(2.1rem, 9vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--tfa-text);
  line-height: 1.1;
}
.tfa-main-hint { font-size: 0.84rem; color: var(--tfa-muted); }
.tfa-backup { display: flex; flex-direction: column; gap: 8px; }
.tfa-backup-title { margin: 0; font-size: 1.02rem; }
.tfa-confirm-inline {
  max-width: 560px;
  padding-top: 16px;
  border-top: 1px solid var(--g-divider, rgba(255, 255, 255, 0.07));
}
.tfa-confirm-inline .tfa-otp,
.tfa-codes-card .tfa-confirm-form .tfa-otp { margin: 4px 0 0; }
.tfa-restart {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0;
  padding-top: 12px;
  font-size: 0.86rem;
  color: var(--tfa-muted);
  border-top: 1px solid var(--g-divider, rgba(255, 255, 255, 0.07));
}
.tfa-intro-actions { margin-top: 16px; }

/* Elegir el codigo: propio o aleatorio */
.tfa-choose-title { margin: 0 0 12px; font-size: 1.08rem; }
.tfa-choices {
  --tfa-accent: var(--accent, #ff3947);
  --tfa-text: var(--text, #f5f5f5);
  --tfa-muted: var(--muted, #a8a8ac);
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}
.tfa-choice { margin: 0; }
.tfa-choice .wave-section-body { display: flex; flex-direction: column; gap: 12px; height: 100%; box-sizing: border-box; }
.tfa-choice-head { display: flex; align-items: center; gap: 12px; }
.tfa-choice-head h3 { margin: 0; font-size: 1.02rem; }
.tfa-choice-icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--tfa-accent), var(--accent-2, #a01a26));
  box-shadow: 0 6px 16px -4px rgba(255, 0, 0, 0.5);
}
.tfa-choice-icon svg { width: 20px; height: 20px; }
.tfa-choice-custom { border-color: rgba(255, 77, 77, 0.4); }
.tfa-choice form { display: flex; flex-direction: column; gap: 10px; margin: 0; flex: 1; }
.tfa-choice .tfa-otp { margin: 2px 0 0; max-width: 416px; }
.tfa-choice-label { font-size: 0.84rem; font-weight: 600; color: var(--tfa-text); }
.tfa-choice-rules { margin: 0; font-size: 0.8rem; line-height: 1.5; color: var(--tfa-muted); }
.tfa-choice .btn { align-self: flex-start; margin-top: auto; }
.tfa-steps-title { margin: 6px 0 12px; font-size: 0.95rem; color: var(--muted, #a8a8ac); font-weight: 600; }

/* Codigo elegido: se activa marcando "ya guarde mis codigos" */
.tfa-finish.tfa-ack { flex-direction: column; align-items: stretch; justify-content: flex-start; }
.tfa-ack .tfa-backup-title,
.tfa-ack .tfa-step-desc { margin: 0; }
.tfa-ack .tfa-saved { align-items: flex-start; }
.tfa-ack .tfa-saved input { margin-top: 1px; flex-shrink: 0; }
.tfa-ack .tfa-actions { margin-top: 0; }
.tfa-intro-actions form { margin: 0; }

/* Aviso de captura de pantalla + "ya guarde mis codigos" */
.tfa-screenshot {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--tfa-muted);
  background: rgba(255, 177, 59, 0.08);
  border: 1px dashed rgba(255, 177, 59, 0.4);
  max-width: 560px;
}
.tfa-screenshot svg { width: 20px; height: 20px; flex-shrink: 0; color: #ff6b75; margin-top: 1px; }
.tfa-finish {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--g-divider, rgba(255, 255, 255, 0.07));
  max-width: 560px;
}
.tfa-saved { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.92rem; color: var(--tfa-text); }
.tfa-saved input { width: 20px; height: 20px; accent-color: var(--tfa-accent); cursor: pointer; }
.tfa-finish .btn.is-disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; filter: grayscale(0.4); }

/* ======================== TARJETA EN CONFIGURACION ======================== */
.tfa-settings .wave-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tfa-settings-heading { display: inline-flex; align-items: center; gap: 8px; }
.tfa-settings-heading svg { width: 18px; height: 18px; color: var(--tfa-accent); }
.tfa-settings .wave-section-body { display: flex; flex-direction: column; gap: 12px; }
.tfa-settings-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.tfa-settings-desc { margin: 0; color: var(--tfa-muted); font-size: 0.9rem; line-height: 1.55; max-width: 620px; }
.tfa-left { margin: 0; font-size: 0.88rem; color: var(--tfa-muted); }
.tfa-left strong { color: var(--tfa-text); }
.tfa-left.is-low strong { color: #ff6b75; }

.tfa-manage { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.tfa-manage-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 14px;
  background: var(--g-subtle, rgba(255, 255, 255, 0.035));
  border: 1px solid var(--g-border, rgba(255, 255, 255, 0.1));
}
.tfa-manage-form h3 { margin: 0; font-size: 0.95rem; }
.tfa-manage-form .btn { align-self: flex-start; }
.tfa-manage-form.tfa-danger { border-color: rgba(255, 77, 94, 0.3); }
.tfa-manage-form .field { margin: 0; }
.tfa-manage-form .hint { font-size: 0.78rem; }

/* Campos de codigo en Configuracion: con puntos y ojito para ver lo escrito */
.tfa-secret { position: relative; }
.tfa-secret .tfa-code-input { width: 100%; padding-right: 46px; box-sizing: border-box; }
.tfa-code-input { font-family: var(--tfa-mono) !important; letter-spacing: 0.12em; -webkit-text-security: disc; }
.tfa-code-input.is-revealed { -webkit-text-security: none; }
.tfa-secret-eye {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 34px;
  height: 34px;
  display: none;
  place-items: center;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--tfa-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
html.tfa-js .tfa-secret-eye { display: grid; }
.tfa-secret-eye svg { width: 19px; height: 19px; }
.tfa-secret-eye:hover { color: var(--tfa-text); }
.tfa-secret-eye:focus-visible { outline: 2px solid var(--tfa-accent); outline-offset: 1px; }
.tfa-secret-eye[aria-pressed="true"] { color: var(--tfa-accent); }
.tfa-secret-eye[aria-pressed="true"] .tfa-eye-show { display: none; }
.tfa-secret-eye[aria-pressed="true"] .tfa-eye-hide { display: block; }

/* ======================== MOBILE ======================== */
@media (max-width: 1100px) {
  .tfa-steps { grid-template-columns: 1fr; }
  .tfa-choices { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .tfa-steps { grid-template-columns: 1fr; }
  .tfa-manage { grid-template-columns: 1fr; }
  .tfa-codes { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tfa-codes li { padding: 10px; }
  .tfa-codes code { font-size: 0.9rem; letter-spacing: 0.04em; }
}
@media (max-width: 420px) {
  html.tfa-js .tfa-otp-boxes { gap: 6px; grid-template-columns: repeat(3, minmax(0, 1fr)) 10px repeat(3, minmax(0, 1fr)); }
  .tfa-otp-box { height: 52px; border-radius: 12px; font-size: 1.4rem; }
  .tfa-otp-row { gap: 6px; }
  .tfa-otp-eye { flex-basis: 42px; height: 52px; border-radius: 12px; }
  .tfa-otp-box.is-dot::before { width: 10px; height: 10px; }
  .tfa-codes { grid-template-columns: 1fr; }
  .tfa-actions .btn { flex: 1 1 auto; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .tfa-otp-box, .tfa-otp-box.is-filled { animation: none !important; transition: none !important; }
  .tfa-otp.is-focused .tfa-otp-box.is-active:not(.is-filled)::after { animation: none; }
}

/* ======================== TEMA CLARO (panel) ======================== */
html[data-theme="light"] .tfa-otp-box { border-bottom-color: rgba(0, 0, 0, 0.2); box-shadow: none; }
html[data-theme="light"] .tfa-otp-dash { background: rgba(0, 0, 0, 0.2); }
html[data-theme="light"] .tfa-otp-eye { border-bottom-color: rgba(0, 0, 0, 0.2); }
html[data-theme="light"] .tfa-otp-box.is-dot::before { box-shadow: none; }
html[data-theme="light"] .tfa-otp-input { border-bottom-color: rgba(0, 0, 0, 0.2); }
