/* ==========================================================================
   TG Lead Radar — экраны аутентификации и служебных состояний.

   Подключается ПОСЛЕ app.css и только дополняет его: токены, сброс,
   типографика и базовые кнопки/поля живут в app.css и здесь не переопределяются
   без нужды.

   Обслуживает:
     /login.php            — вход, регистрация, восстановление, 2FA;
     /invite.php           — приглашение в рабочее пространство;
     /reset.php            — смена пароля по ссылке;
     /verify.php           — подтверждение e-mail;
     /billing/return.php   — возврат из платёжной формы.

   CSP: никаких инлайновых стилей, внешних шрифтов и @import — только этот файл.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Базовый слой задаёт кнопкам и .button-link display:inline-flex, из-за чего
   авторские правила перебивают браузерное [hidden]{display:none} и элементы
   с атрибутом hidden остаются видимыми. На страницах входа это ломало бы
   переключение форм, поэтому возвращаем атрибуту его смысл.
   -------------------------------------------------------------------------- */
[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Общий фон: тот же градиент, что в макете 07-login.
   -------------------------------------------------------------------------- */

.auth-body {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--brand-softer) 0%, var(--brand-soft) 100%);
  background-attachment: fixed;
}

/* --------------------------------------------------------------------------
   Логотип
   -------------------------------------------------------------------------- */

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
  text-decoration: none;
}

.auth-brand:hover { color: var(--ink); text-decoration: none; }

.auth-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px rgba(35, 140, 223, .32);
}

.auth-brand-mark svg { display: block; }

/* --------------------------------------------------------------------------
   Экран входа: две колонки на градиенте
   -------------------------------------------------------------------------- */

.auth-screen {
  max-width: 1240px;
  margin: 0 auto;
  padding: 40px 24px 56px;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  grid-template-rows: auto 1fr;
  align-items: center;
  column-gap: 72px;
  row-gap: 48px;
}

/* Логотип занимает верхнюю строку целиком: так он остаётся в левом верхнем
   углу экрана, как в макете, и не исчезает при складывании колонок. */
.auth-screen-brand {
  grid-column: 1 / -1;
  grid-row: 1;
  align-self: start;
  justify-self: start;
  animation: lr-fade var(--t-slow) var(--ease-out) both;
}

/* Левая колонка — смысловая подводка. */
.auth-intro {
  grid-column: 1;
  grid-row: 2;
  animation: lr-fade-up var(--t-slow) var(--ease-out) both;
}

.auth-eyebrow { display: block; margin: 0 0 18px; }

.auth-headline {
  margin: 0;
  font-size: clamp(32px, 4.2vw, 54px);
  line-height: 1.1;
  letter-spacing: -.03em;
}

.auth-headline span { display: block; }

.auth-subline {
  margin: 28px 0 0;
  max-width: 44ch;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink-muted);
}

.auth-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin-top: 44px;
}

.auth-metric {
  flex: 1 1 180px;
  max-width: 220px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
  animation: lr-fade-up var(--t-slow) var(--ease-out) both;
}

.auth-metric:nth-child(1) { animation-delay: .12s; }
.auth-metric:nth-child(2) { animation-delay: .18s; }

.auth-metric:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.auth-metric-value {
  display: block;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
}

.auth-metric-label {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-muted);
}

.auth-version {
  margin: 34px 0 0;
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   Правая колонка — карточка формы
   -------------------------------------------------------------------------- */

.auth-card-wrap {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  padding: 36px 34px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  animation: lr-fade-up var(--t-slow) var(--ease-out) both;
  animation-delay: .06s;
}

.auth-card-head { margin-bottom: 26px; }

.auth-card-head h2 {
  margin: 0 0 6px;
  font-size: 27px;
  letter-spacing: -.025em;
}

.auth-status {
  margin: 0;
  min-height: 1.4em;
  font-size: 14px;
  color: var(--ink-muted);
}

/* Контейнер форм: мягкий кросс-фейд при переключении режимов. */
.auth-panes {
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.auth-panes.is-swapping {
  opacity: 0;
  transform: translateY(6px);
}

/* --------------------------------------------------------------------------
   Формы
   -------------------------------------------------------------------------- */

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form .note { margin: 0; }

.field { display: grid; gap: 7px; }

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

.field > label,
.field-head label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
  width: 100%;
  height: 52px;
  padding: 0 15px;
  border-radius: var(--r-md);
  font-size: 15px;
}

.auth-form input[readonly] {
  background: var(--surface-sunken);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: .04em;
}

/* Селектор совпадает по весу с правилом для input[type=...] выше и стоит
   позже — иначе размер кода перебивался общим правилом полей. */
.auth-form input.auth-code {
  font-family: var(--font-mono);
  font-size: 19px;
  letter-spacing: .38em;
  text-align: center;
}

.field-hint { margin: 0; font-size: 12.5px; }

.auth-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-muted);
}

.auth-check input { flex: none; margin-top: 2px; }
.auth-check a { color: var(--ink-muted); text-decoration: underline; }
.auth-check a:hover { color: var(--brand); }

/* Основная кнопка карточки — во всю ширину, высотой как поля. */
.auth-submit {
  width: 100%;
  height: 52px;
  margin-top: 6px;
  border-radius: var(--r-md);
  font-size: 15px;
}

button.is-busy::after {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lr-spin .7s linear infinite;
}

button.secondary.is-busy::after {
  border-color: var(--line-strong);
  border-top-color: var(--brand);
}

/* Кнопка, выглядящая как ссылка (переключение режимов, «Забыли пароль?»). */
.auth-link {
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  line-height: inherit;
  box-shadow: none;
}

.auth-link:hover {
  background: transparent;
  color: var(--brand-strong);
  text-decoration: underline;
  box-shadow: none;
}

