/*
 * Раздел «Тесты»: публичный хаб, вкладка обучения и рабочие страницы.
 * Компоненты ui-card/ui-btn остаются владельцами своих стилей.
 */

.th-page__title {
  font-size: var(--ui-font-size-3xl);
  font-weight: var(--ui-font-weight-bold);
  margin: 0 0 var(--ui-space-4);
}

.th {
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-4);
  min-width: 0;
}

/* ---------- направления и предметы ---------- */
.th-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--ui-space-3);
}

.th-switch {
  align-self: flex-start;
  background: var(--ui-surface-muted);
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-pill);
  display: inline-flex;
  gap: var(--ui-space-1);
  max-width: 100%;
  overflow-x: auto;
  padding: var(--ui-space-1);
}

.th-switch__item {
  border-radius: var(--ui-radius-pill);
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-lg);
  font-weight: var(--ui-font-weight-bold);
  letter-spacing: var(--ui-font-tracking-wide);
  padding: var(--ui-space-1) var(--ui-space-5);
  text-decoration: none;
  transition: background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
  white-space: nowrap;
}

.th-switch__item:hover {
  background: var(--ui-state-hover-bg);
  color: var(--ui-text-primary);
}

.th-switch__item.is-active {
  background: var(--ui-btn-primary-bg);
  box-shadow: var(--ui-shadow-sm);
  color: var(--ui-btn-primary-text);
}

.th-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
}

.th-pill {
  background: var(--ui-surface-card);
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-pill);
  color: var(--ui-text-primary);
  font-size: var(--ui-font-size-sm);
  padding: var(--ui-space-1) var(--ui-space-4);
  text-decoration: none;
  transition: border-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
}

.th-pill:hover {
  border-color: var(--ui-color-action);
  color: var(--ui-text-primary);
}

.th-pill.is-active {
  background: var(--ui-color-action-muted);
  border-color: var(--ui-color-action);
  font-weight: var(--ui-font-weight-semibold);
}

.th-switch__item:focus-visible,
.th-pill:focus-visible,
.th-views__item:focus-visible,
.th-variant:focus-visible,
.th-step__btn:focus-visible {
  box-shadow: var(--ui-focus-ring);
  outline: 0;
}

/* ---------- шапка экзамена ---------- */
.th-exam {
  display: grid;
  gap: var(--ui-space-3) var(--ui-space-6);
  grid-template-columns: minmax(0, 1fr) auto;
}

.th-exam__title {
  font-size: var(--ui-font-size-2xl);
  font-weight: var(--ui-font-weight-bold);
  margin: 0 0 var(--ui-space-1);
}

.th-exam__meta {
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-sm);
  margin: 0;
}

.th-exam__format { align-self: start; }

.th-exam__format[open] { grid-column: 1 / -1; }

.th-views {
  border-bottom: 1px solid var(--ui-border-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-1) var(--ui-space-4);
}

.th-views__item {
  border-bottom: 2px solid transparent;
  color: var(--ui-text-secondary);
  font-weight: var(--ui-font-weight-medium);
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  text-decoration: none;
}

.th-views__item:hover { color: var(--ui-text-primary); }

.th-views__item[aria-current="page"] {
  border-bottom-color: var(--ui-color-action);
  color: var(--ui-text-primary);
}

/* ---------- карточки ---------- */
.th-card__head {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2) var(--ui-space-3);
  justify-content: space-between;
}

.th-card__title {
  font-size: var(--ui-font-size-xl);
  font-weight: var(--ui-font-weight-bold);
  margin: 0;
}

.th-card__lead {
  color: var(--ui-text-secondary);
  margin: 0;
}

.th-note {
  color: var(--ui-text-muted);
  font-size: var(--ui-font-size-sm);
  margin: 0;
}

.th-back {
  font-size: var(--ui-font-size-sm);
  white-space: nowrap;
}

.th-pair {
  display: grid;
  gap: var(--ui-space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}

.th-inline-form {
  display: flex;
  gap: var(--ui-space-2);
  margin-top: auto;
}

.th-inline-form .ui-input { flex: 1 1 auto; min-width: 0; }

/* ---------- решайте задания (плитки номеров) ---------- */
.th-pick__form {
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-3);
}

.th-pick__numbers {
  border: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
  margin: 0;
  padding: 0;
}

.th-pick__numbers legend {
  float: none;
  margin-bottom: var(--ui-space-2);
  width: 100%;
}

