/* Robotext Platform — компоненты. Ни одного цвета мимо токенов. */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--on-surface);
  font: var(--text-body-l);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.mono { font-family: var(--font-mono); font-size: .8125rem; }
.muted { color: var(--on-surface-muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- каркас приложения ---------- */

.layout { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }

.rail {
  background: var(--surface-low);
  border-right: 1px solid var(--outline-variant);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.rail-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  height: var(--topbar-h);
}
.rail-head img { width: 26px; height: 26px; display: block; }
.rail-head .wordmark { font: var(--text-title); letter-spacing: -.01em; }
.rail-head .wordmark span { color: var(--on-surface-muted); font-weight: 500; }

.rail-nav { flex: 1; overflow-y: auto; padding: var(--sp-2) var(--sp-3) var(--sp-4); }

.nav-section {
  font: var(--text-label);
  color: var(--on-surface-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: var(--sp-5) var(--sp-3) var(--sp-2);
}

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3);
  border-radius: var(--radius-full);
  color: var(--on-surface-variant);
  font: var(--text-body);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--state-neutral-hover); text-decoration: none; color: var(--on-surface); }
.nav-item.is-active { background: var(--primary-container); color: var(--on-primary-container); }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item .badge-dot { margin-left: auto; }

.rail-foot { border-top: 1px solid var(--outline-variant); padding: var(--sp-3); }

.user-chip {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  color: inherit;
}
.user-chip:hover { background: var(--state-neutral-hover); text-decoration: none; }
.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--radius-full);
  background: var(--primary-container); color: var(--on-primary-container);
  display: grid; place-items: center;
  font: var(--text-label); font-weight: 600;
}
.user-chip .meta { min-width: 0; }
.user-chip .meta b {
  display: block; font: var(--text-body); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .meta small {
  display: block; color: var(--on-surface-muted); font-size: .75rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- шапка ---------- */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-8);
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--outline-variant);
}
.topbar h1 { font: var(--text-title-l); letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }

.content { padding: var(--sp-8); max-width: var(--content-max); width: 100%; }
.stack { display: flex; flex-direction: column; gap: var(--sp-6); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

/* ---------- кнопки ---------- */

.btn {
  --btn-bg: transparent; --btn-fg: var(--primary); --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 40px; padding: 0 var(--sp-5);
  border: 1px solid var(--btn-bd); border-radius: var(--radius-full);
  background: var(--btn-bg); color: var(--btn-fg);
  font: var(--text-body); font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; box-shadow: var(--shadow-1); }
.btn:active { transform: scale(.985); }
.btn svg { width: 18px; height: 18px; }
.btn[disabled], .btn.is-disabled { opacity: .4; pointer-events: none; }

.btn-filled { --btn-bg: var(--primary); --btn-fg: var(--on-primary); }
.btn-filled:hover { --btn-bg: var(--primary-hover); }
.btn-tonal { --btn-bg: var(--primary-container); --btn-fg: var(--on-primary-container); }
.btn-outlined { --btn-bd: var(--outline); --btn-fg: var(--on-surface); }
.btn-outlined:hover { --btn-bg: var(--state-neutral-hover); box-shadow: none; }
.btn-text:hover { --btn-bg: var(--state-hover); box-shadow: none; }
.btn-danger { --btn-bg: var(--danger-container); --btn-fg: var(--danger); }
.btn-sm { height: 32px; padding: 0 var(--sp-4); font-size: .8125rem; }

.icon-btn {
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: var(--radius-full);
  background: transparent; color: var(--on-surface-variant);
  display: grid; place-items: center; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--state-neutral-hover); color: var(--on-surface); }
.icon-btn svg { width: 20px; height: 20px; }

.lang-switch { display: inline-flex; }
.lang-switch .btn { min-width: 44px; font-variant-numeric: tabular-nums; letter-spacing: .04em; }

/* ---------- поверхности ---------- */

