/*
 * auth.css: the look of the app's log-in pages: the "quiet card" (D-89): a white card on the pale
 * bluish page, navy text and blue buttons and links (D-111). Colors, fonts and corners come only from the brand's design tokens (--color-*, --font-*,
 * --radius, written on each page by backend/html-pages.js), never written here.
 *
 * Every rule starts with an .auth- class, so these styles can only ever touch the auth pages
 * (tests/auth.test.js checks it). The basics every webbox screen has: a visible keyboard focus
 * outline, buttons and fields at least 44px tall, long words wrap, readable text (WCAG AA).
 */

.auth-page {
  margin: 0;
  min-height: 100vh;
  box-sizing: border-box;
  /* The logo sits at the same spot on every page (D-107): the page starts from the top, not the middle,
     so only the card below it changes size from page to page. */
  /* The space above the logo and between the logo and the card shares out whatever height is left after
     the tallest card (sign-up, about 650px on a phone): roomy on a tall desktop, small on a laptop or phone, so the
     whole sign-up card still fits on screen (D-109). */
  /* D-112: 50px less on both, so the logo sits higher and the card closer to it. */
  padding: clamp(24px, calc((100vh - 650px) * 0.55 - 50px), 110px) 20px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 28px;
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.5;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}
.auth-page *, .auth-page *::before, .auth-page *::after { box-sizing: border-box; }

.auth-logo {
  /* The gap between the logo and the card: the other share of the leftover height (D-109). */
  margin-bottom: clamp(8px, calc((100vh - 650px) * 0.45 - 50px), 70px);
  font-family: var(--font-logo, var(--font-display));
  font-size: var(--logo-size, 26px);
  line-height: 1.2;
  font-weight: var(--logo-weight, 700);
  letter-spacing: var(--logo-tracking, -0.03em);
  color: var(--color-logo, var(--color-primary));
  /* Drawn a little bolder when the brand asks (logo-stroke, D-111): a thin outline in the same color. */
  -webkit-text-stroke: var(--logo-stroke, 0) currentColor;
  paint-order: stroke fill;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.28em;
}
/* The bot check (D-124): Cloudflare's widget, the card's width, above the button. Hidden (no height) unless
   Cloudflare needs the visitor to click; then it shows with the form's usual spacing. */
.auth-bot-check { width: 100%; }
.auth-bot-check:empty { display: none; }

/* The mark beside the name, as tall as the name's font size (D-123). */
.auth-logo-mark { flex: none; width: 1em; height: 1em; }

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 36px 36px;
  background: var(--color-surface);
  /* A clear but thin edge and a whisper-soft shadow (D-107): the card lifts off the page without looking
     heavy. Both are mixed from the brand's own colors. */
  border: 1px solid color-mix(in srgb, var(--color-border) 60%, var(--color-text-muted));
  border-radius: 20px;
  box-shadow:
    0 1px 2px color-mix(in srgb, var(--color-text) 5%, transparent),
    0 16px 40px -16px color-mix(in srgb, var(--color-text) 14%, transparent);
}

/* The small lines under the card ("Forgot password?", "Create an account", "Back to log in"...): on the
   left, lined up with the card's edge, the same on every page (D-107). */
.auth-below {
  width: 100%;
  max-width: 400px;
  margin: -10px 0 0;
  padding: 0 4px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.auth-below .auth-text { text-align: left; }

.auth-form { display: flex; flex-direction: column; gap: 22px; margin: 0; }

.auth-title {
  margin: 0 0 4px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.auth-text { margin: 0; text-align: center; color: var(--color-text-muted); }

.auth-message {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-background));
  color: var(--color-text);
  font-size: 14px;
}

.auth-field { display: flex; flex-direction: column; gap: 8px; }
.auth-label { font-size: 14px; font-weight: 600; }

.auth-input {
  min-height: 44px;
  padding: 0 14px;
  font: inherit;
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-surface);
  /* A field's edge must stand out 3:1 from the page (WCAG 1.4.11): muted text, lightened a little. */
  border: 1px solid color-mix(in srgb, var(--color-text-muted) 75%, var(--color-background));
  border-radius: 8px;
}
/* Focus (D-92): one quiet change, not two lines: the edge turns dark, with a faint blue glow. Still
   clearly visible for keyboard users (WCAG 2.4.7). */
