/*
 * Shell and UI components of notes.marhub.ru in the look of the team workspace (AppShell.tsx, SectionHeader.tsx,
 * components/ui.tsx). Uses only the custom properties from tokens.css. Plain CSS, no build step.
 *
 * Breakpoints (same as the workspace): phone < 640 (bottom bar, no side menu), tablet 640-1023 (narrow menu
 * column), desktop >= 1024 (full side menu), wide >= 1280 (table of contents panel on prep pages).
 */

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  background: var(--canvas);
}
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
h1 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
@media (min-width: 640px) {
  h1 {
    font-size: 24px;
  }
}
a {
  color: inherit;
}
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}
img,
svg {
  max-width: 100%;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
::selection {
  background: color-mix(in srgb, var(--brand-500) 30%, transparent);
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip {
  position: absolute;
  left: var(--space-2);
  top: -100px;
  z-index: 60;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.skip:focus {
  top: var(--space-2);
}
.skip {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
}
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm {
  width: 18px;
  height: 18px;
}

/* Colours glide only while the theme switches, so normal hovers stay snappy. */
html[data-theme-switching] *,
html[data-theme-switching] *::before,
html[data-theme-switching] *::after {
  transition:
    background-color 240ms ease,
    border-color 240ms ease,
    color 240ms ease,
    fill 240ms ease !important;
}

/* ---------- Shell: side menu + frame (AppShell) ---------- */
.shell {
  display: flex;
  min-height: 100dvh;
}
.frame {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
}

/* Side menu: white, hairline on the right, sticky full height. Hidden on phones. */
.side-nav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: none;
  flex: none;
  flex-direction: column;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid var(--gray-200);
  background: var(--surface);
  padding: 0 var(--space-2) var(--space-3);
}
@media (min-width: 640px) {
  .side-nav {
    display: flex;
    width: var(--nav-w-tablet);
  }
}
@media (min-width: 1024px) {
  .side-nav {
    width: var(--nav-w);
    padding-inline: var(--space-3);
  }
}

/* Wordmark at the top of the menu (h-14) and in the phone header. */
.lockup {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.lockup__mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--on-ink);
  transition: transform 320ms cubic-bezier(0.34, 1.4, 0.64, 1);
}
.lockup__mark .icon {
  width: 18px;
  height: 18px;
}
.lockup__word {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
@media (hover: hover) {
  .lockup:hover .lockup__mark {
    transform: translateX(2px) scale(1.04);
  }
}
.lockup:active .lockup__mark {
  transform: scale(0.96);
}
.side-nav .lockup {
  height: var(--header-h);
  flex: none;
  margin-bottom: var(--space-2);
  padding-inline: var(--space-2);
}
@media (min-width: 640px) and (max-width: 1023px) {
  .side-nav .lockup {
    justify-content: center;
    padding-inline: 0;
  }
  .side-nav .lockup__word {
    display: none;
  }
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* Group label: 11 px, upper case, semibold, gray-500; on a tablet a short line stands in for it. */
.nav-group {
  margin: 0;
  padding: var(--space-4) var(--space-3) 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gray-500);
  white-space: nowrap;
}
.nav-group:first-child {
  padding-top: var(--space-2);
}
@media (max-width: 1023px) {
  .nav-group {
    height: 21px;
    padding: 0;
    margin: var(--space-2) auto;
    width: 20px;
    border-bottom: 1px solid var(--gray-300);
    overflow: hidden;
    color: transparent;
  }
  .nav-group:first-child {
    display: none;
  }
}

/* Menu items: capsules, semibold 13 px, optional 11 px hint; the open section is an ink capsule. */
.nav-item {
  position: relative;
  display: flex;
  min-height: 44px;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-lg);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--gray-700);
  text-decoration: none;
  transition:
    background-color var(--dur) ease,
    color var(--dur) ease;
}
@media (min-width: 1024px) {
  .nav-item {
    min-height: 48px;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: 6px var(--space-3);
    border-radius: var(--radius-full);
    font-size: 13px;
  }
}
.nav-item:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.nav-item[aria-current='page'] {
  background: var(--ink);
  color: var(--on-ink);
}
.nav-item__mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--radius-full);
  transition: transform var(--dur) ease;
}
.nav-item__mark .icon {
  width: 20px;
  height: 20px;
}
.nav-item__badge {
  position: absolute;
  top: -4px;
  right: -8px;
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: var(--radius-full);
  background: var(--brand-600);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}
@media (hover: hover) {
  .nav-item:hover .nav-item__mark {
    transform: scale(1.1);
  }
}
.nav-item__text {
  display: flex;
  min-width: 0;
  max-width: 100%;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
@media (min-width: 1024px) {
  .nav-item__text {
    align-items: flex-start;
    text-align: left;
  }
}
.nav-item__title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item__title--full {
  display: none;
}
/* Rail (640-1023): every item is glyph + one short label (Главная, МО, ОС, ДУ) at the same height. */
@media (min-width: 640px) and (max-width: 1023px) {
  .nav-item {
    min-height: 60px;
  }
}
@media (min-width: 1024px) {
  .nav-item__title {
    white-space: nowrap;
  }
  .nav-item__title--short {
    display: none;
  }
  .nav-item__title--full {
    display: block;
  }
}
.nav-item__hint {
  display: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
}
.nav-item[aria-current='page'] .nav-item__hint {
  color: var(--on-ink-muted);
}
@media (min-width: 1024px) {
  .nav-item__hint {
    display: block;
  }
}

/* ---------- Header (sticky, translucent canvas, blur, hairline) ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: var(--header-h);
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--gray-200);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
@media (min-width: 640px) {
  .app-header {
    padding-inline: var(--space-4);
  }
  .app-header > .lockup {
    display: none;
  }
}
/* Wide screens: the header row and the page share one centred column of --page-w, so the avatar and the theme
   button sit at the right edge of the content, not at the window edge. Percent padding = share of the frame width. */
@media (min-width: 1024px) {
  .app-header {
    padding-inline: max(var(--space-8), calc((100% - var(--page-w)) / 2));
  }
}
.app-header > .lockup .lockup__mark {
  width: 30px;
  height: 30px;
}
/* Narrow phones: the bottom bar has «Главная», so the header gives the lockup's room to the search field. */
@media (max-width: 419px) {
  .app-header > .lockup {
    display: none;
  }
}
.app-header .search {
  flex: 1;
  min-width: 0;
  max-width: 448px;
}
.header-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

/* Round icon button (theme switch, close). 44 px on touch, 40 px with a mouse. */
.icon-btn {
  display: inline-flex;
  width: 44px;
  height: 44px;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--gray-600);
  cursor: pointer;
  transition:
    background-color var(--dur) ease,
    color var(--dur) ease;
}
.icon-btn:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .icon-btn {
    width: 40px;
    height: 40px;
  }
}
/* The theme button shows the moon in light and the sun in dark; it pops when switched. */
.theme-btn .i-sun {
  display: none;
}
:root[data-theme='dark'] .theme-btn .i-sun {
  display: block;
}
:root[data-theme='dark'] .theme-btn .i-moon {
  display: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-btn .i-sun {
    display: block;
  }
  :root:not([data-theme='light']) .theme-btn .i-moon {
    display: none;
  }
}
.theme-btn.is-popping .icon {
  animation: pop-in 260ms var(--ease-out-soft) both;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.6) rotate(-30deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: var(--space-6) var(--space-4) calc(var(--bottom-bar-h) + var(--space-8) + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .main {
    padding-bottom: var(--space-12);
  }
}
@media (min-width: 1024px) {
  .main {
    padding-inline: max(var(--space-8), calc((100% - var(--page-w)) / 2));
  }
}

/* ---------- Bottom bar on phones ---------- */
.bottom-bar {
  position: fixed;
  inset: auto 0 0;
  z-index: 20;
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--gray-200);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
@media (min-width: 640px) {
  .bottom-bar {
    display: none;
  }
}
.bar-item {
  display: flex;
  min-width: 0;
  min-height: var(--bottom-bar-h);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
  text-decoration: none;
  transition: transform 120ms ease;
}
.bar-item:active {
  transform: scale(0.95);
}
.bar-item__mark {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 28px;
  border-radius: var(--radius-full);
  transition:
    background-color 300ms ease,
    color 300ms ease;
}
.bar-item__mark {
  position: relative;
}
/* A dot on «Управление» while profiles wait for approval. */
.bar-item__badge {
  position: absolute;
  top: 2px;
  right: 12px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--canvas);
  border-radius: var(--radius-full);
  background: var(--brand-600);
}
.bar-item__label {
  max-width: 100%;
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 320-359 with the owner's fifth item: a touch tighter, so «Управление» fits its 64 px column. */
@media (max-width: 359px) {
  .bar-item__label {
    padding: 0;
    font-size: 10.5px;
    letter-spacing: -0.01em;
  }
}
/* Six items (owner: home, three subjects, «Заметки», «Управление»): narrower marks and type below 400 px. */
@media (max-width: 399px) {
  .bottom-bar:has(> .bar-item:nth-child(6)) .bar-item__mark {
    width: 44px;
  }
  .bottom-bar:has(> .bar-item:nth-child(6)) .bar-item__label {
    padding: 0;
    font-size: 9.5px;
    letter-spacing: -0.03em;
  }
}
.bar-item[aria-current='page'] {
  font-weight: 600;
  color: var(--gray-900);
}
.bar-item[aria-current='page'] .bar-item__mark {
  background: var(--ink);
  color: var(--on-ink);
}

/* ---------- Buttons (ui.tsx Button): capsules; primary = ink ---------- */
.btn {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--dur) ease,
    border-color var(--dur) ease,
    box-shadow var(--dur) ease,
    color var(--dur) ease,
    transform 150ms ease;
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .btn {
    min-height: 40px;
  }
  .btn--sm {
    min-height: 32px;
  }
}
.btn--sm {
  padding: 0 var(--space-3);
}
.btn:active {
  transform: scale(0.97);
}
.btn--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--on-ink);
}
.btn--primary:hover {
  border-color: var(--ink-hover);
  background: var(--ink-hover);
  box-shadow: var(--shadow-primary-hover);
}
.btn--secondary {
  border-color: var(--gray-300);
  background: var(--surface);
  color: var(--gray-900);
}
.btn--secondary:hover {
  border-color: var(--gray-900);
  background: var(--gray-100);
}
.btn--ghost {
  background: transparent;
  color: var(--gray-600);
}
.btn--ghost:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.btn[aria-pressed='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--on-ink);
}
.btn--primary[aria-busy='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--on-ink);
  cursor: progress;
}
.btn[disabled]:not([aria-busy='true']) {
  cursor: not-allowed;
  border-color: var(--gray-200);
  background: var(--gray-200);
  color: var(--gray-500);
  box-shadow: none;
  transform: none;
}
/* A button whose label changes reserves the width of its longest label, so the row never moves. */
.swap-label {
  display: inline-grid;
}
.swap-label > span {
  grid-area: 1 / 1;
}
.swap-label > [data-off] {
  visibility: hidden;
}
[aria-pressed='true'] .swap-label > [data-on] {
  visibility: hidden;
}
[aria-pressed='true'] .swap-label > [data-off] {
  visibility: visible;
}