.card {
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}
.card-flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--outline-variant);
}
.card-head h2 { font: var(--text-title); }
.card-head .spacer { flex: 1; }
.card-body { padding: var(--sp-6); }

.grid { display: grid; gap: var(--sp-4); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.section-title { font: var(--text-title-l); letter-spacing: -.01em; }
.section-hint { font: var(--text-body); color: var(--on-surface-muted); max-width: 74ch; }

/* показатель */
.metric { display: flex; flex-direction: column; gap: var(--sp-1); }
.metric .label { font: var(--text-label); color: var(--on-surface-muted); }
.metric .value { font: var(--text-headline); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric .value small { font: var(--text-body); color: var(--on-surface-muted); font-weight: 500; }

/* индикатор мест */
.meter { height: 6px; border-radius: var(--radius-full); background: var(--surface-highest); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--primary); border-radius: inherit;
  transition: width 2s linear; }
.meter.is-warn > i { background: var(--warning); }
.meter.is-over > i { background: var(--danger); }

/* ---------- баннеры ---------- */

.banner {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  font: var(--text-body);
}
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.banner b { display: block; font-weight: 600; margin-bottom: 2px; }
.banner-info    { background: var(--primary-soft);      border-color: transparent; color: var(--on-surface); }
.banner-success { background: var(--success-container);  border-color: transparent; color: var(--success); }
.banner-warning { background: var(--warning-container);  border-color: transparent; color: var(--warning); }
.banner-danger  { background: var(--danger-container);   border-color: transparent; color: var(--danger); }

/* ---------- метки ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--surface-high); color: var(--on-surface-variant);
  font: var(--text-label); white-space: nowrap;
}
.chip-primary { background: var(--primary-container); color: var(--on-primary-container); }
.chip-success { background: var(--success-container); color: var(--success); }
.chip-warning { background: var(--warning-container); color: var(--warning); }
.chip-danger  { background: var(--danger-container);  color: var(--danger); }
.chip-outline { background: transparent; border: 1px solid var(--outline); }

.badge-dot { width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--primary); }

/* ---------- формы ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
/* Поле во всю ширину контентной колонки нечитаемо: строка в 1300 px не сканируется
   глазом. Ограничиваем длину строки, а не ширину карточки. */
.field .input, .field .textarea, .field .select { max-width: 62rem; }
.field-wide .input, .field-wide .textarea, .field-wide .select { max-width: none; }
.field > label { font: var(--text-label); color: var(--on-surface-variant); }
.field .hint { font-size: .75rem; color: var(--on-surface-muted); }

.input, .select, .textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px var(--sp-4);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--surface-lowest);
  color: var(--on-surface);
  font: var(--text-body-l);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--on-surface-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--state-hover);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
/* Стрелка рисуется от центра поля, а не от фиксированного отступа сверху:
   иначе на мелком списке она сползает к нижней кромке и двоится. */
.select { appearance: none; padding-right: var(--sp-8); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% - 2px), calc(100% - 15px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.select-sm {
  min-height: 32px; padding: 4px 30px 4px 10px; font-size: .8125rem; width: auto;
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 13px) calc(50% - 2px);
}

input[type="file"].input { padding: 8px var(--sp-3); line-height: 24px; cursor: pointer; }
input[type="file"].input::file-selector-button {
  margin-right: var(--sp-3); padding: 6px var(--sp-4);
  border: 0; border-radius: var(--radius-full);
  background: var(--primary-container); color: var(--on-primary-container);
  font: var(--text-label); font-weight: 600; cursor: pointer;
}
input[type="file"].input::file-selector-button:hover { background: var(--primary); color: var(--on-primary); }

/* карточки в ряду: одинаковые края и одна и та же позиция у повторяющихся элементов */
.card-tile { display: flex; flex-direction: column; gap: var(--sp-2); }
.card-tile .tile-head { display: flex; align-items: flex-start; gap: var(--sp-2); min-height: 44px; }
.card-tile .tile-head h3 { font: var(--text-title); flex: 1; }
.card-tile .tile-meta { margin-top: auto; padding-top: var(--sp-2); }

