/*
 * Center.Identity — self-contained theme.
 *
 * No external fonts or stylesheets: the default Content-Security-Policy is `default-src 'self'`, and the
 * sign-in page is the last place that should be phoning a third party. Colours are declared as custom
 * properties so `Identity:Ui:AccentColor` (injected inline by the layout) and the theme toggle can override
 * them without a rebuild.
 */

:root {
    --accent: #4f46e5;
    --accent-contrast: #ffffff;

    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-alt: #f0f1f6;
    --border: #d6d8e3;
    --text: #16181f;
    --text-muted: #565b6b;

    --danger: #b3261e;
    --danger-bg: #fdecea;
    --info: #1f5fa9;
    --info-bg: #e8f1fb;
    --success: #1c6c3c;
    --success-bg: #e7f5ec;

    --radius: 10px;
    --shadow: 0 1px 2px rgb(16 18 31 / 6%), 0 8px 24px rgb(16 18 31 / 8%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101218;
        --surface: #181b23;
        --surface-alt: #1f232d;
        --border: #333846;
        --text: #e9eaf0;
        --text-muted: #a2a8ba;

        /*
            Акцент светлеет вместе с темой.

            Тёмно-индиговый #4f46e5 на почти чёрном фоне даёт контраст 2.74 при норме 4.5 — то есть «Забыли
            пароль?» и «Создать учётную запись» на странице входа нечитаемы у всех, у кого система в тёмной
            теме. Переменная была объявлена только в светлом блоке, и тёмный молча наследовал её.
        */
        --accent: #a5b4fc;
        --accent-contrast: #10131c;

        --danger: #f2b8b5;
        --danger-bg: #3a1d1b;
        --info: #a8c8ee;
        --info-bg: #16263a;
        --success: #a6d9bb;
        --success-bg: #16301f;

        --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 45%);
    }
}

/* Explicit override always wins over the media query, in both directions. */
:root[data-theme="light"] {
    /* Акцент тоже: без него переключатель темы менял фон и оставлял ссылки от прежней. */
    --accent: #4f46e5;
    --accent-contrast: #ffffff;

    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-alt: #f0f1f6;
    --border: #d6d8e3;
    --text: #16181f;
    --text-muted: #565b6b;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --info: #1f5fa9;
    --info-bg: #e8f1fb;
    --success: #1c6c3c;
    --success-bg: #e7f5ec;
}

:root[data-theme="dark"] {
    --bg: #101218;
    --surface: #181b23;
    --surface-alt: #1f232d;
    --border: #333846;
    --text: #e9eaf0;
    --text-muted: #a2a8ba;
    --danger: #f2b8b5;
    --danger-bg: #3a1d1b;
    --info: #a8c8ee;
    --info-bg: #16263a;
    --success: #a6d9bb;
    --success-bg: #16301f;
}

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

html, body { height: 100%; }

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    padding: .6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.skip-link:focus { left: 1rem; top: 1rem; z-index: 10; }

/* ---------------------------------------------------------------- chrome */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: .6rem; }
.brand-logo { height: 28px; width: auto; }
.brand-name { font-weight: 600; color: var(--text); }