/* ---------- Fields (ui.tsx inputClass) ---------- */
.field {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: 16px;
  outline: none;
  transition:
    border-color var(--dur) ease,
    box-shadow var(--dur) ease;
}
@media (min-width: 640px) {
  .field {
    font-size: 14px;
  }
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .field {
    min-height: 40px;
  }
}
.field::placeholder {
  color: var(--gray-500);
}
.field:hover {
  border-color: var(--gray-500);
}
.field:focus {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-600) 20%, transparent);
}
textarea.field {
  min-height: 160px;
  padding: 10px var(--space-4);
  border-radius: var(--radius-lg);
  line-height: 1.55;
  resize: vertical;
}
.label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  color: var(--gray-900);
}
.help {
  margin: 6px 0 0;
  min-height: 16px;
  font-size: 12px;
  line-height: 16px;
  color: var(--gray-500);
}

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  max-width: 100%;
  height: 24px;
  align-items: center;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--gray-100);
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill--accent {
  background: var(--brand-50);
  color: var(--brand-700);
}
.pill--warn {
  background: var(--amber-50);
  color: var(--amber-700);
}

/* ---------- Search (header and home) ---------- */
.search {
  position: relative;
}
.search__form {
  position: relative;
  margin: 0;
}
.search__icon {
  position: absolute;
  top: 50%;
  left: 14px;
  color: var(--gray-400);
  transform: translateY(-50%);
  pointer-events: none;
}
.search__input {
  padding-left: 40px;
  -webkit-appearance: none;
  appearance: none;
}
.search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
.search--lg .search__input {
  min-height: 48px;
  padding-left: 44px;
  font-size: 16px;
}
.search--lg .search__icon {
  left: 16px;
}
/* Results: fixed maximum height, scrolls inside; never wider than the screen. */
.search__pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  min-width: min(360px, calc(100vw - 2 * var(--space-4)));
  max-height: min(420px, calc(100dvh - 140px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  animation: pop-down 160ms var(--ease-out-soft) both;
}
@keyframes pop-down {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (max-width: 639px) {
  .app-header .search__pop {
    position: fixed;
    top: calc(var(--header-h) + 6px);
    left: var(--space-3);
    right: var(--space-3);
    min-width: 0;
  }
}
.search__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.search__group {
  padding: var(--space-2) var(--space-4) var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.search__item {
  display: flex;
  min-height: 44px;
  margin: 0 6px;
  padding: 6px var(--space-3);
  flex-direction: column;
  justify-content: center;
  border-radius: var(--radius-md);
  text-decoration: none;
  cursor: pointer;
}
.search__item:hover,
.search__item.is-active {
  background: var(--gray-100);
}
.search__title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--gray-900);
}
.search__title mark {
  background: none;
  color: inherit;
  font-weight: 700;
}
.search__sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--gray-500);
}
.search__empty {
  margin: 0;
  padding: var(--space-4);
  font-size: 14px;
  color: var(--gray-600);
}

/* ---------- Section header (SectionHeader.tsx) ---------- */
.section-header {
  display: flex;
  max-width: var(--page-w);
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.section-header__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.section-header__titles {
  min-width: 0;
}
.section-header__hint {
  display: none;
  max-width: 672px;
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-500);
}
@media (min-width: 640px) {
  .section-header__hint {
    display: block;
  }
}
.section-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
/* Narrow phones: short labels («Изменить») and icon-only secondary actions (44 × 44), one row. */
@media (max-width: 419px) {
  .section-header__actions .label-long,
  .section-header__actions .btn--narrow-icon .btn__label {
    display: none;
  }
  .section-header__actions .label-short {
    display: inline;
  }
  .section-header__actions .btn--narrow-icon {
    width: 44px;
    padding: 0;
  }
}
/* Tabs: muted words on one hairline; the active one dark with an ink underline. */
.tabs {
  margin-inline: calc(-1 * var(--space-4));
  padding-inline: var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
@media (min-width: 640px) {
  .tabs {
    margin-inline: 0;
    padding-inline: 0;
  }
}
.tabs__list {
  position: relative;
  display: flex;
  min-width: max-content;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--gray-200);
}
.tab {
  position: relative;
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--dur) ease,
    color var(--dur) ease;
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .tab {
    min-height: 40px;
  }
}
.tab:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.tab[aria-current='page'] {
  color: var(--gray-900);
}
.tab[aria-current='page']::after {
  content: '';
  position: absolute;
  inset: auto 0 -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
}
.tab[aria-current='page']:hover {
  background: transparent;
}
.tab__count {
  margin-left: 6px;
  font-weight: 500;
  color: var(--gray-500);
}

