/* ============================================================
   Окно входа: почта, код из письма, согласие с условиями, пароль
   сотрудника (accounts/auth/dialog.html).

   Макета в Figma нет — окно собрано в стиле кабинета: тёплая палитра,
   коралловый на действиях, мягкое торможение в анимациях. Цвета — только
   из core/css/tokens.css; --a-* — их короткие имена внутри окна.

   Компьютер и планшет — окно по центру, телефон (до 767px) — шторка снизу.
   ============================================================ */

/* --- Токены и окно ------------------------------------------ */
.auth {
  --a-primary: var(--c-primary);
  --a-primary-hover: var(--c-primary-hover);
  --a-ink: var(--c-ink);
  --a-body: var(--c-body);
  --a-secondary: var(--c-secondary);
  --a-muted: var(--c-muted);
  --a-border: var(--c-border);
  --a-surface: var(--c-surface);
  --a-page: var(--c-page);
  --a-white: var(--c-white);
  --a-alert: var(--c-alert);
  --a-alert-bg: var(--c-alert-soft);
  --a-success: var(--c-success);
  --a-success-bg: var(--c-success-soft);
  --a-ring: color-mix(in srgb, var(--c-primary) 16%, transparent);

  --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: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}

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

.auth::backdrop {
  background-color: color-mix(in srgb, var(--c-ink) 36%, transparent);
  -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 color-mix(in srgb, var(--c-ink) 16%, transparent),
    0 2px 6px color-mix(in srgb, var(--c-ink) 10%, transparent);
  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 color-mix(in srgb, var(--c-alert) 14%, transparent);
}

/* Автозаполнение браузера не должно красить поле в жёлтый */
.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);
}

/* «или» и «Войти через Google» под формой почты */
.auth .auth__or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--a-muted);
  font-size: 14px;
  line-height: 20px;
}

.auth .auth__or::before,
.auth .auth__or::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--a-border);
}

.auth .auth__google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: var(--field-h);
  padding: 0 24px;
  border: 1px solid var(--a-border);
  border-radius: 99px;
  background-color: var(--a-white);
  color: var(--a-ink);
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  transition: border-color var(--t-color) var(--ease-soft), background-color var(--t-color) var(--ease-soft);
}

.auth .auth__google-icon {
  flex: none;
}

@media (hover: hover) {
  .auth .auth__google:hover {
    border-color: var(--a-primary);
    background-color: var(--a-page);
  }
}

@media (hover: hover) {
  .auth .auth__submit:not(:disabled):hover {
    background-color: var(--a-primary-hover);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--c-primary) 28%, transparent);
  }
}

.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 color-mix(in srgb, var(--c-white) 40%, transparent);
  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 {
  margin-top: 16px;
  font-size: 12px !important;
  line-height: 18px !important;
  color: var(--a-muted);
  text-align: center;
  text-wrap: pretty;
}

.auth__consent a,
.auth__docs a {
  font-size: inherit;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--c-muted) 50%, transparent);
  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"] .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: color-mix(in srgb, var(--c-body) 20%, transparent);
    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;
  }
}
