/* Auth: композиция карточек входа, регистрации и восстановления доступа. */

/* Каркас страницы */
body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    margin: 0;
}

#auth {
    min-height: 100dvh;
    box-sizing: border-box;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: clamp(90px, 12vh, 112px) clamp(10px, 4vw, 16px) clamp(24px, 6vh, 60px);
    width: 100%;
}

/* Карточка формы */
.auth-form-card {
    width: 100%;
    max-width: 480px;
    margin-block: auto;
    background-color: transparent;
    border: 1px solid var(--border);
    border-radius: clamp(16px, 4vw, 24px);
    padding: clamp(16px, 5vw, 40px);
    opacity: 0;
    animation: authFadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    box-sizing: border-box;
}

.form-header {
    padding-bottom: clamp(18px, 4vw, 28.8px);
    margin-bottom: clamp(20px, 4vw, 28.8px);
    border-bottom: 1px solid var(--border-light);
    text-align: center;
}

.form-header :is(h1, h2) {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: clamp(1.75rem, 5vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
}

.form-header p {
    max-width: 600px;
    margin: 0 auto;
    color: var(--text-secondary);
    font-size: 1.05rem;
    text-align: center;
}

/* Поля */
.field {
    display: block;
    width: 100%;
}

.auth-form-card > .field {
    margin-bottom: 0.2rem;
}

.input-with-icon {
    position: relative;
    display: block;
    width: 100%;
}

.input-with-icon input {
    width: 100%;
    height: 52px;
    padding: 0 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.password-wrapper {
    display: block;
}

.password-wrapper .input-with-icon input {
    padding-right: 64px;
}

.password-wrapper input[type="password"]::-ms-reveal,
.password-wrapper input[type="password"]::-ms-clear {
    display: none;
    width: 0;
    height: 0;
}

/* Ошибки чекбоксов */
.checkbox input.invalid-field + .box {
    border-color: var(--error);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--error) 18%, transparent);
}

.checkbox input:focus-visible + .box {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* Действия формы */
.auth-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 28px;
    gap: 12px;
    flex-wrap: nowrap;
}

#loginForm > .password-wrapper {
    margin-bottom: 8px;
}

#loginForm .auth-actions {
    margin-bottom: 0;
    padding-inline: 5px;
}

.checkbox.remember {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.checkbox.remember input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox.remember .box {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--control-bg);
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
}

.checkbox.remember .box::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #ffffff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity 0.2s;
}

.checkbox.remember input:checked + .box {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox.remember input:checked + .box::after {
    opacity: 1;
}

.checkbox.remember .label-text {
    color: var(--text-secondary);
    font-size: clamp(0.85rem, calc(0.82rem + 0.12vw), 0.9rem);
    white-space: nowrap;
}

.forgot-link {
    color: var(--text-muted);
    font-size: clamp(0.85rem, calc(0.82rem + 0.12vw), 0.9rem);
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
    margin-left: auto;
}

.forgot-link:hover {
    color: var(--accent-hover);
}

.auth-submit {
    width: 100%;
    height: 52px;
    padding: 0.85rem;
    margin-top: 0.9rem;
    border-radius: 12px;
    font-size: 1rem;
    cursor: pointer;
}

#loginForm .auth-submit {
    margin-top: 20px;
}

.auth-submit[data-loading="true"],
.resend-link[data-loading="true"] {
    cursor: wait;
}

.auth-submit[data-loading="true"]::after,
.resend-link[data-loading="true"]::after {
    content: '';
    display: inline-block;
    width: 0.8em;
    height: 0.8em;
    margin-inline-start: 0.55em;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: 50%;
    vertical-align: -0.08em;
    animation: authLoadingSpin 0.7s linear infinite;
}

.auth-status {
    min-height: 1.4em;
    margin: 0.75rem 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.4;
    text-align: center;
}

.auth-status:empty:not([data-state]) {
    display: none;
}

.auth-status[data-state="loading"] {
    color: var(--text-muted);
}

.auth-status[data-state="error"] {
    color: var(--error);
}

.auth-status[data-state="success"] {
    display: grid;
    justify-items: center;
    gap: 0.45rem;
    min-height: 0;
    margin-block: 1rem 0.25rem;
    padding-block: 0.35rem;
    color: var(--text-secondary);
    animation: authResultIn 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.auth-result-marker {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 0.35rem color-mix(in srgb, var(--accent) 13%, transparent);
}

.auth-result-title {
    color: var(--text-primary);
    font-size: 1.05rem;
    line-height: 1.25;
}

.auth-result-text {
    max-width: 34ch;
}

.auth-result-action {
    margin-block-start: 0.25rem;
    color: var(--accent);
    font-weight: 650;
    text-decoration: none;
}

.auth-result-action:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.auth-result-action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 3px;
}

.auth-form-card[data-auth-terminal-form] > :not([data-auth-status]) {
    transition:
        opacity 180ms ease,
        transform 180ms ease,
        visibility 0s linear 180ms;
}

