/* ============================================================
 * AICentra — Authentication surface
 * Phase 10 · 2026-08-14
 * ============================================================
 * Scope: the login / register / OTP / password screens ONLY.
 * Every selector is namespaced under `.aic-auth*` or `.aic-otp*`
 * so this file cannot reach into the shell, the sidebar, or any
 * dashboard component (D4-07 protection).
 *
 * Rules honoured here
 * -------------------
 * D-11  no inline <style> anywhere — this file is the only place
 *       auth styling lives.
 * D-09  no raw colour/radius/shadow/spacing literals: every value
 *       is a `--aic-*` token. Two new tokens were added in
 *       tokens.css (`--aic-tap-min`, `--aic-auth-card-max`); this
 *       file introduces none of its own.
 * RTL   **logical properties only** — `inline-start`/`inline-end`,
 *       `margin-block`, `padding-inline`, `border-start-*`. There
 *       is no `[dir="rtl"]` override block and there must never be
 *       one: the same rules serve Persian (RTL, default) and
 *       English (LTR) because the browser resolves the axis from
 *       the document direction. This is why the file is short.
 * A11y  focus is never removed, only restyled; every interactive
 *       target clears `--aic-tap-min`; motion respects the global
 *       reduced-motion override already set in tokens.css.
 *
 * Load order:
 *   tokens.css → components.css → auth.css
 * ============================================================ */

/* ------------------------------------------------------------
 * 1. Page frame
 * ------------------------------------------------------------ */

.aic-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--aic-space-6) var(--aic-space-4);
  background: var(--aic-color-bg);
  color: var(--aic-color-text);
}

.aic-auth__card {
  inline-size: 100%;
  max-inline-size: var(--aic-auth-card-max);
  background: var(--aic-color-surface);
  border: 1px solid var(--aic-color-border);
  border-radius: var(--aic-radius-lg);
  box-shadow: var(--aic-shadow-md);
  padding: var(--aic-space-8) var(--aic-space-6);
}

/* Single column, mobile-first: the card never becomes a two-pane
 * layout, because the UX research found the marketing pane on the
 * second column costs above-the-fold space on phones and adds
 * nothing on desktop. */

.aic-auth__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--aic-space-2);
  margin-block-end: var(--aic-space-5);
}

.aic-auth__brand-mark {
  inline-size: 2.25rem;
  block-size: 2.25rem;
  border-radius: var(--aic-radius-md);
  background: var(--aic-color-primary-soft);
  color: var(--aic-color-primary-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--aic-weight-black);
}

.aic-auth__title {
  margin: 0 0 var(--aic-space-2);
  font-size: var(--aic-font-xl);
  font-weight: var(--aic-weight-bold);
  text-align: center;
  color: var(--aic-color-text);
}

.aic-auth__lead {
  margin: 0 0 var(--aic-space-6);
  font-size: var(--aic-font-sm);
  text-align: center;
  color: var(--aic-color-text-muted);
}

/* ------------------------------------------------------------
 * 2. Alerts (also the SMS-failure fallback panel)
 * ------------------------------------------------------------ */

.aic-auth__alert {
  margin-block-end: var(--aic-space-5);
  padding: var(--aic-space-3) var(--aic-space-4);
  border-radius: var(--aic-radius-md);
  font-size: var(--aic-font-sm);
  line-height: 1.7;
  border-inline-start: 3px solid transparent;
}

.aic-auth__alert--error {
  background: var(--aic-color-danger-soft);
  border-inline-start-color: var(--aic-color-danger);
  color: var(--aic-color-text);
}

.aic-auth__alert--info {
  background: var(--aic-color-info-soft);
  border-inline-start-color: var(--aic-color-info);
  color: var(--aic-color-text);
}

.aic-auth__alert--warn {
  background: var(--aic-color-warn-soft);
  border-inline-start-color: var(--aic-color-warn);
  color: var(--aic-color-text);
}

.aic-auth__alert--success {
  background: var(--aic-color-success-soft);
  border-inline-start-color: var(--aic-color-success);
  color: var(--aic-color-text);
}

/* Rule A: when SMS delivery fails the user must be handed two real
 * alternatives, not just an apology. The list inherits the alert's
 * colours so it reads as one block. */
