/* color-scheme обязан следовать за выбранной темой, а не за системной:
   иначе браузер красит холст под <body> чёрным и он просвечивает по краям. */
:root {
    color-scheme: light;

    --auth-page: #f4f5f7;
    --auth-card: #ffffff;
    --auth-border: #e4e7ec;
    --auth-card-shadow: 0 12px 32px rgba(16, 24, 40, 0.08);
    --auth-title: #101828;
    --auth-label: #344054;
    --auth-muted: #667085;
    --auth-field: #ffffff;
    --auth-field-border: #d0d5dd;
    --auth-placeholder: #98a2b3;
    --auth-accent: #238653;
    --auth-accent-hover: #176b42;
    --auth-accent-ring: rgba(35, 134, 83, 0.18);
    --auth-flash-bg: #fef3f2;
    --auth-flash-border: #fecdca;
    --auth-flash-text: #b42318;
    --auth-logo-filter: none;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) {
        color-scheme: dark;

        --auth-page: #121212;
        --auth-card: #1e1e24;
        --auth-border: #333333;
        --auth-card-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
        --auth-title: #f5f5f5;
        --auth-label: #d0d0d0;
        --auth-muted: #909090;
        --auth-field: #26262a;
        --auth-field-border: #444444;
        --auth-placeholder: #7a7a7a;
        --auth-accent: #2c9a63;
        --auth-accent-hover: #35b073;
        --auth-accent-ring: rgba(44, 154, 99, 0.28);
        --auth-flash-bg: #3a1d1b;
        --auth-flash-border: #6b2f2a;
        --auth-flash-text: #f5a3a0;
        --auth-logo-filter: invert(1);
    }
}

html[data-theme='dark'] {
    color-scheme: dark;

    --auth-page: #121212;
    --auth-card: #1e1e24;
    --auth-border: #333333;
    --auth-card-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --auth-title: #f5f5f5;
    --auth-label: #d0d0d0;
    --auth-muted: #909090;
    --auth-field: #26262a;
    --auth-field-border: #444444;
    --auth-placeholder: #7a7a7a;
    --auth-accent: #2c9a63;
    --auth-accent-hover: #35b073;
    --auth-accent-ring: rgba(44, 154, 99, 0.28);
    --auth-flash-bg: #3a1d1b;
    --auth-flash-border: #6b2f2a;
    --auth-flash-text: #f5a3a0;
    --auth-logo-filter: invert(1);
}

body {
    margin: 0;
    background-color: var(--auth-page);
    font-family: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.auth {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 1.5rem;
}

.auth-card {
    box-sizing: border-box;
    width: 100%;
    max-width: 25rem;
    padding: 2.5rem 2rem;
    background-color: var(--auth-card);
    border: 1px solid var(--auth-border);
    border-radius: 1rem;
    box-shadow: var(--auth-card-shadow);
}

.auth-logo {
    display: block;
    width: 12rem;
    max-width: 75%;
    height: auto;
    margin: 0 auto 1.5rem;
    filter: var(--auth-logo-filter);
}

.auth-title {
    margin: 0 0 1.75rem;
    color: var(--auth-title);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-align: center;
}

.auth-flash {
    margin: 0 0 1.25rem;
    padding: 0.7rem 0.9rem;
    color: var(--auth-flash-text);
    background-color: var(--auth-flash-bg);
    border: 1px solid var(--auth-flash-border);
    border-radius: 0.625rem;
    font-size: 0.95rem;
    text-align: center;
}

.auth-form,
.auth-secret {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.auth-label {
    color: var(--auth-label);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.auth-control {
    position: relative;
    display: flex;
    align-items: center;
}

.auth-icon {
    position: absolute;
    left: 0.9rem;
    width: 1.25rem;
    height: 1.25rem;
    color: var(--auth-muted);
    pointer-events: none;
}

.auth-input {
    box-sizing: border-box;
    width: 100%;
    height: 3rem;
    padding: 0 1rem 0 2.85rem;
    color: var(--auth-title);
    background-color: var(--auth-field);
    border: 1px solid var(--auth-field-border);
    border-radius: 0.625rem;
    outline: 0;
    font-family: inherit;
    font-size: 1rem;
    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

.auth-input::placeholder {
    color: var(--auth-placeholder);
}

.auth-input:focus {
    border-color: var(--auth-accent);
    box-shadow: 0 0 0 4px var(--auth-accent-ring);
}

/* Автозаполнение в WebKit перекрашивает поле в свой жёлтый фон. */
.auth-input:-webkit-autofill,
.auth-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--auth-title);
    box-shadow: 0 0 0 1000px var(--auth-field) inset;
    transition: background-color 5000s ease-in-out 0s;
}

.auth-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-sizing: border-box;
    width: 100%;
    height: 3rem;
    margin-top: 0.25rem;
    color: #ffffff;
    background-color: var(--auth-accent);
    border: 0;
    border-radius: 0.625rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    transition:
        background-color 0.18s ease,
        box-shadow 0.18s ease,
        transform 0.18s ease;
}

.auth-submit:hover {
    background-color: var(--auth-accent-hover);
    box-shadow: 0 4px 12px var(--auth-accent-ring);
}

.auth-submit:active {
    transform: translateY(1px);
    box-shadow: none;
}

.auth-submit > svg {
    width: 1rem;
    height: 1rem;
    transition: transform 0.18s ease;
}

.auth-submit:hover > svg {
    transform: translateX(3px);
}

.auth-passkey {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.25rem;
}

/* Браузерное [hidden] { display: none } живёт в UA-стилях с нулевой
   специфичностью, поэтому display:flex выше его перебивает: без этого правила
   блок оставался на экране там, где биометрии нет. */
.auth-passkey[hidden],
.auth-passkey-status[hidden] {
    display: none;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--auth-muted);
    font-size: 0.8rem;
}

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

.auth-passkey-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    box-sizing: border-box;
    width: 100%;
    height: 3rem;
    color: var(--auth-accent);
    background-color: transparent;
    border: 1px solid var(--auth-accent);
    border-radius: 0.625rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    transition:
        background-color 0.18s ease,
        box-shadow 0.18s ease;
}

.auth-passkey-button > svg {
    width: 1.35rem;
    height: 1.35rem;
}

.auth-passkey-button:hover:not(:disabled) {
    background-color: var(--auth-accent-ring);
    box-shadow: 0 4px 12px var(--auth-accent-ring);
}

.auth-passkey-button:disabled {
    opacity: 0.55;
    cursor: progress;
}

.auth-passkey-status {
    margin: 0;
    color: var(--auth-flash-text);
    font-size: 0.9rem;
    text-align: center;
}

/* Без JS оба поля видны сразу — форма остаётся рабочей. */
html.js .auth-secret {
    display: none;
}

html.js .auth-secret.is-visible {
    display: flex;
    animation: auth-reveal 0.26s ease both;
}

@keyframes auth-reveal {
    from {
        opacity: 0;
        transform: translateY(-0.4rem);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.js .auth-secret.is-visible {
        animation: none;
    }

    .auth-submit,
    .auth-submit > svg {
        transition: none;
    }
}

@media (max-width: 30rem) {
    .auth {
        padding: 1rem;
    }

    .auth-card {
        padding: 2rem 1.25rem;
    }
}
