/* ============================================================
   Окно авторизации: вход, регистрация, подтверждение почты,
   сброс пароля (accounts/auth_system/authentication_n_authorization.html).

   Макета в Figma нет — окно собрано в стиле новых страниц сайта и
   личного кабинета (accounts/css/cabinet.css): тёплая палитра, шрифт
   Hanken Grotesk, коралловый #E25C42 на действиях и при наведении
   на интерактивные иконки, мягкое торможение в анимациях.

   Ширины — по .memory-bank/ui-rules.md, как у кабинета: Desktop и
   Tablet — окно по центру, Mobile (до 767px) — шторка снизу.

   html в base.css имеет font-size 8.5px, поэтому размеры здесь в px.
   ============================================================ */

/* --- Токены и окно ------------------------------------------ */
.auth {
  --a-primary: #e25c42;
  --a-primary-hover: #cc4b32;
  --a-ink: #2a2420;
  --a-body: #4a433d;
  --a-secondary: #6e655f;
  --a-muted: #8a817b;
  --a-border: #e4dcd5;
  --a-surface: #f5efe9;
  --a-page: #fdf8f4;
  --a-white: #ffffff;
  --a-alert: #b23c25;
  --a-alert-bg: #fbefec;
  --a-success: #2e8b6e;
  --a-success-bg: #edf6f2;
  --a-ring: rgba(226, 92, 66, 0.16);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --t-color: 0.3s;
  --t-press: 0.25s;
  --t-move: 0.45s;

  --win-w: 480px;
  --win-pad-x: 40px;
  --win-radius: 32px;
  --fs-title: 28px;
  --lh-title: 36px;
  --field-h: 48px;

  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: transparent;
  border: 0;
  color: var(--a-body);
  font-family: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}

/* Окно по центру, а если оно выше экрана — от верхнего края с прокруткой
   (place-items: center обрезал бы верх без возможности до него докрутить) */
.auth[open] {
  display: grid;
}

.auth::backdrop {
  background-color: rgba(42, 36, 32, 0.36);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

html:has(.auth[open]) {
  overflow: hidden;
}

/* base.css навязывает элементам шрифт, размеры и курсор по умолчанию */
.auth *,
.auth *::before,
.auth *::after {
  box-sizing: border-box;
  cursor: inherit;
}

.auth a,
.auth button,
.auth label {
  cursor: pointer;
}

.auth input {
  cursor: text;
}

.auth a,
.auth button,
.auth input,
.auth p,
.auth h2 {
  font-family: inherit;
}

.auth p {
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

.auth [hidden] {
  display: none !important;
}

.auth__window {
  position: relative;
  width: min(var(--win-w), 100%);
  margin: auto;
  padding: 40px var(--win-pad-x) 28px;
  background-color: var(--a-white);
  border-radius: var(--win-radius);
  box-shadow:
    0 32px 80px rgba(42, 36, 32, 0.16),
    0 2px 6px rgba(42, 36, 32, 0.1);
  outline: none;
}

/* Ручка шторки — только на мобильном */
.auth__handle {
  display: none;
}

/* --- «Назад» и «Закрыть» в верхних углах окна --------------- */
.auth__bar {
  position: absolute;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 2;
  display: flex;
  align-items: center;
  height: 40px;
  pointer-events: none;
}

.auth__bar > * {
  pointer-events: auto;
}

.auth__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--a-muted);
  background-color: transparent;
  border: 0;
  border-radius: 50%;
  transition:
    color var(--t-color) var(--ease-soft),
    background-color var(--t-color) var(--ease-soft),
    transform var(--t-press) var(--ease-out);
}

.auth__close {
  margin-left: auto;
}

@media (hover: hover) {
  .auth__icon-btn:hover {
    color: var(--a-primary);
    background-color: var(--a-surface);
  }

  .auth__close:hover svg {
    transform: rotate(90deg);
  }

  .auth__back:hover svg {
    transform: translateX(-2px);
  }
}

.auth__icon-btn svg {
  transition: transform var(--t-move) var(--ease-out);
}

.auth__icon-btn:active {
  transform: scale(0.92);
}

.auth__icon-btn:focus-visible,
.auth__link:focus-visible,
.auth__submit:focus-visible,
.auth-field__eye:focus-visible,
.auth__footer a:focus-visible,
.auth-consent a:focus-visible {
  outline: 2px solid var(--a-primary);
  outline-offset: 2px;
}

