:root {
  color-scheme: light dark;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;

  /* Colours by role; the dark theme below follows the device setting. The
     realm's brand color (theme.css: --brand, --brand-contrast) replaces the
     accent; without it the accent is the product's neutral slate: a dark
     button on the light theme, a light one on the dark theme. */
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --surface-hover: #e2e8f0;
  --surface-subtle: #f8fafc;
  --tab-active: #ffffff;
  --text: #111827;
  --text-strong: #09090b;
  --text-label: #1f2937;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --text-control: #334155;
  --border: #e2e8f0;
  --border-input: #cbd5e1;
  --accent: var(--brand, #334155);
  --accent-ring: rgba(51, 65, 85, 0.13);
  --accent-outline: rgba(51, 65, 85, 0.25);
  --accent-text: #1e293b;
  --accent-soft: #f1f5f9;
  --accent-wash: #f8fafc;
  --accent-border: #cbd5e1;
  --button: var(--brand, #1e293b);
  --button-hover: #0f172a;
  --on-button: var(--brand-contrast, #ffffff);
  --danger: #dc2626;
  --danger-ring: rgba(220, 38, 38, 0.10);
  --error-text: #b91c1c;
  --error-bg: #fef2f2;
  --info-text: #2563eb;
  --info-bg: #eff6ff;
  --warn-text: #b45309;
  --warn-bg: #fffbeb;
  --card-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  --tab-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0f;
    --surface: #17171b;
    --surface-muted: #232329;
    --surface-hover: #2e2e36;
    --surface-subtle: #1e1e23;
    --tab-active: #34343c;
    --text: #e4e4e7;
    --text-strong: #fafafa;
    --text-label: #d4d4d8;
    --text-secondary: #a1a1aa;
    --text-muted: #9a9aa4;
    --text-faint: #71717a;
    --text-control: #d4d4d8;
    --border: #2e2e36;
    --border-input: #3f3f48;
    --accent: var(--brand, #cbd5e1);
    --accent-ring: rgba(203, 213, 225, 0.25);
    --accent-outline: rgba(203, 213, 225, 0.45);
    --accent-text: #e2e8f0;
    --accent-soft: rgba(148, 163, 184, 0.18);
    --accent-wash: rgba(148, 163, 184, 0.08);
    --accent-border: rgba(148, 163, 184, 0.45);
    --button: var(--brand, #e2e8f0);
    --button-hover: #f8fafc;
    --on-button: var(--brand-contrast, #111827);
    --danger: #f87171;
    --danger-ring: rgba(248, 113, 113, 0.18);
    --error-text: #fca5a5;
    --error-bg: rgba(239, 68, 68, 0.13);
    --info-text: #93c5fd;
    --info-bg: rgba(59, 130, 246, 0.14);
    --warn-text: #fcd34d;
    --warn-bg: rgba(245, 158, 11, 0.14);
    /* A shadow is lost on a dark page: the card gets a hairline instead. */
    --card-shadow: 0 0 0 1px #26262d;
    --tab-shadow: none;
  }
}

/* A realm with a brand color (class "branded", theme.css): the shades of the
   accent follow the color. A browser without color-mix() keeps the button
   still on hover and the built-in rings. */
:root.branded { --button-hover: var(--brand); }

@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root.branded {
    --button-hover: color-mix(in srgb, var(--brand) 88%, #000000);
    --accent-ring: color-mix(in srgb, var(--brand) 13%, transparent);
    --accent-outline: color-mix(in srgb, var(--brand) 25%, transparent);
    --accent-text: color-mix(in srgb, var(--brand) 75%, var(--text));
    --accent-soft: color-mix(in srgb, var(--brand) 14%, var(--surface));
    --accent-wash: color-mix(in srgb, var(--brand) 6%, var(--surface));
    --accent-border: color-mix(in srgb, var(--brand) 45%, var(--surface));
  }

  @media (prefers-color-scheme: dark) {
    :root.branded {
      --button-hover: color-mix(in srgb, var(--brand) 85%, #ffffff);
      --accent-ring: color-mix(in srgb, var(--brand) 25%, transparent);
      --accent-outline: color-mix(in srgb, var(--brand) 45%, transparent);
      --accent-soft: color-mix(in srgb, var(--brand) 18%, var(--surface));
      --accent-wash: color-mix(in srgb, var(--brand) 8%, var(--surface));
    }
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 448px;
  padding: 40px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

/* The account pages (profile, sessions) hold lists and more fields. */
.account-card { max-width: 520px; }

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.45px;
}

/* The realm's logo in place of the icon and the name. */
.brand-logo picture { display: block; }
.brand-logo img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 40px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

h1 {
  margin: 0 0 26px;
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
}

form { margin: 0; }

.field { margin-bottom: 20px; }

label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-label);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 15px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input::placeholder { color: var(--text-faint); }

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

.field-error {
  display: none;
  margin-top: 6px;
  color: var(--danger);
  font-size: 13px;
  line-height: 18px;
}

input:user-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-ring);
}

input:user-invalid + .field-error { display: block; }

/* A password field with the eye button that shows what was typed (app.js). */
.password-input { position: relative; }
.password-input input { padding-right: 52px; }
.password-input input::-ms-reveal { display: none; }

.password-toggle {
  position: absolute;
  top: 5px;
  right: 5px;
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-muted);
  background: transparent;
}

.password-toggle[hidden] { display: none; }
.password-toggle:hover { color: var(--text-control); background: var(--surface-muted); }
.password-toggle:active { transform: none; }
.password-toggle-hide, .password-toggle[aria-pressed="true"] .password-toggle-show { display: none; }
.password-toggle[aria-pressed="true"] .password-toggle-hide { display: block; }

.form-error {
  margin: -8px 0 20px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--error-text);
  background: var(--error-bg);
  font-size: 14px;
  line-height: 18px;
}

.notice {
  min-height: 36px;
  margin: 0 0 20px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--info-text);
  background: var(--info-bg);
  font-size: 14px;
  line-height: 18px;
}

button {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 8px;
  color: var(--on-button);
  background: var(--button);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms ease, transform 80ms ease;
}

button:hover { background: var(--button-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 3px solid var(--accent-outline); outline-offset: 2px; }

.primary-link {
  display: flex;
  width: 100%;
  height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--on-button);
  background: var(--button);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

.primary-link:hover { background: var(--button-hover); }
.primary-link:focus-visible { outline: 3px solid var(--accent-outline); outline-offset: 2px; }

.back-link {
  display: block;
  width: fit-content;
  margin: 20px auto 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}

.back-link:hover { color: var(--text-control); text-decoration: underline; }
.back-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.subtitle {
  color: var(--text-muted);
  font-weight: 500;
}

.intro {
  margin: -14px 0 22px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 18px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin: -8px 0 22px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-muted);
}

.tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
}

