/* Страницы авторизации IdP: вход, 2FA, восстановление и смена пароля.
   Без внешних шрифтов и скриптов: системный стек, один файл стилей. */

:root {
  --bg: #f1f3f7;
  --surface: #ffffff;
  --ink: #12151c;
  --ink-2: #4a5262;
  --ink-3: #667085;
  --line: #dde1e9;
  --line-strong: #c3c9d4;
  --hover: #f5f6f9;
  --brand: #1976d2;
  --brand-press: #1565c0;
  --on-brand: #ffffff;
  --ring: rgba(25, 118, 210, 0.25);
  --err: #d92d20;
  --err-bg: #fdecec;
  --err-ink: #9e1c20;
  --shadow: 0 1px 2px rgba(18, 21, 28, 0.04), 0 12px 32px -8px rgba(18, 21, 28, 0.1);
  --radius-card: 24px;
  --radius-field: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

/* Светлая тема по умолчанию; тёмную включает переключатель (запоминается в браузере) */
:root[data-theme="dark"] {
  --bg: #0e1015;
  --surface: #171a22;
  --ink: #f2f4f8;
  --ink-2: #b4bbc9;
  --ink-3: #8f97a8;
  --line: #2a2f3b;
  --line-strong: #3b4252;
  --hover: #1e222c;
  --ring: rgba(100, 168, 255, 0.4);
  --err: #ff6b6b;
  --err-bg: #2c1517;
  --err-ink: #ffb4b6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -8px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--ring);
}

[hidden] {
  display: none !important;
}

/* ---------- каркас ---------- */

.theme-toggle {
  display: none;
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.js .theme-toggle {
  display: grid;
}

.theme-toggle:hover {
  background: var(--surface);
  color: var(--ink);
}

.theme-toggle [data-icon="sun"],
:root[data-theme="dark"] .theme-toggle [data-icon="moon"] {
  display: none;
}

:root[data-theme="dark"] .theme-toggle [data-icon="sun"] {
  display: block;
}

.page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(32px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.page__brand {
  margin-bottom: 28px;
}

.page__brand a {
  display: block;
  border-radius: 8px;
}

.page__brand img {
  display: block;
  height: 24px;
  width: auto;
}

.card {
  width: 100%;
  max-width: var(--card-max-width);
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 36px 36px 32px;
  text-align: center;
  animation: rise 0.5s var(--ease) both;
}

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

.legal {
  margin-top: auto;
  padding-top: 28px;
  max-width: 520px;
  text-align: center;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.6;
}

/* всё содержимое занимает экран: бренд и форма по центру, юр. текст прижат к низу */
.stage {
  --card-max-width: 440px;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* свободное место под будущий способ входа (1Password, passkey) */
.alt-method {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.alt-method:empty {
  display: none;
}

.alt-method__or {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-3);
  font-size: 13px;
}

.alt-method__or::before,
.alt-method__or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* телефон: карточка растворяется, форма лежит прямо на странице */
@media (max-width: 559px) {
  body {
    background: var(--surface);
  }
  .page {
    padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  }
  /* логотип в углу, форма по центру свободного места между ним и подписью */
  .stage {
    --card-max-width: none;
    padding-top: 56px;
  }
  .page__brand {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: 20px;
    margin: 0;
  }
  .theme-toggle {
    top: calc(max(20px, env(safe-area-inset-top)) - 10px);
    right: 12px;
  }
  .card {
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    animation: none;
  }
  .title {
    font-size: 28px;
  }
}

/* ---------- текст ---------- */

.title {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.lead {
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: 15px;
  text-wrap: pretty;
}

.lead strong {
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.auth-phone {
  display: inline-block;
  white-space: nowrap;
}

.head {
  margin-bottom: 24px;
}

.link-plain.login-settings-action {
  justify-self: center;
  min-height: 44px;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.note {
  margin: 16px 0 0;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.link,
.note a,
.lead a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 0.15s;
}

.link:hover,
.note a:hover,
.lead a:hover {
  text-decoration-color: currentColor;
}

.personal-account-nav {
  width: 100%;
  max-width: var(--card-max-width);
  margin-bottom: 8px;
}

.personal-account-nav .link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--brand-press);
  font-size: 14px;
  text-decoration: none;
}

.personal-account-nav .link span {
  text-decoration: underline;
  text-underline-offset: 3px;
}

:root[data-theme="dark"] .personal-account-nav .link {
  color: #86c1ff;
}

.link-plain {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--ink-2);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.link-plain:hover {
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- ошибки ---------- */

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: center;
  margin: 0 0 20px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--err-bg);
  color: var(--err-ink);
  font-size: 14px;
  line-height: 1.45;
}

.alert svg {
  flex: none;
  margin-top: 2px;
}

.alert a {
  color: inherit;
  font-weight: 600;
}

.alert ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------- поля ---------- */

.form {
  margin: 0;
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 8px;
  text-align: start;
}

.field__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field label,
.field__label {
  font-size: 14px;
  font-weight: 550;
  color: var(--ink);
}

.field__hint {
  margin: 0;
  color: var(--ink-3);
  font-size: 13px;
}

.field__hint ul {
  margin: 0;
  padding-left: 18px;
}

.status {
  width: 56px;
  height: 56px;
  margin-bottom: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e6f4ea;
  color: #1a7f3c;
}

.status--info {
  background: rgba(25, 118, 210, 0.1);
  color: var(--brand);
}

:root[data-theme="dark"] .status {
  background: #14281c;
  color: #5fd38a;
}

:root[data-theme="dark"] .status--info {
  background: rgba(100, 168, 255, 0.14);
  color: #7fb6ff;
}

.rules {
  color: var(--ink-3);
  font-size: 13px;
}

.rules summary {
  cursor: pointer;
  width: fit-content;
  color: var(--ink-2);
}

.rules__body ul {
  margin: 8px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.control {
  position: relative;
}

.control input,
.field > input {
  display: block;
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-field);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px: iOS не приближает страницу при фокусе */
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.control input:hover,
.field > input:hover {
  border-color: var(--line-strong);
}

.control input:focus,
.field > input:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
}

.control input::placeholder,
.field > input::placeholder {
  color: var(--ink-3);
  opacity: 1;
}

/* автозаполнение менеджера паролей не должно перекрашивать поле в жёлтый */
input:-webkit-autofill,
input:-webkit-autofill:focus {
  box-shadow: 0 0 0 1000px var(--surface) inset;
  background-clip: padding-box; /* автозаливка браузера не просвечивает по скруглённым углам рамки */
  transition: background-color 9999s;
}

/* Цвет текста — только когда в поле есть значение: Chrome держит :-webkit-autofill
   и после очистки поля скриптом («Это не вы»), тогда подсказка красилась как введённый текст. */
input:-webkit-autofill:not(:placeholder-shown),
input:-webkit-autofill:not(:placeholder-shown):focus {
  -webkit-text-fill-color: var(--ink);
}

.control--trail input {
  padding-right: 56px;
}

.control__action {
  position: absolute;
  right: 6px;
  top: 50%;
  translate: 0 -50%;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}

.control__action:hover {
  color: var(--ink);
  background: var(--hover);
}

/* ---------- кнопки ---------- */

.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-field);
  background: var(--brand);
  color: var(--on-brand);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--brand-press);
}

.btn:active {
  transform: scale(0.99);
}

.btn:focus-visible {
  outline-offset: 3px;
  border-radius: var(--radius-field);
}

.btn[aria-busy="true"] {
  pointer-events: none;
  color: transparent;
}

.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    rotate: 1turn;
  }
}