.th-chip {
  cursor: pointer;
  margin: 0;
  position: relative;
}

.th-chip__input {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.th-chip__face {
  align-items: center;
  background: var(--ui-surface-card);
  border: 2px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-control);
  box-shadow: 0 3px 0 var(--ui-border-strong);
  color: var(--ui-text-primary);
  display: inline-flex;
  font-size: var(--ui-font-size-md);
  font-variant-numeric: tabular-nums;
  font-weight: var(--ui-font-weight-semibold);
  height: 2.75rem;
  justify-content: center;
  min-width: 2.75rem;
  padding: 0 var(--ui-space-2);
  transition: background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), border-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), box-shadow var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), transform var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
}

.th-chip:hover .th-chip__face { border-color: var(--ui-color-action); }

.th-chip__input:focus-visible + .th-chip__face { box-shadow: var(--ui-focus-ring); }

.th-chip__input:checked + .th-chip__face {
  background: var(--ui-btn-primary-bg);
  border-color: var(--ui-btn-primary-border);
  box-shadow: 0 1px 0 var(--ui-btn-primary-border);
  color: var(--ui-btn-primary-text);
  transform: translateY(2px);
}

.th-chip.is-empty { cursor: default; }

.th-chip.is-empty .th-chip__face {
  border-style: dashed;
  box-shadow: none;
  color: var(--ui-text-muted);
}

/* ---------- статистика под плитками (hub.STAT_TONES) ---------- */
.th-pick__numbers { row-gap: var(--ui-space-3); }

.th-stat-dot {
  --th-stat-color: var(--ui-border-strong);
  background: var(--th-stat-color);
  border-radius: var(--ui-radius-pill);
  display: inline-block;
  flex: none;
  height: 0.5rem;
  width: 1.25rem;
}

.th-stat-dot--good { --th-stat-color: var(--ui-color-success); }
.th-stat-dot--mid { --th-stat-color: var(--ui-color-warning); }
.th-stat-dot--low { --th-stat-color: var(--ui-color-danger); }

.th-chip__stat {
  bottom: -0.3rem;
  box-shadow: 0 0 0 2px var(--ui-surface-card);
  left: 50%;
  pointer-events: none;
  position: absolute;
  transform: translateX(-50%);
}

.th-chip.is-empty .th-chip__stat { opacity: 0.5; }

.th-pick__heading {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2) var(--ui-space-3);
}

.th-stat-help { position: relative; }

.th-stat-help > summary { list-style: none; }
.th-stat-help > summary::-webkit-details-marker { display: none; }

.th-stat-help__body {
  background: var(--ui-surface-card);
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-control);
  box-shadow: var(--ui-shadow-md);
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-sm);
  margin-top: var(--ui-space-2);
  max-width: 22rem;
  padding: var(--ui-space-3) var(--ui-space-4);
  position: absolute;
  right: 0;
  width: max-content;
  z-index: 5;
}

.th-stat-help__body p { margin: 0 0 var(--ui-space-2); }
.th-stat-help__body p:last-child { margin-bottom: 0; }

.th-stat-help__legend {
  display: grid;
  gap: var(--ui-space-1);
  list-style: none;
  margin: 0 0 var(--ui-space-2);
  padding: 0;
}

.th-stat-help__legend li {
  align-items: center;
  display: flex;
  gap: var(--ui-space-2);
}

.th-pick__bar {
  align-items: stretch;
  display: flex;
  gap: var(--ui-space-3);
}

.th-pick__level { flex: 1 1 auto; margin: 0; }
.th-pick__level .ui-select { height: 100%; }
.th-pick__submit { min-width: 10rem; }

.th-switch-toggle {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  gap: var(--ui-space-2);
  margin: 0;
  position: relative;
}

.th-switch-toggle input {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.th-switch-toggle__track {
  background: var(--ui-border-strong);
  border-radius: var(--ui-radius-pill);
  flex: none;
  height: 1.375rem;
  position: relative;
  transition: background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
  width: 2.5rem;
}

.th-switch-toggle__track::after {
  background: var(--ui-surface-card);
  border-radius: var(--ui-radius-circle);
  box-shadow: var(--ui-shadow-sm);
  content: "";
  height: 1rem;
  left: 0.1875rem;
  position: absolute;
  top: 0.1875rem;
  transition: transform var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
  width: 1rem;
}

.th-switch-toggle input:checked + .th-switch-toggle__track { background: var(--ui-btn-primary-bg); }
.th-switch-toggle input:checked + .th-switch-toggle__track::after { transform: translateX(1.125rem); }
.th-switch-toggle input:focus-visible + .th-switch-toggle__track { box-shadow: var(--ui-focus-ring); }

/* ---------- тренировочные варианты ---------- */
.th-variants {
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-3);
}