.tab:hover { color: var(--text-strong); }
.tab.active { color: var(--text-strong); background: var(--tab-active); box-shadow: var(--tab-shadow); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The profile page (/account/profile) and the required attributes page. */

.profile-data {
  display: grid;
  gap: 10px;
  margin: 0;
}

.profile-data div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  font-size: 14px;
  line-height: 20px;
}

.profile-data dt { color: var(--text-muted); }
.profile-data dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.profile-data-hint { margin: 10px 0 0; }
/* The email the user sets himself (self_confirmed) follows the read-only data. */
.profile-data-hint + .compact-form { margin-top: 20px; }
.muted { color: var(--text-faint); }

.section-title {
  margin: 22px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.required-mark {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--warn-text);
  background: var(--warn-bg);
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  vertical-align: 1px;
}

fieldset.field {
  min-width: 0;
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 7px;
  padding: 0;
  color: var(--text-label);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.choice-row { display: flex; flex-wrap: wrap; gap: 8px 22px; }

.choice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
}

.choice input {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  box-shadow: none;
  accent-color: var(--button);
}

.field-message {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 18px;
}

input[aria-invalid="true"] { border-color: var(--danger); }

.secondary-button { margin-top: 10px; color: var(--text-control); background: var(--surface-muted); }
.secondary-button:hover { background: var(--surface-hover); }

/* The profile form: compact fields, there can be many of them. */

.compact-form .field, .compact-form fieldset.field { margin-bottom: 14px; }
.compact-form label, .compact-form legend { margin-bottom: 4px; font-size: 13px; }
.compact-form input { height: 38px; padding: 0 12px; font-size: 14px; border-radius: 7px; }
.compact-form .choice { font-size: 14px; }
.compact-form .choice input { width: 16px; height: 16px; padding: 0; }
.compact-form .required-mark { padding: 0 7px; font-size: 11px; line-height: 17px; }
.compact-form .form-error { margin: 0 0 14px; }
.compact-form button { height: 40px; font-size: 15px; }
.compact-form .secondary-button { margin-top: 8px; }

/* The sessions page (/account/sessions). */

