/* ==========================================================================
   Base: layout, header, buttons, fields, badges, «Скоро» teasers, flash, empty and error states. Colours only via tokens (tokens.css).
   ========================================================================== */

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + var(--s-4)); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: -0.012em;
  margin: 0;
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: auto;
}
p { margin: 0; }
a { color: var(--c-link); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
ul, ol { margin: 0; }
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--c-accent-soft); color: var(--c-text); }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i--sm { width: 16px; height: 16px; }
.i--lg { width: 24px; height: 24px; }
.i--fill { fill: currentColor; stroke: none; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s-4); top: -80px; z-index: 200;
  background: var(--c-surface); color: var(--c-text); padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); box-shadow: var(--shadow-3); font-weight: var(--fw-medium);
}
.skip-link:focus { top: var(--s-3); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .spin { animation-duration: 1.8s !important; animation-iteration-count: infinite !important; }
}

/* ---- Layout ---------------------------------------------------------------- */
.container { width: min(100% - 2 * var(--gutter), var(--container)); margin-inline: auto; }
.container--narrow { width: min(100% - 2 * var(--gutter), 820px); }
.page { padding-block: var(--s-6) var(--s-9); }
.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-7); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.muted { color: var(--c-text-muted); }
.small { font-size: var(--fs-sm); }
.eyebrow { font-family: var(--font-body); line-height: 1.4; display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--c-text-muted); }

.page-head { display: grid; gap: var(--s-3); margin-bottom: var(--s-6); }
.page-title { font-size: var(--fs-xl); }
@media (min-width: 900px) { .page-title { font-size: var(--fs-2xl); } }
.section-title { font-size: var(--fs-lg); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4); }

.back-link {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap);
  color: var(--c-text-muted); text-decoration: none; font-weight: var(--fw-medium);
  max-width: 100%;
}
.back-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link:hover { color: var(--c-text); }
.back-link .i { transition: transform var(--dur) var(--ease); }
.back-link:hover .i { transform: translateX(-3px); }

/* ---- Wordmark ---------------------------------------------------------------- */
.wordmark {
  display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap);
  color: var(--c-text); text-decoration: none;
  font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: 1.3125rem; letter-spacing: -0.01em;
}
.wordmark__mark { width: 30px; height: 30px; color: var(--c-accent); flex: none; }
.wordmark--lg { font-size: 2rem; gap: 14px; }
.wordmark--lg .wordmark__mark { width: 44px; height: 44px; }

/* ---- Header ---------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--c-header-bg);
  -webkit-backdrop-filter: saturate(1.2) blur(10px); backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--c-line);
}
.site-header__inner { display: flex; align-items: center; gap: var(--s-5); min-height: var(--header-h); }
.nav { display: flex; gap: var(--s-1); }
.nav a {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: 0 14px;
  border-radius: var(--r-pill); color: var(--c-text-muted); text-decoration: none; font-weight: var(--fw-medium);
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.nav a:hover { color: var(--c-text); background: var(--c-surface-2); }
.nav a[aria-current] { color: var(--c-text); background: var(--c-surface-2); box-shadow: inset 0 0 0 1px var(--c-line); }

.usermenu { margin-left: auto; position: relative; }
.usermenu > summary {
  list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer;
  min-height: var(--tap); padding: 4px 10px 4px 4px; border-radius: var(--r-pill);
  border: 1px solid transparent; transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu > summary:hover, .usermenu[open] > summary { background: var(--c-surface); border-color: var(--c-line); }
.usermenu__who { display: grid; line-height: 1.2; text-align: left; }
.usermenu__name { font-weight: var(--fw-medium); }
.usermenu__role { font-size: var(--fs-xs); color: var(--c-text-muted); }
.usermenu .chev { color: var(--c-text-muted); transition: transform var(--dur) var(--ease); }
.usermenu[open] .chev { transform: rotate(180deg); }
.usermenu__menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; z-index: 40;
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); padding: var(--s-2);
}
.usermenu__menu a, .usermenu__menu button {
  display: flex; align-items: center; gap: var(--s-3); min-height: var(--tap); padding: 0 var(--s-3);
  border-radius: var(--r-md); color: var(--c-text); text-decoration: none;
  width: 100%; border: 0; background: none; cursor: pointer; text-align: left;
}
.usermenu__menu a:hover, .usermenu__menu button:hover { background: var(--c-surface-2); }
.usermenu__menu form { margin: 0; }
.usermenu__menu hr { border: 0; border-top: 1px solid var(--c-line); margin: var(--s-2) 0; }
.usermenu__menu .hint { padding: var(--s-1) var(--s-3) var(--s-2); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--c-accent-soft); color: var(--c-accent-text);
  font-weight: var(--fw-semibold); font-size: var(--fs-sm);
}
.avatar--lg { width: 72px; height: 72px; font-size: 1.5rem; font-family: var(--font-display); }
.avatar--teacher { background: var(--c-warn-soft); color: var(--c-warn-text); }

@media (max-width: 639px) {
  .site-header__inner { gap: var(--s-2); }
  .usermenu__who { display: none; }
  .wordmark { font-size: 1.1875rem; }
  .nav a { padding: 0 12px; }
}

/* Plain header for signed-out pages */
.site-header--plain { position: static; background: transparent; border-bottom: 0; -webkit-backdrop-filter: none; backdrop-filter: none; }