.aic-auth__alert-actions {
  margin: var(--aic-space-3) 0 0;
  padding-inline-start: var(--aic-space-5);
}

.aic-auth__alert-actions li + li {
  margin-block-start: var(--aic-space-1);
}

/* ------------------------------------------------------------
 * 3. Quick login (above the fold, before the password form)
 * ------------------------------------------------------------ */

.aic-auth__quick {
  display: grid;
  gap: var(--aic-space-3);
  margin-block-end: var(--aic-space-5);
}

.aic-auth__provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--aic-space-2);
  min-block-size: var(--aic-tap-min);
  padding: var(--aic-space-3) var(--aic-space-4);
  border: 1px solid var(--aic-color-border-strong);
  border-radius: var(--aic-radius-md);
  background: var(--aic-color-surface);
  color: var(--aic-color-text);
  font-size: var(--aic-font-md);
  font-weight: var(--aic-weight-medium);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--aic-transition-fast),
              border-color var(--aic-transition-fast);
}

.aic-auth__provider:hover,
.aic-auth__provider:focus-visible {
  background: var(--aic-color-surface-alt);
  border-color: var(--aic-color-primary);
}

.aic-auth__provider-icon {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  flex: 0 0 auto;
}

/* ------------------------------------------------------------
 * 4. Divider
 * ------------------------------------------------------------ */

.aic-auth__divider {
  display: flex;
  align-items: center;
  gap: var(--aic-space-3);
  margin-block: var(--aic-space-5);
  color: var(--aic-color-text-muted);
  font-size: var(--aic-font-xs);
}

.aic-auth__divider::before,
.aic-auth__divider::after {
  content: "";
  flex: 1 1 auto;
  block-size: 1px;
  background: var(--aic-color-border);
}

/* ------------------------------------------------------------
 * 5. Fields
 * ------------------------------------------------------------ */

.aic-auth__form {
  display: grid;
  gap: var(--aic-space-4);
}

.aic-field {
  display: grid;
  gap: var(--aic-space-2);
}

.aic-field__label {
  font-size: var(--aic-font-sm);
  font-weight: var(--aic-weight-medium);
  color: var(--aic-color-text);
}

.aic-field__input {
  inline-size: 100%;
  min-block-size: var(--aic-tap-min);
  padding: var(--aic-space-3) var(--aic-space-4);
  border: 1px solid var(--aic-color-border-strong);
  border-radius: var(--aic-radius-md);
  background: var(--aic-color-surface);
  color: var(--aic-color-text);
  font: inherit;
  font-size: var(--aic-font-md);
  transition: border-color var(--aic-transition-fast),
              box-shadow var(--aic-transition-fast);
}

.aic-field__input:focus {
  outline: none;              /* replaced immediately below, never removed */
  border-color: var(--aic-color-primary);
  box-shadow: var(--aic-focus-ring);
}

.aic-field__input::placeholder {
  color: var(--aic-color-text-muted);
  opacity: 1;                 /* Firefox dims placeholders by default */
}

/* Inline validation state, driven by auth.js setting aria-invalid.
 * Keying off the ARIA attribute rather than a bespoke class means the
 * visual state and the accessible state can never disagree. */
.aic-field__input[aria-invalid="true"] {
  border-color: var(--aic-color-danger);
}

.aic-field__error {
  min-block-size: 1.25em;     /* reserved: no layout shift when it appears */
  font-size: var(--aic-font-xs);
  color: var(--aic-color-danger);
}

.aic-field__hint {
  font-size: var(--aic-font-xs);
  color: var(--aic-color-text-muted);
}

/* Password field with reveal toggle. The toggle sits on the inline-end
 * edge, which resolves to the left in Persian and the right in English
 * with no override. */
.aic-field--password {
  position: relative;
}

.aic-field--password .aic-field__input {
  padding-inline-end: calc(var(--aic-tap-min) + var(--aic-space-2));
}