.th-variants__grid {
  display: grid;
  gap: var(--ui-space-2);
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
}

.th-variant {
  background: var(--ui-btn-secondary-bg);
  border: 1px solid var(--ui-btn-secondary-border);
  border-radius: var(--ui-btn-radius);
  color: var(--ui-btn-secondary-text);
  cursor: pointer;
  font-weight: var(--ui-font-weight-semibold);
  min-height: var(--ui-btn-height);
  padding: var(--ui-space-2) var(--ui-space-3);
  transition: background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), border-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard), color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
}

.th-variant:hover {
  background: var(--ui-color-action-muted);
  border-color: var(--ui-color-action);
}

.th-variant:disabled {
  cursor: default;
  opacity: var(--ui-state-disabled-opacity);
}

.th-personal {
  align-items: center;
  border-top: 1px dashed var(--ui-border-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2) var(--ui-space-3);
  padding-top: var(--ui-space-3);
}

.th-personal form {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2) var(--ui-space-3);
}

/* ---------- конструктор ---------- */
.th-builder {
  display: grid;
  gap: var(--ui-space-4) var(--ui-space-6);
  grid-template-columns: minmax(0, 1fr) 15rem;
  grid-template-areas: "choices options" "choices submit";
  grid-template-rows: auto 1fr;
}

.th-builder__colhead {
  color: var(--ui-text-muted);
  display: grid;
  font-size: var(--ui-font-size-xs);
  font-weight: var(--ui-font-weight-semibold);
  gap: var(--ui-space-3);
  grid-template-columns: 7.5rem minmax(0, 1fr) 4.5rem;
  letter-spacing: var(--ui-font-tracking-wide);
  padding: 0 var(--ui-space-2) var(--ui-space-1);
  text-transform: uppercase;
}

.th-builder__colhead span:last-child { text-align: right; }

.th-builder__group {
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-sm);
  font-style: italic;
  margin: var(--ui-space-3) 0 var(--ui-space-1);
  padding: 0 var(--ui-space-2);
}

.th-builder__row {
  align-items: center;
  border-radius: var(--ui-radius-control);
  display: grid;
  gap: var(--ui-space-3);
  grid-template-columns: 7.5rem minmax(0, 1fr) 4.5rem;
  padding: var(--ui-space-1) var(--ui-space-2);
  transition: background-color var(--ui-motion-duration-fast) var(--ui-motion-easing-standard);
}

.th-builder__row:hover { background: var(--ui-state-hover-bg); }
.th-builder__row.is-picked { background: var(--ui-color-action-muted); }
.th-builder__row.is-empty { color: var(--ui-text-muted); }

.th-builder__name {
  cursor: pointer;
  margin: 0;
  min-width: 0;
}

.th-builder-types {
  font-size: var(--ui-font-size-sm);
  margin-top: var(--ui-space-1);
}

.th-builder-types summary {
  cursor: pointer;
  width: fit-content;
}

.th-builder-types[open] summary { margin-bottom: var(--ui-space-1); }

.th-builder-types__list {
  display: grid;
  gap: var(--ui-space-1);
  margin-block: var(--ui-space-2);
}

.th-builder-types__option {
  align-items: baseline;
  cursor: pointer;
  display: grid;
  gap: var(--ui-space-2);
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.th-builder-types__option:has(:disabled) { cursor: default; }

.th-builder-types__count {
  color: var(--ui-text-muted);
  font-variant-numeric: tabular-nums;
}

.th-builder__num {
  color: var(--ui-text-muted);
  font-variant-numeric: tabular-nums;
  margin-right: var(--ui-space-1);
}

.th-builder__bank {
  font-size: var(--ui-font-size-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.th-builder__bank.is-empty {
  color: var(--ui-text-muted);
  font-size: var(--ui-font-size-xs);
}

.th-step {
  align-items: center;
  display: inline-flex;
  gap: var(--ui-space-1);
}

.th-step__btn {
  align-items: center;
  background: var(--ui-surface-card);
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-circle);
  color: var(--ui-text-primary);
  cursor: pointer;
  display: inline-flex;
  font-size: var(--ui-font-size-lg);
  height: 2rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 2rem;
}

.th-step__btn:hover:not(:disabled) {
  border-color: var(--ui-color-action);
  color: var(--ui-color-action);
}

.th-step__btn:disabled {
  cursor: default;
  opacity: var(--ui-state-disabled-opacity);
}

.th-step__input {
  -moz-appearance: textfield;
  appearance: textfield;
  background: var(--ui-surface-card);
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-control);
  color: var(--ui-text-primary);
  font-variant-numeric: tabular-nums;
  height: 2rem;
  text-align: center;
  width: 2.5rem;
}

.th-step__input::-webkit-inner-spin-button,
.th-step__input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.th-step__input:focus-visible {
  border-color: var(--ui-color-action);
  box-shadow: var(--ui-focus-ring);
  outline: 0;
}

.th-builder__table { grid-area: choices; }
.th-builder__options { grid-area: options; }
.th-builder__side { grid-area: submit; }

.th-builder__side, .th-builder__options {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-3);
}