.auth-form-card[data-auth-terminal-form][data-auth-complete="true"] {
    position: relative;
    display: grid;
    min-height: var(--auth-completion-height);
    place-items: center;
}

.auth-form-card[data-auth-terminal-form][data-auth-complete="true"] > :not([data-auth-status]) {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px);
}

.auth-form-card[data-auth-terminal-form][data-auth-complete="true"] > [data-auth-status] {
    display: grid;
    justify-items: center;
    width: 100%;
    max-width: 34ch;
    margin: 0;
    padding: 0;
    text-align: center;
    animation-duration: 240ms;
}

.auth-form-card[data-auth-terminal-form][data-auth-complete="true"] .auth-result-title {
    font-size: clamp(1.35rem, 4vw, 1.5rem);
}

@keyframes authLoadingSpin {
    to { transform: rotate(1turn); }
}

@keyframes authResultIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .auth-form-card[data-auth-terminal-form] > :not([data-auth-status]) {
        transition: none;
    }

    .auth-status[data-state="success"],
    .auth-submit[data-loading="true"]::after,
    .resend-link[data-loading="true"]::after {
        animation: none;
    }
}

.welcome-login {
    margin-top: 18px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    text-align: center;
}

.welcome-login a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.welcome-login a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.resend-feedback {
    display: block;
    margin-block-start: 0.45rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.resend-feedback:empty:not([data-state]) {
    display: none;
}

.resend-feedback[data-state="error"] {
    color: var(--error);
}

.resend-feedback[data-state="success"] {
    color: var(--accent);
}

/* Ввод кода */
.code-inputs {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    max-width: 360px;
    margin: 0 auto 0 auto;
}

.code-digit {
    flex: 1 1 46px;
    max-width: 46px;
    min-width: 0;
    height: 52px;
    padding: 0;
    background: var(--control-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    outline: none;
    -moz-appearance: none;
    appearance: none;
}

.code-digit:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.code-digit::-webkit-outer-spin-button,
.code-digit::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.verify-email {
    color: var(--text-primary);
    font-weight: 600;
    word-break: break-all;
}

.resend-timer {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-left: 4px;
}

.resend-link.disabled {
    color: var(--text-muted);
    pointer-events: none;
    cursor: default;
    text-decoration: none;
}

/* Согласие */
.compliance-field {
    margin-bottom: 0px;
    width: 100%;
}

.compliance-note {
    margin: 8px 0 0 32px;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.compliance-note a {
    color: var(--accent);
    text-decoration: none;
}

.compliance-note a:hover {
    text-decoration: underline;
}

.checkbox.terms-agreement {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    width: 100%;
}

.checkbox.terms-agreement input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox.terms-agreement .box {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--control-bg);
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
    margin-top: 2px;
}

.checkbox.terms-agreement .box::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #ffffff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    opacity: 0;
    transition: opacity 0.2s;
}

.checkbox.terms-agreement input:checked + .box {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox.terms-agreement input:checked + .box::after {
    opacity: 1;
}

.checkbox.terms-agreement .label-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.4;
}

.checkbox.terms-agreement .label-text a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.checkbox.terms-agreement .label-text a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Пароль */
.password-checklist {
    margin: 2px 0 16px;
}

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

.password-checklist li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.15;
}

.password-checklist .check-icon {
    position: relative;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
    border-radius: 50%;
    background: transparent;
    flex: 0 0 14px;
}

.password-checklist .check-icon::after {
    position: absolute;
    inset: 2px;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    content: '';
    opacity: 0;
}

.password-checklist li.met {
    color: var(--text-secondary);
}

.password-checklist li.met .check-icon {
    border-color: var(--accent);
    background: transparent;
}

.password-checklist li.met .check-icon::after {
    opacity: 1;
}

.password-checklist li.invalid .check-icon {
    border-color: var(--error);
    background: transparent;
}

.password-toggle {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 9px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.password-toggle svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.password-toggle .eye-visible,
.password-toggle[aria-pressed="true"] .eye-hidden {
    display: none;
}

.password-toggle[aria-pressed="true"] .eye-visible {
    display: block;
}

.password-toggle[aria-pressed="true"] {
    color: var(--accent);
}

.password-wrapper .input-with-icon input.invalid-field + .password-toggle {
    color: var(--error);
}

.password-toggle:hover {
    background: color-mix(in srgb, currentColor 8%, transparent);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Анимация */
@keyframes authFadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Адаптивная компоновка */
.forgot-link-short {
    display: none;
}

@media (max-width: 560px) {
    .auth-form-card {
        border: 0;
        border-radius: 0;
    }
}

@media (max-width: 354px) {
    .forgot-link-full {
        display: none;
    }

    .forgot-link-short {
        display: inline;
    }
}

.checkbox.terms-agreement input.invalid-field ~ .label-text {
    color: var(--error);
}