/* ---- Buttons ---------------------------------------------------------------- */
.btn {
  --btn-bg: var(--c-surface); --btn-fg: var(--c-text); --btn-bd: var(--c-line-strong);
  --btn-bg-h: var(--c-surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-5);
  border: 1px solid var(--btn-bd); border-radius: var(--r-pill);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: var(--fw-medium); line-height: 1.2; text-decoration: none; text-align: center;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
}
.btn:hover, .btn.is-hover { background: var(--btn-bg-h); }
.btn:active { transform: translateY(1px); }
.btn.is-focus { outline: 3px solid var(--c-focus); outline-offset: 2px; }
.btn--primary { --btn-bg: var(--c-accent); --btn-fg: var(--c-on-accent); --btn-bd: var(--c-accent); --btn-bg-h: var(--c-accent-hover); }
.btn--primary:hover, .btn--primary.is-hover { border-color: var(--c-accent-hover); }
.btn--ok { --btn-bg: var(--c-ok); --btn-fg: var(--c-on-ok); --btn-bd: var(--c-ok); --btn-bg-h: var(--c-ok-hover); }
.btn--warn { --btn-bg: var(--c-warn); --btn-fg: var(--c-on-warn); --btn-bd: var(--c-warn); --btn-bg-h: var(--c-warn-hover); }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--c-accent-text); --btn-bg-h: var(--c-accent-soft); padding: 0 var(--s-4); }
.btn--sm { min-height: 36px; padding: 0 var(--s-4); font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"], .btn.is-disabled {
  cursor: not-allowed; transform: none;
  --btn-bg: var(--c-surface-2); --btn-bg-h: var(--c-surface-2); --btn-fg: var(--c-text-muted); --btn-bd: var(--c-line);
}
.btn[aria-busy="true"], .btn.is-loading {
  cursor: progress; transform: none;
}
.btn[aria-busy="true"] .btn__icon, .btn.is-loading .btn__icon { display: none; }
.btn .spin { display: none; }
.btn[aria-busy="true"] .spin, .btn.is-loading .spin { display: inline-block; }
@media (max-width: 639px) { .btn--stack-mobile { width: 100%; } }

/* While htmx sends a form it puts .htmx-request on it and disables its buttons and textarea
   (hx-disable). static/js/app.js marks the pressed button aria-busy: only it shows the spinner
   and its busy label. The previous try's error is hidden, as the response replaces it. */
.htmx-request .btn { cursor: progress; transform: none; }
.btn__busy { display: none; }
.btn[aria-busy="true"] .btn__idle { display: none; }
.btn[aria-busy="true"] .btn__busy { display: inline; }
.htmx-request .field-error { display: none; }
.htmx-request .textarea[aria-invalid="true"] { border-color: var(--c-line-strong); box-shadow: none; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.9s linear infinite; }

/* ---- Form fields ---------------------------------------------------------------- */
.field { display: grid; gap: var(--s-2); }
.label { font-weight: var(--fw-medium); }
.label .opt { font-weight: var(--fw-regular); color: var(--c-text-muted); }
.hint { font-size: var(--fs-sm); color: var(--c-text-muted); }
.input, .textarea, .select {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-line-strong); border-radius: var(--r-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 168px; line-height: 1.65; resize: vertical; display: block; }
.input::placeholder, .textarea::placeholder { color: var(--c-text-muted); opacity: 1; }
.input:hover, .textarea:hover, .input.is-hover { border-color: var(--c-text-muted); }
.input:focus-visible, .textarea:focus-visible, .input.is-focus, .textarea.is-focus {
  outline: 3px solid var(--c-focus); outline-offset: 1px; border-color: var(--c-focus);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--c-danger); box-shadow: inset 0 0 0 1px var(--c-danger); }