.th-builder__submit { width: 100%; }

.th-builder__total {
  font-weight: var(--ui-font-weight-semibold);
  margin: 0;
  text-align: center;
}

.th-builder__level {
  display: flex;
  flex-direction: column;
  font-size: var(--ui-font-size-sm);
  gap: var(--ui-space-1);
}

.th-builder__presets {
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-2);
}

/* ---------- каталог по типам ---------- */
.th-types,
.th-topics {
  list-style: none;
  margin: 0;
  padding: 0;
}

.th-types__row {
  align-items: center;
  border-top: 1px solid var(--ui-border-row);
  display: flex;
  gap: var(--ui-space-4);
  justify-content: space-between;
  padding: var(--ui-space-3) 0;
}

.th-types__row:first-child { border-top: 0; }
.th-types__row.is-empty .th-types__title { color: var(--ui-text-muted); }

.th-types__main { min-width: 0; }

.th-types__title {
  font-weight: var(--ui-font-weight-semibold);
  margin: 0;
}

.th-types__meta {
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-sm);
  margin: 0;
}

.th-levels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-1) var(--ui-space-3);
  margin: var(--ui-space-1) 0 0;
}

.th-levels__item {
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-xs);
}

.th-levels__item.is-empty { color: var(--ui-text-muted); }

.th-types__actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
  justify-content: flex-end;
}

.th-types__count {
  font-size: var(--ui-font-size-lg);
  font-variant-numeric: tabular-nums;
  font-weight: var(--ui-font-weight-bold);
  min-width: 2.5rem;
  text-align: right;
}

.th-types__train {
  align-items: center;
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
}

.th-types__train .ui-select {
  max-width: 12rem;
  width: auto;
}

/* ---------- каталог по темам ---------- */
.th-topics {
  display: grid;
  gap: var(--ui-space-2);
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

.th-topics__link {
  align-items: center;
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-control);
  color: var(--ui-text-primary);
  display: flex;
  gap: var(--ui-space-3);
  justify-content: space-between;
  padding: var(--ui-space-2) var(--ui-space-3);
  text-decoration: none;
}

.th-topics__link:hover {
  background: var(--ui-state-hover-bg);
  border-color: var(--ui-color-action);
}

.th-topics__name { min-width: 0; overflow-wrap: anywhere; }

.th-topics__count {
  color: var(--ui-text-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: var(--ui-font-weight-semibold);
}

/* ---------- поиск ---------- */
.th-filters {
  display: grid;
  gap: var(--ui-space-3);
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
}

.th-filters label {
  display: flex;
  flex-direction: column;
  font-size: var(--ui-font-size-sm);
  gap: var(--ui-space-1);
}

.th-filters__wide { grid-column: 1 / -1; }

.th-filters .th-check {
  align-items: center;
  flex-direction: row;
  font-size: var(--ui-font-size-md);
  gap: var(--ui-space-2);
}

.th-filters__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
  grid-column: 1 / -1;
}

.th-chip-row {
  align-items: center;
  display: flex;
  gap: var(--ui-space-2);
  margin: 0;
}

.th-results {
  display: grid;
  gap: var(--ui-space-3);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
}

.th-results > .ui-empty-state { grid-column: 1 / -1; }

.th-result {
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-card);
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-2);
  padding: var(--ui-space-3) var(--ui-space-4);
}

.th-result__head {
  align-items: flex-start;
  display: flex;
  gap: var(--ui-space-2);
  justify-content: space-between;
}