/* сетка карточек не растягивает одиночный элемент на всю ширину */
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-cards.is-sparse { grid-template-columns: repeat(auto-fill, minmax(320px, 420px)); justify-content: start; }

/* переключатель */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 46px; height: 26px; flex: none;
  border-radius: var(--radius-full);
  background: var(--surface-highest);
  border: 1px solid var(--outline);
  position: relative;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: var(--radius-full);
  background: var(--on-surface-muted);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); background: var(--on-primary); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- таблицы ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font: var(--text-body); }
table.data th, table.data td {
  text-align: left; padding: 12px var(--sp-6);
  border-bottom: 1px solid var(--outline-variant);
  vertical-align: middle;
}
table.data th {
  font: var(--text-label); color: var(--on-surface-muted);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-low); white-space: nowrap;
}
table.data tbody tr { transition: background var(--dur-fast) var(--ease); }
table.data tbody tr:hover { background: var(--state-neutral-hover); }
table.data tbody tr:last-child td { border-bottom: none; }

/* ---------- вход ---------- */

.auth {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--sp-6);
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--primary-soft), transparent 70%),
    var(--surface);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  padding: var(--sp-8);
  display: flex; flex-direction: column; gap: var(--sp-5);
}
.auth-brand { display: flex; align-items: center; gap: var(--sp-3); }
.auth-brand img { width: 34px; height: 34px; }
.auth-brand .wordmark { font: var(--text-title-l); letter-spacing: -.015em; }
.auth-brand .wordmark span { color: var(--on-surface-muted); font-weight: 500; }
.auth h1 { font: var(--text-title-l); letter-spacing: -.01em; }

/* ---------- пустое состояние ---------- */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6);
  text-align: center; color: var(--on-surface-muted);
}
.empty svg { width: 40px; height: 40px; opacity: .5; }
.empty b { color: var(--on-surface); font: var(--text-title); }

/* ---------- мелочи ---------- */

.divider { height: 1px; background: var(--outline-variant); border: 0; margin: 0; }
.kbd {
  font-family: var(--font-mono); font-size: .75rem;
  padding: 2px 6px; border-radius: 6px;
  background: var(--surface-high); border: 1px solid var(--outline-variant);
}