/* ---------- Surfaces ---------- */
.panel {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* ---------- Home ---------- */
.home-search {
  max-width: 640px;
  margin-bottom: var(--space-6);
}
/* One column on phones, two from 640, three from 1280. A last card left alone in its row spans the row,
   so there is never an orphan next to an empty cell. */
.subject-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  max-width: var(--page-w);
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (min-width: 640px) {
  .subject-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .subject-grid > li:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}
@media (min-width: 1280px) {
  .subject-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .subject-grid > li:last-child:nth-child(odd) {
    grid-column: auto;
  }
  .subject-grid > li:last-child:nth-child(3n + 1) {
    grid-column: 1 / -1;
  }
}
.subject-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  transition:
    border-color var(--dur) ease,
    box-shadow var(--dur) ease;
}
@media (hover: hover) {
  .subject-card:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-pop);
  }
}
.subject-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}
.mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: var(--radius-lg);
  background: var(--ink);
  color: var(--on-ink);
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 700;
}
.subject-card__title {
  margin: var(--space-1) 0 0;
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.subject-card__title a {
  text-decoration: none;
}
/* The whole card opens the subject; buttons below stay clickable on top. */
.subject-card__title a::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.subject-card__ahead {
  flex: 1;
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--gray-600);
}
.subject-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
}
.subject-card__actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-1);
}

/* ---------- Prep page: content column + table of contents ---------- */
.prep {
  --anchor-offset: 136px;
  display: grid;
  max-width: var(--page-w);
  grid-template-columns: minmax(0, var(--content-w));
  gap: var(--space-12);
}
@media (min-width: 1280px) {
  .prep {
    grid-template-columns: minmax(0, var(--content-w)) var(--toc-w);
  }
  .prep--no-tools {
    --anchor-offset: 80px;
  }
}
.prep__main {
  min-width: 0;
}

/* Sticky bar under the header: «Оглавление» (below 1280) and the page tools. Full bleed on narrow screens. */
.prep-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 calc(-1 * var(--space-4)) var(--space-6);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--gray-200);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.prep-bar .scroll-row {
  flex: 1 1 auto;
  padding-inline: var(--space-4) 0;
  scroll-padding-inline: var(--space-4);
}
/* «Оглавление» stays at the right end of the bar, outside the scrolling row. */
.prep-bar__toc {
  flex: none;
  margin-right: var(--space-4);
}
.prep--no-tools .prep-bar .scroll-row {
  display: none;
}
.prep--no-tools .prep-bar__toc {
  margin-left: auto;
}
@media (min-width: 640px) {
  .prep-bar {
    margin-inline: 0;
  }
  .prep-bar .scroll-row {
    padding-inline: 0;
    scroll-padding-inline: 0;
  }
  .prep-bar__toc {
    margin-right: 0;
  }
}
/* Long and short labels of the bar buttons: narrow phones get «Вопрос» and an icon-only «Оглавление». */
.label-short {
  display: none;
}
@media (max-width: 419px) {
  .prep-bar .label-long {
    display: none;
  }
  .prep-bar .label-short {
    display: inline;
  }
  .prep-bar__toc {
    width: 44px;
    padding: 0;
  }
  .prep-bar__toc-label {
    display: none;
  }
}
@media (min-width: 1280px) {
  .prep--no-tools .prep-bar {
    display: none;
  }
  .prep-bar__toc {
    display: none !important;
  }
}
.scroll-row {
  display: flex;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
/* A row that scrolls sideways fades on the side that has more (classes set by shell.js). */
:is(.scroll-row, .tabs, .code-block pre, .code__scroll).is-scrollable:not(.at-end) {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
}
:is(.scroll-row, .tabs, .code-block pre, .code__scroll).is-scrollable.at-end:not(.at-start) {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
}
:is(.scroll-row, .tabs, .code-block pre, .code__scroll).is-scrollable:not(.at-start):not(.at-end) {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
}
.scroll-row::-webkit-scrollbar {
  display: none;
}
.scroll-row > * {
  flex: none;
}

/* Right panel «На странице» (>= 1280). */
.toc-panel {
  display: none;
}
@media (min-width: 1280px) {
  .toc-panel {
    position: sticky;
    top: calc(var(--header-h) + var(--space-6));
    display: flex;
    max-height: calc(100dvh - var(--header-h) - var(--space-12));
    flex-direction: column;
    align-self: start;
    padding: var(--space-4) 0 var(--space-2) var(--space-2);
  }
}
.toc-panel__title {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-900);
}
.toc-panel .toc {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.toc__group + .toc__group {
  margin-top: var(--space-2);
}
.toc__label {
  margin: 0;
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.toc__link {
  display: flex;
  min-height: 36px;
  align-items: center;
  padding: 6px var(--space-3);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--gray-600);
  text-decoration: none;
  transition:
    background-color var(--dur) ease,
    color var(--dur) ease;
}
.sheet .toc__link {
  min-height: 44px;
  font-size: 14px;
}
.toc__link:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.toc__link.is-current {
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 600;
}

/* ---------- Dialogs (.ed-dialog): the question dialog and the editor's dialogs; one look on every page ---------- */
.ed-dialog {
  width: min(440px, calc(100vw - 2 * var(--space-4)));
  max-width: none;
  max-height: calc(100dvh - 2 * var(--space-4));
  padding: 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-2xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
}
.ed-dialog[open] {
  display: flex;
  flex-direction: column;
  animation: ed-pop 180ms var(--ease-out-soft) both;
}
.ed-dialog::backdrop {
  background: rgb(9 9 9 / 0.32);
}
.ed-dialog--wide {
  width: min(980px, calc(100vw - 2 * var(--space-4)));
  height: min(760px, calc(100dvh - 2 * var(--space-4)));
}
.ed-dialog__box {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  overflow-y: auto;
}
@media (min-width: 640px) {
  .ed-dialog__box {
    padding: var(--space-6);
  }
}
.ed-dialog__title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}
.ed-dialog__text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-600);
}
.ed-dialog__text[hidden] {
  display: none;
}
.ed-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.ed-dialog__actions .btn {
  flex: 1 1 auto;
}
@media (min-width: 640px) {
  .ed-dialog__actions .btn {
    flex: none;
  }
}
.ed-dialog__grow {
  display: none;
}
@media (min-width: 768px) {
  .ed-dialog__grow {
    display: block;
    flex: 1;
  }
}
@keyframes ed-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
@media (prefers-reduced-motion: reduce) {
  .ed-dialog[open] {
    animation: none;
  }
}
/* A question about something that cannot be taken back in one click («В корзину», «Отозвать»): a red «yes». */
.ed-dialog[data-tone='danger'] [data-ask-ok] {
  border-color: var(--red-700);
  background: var(--red-700);
  color: var(--surface);
}
.ed-dialog[data-tone='danger'] [data-ask-ok]:hover {
  border-color: var(--red-700);
  background: color-mix(in srgb, var(--red-700) 86%, var(--ink));
  box-shadow: none;
}

/* ---------- Dialog sheet: TOC below 1280 and the drill results. Fixed size, scrolls inside. ---------- */
.sheet {
  width: min(440px, calc(100vw - 2 * var(--space-4)));
  max-width: none;
  height: min(600px, calc(100dvh - 160px));
  max-height: none;
  margin: 112px auto auto;
  padding: 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-2xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
}
.sheet--drill {
  /* head 57 + body padding 32 + hint 32 + rows × (card 80 + gap 8) + foot 69 */
  bottom: auto;
  height: min(calc(190px + var(--rows, 3) * 88px), calc(100dvh - 160px));
}
.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: pop-down 200ms var(--ease-out-soft) both;
}
.sheet::backdrop {
  background: rgb(9 9 9 / 0.32);
}
@media (max-width: 639px) {
  .sheet {
    width: 100vw;
    height: min(78dvh, 640px);
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet--drill {
    top: auto;
    bottom: 0;
    height: min(calc(190px + var(--rows, 3) * 88px + env(safe-area-inset-bottom)), 86dvh);
  }
  .sheet[open] {
    animation-name: sheet-up;
  }
}
@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.sheet__head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--gray-200);
}
.sheet__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.sheet__body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-1);
}
.sheet--drill .sheet__body {
  padding: var(--space-4);
}
.sheet__foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--gray-200);
}
.drill-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.drill-list a {
  display: flex;
  min-height: 80px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  transition:
    border-color var(--dur) ease,
    background-color var(--dur) ease;
}
.drill-list a:hover {
  border-color: var(--gray-900);
  background: var(--gray-50);
}
.drill-list .drill-n {
  display: inline-grid;
  min-width: 44px;
  white-space: nowrap;
  height: 28px;
  flex: none;
  place-items: center;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 12px;
  font-weight: 700;
}
.drill-hint {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  color: var(--gray-500);
}

