/* ═══ 18. SIGN-IN GATE ═══════════════════════════════════════════════ */

/* Deliberately theme-agnostic: unlike the rest of the app, the gate does NOT
   use the --bg/--fg tokens that flip with the dark/light toggle. It renders
   before that preference applies and must look identical either way, so all
   colors below are a fixed palette scoped to .auth-gate. Structural tokens
   (spacing/radius/type scale/duration/blur) still come from tokens.css since
   those don't change with theme. */
.auth-gate {
  /* #161616 / rgba(31,31,31,.40) are the app's real dark-mode --bg and
     --popover-bg (tokens.css, body.dark), hardcoded so they stay fixed
     regardless of which theme is toggled. */
  --login-bg:          #161616;
  --login-fg:          #f2f0ea;
  --login-ink-faint:   #8f8c84;
  --login-line-strong: rgba(242,240,234,0.38);
  --login-popover-bg:  rgba(31, 31, 31, 0.40);

  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: stretch; justify-content: center;
  background: var(--login-bg);
  transition: opacity var(--dur-base) ease, visibility var(--dur-base) ease;
}
.auth-gate.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* ── Desktop: motion panel floats above the gate canvas, inset on all four
   sides (padding, not margin, so it isn't fighting the 61.803% flex basis).
   Golden-ratio split — visual gets the larger phi share, form the smaller. */
.auth-visual {
  flex: 0 0 61.803%;
  box-sizing: border-box;
  padding: 30px;
  display: flex;
}
.motion-panel {
  position: relative;
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  /* #050505 matches motion-panel.js's canvas clear color — no flash of a
     different tone before the first animation frame paints. */
  background: #050505;
  color: var(--login-fg);
  padding: var(--ab-pad-y) var(--ab-pad-x);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 14px rgba(0,0,0,.3);
  overflow: hidden;
}
/* Animated mesh-gradient (motion-panel.js) + grain, both behind the copy. */
.motion-panel-canvas {
  position: absolute; inset: 0; z-index: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  filter: blur(120px);
  transform: scale(1.3); /* overshoot so the heavy blur never clips at the edges */
}
.motion-panel-noise {
  position: absolute; inset: 0; z-index: 1;
  pointer-events: none; opacity: .08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}
.motion-panel-inner { position: relative; z-index: 2; max-width: 380px; text-align: left; }
.motion-panel .auth-logo {
  position: absolute; z-index: 2; top: var(--ab-pad-y); left: var(--ab-pad-x);
  color: var(--login-fg);
}
.motion-panel .auth-logo span { color: color-mix(in srgb, var(--login-fg) 65%, transparent); }
.auth-logo.auth-logo-xl { font-size: calc(var(--text-xl) * 2); }
.auth-tagline {
  margin: 14px 0 0; font-size: var(--text-base);
  color: color-mix(in srgb, var(--login-fg) 75%, transparent);
  line-height: 1.5;
}

.auth-panel {
  position: relative;
  flex: 0 0 38.197%;
  display: flex; align-items: center; justify-content: center;
  padding: var(--ab-pad-y) var(--ab-pad-x);
}

/* .auth-credit / .auth-panel-subtitle / .auth-version share the same centered
   width as .auth-card (min(100%,340px)) so their left/right edges line up
   exactly with the entry fields, not the panel's outer edge. */
.auth-credit, .auth-panel-subtitle, .auth-version {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: min(100%, 340px);
}
.auth-credit {
  bottom: 22px; text-align: left;
  font-size: var(--text-sm); color: var(--login-ink-faint);
  letter-spacing: .2px;
}
.auth-panel-subtitle {
  top: var(--ab-pad-y); text-align: right;
  font-size: var(--text-xs); color: var(--login-ink-faint);
  text-transform: uppercase; letter-spacing: .08em;
}
.auth-version {
  bottom: 22px; text-align: right;
  font-size: var(--text-sm); color: var(--login-ink-faint);
  letter-spacing: .2px;
}

.auth-card {
  width: min(100%, 340px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  text-align: left;
  /* Soft materialize-in on load (the card is the focal point over constant
     ambient motion, so it should arrive deliberately). Default state is
     visible; @starting-style supplies the from-state, so if the browser
     lacks @starting-style support the card simply appears — never invisible. */
  transition: opacity 220ms cubic-bezier(0.23, 1, 0.32, 1),
              transform 220ms cubic-bezier(0.23, 1, 0.32, 1);
}
@starting-style {
  .auth-card { opacity: 0; transform: scale(0.97); }
}
.auth-logo {
  font-size: var(--text-xl); line-height: var(--lh-title); letter-spacing: .3px;
  color: var(--login-fg); display: flex; flex-direction: column;
}
.auth-logo span {
  display: block; margin-top: 3px;
  font-size: var(--text-xs); color: var(--login-ink-faint);
  text-transform: uppercase; letter-spacing: .08em;
}

/* Status text and success checkmark share one grid cell so they crossfade in
   place. .auth-card is centered in the panel, so as the form below collapses
   the whole card shrinks and this heading glides to the panel's vertical
   centre — the "move to centre" is the flex re-centering, animated for free. */
.auth-status-wrap { position: relative; display: grid; width: 100%; }
.auth-status, .auth-check { grid-area: 1 / 1; }
.auth-status {
  font-size: var(--text-xl); font-weight: 600; letter-spacing: .3px;
  color: var(--login-fg); margin: 0;
  transition: opacity var(--dur-base) ease;
}
.auth-check {
  justify-self: start; align-self: center;
  width: 34px; height: 34px; color: var(--login-fg);
  opacity: 0; transition: opacity var(--dur-base) ease;
}
.auth-check svg { width: 100%; height: 100%; display: block; }
.auth-check-circle { stroke-dasharray: 151; stroke-dashoffset: 151;
  transition: stroke-dashoffset .5s ease; }
.auth-check-mark   { stroke-dasharray: 40;  stroke-dashoffset: 40;
  transition: stroke-dashoffset .4s ease .32s; }

/* Real Firebase auth latency is variable — a pulsing dot trio keeps the
   "Connecting"/"Logging in" heading reading as active work rather than a
   stalled screen, for however long the wait actually is. Shown only while
   .is-authenticating; the heading text drops its own ellipsis so the dots
   are the sole motion cue. */
.auth-loading-dots {
  display: inline-flex; gap: 3px; margin-left: 7px; vertical-align: middle;
  opacity: 0; transition: opacity 150ms ease;
}
.auth-gate.is-authenticating .auth-loading-dots { opacity: 1; }
.auth-loading-dots span {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor;
  animation: loading-dot-pulse 1.1s ease-in-out infinite;
}
.auth-loading-dots span:nth-child(2) { animation-delay: .15s; }
.auth-loading-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes loading-dot-pulse {
  0%, 80%, 100% { opacity: .25; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* The collapsible form region: grid-rows 1fr↔0fr gives a smooth height
   animation without magic numbers; the inner clips its own top padding. */
.auth-collapse {
  display: grid; grid-template-rows: 1fr; width: 100%;
  transition: grid-template-rows .5s cubic-bezier(.4, 0, .2, 1),
              opacity .4s ease;
}
.auth-collapse-inner { overflow: hidden; padding-top: 22px; }

.auth-gate.is-authenticating .auth-collapse {
  grid-template-rows: 0fr; opacity: 0; pointer-events: none;
}
.auth-gate.is-success .auth-status { opacity: 0; }
.auth-gate.is-success .auth-check  { opacity: 1; }
.auth-gate.is-success .auth-check-circle,
.auth-gate.is-success .auth-check-mark { stroke-dashoffset: 0; }

.auth-logo-compact { display: none; margin-bottom: 18px; }

.auth-form { width: 100%; display: flex; flex-direction: column; gap: 22px; }

.auth-fields { display: flex; flex-direction: column; gap: 18px; }
.auth-field {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 8px;
  text-align: left;
}
.auth-field-label {
  font-size: var(--text-sm); font-weight: 500; letter-spacing: .4px;
  color: var(--login-ink-faint);
}

.auth-remember {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--text-base); color: var(--login-fg); opacity: .82;
  cursor: pointer; user-select: none;
}
.auth-remember input {
  appearance: none; -webkit-appearance: none;
  box-sizing: border-box; padding: 0;
  width: 14px; height: 14px; min-width: 14px; margin: 0; flex: none; position: relative;
  background: transparent; border: 1px solid var(--login-line-strong); border-radius: var(--radius-sm);
  cursor: pointer;
}
.auth-remember input:checked { border-color: var(--login-fg); }
.auth-remember input:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid var(--login-fg); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.auth-form input:not([type="checkbox"]) {
  width: 100%; box-sizing: border-box;
  padding: 0 0 8px; font-size: var(--text-base);
  color: var(--login-fg); background: transparent;
  border: none; border-bottom: 1px solid var(--login-line-strong); border-radius: 0;
  transition: border-color 150ms ease;
}
.auth-form input:not([type="checkbox"])::placeholder { color: var(--login-ink-faint); opacity: .75; }
.auth-form input:not([type="checkbox"]):focus {
  outline: none; border-bottom-color: var(--login-fg);
}

.auth-input-wrap { position: relative; display: flex; }
.auth-input-wrap input { padding-right: 26px; }
.auth-pw-toggle {
  position: absolute; right: 0; bottom: 6px;
  display: grid; place-items: center;
  padding: 0; border: none; background: transparent; cursor: pointer;
  color: var(--login-ink-faint);
  transition: color 150ms ease;
}
.auth-pw-toggle:hover { color: var(--login-fg); }
/* Both icons stacked in one cell and cross-faded via opacity, instead of an
   instant display:none swap. */
.auth-pw-toggle svg { grid-area: 1 / 1; display: block; transition: opacity 120ms ease; }
.auth-pw-toggle .eye-off { opacity: 0; }
.auth-pw-toggle[aria-pressed="true"] .eye-on { opacity: 0; }
.auth-pw-toggle[aria-pressed="true"] .eye-off { opacity: 1; }

.auth-form .btn { justify-content: center; padding: 10px; margin-top: 2px; }
/* Theme-agnostic override of the shared .btn.primary (which uses --fg/--bg). */
.auth-form .btn.primary {
  background: var(--login-fg); color: var(--login-bg); border-color: var(--login-fg);
  transition: opacity 150ms ease, transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.auth-form .btn.primary:hover { opacity: .88; }
.auth-form .btn.primary:active { transform: scale(0.97); }

.auth-error {
  margin: 2px 0 0; font-size: var(--text-sm); color: #e08a8a;
  animation: field-alert-in var(--dur-fast) ease-out;
}
@keyframes field-alert-in {
  from { opacity: 0; transform: translateY(-4px); }
}

/* ── Mobile: motion panel goes edge-to-edge as the backdrop; the sign-in
   form sits in a floating frosted card layered above it. ── */
@media (max-width: 700px) {
  .auth-visual { position: absolute; inset: 0; padding: 0; flex: none; z-index: 0; }
  .motion-panel { border-radius: 0; box-shadow: none; }
  /* Hero copy is desktop-only — the compact logo inside the card carries the
     branding on mobile so the backdrop stays a clean canvas for the gradient. */
  .motion-panel-inner, .motion-panel > .auth-logo { display: none; }

  .auth-panel {
    position: relative; z-index: 1; flex: 1 1 auto;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; padding: 24px;
  }
  .auth-panel-subtitle { display: none; }

  .auth-card {
    width: 100%;
    background: var(--login-popover-bg);
    backdrop-filter: var(--popover-blur);
    -webkit-backdrop-filter: var(--popover-blur);
    border-radius: var(--radius-md);
    padding: 28px 22px;
    box-shadow: 0 4px 20px rgba(0,0,0,.3);
  }
  .auth-logo-compact { display: flex; margin-bottom: 32px; }
  .auth-fields { gap: 18px; }

  /* Credit + version form one combined footer line pinned to the true bottom
     of the screen, independent of the vertically-centered card. .auth-footer
     is centered as ONE measured flex box (translateX(-50%) on the wrapper,
     not on each child) — and the children reset the base rule's own
     translateX(-50%), which otherwise shifts each left by half its width and
     throws the pair visually off-centre. */
  .auth-footer {
    position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
    display: flex; align-items: baseline; width: auto;
  }
  .auth-credit, .auth-version {
    position: static; width: auto; text-align: left; margin: 0;
    transform: none;
  }
  .auth-version::before { content: '·'; margin: 0 6px; color: var(--login-ink-faint); }
}
