/* ==========================================================================
   Tradevane authentication gate — the first screen of the workspace.

   One centred card, read top to bottom: a compact brand header, the
   login / register segmented control, the form heading, the fields, one
   primary action and a quiet secondary link. The marketing panel of the old
   two-column gate is folded into the header so the gate reads as a single
   surface; nothing else about the flow changes.

   Colour comes only from the tokens in theme.css: the brand green is the one
   accent, neutrals are the --tv-* scale, the message line uses the semantic
   info / success / danger tokens. No colour literal is declared in this file.

   Controls keep the conventions already defined for .tv-btn / .tv-input:
     fields            40px, 8px radius, brand focus ring (theme.css owns
                       field chrome; this layer only sets width and rhythm)
     primary action    40px  --tv-control-h-lg, brand fill, 600 weight
     tabs              30px pills inside a 4px track  --tv-control-h-sm
     quiet link        30px borderless text button, text-3 until hover
     focus             3px --tv-brand-ring halo on every control
     disabled          opacity .5, as .tv-btn:disabled
   The display size (--tv-fs-display) is used once, on the card heading;
   every other size in this file is 13px or larger.
   Every transition has a reduced-motion fallback at the end of the file.

   Sections: 01 lock · 02 overlay · 03 brand header · 04 card · 05 tabs ·
             06 heading · 07 message · 08 fields · 09 actions · 10 pending ·
             11 account row · 12 responsive · 13 reduced motion
   ========================================================================== */

/* ---- 01 lock: hide the application shell while unauthenticated ---------- */
html.auth-gate-locked,
html.auth-gate-locked body { overflow: hidden; }

html.auth-gate-locked .shell { visibility: hidden !important; pointer-events: none !important; }

/* The overlay itself must never be hidden by the shell lock. */
.auth-gate[hidden] { display: none !important; }
.auth-gate [hidden] { display: none !important; }

/* ---- 02 overlay --------------------------------------------------------- */
/* The two sections are the two halves of one card, so the overlay only
   centres them. safe centring keeps the card reachable when a short window
   scrolls. */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: grid;
  align-content: center;
  align-content: safe center;
  justify-items: center;
  overflow: auto;
  padding: var(--tv-s6);
  background: radial-gradient(ellipse at 70% 12%, var(--tv-brand-soft), transparent 56%), var(--tv-bg);
  color: var(--tv-text);
  font-family: var(--tv-font);
}

.auth-gate p { margin: 0; }

/* ---- 03 brand header ---------------------------------------------------- */
.auth-gate-brand {
  width: 100%;
  max-width: 436px;
  padding: var(--tv-s4) var(--tv-s7);
  border-radius: var(--tv-radius-feature) var(--tv-radius-feature) 0 0;
  background: var(--tv-plum);
}

/* Decorative rings belonged to the full-height brand panel. */
.auth-gate-brand::before,
.auth-gate-brand::after { display: none; }

.auth-gate-brand-top {
  display: inline-block;
  max-width: 100%;
  padding: 5px var(--tv-s2);
  border-radius: var(--tv-radius);
  background: var(--tv-surface);
}

.auth-gate-logo { display: block; width: 148px; max-width: 100%; height: auto; }

/* The marketing headline, lede, feature row and footer stay in the markup for
   the workspace's own copy pass but are not shown on the single-card gate. */
.auth-gate-brand-body,
.auth-gate-brand-foot { display: none; }

/* ---- 04 card ------------------------------------------------------------ */
.auth-gate-form-panel {
  width: 100%;
  max-width: 436px;
  padding: var(--tv-s6) var(--tv-s7) var(--tv-s7);
  border-radius: 0 0 var(--tv-radius-feature) var(--tv-radius-feature);
  background: var(--tv-surface);
  box-shadow: var(--tv-shadow-lg);
}

.auth-gate-form-panel::after { display: none; }

.auth-gate-card {
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* ---- 05 login / register tabs ------------------------------------------ */
.auth-gate-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--tv-s1);
  padding: var(--tv-s1);
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius-full);
  background: var(--tv-subtle);
}

