/* Шесть состояний экрана (docs/design/REDESIGN.md §3.6, как пользоваться — docs/design/states.md):
   пусто, загрузка, ошибка, успех, нет прав, без сети. Подключается на каждой странице (core/_states_head.html),
   поведение — static/js/states.js. Цвета — только токены theme.css; движение — токены --t-* и --ease-*. */

/* Токены движения (--t-*, --ease-*) — общие, в theme.css; здесь на них ссылаются с запасным значением. */
:root {
  --hair: 1px solid var(--line);
}

/* ——— Пусто · ошибка · нет прав · без сети: иллюстрация, одна фраза, одно действие ———
   {% include "core/_empty.html" with art=… title=… text=… action_url=… action_label=… %} */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  padding: 40px 24px; color: var(--muted); }
.state > b, .state > .state-h { margin: 4px 0 0; font: 650 17px/1.3 var(--f-body); color: var(--ink); letter-spacing: -.01em; max-width: 36ch; text-wrap: balance; }
.state > p { margin: 0; max-width: 46ch; font-size: 14.5px; line-height: 1.5; text-wrap: pretty; }
.state > .btn, .state > button, .state > .state-acts { margin-top: 10px; }
.state-acts { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.state-acts > .link-quiet { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; }
.state .rid { font: 12px var(--f-code); color: var(--faint); user-select: all; }

/* Пустой список: на фоне страницы — спокойная карточка, внутри блока, таблицы или превью — без рамки */
.state-empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 48px 24px 44px; box-shadow: var(--lift, none); }
:is(.panel, .card, .w, .list, .tbl-wrap, td, li, .cat-pane, .cat-list, .msgr, .bento, .ev-grid, dialog, .state-empty) .state-empty { background: none; border: 0; box-shadow: none; padding: 32px 16px; }
td > .state-empty { padding: 36px 16px; }
tr.state-row > td, tr.state-row:hover > td { padding: 0; background: none; }
tr.state-row > td::before { content: none; }
/* Таблица-карточки на телефоне внутри блока: пустая строка не рисует карточку в карточке */
:is(.panel, .card, .w) table.tbl-cards tr.state-row { border: 0; background: none; padding: 0; box-shadow: none; }
.state-empty.state-sm { padding: 24px 16px; gap: 6px; }
.state-empty.state-sm .state-art { width: 72px; height: 54px; }
.state-empty.state-sm > b { font-size: 15.5px; }
.state-empty.state-left { align-items: flex-start; text-align: left; }
.state-empty.state-left .state-acts { justify-content: flex-start; }
/* Сетки карточек: пустое состояние занимает всю строку */
.state-empty { grid-column: 1 / -1; }

/* ——— Иллюстрации (core/_state_art.html): линия 1,5 px как у логотипа — серый предмет и золотая траектория прыжка ——— */
.state-art { flex: none; width: 96px; height: 72px; overflow: visible; fill: none; stroke: var(--faint); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round; }
.state-art * { vector-effect: non-scaling-stroke; }
.state-art .a-soft { fill: var(--surface-2); stroke: none; }
.state-art .a-ob { fill: var(--surface); }
.state-art .a-ink { stroke: var(--muted); }
.state-art .a-fill { fill: var(--surface-2); }
.state-art .a-gold { stroke: var(--gold); }
.state-art .a-dash { stroke-dasharray: 1.5 4.5; }
.state-art .a-dot { fill: var(--gold); stroke: none; }
.state-art .a-ring { fill: none; stroke: var(--gold); opacity: .35; }
.state-empty .state-art .a-ob { fill: var(--surface); }
.state-error .state-art .a-gold { stroke: var(--warn); }
.state-error .state-art .a-dot { fill: var(--warn); }
.state-error .state-art .a-ring { stroke: var(--warn); }
@media (prefers-reduced-motion: no-preference) {
  .state-art .a-dot { transform-box: fill-box; transform-origin: center; animation: art-land var(--t-camera, 400ms) var(--ease-spring, ease-out) both 120ms; }
}
@keyframes art-land { from { opacity: 0; transform: translateY(-6px) scale(.4); } }

/* ——— Загрузка: скелет той же формы, что содержимое, с мягким переливом (без него при «уменьшить движение») ———
   <div class="sk sk-line"></div> · .sk-title · .sk-avatar · .sk-tile · .sk-block · <div class="sk-row">…</div>; готовые — core/_skeleton.html */
.sk { display: block; position: relative; overflow: hidden; border-radius: var(--r-s); background: var(--surface-2); isolation: isolate; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 65%, transparent), transparent);
  animation: sk-shine 1.6s ease-in-out infinite; }
