/* ==========================================================================
   Auth sheet v2 (Trello ONB-15) — users/templates/users/auth-modal.html
   Figma "Auth Sheet v2 · Log in / · Create account".

   Tokens only: every colour is a var(--ds-*) from seo/css/ds-tokens.css,
   spacing sits on the 4px grid and radii on sm 8 / md 12 / xl 20 / pill.
   Mobile first: a bottom sheet with a grabber; from the 813px desktop
   breakpoint the same content is a centred elevated dialog.

   Everything is scoped under #auth-modal so the legacy .modal, .big-button,
   .text-input and .error-msg rules elsewhere cannot leak in or out.
   ========================================================================== */

#auth-modal.modal-container {
  align-items: flex-end;
}

#auth-modal .dark-overlay {
  background: var(--ds-overlay);
  animation: auth-scrim-in 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Shell ---------------------------------------------------------------- */

#auth-modal .auth-sheet {
  position: relative;
  z-index: var(--z-modal-tier-3-content, 810);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px));
  border-radius: 20px 20px 0 0; /* radius.xl on the top edge only */
  background: var(--ds-elevated);
  color: var(--ds-ink);
  /* font.sans */
  font-family: 'SFProText', -apple-system, BlinkMacSystemFont, 'Montserrat', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  text-align: left;
  /* shadow.elevated pointing up; 30% of the overlay token is the same 12% black */
  box-shadow: 0 -8px 20px color-mix(in srgb, var(--ds-overlay) 30%, transparent);
  animation: auth-sheet-up 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .auth-sheet__grabber {
  flex: none;
  width: 36px;
  height: 4px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--ds-line);
}

#auth-modal .auth-sheet__bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

#auth-modal .auth-sheet__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0 -8px 0 auto;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ds-ink-soft);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1), color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .auth-sheet__close:hover {
  background: var(--ds-surface);
  color: var(--ds-ink);
}

/* --- Segmented control (role=tablist) -------------------------------------- */

#auth-modal .auth-tabs {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--ds-surface);
}

#auth-modal .auth-tabs__tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ds-ink-soft);
  font-family: inherit;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1), color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .auth-tabs__tab[aria-selected='true'] {
  /* elevated (not card) so the pill still separates from the track in dark mode */
  background: var(--ds-elevated);
  color: var(--ds-ink);
  font-weight: 600;
  box-shadow: var(--ds-shadow-card);
  cursor: default;
}

#auth-modal .auth-tabs__tab:not([aria-selected='true']):hover {
  color: var(--ds-ink);
}

/* Password recovery is not one of the two tabs: hide the switch and the legal line there. */
#auth-modal .auth-sheet[data-auth-pane='reset'] .auth-tabs,
#auth-modal .auth-sheet[data-auth-pane='reset-sent'] .auth-tabs,
#auth-modal .auth-sheet[data-auth-pane='reset'] .auth-legal,
#auth-modal .auth-sheet[data-auth-pane='reset-sent'] .auth-legal {
  display: none;
}

/* --- Panes, headings ------------------------------------------------------- */

#auth-modal .auth-form,
#auth-modal .auth-step {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
}

#auth-modal .auth-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#auth-modal .auth-title {
  margin: 0;
  font-family: inherit;
  font-size: 22px;
  line-height: 28px;
  font-weight: 700;
  color: var(--ds-ink);
}

/* Programmatic focus target when a pane opens; it is not a control. */
#auth-modal .auth-title:focus {
  outline: none;
}

#auth-modal .auth-subtitle {
  margin: 0;
  font-size: 15px;
  line-height: 22px;
  font-weight: 400;
  color: var(--ds-ink-soft);
  overflow-wrap: anywhere;
}

#auth-modal .auth-strong {
  font-weight: 600;
  color: var(--ds-ink);
}

/* --- Inputs ---------------------------------------------------------------- */

#auth-modal .auth-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#auth-modal .auth-label {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  color: var(--ds-ink-soft);
}

#auth-modal .auth-input {
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--ds-input-border);
  border-radius: 8px;
  background: var(--ds-elevated);
  color: var(--ds-ink);
  font-family: inherit;
  font-size: 16px; /* never below 16px: iOS Safari zooms into smaller inputs */
  line-height: 24px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 150ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .auth-input::placeholder {
  color: var(--ds-ink-faint);
  opacity: 1;
}

#auth-modal .auth-input:focus,
#auth-modal .auth-input:focus-visible {
  border-color: var(--ds-focus);
  box-shadow: 0 0 0 1px var(--ds-focus); /* 2px focus border without a layout shift */
  outline: none;
}

#auth-modal .auth-input.error,
#auth-modal .auth-input[aria-invalid='true'] {
  border-color: var(--ds-error);
  box-shadow: 0 0 0 1px var(--ds-error);
  background: var(--ds-elevated);
}

#auth-modal .auth-input[readonly] {
  color: var(--ds-ink-soft);
}

#auth-modal .auth-input--code {
  height: 48px;
  font-size: 20px;
  line-height: 28px;
  letter-spacing: 4px;
  font-variant-numeric: tabular-nums;
}