/* ---------- Documents ---------- */
.files {
  display: flex;
  max-width: var(--page-w);
  flex-direction: column;
  gap: var(--space-4);
}
.file-group {
  padding: var(--space-2) 0;
}
.file-group__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-2);
}
.file-group__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.file-group__count {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
}
.file-sub {
  margin: 0;
  padding: var(--space-4) var(--space-5) var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.file-list {
  margin: 0;
  padding: 0 var(--space-2);
  list-style: none;
}
.file-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  padding: 6px var(--space-3);
  border-radius: var(--radius-lg);
  transition: background-color var(--dur) ease;
}
.file-row + .file-row {
  box-shadow: 0 -1px 0 var(--gray-100);
}
.file-row:hover {
  background: var(--gray-50);
}
.file-row__name {
  display: flex;
  min-width: 0;
  min-height: 44px;
  flex: 1 1 180px;
  align-items: center;
  gap: var(--space-3);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--gray-900);
  text-decoration: none;
  overflow-wrap: anywhere;
}
.file-row__name:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.file-row__icon {
  color: var(--gray-400);
}
.file-row__formats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}
@media (max-width: 639px) {
  .file-row {
    padding-inline: var(--space-2);
  }
  .file-row__formats {
    padding-bottom: 2px;
  }
}
.fmt {
  display: inline-flex;
  min-width: 96px;
  min-height: 36px;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 var(--space-3);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-900);
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color var(--dur) ease,
    background-color var(--dur) ease;
}
@media (any-pointer: coarse) {
  .fmt {
    min-height: 44px;
  }
}
.fmt:hover {
  border-color: var(--gray-900);
  background: var(--gray-100);
}
.fmt__size {
  font-weight: 500;
  color: var(--gray-500);
}
.file-more {
  margin: var(--space-1) var(--space-2) 0;
}
.file-more > summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  list-style: none;
}
.file-more > summary::-webkit-details-marker {
  display: none;
}
.file-more > summary:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.file-more > summary .icon {
  transition: transform var(--dur) ease;
}
.file-more[open] > summary .icon {
  transform: rotate(90deg);
}
.file-more .file-list {
  padding: 0;
}

/* ---------- Empty state ---------- */
.empty {
  display: flex;
  max-width: var(--content-w);
  min-height: 320px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
  text-align: center;
}
.empty__icon {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--gray-100);
  color: var(--gray-600);
}
.empty__icon .icon {
  width: 24px;
  height: 24px;
}
.empty__title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
}
.empty__text {
  max-width: 420px;
  margin: 0 0 var(--space-2);
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-600);
}

/* ---------- Account and editor mockups ---------- */
.auth {
  display: grid;
  min-height: calc(100dvh - var(--header-h) - 2 * var(--space-6));
  align-content: start;
  justify-items: center;
  padding-top: var(--space-6);
}
@media (min-width: 640px) {
  .auth {
    padding-top: var(--space-12);
  }
}
.auth__card {
  width: min(100%, 420px);
  padding: var(--space-6);
}
@media (min-width: 640px) {
  .auth__card {
    padding: var(--space-8);
  }
}
.auth__title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 700;
}
.auth__lead {
  margin: 0 0 var(--space-6);
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-600);
}
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.form-actions .btn--primary {
  flex: 1 1 auto;
}
.fine {
  margin: var(--space-5) 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--gray-500);
}
.fine a,
.auth a:not(.btn) {
  color: var(--brand-600);
}

/* Segmented control (ui.tsx Segmented): white capsule track, ink thumb. CSS-only with radio inputs. */
.seg {
  display: inline-flex;
  max-width: 100%;
  padding: 2px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-full);
  background: var(--surface);
}
.seg--block {
  display: flex;
}
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg label {
  display: inline-flex;
  min-width: 0;
  min-height: var(--control-h);
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 clamp(8px, 2vw, var(--space-4));
  border-radius: var(--radius-full);
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--dur) ease,
    color var(--dur) ease;
}
.seg label:hover {
  color: var(--gray-900);
}
.seg input:checked + label {
  background: var(--ink);
  color: var(--on-ink);
}
.seg input:focus-visible + label {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* A label never pushes the capsule past its frame: the words get «…» before they spill out. */
.seg label > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* .seg-frame: a block around a capsule that measures the room it has (phones; wider screens give the capsule its
   natural width, and a size container would collapse an auto-width column). Under ~300 px the icons go first. */
.seg-frame {
  min-width: 0;
}
@media (max-width: 767px) {
  .seg-frame {
    container-type: inline-size;
  }
}
@container (max-width: 300px) {
  .seg label .icon {
    display: none;
  }
}

.status-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0 0 var(--space-6);
  padding: 0;
  list-style: none;
}
.status-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  font-size: 14px;
}
.status-step__dot {
  display: grid;
  width: 24px;
  height: 24px;
  flex: none;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--gray-100);
  color: var(--gray-500);
}
.status-step__dot .icon {
  width: 14px;
  height: 14px;
}
.status-step--done .status-step__dot {
  background: var(--ink);
  color: var(--on-ink);
}
.status-step--wait .status-step__dot {
  background: var(--brand-50);
  color: var(--brand-700);
}
.status-step__text {
  flex: 1;
  min-width: 0;
}
.status-step__meta {
  font-size: 12px;
  color: var(--gray-500);
}

.editor {
  display: grid;
  max-width: 1200px;
  gap: var(--space-4);
}
.editor__meta {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
}
@media (min-width: 768px) {
  .editor__meta {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }
}
.editor__switch {
  display: flex;
}
@media (min-width: 1024px) {
  .editor__switch {
    display: none;
  }
}
.editor__panes {
  display: grid;
  gap: var(--space-4);
}
@media (min-width: 1024px) {
  .editor__panes {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
.editor__pane {
  display: flex;
  min-width: 0;
  height: 560px;
  flex-direction: column;
}
.editor__pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--gray-200);
  font-size: 13px;
  font-weight: 600;
}
.editor__pane textarea {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: var(--space-4) var(--space-5);
  border: 0;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
}
.editor__pane textarea:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus);
}
.editor__preview {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
}
/* Phones and tablets: one pane at a time, picked by the «Текст | Просмотр» switch (radio inputs, no script). */
@media (max-width: 1023px) {
  #pane-text:checked ~ .editor__panes [data-pane='preview'],
  #pane-preview:checked ~ .editor__panes [data-pane='text'] {
    display: none;
  }
}
.editor__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.editor__foot .help {
  margin: 0;
}