.auth-gate-tab {
  height: var(--tv-control-h-sm);
  min-height: var(--tv-control-h-sm);
  padding: 0 var(--tv-s3);
  border: 0;
  border-radius: var(--tv-radius-full);
  background: transparent;
  color: var(--tv-text-3);
  font: 500 var(--tv-fs-md) / 1 var(--tv-font);
  cursor: pointer;
  transition: background .12s ease, color .12s ease, box-shadow .12s ease;
}

.auth-gate-tab:hover { background: var(--tv-surface-hover); color: var(--tv-text); }

.auth-gate-tab[aria-selected="true"] { background: var(--tv-surface); color: var(--tv-text); font-weight: 600; box-shadow: var(--tv-shadow-sm); }

.auth-gate-tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.auth-gate-tab:disabled { opacity: .5; cursor: not-allowed; }

/* ---- 06 heading --------------------------------------------------------- */
.auth-gate-head { margin: var(--tv-s5) 0 var(--tv-s4); }

.auth-gate-head h3 { margin: 0 0 var(--tv-s1); color: var(--tv-text); font-size: var(--tv-fs-display); font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }

.auth-gate-hint { color: var(--tv-text-3); font-size: var(--tv-fs-md); line-height: 1.6; }

.auth-gate-password-note { margin: 0; color: var(--tv-text-3); font-size: var(--tv-fs-md); line-height: 1.55; }

/* ---- 07 message: info by default, error and success on demand ----------- */
.auth-gate-message {
  margin: 0 0 var(--tv-s4);
  padding: var(--tv-s2) var(--tv-s3);
  border: 1px solid var(--tv-info-border);
  border-radius: var(--tv-radius);
  background: var(--tv-info-bg);
  color: var(--tv-info);
  font-size: var(--tv-fs-md);
  font-weight: 500;
  line-height: 1.5;
}

.auth-gate-message[data-tone="error"] { border-color: var(--tv-danger-border); background: var(--tv-danger-bg); color: var(--tv-danger); }

.auth-gate-message[data-tone="success"] { border-color: var(--tv-success-border); background: var(--tv-success-bg); color: var(--tv-success); }

.auth-gate-message code { color: inherit; font: 500 var(--tv-fs-md) / 1.4 var(--tv-mono); }

/* ---- 08 fields ---------------------------------------------------------- */
.auth-gate-form { display: grid; gap: var(--tv-s4); }

.auth-gate-field { display: grid; gap: var(--tv-s1); min-width: 0; }

.auth-gate-field > span { color: var(--tv-text-2); font-size: var(--tv-fs-md); font-weight: 500; line-height: 1.4; }

.auth-gate-field input { width: 100%; min-width: 0; box-sizing: border-box; }

/* The password field and its reveal button share one 40px row instead of
   stacking text under the field. */
.auth-password-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--tv-s2); align-items: center; min-width: 0; }

.auth-password-toggle {
  display: grid;
  place-items: center;
  width: var(--tv-control-h-lg);
  height: var(--tv-control-h-lg);
  padding: 0;
  border: 1px solid var(--tv-border);
  border-radius: var(--tv-radius);
  background: var(--tv-surface);
  color: var(--tv-text-3);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.auth-password-toggle:hover { background: var(--tv-surface-hover); border-color: var(--tv-border-strong); color: var(--tv-text); }

.auth-password-toggle:active { background: var(--tv-subtle); }

.auth-password-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.auth-password-toggle:disabled { opacity: .5; cursor: not-allowed; }

.auth-password-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.auth-password-toggle .auth-eye-slash { display: block; }

.auth-password-toggle.is-visible .auth-eye-slash { display: none; }

/* theme.css owns field chrome with a four-attribute selector, so the single
   invalid-state override is explicit about winning. */
.auth-gate-field[data-invalid="true"] > span { color: var(--tv-danger); }

.auth-gate-field[data-invalid="true"] input { border-color: var(--tv-danger) !important; }

/* ---- 09 primary action and quiet secondary link ------------------------ */
.auth-gate-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--tv-s2);
  width: 100%;
  height: var(--tv-control-h-lg);
  min-height: var(--tv-control-h-lg);
  margin: 0;
  padding: 0 var(--tv-s5);
  border: 1px solid var(--tv-brand);
  border-radius: var(--tv-radius);
  background: var(--tv-brand);
  color: var(--tv-on-brand);
  font: 600 var(--tv-fs-body) / 1 var(--tv-font);
  cursor: pointer;
  box-shadow: var(--tv-shadow-sm);
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.auth-gate-submit:hover { background: var(--tv-brand-hover); border-color: var(--tv-brand-hover); }