.site-nav { display: flex; align-items: center; gap: .85rem; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    width: 2rem;
    height: 2rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.site-main {
    flex: 1 0 auto;
    width: 100%;
    max-width: 62rem;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    padding: 1.25rem;
    color: var(--text-muted);
    font-size: .875rem;
    border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------ cards */

.auth-card {
    max-width: 27rem;
    margin: 0 auto;
    padding: 1.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.auth-card.wide { max-width: 42rem; }

.auth-title {
    margin: 0 0 1.25rem;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.25;
}

.auth-card h2.auth-title { margin-top: 1.75rem; font-size: 1.05rem; }

/* ------------------------------------------------------------------ forms */

.field { margin-bottom: 1rem; }

.field-label {
    display: block;
    margin-bottom: .35rem;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
}

.field-input,
.field select,
.field textarea {
    width: 100%;
    padding: .6rem .7rem;
    font: inherit;
    color: var(--text);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.field-input:focus { border-color: var(--accent); }

.field input[type="checkbox"] { margin-right: .45rem; }

.field .field-label:has(input[type="checkbox"]) { font-weight: 400; }

.field span.field-validation-error,
.field-validation-error {
    display: block;
    margin-top: .3rem;
    color: var(--danger);
    font-size: .85rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .6rem 1.1rem;
    font: inherit;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: filter .12s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .btn { transition: none; }
}

.btn:hover { filter: brightness(1.06); }

.btn-primary { background: var(--accent); color: var(--accent-contrast); width: 100%; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

.link-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1.1rem;
    font-size: .9rem;
}

/* ----------------------------------------------------------------- alerts */

.alert {
    padding: .75rem .9rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: .92rem;
}

.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }

/* -------------------------------------------------------------- providers */

.provider-list { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .5rem; }

.provider-button {
    flex: 1 1 10rem;
    padding: .6rem 1rem;
    font: inherit;
    color: var(--text);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

/* ---------------------------------------------------------------- consent */

.scope-list { list-style: none; margin: 1rem 0; padding: 0; }

.scope-item {
    padding: .7rem .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: .5rem;
    background: var(--surface-alt);
}

.scope-item strong { display: block; font-size: .95rem; }
.scope-item span { color: var(--text-muted); font-size: .85rem; }

.consent-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.consent-actions .btn { flex: 1; }

/* ----------------------------------------------------------------- manage */

.manage-layout { display: grid; grid-template-columns: 14rem 1fr; gap: 1.5rem; align-items: start; }

.manage-nav { display: flex; flex-direction: column; gap: .2rem; }

.manage-nav a {
    padding: .5rem .7rem;
    border-radius: 8px;
    color: var(--text);
}

.manage-nav a:hover { background: var(--surface-alt); text-decoration: none; }
.manage-nav a.active { background: var(--accent); color: var(--accent-contrast); }

@media (max-width: 48rem) {
    .manage-layout { grid-template-columns: 1fr; }
    .manage-nav { flex-direction: row; flex-wrap: wrap; }
}

.code-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: .5rem;
    margin: 1rem 0;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.code-grid code {
    display: block;
    padding: .5rem;
    text-align: center;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.qr {
    display: block;
    width: min(14rem, 60vw);
    height: auto;
    margin: 1rem auto;
    padding: .75rem;
    background: #ffffff;
    border-radius: 8px;
}

.data-list { margin: 0; }
.data-list dt { font-size: .82rem; color: var(--text-muted); margin-top: .75rem; }
.data-list dd { margin: .15rem 0 0; word-break: break-word; }

.session-item {
    padding: .8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: .6rem;
    background: var(--surface-alt);
}

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); text-align: left; }

.table-scroll { overflow-x: auto; }

/* --- Путь обратно в приложение ---
   Без этих ссылок сервер идентификации — тупик: зарегистрировался, оказался в профиле и вернуться некуда. */
.site-app-link {
    padding: .3rem .7rem;
    border: 1px solid var(--border, #d4d4d8);
    border-radius: 999px;
    font-size: .9rem;
    text-decoration: none;
}

.site-app-link:hover { border-color: var(--accent); color: var(--accent); }

.app-list { list-style: none; margin: 1.2rem 0; padding: 0; display: grid; gap: .6rem; }

.app-list li {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    flex-wrap: wrap;
    padding: .75rem 1rem;
    border: 1px solid var(--border, #d4d4d8);
    border-radius: .6rem;
}

.app-link { font-weight: 600; text-decoration: none; }
.app-link:hover { color: var(--accent); }
.app-desc { font-size: .88rem; opacity: .75; }

/* ---------------------------------------------------------------------------------------------------
   Цели нажатия
   ---------------------------------------------------------------------------------------------------
   WCAG 2.2 называет нижней границей 24 пикселя, и не из вежливости: попадание пальцем на телефоне и
   попадание мышью при треморе считаются одинаково. Строчная ссылка высотой 22 и галочка 13×13 — это цели,
   в которые промахиваются, а промах на странице входа означает ещё одну попытку ввести пароль.
*/
.auth-links a,
.auth-card a:not(.btn),
.site-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding-block: 3px;
}

/* ------------------------------------------------------------- build stamp */

/*
    The build stamp in the footer: version, engine and environment of this deployment. Collapsed it is one
    short line among the footer links; the details open upwards so the footer does not grow. Restrained in
    production — dimmed, version only — but never absent.
*/
.build-stamp { position: relative; }

.build-stamp summary {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding-block: 3px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    white-space: nowrap;
}

.build-stamp summary::-webkit-details-marker { display: none; }

.build-stamp summary:hover,
.build-stamp[open] summary { color: var(--text); }

.build-stamp dl {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 10;
    min-width: 16rem;
    margin: 0;
    padding: .625rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .375rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: left;
}

.build-stamp dl > div { display: flex; justify-content: space-between; gap: 1.25rem; }
.build-stamp dt { color: var(--text-muted); }
.build-stamp dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }

.build-stamp-quiet { opacity: .7; }

/*
    С !important и flex: none — потому что правило ниже по файлу задаёт всем полям в форме `width: 100%`,
    и галочка внутри такой формы получала 14 пикселей в ширину против заданных 20. Побеждать это
    специфичностью пришлось бы селектором, который переживёт следующую правку хуже.
*/
input[type="checkbox"],
input[type="radio"] {
    width: 20px !important;
    height: 20px;
    flex: none;
    accent-color: var(--accent);
}

/* Подпись входит в нажимаемую область: целиться в саму галочку не нужно ни пальцем, ни мышью. */
label:has(input[type="checkbox"]),
label:has(input[type="radio"]) {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 32px;
    cursor: pointer;
}
