/* auth.css — themed shell for /login, /register, /invite/<token>.
 *
 * Self-contained: we deliberately do NOT import the main webui's
 * stylesheet because that one is served from the per-user container,
 * which doesn't exist before the user logs in. Instead we mirror the
 * webui's design tokens (the same purples, grays, accents) so the
 * unauth shell and the authed app feel like the same product.
 *
 * Variables match the webui's :root vars by name where possible so a
 * future theme system can target both with one selector. */

:root {
  --bg:        #07090d;
  --bg-soft:   #11151c;
  --bg-card:   rgba(20, 24, 32, 0.72);
  --fg:        #f5f5f7;
  --fg-dim:    #c8ced6;
  --muted:     #98a2ad;
  --border:    rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent:    #7e57c2;
  --accent-2:  #b39ddb;
  --accent-bg: rgba(126, 87, 194, 0.18);
  --danger:    #ef5350;
  --danger-bg: rgba(239, 83, 80, 0.10);
  --success:   #66bb6a;
  --info:      #42a5f5;
  --radius:    14px;
  --radius-sm: 8px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "SF Pro Text", system-ui, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(126,87,194,.18), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(38,166,154,.12), transparent 55%),
    var(--bg);
  color: var(--fg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout primitives ─────────────────────────────────────────── */

.auth-root {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-loading {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 40px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow:
    0 1px 0 rgba(255,255,255,.04) inset,
    0 24px 80px rgba(0,0,0,.45),
    0 4px 20px rgba(0,0,0,.25);
  animation: auth-card-in .28s cubic-bezier(.22,1,.36,1);
}
@keyframes auth-card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.auth-brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #7e57c2, #5e35b1);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px rgba(126,87,194,.35);
}
.auth-brand-name {
  font-weight: 600; font-size: 15px; letter-spacing: .2px;
}
.auth-brand-meta { color: var(--muted); font-size: 11px; margin-left: auto; }

.auth-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -.2px;
}
.auth-sub {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 20px;
}

/* ── Form components ───────────────────────────────────────────── */

.auth-field { margin-bottom: 14px; }

.auth-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-dim);
  margin-bottom: 6px;
  letter-spacing: .2px;
}

.auth-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-input {
  width: 100%;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--fg);
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .14s, background .14s, box-shadow .14s;
  -webkit-appearance: none;
  appearance: none;
}
.auth-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255,255,255,.06);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.auth-input[disabled] { opacity: .5; cursor: not-allowed; }
.auth-input::placeholder { color: rgba(152, 162, 173, .55); }

/* Reveal-password toggle inside the field. */
.auth-toggle-pw {
  position: absolute; right: 4px;
  background: transparent; border: 0; padding: 6px 8px;
  color: var(--muted); cursor: pointer;
  border-radius: 6px; font-size: 11px; font-weight: 600;
  letter-spacing: .3px;
}
.auth-toggle-pw:hover { color: var(--fg-dim); background: rgba(255,255,255,.04); }

/* Strength meter under the password field. */
.auth-strength {
  display: flex; gap: 3px; margin-top: 6px; height: 4px;
}
.auth-strength-seg {
  flex: 1; background: rgba(255,255,255,.06); border-radius: 2px;
  transition: background .14s;
}
.auth-strength-seg.on-1 { background: #ef5350; }
.auth-strength-seg.on-2 { background: #ffa726; }
.auth-strength-seg.on-3 { background: #ffee58; }
.auth-strength-seg.on-4 { background: #66bb6a; }

.auth-help {
  font-size: 11px; color: var(--muted); margin-top: 6px;
}
.auth-help.error { color: var(--danger); }

/* ── Buttons ────────────────────────────────────────────────────── */

.auth-btn {
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .12s, transform .06s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}
.auth-btn:hover:not(:disabled) { filter: brightness(1.08); }
.auth-btn:active:not(:disabled) { transform: translateY(1px); }
.auth-btn:disabled { opacity: .55; cursor: not-allowed; }
.auth-btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--fg-dim);
}
.auth-btn.ghost:hover:not(:disabled) {
  background: rgba(255,255,255,.04);
}

/* Tiny spinner used in the button while submitting. */
.auth-spin {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.32);
  border-top-color: white;
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

/* ── Footer / mode toggle ──────────────────────────────────────── */

.auth-foot {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.auth-foot a {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 500;
}
.auth-foot a:hover { text-decoration: underline; }
.auth-foot-row { margin-top: 10px; text-align: right; font-size: 12px; }
.auth-foot-link { color: var(--muted); }
.auth-foot-link:hover { color: var(--accent-2); }

/* ── Legal footer (Privacy / Terms) — always visible ─────────── */
.auth-legal {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .2px;
  margin-top: 4px;
}
.auth-legal a {
  color: var(--muted);
  text-decoration: none;
}
.auth-legal a:hover { color: var(--accent-2); }

/* ── OAuth provider buttons ────────────────────────────────────── */
.auth-oauth { margin-top: 4px; }
.auth-oauth-list {
  display: flex; flex-direction: column;
  gap: 8px;
}
.auth-oauth-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.auth-oauth-btn svg { flex-shrink: 0; }

.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted);
  font-size: 11px;
  margin: 18px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Status / error banners ────────────────────────────────────── */

.auth-banner {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.45;
}
.auth-banner.error {
  background: var(--danger-bg);
  color: #ffcdd2;
  border: 1px solid rgba(239,83,80,.32);
}
.auth-banner.info {
  background: rgba(66,165,245,.10);
  color: #bbdefb;
  border: 1px solid rgba(66,165,245,.32);
}

/* ── Stats badge (active users / GPU) ──────────────────────────── */

.auth-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  justify-content: center;
}
.auth-stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.auth-stat-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
}
.auth-stat-pill.online .auth-stat-dot { background: var(--success); box-shadow: 0 0 0 2px rgba(102,187,106,.18); }
.auth-stat-pill.gpu-on  .auth-stat-dot { background: var(--info); }
.auth-stat-pill.gpu-off .auth-stat-dot { background: var(--muted); }