/* --- Шаги ---------------------------------------------------- */
.auth__viewport {
  position: relative;
}

/* base.css даёт каждой section отступ сверху и overflow: hidden */
.auth .auth__step {
  margin: 0;
  overflow: visible;
}

.auth__head {
  margin-bottom: 24px;
  text-align: center;
}

.auth__badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  color: var(--a-primary);
  background-color: var(--a-surface);
  border-radius: 50%;
}

.auth .auth__title {
  margin: 0 0 8px;
  font-size: var(--fs-title);
  line-height: var(--lh-title);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--a-ink);
}

.auth__lead {
  max-width: 360px;
  margin: 0 auto !important;
  font-size: 15px !important;
  line-height: 22px !important;
  color: var(--a-secondary);
  overflow-wrap: anywhere;
}

.auth__email {
  font-weight: 600;
  color: var(--a-ink);
}

/* --- Формы и поля ------------------------------------------- */
.auth__form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-field__label {
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  color: var(--a-body);
}

.auth-field__control {
  position: relative;
}

.auth .auth-field__input {
  display: block;
  width: 100%;
  height: var(--field-h);
  padding: 0 16px;
  /* 16px — меньше iOS увеличивает страницу при фокусе */
  font-size: 16px;
  line-height: 24px;
  color: var(--a-ink);
  background-color: var(--a-page);
  border: 1px solid var(--a-border);
  border-radius: 14px;
  box-shadow: 0 0 0 0 transparent;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition:
    border-color var(--t-color) var(--ease-soft),
    background-color var(--t-color) var(--ease-soft),
    box-shadow var(--t-color) var(--ease-soft);
}

.auth .auth-field__input--password {
  padding-right: 52px;
}

.auth .auth-field__input::placeholder {
  color: var(--a-muted);
  opacity: 0.7;
}

@media (hover: hover) {
  .auth .auth-field__input:hover {
    border-color: var(--a-muted);
  }
}

/* base.css ставит на :focus-visible серую рамку с !important */
.auth .auth-field__input:focus,
.auth .auth-field__input:focus-visible {
  background-color: var(--a-white);
  border-color: var(--a-primary) !important;
  box-shadow: 0 0 0 4px var(--a-ring);
}

.auth .auth-field.has-error .auth-field__input {
  background-color: var(--a-alert-bg);
  border-color: var(--a-alert);
}

.auth .auth-field.has-error .auth-field__input:focus {
  box-shadow: 0 0 0 4px rgba(178, 60, 37, 0.14);
}

/* Автозаполнение браузера не должно красить поле в жёлтый */
.auth .auth-field__input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 40px var(--a-page) inset;
  -webkit-text-fill-color: var(--a-ink);
}

.auth-field__eye {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--a-muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  transition: color var(--t-color) var(--ease-soft);
}

.auth-field__eye-shut,
.auth-field__eye[aria-pressed="true"] .auth-field__eye-open {
  display: none;
}

.auth-field__eye[aria-pressed="true"] .auth-field__eye-shut {
  display: block;
}

@media (hover: hover) {
  .auth-field__eye:hover {
    color: var(--a-primary);
  }
}

.auth-field__hint,
.auth-field__error {
  font-size: 13px !important;
  line-height: 18px !important;
}

.auth-field__hint {
  color: var(--a-muted);
}

.auth-field__error {
  color: var(--a-alert);
}

/* Общие ошибки и сообщения шага */
.auth__error,
.auth__notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  font-size: 14px !important;
  line-height: 20px !important;
  border-radius: 12px;
}

.auth__error {
  color: var(--a-alert);
  background-color: var(--a-alert-bg);
}

.auth__notice {
  color: var(--a-success);
  background-color: var(--a-success-bg);
}

.auth__notice svg {
  flex: none;
  margin-top: 1px;
}

/* --- Кнопки и ссылки ---------------------------------------- */
.auth .auth__submit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--field-h);
  margin-top: 8px;
  padding: 0 24px;
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  color: var(--a-white);
  background-color: var(--a-primary);
  border: 0;
  border-radius: 99px;
  transition:
    background-color var(--t-color) var(--ease-soft),
    opacity var(--t-color) var(--ease-soft),
    transform var(--t-press) var(--ease-out),
    box-shadow var(--t-color) var(--ease-soft);
}