.device-list { margin: 0 0 16px; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: 10px; }
.device { padding: 10px 12px; }
.device + .device { border-top: 1px solid var(--border); }
.device-current { background: var(--accent-wash); }
.device:first-child { border-radius: 9px 9px 0 0; }
.device:last-child { border-radius: 0 0 9px 9px; }
.device:only-child { border-radius: 9px; }

.device-row { display: flex; align-items: center; gap: 12px; }
.device-info { flex: 1; min-width: 0; }
.device-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.device-name { color: var(--text-strong); font-size: 14px; font-weight: 700; line-height: 20px; }

.device-badge {
  padding: 0 7px;
  border-radius: 999px;
  color: var(--accent-text);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 600;
  line-height: 17px;
}
.device-badge-muted { color: var(--text-muted); background: var(--surface-muted); }

.device-meta:empty { display: none; }
.nowrap { white-space: nowrap; }
.device-meta, .device-note { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; line-height: 18px; overflow-wrap: anywhere; }

/* Applications of a device: a column, the ones past the first few fold under
   «Показать ещё». The folded list sits before the toggle, so it opens above
   «Свернуть»: :has() ties them; without it the list just stays open. */
.app-list { margin: 4px 0 0; padding: 0; list-style: none; color: var(--text); font-size: 13px; line-height: 20px; }
.app-list li { position: relative; padding-left: 12px; overflow-wrap: anywhere; }
.app-list li::before { content: ""; position: absolute; top: 8px; left: 2px; width: 4px; height: 4px; border-radius: 50%; background: var(--border-input); }
.app-list-more { margin-top: 0; }
.app-kept { color: var(--text-muted); }

.app-more { display: none; }
.app-more summary {
  display: inline-block;
  margin-top: 2px;
  color: var(--accent-text);
  font-size: 13px;
  line-height: 20px;
  list-style: none;
  cursor: pointer;
}
.app-more summary::-webkit-details-marker { display: none; }
.app-more summary:hover { text-decoration: underline; }
.app-more summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.app-more-open, .app-more[open] .app-more-closed { display: none; }
.app-more[open] .app-more-open { display: inline; }

@supports selector(:has(*)) {
  .app-more { display: block; }
  .device-info:not(:has(.app-more[open])) .app-list-more { display: none; }
}

.device-action {
  display: inline-flex;
  flex: none;
  width: auto;
  height: 30px;
  align-items: center;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--text-control);
  background: var(--surface-muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.device-current .device-action { background: var(--surface); box-shadow: inset 0 0 0 1px var(--accent-border); }
.device-action:hover { background: var(--surface-hover); }
.device-action:focus-visible { outline: 3px solid var(--accent-outline); outline-offset: 2px; }

/* The root page (/). */

.home-user { margin-bottom: 16px; }
.home-user p { margin: 0; overflow-wrap: anywhere; }
.home-user-name { color: var(--text-strong); font-size: 16px; font-weight: 700; line-height: 22px; }
.home-user .home-user-meta { margin-top: 2px; color: var(--text-muted); font-size: 13px; line-height: 18px; }

.home-links { margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: 10px; }
.home-links li + li { border-top: 1px solid var(--border); }
.home-links a { display: block; padding: 10px 12px; color: inherit; text-decoration: none; }
.home-links li:first-child a { border-radius: 9px 9px 0 0; }
.home-links li:last-child a { border-radius: 0 0 9px 9px; }
.home-links li:only-child a { border-radius: 9px; }
.home-links a:hover { background: var(--surface-subtle); }
.home-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.home-link-title { display: block; color: var(--text-strong); font-size: 14px; font-weight: 700; line-height: 20px; }
.home-link-text { display: block; margin-top: 2px; color: var(--text-muted); font-size: 13px; line-height: 18px; }

/* The realm's support, terms and privacy links. */
.realm-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  line-height: 18px;
}

.realm-links,
.locale-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
}

.locale-switch { gap: 6px 14px; }

.realm-footer a { color: var(--text-muted); text-decoration: none; }
.realm-footer a:hover { color: var(--text-control); text-decoration: underline; }
.realm-footer a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.locale-switch a[aria-current] { color: var(--text-control); font-weight: 600; }
.locale-switch a[aria-current]:hover { text-decoration: none; }

.attr-list { margin: 16px 0; padding-left: 20px; }
.attr-list li { margin: 4px 0; }
.attr-list code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-muted);
  font-size: 13px;
}

@media (max-width: 520px) {
  body { align-items: flex-start; padding: 16px; }
  .auth-card { margin-top: 8vh; padding: 28px 24px; border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  input, button { transition: none; }
}