.auth-input:focus, .auth-code:focus-within .auth-code-box {
  outline: none;
  border-color: var(--color-text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 18%, transparent);
}

/*
 * The code (D-92): six squares drawn behind ONE real field, so pasting and "fill code from email" work.
 * Digits use a monospace font, so each one is exactly 1ch wide; letter-spacing then steps each digit into
 * the next square. The squares fill the card's width, like the button (the card is 328px inside; on a
 * narrow phone, 100vw minus the page and card padding). The field is a little wider than the squares,
 * so it never scrolls sideways; the extra bit is clipped off.
 */
.auth-code {
  --code-width: min(328px, calc(100vw - 112px));
  --code-gap: 8px;
  --code-box: calc((var(--code-width) - 5 * var(--code-gap)) / 6);
  position: relative;
  width: var(--code-width);
  height: 52px;
}
.auth-code-boxes { position: absolute; inset: 0; display: flex; gap: var(--code-gap); }
.auth-code-box {
  flex: 1;
  border: 1px solid color-mix(in srgb, var(--color-text-muted) 75%, var(--color-background));
  border-radius: 8px;
  background: var(--color-surface);
}
.auth-code-input {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--code-width) + var(--code-gap) + (var(--code-box) - 1ch) / 2 + 4px);
  clip-path: inset(0 calc(100% - var(--code-width)) 0 0);
  margin: 0;
  padding: 0 0 0 calc((var(--code-box) - 1ch) / 2);
  border: 0;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 22px;
  letter-spacing: calc(var(--code-box) + var(--code-gap) - 1ch);
}

.auth-button {
  margin-top: 6px;
  min-height: 44px;   /* slightly slimmer (D-106); still the 44px touch minimum */
  min-width: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* Links (D-106, D-120): the brand's link color (the "link" token: deep indigo, so links don't look like the
   blue buttons), never underlined. Semibold, so they stand out from the text around them by weight as well as
   color (WCAG 1.4.1: never by color alone). On hover they turn a touch darker; the pointer shows they click. */
.auth-link { color: var(--color-link); font-weight: 600; text-decoration: none; transition: color 0.15s ease; }
.auth-link:hover { color: color-mix(in srgb, var(--color-link) 70%, var(--color-text)); }

/* The keyboard focus ring: the brand blue, which stands out at least 3:1 from the page (WCAG 1.4.11; D-111). */
.auth-logo:focus-visible, .auth-button:focus-visible, .auth-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* Sign-up and "You're in" (D-103) */
.auth-form-after { margin-top: 18px; gap: 10px; }
.auth-hint { font-size: 13px; color: var(--color-text-muted); }
.auth-small { margin: 0; text-align: center; font-size: 13px; line-height: 1.5; color: var(--color-text-muted); }
/* A label with a small link beside it ("Forgot password?", "See plans"). */
.auth-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; padding: 0; }
.auth-small-link { font-size: 14px; }
/* The plan dropdown (D-104): a real <select>, drawn like the other boxes, with a small chevron made of
   two CSS gradients (no image, no colors of its own). Stays tidy however many plans there are. */
.auth-select {
  appearance: none;
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 16px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.auth-summary { margin: 0; padding: 4px 16px; border: 1px solid var(--color-border); border-radius: 12px; background: var(--color-surface); }
.auth-summary-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }
.auth-summary-row + .auth-summary-row { border-top: 1px solid var(--color-border); }
.auth-summary-row dt { color: var(--color-text-muted); }
.auth-summary-row dd { margin: 0; font-weight: 600; }
/* A button that looks like a link ("Send a new code", "Log out"): a real button, so it can send a form. */
.auth-link-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--color-link);
  text-decoration: none;
  cursor: pointer;
  min-height: 24px;
  transition: color 0.15s ease;
}
.auth-link-button:hover { color: color-mix(in srgb, var(--color-link) 70%, var(--color-text)); }
.auth-link-button:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; }
.auth-button[href] { display: flex; align-items: center; justify-content: center; text-decoration: none; }