#auth-modal .auth-input-wrap {
  position: relative;
}

#auth-modal .auth-input-wrap .auth-input {
  padding-right: 48px;
}

#auth-modal .auth-input-toggle {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ds-ink-soft);
  font-size: 20px;
  cursor: pointer;
}

#auth-modal .auth-input-toggle:hover {
  color: var(--ds-ink);
}

#auth-modal .auth-helper {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--ds-ink-soft);
}

/* Plain inline text; resets the boxed .error-msg[role='alert'] style from home/css/a11y.css. */
#auth-modal .auth-field-error {
  margin: 4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  color: var(--ds-error-text);
}

/* --- Password rules checklist (ONB-05) ------------------------------------- */

#auth-modal .auth-rules {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

#auth-modal .auth-rule {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--ds-ink-soft);
}

#auth-modal .auth-rule__dot {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ds-line);
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .auth-rule[data-met='true'] {
  color: var(--ds-ink);
}

#auth-modal .auth-rule[data-met='true'] .auth-rule__dot {
  background: var(--ds-success);
}

/* A check mark, so a met rule differs by shape and not by colour alone. */
#auth-modal .auth-rule[data-met='true'] .auth-rule__dot::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 3px;
  height: 7px;
  border: solid var(--ds-on-cta);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* After a submit attempt, rules that still fail read as errors. */
#auth-modal .auth-rules.is-invalid .auth-rule[data-met='false'] {
  color: var(--ds-error-text);
}

#auth-modal .auth-rules.is-invalid .auth-rule[data-met='false'] .auth-rule__dot {
  background: var(--ds-error);
}

/* --- Links, banner, actions ------------------------------------------------ */

#auth-modal .auth-link {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 0;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--ds-link);
  font-family: inherit;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

#auth-modal .auth-link:hover {
  text-decoration: underline;
}

#auth-modal .auth-link--strong {
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}

#auth-modal .auth-forgot {
  align-self: flex-end;
  margin-top: 12px;
}

#auth-modal .auth-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--ds-error);
  border-radius: 8px;
  background: var(--ds-surface);
  color: var(--ds-error-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}

#auth-modal .auth-banner .material-icons-outlined {
  flex: none;
  font-size: 20px;
  line-height: 20px;
}

#auth-modal .auth-turnstile:empty {
  display: none;
}

#auth-modal .auth-actions {
  display: flex;
  flex-direction: column;
}

/* The shared primary (address_transactions/ui/big-button.html): brand fill + fixed dark label. */
#auth-modal .big-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: auto;
  min-height: 48px;
  margin: 0;
  padding: 14px 24px;
  border: 0;
  border-radius: 12px;
  background: var(--ds-brand);
  color: var(--ds-on-cta);
  font-family: inherit;
  font-size: 17px;
  line-height: 20px;
  font-weight: 700;
  box-shadow: none;
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

#auth-modal .big-button:hover {
  background: var(--ds-brand-hover);
}

#auth-modal .big-button:focus-visible,
#auth-modal .auth-tabs__tab:focus-visible,
#auth-modal .auth-sheet__close:focus-visible,
#auth-modal .auth-input-toggle:focus-visible,
#auth-modal .auth-link:focus-visible,
#auth-modal .auth-legal a:focus-visible {
  outline: 2px solid var(--ds-focus);
  outline-offset: 2px;
}

/* Pending twin shown while a request is in flight. */
#auth-modal .big-button.disabled {
  background: var(--ds-brand);
  opacity: 0.6;
  cursor: progress;
}

#auth-modal .auth-secondary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
}

#auth-modal .auth-secondary-actions .auth-link {
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}

#auth-modal .auth-swap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--ds-ink-soft);
  text-align: center;
}

#auth-modal .auth-legal {
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--ds-ink-soft); /* ink-faint in the frame is below AA for body text */
  text-align: center;
}

#auth-modal .auth-legal a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#auth-modal .auth-legal a:hover {
  color: var(--ds-ink);
}

/* --- Breakpoints ----------------------------------------------------------- */

@media (max-width: 359px) {
  #auth-modal .auth-sheet {
    padding-right: 16px;
    padding-left: 16px;
  }

  #auth-modal .auth-tabs__tab {
    padding-right: 8px;
    padding-left: 8px;
  }
}

@media (min-width: 813px) {
  #auth-modal.modal-container {
    align-items: center;
  }

  #auth-modal .auth-sheet {
    width: 440px;
    max-width: calc(100% - 48px);
    max-height: calc(100% - 48px);
    padding: 24px;
    border-radius: 20px;
    box-shadow: var(--ds-shadow-elevated);
    animation: auth-dialog-in 250ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  #auth-modal .auth-sheet__grabber {
    display: none;
  }
}

/* --- Motion ---------------------------------------------------------------- */

@keyframes auth-sheet-up {
  from {
    transform: translateY(100%);
  }
}

@keyframes auth-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes auth-scrim-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #auth-modal .auth-sheet,
  #auth-modal .dark-overlay {
    animation: none;
  }

  #auth-modal .auth-sheet *,
  #auth-modal .auth-sheet *::after {
    transition: none;
  }
}