.aic-field__reveal {
  position: absolute;
  inset-inline-end: var(--aic-space-1);
  /* Phase M1 (2026-09-01): `inset-block-end: 0` glued the toggle to the
   * bottom of the WHOLE .aic-field grid — i.e. BELOW the reserved error
   * line (min-block-size 1.25em at --aic-font-xs) plus the grid gap
   * (--aic-space-2) — so on production the eye rendered under the input,
   * detached from it. Offset by exactly that reserved space so the toggle
   * vertically centres on the input box itself. */
  inset-block-end: calc((1.25 * var(--aic-font-xs, 0.75rem)) + var(--aic-space-2, 0.5rem));
  inline-size: var(--aic-tap-min);
  block-size: var(--aic-tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--aic-radius-sm);
  background: transparent;
  color: var(--aic-color-text-muted);
  cursor: pointer;
}

.aic-field__reveal:focus-visible {
  outline: none;
  box-shadow: var(--aic-focus-ring);
}

/* Non-blocking password strength: advisory only, never gates submit. */
.aic-strength {
  display: grid;
  gap: var(--aic-space-1);
}

.aic-strength__track {
  block-size: 4px;
  border-radius: var(--aic-radius-pill);
  background: var(--aic-color-neutral-soft);
  overflow: hidden;
}

.aic-strength__bar {
  block-size: 100%;
  inline-size: 0;
  border-radius: var(--aic-radius-pill);
  background: var(--aic-color-neutral);
  transition: inline-size var(--aic-transition-med),
              background var(--aic-transition-med);
}

.aic-strength__bar[data-level="1"] { inline-size: 25%;  background: var(--aic-color-danger); }
.aic-strength__bar[data-level="2"] { inline-size: 50%;  background: var(--aic-color-warn); }
.aic-strength__bar[data-level="3"] { inline-size: 75%;  background: var(--aic-color-info); }
.aic-strength__bar[data-level="4"] { inline-size: 100%; background: var(--aic-color-success); }

.aic-strength__label {
  font-size: var(--aic-font-xs);
  color: var(--aic-color-text-muted);
}

/* Checkbox row (terms). The 44px floor applies to the control itself,
 * and the whole label is clickable, so the effective target is larger. */
.aic-check {
  display: flex;
  align-items: flex-start;
  gap: var(--aic-space-3);
  font-size: var(--aic-font-sm);
  color: var(--aic-color-text-muted);
  line-height: 1.7;
}

.aic-check__box {
  inline-size: 1.15rem;
  block-size: 1.15rem;
  margin-block-start: 0.2rem;
  flex: 0 0 auto;
  accent-color: var(--aic-color-primary);
}

/* ------------------------------------------------------------
 * 6. Buttons
 * ------------------------------------------------------------ */

.aic-auth__submit {
  min-block-size: var(--aic-tap-min);
  inline-size: 100%;
  padding: var(--aic-space-3) var(--aic-space-5);
  border: 0;
  border-radius: var(--aic-radius-md);
  background: var(--aic-color-primary);
  color: var(--aic-color-surface);
  font: inherit;
  font-size: var(--aic-font-md);
  font-weight: var(--aic-weight-bold);
  cursor: pointer;
  transition: background var(--aic-transition-fast);
}

.aic-auth__submit:hover,
.aic-auth__submit:focus-visible {
  background: var(--aic-color-primary-strong);
}

.aic-auth__submit:focus-visible {
  outline: none;
  box-shadow: var(--aic-focus-ring);
}

.aic-auth__submit[disabled],
.aic-auth__submit[aria-busy="true"] {
  opacity: 0.65;
  cursor: not-allowed;
}

/* An <a> that carries the primary action of a screen with no form to post —
   the two social-account outcome pages. An anchor does not inherit the
   button box model, so the three properties a button gets for free are
   restored here. Everything else above already applies. */
.aic-auth__submit--link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.aic-auth__link {
  color: var(--aic-color-primary-strong);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.aic-auth__link:focus-visible {
  outline: none;
  box-shadow: var(--aic-focus-ring);
  border-radius: var(--aic-radius-sm);
}

/* ------------------------------------------------------------
 * 7. Card footer / secondary actions
 * ------------------------------------------------------------ */

.aic-auth__foot {
  margin-block-start: var(--aic-space-6);
  padding-block-start: var(--aic-space-4);
  border-block-start: 1px solid var(--aic-color-border);
  display: grid;
  gap: var(--aic-space-2);
  text-align: center;
  font-size: var(--aic-font-sm);
  color: var(--aic-color-text-muted);
}

.aic-auth__lang {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--aic-space-2);
  margin-block-start: var(--aic-space-4);
}