/* Десктоп — основной сценарий. Мобильная раскладка заложена, но не отлажена. */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--outline-variant); }
  .rail-nav { display: flex; gap: var(--sp-2); overflow-x: auto; padding: var(--sp-2) var(--sp-3); }
  .nav-section { display: none; }
  .content, .topbar { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* ---------- редактор слайда: фон рендерится, текст накладывается ---------- */

.stage-wrap { display: flex; flex-direction: column; gap: var(--sp-4); }

.stage {
  position: relative;
  container-type: inline-size;
  /* Ширина задаётся явно: во флекс-колонке auto-поля схлопывают элемент,
     содержимое которого само задано в процентах. */
  width: 100%;
  max-width: max(720px, min(100%, calc((100vh - 320px) * 16 / 9)));
  align-self: center;
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.stage img.bg { display: block; width: 100%; height: auto; }

/* Слот позиционируется в процентах от слайда, а кегль — в единицах контейнера,
   поэтому наложение совпадает с фоном при любом размере окна. */
.slot {
  position: absolute;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  outline: 1px dashed transparent;
  outline-offset: 2px;
  transition: outline-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.slot[contenteditable="true"] { cursor: text; }
.slot:hover { outline-color: var(--outline); background: var(--state-hover); }
/* Фон при правке не подменяем: у слота свой цвет текста из шаблона, и белый
   текст на белой подложке становится невидимым. Границы хватает, чтобы понять,
   что поле в работе, а сам текст остаётся читаемым на плашке шаблона. */
.slot:focus { outline: 2px solid var(--primary); background: transparent; }
.slot:focus::selection, .slot:focus *::selection {
  background: var(--primary); color: var(--on-primary);
}
.slot.is-overflow { outline-color: var(--danger); background: rgba(179, 38, 30, .06); }
.slot .list { margin: 0; padding-left: 1.15em; }
.slot .list li { margin: 0; }
.slot.is-list { display: block; }

.slot-object {
  position: absolute;
  display: grid; place-items: center;
  border: 1px dashed var(--outline);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.slot-object:hover, .slot-object:focus-visible {
  background: rgba(11, 87, 201, .12); color: var(--primary);
  border-color: var(--primary);
}
.slot-object span {
  font: var(--text-label); font-weight: 600;
  background: var(--surface-lowest); padding: 4px 10px; border-radius: var(--radius-full);
  box-shadow: var(--shadow-1);
  /* Подпись появляется по наведению: постоянная плашка посреди диаграммы
     закрывает то, ради чего слайд и смотрят. */
  opacity: 0; transition: opacity var(--dur-fast) var(--ease);
}
.slot-object:hover span, .slot-object:focus-visible span { opacity: 1; }

.stage-bar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  scroll-margin-top: calc(var(--topbar-h) + var(--sp-4));
}
.stage-hint { font-size: .8125rem; color: var(--on-surface-muted); }
.overflow-badge {
  font: var(--text-label); color: var(--danger);
  background: var(--danger-container); padding: 2px 8px; border-radius: var(--radius-full);
}

details.technical > summary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px; border-radius: var(--radius-full);
  font: var(--text-label); color: var(--on-surface-muted);
  cursor: pointer; list-style: none; user-select: none;
}
details.technical > summary::-webkit-details-marker { display: none; }
details.technical > summary::before {
  content: "›"; display: inline-block; width: 16px; text-align: center;
  transition: transform var(--dur-fast) var(--ease);
}
details.technical[open] > summary::before { transform: rotate(90deg); }
details.technical > summary:hover { background: var(--state-neutral-hover); color: var(--on-surface); }

.filmstrip { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: var(--sp-2); }
.filmstrip a {
  flex: none; width: 132px; border: 2px solid transparent; border-radius: 8px;
  overflow: hidden; background: var(--surface-container); text-decoration: none;
}
.filmstrip a.is-active { border-color: var(--primary); }
.filmstrip img { display: block; width: 100%; height: auto; }
.filmstrip .num {
  display: block; font: var(--text-label); color: var(--on-surface-muted);
  padding: 3px 6px; text-align: center;
}

/* ---------- вкладки этапов ---------- */

.stages {
  display: flex; align-items: center; gap: var(--sp-1);
  border-bottom: 1px solid var(--outline-variant);
}
.stages a {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 10px var(--sp-4) 12px;
  color: var(--on-surface-muted);
  font: var(--text-body); font-weight: 600;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.stages a:hover { color: var(--on-surface); text-decoration: none; }
.stages a.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.stages a .step {
  width: 20px; height: 20px; border-radius: var(--radius-full);
  display: grid; place-items: center;
  background: var(--surface-highest); color: var(--on-surface-variant);
  font-size: .6875rem; font-weight: 700;
}
.stages a.is-active .step { background: var(--primary); color: var(--on-primary); }
.stages .spacer { flex: 1; }

/* ---------- инструменты в шапке карточки ---------- */

.card-head .tools { display: flex; align-items: center; gap: 2px; }
.icon-btn-sm { width: 30px; height: 30px; }
.icon-btn-sm svg { width: 16px; height: 16px; }
.icon-btn-danger:hover { background: var(--danger-container); color: var(--danger); }

/* ---------- список слайдов второго этапа ---------- */

.slide-row { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 0; }
@media (max-width: 900px) { .slide-row { grid-template-columns: 1fr; } }

.slide-preview {
  position: relative; display: block; padding: var(--sp-5) var(--sp-5) var(--sp-5) var(--sp-6);
  background: var(--surface-container); border-right: 1px solid var(--outline-variant);
  text-decoration: none;
}
.slide-preview:hover { background: var(--surface-high); text-decoration: none; }
.slide-thumb {
  display: block; width: 100%; aspect-ratio: 16 / 9;
  border: 1px solid var(--outline-variant); border-radius: 6px;
  background: var(--surface-lowest); object-fit: contain;
}
.slide-thumb.is-loading, .slide-thumb.is-empty {
  display: grid; place-items: center;
  font: var(--text-label); color: var(--on-surface-muted);
}
.slide-num {
  position: absolute; top: 10px; left: 10px;
  min-width: 24px; height: 24px; padding: 0 7px;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--on-surface); color: var(--surface-lowest);
  font: var(--text-label); font-weight: 700;
  box-shadow: var(--shadow-1);
}
.slide-side { padding: var(--sp-5) var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-3); }
.slide-side h2 a { color: inherit; }

/* ---------- панель объекта ---------- */

.editor-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
.editor-body.has-panel { grid-template-columns: minmax(0, 1fr) 420px; align-items: start; }
@media (max-width: 1180px) { .editor-body.has-panel { grid-template-columns: minmax(0, 1fr); } }

/* В сетке с панелью высоту строки задаёт панель, и центрирование по оси
   уводило слайд на середину пустого места. */
.editor-body.has-panel .stage { max-width: 100%; align-self: start; }

.panel:empty { display: none; }
.panel {
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky; top: calc(var(--topbar-h) + var(--sp-3));
  /* Высота считается от места, где панель закрепляется. Без этого при открытии
     кнопка «Применить» уезжала под нижнюю кромку окна и была недоступна. */
  max-height: calc(100vh - var(--topbar-h) - var(--sp-6));
  display: flex; flex-direction: column;
}
.panel form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--outline-variant);
  background: var(--surface-low);
}
.panel-body { padding: var(--sp-4); overflow-y: auto; min-height: 0; }
.panel-foot {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--outline-variant);
  background: var(--surface-low);
}