.input:disabled, .textarea:disabled, .textarea[readonly] { background: var(--c-surface-2); color: var(--c-text-muted); cursor: not-allowed; }
.field-error {
  display: flex; align-items: flex-start; gap: var(--s-2);
  color: var(--c-danger-text); font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.field-error .i { width: 18px; height: 18px; margin-top: 1px; }
.check {
  display: flex; align-items: flex-start; gap: var(--s-3); min-height: var(--tap); padding-block: 10px; cursor: pointer;
}
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--c-accent); flex: none; cursor: pointer; }
.form-actions { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }

/* ---- Badges & chips ---------------------------------------------------------------- */
.badge {
  --b-bg: var(--c-neutral-soft); --b-fg: var(--c-neutral-text); --b-bd: transparent;
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 3px 10px 3px 8px; border-radius: var(--r-pill);
  background: var(--b-bg); color: var(--b-fg); border: 1px solid var(--b-bd);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1.35; white-space: nowrap;
}
.badge .i { width: 15px; height: 15px; stroke-width: 2; }
.badge--none { --b-bg: var(--c-surface); --b-bd: var(--c-line-strong); }
.badge--pending { --b-bg: var(--c-pending-soft); --b-fg: var(--c-pending-text); }
.badge--ok { --b-bg: var(--c-ok-soft); --b-fg: var(--c-ok-text); }
.badge--warn { --b-bg: var(--c-warn-soft); --b-fg: var(--c-warn-text); }
.badge--access { --b-bg: var(--c-accent-soft); --b-fg: var(--c-accent-text); }
.badge--locked { --b-bg: var(--c-surface); --b-fg: var(--c-neutral-text); --b-bd: var(--c-line); }
.badge--solid { box-shadow: var(--shadow-1); }

.chip-soon {
  display: inline-flex; align-items: center; gap: 4px; flex: none; vertical-align: middle;
  padding: 1px 8px 1px 6px; border-radius: var(--r-pill);
  background: var(--c-soon-bg); color: var(--c-soon-text); border: 1px solid var(--c-soon-line);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.02em; line-height: 1.5; white-space: nowrap;
}
.chip-soon .i { width: 13px; height: 13px; stroke-width: 2; }

.counter { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--c-text-muted); }
.counter b { color: var(--c-text); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }

/* ---- «Скоро» teasers ---------------------------------------------------------------- */
/* Inline: the sample element dimmed (aria-hidden) + a chip. Takes no extra layout. */
.soon-inline { display: inline-flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; min-width: 0; }
.soon-inline__sample { opacity: 0.5; filter: grayscale(0.4); pointer-events: none; user-select: none; }
.soon-inline--block { display: flex; }
.soon-inline--block .soon-inline__sample { flex: 1; min-width: 0; }

/* Panel: dimmed, lightly blurred preview + an overlay note. */
.soon {
  position: relative; isolation: isolate; overflow: hidden;
  border-radius: var(--r-lg); border: 1px dashed var(--c-soon-line);
  background: var(--c-surface);
}
.soon__preview { padding: var(--s-5); filter: blur(1.4px) grayscale(0.3); opacity: 0.55; pointer-events: none; user-select: none; }
.soon__veil {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center; padding: var(--s-4);
  background: linear-gradient(180deg, var(--c-soon-veil-from), var(--c-soon-veil-to));
}
.soon__note {
  display: grid; justify-items: center; gap: 6px; max-width: 36ch; text-align: center;
  background: var(--c-surface); border: 1px solid var(--c-soon-line); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4) var(--s-4); box-shadow: var(--shadow-2);
}
.soon__title { font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: var(--fs-md); line-height: 1.25; }
.soon__promise { font-size: var(--fs-sm); color: var(--c-text-muted); }
.soon--compact .soon__preview { padding: var(--s-4) var(--s-4) calc(var(--s-4) + 112px); }
.soon--compact .soon__veil { align-items: flex-end; padding: var(--s-3); }
.soon--compact .soon__note { max-width: none; width: 100%; padding: var(--s-3) var(--s-4); }
.soon--compact .soon__title { font-size: var(--fs-base); }