.aic-auth__lang-btn {
  min-block-size: var(--aic-tap-min);
  min-inline-size: var(--aic-tap-min);
  padding: var(--aic-space-2) var(--aic-space-4);
  border: 1px solid var(--aic-color-border);
  border-radius: var(--aic-radius-pill);
  background: var(--aic-color-surface);
  color: var(--aic-color-text-muted);
  font: inherit;
  font-size: var(--aic-font-xs);
  cursor: pointer;
}

.aic-auth__lang-btn[aria-current="true"] {
  background: var(--aic-color-primary-soft);
  border-color: var(--aic-color-primary);
  color: var(--aic-color-primary-strong);
  font-weight: var(--aic-weight-bold);
}

.aic-auth__lang-btn:focus-visible {
  outline: none;
  box-shadow: var(--aic-focus-ring);
}

/* ------------------------------------------------------------
 * 8. OTP input  (D10-09)
 * ------------------------------------------------------------
 * ONE real <input type="text" autocomplete="one-time-code"> with six
 * boxes DRAWN underneath it. Six separate inputs is the common
 * pattern and it is the wrong one: it breaks iOS/Android SMS
 * autofill, breaks paste, produces six tab stops for screen-reader
 * users, and needs JavaScript to be usable at all. Here the boxes
 * are decorative (`aria-hidden`), the single input carries the whole
 * value, and the flow degrades to a plain text field with JS off.
 * ------------------------------------------------------------ */

.aic-otp {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--aic-space-2);
}

.aic-otp__input {
  /* The real control: full width, transparent, sitting exactly on top
   * of the drawn boxes so the caret and native selection still work. */
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: var(--aic-color-primary);
  font: inherit;
  letter-spacing: 0;
  text-align: center;
  opacity: 0;                 /* value is mirrored into the boxes by JS */
  z-index: 2;
}

.aic-otp__input:focus {
  outline: none;
}

.aic-otp__boxes {
  display: flex;
  gap: var(--aic-space-2);
  direction: ltr;             /* digits always read left-to-right */
}

.aic-otp__boxes > span {
  inline-size: var(--aic-tap-min);
  block-size: calc(var(--aic-tap-min) + var(--aic-space-2));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--aic-color-border-strong);
  border-radius: var(--aic-radius-md);
  background: var(--aic-color-surface);
  font-size: var(--aic-font-xl);
  font-weight: var(--aic-weight-bold);
  font-variant-numeric: tabular-nums;
  color: var(--aic-color-text);
  transition: border-color var(--aic-transition-fast),
              box-shadow var(--aic-transition-fast);
}

/* The box the caret is in, mirrored by auth.js. */
.aic-otp__boxes > span[data-active="true"] {
  border-color: var(--aic-color-primary);
  box-shadow: var(--aic-focus-ring);
}

.aic-otp[data-invalid="true"] .aic-otp__boxes > span {
  border-color: var(--aic-color-danger);
}

.aic-otp__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--aic-space-3);
  inline-size: 100%;
  font-size: var(--aic-font-xs);
  color: var(--aic-color-text-muted);
}

.aic-otp__resend {
  min-block-size: var(--aic-tap-min);
  padding: var(--aic-space-2) var(--aic-space-3);
  border: 0;
  border-radius: var(--aic-radius-sm);
  background: transparent;
  color: var(--aic-color-primary-strong);
  font: inherit;
  font-size: var(--aic-font-xs);
  font-weight: var(--aic-weight-medium);
  cursor: pointer;
}

.aic-otp__resend[disabled] {
  color: var(--aic-color-text-muted);
  cursor: not-allowed;
}

.aic-otp__resend:focus-visible {
  outline: none;
  box-shadow: var(--aic-focus-ring);
}

/* ------------------------------------------------------------
 * 9. Screen-reader-only helper (live regions)
 * ------------------------------------------------------------ */

.aic-sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
 * 10. Persian typography
 * ------------------------------------------------------------
 * The shell already loads the project's Persian face; this only
 * relaxes the line height, because Persian ascenders/descenders
 * collide at the Latin default, and makes digits tabular so OTP
 * boxes and countdown timers do not jitter.
 * ------------------------------------------------------------ */

