/* ============================================================
   auth.css — Página de inicio de sesión / registro
   Usa los tokens y componentes de styles.css (cárgalo antes).
   ============================================================ */

.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
}

/* Header minimalista */
.auth-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.auth-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

/* Zona central */
.auth-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(24px, 6vw, 64px) var(--pad);
}
.auth-wrap {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.auth-card {
  width: 100%;
  padding: clamp(24px, 5vw, 40px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* Fail-closed: acceso no disponible (sin Supabase/config/SDK) */
.auth-unavailable {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid #f3c7c7;
  border-radius: 12px;
  background: #fdf2f2;
  color: #8a1c1c;
  font-size: .92rem;
}
.auth-unavailable p { margin: 0; }
.auth-unavailable .btn { justify-self: start; }
.auth-unavailable[hidden] { display: none; }
.auth-form button[disabled], .social-btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Pestañas Iniciar sesión / Crear cuenta */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 26px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: 999px;
}
.auth-tab {
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .9rem;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, color .2s;
}
.auth-tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.auth-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  letter-spacing: -.02em;
}
.auth-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: .95rem;
}

/* Botones sociales (visuales, sin auth real todavía) */
.auth-social {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}
.social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .92rem;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s var(--ease);
}
.social-btn:hover { border-color: var(--ink); background: var(--bg-2); }
.social-btn:active { transform: translateY(1px); }
.social-btn svg { width: 18px; height: 18px; flex: none; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 22px 0 18px;
  color: var(--muted-2);
  font-size: .82rem;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* Formularios */
.auth-form { display: grid; gap: 16px; }
.auth-form[hidden] { display: none; }

.field { display: grid; gap: 6px; }
.field[hidden] { display: none; }
.field label {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .82rem;
  color: var(--ink-soft);
}
.field input {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, .08);
}
.field.has-error input { border-color: #b00020; }
.field-error { font-size: .8rem; color: #b00020; }
.field-error:empty { display: none; }

.input-wrap { position: relative; }
.input-wrap input { width: 100%; padding-right: 46px; }
.toggle-pw {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.toggle-pw:hover { background: var(--bg-2); color: var(--ink); }
.toggle-pw svg { width: 18px; height: 18px; }

.forgot-row { margin-top: -4px; }

.auth-form .btn { height: 50px; margin-top: 2px; }

.form-message {
  display: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: .88rem;
}
.form-message.is-error { display: block; background: #fdecee; color: #b00020; }
.form-message.is-success { display: block; background: #eef7ee; color: #1e6b2e; }
.form-message.is-info { display: block; background: var(--bg-2); color: var(--ink-soft); }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
}
.forgot-row .link-btn { font-weight: 500; font-size: .88rem; color: var(--ink-soft); }

.auth-switch {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line-2);
  text-align: center;
  font-size: .9rem;
  color: var(--muted);
}
.auth-switch .link-btn { margin-left: 4px; }

.auth-demo-note {
  margin-top: 16px;
  font-size: .78rem;
  color: var(--muted-2);
  text-align: center;
}

/* Estado: ya hay sesión */
.auth-loggedin { display: grid; gap: 14px; text-align: center; }
/* display:grid empata con el [hidden] del navegador y le gana: sin esto el
   panel "Ya has iniciado sesión" se veía SIEMPRE bajo el formulario. */
.auth-loggedin[hidden] { display: none; }
.auth-loggedin .user-avatar {
  width: 54px;
  height: 54px;
  margin: 4px auto 0;
  font-size: 1.25rem;
}
.auth-loggedin p { color: var(--ink-soft); }

.auth-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 22px;
  color: var(--muted);
  text-decoration: none;
  font-size: .88rem;
}
.auth-back:hover { color: var(--ink); }
.auth-back::before { content: "\2190"; }

/* Avisos flotantes */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  display: grid;
  gap: 8px;
  width: min(92vw, 420px);
}
.toast {
  padding: 13px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: .88rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- Selector de rol (crear cuenta) ---------- */
.auth-role { display: grid; gap: 8px; }
.auth-role__opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  cursor: pointer;
  font-size: .9rem;
  color: var(--ink-soft);
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.auth-role__opt:hover { border-color: var(--ink); }
.auth-role__opt input {
  margin: 1px 0 0;
  width: 16px;
  height: 16px;
  flex: none;
  accent-color: var(--ink);
}
.auth-role__opt:has(input:checked) {
  border-color: var(--ink);
  background: var(--bg-2);
  color: var(--ink);
}
.auth-role__opt:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- CAPTCHA adaptativo (solo aparece ante actividad sospechosa) ----------
   Ver js/auth-throttle.js + SECURITY-AUTH.md. No forma parte del flujo
   normal: queda oculto hasta que hay varios intentos fallidos o abuso. */
.auth-captcha { display: grid; gap: 8px; }
.auth-captcha[hidden] { display: none; }
.auth-captcha__widget { min-height: 0; }
.auth-captcha__widget:empty { min-height: 0; }
.auth-captcha__hint[hidden] { display: none; }
/* Con Supabase Attack Protection el widget SIEMPRE se monta (necesita entregar
   un token en cada petición), pero en "interaction-only" es invisible para el
   usuario legítimo. Mientras no haya actividad sospechosa lo sacamos del flujo
   visual sin usar display:none (Turnstile necesita estar renderizado para
   ejecutar el reto). Al marcarse (is-flagged) vuelve a su sitio. */
.auth-captcha--quiet {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
}
.auth-captcha__hint {
  margin: 0;
  font-size: .8rem;
  color: var(--ink-soft, #666);
  line-height: 1.4;
}


/* Móvil / táctil: pestañas y enlaces del formulario con objetivo >= 44px. */
@media (pointer: coarse) {
  .auth-tab { height: 44px; }
  .toggle-pw { width: 44px; height: 44px; }
  .auth-main { padding-bottom: max(clamp(24px, 6vw, 64px), env(safe-area-inset-bottom)); }
}

/* Casillas de aceptación legal y marketing (registro) */
.auth-consent { margin-top: 2px; }
.auth-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: .86rem; line-height: 1.5; color: var(--ink-soft, #3d3d3d); }
.auth-check input { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 2px; accent-color: var(--ink, #0a0a0a); cursor: pointer; }
.auth-check a { color: var(--ink, #0a0a0a); text-decoration: underline; text-underline-offset: 2px; }
.auth-check__hint { display: block; margin: 4px 0 0 28px; color: var(--muted, #6f6f6f); font-size: .78rem; }
.field.has-error .auth-check input { outline: 2px solid #b00020; outline-offset: 2px; }
.field .auth-check { display: flex; margin: 0; font-family: var(--font-body, Inter, system-ui, sans-serif); font-weight: 400; font-size: .86rem; color: var(--ink-soft, #3d3d3d); }