.auth-link:active { transform: none; }

.auth-back { justify-self: start; font-size: 13px; }

#auth-error:empty { min-height: 0; }
#auth-error { margin: 14px 0 0; }

/* --------------------------------------------------------------------------
   «Вы уже в системе»
   -------------------------------------------------------------------------- */

.auth-signed { display: grid; gap: 14px; }

.auth-signed-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.auth-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
}

.auth-signed-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.auth-signed-id {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.auth-resend {
  width: 100%;
  min-height: 40px;
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   Разделитель и вторичный сценарий (приглашение в команду)
   -------------------------------------------------------------------------- */

.auth-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 24px 0 18px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  color: var(--ink-faint);
}

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

.auth-aside {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.auth-aside-icon { flex: none; color: var(--brand); line-height: 0; }

.auth-aside-title {
  margin: 0 0 3px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.auth-aside-text {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}

/* --------------------------------------------------------------------------
   Низ карточки
   -------------------------------------------------------------------------- */

.auth-card-foot {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  text-align: center;
}

.auth-switch {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.auth-legal {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-faint);
}

.auth-legal a { color: var(--ink-muted); text-decoration: underline; }
.auth-legal a:hover { color: var(--brand); }

/* --------------------------------------------------------------------------
   Узкие служебные страницы: приглашение, сброс пароля, подтверждение
   e-mail, возврат из платёжной формы.
   -------------------------------------------------------------------------- */

.auth-narrow {
  max-width: 560px;
  margin: 0 auto;
  padding: 40px 20px 56px;
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 26px;
}

.auth-narrow .auth-brand {
  animation: lr-fade var(--t-slow) var(--ease-out) both;
}

.state-card {
  width: 100%;
  padding: 34px 32px 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: lr-fade-up var(--t-slow) var(--ease-out) both;
  animation-delay: .05s;
}

.state-card h1 {
  margin: 0 0 10px;
  font-size: 25px;
  letter-spacing: -.025em;
}

.state-eyebrow { display: block; margin-bottom: 14px; }

.state-text {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-muted);
  min-height: 1.6em;
}

.state-hint {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-muted);
}

.state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.state-actions button,
.state-actions .button-link,
.state-actions .btn {
  min-height: 44px;
  padding: 0 20px;
}

/* Пока все кнопки состояния скрыты, ряд не должен занимать вертикальный
   ритм карточки. Браузеры без :has() просто оставят отступ — не критично. */
.state-actions:not(:has(> :not([hidden]))) { display: none; }

.state-form {
  display: grid;
  gap: 16px;
  margin-top: 22px;
  text-align: left;
}

.state-error { margin: 14px 0 0; }

.state-foot {
  margin: 0;
  font-size: 12px;
  color: var(--ink-faint);
  text-align: center;
}

.state-foot a { color: var(--ink-muted); text-decoration: underline; }

/* Иконка состояния: все три глифа лежат в разметке, видимый выбирается
   атрибутом data-state — так JS обходится без создания SVG и без innerHTML. */
.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: var(--r-pill);
  background: var(--brand-soft);
  color: var(--brand);
  animation: lr-fade var(--t) var(--ease-out) both;
}

.status-glyph { display: none; }

.status-icon[data-state="pending"] { background: var(--brand-soft); color: var(--brand); }
.status-icon[data-state="pending"] .status-glyph-pending {
  display: block;
  animation: lr-spin 1.1s linear infinite;
}

.status-icon[data-state="success"] { background: var(--green-soft); color: var(--green); }
.status-icon[data-state="success"] .status-glyph-success { display: block; }

.status-icon[data-state="error"] { background: var(--red-soft); color: var(--red); }
.status-icon[data-state="error"] .status-glyph-error { display: block; }

/* --------------------------------------------------------------------------
   Адаптив. Колонки складываются так, чтобы форма оставалась первой.
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .auth-screen { column-gap: 44px; row-gap: 36px; }
}

/* Колонки складываются: логотип, затем форма, затем левый блок. */
@media (max-width: 980px) {
  .auth-screen {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    max-width: 520px;
    row-gap: 30px;
    padding: 28px 18px 44px;
    /* Все три строки auto: без этого свободная высота растянула бы их
       по экрану и между блоками появились бы огромные провалы. */
    align-content: start;
  }
  .auth-screen-brand { grid-column: 1; grid-row: 1; justify-self: center; }
  .auth-card-wrap { grid-column: 1; grid-row: 2; }
  .auth-intro { grid-column: 1; grid-row: 3; }
  .auth-headline { font-size: clamp(26px, 7vw, 34px); }
  .auth-subline { margin-top: 18px; font-size: 15px; }
  .auth-metrics { margin-top: 26px; gap: 12px; }
  .auth-metric { flex: 1 1 140px; max-width: none; padding: 14px 16px; }
  .auth-metric-value { font-size: 22px; }
  .auth-version { margin-top: 22px; }
}

/* Низкий экран (например, телефон в альбомной ориентации): центрирование по
   высоте увело бы верх карточки за границу окна, поэтому прижимаем к началу. */
@media (max-height: 720px) {
  .auth-narrow { align-content: start; }
}

@media (max-width: 640px) {
  .auth-card { padding: 26px 20px 22px; border-radius: var(--r-xl); }
  .auth-card-head h2 { font-size: 23px; }
  .auth-headline span { display: inline; }
  .state-card { padding: 26px 20px 24px; border-radius: var(--r-xl); }
  .state-card h1 { font-size: 21px; }
  .state-actions button,
  .state-actions .button-link,
  .state-actions .btn { width: 100%; }
  .auth-narrow { padding: 26px 16px 40px; gap: 20px; }
}