@keyframes sk-shine { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .sk::after { animation: none; display: none; } }
.sk-line { height: 12px; width: var(--w, 100%); border-radius: 999px; }
.sk-title { height: 22px; width: var(--w, 60%); }
.sk-avatar { flex: none; width: var(--s, 40px); height: var(--s, 40px); border-radius: 50%; }
.sk-tile { height: var(--h, 132px); border-radius: var(--r-l); }
.sk-block { height: var(--h, 120px); border-radius: var(--r-m); }
.sk-chip { display: inline-block; height: 24px; width: var(--w, 72px); border-radius: 999px; }
.sk-stack { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.sk-stack > .sk-line:nth-child(3n) { --w: 82%; }
.sk-stack > .sk-line:nth-child(3n+1) { --w: 64%; }
.sk-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sk-row > .sk-line { flex: 1 1 0; }
.sk-row > .sk-line:first-of-type { flex-grow: 2; }
.sk-rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); overflow: hidden; }
.sk-rows > .sk-row:last-child { border-bottom: 0; }
.sk-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.sk-card { display: flex; flex-direction: column; gap: 10px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.sk-card > .sk-head { display: flex; align-items: center; gap: 12px; }
.sk-card > .sk-head > div { flex: 1; display: flex; flex-direction: column; gap: 8px; }

/* ——— Ожидание ответа: спиннер только в кнопке, повторное нажатие не уходит (<form data-pending>) ——— */
:is(button, .btn)[aria-busy="true"] { position: relative; cursor: progress; pointer-events: none; }
:is(button, .btn)[aria-busy="true"]::before { content: ""; display: inline-block; flex: none; width: 1em; height: 1em; margin-right: 8px;
  vertical-align: -.15em; box-sizing: border-box; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  opacity: .9; animation: btn-spin .7s linear infinite; }
:is(button, .btn)[aria-busy="true"]:not(.primary):not(.ai) { color: var(--muted); }
@keyframes btn-spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { :is(button, .btn)[aria-busy="true"]::before { animation: none; border-right-color: currentColor; border-style: dotted; } }
form[aria-busy="true"] :is(button, input[type=submit]):not([aria-busy="true"]) { opacity: .6; pointer-events: none; }

/* ——— Ошибка в форме: сводка сверху со ссылками на поля, фокус переходит на неё (core/_form_errors.html) ——— */
.err-sum { display: flex; gap: 12px; align-items: flex-start; margin: 0 0 20px; padding: 14px 16px; border-radius: var(--r-m);
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); color: var(--ink); font-size: 14.5px;
  scroll-margin-top: calc(var(--header-h, 56px) + 24px); grid-column: 1 / -1; }
:is(input, select, textarea)[aria-invalid="true"] { scroll-margin-top: calc(var(--header-h, 56px) + 24px); }
.err-sum:focus { outline: 2px solid var(--warn); outline-offset: 2px; }
.err-sum::before { content: "!"; flex: none; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%;
  background: var(--warn); color: var(--surface); font: 800 13px/1 var(--f-body); }