/* ── Boot shell (post-login while container provisions) ────────── */

.auth-boot {
  text-align: center;
  padding: 8px 0 4px;
}
.auth-boot-title {
  font-size: 17px; font-weight: 600; margin-bottom: 6px;
}
.auth-boot-status {
  font-size: 13px; color: var(--muted);
  min-height: 18px; margin-bottom: 18px;
}
.auth-boot-bar {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,.06);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.auth-boot-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%;
  transition: width .35s ease;
  border-radius: 3px;
}
.auth-boot-meta {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted);
  margin-bottom: 16px;
}
/* Stage-1 composer: textarea + Send button side-by-side, same visual
   shape as the in-app composer + the loader queue, so the journey
   across the three stages feels continuous. */
.auth-boot-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}
.auth-boot-msg {
  flex: 1;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  min-height: 72px;
  max-height: 140px;
  outline: none;
}
.auth-boot-msg:focus { border-color: var(--accent); }
.auth-boot-send {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center; justify-content: center;
  transition: filter .12s, transform .06s, opacity .12s;
}
.auth-boot-send:hover:not(:disabled) { filter: brightness(1.08); }
.auth-boot-send:active:not(:disabled) { transform: translateY(1px); }
.auth-boot-send:disabled { opacity: .4; cursor: not-allowed; }
/* Queued state — replaces the composer once user commits. Same visual
   pattern as the loader's hl-queued-chip so the transition between
   Stage 1 → Stage 2 doesn't visually jump. */
.auth-boot-queued {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--accent-bg);
  border: 1px solid rgba(126, 140, 230, .32);
  color: var(--accent-2);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  margin: 4px auto 0;
  width: fit-content;
}
.auth-boot-hint {
  font-size: 11px; color: var(--muted);
  text-align: center; margin-top: 6px;
}

/* ── Invite preview card ───────────────────────────────────────── */

.invite-meta {
  text-align: center;
  margin-bottom: 18px;
}
.invite-ws-name {
  font-size: 22px; font-weight: 700;
  margin: 4px 0 6px;
  letter-spacing: -.3px;
}
.invite-inviter {
  color: var(--muted); font-size: 13px;
}
.invite-role-pill {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-bg);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
}

/* ── Mobile tweaks ─────────────────────────────────────────────── */

@media (max-width: 480px) {
  body { padding: 0; }
  .auth-root {
    max-width: 100%;
    height: 100dvh;
    justify-content: center;
    padding: 0 16px;
  }
  .auth-card {
    border-radius: 0;
    border-left: 0; border-right: 0;
    margin: 0 -16px;
    padding: 24px 22px 22px;
  }
}

/* ── Polish pass: a11y + micro-interactions ───────────────────── */

/* Caps Lock indicator (lives inside .auth-field, below the password
   input). Slides in only when caps is engaged. */
.auth-caps-warn {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 167, 38, 0.10);
  border: 1px solid rgba(255, 167, 38, 0.32);
  color: #ffcc80;
  font-size: 11px;
  font-weight: 500;
  animation: auth-fade-in 0.18s ease;
}
.auth-caps-icon {
  font-size: 14px;
  line-height: 1;
}

/* Help text that doubles as ✓/✗ feedback for the username field. */
.auth-help.ok    { color: var(--success); }
.auth-help.error { color: var(--danger); }

/* Focus-visible: keyboard focus gets a ring; mouse focus does not.
   Better than `outline: none` (we keep accessibility while losing
   the ugly browser default). */
.auth-input:focus-visible,
.auth-btn:focus-visible,
.auth-toggle-pw:focus-visible,
.auth-foot a:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* Skeleton placeholder for the invite preview (and any other
   "loading from network" surface). Uses a moving gradient — shut off
   under prefers-reduced-motion below. */