/* выбор типа диаграммы */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.type-option {
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px; border-radius: var(--radius);
  border: 1px solid var(--outline-variant); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
/* Переключатель накрывает всю карточку, а не сжат в ноль: так он остаётся
   кликабельным и доступным с клавиатуры, а не только через подпись. */
.type-option input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: inherit; }
.type-option:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.type-option:hover { background: var(--state-neutral-hover); }
.type-option.is-selected { border-color: var(--primary); background: var(--primary-soft); }
.type-option.is-disabled { opacity: .45; cursor: not-allowed; }
.type-name { font: var(--text-body); font-weight: 600; }
.type-hint { font-size: .6875rem; color: var(--on-surface-muted); line-height: 1.3; }

/* Сетка данных строится на grid, а не на таблице с полями в ячейках:
   в таблице поля не выравниваются по колонкам, а служебные кнопки занимают
   отдельные ячейки с чужим фоном. */
.grid-rows {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)) 30px;
  gap: 4px; align-items: center; margin-bottom: 4px;
}
.grid-rows .input {
  min-height: 32px; padding: 5px 9px; font-size: .8125rem; max-width: none;
}
.grid-label {
  font: var(--text-label); color: var(--on-surface-muted);
  padding-left: 2px; align-self: center;
}
.panel .field > label { font-weight: 600; }

.panel-preview {
  display: block; width: 100%; border-radius: var(--radius);
  border: 1px solid var(--outline-variant);
}
.library { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.library-item {
  padding: 0; border: 2px solid transparent; border-radius: 8px;
  background: var(--surface-container); cursor: pointer; overflow: hidden;
}
.library-item:hover { border-color: var(--primary); }
.library-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }

/* У открытого объекта подпись должна читаться: сам по себе цвет текста
   прозрачный, и без него получалась белая плашка без надписи. */
.slot-object.is-open {
  background: rgba(11, 87, 201, .16); border-color: var(--primary); color: var(--primary);
}
.slot-object.is-open span { opacity: 1; }