.err-sum > div { flex: 1; min-width: 0; }
.err-sum b { display: block; font-weight: 650; }
.err-sum ul { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.err-sum li { color: var(--muted); }
.err-sum a { color: var(--warn); font-weight: 600; }
.err-sum p { margin: 4px 0 0; color: var(--muted); }

/* ——— Успех: уведомления снизу (Tramplin.toast и сообщения Django), 4 с, можно закрыть ———
   Без JS сообщения остаются плашками сверху (main > .messages, как раньше). */
:root { --toast-bg: var(--night); --toast-ink: var(--night-ink); --toast-muted: var(--night-muted);
  --toast-line: color-mix(in srgb, var(--night-ink) 14%, transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --toast-bg: var(--raised); --toast-ink: var(--ink); --toast-muted: var(--muted); --toast-line: var(--line); } }
:root[data-theme="dark"] { --toast-bg: var(--raised); --toast-ink: var(--ink); --toast-muted: var(--muted); --toast-line: var(--line); }

.js main > .messages:not(.toasts) { display: none; }  /* states.js перенесёт их в уведомления; ниже — запасной вид, если скрипт не загрузился */
.js.no-states main > .messages:not(.toasts) { display: flex; }
/* Снизу, над нижней панелью телефона: --tabbar-offset (shell.css) — её высота, пока она видна, иначе 0 */
.toasts { position: fixed; z-index: 90; left: 50%; bottom: calc(var(--tabbar-offset, 0px) + 16px);
  transform: translateX(-50%); width: min(440px, calc(100vw - 32px)); margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; position: relative; display: flex; align-items: center; gap: 12px; margin: 0; overflow: hidden;
  padding: 12px 8px 12px 14px; border-radius: var(--r-m); background: var(--toast-bg); color: var(--toast-ink);
  border: 1px solid var(--toast-line); box-shadow: var(--shadow); font: 500 14.5px/1.4 var(--f-body);
  animation: toast-in var(--t-move, 320ms) var(--ease-spring, ease-out) both; }
.toast-ic { flex: none; display: grid; place-items: center; width: 20px; height: 20px; color: var(--ok); }
.toast.error .toast-ic, .toast.warning .toast-ic { color: var(--warn); }
.toast.info .toast-ic { color: var(--gold); }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-text small { display: block; margin-top: 2px; color: var(--toast-muted); font: 12px var(--f-code); }
.toast-text small button { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.toast-act { flex: none; min-height: 32px; padding: 0 10px; border: 0; border-radius: var(--r-s); background: none; color: var(--gold);
  font: 650 14px var(--f-body); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.toast-act:hover { background: color-mix(in srgb, var(--toast-ink) 10%, transparent); color: var(--gold); border: 0; }
.toast-x { flex: none; display: grid; place-items: center; width: 32px; min-height: 32px; padding: 0; border: 0; border-radius: var(--r-s);
  background: none; color: var(--toast-muted); cursor: pointer; }
.toast-x:hover { color: var(--toast-ink); background: color-mix(in srgb, var(--toast-ink) 10%, transparent); border: 0; }
.toast :focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
/* Сколько осталось до исчезновения — тонкая линия снизу; при наведении и фокусе время стоит */
.toast-left { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--gold); opacity: .55; transform-origin: left;
  animation: toast-left var(--toast-ms, 4000ms) linear both; }
.toast:is(:hover, :focus-within) .toast-left { animation-play-state: paused; }
@keyframes toast-left { to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-left { display: none; } }
.toast.leaving { animation: toast-out var(--t-base, 200ms) var(--ease-out, ease-out) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ——— Без сети: полоса сверху, пока нет соединения; набранный текст хранится в браузере ——— */
.offline-bar { position: fixed; z-index: 95; top: calc(var(--header-h, 56px) + 8px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 8px 14px 8px 12px; border-radius: 999px;
  background: var(--toast-bg); color: var(--toast-ink); border: 1px solid var(--toast-line); box-shadow: var(--shadow);
  font: 550 13.5px/1.35 var(--f-body); animation: toast-in var(--t-move, 320ms) var(--ease-out, ease-out) both; }
.offline-bar::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 30%, transparent); }
.offline-bar span { color: var(--toast-muted); font-weight: 450; }
.offline-bar[hidden] { display: none; }
@media (max-width: 560px) { .offline-bar span { display: none; } }

/* Черновик в браузере: <textarea data-draft> — «Вернуть · Удалить» над полем */
.draft-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0 0 8px; padding: 8px 8px 8px 12px;
  border-radius: var(--r-m); background: var(--gold-soft); color: var(--ink); font-size: 13.5px;
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); animation: toast-in var(--t-base, 200ms) var(--ease-out, ease-out) both; }
.draft-bar > span { flex: 1 1 auto; min-width: 12ch; }
.draft-bar > span b { font-weight: 650; }
.draft-bar button { min-height: 30px; padding: 0 10px; font-size: 13.5px; border-radius: var(--r-s); }
.draft-bar button.link-like { border-color: transparent; background: none; color: var(--muted); }
.draft-bar button.link-like:hover { color: var(--warn); border-color: transparent; }

/* ——— Нет прав (403), ошибка сервера (500), не найдено (404): одна форма для всех ——— */
.state-page { max-width: 620px; margin: clamp(16px, 7vh, 72px) auto 0; padding: clamp(32px, 6vw, 56px) clamp(20px, 5vw, 48px);
  gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl, 28px); box-shadow: var(--lift, none); }
.state-page .state-art { width: 120px; height: 90px; margin-bottom: 6px; }
.state-page .state-code { font: 600 13px var(--f-body); color: var(--accent); letter-spacing: .01em; }
.state-page h1 { margin: 0; font-size: clamp(26px, 4vw, 34px); line-height: 1.12; letter-spacing: -.025em; color: var(--ink); text-wrap: balance; }
.state-page > p { font-size: 15.5px; max-width: 48ch; }
.state-why { width: 100%; max-width: 480px; margin: 10px 0 2px; padding: 0; list-style: none; text-align: left; display: grid; gap: 1px;
  border-radius: var(--r-m); overflow: hidden; border: 1px solid var(--line); background: var(--line); }
.state-why > div { display: grid; grid-template-columns: 9.5em 1fr; gap: 12px; padding: 12px 14px; background: var(--surface); font-size: 14px; }
.state-why dt { color: var(--muted); }
.state-why dd { margin: 0; color: var(--ink); }
.state-why dd a { font-weight: 600; }
@media (max-width: 520px) { .state-why > div { grid-template-columns: 1fr; gap: 2px; } }
.state-page .state-acts { margin-top: 14px; }
.state-rid { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; padding: 6px 6px 6px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 13px; }
.state-rid code { font: 500 12.5px var(--f-code); color: var(--ink); user-select: all; }
.state-rid button { min-height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 999px; }
@media (max-width: 640px) { .state-page { margin-top: 8px; } .state-page .state-acts { width: 100%; } .state-page .state-acts .btn { flex: 1 1 100%; justify-content: center; } }

@media print { .toasts, .offline-bar, .draft-bar { display: none !important; } }

/* Видимая рамка фокуса на экранах-архетипах — 2 px акцентом с отступом 2 px (REDESIGN §4) */
.archetype main :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