.auth-skel {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,.04) 0%,
    rgba(255,255,255,.10) 50%,
    rgba(255,255,255,.04) 100%
  );
  background-size: 200% 100%;
  animation: auth-skel-shimmer 1.4s linear infinite;
  border-radius: 4px;
}
.auth-skel-line { display: block; }
@keyframes auth-skel-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Soft fade between login ↔ register in-place switches. */
.auth-leave { opacity: 0; transition: opacity .14s ease-out; }
.auth-enter { opacity: 0; }
.auth-root  { transition: opacity .18s ease-in; }
@keyframes auth-fade-in {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: none; }
}
/* Form → boot transition: fade the card contents out before the
   DOM swap, then fade the new contents in. Without this the form
   contents instantly disappear and the boot UI pops in — feels
   jarring after the user clicks Submit. */
.auth-card.auth-boot-leaving  { opacity: 0; transition: opacity .14s ease-out; }
.auth-card.auth-boot-entering { opacity: 0; }
.auth-card                    { transition: opacity .18s ease-in; }

/* ── prefers-reduced-motion: kill animations cleanly ─────────── */
@media (prefers-reduced-motion: reduce) {
  .auth-card,
  .auth-skel,
  .auth-caps-warn,
  .auth-leave,
  .auth-enter,
  .auth-root,
  .auth-spin {
    animation: none !important;
    transition: none !important;
  }
}

/* ── prefers-contrast: more deliberate borders + text on hi-contrast ── */
@media (prefers-contrast: more) {
  :root {
    --border:        rgba(255, 255, 255, 0.32);
    --border-strong: rgba(255, 255, 255, 0.55);
    --muted:         #d8dde3;
  }
  .auth-card { border-width: 2px; }
  .auth-input { border-width: 2px; }
}

/* ── prefers-color-scheme: light — invert the dark tokens ─────── */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f5f6f8;
    --bg-soft:   #ffffff;
    --bg-card:   rgba(255, 255, 255, 0.86);
    --fg:        #1a1d23;
    --fg-dim:    #2e3340;
    --muted:     #5a6470;
    --border:    rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.16);
    --accent:    #5e35b1;
    --accent-2:  #7e57c2;
    --accent-bg: rgba(94, 53, 177, 0.10);
    --danger:    #c62828;
    --danger-bg: rgba(198, 40, 40, 0.08);
  }
  body {
    background:
      radial-gradient(circle at 20% 0%, rgba(126,87,194,.12), transparent 50%),
      radial-gradient(circle at 80% 100%, rgba(38,166,154,.08), transparent 55%),
      var(--bg);
  }
  .auth-input { background: rgba(0,0,0,.02); }
  .auth-input:focus { background: rgba(0,0,0,.04); }
  .auth-banner.error { color: #b71c1c; }
  .auth-banner.info  { color: #0d47a1; }
  .auth-caps-warn { color: #b26500; }
  .auth-skel {
    background: linear-gradient(
      90deg,
      rgba(0,0,0,.04) 0%,
      rgba(0,0,0,.10) 50%,
      rgba(0,0,0,.04) 100%
    );
  }
  .auth-boot-msg { background: rgba(0,0,0,.02); }
  .auth-boot-bar { background: rgba(0,0,0,.06); }
}

/* ── Captcha (Bug I) ─────────────────────────────────────────────
   Stateless math captcha rendered inline in /login and /register.
   Layout: question on top with a refresh ↻ button on the right, the
   answer input below. Visual weight is intentionally lower than the
   primary fields — captcha is friction, not the main event. */
.auth-captcha {
  border: 1px dashed rgba(255,255,255,.14);
  border-radius: 10px;
  padding: 10px 12px 12px;
  background: rgba(255,255,255,.02);
}
.auth-captcha-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.auth-captcha-q {
  font-size: 13px;
  color: var(--text, #e8eaed);
  font-weight: 500;
  letter-spacing: .01em;
  /* Make the question feel "machine-readable" and tougher to OCR — */
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.auth-captcha-refresh {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.12);
  background: transparent;
  color: rgba(232,234,237,.72);
  cursor: pointer;
  font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s, transform .2s;
}
.auth-captcha-refresh:hover {
  background: rgba(255,255,255,.06);
  color: rgba(232,234,237,.95);
  transform: rotate(90deg);
}
.auth-captcha .auth-input {
  /* Narrower than the username/password fields — the answer is one or
     two digits; a 64-char field would feel ridiculous. */
  max-width: 140px;
}
@media (prefers-color-scheme: light) {
  .auth-captcha {
    border-color: rgba(0,0,0,.16);
    background: rgba(0,0,0,.02);
  }
  .auth-captcha-q { color: var(--text, #15151F); }
  .auth-captcha-refresh {
    border-color: rgba(0,0,0,.18);
    color: rgba(50,55,70,.72);
  }
  .auth-captcha-refresh:hover {
    background: rgba(0,0,0,.04);
    color: rgba(20,25,35,.95);
  }
}