.auth-gate-submit:active { background: var(--tv-brand-hover); border-color: var(--tv-brand-hover); box-shadow: none; }

.auth-gate-submit:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.auth-gate-submit:disabled { opacity: .55; cursor: not-allowed; }

.auth-gate-spinner { display: none; }

.auth-gate[data-state="pending"] .auth-gate-spinner,
.auth-gate[data-state="checking"] .auth-gate-spinner {
  display: block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--tv-brand-soft);
  border-top-color: var(--tv-on-brand);
  border-radius: var(--tv-radius-full);
  animation: auth-gate-spin .7s linear infinite;
}

@keyframes auth-gate-spin { to { transform: rotate(360deg); } }

.auth-gate-actions { display: flex; flex-direction: column; align-items: center; gap: var(--tv-s1); margin-top: var(--tv-s4); }

.auth-gate-retry {
  width: 100%;
  height: var(--tv-control-h-md);
  min-height: var(--tv-control-h-md);
  padding: 0 var(--tv-s4);
  border: 1px solid var(--tv-border-strong);
  border-radius: var(--tv-radius);
  background: var(--tv-surface);
  color: var(--tv-text-2);
  font: 500 var(--tv-fs-md) / 1 var(--tv-font);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.auth-gate-retry:hover { background: var(--tv-surface-hover); border-color: var(--tv-border-strong); color: var(--tv-text); }

.auth-gate-retry:active { background: var(--tv-subtle); }

.auth-gate-retry:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.auth-gate-retry:disabled { opacity: .5; cursor: not-allowed; }

.auth-gate-local-reset {
  display: block;
  margin: 0 auto;
  height: var(--tv-control-h-sm);
  min-height: var(--tv-control-h-sm);
  padding: 0 var(--tv-s3);
  border: 0;
  border-radius: var(--tv-radius-sm);
  background: transparent;
  color: var(--tv-text-3);
  font: 500 var(--tv-fs-md) / 1 var(--tv-font);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

.auth-gate-local-reset:hover { color: var(--tv-text); text-decoration: underline; text-underline-offset: 2px; }

.auth-gate-local-reset:active { color: var(--tv-text-2); }

.auth-gate-local-reset:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--tv-brand-ring); }

.auth-gate-local-reset:disabled { opacity: .5; cursor: not-allowed; }

/* Password reset mode shows only the reset form. */
.auth-gate[data-local-reset="true"] .auth-gate-tabs { display: none; }

.auth-gate[data-local-reset="true"] .auth-gate-head { margin-top: var(--tv-s1); }

/* ---- 10 pending: one state for the whole card --------------------------- */
.auth-gate[data-state="pending"] .auth-gate-tab,
.auth-gate[data-state="pending"] .auth-gate-field input { pointer-events: none; opacity: .65; }

/* ---- 11 account row (settings) ----------------------------------------- */
#authSessionChip,
.auth-session-chip { display: none !important; }

.settings-profile .settings-account-email { max-width: min(100%, 520px); overflow-wrap: anywhere; }

/* ---- 12 responsive ------------------------------------------------------ */
@media (max-width: 520px) {
  .auth-gate { padding: var(--tv-s3); }
  .auth-gate-brand { padding: var(--tv-s3) var(--tv-s4); }
  .auth-gate-form-panel { padding: var(--tv-s5) var(--tv-s4); }
  .settings-profile { align-items: flex-start; }
  .settings-profile .settings-account-email { font-size: var(--tv-fs-md); }
}

/* ---- 13 reduced motion ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .auth-gate *,
  .auth-gate *::before,
  .auth-gate *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