.th-result__title {
  font-size: var(--ui-font-size-md);
  font-weight: var(--ui-font-weight-semibold);
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.th-result__meta,
.th-result__topics {
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-sm);
  margin: 0;
}

.th-pager {
  align-items: center;
  display: flex;
  gap: var(--ui-space-3);
  justify-content: center;
}


.th-frame { max-width: 96rem; }

.th-frame:has(> .th-template-author) { max-width: none; }

@media (min-width: 577px) {
  .testing-tab:has(> .th-template-author) { padding-inline-end: var(--ui-space-2); }
}

.th-practice,
.th-panel-grid {
  display: grid;
  align-items: start;
  gap: var(--ui-space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr));
}

.th-practice > *, .th-panel-grid > *, .th-stack > *, .th-form-grid > * { min-width: 0; }

.th-quick .th-card__title { font-size: var(--ui-font-size-md); }

.th-resume,
.th-link-row,
.th-screen-head--actions,
.th-workspace-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--ui-space-2) var(--ui-space-4);
}

.th-resume {
  flex-direction: row;
  justify-content: space-between;
  overflow-wrap: anywhere;
}

.th-workspace-nav {
  border-bottom: 1px solid var(--ui-border-subtle);
  margin-bottom: var(--ui-space-4);
}

.th-workspace-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  color: var(--ui-text-secondary);
}

.th-workspace-nav a[aria-current="page"] {
  color: var(--ui-text-primary);
  font-weight: var(--ui-font-weight-semibold);
}

.th-screen-head {
  margin-bottom: var(--ui-space-4);
  overflow-wrap: anywhere;
}
.th-screen-head--actions { justify-content: space-between; }
.th-screen-head > *, .th-screen-head--actions > div { min-width: 0; }

.th-screen-head h1 {
  font-size: var(--ui-font-size-2xl);
  margin: 0;
}

.th-screen-head p:not(.th-note) { margin: var(--ui-space-1) 0 0; }

.th-stack, .th-form-grid {
  display: grid;
  gap: var(--ui-space-3);
}

.th-form-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}

.th-field label { display: block; margin-bottom: var(--ui-space-1); }
.th-field > :last-child, .th-stack > :last-child { margin-bottom: 0; }
.th-field--wide, .th-form-grid > .errorlist { grid-column: 1 / -1; }

.th-field--check label {
  display: flex;
  align-items: center;
  gap: var(--ui-space-2);
}

.th-field .errorlist, .th-form-grid > .errorlist {
  color: var(--ui-color-danger);
  margin: var(--ui-space-1) 0;
}

.th-meta {
  display: grid;
  gap: var(--ui-space-3);
  margin: 0;
}

.th-meta > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--ui-space-2);
}

.th-meta dd { margin: 0; overflow-wrap: anywhere; }

.th-form-shell { max-width: 72rem; }

.th-template-author {
  min-width: 0;
}

.th-template-catalog__groups {
  display: grid;
  align-items: start;
  gap: var(--ui-space-4);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
}

.th-template-catalog .ui-list-row {
  flex-wrap: nowrap;
}

.th-template-catalog .ui-list-row-group > li { min-width: 0; }

.th-template-toolbar__type {
  flex: 1 1 20rem;
  max-width: 38rem;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ui-space-2);
}

.th-template-toolbar__type .ui-label {
  margin: 0;
}

.th-template-toolbar__type .ui-select {
  flex: 1 1 12rem;
  width: auto;
  min-width: 0;
  max-width: 100%;
}

[data-testing-locked-template] [data-exam-switch] { display: none; }

.th-task-editor {
  container-type: inline-size;
}

.th-task-workbench {
  display: grid;
  align-items: start;
  gap: var(--ui-space-4);
}

.th-task-workbench > * {
  min-width: 0;
}

.th-task-workbench [data-testing-source-issue][hidden] {
  display: none;
}

.th-task-workbench summary {
  cursor: pointer;
  font-weight: var(--ui-font-weight-semibold);
}

.th-task-extra {
  border-top: 1px solid var(--ui-border-subtle);
  padding-top: var(--ui-space-2);
}

.th-task-metadata label {
  display: block;
  margin-bottom: var(--ui-space-1);
}

.th-task-metadata > p {
  margin: 0;
}

@container (min-width: 54rem) {
  .th-task-workbench {
    grid-template-columns: minmax(0, 5fr) minmax(0, 3fr);
  }
}