@media (hover: hover) {
  .auth .auth__submit:not(:disabled):hover {
    background-color: var(--a-primary-hover);
    box-shadow: 0 8px 20px rgba(226, 92, 66, 0.28);
  }
}

.auth .auth__submit:not(:disabled):active {
  transform: scale(0.98);
}

.auth .auth__submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Отправка: текст уступает место крутилке, кнопка не жмётся повторно */
.auth .auth__submit.is-loading {
  color: transparent;
  opacity: 1;
  cursor: progress;
}

.auth .auth__submit.is-loading::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--a-white);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}

.auth .auth__link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: var(--a-primary);
  background: transparent;
  border: 0;
  border-radius: 4px;
  transition: color var(--t-color) var(--ease-soft);
}

@media (hover: hover) {
  .auth .auth__link:not(:disabled):hover {
    color: var(--a-primary-hover);
  }
}

.auth .auth__link:disabled {
  color: var(--a-muted);
  cursor: default;
}

.auth__resend {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.auth__resend-timer {
  font-variant-numeric: tabular-nums;
}

.auth__turnstile {
  display: flex;
  justify-content: center;
}

/* --- Код из письма: шесть ячеек поверх настоящего поля ------- */
.auth-code__control {
  position: relative;
}

.auth-code__cells {
  display: none;
}

.auth-code.is-enhanced .auth-code__cells {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  pointer-events: none;
}

.auth .auth-code.is-enhanced .auth-code__input {
  position: absolute;
  inset: 0;
  z-index: 1;
  height: 100%;
  padding: 0;
  color: transparent;
  caret-color: transparent;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  letter-spacing: 0;
  /* Выделение текста в прозрачном поле не должно подсвечиваться */
  -webkit-user-select: none;
  user-select: none;
}

.auth .auth-code.is-enhanced .auth-code__input::selection {
  background: transparent;
}

.auth-code__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--a-ink);
  background-color: var(--a-page);
  border: 1px solid var(--a-border);
  border-radius: 14px;
  transition:
    border-color var(--t-color) var(--ease-soft),
    background-color var(--t-color) var(--ease-soft),
    box-shadow var(--t-color) var(--ease-soft);
}

.auth-code__cell.is-filled {
  background-color: var(--a-white);
}

.auth-code__cell.is-filled span {
  animation: auth-pop 0.35s var(--ease-out);
}

.auth-code.is-focused .auth-code__cell.is-active {
  background-color: var(--a-white);
  border-color: var(--a-primary);
  box-shadow: 0 0 0 4px var(--a-ring);
}

/* Мигающая каретка в пустой активной ячейке */
.auth-code.is-focused .auth-code__cell.is-active:not(.is-filled)::after {
  content: "";
  width: 2px;
  height: 26px;
  background-color: var(--a-primary);
  border-radius: 1px;
  animation: auth-caret 1s steps(1) infinite;
}

.auth-code.has-error .auth-code__cell {
  background-color: var(--a-alert-bg);
  border-color: var(--a-alert);
}