/* Sample content building blocks used inside teaser previews */
.fake-line { height: 10px; border-radius: 6px; background: var(--c-surface-3); }
.fake-toggle { width: 40px; height: 24px; border-radius: 12px; background: var(--c-surface-3); position: relative; flex: none; }
.fake-toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--c-surface); box-shadow: var(--shadow-1); }
.fake-toggle.is-on { background: var(--c-accent); }
.fake-toggle.is-on::after { left: 19px; }
.fake-radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--c-line-strong); flex: none; }
.fake-radio.is-on { border: 6px solid var(--c-accent); }

.progress { height: 8px; border-radius: var(--r-pill); background: var(--c-surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--c-accent); }
.ring { --p: 40; width: 96px; height: 96px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--c-accent) calc(var(--p) * 1%), var(--c-surface-3) 0); }
.ring::before { content: attr(data-label); width: 74px; height: 74px; border-radius: 50%; background: var(--c-surface); display: grid; place-items: center; font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: 1.375rem; }

/* ---- Cards (generic) ---------------------------------------------------------------- */
.card { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg); padding: var(--s-5); }
.card--flat { box-shadow: none; }
.card__title { font-size: var(--fs-md); margin-bottom: var(--s-3); }

/* ---- Flash ---------------------------------------------------------------- */
.flash { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); border: 1px solid; font-weight: var(--fw-medium); }
.flash .i { margin-top: 2px; }
.flash--error { background: var(--c-danger-soft); color: var(--c-danger-text); border-color: color-mix(in oklab, var(--c-danger) 35%, transparent); }
.flash--ok { background: var(--c-ok-soft); color: var(--c-ok-text); border-color: color-mix(in oklab, var(--c-ok) 35%, transparent); }
.flash--info { background: var(--c-pending-soft); color: var(--c-pending-text); border-color: color-mix(in oklab, var(--c-pending) 30%, transparent); }
.flash-slot:not(:empty) { margin-bottom: var(--s-5); }

/* ---- Empty & error states ---------------------------------------------------------------- */
.empty { display: grid; justify-items: center; text-align: center; gap: var(--s-3); padding: var(--s-8) var(--s-5); border-radius: var(--r-xl); background: var(--c-surface); border: 1px solid var(--c-line); }
.empty__art { width: 180px; height: 130px; margin-bottom: var(--s-2); }
.empty__title { font-size: var(--fs-lg); }
.empty p { color: var(--c-text-muted); max-width: 44ch; }
.empty .btn { margin-top: var(--s-2); }

.art-line { fill: none; stroke: var(--c-text-muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.art-accent { fill: none; stroke: var(--c-accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.art-fill-a { fill: var(--c-accent-soft); }
.art-fill-b { fill: var(--c-warn-soft); }
.art-fill-c { fill: var(--c-soon-bg); }
.art-fill-s { fill: var(--c-surface); }

.errpage { display: grid; gap: var(--s-6); align-items: center; padding-block: var(--s-7); }
.errpage__art { width: min(100%, 360px); justify-self: center; }
.errpage__text { display: grid; gap: var(--s-4); max-width: 52ch; }
.errpage__code { font-family: var(--font-display); font-size: var(--fs-3xl); line-height: 1; color: var(--c-accent-text); }
@media (min-width: 900px) { .errpage { grid-template-columns: 1fr 1fr; min-height: 60vh; } .errpage__art { order: 2; } }
.errpage__svg { width: 100%; height: auto; display: block; }
.errpage__lead { font-size: var(--fs-md); }

/* ---- Small layout helpers (no inline styles in templates) ---------------------------------------------------------------- */
.row--xs { gap: 6px; }
.row--tight { gap: 10px; }
.row--wide { gap: var(--s-4); }
.row--nowrap { flex-wrap: nowrap; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.vstack { display: grid; gap: 6px; }
.vstack--xs { gap: 2px; }
.vstack--md { gap: var(--s-3); }
.strong { font-weight: var(--fw-semibold); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }

/* Sample values inside «Скоро» previews */
.progress--card { width: 120px; }
.progress__fill-40 { width: 40%; }
.fake-select--wide { justify-content: space-between; }
.fake-select--area { min-height: 64px; align-items: flex-start; padding-top: var(--s-2); }
.fake-btn--start { justify-self: start; }
.cert-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