.aic-auth:lang(fa),
[dir="rtl"] .aic-auth {
  line-height: 1.85;
}

.aic-auth :is(input, .aic-otp__boxes, .aic-otp__meta) {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
 * 11. Narrow viewports
 * ------------------------------------------------------------ */

@media (max-width: 480px) {
  .aic-auth {
    padding: var(--aic-space-4) var(--aic-space-3);
    align-items: flex-start;
  }

  .aic-auth__card {
    padding: var(--aic-space-6) var(--aic-space-4);
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .aic-otp__boxes {
    gap: var(--aic-space-1);
  }
}

/* ------------------------------------------------------------
 * 12. Forced-colors / high-contrast
 * ------------------------------------------------------------ */

@media (forced-colors: active) {
  .aic-auth__provider,
  .aic-auth__submit,
  .aic-otp__boxes > span {
    border: 1px solid CanvasText;
  }
}

/* ------------------------------------------------------------
 * 13. Note on the two `*_modern.html` pages
 * ------------------------------------------------------------
 * `accounts/login_modern.html` and `accounts/register_modern.html`
 * also carried inline `style=` attributes that D-11 forbids, and an
 * earlier draft of this file hosted their replacements here.
 *
 * That was wrong, and measurement caught it: those two templates
 * extend `base.html` and pull `css/aicentra_ui_phase2.css`; they
 * never load `auth.css`. Rules parked here would have been dead
 * bytes and the pages would have silently lost their spacing.
 *
 * The three replacement utilities therefore live beside their
 * siblings (`.aic-badge`, `.aic-inline`) at the end of
 * `static/css/aicentra_ui_phase2.css`. Recorded as D10-15.
 * ------------------------------------------------------------ */

/* ------------------------------------------------------------
 * 14. Phase M1 (2026-09-01) — production rendering hardening
 * ------------------------------------------------------------
 * Zero template edits (the brief forbids touching the login template).
 *
 * What was wrong on https://api.aicentra.pro/accounts/login/
 *  a) The card chrome (surface, border, radius, shadow, padding) and the
 *     page background were declared with bare var(--aic-*) references and
 *     no fallback. If tokens.css is cached-mismatched, blocked, or fails
 *     to load, every one of those declarations is INVALID AT COMPUTED-
 *     VALUE TIME and the card collapses to a transparent, borderless,
 *     unpadded strip — exactly the "به‌هم‌ریخته" rendering captured in the
 *     production screenshot. Every critical declaration below now carries
 *     an explicit fallback so the screen degrades to a styled card instead
 *     of raw unstyled content. (Logged D-09 deviation: literal values are
 *     var() fallbacks ONLY — they activate solely when the token system
 *     itself is unavailable, so they can never fight the design tokens.)
 *  b) .aic-field__label had no display/margin reset: a UA stylesheet
 *     margin on <label> shifts the whole field rhythm.
 *  c) Provider buttons and inputs had no box-sizing guarantee inside the
 *     auth surface; the shell's global reset is outside this file's
 *     namespace and cannot be relied on here (D4-07 protection works both
 *     ways).
 * ------------------------------------------------------------ */

.aic-auth {
  background: var(--aic-color-bg, #f4f6fb);
}

.aic-auth__card {
  background: var(--aic-color-surface, #ffffff);
  border: 1px solid var(--aic-color-border, #e2e8f0);
  border-radius: var(--aic-radius-lg, 1rem);
  box-shadow: var(--aic-shadow-md, 0 8px 24px rgba(15, 23, 42, 0.08));
  padding: var(--aic-space-8, 2rem) var(--aic-space-6, 1.5rem);
}

.aic-field__label {
  display: block;
  margin: 0;
}

.aic-field__input,
.aic-auth__provider,
.aic-auth__submit {
  box-sizing: border-box;
}

.aic-auth__provider {
  inline-size: 100%;
}

/* The Google mark SVG ships intrinsic width/height attributes; without an
 * explicit cap a missing partial style lets it render at attribute size
 * and break the button's vertical rhythm. */
.aic-auth__provider svg,
.aic-auth__provider-icon {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  flex: 0 0 auto;
}

/* Keep the secondary links visually grouped even when the messages region
 * above them is empty (no phantom gap, no collapsed border). */
.aic-auth__foot {
  text-align: center;
}