.th-task-options {
  max-height: 22rem;
  overflow: auto;
  padding: var(--ui-space-2);
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-control);
}

.th-task-filters {
  display: grid;
  gap: var(--ui-space-2);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
}

.th-task-option {
  padding-block: var(--ui-space-1);
  border-bottom: 1px solid var(--ui-border-subtle);
}

.th-task-option:last-child { border-bottom: 0; }

.th-task-option > details { margin: 0 var(--ui-space-3) var(--ui-space-2); }

.th-task-option > details > summary { cursor: pointer; }

.th-task-options label {
  display: flex;
  gap: var(--ui-space-2);
  align-items: baseline;
  overflow-wrap: anywhere;
  padding: var(--ui-space-2);
  cursor: pointer;
}

.th-stack [hidden] { display: none; }

.th-form-actions { margin-top: var(--ui-space-4); }

.th-advanced__fields, details > .th-link-row { margin-top: var(--ui-space-2); }

.th-filters--search {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

.th-footer, .th-workspace-footer {
  border-top: 1px solid var(--ui-border-subtle);
  padding-top: var(--ui-space-3);
}

.th-workspace-footer { margin-top: var(--ui-space-4); }
.th-author { font-size: var(--ui-font-size-sm); }
.th-footer .th-note { margin-bottom: var(--ui-space-2); }
.th-workspace-copy { max-width: 65ch; overflow-wrap: anywhere; }

.th-report-table td { overflow-wrap: anywhere; }
.th-report-table td > .th-note { display: block; }

.th-copy-field .ui-input { min-width: 0; flex: 1 1 14rem; }
.th-copy-field { align-items: stretch; }

.th-builder__side .th-builder__submit { margin-top: var(--ui-space-1); }

/* ---------- узкая ширина ---------- */
@media (max-width: 767.98px) {
  :is(#tabPanel-my_learning-tests, #tabPanel-teaching-mytests) > .tab-content-inner {
    padding: var(--ui-tabs-content-compact-padding);
  }

  .th-exam { grid-template-columns: minmax(0, 1fr); }
  .th-builder {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "options" "choices" "submit";
    grid-template-rows: auto;
  }
  .th-builder__presets { flex-direction: row; flex-wrap: wrap; }
  .th-builder__colhead { display: none; }
  .th-builder__row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .th-types__row { align-items: flex-start; flex-direction: column; }
  .th-types__actions { justify-content: flex-start; }
  .th-variants__grid { grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); }
  .th-switch__item { padding: var(--ui-space-1) var(--ui-space-4); }
  .th-pick__bar { flex-direction: column; }
  .th-stat-help__body { position: static; width: auto; max-width: 100%; margin-top: var(--ui-space-2); }
  .th-filters--search { grid-template-columns: minmax(0, 1fr); }
  .th-pick__submit { width: 100%; }

  .th-report-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .th-report-table,
  .th-report-table tbody,
  .th-report-table tr { display: block; }

  .th-report-table td {
    border: 0;
    display: block;
    padding: var(--ui-space-1) var(--ui-space-2);
  }

  .th-report-table td[data-label]::before {
    color: var(--ui-text-muted);
    content: attr(data-label) " ";
    margin-inline-end: var(--ui-space-1);
  }

  .th-report-table tr {
    border-bottom: 1px solid var(--ui-border-subtle);
    padding-block: var(--ui-space-2);
  }

  .th-report-table tr:last-child { border-bottom: 0; }
}

/* The legacy viewport uses half scale on phones. Keep the actual touch
   target the same size as the native-scale UI kit target. */
@media (pointer: coarse) and (max-device-width: 576px) {
  .th-builder {
    --th-touch-size: calc(2 * var(--ui-touch-target, 44px));
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "options" "choices" "submit";
    grid-template-rows: auto;
  }

  html[data-mobile-native-scale="1"] .th-builder {
    --th-touch-size: var(--ui-touch-target, 44px);
  }

  .th-builder__colhead { display: none; }
  .th-builder__row { grid-template-columns: auto minmax(0, 1fr) auto; }

  .th-step__btn {
    width: var(--th-touch-size);
    height: var(--th-touch-size);
    flex: 0 0 var(--th-touch-size);
    font-size: calc(var(--th-touch-size) / 2.5);
  }

  .th-step__input,
  .th-builder-types__option,
  .th-builder-types summary { min-block-size: var(--th-touch-size); }

  .th-builder-types__option { align-items: center; }

  .th-builder-types summary { align-content: center; }
}