/* --- Согласие при регистрации ------------------------------- */
.auth-consent {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.auth-consent__label {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* Настоящий чекбокс остаётся в потоке фокуса, но не виден */
.auth-consent__checkbox {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  margin: 0;
  padding: 0;
  opacity: 0;
}

.auth-consent__box {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  color: transparent;
  background-color: var(--a-page);
  border: 1.5px solid var(--a-border);
  border-radius: 6px;
  transition:
    color var(--t-color) var(--ease-soft),
    background-color var(--t-color) var(--ease-soft),
    border-color var(--t-color) var(--ease-soft),
    transform var(--t-press) var(--ease-out);
}

@media (hover: hover) {
  .auth-consent__label:hover .auth-consent__box {
    border-color: var(--a-primary);
  }
}

.auth-consent__checkbox:checked + .auth-consent__box {
  color: var(--a-white);
  background-color: var(--a-primary);
  border-color: var(--a-primary);
}

.auth-consent__checkbox:checked + .auth-consent__box svg {
  animation: auth-pop 0.35s var(--ease-out);
}

.auth-consent__checkbox:active + .auth-consent__box {
  transform: scale(0.9);
}

.auth-consent__checkbox:focus-visible + .auth-consent__box {
  outline: 2px solid var(--a-primary);
  outline-offset: 2px;
}

.auth-consent.has-error .auth-consent__box {
  border-color: var(--a-alert);
}

.auth-consent__text,
.auth-consent__fine {
  font-size: 12px !important;
  line-height: 18px !important;
}

.auth-consent__text {
  color: var(--a-secondary);
}

.auth-consent__fine {
  padding-left: 32px;
  color: var(--a-muted);
}

.auth-consent a,
.auth__docs a {
  font-size: inherit;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(138, 129, 123, 0.5);
  text-underline-offset: 2px;
  transition:
    color var(--t-color) var(--ease-soft),
    text-decoration-color var(--t-color) var(--ease-soft);
}

@media (hover: hover) {
  .auth-consent a:hover,
  .auth__docs a:hover,
  .auth__help a:hover {
    color: var(--a-primary);
    text-decoration-color: var(--a-primary);
  }
}

/* --- Подвал: помощь и документы ----------------------------- */
.auth__footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
  padding-top: 20px;
  text-align: center;
  border-top: 1px solid var(--a-surface);
}

.auth__help {
  font-size: 13px !important;
  line-height: 20px !important;
  color: var(--a-muted);
}

.auth__help a {
  font-size: inherit;
  font-weight: 500;
  color: var(--a-body);
  white-space: nowrap;
  transition: color var(--t-color) var(--ease-soft);
}

/* В согласии нового кабинета все четыре документа уже названы */
.auth[data-step="login_create"] .auth__docs {
  display: none;
}

.auth__docs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 14px;
  font-size: 12px !important;
  line-height: 18px !important;
  color: var(--a-muted);
}

/* --- Mobile: шторка снизу ----------------------------------- */
@media (max-width: 767px) {
  .auth {
    --win-pad-x: 20px;
    --win-radius: 28px;
    --fs-title: 24px;
    --lh-title: 32px;

    padding: 0;
    overflow: hidden;
  }

  .auth[open] {
    align-items: end;
  }

  .auth__window {
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    margin: auto 0 0;
    padding-top: 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: var(--win-radius) var(--win-radius) 0 0;
  }

  .auth__handle {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: center;
    margin: 0 calc(-1 * var(--win-pad-x));
    padding: 10px 0 2px;
    background-color: var(--a-white);
  }

  .auth__bar {
    top: 18px;
    right: 8px;
    left: 8px;
  }

  .auth__head {
    padding-top: 16px;
  }

  .auth__handle span {
    width: 40px;
    height: 4px;
    background-color: rgba(74, 67, 61, 0.2);
    border-radius: 2px;
  }

  .auth__badge {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
  }

  .auth-code__cells {
    gap: 6px;
  }

  .auth-code__cell {
    height: 54px;
    font-size: 22px;
  }
}

/* --- Движение ------------------------------------------------ */
@keyframes auth-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
}

@keyframes auth-out {
  to {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

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

@keyframes auth-sheet-out {
  to {
    transform: translateY(100%);
  }
}

@keyframes auth-fade {
  from {
    opacity: 0;
  }
}

@keyframes auth-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes auth-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes auth-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

@keyframes auth-caret {
  50% {
    opacity: 0;
  }
}

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

.auth[open] .auth__window {
  animation: auth-in 0.6s var(--ease-out) both;
}

.auth[open]::backdrop {
  animation: auth-fade 0.4s var(--ease-soft) both;
}

.auth.is-closing .auth__window {
  animation: auth-out 0.28s var(--ease-soft) both;
}

.auth.is-closing::backdrop {
  animation: auth-fade-out 0.28s var(--ease-soft) both;
}

@media (max-width: 767px) {
  .auth[open] .auth__window {
    animation-name: auth-sheet-in;
  }

  .auth.is-closing .auth__window {
    animation-name: auth-sheet-out;
  }
}

/* Содержимое окна проявляется следом за самим окном при открытии */
.auth.is-opening .auth__viewport > :not([hidden]),
.auth.is-opening .auth__footer {
  animation: auth-rise 0.7s var(--ease-out) 0.08s backwards;
}

/* Ошибку с сервера или из проверки подчёркивает короткая встряска */
.auth .is-shaking {
  animation: auth-shake 0.4s var(--ease-soft);
}

@media (prefers-reduced-motion: reduce) {
  .auth *,
  .auth *::before,
  .auth *::after,
  .auth[open] .auth__window,
  .auth.is-closing .auth__window,
  .auth::backdrop {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