.mockups {
  display: grid;
  max-width: 920px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.mockups a {
  display: flex;
  min-height: 120px;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  text-decoration: none;
}
.mockups a:hover {
  border-color: var(--gray-300);
  box-shadow: var(--shadow-pop);
}
.mockups b {
  font-size: 15px;
}
.mockups span {
  font-size: 13px;
  line-height: 1.5;
  color: var(--gray-600);
}

/* ---------- Small helpers ---------- */
.main:focus {
  outline: none;
}
fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
legend {
  padding: 0;
}
.btn--block {
  width: 100%;
}
.btn .icon,
.fmt .icon {
  width: 18px;
  height: 18px;
}
@media (max-width: 639px) {
  .hide-phone {
    display: none !important;
  }
}
.pill--danger {
  background: var(--red-50);
  color: var(--red-700);
}
.field--num {
  width: 56px;
  padding: 0 var(--space-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
textarea.field.field--short {
  min-height: 96px;
}
.form-actions--center {
  justify-content: center;
}
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--red-200);
  border-radius: var(--radius-lg);
  background: var(--red-50);
  font-size: 14px;
  line-height: 1.5;
  color: var(--red-700);
}
.alert .icon {
  margin-top: 1px;
}
.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 800ms linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.skeleton {
  display: block;
  border-radius: var(--radius-full);
  background: var(--gray-100);
  animation: shimmer 1400ms ease-in-out infinite;
}
@keyframes shimmer {
  50% {
    opacity: 0.55;
  }
}

/* Segmented controls whose radio inputs sit before the switch (so siblings further down can react too). */
:is(#st-idle:checked ~ * [for='st-idle'], #st-wait:checked ~ * [for='st-wait'], #st-error:checked ~ * [for='st-error'],
  #docx-text:checked ~ * [for='docx-text'], #docx-orig:checked ~ * [for='docx-orig'],
  #pane-text:checked ~ * [for='pane-text'], #pane-preview:checked ~ * [for='pane-preview']) {
  background: var(--ink);
  color: var(--on-ink);
}
:is(#st-idle:focus-visible ~ * [for='st-idle'], #st-wait:focus-visible ~ * [for='st-wait'], #st-error:focus-visible ~ * [for='st-error'],
  #docx-text:focus-visible ~ * [for='docx-text'], #docx-orig:focus-visible ~ * [for='docx-orig'],
  #pane-text:focus-visible ~ * [for='pane-text'], #pane-preview:focus-visible ~ * [for='pane-preview']) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* States of one card stacked in one grid cell: the card is as tall as its tallest state and never jumps. */
.states {
  display: grid;
}
.states--center > .states__item {
  align-self: center;
}
.states__item {
  grid-area: 1 / 1;
  min-width: 0;
  visibility: hidden;
}
#st-idle:checked ~ * [data-state='idle'],
#st-wait:checked ~ * [data-state='wait'],
#st-error:checked ~ * [data-state='error'] {
  visibility: visible;
}
.mock-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
}
.mock-switch__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
}
.mock-switch .seg {
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.mock-switch .seg label {
  min-height: 36px;
  flex: none;
  padding: 0 var(--space-3);
}
@media (max-width: 359px) {
  .mock-switch .seg label {
    padding: 0 10px;
    font-size: 12px;
  }
}
.auth > .mock-switch {
  width: min(100%, 420px);
}
.auth__card .pill {
  margin-bottom: var(--space-3);
}
.auth__card .status-steps {
  margin-bottom: var(--space-5);
}
.auth__card .states__item > .label {
  margin-top: var(--space-1);
}

/* ---------- Document viewer (plan R7) ---------- */
.viewer {
  display: flex;
  max-width: var(--page-w);
  min-width: 0;
  flex-direction: column;
  gap: var(--space-4);
}
.crumbs {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  margin: calc(-1 * var(--space-2)) 0 0;
  font-size: 13px;
  color: var(--gray-500);
}
.crumbs__back {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 6px;
  margin-left: calc(-1 * var(--space-3));
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 600;
  color: var(--gray-900);
  text-decoration: none;
}
.crumbs__back:hover {
  background: var(--gray-100);
}
.crumbs__back + .crumbs__sep {
  margin-left: calc(-1 * var(--space-3));
}
.crumbs__here {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer__head {
  min-width: 0;
}
.viewer__headrow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}
.viewer__headrow .viewer__title {
  min-width: 0;
  margin: 0;
}
/* The 44 px «⋯» hangs into the title's line box (negative margins), so the meta line sits as close to the title for
   the author as for a reader: the header is one height whatever the role. */
.viewer__manage {
  flex: none;
  margin-block: -10px;
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .viewer__manage {
    margin-block: -8px;
  }
}
.viewer__title {
  font-size: 20px;
}
@media (min-width: 640px) {
  .viewer__title {
    font-size: 22px;
  }
}
.viewer__meta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--gray-500);
}
/* Toolbar: sticky under the header; groups of round buttons; search drops below it without moving the page. */
.viewer-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  display: flex;
  min-height: 61px;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 calc(-1 * var(--space-4));
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--gray-200);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
@media (min-width: 640px) {
  .viewer-bar {
    margin: 0;
    padding: var(--space-2);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-full);
    background: var(--surface);
    box-shadow: var(--shadow-card);
    top: calc(var(--header-h) + var(--space-2));
  }
}
.viewer-bar__group {
  display: flex;
  align-items: center;
  gap: 2px;
}
.viewer-bar__group + .viewer-bar__group {
  padding-left: var(--space-2);
  border-left: 1px solid var(--gray-200);
}
.viewer-bar__end {
  margin-left: auto;
  gap: var(--space-1);
}
.viewer-bar__end.viewer-bar__group {
  border-left: 0;
}
.viewer-bar__of {
  padding: 0 var(--space-2);
  font-size: 13px;
  color: var(--gray-600);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.viewer-bar__zoom {
  min-width: 52px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.viewer-bar .icon-btn[disabled] {
  opacity: 0.4;
  cursor: default;
}
.viewer-bar .seg label {
  min-height: 40px;
}
@media (any-pointer: coarse) {
  .viewer-bar .seg label {
    min-height: 44px;
  }
}
.viewer-search {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 11;
  display: flex;
  width: min(420px, calc(100vw - 2 * var(--space-4)));
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  box-shadow: var(--shadow-pop);
  animation: pop-down 160ms var(--ease-out-soft) both;
}
@media (max-width: 639px) {
  .viewer-search {
    right: var(--space-4);
  }
}
.viewer-search__field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.viewer-search .field {
  padding-right: 72px;
}
.viewer-search .field::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
/* «3 из 12» / «Нет совпадений» inside the field on the right: the field never shrinks when it appears. */
.viewer-search__count {
  position: absolute;
  top: 50%;
  right: var(--space-3);
  max-width: 64px;
  overflow: hidden;
  font-size: 12px;
  color: var(--gray-500);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transform: translateY(-50%);
  pointer-events: none;
}
.viewer-search .icon-btn {
  flex: none;
}
/* Narrow phones: the zoom buttons go (pinch zooms), so page, search and download stay in one row. */
@media (max-width: 359px) {
  .viewer-bar__group--zoom {
    display: none;
  }
  .viewer-search {
    gap: 0;
  }
  .viewer-search .icon-btn {
    width: 40px;
  }
  .viewer-bar__of {
    padding: 0 var(--space-1) 0 var(--space-2);
  }
}

/* DOCX with a PDF twin: one toolbar for both views. The slot holds the note («Текст») and the PDF controls
   («Как в оригинале») in one grid cell; the hidden one keeps its room, so the bar never changes height.
   Below 1280 the slot takes its own full row (same in both views); from 1280 everything fits in one row. */
.viewer-bar__slot {
  display: grid;
  min-width: 0;
  align-items: center;
}
.viewer-bar__slot > * {
  grid-area: 1 / 1;
  min-width: 0;
}
.viewer-bar__pdf {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.viewer-bar__note {
  margin: 0;
  padding: 0 var(--space-2);
  overflow: hidden;
  font-size: 13px;
  color: var(--gray-500);
  text-overflow: ellipsis;
  white-space: nowrap;
}
#docx-text:checked ~ .viewer-bar .viewer-bar__pdf,
#docx-orig:checked ~ .viewer-bar .viewer-bar__note {
  visibility: hidden;
}
@media (max-width: 1279px) {
  .viewer-bar--docx .viewer-bar__slot {
    order: 2;
    flex: 1 1 100%;
  }
  .viewer-bar--docx .viewer-bar__pdf .viewer-bar__end {
    margin-left: auto;
  }
}
@media (min-width: 1280px) {
  .viewer-bar--docx .viewer-bar__slot {
    padding-left: var(--space-2);
    border-left: 1px solid var(--gray-200);
  }
}
@media (min-width: 640px) and (max-width: 1279px) {
  .viewer-bar--docx {
    border-radius: var(--radius-2xl);
  }
}
.viewer-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 13px;
  color: var(--gray-500);
}

/* PDF pages: A4 ratio, fit to width (zoom = scale of the width), always white like paper. */
.pdf-stage {
  --pdf-zoom: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin: 0 calc(-1 * var(--space-4));
  padding: 0 var(--space-4);
  overflow-x: auto;
}
@media (min-width: 640px) {
  .pdf-stage {
    margin: 0;
    padding: 0;
  }
}
.pdf-page {
  position: relative;
  width: calc(100% * var(--pdf-zoom));
  max-width: calc(880px * var(--pdf-zoom));
  flex: none;
  scroll-margin-top: calc(var(--header-h) + 88px);
}
.pdf-page__sheet {
  display: flex;
  aspect-ratio: 210 / 297;
  flex-direction: column;
  gap: 2.2%;
  padding: 9% 10%;
  border-radius: var(--radius-sm);
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--gray-200), var(--shadow-card);
}
.pdf-page__sheet .line {
  display: block;
  height: 1.5%;
  border-radius: 2px;
  background: #e8e9ef;
}
.pdf-page__sheet .line:nth-child(1) {
  width: 58%;
  height: 3%;
  margin-bottom: 3%;
  background: #d5d7df;
}
.pdf-page__sheet .line:nth-child(3n) {
  width: 86%;
}
.pdf-page__sheet .line:nth-child(4n) {
  width: 72%;
}
.pdf-page__sheet .line:nth-child(7) {
  height: 22%;
  margin: 2% 0;
  border-radius: 6px;
  background: #f0f1f5;
}
.pdf-page__no {
  position: absolute;
  right: var(--space-3);
  bottom: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: rgb(9 9 9 / 0.6);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
[aria-busy='true'] .pdf-page__sheet .line {
  animation: shimmer 1400ms ease-in-out infinite;
}

/* DOCX reading view */
.doc-text {
  padding: var(--space-5) var(--space-4);
}
@media (min-width: 640px) {
  .doc-text {
    padding: var(--space-8) var(--space-10);
  }
}
.doc-text figure {
  margin: var(--space-4) 0;
}
.doc-text .figure-ph {
  display: grid;
  height: clamp(120px, 28vw, 240px);
  place-items: center;
  border: 1px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
  color: var(--gray-400);
}
.doc-text figcaption {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--gray-500);
  text-align: center;
}
#docx-text:checked ~ [data-view='orig'],
#docx-orig:checked ~ [data-view='text'] {
  display: none;
}