.btn--quiet {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.btn--quiet:hover {
  background: var(--hover);
}

.actions {
  display: grid;
  gap: 10px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 20px;
  margin-top: 22px;
  font-size: 14px;
}

.footer-links a {
  color: var(--ink-2);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- аватар ---------- */

.avatar {
  --h: 250;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: oklch(93% 0.045 var(--h));
  color: oklch(38% 0.1 var(--h));
  font-size: 15px;
  font-weight: 650;
  text-transform: uppercase;
  user-select: none;
}

:root[data-theme="dark"] .avatar {
  background: oklch(32% 0.06 var(--h));
  color: oklch(88% 0.07 var(--h));
}

.avatar--empty {
  background: var(--hover);
  color: var(--ink-3);
}

/* ---------- запомненные аккаунты ---------- */

.accounts {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.accounts li {
  position: relative;
}

.accounts .account {
  padding-right: 56px;
}

.account {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.account:hover {
  border-color: var(--line-strong);
  background: var(--hover);
}

.account__name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account__chev {
  flex: none;
  color: var(--ink-3);
}

.account--new {
  width: 100%;
  border-style: dashed;
  color: var(--ink-2);
}

.account--new .account__name {
  font-weight: 500;
}

.account-remove {
  position: absolute;
  right: 8px;
  top: 50%;
  translate: 0 -50%;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.account-remove:hover {
  color: var(--err-ink);
  background: var(--err-bg);
}

.back {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  margin: -8px 0 16px -6px;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.back:hover {
  color: var(--ink);
  background: var(--hover);
}

.back[hidden] {
  display: none;
}

.view-in {
  animation: slide 0.35s var(--ease) both;
}

@keyframes slide {
  from {
    opacity: 0;
    transform: translateX(14px);
  }
}

/* ---------- выбор способа 2FA ---------- */

.methods {
  display: grid;
  gap: 10px;
}

.methods form {
  margin: 0;
}

.method {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.method:hover {
  border-color: var(--brand);
  background: var(--hover);
}

.method__icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--hover);
  color: var(--ink-2);
}

.method__text {
  grid-column: 2;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.method__text:only-child {
  grid-column: 1 / -1;
}

.method__value {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.method__hint {
  color: var(--ink-3);
  font-size: 13px;
}

/* ---------- код из квадратиков ---------- */

.otp {
  position: relative;
  /* единственный настоящий input лежит поверх плиток: SMS-автоподстановка,
     вставка, Backspace и менеджеры паролей работают как с обычным полем */
}

.otp__cells {
  display: grid;
  grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr));
  gap: 8px;
}

.otp__cell {
  height: 64px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.otp__cell[data-active] {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
}

.otp__cell[data-active]:empty::after {
  content: "";
  width: 2px;
  height: 28px;
  border-radius: 1px;
  background: var(--brand);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.otp__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;
  caret-color: transparent;
  cursor: text;
}

.otp[data-invalid] .otp__cell {
  border-color: var(--err);
}

.otp[data-invalid] .otp__cells {
  animation: shake 0.4s var(--ease);
}

@keyframes shake {
  20% {
    translate: -6px 0;
  }
  45% {
    translate: 5px 0;
  }
  70% {
    translate: -3px 0;
  }
}

@media (max-width: 380px) {
  .otp__cells {
    gap: 6px;
  }
  .otp__cell {
    height: 58px;
    font-size: 24px;
    border-radius: 12px;
  }
}

/* ---------- чекбокс ---------- */

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--brand);
  flex: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Настройка приложения-аутентификатора и резервные коды. */
.totp-qr {
  display: grid;
  width: fit-content;
  margin: 0 auto 18px;
  padding: 8px;
  border-radius: 8px;
  background: #fff;
}

.totp-qr img {
  display: block;
  image-rendering: pixelated;
}

.totp-details {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 14px;
}

.totp-details summary {
  color: var(--ink);
  cursor: pointer;
  font-weight: 550;
}

.totp-management > summary {
  min-height: 44px;
  padding-block: 10px;
}

.totp-management > form {
  margin-top: 12px;
}

.totp-key,
.recovery-codes code {
  overflow-wrap: anywhere;
  user-select: all;
}

.totp-cancel,
.totp-links {
  margin-top: 18px;
}

.totp-links {
  display: grid;
  justify-items: center;
  gap: 8px;
  font-size: 14px;
}

.totp-links a {
  color: var(--ink-2);
  text-decoration-color: var(--line-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  width: fit-content;
}

.totp-links a:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

.totp-enrollment-offer {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin-top: 20px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.totp-enrollment-offer .link-plain {
  min-height: 44px;
  color: var(--ink);
  font-size: 16px;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.totp-enrollment-offer p {
  margin: 0;
  color: var(--ink-2);
  font-size: 14px;
}

.recovery-codes {
  display: grid;
  gap: 4px;
  margin: 0 0 20px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  list-style: none;
  background: var(--hover);
}

.recovery-codes code {
  font-size: clamp(10px, 3.2vw, 13px);
}

.totp-copy,
.totp-copy-status {
  margin-bottom: 12px;
}
