/*
 * Hosted auth screens.
 *
 * System fonts only, same as the dashboard: a webfont would need either a
 * third-party origin the CSP forbids or a binary in the repo, and it would
 * delay first paint on the one page where a user is deciding whether they
 * trust what they are looking at.
 *
 * --accent is overwritten at runtime from the project's brandColor. It is the
 * only tenant-controlled value that reaches CSS, it is set as a property value
 * rather than injected as text, and it is validated as a hex colour before it
 * is ever stored - see validateProjectSettings.
 */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #99a1b3;
  --accent: #5b8cff;
  --accent-text: #ffffff;
  --danger: #ff5c5c;
  --danger-bg: #2a1618;
  --ok: #3ecf8e;
  --ok-bg: #10251d;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #d9dde5;
    --text: #14171f;
    --muted: #5c6577;
    --accent: #2f5fd8;
    --danger: #c9252d;
    --danger-bg: #fdf0f0;
    --ok: #17794f;
    --ok-bg: #edf7f2;
  }
}

* {
  box-sizing: border-box;
}

/*
 * Load-bearing, and the reason is easy to miss.
 *
 * The `hidden` attribute is implemented by the user-agent stylesheet as
 * display:none, and ANY author rule that sets display beats it - including
 * `.view { display: flex }` below. Without this line every screen renders at
 * once: the sign-in form, the sign-up form and the reset form stacked on one
 * page, all wired and all submittable.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  /*
   * A quiet radial wash behind the card, in --accent, the one tenant colour
   * this page already trusts (validated as a hex value before it ever
   * reaches CSS - see the note at the top of this file). Fixed so it does
   * not scroll with a tall sign-up form, and far too faint to compete with
   * the card itself for attention.
   */
  background-image: radial-gradient(
    480px 320px at 50% 15%,
    color-mix(in srgb, var(--accent) 16%, transparent),
    transparent 70%
  );
  background-attachment: fixed;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  margin-bottom: 12px;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-mark .arc {
  stroke-width: 3.6;
  stroke-linecap: round;
  /*
   * castomo's mark, drawn in the tenant's own --accent rather than its usual
   * fixed warm palette - it still reads as one broken ring, but it now sits
   * on the page in the tenant's colour instead of clashing with it. The
   * three arcs step in opacity, from the original mark's three tones down to
   * one hue.
   */
  stroke: var(--accent);
}

.brand-mark .arc-1 {
  opacity: 0.55;
}

.brand-mark .arc-2 {
  opacity: 0.8;
}

.brand-mark .arc-3 {
  opacity: 1;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  /* An app name is tenant-controlled and arbitrary length; it must wrap rather
     than push the card wider than the viewport. */
  overflow-wrap: anywhere;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.view {
  display: flex;
  flex-direction: column;
}

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

label + input,
label + select,
label + textarea {
  margin-bottom: 16px;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="checkbox"] {
  width: auto;
  margin: 0 8px 16px 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}

.checkbox-row label {
  margin: 0;
}

/* The stacked-field bottom margin would push the box off the label's baseline. */
.checkbox-row input[type="checkbox"] {
  margin: 0 8px 0 0;
}

button.primary {
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  margin-top: 4px;
}

button.primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  font-size: 13px;
}

.links a {
  color: var(--accent);
  text-decoration: none;
}

.links a:hover {
  text-decoration: underline;
}

.hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

/* Provider sign-in */

.providers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.providers a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  text-decoration: none;
}

.providers a:hover {
  border-color: var(--muted);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
}

/* Rules either side of the word, without an extra pair of elements to style. */
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.banner {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
  overflow-wrap: anywhere;
}

.banner.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
}

.banner.ok {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: var(--ok);
}

.footnote {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  button.primary {
    transition: opacity 120ms ease;
  }

  /*
   * The card's one entrance, on first paint only - nothing here re-fires
   * when JS swaps between sign-in/sign-up/forgot, because showView() only
   * ever toggles `hidden` on the forms nested inside this same card.
   */
  .card {
    animation: card-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  @keyframes card-in {
    from {
      opacity: 0;
      transform: translateY(10px) scale(0.98);
    }
  }

  /*
   * Each arc draws itself in, stroke-dasharray sized to roughly that arc's
   * own length so the line appears to trace the ring rather than just fade.
   * Staggered by 90ms per arc so the mark assembles rather than blinking on
   * as one shape.
   */
  .brand-mark .arc {
    stroke-dasharray: 17;
    stroke-dashoffset: 17;
    animation: arc-draw 620ms ease-out both;
  }

  .brand-mark .arc-1 {
    animation-delay: 0ms;
  }

  .brand-mark .arc-2 {
    animation-delay: 90ms;
  }

  .brand-mark .arc-3 {
    animation-delay: 180ms;
  }

  @keyframes arc-draw {
    from {
      stroke-dashoffset: 17;
    }
    to {
      stroke-dashoffset: 0;
    }
  }
}