/* Code view: line numbers by CSS counter, horizontal scroll inside unless wrapped. */
.code {
  overflow: hidden;
}
.code__pre {
  margin: 0;
  padding: var(--space-4) 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  counter-reset: line;
  tab-size: 4;
}
.code__pre code {
  display: block;
  min-width: max-content;
}
.code__line {
  display: block;
  padding-right: var(--space-4);
  counter-increment: line;
}
.code__line::before {
  content: counter(line);
  display: inline-block;
  width: 4ch;
  margin-right: var(--space-4);
  padding-right: var(--space-2);
  border-right: 1px solid var(--gray-200);
  color: var(--gray-400);
  text-align: right;
  user-select: none;
}
.code.is-wrapped code {
  min-width: 0;
}
.code.is-wrapped .code__line {
  padding-left: calc(4ch + var(--space-6));
  text-indent: calc(-4ch - var(--space-6));
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.code.is-wrapped .code__line::before {
  text-indent: 0;
}
.tok-c {
  color: var(--gray-500);
  font-style: italic;
}
.tok-s {
  color: var(--green-700);
}
.tok-k {
  color: var(--brand-600);
  font-weight: 600;
}
.tok-p {
  color: var(--amber-700);
}

/* Gallery + lightbox */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(46%, 200px), 1fr));
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.gallery button {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--gray-100);
  cursor: zoom-in;
}
.gallery img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 240ms var(--ease-out-soft);
}
@media (hover: hover) {
  .gallery button:hover img {
    transform: scale(1.03);
  }
}
.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #0b0b0c;
  color: #f5f6fa;
}
.lightbox[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  animation: fade-in 180ms ease both;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
.lightbox::backdrop {
  background: #0b0b0c;
}
.lightbox__bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-5);
}
.lightbox__count {
  margin-right: auto;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.lightbox .icon-btn {
  color: #f5f6fa;
}
.lightbox .icon-btn:hover {
  background: rgb(255 255 255 / 0.12);
  color: #fff;
}
.lightbox .btn--secondary {
  border-color: rgb(255 255 255 / 0.25);
  background: transparent;
  color: #f5f6fa;
}
.lightbox .btn--secondary:hover {
  border-color: #fff;
  background: rgb(255 255 255 / 0.08);
}
.lightbox__stage {
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 0 var(--space-2) var(--space-4);
  overflow: auto;
  touch-action: pan-y pinch-zoom;
}
.lightbox__stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.lightbox__nav {
  position: fixed;
  top: 50%;
  background: rgb(0 0 0 / 0.4);
  transform: translateY(-50%);
}
.lightbox__nav--prev {
  left: var(--space-3);
}
.lightbox__nav--next {
  right: var(--space-3);
}
@media (any-pointer: coarse) {
  .lightbox__nav {
    display: none;
  }
}

/* Error block: the size of a document area */
.doc-error {
  display: grid;
  min-height: 420px;
  place-items: center;
  padding: var(--space-8) var(--space-6);
  text-align: center;
}
.doc-error .states__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.doc-error .empty__icon .icon {
  width: 24px;
  height: 24px;
}

/* Prev / next document */
.pager {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
@media (min-width: 640px) {
  .pager {
    grid-template-columns: 1fr 1fr;
  }
}
.pager__link {
  display: flex;
  min-height: 72px;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: var(--space-3) var(--space-5);
  text-decoration: none;
  transition:
    border-color var(--dur) ease,
    box-shadow var(--dur) ease;
}
.pager__link:hover {
  border-color: var(--gray-300);
  box-shadow: var(--shadow-pop);
}
.pager__link--next {
  align-items: flex-end;
  text-align: right;
}
@media (min-width: 640px) {
  .pager__link--next:only-child {
    grid-column: 2;
  }
}
.pager__dir {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  line-height: 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
}
.pager__name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- App pages (server-rendered, wave 2c) ---------- */

/* Header: «Войти» or the account menu (a <details>; the panel drops under the header, nothing moves). */
.header-login {
  flex: none;
}
.header-login__icon {
  display: none;
}
/* Narrow phones: «Войти» stays a text capsule (a bare key icon did not read as sign-in), just tighter. */
@media (max-width: 419px) {
  .header-login {
    padding: 0 var(--space-3);
  }
}
.avatar {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: none;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.avatar--lg {
  width: 40px;
  height: 40px;
  font-size: 15px;
}
.account {
  position: relative;
}
.account__btn {
  position: relative;
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius-full);
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.account__btn::-webkit-details-marker {
  display: none;
}
.account__btn:hover .avatar {
  box-shadow: 0 0 0 3px var(--gray-200);
}
.account__dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--canvas);
  border-radius: var(--radius-full);
  background: var(--brand-600);
}
.account__pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 45;
  width: min(280px, calc(100vw - 2 * var(--space-3)));
  padding: var(--space-2);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-pop);
  animation: pop-down 160ms var(--ease-out-soft) both;
}
.account__who {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: var(--space-1);
}
.account__name {
  display: flex;
  min-width: 0;
  flex-direction: column;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.account__role {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
}
.account__links {
  margin: 0;
  padding: 0;
  list-style: none;
}
.account__out {
  margin: var(--space-1) 0 0;
  padding-top: var(--space-1);
  border-top: 1px solid var(--gray-200);
}
.account__link {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-800);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.account__link > span:not(.pill) {
  flex: 1;
}
.account__link:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.account__link .icon {
  color: var(--gray-500);
}

/* Search dropdown: «Все результаты по …» pinned to the bottom (sticky inside the scrolling dropdown) with a fade
   above it, so a row cut mid-line reads as «scroll for more»; the empty state with a hint. */
.search__pop {
  padding-bottom: 0;
  scroll-padding-bottom: 72px;
}
.search__pop.at-end .search__full::before {
  opacity: 0;
}
.search__full {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: var(--space-1);
  padding: var(--space-1) 0 6px;
  border-top: 1px solid var(--gray-200);
  background: var(--surface);
}
.search__full::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  height: 28px;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--surface) 0%, transparent), var(--surface));
  pointer-events: none;
}
.search__item--full .search__title {
  color: var(--brand-600);
  font-weight: 600;
}
.search__empty-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
}
.search__empty-hint {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--gray-500);
}
div.search__empty {
  padding: var(--space-3) var(--space-4) var(--space-2);
}