/* --- Ассистент ------------------------------------------------------------
   Док справа поверх содержимого: документ остаётся на своём месте, а не
   переезжает при открытии панели — иначе слайд под курсором уходит из-под
   мыши прямо во время правки. */
.assistant-fab {
  position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: 40;
  height: 52px; padding: 0 var(--sp-5); border-radius: var(--radius-full);
  box-shadow: var(--shadow-2);
}
.assistant-fab[hidden] { display: none; }

.assistant {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--assistant-w); z-index: 45;
  display: flex; flex-direction: column;
  background: var(--surface-lowest);
  border-left: 1px solid var(--outline-variant);
  box-shadow: var(--shadow-3);
}
.assistant[hidden] { display: none; }

/* Открытая панель сдвигает содержимое, а не накрывает его: под ней иначе
   оказываются кнопки действий и выбор макета — ровно то, о чём в этот момент
   и идёт разговор. На узком окне места на сдвиг нет, там панель поверх. */
.has-assistant .layout.has-assistant-slot { padding-right: var(--assistant-w); }
@media (max-width: 1180px) { .has-assistant .layout.has-assistant-slot { padding-right: 0; } }

.assistant-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--outline-variant);
}
.assistant-head > svg { color: var(--primary); flex: none; }
.assistant-title { flex: 1; min-width: 0; }
.assistant-title b { display: block; font: var(--text-title); }
.assistant-title small { color: var(--on-surface-muted); font: var(--text-label); }

.assistant-log {
  flex: 1; overflow-y: auto; padding: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.assistant-empty { color: var(--on-surface-muted); font: var(--text-body); }
.assistant-empty p { margin-bottom: var(--sp-3); }
.chip-hint {
  /* Подсказка — целая фраза, а не ярлык: у .chip нет переноса и высота в 24px,
     из-за чего длинный пример уезжал за край панели. */
  display: block; height: auto; white-space: normal; text-align: left;
  cursor: pointer; border: 1px solid var(--outline-variant);
  background: var(--surface-low); color: var(--on-surface-variant);
  border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); font: var(--text-body);
}
.chip-hint:hover { background: var(--state-hover); border-color: var(--primary); }

.bubble {
  border-radius: var(--radius-lg); padding: var(--sp-3) var(--sp-4);
  font: var(--text-body); white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble-user {
  align-self: flex-end; max-width: 88%;
  background: var(--primary-container); color: var(--on-primary-container);
  border-bottom-right-radius: var(--radius-sm);
}
.bubble-bot {
  align-self: flex-start; max-width: 94%;
  background: var(--surface-container); color: var(--on-surface);
  border-bottom-left-radius: var(--radius-sm);
}
.bubble-tool {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--success-container); color: var(--success);
  font: var(--text-label); padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-full);
}
.bubble-tool svg { width: 16px; height: 16px; flex: none; }
.bubble-tool.is-failed { background: var(--warning-container); color: var(--warning); }
.bubble-tool.is-running { background: var(--surface-high); color: var(--on-surface-muted); }
.assistant-rev { font-style: normal; opacity: .7; margin-left: auto; padding-left: var(--sp-2); }
.bubble-error {
  display: flex; gap: var(--sp-2); background: var(--danger-container); color: var(--danger);
}
.bubble-error svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }

.assistant-form {
  display: flex; gap: var(--sp-2); align-items: flex-end;
  padding: var(--sp-4); border-top: 1px solid var(--outline-variant);
}
.assistant-form textarea {
  flex: 1; resize: none; max-height: 160px;
  padding: var(--sp-3); border-radius: var(--radius);
  border: 1px solid var(--outline); background: var(--surface);
  color: var(--on-surface); font: var(--text-body);
}
.assistant-form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.assistant-form .btn { height: 44px; padding: 0 var(--sp-4); }
.assistant.is-busy .assistant-form { opacity: .6; pointer-events: none; }

/* Точки набора: единственный признак того, что модель ещё думает.
   Без него сорок секунд ожидания выглядят как зависший интерфейс. */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: currentColor;
            animation: typing 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }

