/* ================================================
   Auth Gate — pantalla de login (G1+G4+G5)
   - Fondo blanco izq/centro
   - Esfera 3D de tarjetas rotando
   - Logo centrado encima de las tarjetas (no separado)
   - Panel de login a la derecha
   ================================================ */

/* ----- Toggling de la app vs gate ----- */
body:not(.is-authenticated) .app-layout { display: none !important; }
body.is-authenticated #auth-gate { display: none !important; }

/* ----- Contenedor principal (grid 2 columnas) ----- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr min(440px, 38%);
  background: var(--bg, #ffffff);
  animation: gateFadeIn 0.4s ease-out;
}

@keyframes gateFadeIn { from { opacity: 0; } to { opacity: 1; } }
.auth-gate[hidden] { display: none !important; }

/* ----- Stage izq/centro: fondo blanco, sphere + logo centrados ----- */
.auth-gate-sphere-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  perspective: 1400px;
  perspective-origin: 50% 50%;
  overflow: hidden;
}

[data-theme="dark"] .auth-gate-sphere-stage {
  background: var(--surface, #13243a);
}

/* v177: wallpaper detrás de la esfera con DCDs, indicadores y íconos
   MINEDUC (competencias + inserciones) en distintos tamaños, ángulos y
   opacidades. Solo decorativo (aria-hidden), no captura clicks. */
.auth-gate-wallpaper {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.auth-gate-wallpaper-item {
  position: absolute;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-weight: 700;
  color: #1e3a8a;
  white-space: nowrap;
  user-select: none;
  letter-spacing: 0.02em;
  /* las variables --left, --top, --rot, --size, --op las inyecta JS */
  left: var(--left);
  top: var(--top);
  font-size: var(--size, 14px);
  opacity: var(--op, 0.1);
  transform: rotate(var(--rot, 0deg));
  transition: opacity 0.4s ease;
}
.auth-gate-wallpaper-item--ind { color: #6d28d9; }
.auth-gate-wallpaper-item--ico {
  font-family: inherit;
  width: var(--icoW, 40px);
  height: auto;
  filter: grayscale(0.35);
}
[data-theme="dark"] .auth-gate-wallpaper-item { color: #93c5fd; }
[data-theme="dark"] .auth-gate-wallpaper-item--ind { color: #c4b5fd; }
[data-theme="dark"] .auth-gate-wallpaper-item--ico { filter: grayscale(0.5) brightness(1.4); }

/* La esfera tiene que quedar SOBRE el wallpaper. */
.auth-gate-sphere {
  z-index: 1;
}

/* ----- Esfera giratoria (contiene las tarjetas) ----- */
/* v98: radio aumentado + más rotación lenta para acomodar las ~57 tarjetas
   (cada asignatura × sus 3 años).
   v176: la animación CSS @keyframes se reemplazó por una animación JS en
   boot.js que permite arrastrar la esfera con el cursor para impulsarla
   sin nunca detenerse. La esfera siempre rota; al soltar tras un drag,
   el momentum decae gradualmente al baseline (360°/55s). */
.auth-gate-sphere {
  position: relative;
  width: 640px;
  height: 640px;
  transform-style: preserve-3d;
  will-change: transform;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  /* Transform inicial coherente con el baseline; lo manda JS desde frame 1 */
  transform: rotateY(0deg) rotateX(-10deg);
  touch-action: none; /* bloquear scroll vertical en touch al arrastrar */
}
.auth-gate-sphere.is-dragging { cursor: grabbing; }

/* ----- Tarjetas en la superficie de la esfera ----- */
.sphere-card {
  --bg: #3b82f6;     /* color de la asignatura (banda superior) */
  --theta: 0deg;     /* longitud (yaw) */
  --phi: 0deg;       /* latitud  (pitch) */
  --r: 280px;        /* v98: radio mayor para acomodar más tarjetas */

  position: absolute;
  top: 50%;
  left: 50%;
  width: 118px;
  height: 96px;
  margin: -48px 0 0 -59px;

  background: #ffffff;
  border: 1px solid var(--border, #e1e6ec);
  border-radius: 12px;
  padding: 0.55rem 0.5rem 0.65rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  user-select: none;
  cursor: default;

  /* Posición + orientación tangente a la esfera */
  transform:
    rotateY(var(--theta))
    rotateX(var(--phi))
    translateZ(var(--r));

  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;

  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.10);
  transition: box-shadow 0.25s ease;
}

[data-theme="dark"] .sphere-card {
  background: var(--surface-elevated, #1c3050);
  border-color: var(--border, #23375b);
  color: var(--text, #e2e8f0);
}

/* Banda superior con el color de la asignatura */
.sphere-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--bg);
  border-radius: 12px 12px 0 0;
}

.sphere-card-icono {
  font-size: 1.45rem;
  line-height: 1;
}

.sphere-card-nombre {
  font-weight: 700;
  font-size: 0.72rem;
  line-height: 1.15;
  color: var(--text, #1e293b);
}

.sphere-card-area {
  font-size: 0.58rem;
  line-height: 1.15;
  color: var(--muted, #64748b);
}

/* v98: badge de año en esquina superior derecha. Permite distinguir
   visualmente las variantes (1BGU vs 2BGU vs 8EGB, etc.) */
.sphere-card-anio {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--bg);
  color: white;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  line-height: 1;
}

.sphere-card--egb .sphere-card-anio {
  background: linear-gradient(135deg, var(--bg), rgba(255,255,255,0.85));
  color: #0f172a;
}

/* ----- Panel de login (derecha) — con logo como cabecera ----- */
.auth-gate-panel {
  background: var(--surface-2, #f6f8fb);
  border-left: 1px solid var(--border, #e2e8f0);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem 1.85rem;
  overflow-y: auto;
  animation: panelSlideIn 0.5s 0.1s ease-out backwards;
}

/* Logo como cabecera del formulario */
.auth-gate-logo-header {
  display: block;
  height: 140px;
  width: auto;
  max-width: 90%;
  margin: 0 auto 1.25rem;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.10));
}

@keyframes panelSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

[data-theme="dark"] .auth-gate-panel {
  background: var(--surface-2, #1a2c47);
  color: #e2e8f0;
}

.auth-gate-title {
  font-size: 1.55rem;
  line-height: 1.15;
  margin: 0 0 0.5rem;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #ec4899 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.auth-gate-subtitle {
  color: var(--muted, #64748b);
  margin: 0 0 1.5rem;
  font-size: 0.92rem;
  line-height: 1.45;
}

.auth-gate-stats {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0.85rem 0;
  display: flex;
  justify-content: space-around;
  font-size: 0.78rem;
  border-top: 1px solid var(--border, #e2e8f0);
  border-bottom: 1px solid var(--border, #e2e8f0);
  color: var(--muted, #64748b);
}

.auth-gate-stats li { flex: 1; text-align: center; }

.auth-gate-stats strong {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: #3b82f6;
  margin-bottom: 0.15rem;
}

[data-theme="dark"] .auth-gate-stats strong { color: #60a5fa; }

.auth-gate-btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.9rem 1.5rem;
  background: white;
  color: #3c4043;
  font-weight: 600;
  font-size: 1rem;
  border: 1px solid #dadce0;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.18s ease, transform 0.1s ease;
  font-family: inherit;
}

.auth-gate-btn-google:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.auth-gate-btn-google:active { transform: scale(0.985); }
.auth-gate-btn-google:disabled { opacity: 0.6; cursor: wait; }

[data-theme="dark"] .auth-gate-btn-google {
  background: #1f2937;
  color: #e5e7eb;
  border-color: #374151;
}

.google-logo {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.auth-gate-hint {
  margin-top: 1.1rem;
  font-size: 0.8rem;
  color: var(--muted, #94a3b8);
  line-height: 1.4;
}

.auth-gate-hint strong { color: #3b82f6; }
[data-theme="dark"] .auth-gate-hint strong { color: #93c5fd; }

.auth-gate-foot {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--muted, #94a3b8);
  font-size: 0.72rem;
}

.auth-gate-foot img {
  height: 18px;
  opacity: 0.7;
}

/* ----- Mobile / Tablet ----- */
@media (max-width: 900px) {
  .auth-gate {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .auth-gate-sphere {
    width: 380px;
    height: 380px;
  }
  .sphere-card {
    --r: 165px;
    width: 108px;
    height: 84px;
    margin: -42px 0 0 -54px;
  }
  .sphere-card-icono { font-size: 1.3rem; }
  .sphere-card-nombre { font-size: 0.7rem; }
  .sphere-card-area { font-size: 0.58rem; }
  .auth-gate-logo-header { height: 110px; }
  .auth-gate-panel {
    padding: 1.5rem 1.5rem;
    border-left: none;
    border-top: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.08);
  }
}

@media (max-width: 520px) {
  .auth-gate-sphere-stage { display: none; }
  .auth-gate { grid-template-rows: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .auth-gate { animation: none; }
  .auth-gate-panel { animation: none; }
  .auth-gate-sphere { animation: none; }
}

/* =====================================================
   Modos del panel: signedout (default), loading, pending, denied.
   El JS cambia data-authz-mode en #auth-gate-panel; el CSS oculta
   los modos no activos.
   ===================================================== */
.auth-gate-mode { display: contents; }
.auth-gate-panel[data-authz-mode="signedout"] .auth-gate-mode:not([data-mode="signedout"]),
.auth-gate-panel[data-authz-mode="loading"]   .auth-gate-mode:not([data-mode="loading"]),
.auth-gate-panel[data-authz-mode="pending"]   .auth-gate-mode:not([data-mode="pending"]),
.auth-gate-panel[data-authz-mode="denied"]    .auth-gate-mode:not([data-mode="denied"]) {
  display: none !important;
}

/* Spinner para modo loading */
.auth-gate-spinner {
  width: 56px;
  height: 56px;
  margin: 1rem auto 1.5rem;
  border: 4px solid var(--surface-2, #f1f5f9);
  border-top-color: var(--primary, #3b82f6);
  border-radius: 50%;
  animation: auth-gate-spin 0.85s linear infinite;
}
@keyframes auth-gate-spin {
  to { transform: rotate(360deg); }
}

/* Iconos grandes para pending/denied */
.auth-gate-icon {
  font-size: 4rem;
  text-align: center;
  margin: 0.5rem 0 1rem;
  line-height: 1;
}

/* Mensaje meta (email del user en pending/denied) */
.auth-gate-meta {
  margin: 0.5rem 0 1.25rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2, #f1f5f9);
  border-radius: 8px;
  color: var(--muted, #64748b);
  font-size: 0.85rem;
  font-family: ui-monospace, monospace;
  text-align: center;
  word-break: break-all;
}

/* Botones secundarios para pending/denied */
.auth-gate-btn-secondary {
  display: block;
  width: 100%;
  margin: 0.5rem 0;
  padding: 0.7rem 1rem;
  background: transparent;
  border: 1px solid var(--border, #cbd5e1);
  border-radius: 10px;
  color: var(--text, #1e293b);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.auth-gate-btn-secondary:hover {
  background: var(--surface-2, #f1f5f9);
  border-color: var(--primary, #3b82f6);
  color: var(--primary, #3b82f6);
}

[data-theme="dark"] .auth-gate-meta {
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
}
[data-theme="dark"] .auth-gate-btn-secondary {
  border-color: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}
[data-theme="dark"] .auth-gate-btn-secondary:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.4);
  color: #93c5fd;
}