/* Search page */
.search-page {
  display: flex;
  max-width: var(--content-w);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.search-page__field {
  position: relative;
  flex: 1;
  min-width: 0;
}
.search-page__total {
  min-height: 20px;
  margin: 0 0 var(--space-3);
  font-size: 13px;
  color: var(--gray-500);
}
.results {
  max-width: var(--content-w);
  margin-bottom: var(--space-4);
  padding: var(--space-2);
}
.results__title {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
}
.results__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.result {
  display: flex;
  min-height: 56px;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  text-decoration: none;
}
.result:hover {
  background: var(--gray-50);
}
.result__title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.result__sub {
  font-size: 12px;
  color: var(--gray-500);
}
.result__snippet {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--gray-600);
}
.result__snippet mark {
  border-radius: 3px;
  background: var(--amber-50);
  color: var(--gray-900);
  font-weight: 600;
}

/* Home: subject cards and «Продолжить» (three fixed slots). On phones a returning reader sees «Продолжить» first. */
.home {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
@media (max-width: 639px) {
  .has-recent .home .recent {
    order: -1;
  }
}
.recent {
  max-width: var(--page-w);
  padding: var(--space-2);
}
.recent__head {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-2) 0 var(--space-3);
}
.recent__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.recent__body {
  display: grid;
  height: calc(3 * 56px + 2 * 2px);
}
.recent__body > * {
  grid-area: 1 / 1;
}
.recent__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  animation: fade-in 180ms ease both;
}
.recent__item {
  display: flex;
  height: 56px;
  flex-direction: column;
  justify-content: center;
  padding: 0 var(--space-3);
  border-radius: var(--radius-lg);
  text-decoration: none;
}
.recent__item:hover {
  background: var(--gray-50);
}
.recent__name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent__sub {
  overflow: hidden;
  font-size: 12px;
  color: var(--gray-500);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin: 0;
  padding: 0 var(--space-4);
  border: 1px dashed var(--gray-200);
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-500);
  text-align: left;
}
.recent__empty .icon {
  color: var(--gray-400);
}
.subject-grid__empty {
  grid-column: 1 / -1;
}

/* Prep page extras */
.prep-foot {
  margin: var(--space-8) 0 0;
  font-size: 12px;
  color: var(--gray-500);
}
.btn--toggle[aria-pressed='true'] {
  border-color: var(--gray-900);
  background: var(--gray-100);
  color: var(--gray-900);
}
.btn--toggle[aria-pressed='true']:hover {
  background: var(--gray-200);
}

/* Documents: rows with two formats put their pills under the name on phones; photos are a thumbnail grid. */
.file-row__text {
  display: flex;
  min-width: 0;
  flex-direction: column;
}
.file-row__meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
}
@media (max-width: 639px) {
  .file-row--multi .file-row__formats {
    width: 100%;
    margin-left: 0;
    padding-left: calc(20px + var(--space-3));
  }
}
.thumbs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-1) var(--space-4) var(--space-3);
  list-style: none;
}
@media (min-width: 640px) {
  .thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding-inline: var(--space-5);
  }
}
@media (min-width: 1024px) {
  .thumbs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--gray-100);
  cursor: zoom-in;
}
.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 240ms var(--ease-out-soft);
}
@media (hover: hover) {
  .thumb:hover img {
    transform: scale(1.03);
  }
}
.thumb.is-current {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.file-locked {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: var(--space-1) var(--space-2) var(--space-2);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
}
.file-locked__icon {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--gray-600);
  box-shadow: 0 0 0 1px var(--gray-200);
}
.file-locked__icon .icon {
  width: 18px;
  height: 18px;
}
.file-locked__text {
  flex: 1 1 220px;
  min-width: 0;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-700);
}

/* Notes */
.note-list {
  display: flex;
  max-width: var(--page-w);
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}
.note-card {
  position: relative;
  padding: var(--space-4) var(--space-5);
}
.note-card__title {
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.note-card__title::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.note-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin: var(--space-2) 0 0;
  font-size: 13px;
  color: var(--gray-500);
}
.note-card__meta .pill {
  gap: 4px;
}
.icon--xs {
  width: 14px;
  height: 14px;
}
.note-view {
  display: flex;
  max-width: var(--page-w);
  flex-direction: column;
  gap: var(--space-4);
}
.note-view__top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}
.note-view__top .note-view__title {
  min-width: 0;
  flex: 1 1 240px;
}
.note-view__act {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.note-view__title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 20px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.note-view__body {
  padding: var(--space-5) var(--space-4);
}
@media (min-width: 640px) {
  .note-view__body {
    padding: var(--space-8) var(--space-10);
  }
}

/* «Правила» */
.rules {
  max-width: var(--page-w);
  padding: var(--space-5) var(--space-4);
}
/* Reading measure inside wide cards: the card follows the page column, the lines stay ~70 characters. */
.rules > *,
.note-view__body > *,
.doc-text > * {
  max-width: var(--content-w);
}
@media (min-width: 640px) {
  .rules {
    padding: var(--space-8) var(--space-10);
  }
}
.rules h2:first-child {
  margin-top: 0;
}

/* Account cards */
.auth__card--wide {
  width: min(100%, 480px);
}
.auth__out {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--gray-200);
}
.help--row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}
.help--row > :last-child {
  font-variant-numeric: tabular-nums;
}
.auth__card .help {
  text-align: center;
}
.auth__card .about-form .help {
  text-align: left;
}
[data-login] .states__item {
  visibility: hidden;
}
[data-login][data-state='idle'] [data-state-item='idle'],
[data-login][data-state='wait'] [data-state-item='wait'],
[data-login][data-state='error'] [data-state-item='error'] {
  visibility: visible;
}
.auth__card .alert {
  margin-bottom: var(--space-3);
}
.btn[aria-busy='true'] {
  cursor: progress;
}

/* Admin: users. Under the «Управление» tab strip, a row of filter capsules: Заявки, Одобренные, Заблокированы. */
.subtabs {
  max-width: var(--page-w);
  margin: calc(-1 * var(--space-1)) calc(-1 * var(--space-4)) var(--space-4);
  padding-inline: var(--space-4);
}
@media (min-width: 640px) {
  .subtabs {
    margin-inline: 0;
    padding-inline: 0;
  }
}
.subtab {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--dur) ease,
    border-color var(--dur) ease,
    color var(--dur) ease;
}
@media (min-width: 640px) and (pointer: fine) and (not (any-pointer: coarse)) {
  .subtab {
    min-height: 36px;
  }
}
.subtab:hover {
  border-color: var(--gray-300);
  color: var(--gray-900);
}
.subtab[aria-current='page'] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--on-ink);
}
.subtab__count {
  font-weight: 500;
  opacity: 0.7;
}