/* --- Материалы задания ---------------------------------------------------- */
.source-text {
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
  font: var(--text-body); font-family: var(--font-mono); font-size: .8125rem;
  background: var(--surface-low); border: 1px solid var(--outline-variant);
  border-radius: var(--radius); padding: var(--sp-4); max-height: 70vh; overflow-y: auto;
}
.source-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--outline-variant);
}
.source-row:last-child { border-bottom: 0; }
.source-row .name { flex: 1; min-width: 0; }
.source-row .name b { display: block; font: var(--text-body); overflow-wrap: anywhere; }
.source-row .name small { color: var(--on-surface-muted); font: var(--text-label); }
.source-row svg { width: 18px; height: 18px; flex: none; color: var(--on-surface-muted); }

/* Вложения в чате ассистента */
.assistant-form { flex-direction: column; align-items: stretch; gap: var(--sp-2); }
.assistant-input { display: flex; gap: var(--sp-2); align-items: flex-end; }
.assistant-input textarea { flex: 1; }
.assistant-input .icon-btn { height: 44px; width: 44px; cursor: pointer; }
.assistant-attached { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.assistant-attached[hidden] { display: none; }
.assistant-attached .chip { cursor: pointer; }
.assistant-attached .chip::after { content: '×'; margin-left: 4px; opacity: .6; }

/* Смена макета: текст раскладывается заново, это несколько секунд */
.layout-switch { display: inline-flex; align-items: center; gap: var(--sp-2); }
.layout-switch select[disabled] { opacity: .5; }
.layout-busy {
  display: none; align-items: center; gap: 5px;
  font: var(--text-label); color: var(--on-surface-muted); white-space: nowrap;
}
.layout-busy.htmx-request, .htmx-request .layout-busy { display: inline-flex; }
.layout-busy i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: typing 1.1s infinite ease-in-out;
}
.layout-busy i:nth-child(2) { animation-delay: .15s; }
.layout-busy i:nth-child(3) { animation-delay: .3s; }

/* ---------- панель действий этапа ----------
   Кнопки перехода между этапами живут в содержимом, а не в шапке: рядом с тем,
   к чему относятся. Главное действие — залитое, переделка — контурное,
   ассистент — справа. */
.actions-bar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-container); border: 1px solid var(--outline-variant);
  border-radius: var(--radius);
}
.actions-bar .spacer { flex: 1; }
.actions-bar form { display: inline-flex; }

/* Инструменты слайда: порядок и правка рядом, удаление — в стороне */
.slide-tools { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.slide-tools .spacer { flex: 1; }
.slide-tools .tools { display: inline-flex; align-items: center; gap: 2px; }
.slide-tools .tools-danger { margin-left: var(--sp-4); padding-left: var(--sp-3);
  border-left: 1px solid var(--outline-variant); }
.icon-btn[disabled] { opacity: .3; pointer-events: none; }

/* Слайды появляются по мере подбора: пока списка нет — подсказка вместо него */
.slides-pending { display: none; }
#deck-slides-list:empty ~ .slides-pending { display: flex; }

/* Список выбранных файлов под полем выбора */
.file-list { list-style: none; margin: var(--sp-2) 0 0; padding: 0;
  border: 1px solid var(--outline-variant); border-radius: var(--radius); overflow: hidden; }
.file-list li { display: flex; align-items: center; gap: var(--sp-3); padding: 6px var(--sp-3);
  border-top: 1px solid var(--outline-variant); font-size: .875rem; }
.file-list li:first-child { border-top: 0; }
.file-list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li small { color: var(--on-surface-muted); white-space: nowrap; }
.file-list li.total { background: var(--surface-container); color: var(--on-surface-muted);
  font-size: .8125rem; justify-content: flex-end; }
.file-list[hidden] { display: none; }

/* Строка слайда во время подбора: только смотреть */
.slide-row.is-readonly .slide-preview { cursor: default; }
.slide-row.is-readonly .slide-preview:hover { background: var(--surface-container); }