/* Admin: users */
.notice {
  display: flex;
  max-width: var(--page-w);
  min-height: 24px;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  font-size: 14px;
  color: var(--green-700);
  opacity: 0;
  transition: opacity var(--dur) ease;
}
.notice.is-shown {
  opacity: 1;
}
.alert--warn {
  max-width: var(--page-w);
  margin-bottom: var(--space-3);
  border-color: var(--amber-200);
  background: var(--amber-50);
  color: var(--amber-700);
}
.user-list {
  display: flex;
  max-width: var(--page-w);
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}
.user-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--space-3) var(--space-4);
  padding: var(--space-4);
}
@media (min-width: 768px) {
  .user-row {
    grid-template-columns: auto minmax(0, 1fr) 260px;
    padding: var(--space-4) var(--space-5);
  }
}
.user-row__main {
  min-width: 0;
}
.user-row__name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.user-row__meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--gray-500);
}
.user-row__about {
  margin: var(--space-2) 0 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--gray-700);
  overflow-wrap: anywhere;
}
.user-row__about--empty {
  color: var(--gray-500);
  font-style: italic;
}
/* Actions keep their column: approving does not reflow the row. */
.user-row__actions {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}
@media (min-width: 768px) {
  .user-row__actions {
    grid-column: auto;
    align-self: center;
  }
}
.user-row__actions form {
  margin: 0;
}
.btn--danger {
  color: var(--red-700);
}
.btn--danger:hover {
  background: var(--red-50);
  color: var(--red-700);
}
.list-pager {
  display: flex;
  max-width: var(--page-w);
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.list-pager:empty {
  display: none;
}
.empty__code {
  margin: var(--space-2) 0 0;
  font-size: 12px;
  color: var(--gray-500);
}
.empty {
  max-width: var(--page-w);
}

/* Viewer: shared pieces */
.viewer-bar {
  position: sticky;
}
.viewer-bar__progress {
  position: absolute;
  left: var(--space-5);
  right: var(--space-5);
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}
.viewer-bar__progress::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--brand-600);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
  transition: transform 240ms ease;
}
.viewer-bar.is-loading .viewer-bar__progress,
.viewer-bar__pdf.is-loading .viewer-bar__progress {
  opacity: 1;
}
.icon-btn--outline {
  box-shadow: inset 0 0 0 1px var(--gray-300);
  color: var(--gray-900);
}
.doc-error__body {
  display: flex;
  max-width: 460px;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.doc-error {
  min-height: 360px;
}

/* PDF: placeholder pages are grey and shimmer; drawn pages are white paper with a canvas and a text layer.
   A page is as wide as the toolbar above it (the page column). Zoomed pages grow to the right from the left edge
   (auto margins collapse to 0 when a page is wider than the stage), so line starts are never cut off. */
.pdf-stage {
  align-items: flex-start;
  touch-action: pan-x pan-y;
  transform-origin: 50% 0;
}
.pdf-page {
  width: calc(100% * var(--pdf-zoom));
  max-width: none;
  margin-inline: auto;
}
.pdf-page__sheet {
  position: relative;
  display: block;
  aspect-ratio: var(--ratio, 210 / 297);
  padding: 0;
  overflow: hidden;
  background: #ffffff;
}
.pdf-page__sheet.is-loading {
  background: var(--gray-100);
  box-shadow: 0 0 0 1px var(--gray-200);
  animation: shimmer 1400ms ease-in-out infinite;
}
.pdf-page__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.pdf-page__sheet .textLayer {
  position: absolute;
  inset: 0;
  overflow: clip;
  line-height: 1;
  text-align: initial;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 1;
  opacity: 1;
}
.pdf-page__sheet .textLayer :is(span, br) {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.pdf-page__sheet .textLayer span.markedContent {
  top: 0;
  height: 0;
}
.pdf-page__sheet .textLayer .highlight {
  margin: -1px;
  padding: 1px;
  border-radius: 4px;
  background: rgb(255 196 0 / 0.38);
}
.pdf-page__sheet .textLayer .highlight.selected {
  background: rgb(22 0 237 / 0.28);
}
.pdf-page__sheet .textLayer ::selection {
  background: rgb(22 0 237 / 0.25);
}
.pdf-page__sheet .textLayer .endOfContent {
  position: absolute;
  inset: 100% 0 0;
  display: block;
  cursor: default;
  user-select: none;
}
.pdf-page__no {
  z-index: 2;
}
.pdf-stage .pdf-page {
  scroll-margin-top: calc(var(--header-h) + 80px);
}
.docx-orig {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
#docx-text:checked ~ [data-view='orig'],
#docx-orig:checked ~ [data-view='text'] {
  display: none;
}

/* Code: Pygments output (.hl) with line numbers by counter; wrapped lines get a hanging indent. */
.code__scroll {
  overflow-x: auto;
}
.code .hl pre {
  margin: 0;
  padding: var(--space-4) 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 4;
  counter-reset: line;
}
.code .hl code {
  display: block;
  min-width: max-content;
  font-family: inherit;
}
.code .hl code > span[id^='L-'] {
  display: block;
  padding-right: var(--space-4);
  counter-increment: line;
}
.code .hl code > span[id^='L-']::before {
  content: counter(line);
  display: inline-block;
  box-sizing: content-box;
  width: 4ch;
  margin-right: var(--space-4);
  padding-right: var(--space-2);
  border-right: 1px solid var(--gray-200);
  color: var(--gray-500);
  text-align: right;
  user-select: none;
}
.code .hl code > span[id^='L-']:target {
  background: var(--amber-50);
}
.code.is-wrapped .hl code {
  min-width: 0;
}
.code.is-wrapped .hl code > span[id^='L-'] {
  /* gutter = number (4ch) + its padding and hairline + gap; wrapped parts hang 2ch further in */
  --gut: calc(4ch + var(--space-2) + 1px + var(--space-4));
  padding-left: calc(var(--gut) + 2ch);
  text-indent: calc(-1 * var(--gut) - 2ch);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.code.is-wrapped .hl code > span[id^='L-']::before {
  text-indent: 0;
}

/* HTML documents in a frame: the card's paper (the frame page wears the site skin), height set by viewer.js */
.html-frame {
  position: relative;
  overflow: hidden;
  min-height: 480px;
}
.html-frame iframe {
  display: block;
  width: 100%;
  height: 480px;
  border: 0;
  border-radius: inherit;
  background: var(--surface);
}
.html-frame.is-loading::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--gray-100);
  animation: shimmer 1400ms ease-in-out infinite;
}

/* Photo page: the photo at its own ratio (no jump while it loads), a strip of the group under it. */
.photo-hero {
  margin: 0;
  padding: 0;
  list-style: none;
}
.photo-hero__frame {
  display: block;
  max-height: calc(100dvh - var(--header-h) - 180px);
  margin-inline: auto;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-xl);
  background: var(--gray-100);
}
.photo-hero__frame img {
  object-fit: contain;
}
.photo-strip__title {
  margin: 0 0 var(--space-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
}
.thumbs--strip {
  display: flex;
  gap: var(--space-2);
  padding: 0 0 var(--space-2);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.thumbs--strip > li {
  flex: none;
  width: 104px;
  scroll-snap-align: center;
}

/* Lightbox: one icon-button style for every control; counter and prev/next on phones too. */
.lightbox[open] {
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.lightbox__bar {
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
}
.lightbox__btn {
  color: #f5f6fa;
}
.lightbox__btn[disabled] {
  opacity: 0.35;
  cursor: default;
}
.lightbox__stage {
  touch-action: none;
  overflow: hidden;
  user-select: none;
}
.lightbox__stage img {
  transition: transform 160ms ease-out, opacity 160ms ease;
  will-change: transform;
}
.lightbox.is-zoomed .lightbox__stage img {
  cursor: grab;
}
.lightbox__stage img.is-swapping {
  opacity: 0.4;
}
.lightbox__caption {
  min-height: 20px;
  margin: 0;
  padding: 0 var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  font-size: 13px;
  color: rgb(245 246 250 / 0.7);
  text-align: center;
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
@media (prefers-reduced-motion: no-preference) {
  html.is-loaded {
    scroll-behavior: smooth;
  }
}

@media print {
  .side-nav,
  .app-header,
  .bottom-bar,
  .prep-bar,
  .toc-panel,
  .section-header .tabs {
    display: none !important;
  }
  body,
  html {
    background: #fff;
  }
  .main {
    padding: 0;
  }
}
