/* Панель «Мозг»: плоский спокойный стиль, светлая и тёмная темы через CSS-переменные.
   Дизайн-система (один раз для всей панели): шкала отступов --sp-1..--sp-5 (4/8/12/16/24), радиусы --r-*,
   типографика --fs-* (база 14px, на телефоне 15px, подписи 12px), высота контрола --ctl-h (на телефоне 44px -
   зона касания), цвета состояний --ok/--warn/--err/--accent и квадратов шахматки --sq-*, тени --shadow-*,
   подсветки --hover/--press/--selected. Компоненты: кнопка, иконка-кнопка, чип, карточка, таблица, поле, селект,
   модальное окно / нижний лист, тост - описаны ниже по одному разу. Телефон (<= 768px) - в конце файла. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1d2228;
  --muted: #5d6673;
  --border: #dde1e6;
  --border-strong: #7b8494;   /* рамки полей, кнопок, полосок: ≥ 3:1 к фону (WCAG 1.4.11) */
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --green: #1f8a4c;
  --yellow: #b7791f;
  --gray: #7b8494;            /* точка «не в сети»: 3.8:1 к белому */
  --bubble-user: #e5edff;
  --bubble-asst: #f0f2f5;
  --chip: #eef0f3;
  --focus: #1a56db;
  --lim-track: #e4e7eb;        /* фон полосы лимита - светло-серый */
  --lim-ok: #2f5fd0;
  --lim-mid: #d69e2e;
  --lim-high: #c53030;
  --lim-mid-text: #8a5a00;     /* текст подсказок: ≥ 4.5:1 к белому */
  --lim-ok-text: #1a7340;
  --radius: 8px;
  /* шахматка: фон квадрата / текст на нём (контраст текста ≥ 4.5:1) */
  --sq-done: #1f7a45; --sq-done-text: #ffffff;
  --sq-work: #f2c94c; --sq-work-text: #2b2100;
  --sq-wait: #e3e6ea; --sq-wait-text: #4a525e;
  --sq-redo: #c0312a; --sq-redo-text: #ffffff;
  --gate-border: rgba(0, 0, 0, .25); --warn-border: #8a5a00; --warn-text: #8a5a00;
  --gatebar-bg: #fff6d6; --gatebar-border: #8a5a00; --gatebar-text: #3d2c00;
  /* дизайн-система: отступы, радиусы, шрифт, контролы, тени, подсветки */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --r-pill: 999px;
  --fs-xs: 11px; --fs-sm: 12px; --fs-base: 14px; --fs-md: 15px; --fs-lg: 16px;
  --ctl-h: 32px; --touch: 44px; --nav-h: 58px;
  --ok: var(--green); --warn: var(--yellow); --err: var(--danger);
  --hover: rgba(29, 34, 40, .06); --press: rgba(29, 34, 40, .11);
  --selected: rgba(47, 95, 208, .12); --selected-border: rgba(47, 95, 208, .55);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .06); --shadow-2: 0 8px 24px rgba(0, 0, 0, .18);
  --shadow-3: 0 -8px 32px rgba(0, 0, 0, .22); --scrim: rgba(0, 0, 0, .38);
  --edge-shade: rgba(0, 0, 0, .16);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --panel: #1c2026;
    --panel-2: #232830;
    --text: #e6e9ed;
    --muted: #a0a8b3;
    --border: #2f353e;
    --border-strong: #77808c;
    --accent: #6b93f0;
    --accent-text: #0d1117;
    --danger: #f2827a;
    --green: #4cc38a;
    --yellow: #e0b04a;
    --gray: #6e7682;
    --bubble-user: #263452;
    --bubble-asst: #232830;
    --chip: #2a3039;
    --focus: #8fb0ff;
    --lim-track: #343a44;
    --lim-ok: #6b93f0;
    --lim-mid: #e0b04a;
    --lim-high: #f2827a;
    --lim-mid-text: #e0b04a;
    --lim-ok-text: #4cc38a;
    --sq-done: #237a46; --sq-done-text: #ffffff;
    --sq-work: #c9a227; --sq-work-text: #1d1600;
    --sq-wait: #2c323b; --sq-wait-text: #a7afba;
    --sq-redo: #b8322b; --sq-redo-text: #ffffff;
    --gate-border: rgba(255, 255, 255, .3); --warn-border: #f2c94c; --warn-text: #f2c94c;
    --gatebar-bg: #2e2810; --gatebar-border: #c9a227; --gatebar-text: #f5e7b0;
    --hover: rgba(230, 233, 237, .07); --press: rgba(230, 233, 237, .13);
    --selected: rgba(107, 147, 240, .2); --selected-border: rgba(107, 147, 240, .7);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-3: 0 -8px 32px rgba(0, 0, 0, .6); --scrim: rgba(0, 0, 0, .55);
    --edge-shade: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-base);
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
html, body { overflow-x: clip; }      /* страница вбок не прокручивается: широкое - внутри своих блоков */
code, .path, .viewer-path code, .gatebar-list code { overflow-wrap: anywhere; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
code, pre { font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { background: var(--panel-2); padding: 8px; border-radius: var(--radius); white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.error { color: var(--danger); margin: 6px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: var(--panel-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
/* одна высота контролов в ряду (кнопка = поле = селект); чипы, квадраты шахматки и ссылки-кнопки - свои размеры */
:where(button:not(.chip, .cell, .g-go)), :where(select), :where(input:not([type=checkbox], [type=radio])) { min-height: var(--ctl-h); }
button { line-height: 1.25; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:active:not(:disabled) { background: var(--press); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.primary:active:not(:disabled) { filter: brightness(.94); background: var(--accent); }
button.ghost:hover:not(:disabled) { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 2px 8px; font-size: 12px; min-height: 26px; }
input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 8px;
  width: 100%;
}
textarea { resize: vertical; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--text); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; background: var(--panel-2); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* общие компоненты, которые нужны и на телефоне: показ только на телефоне, иконки вкладок, ручка листа */
.m-only, .tab-more, .ti, .tab-short, .send-ic, .dlg-bar, .pop-handle, td.m-toggle, .chip-lim { display: none; }
.nav { display: flex; align-items: center; min-width: 0; }

/* Вход */
.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; width: 100%; max-width: 360px; display: grid; gap: 8px;
}
.login-card h1 { font-size: 22px; }
.login-card button { margin-top: 8px; }

/* Шапка */
/* Панель занимает ровно окно: шапка сверху, раздел под ней растягивается (прокрутка - внутри раздела) */
#app-view { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#app-view > main { flex: 1 1 auto; min-height: 0; }
.top {
  display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; flex: 0 0 auto;
  padding: 4px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.top button { padding: 3px 10px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand strong { font-size: 16px; }
.brand #summary { font-size: 12px; white-space: nowrap; }
.logo { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); display: inline-block; }
.tabs { display: flex; gap: 2px; }
.tabs [role=tab] { border-color: transparent; background: transparent; }
.tabs [role=tab][aria-selected=true] { background: var(--panel-2); border-color: var(--border); font-weight: 600; }
.tabs [role=tab]:hover:not([aria-selected=true]) { background: var(--hover); }
.actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* Меню пользователя (иконка человечка в шапке) */
.usermenu { position: relative; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border-radius: 50%; background: var(--panel-2); border-color: var(--border-strong);
}
.icon-btn[aria-expanded=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.icon { display: block; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 220px; max-width: calc(100vw - 32px);
  background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 6px;
}
.menu-user {
  margin: 0; padding: 6px 10px 8px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-user strong { color: var(--text); font-size: 14px; }
.menu { list-style: none; margin: 4px 0 0; padding: 0; }
.menu [role=menuitem] {
  display: block; width: 100%; text-align: left; background: transparent; border-color: transparent;
  padding: 8px 10px; min-height: 36px;
}
.menu [role=menuitem]:hover, .menu [role=menuitem]:focus { background: var(--panel-2); }
.menu [role=menuitem]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.menu-sep { height: 1px; margin: 4px 0; background: var(--border); }

/* Сетка из двух колонок: аккаунты слева, чат - всё остальное по ширине и высоте */
.grid {
  display: grid; grid-template-columns: clamp(280px, 24vw, 360px) minmax(0, 1fr); gap: 8px;
  grid-template-rows: minmax(0, 1fr);   /* длинный список слева не растягивает строку выше окна */
  padding: 8px;
}
.col { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-height: 0; min-width: 0; }
/* Левая колонка: список прокручивается сам, строка очереди прижата к низу */
.left { display: flex; flex-direction: column; overflow: hidden; padding: 10px 8px 0; }
.left > .col-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.col-toggle { display: none; }        /* видна только на узком экране */
.center { display: flex; flex-direction: column; padding: 0; overflow: hidden; }

.seg { display: flex; gap: 4px; margin-bottom: 8px; }
.seg button { flex: 1; }
.seg button[aria-pressed=true] { background: var(--panel-2); font-weight: 600; }
.filter { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; font-size: 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { margin-top: 4px; }
.item {
  display: grid; grid-template-columns: 12px 1fr; gap: 2px 8px; align-items: center; width: 100%;
  text-align: left; border-color: transparent; background: transparent; padding: 6px;
}
.item[aria-current=true] { background: var(--panel-2); border-color: var(--border); }
.item:hover:not([aria-current=true]) { background: var(--hover); }
/* Имя и пометки не обрезаются: пометки (тариф · компьютер) при нехватке места уходят на вторую строку */
.item .name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.acc .item .name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.acc-name { overflow-wrap: anywhere; }
.acc-meta { font-weight: 400; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.item .sub { grid-column: 2; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.item .sub-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Лимиты под аккаунтом: две компактные строки «5 ч» / «Неделя» (подпись, сброс и %, под ними полоса 6px) */
.lims { padding: 0 6px 4px 26px; display: grid; gap: 2px; container-type: inline-size; }
.acc { border: 1px solid transparent; border-radius: var(--radius); }
.acc > .item { padding-bottom: 2px; }
.acc:has(> .item[aria-current=true]) { background: var(--panel-2); border-color: var(--border); }
.acc > .item[aria-current=true] { border-color: transparent; }
.lim-cap { display: flex; align-items: baseline; gap: 6px; font-size: 11px; line-height: 14px; color: var(--muted); }
.lim-name { flex: 0 0 auto; color: var(--text); }
/* Время сброса и процент не обрезаются (без многоточий); при нехватке места «Сброс» -> «сбр.» */
.lim-reset { flex: 1 1 auto; min-width: 0; text-align: right; white-space: nowrap; }
@container (max-width: 230px) {
  .lim-reset .lw { font-size: 0; }
  .lim-reset .lw::before { content: "сбр."; font-size: 11px; }
}
.lim-pct { flex: 0 0 auto; min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.lbar { height: 6px; background: var(--lim-track); border-radius: 3px; overflow: hidden; }
.lbar > span { display: block; height: 100%; border-radius: 3px; background: var(--lim-ok); }
.lbar.mid > span { background: var(--lim-mid); }
.lbar.high > span { background: var(--lim-high); }
.lbar.none > span { display: none; }
.lhint { flex: 0 0 auto; font-size: 11px; font-weight: 600; }
.lhint.ok { color: var(--lim-ok-text); }
.lhint.mid { color: var(--lim-mid-text); }
.lhint.high { color: var(--danger); }
@media (forced-colors: active) { .lbar { border: 1px solid CanvasText; } .lbar > span { background: Highlight; } }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--gray); }
.dot.work { background: var(--green); }
.dot.wait { background: var(--yellow); }
.dot.off { background: var(--gray); }
.legend { margin-top: 12px; font-size: 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.prio { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 22px; display: inline-block; text-align: center; }
.prio.high { color: var(--danger); }

/* Очередь внизу левой колонки: строка «Очередь: N», раскрывается списком */
.queue-box { flex: 0 0 auto; border-top: 1px solid var(--border); margin: 6px -8px 0; padding: 4px 8px 6px; }
.queue-toggle {
  width: 100%; text-align: left; font-size: 13px; font-weight: 600; padding: 4px 6px;
  background: transparent; border-color: transparent;
}
.queue-toggle::after { content: " ▸"; color: var(--muted); }
.queue-toggle[aria-expanded=true]::after { content: " ▾"; }
.queue-toggle.empty, .queue-toggle:disabled { color: var(--muted); font-weight: 400; opacity: 1; cursor: default; }
.queue-toggle.empty::after { content: none; }
.qmini { list-style: none; margin: 2px 0 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.qmini li {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 0 6px; align-items: baseline;
  padding: 3px 4px; border-top: 1px solid var(--border); font-size: 12px;
}
.qmini .qt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmini .qmeta {
  grid-column: 2; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; min-width: 0;
}
.qmini .qproj { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmini .qwho { flex: 0 0 auto; white-space: nowrap; }

/* Полоски лимитов и прогресса */
.bar { height: 8px; background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; margin: 3px 0 6px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.warn > span { background: var(--yellow); }
.bar.ok > span { background: var(--green); }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.plain li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.plain li:last-child { border-bottom: 0; }

/* Чат */
/* Шапка чата - одна строка: имя, статус (обрезается), селект сессии, кнопки-иконки */
.chat-head {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-width: 0;
  padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--border);
}
.chat-head h2 { font-size: 15px; white-space: nowrap; flex: 0 0 auto; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.chat-sub {
  margin: 0; flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-head select { flex: 0 1 auto; max-width: 200px; }
.chat-tools { display: flex; gap: 4px; flex: 0 0 auto; margin-left: auto; }
.tip { display: inline-flex; }
.tool-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0;
  border-radius: 6px; background: var(--panel);
}
.tool-btn:disabled { pointer-events: none; }
.tool-btn, .pop-close { min-height: 0; }      /* квадратные иконки-кнопки: размер задан явно */   /* наведение достаётся обёртке .tip с той же подсказкой */
select.compact { width: auto; padding: 2px 6px; font-size: 13px; min-width: 0; }

/* Лента: растягивается между шапкой и полем ввода, прокручивается сама */
.feed { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.transcript {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 10px 12px 16px; background: var(--bg);
  display: flex; flex-direction: column; gap: 6px;
}
.transcript:focus-visible { outline-offset: -2px; }
.msg { position: relative; max-width: 100%; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg.user { align-self: flex-end; max-width: 75%; background: var(--bubble-user); padding: 6px 10px; border-radius: 12px 12px 4px 12px; }
.msg.user .body { white-space: pre-wrap; }
.msg.user .time { display: block; text-align: right; margin-top: 2px; }
.msg.assistant, .msg.tool, .msg.note { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 10px; align-items: start; }
.msg.assistant { padding: 2px 0; }
.msg.assistant .time, .msg.tool .time, .msg.note .time { padding-top: 2px; }
.msg.note { color: var(--muted); font-size: 12px; }
.msg.note.err { color: var(--danger); }
.msg.tool { gap: 0 10px; }

/* Простое оформление ответа (DOM-узлами, без HTML из данных) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 6px; }
.md .md-h { margin: 8px 0 4px; font-weight: 700; }
.md ul, .md ol { margin: 0 0 6px; padding-left: 20px; }
.md li + li { margin-top: 2px; }
.md code { background: var(--chip); border-radius: 4px; padding: 0 4px; }
.md pre { margin: 0 0 6px; overflow-x: auto; white-space: pre; word-break: normal; }
.md pre code { background: transparent; padding: 0; }

/* Вызовы инструментов - серые чипы в одну строку; результат - свёрнутая строка */
.chips { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.chip {
  background: var(--chip); border: 1px solid var(--border); border-radius: 6px; padding: 1px 8px;
  font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: left; cursor: pointer; color: var(--muted);
}
.chip b { font-weight: 600; color: var(--text); }
.chip code { font-size: 11px; }
.chip.result { background: transparent; border-color: transparent; padding-left: 4px; }
.chip.result::before { content: "↳ "; }
.chip[aria-expanded=true] { white-space: pre-wrap; overflow: visible; word-break: break-word; }
.chip.result[aria-expanded=true] { background: var(--chip); border-color: var(--border); }

/* «Сессия завершена» - тонкая линия с подписью */
.divider { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.empty { color: var(--muted); text-align: center; margin: auto; }

.newer {
  position: absolute; right: 16px; bottom: 12px; z-index: 2; border-radius: 16px; padding: 3px 12px;
  font-size: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
/* Тост: короткое подтверждение поверх ленты, места не занимает */
.toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 3;
  max-width: calc(100% - 32px); padding: 6px 14px; border-radius: 8px; font-size: 13px;
  background: var(--text); color: var(--panel); box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
.toast.on { opacity: 1; }
.toast:empty { padding: 0; }
.toast.err { background: var(--danger); color: var(--panel); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Поле ввода - одна панель: селекты слева, текст, «Отправить» справа */
.composer {
  display: flex; align-items: flex-end; gap: 8px; flex: 0 0 auto;
  padding: 8px; border-top: 1px solid var(--border); background: var(--panel);
}
.composer-sel { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; max-width: 220px; }
.sel-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sel-line > span { width: 48px; flex: 0 0 auto; }
.sel-line select { flex: 1 1 auto; max-width: 166px; color: var(--text); }
.composer textarea { flex: 1 1 auto; resize: none; min-height: 0; line-height: 1.45; overflow-y: auto; }
.composer button[type=submit] { flex: 0 0 auto; align-self: stretch; max-height: 60px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row label { white-space: nowrap; }
.row select { width: auto; min-width: 160px; }

/* Телефоны */
.phones { padding: 8px; display: flex; flex-direction: column; }
.phones iframe { flex: 1 1 auto; min-height: 0; }
.page { overflow-y: auto; width: 100%; }
.phones iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.hint { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; max-width: 720px; }

/* Модалки */
dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text);
  padding: 20px; width: min(520px, calc(100vw - 24px));
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { display: grid; gap: 6px; }
dialog h2 { margin-bottom: 6px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin-right: 12px; }
label.inline input { width: auto; }

/* Узкий экран (<900px): левая колонка - над чатом горизонтальной лентой аккаунтов, сворачивается кнопкой «Аккаунты» */
@media (max-width: 899px) {
  #app-view { height: auto; min-height: 100vh; }
  #view-brain { overflow: visible; }
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; padding: 6px; gap: 6px; }
  .left { overflow: visible; padding: 6px 8px 0; }
  .left > .col-body { overflow: visible; }
  .col-toggle {
    display: block; width: 100%; text-align: left; font-weight: 600; background: transparent; border-color: transparent;
    padding: 2px 4px;
  }
  .col-toggle::after { content: " ▾"; color: var(--muted); }
  .col-toggle[aria-expanded=false]::after { content: " ▸"; }
  .col.collapsed .col-body { display: none; }
  .col-toggle + .col-body { margin-top: 6px; }
  /* аккаунты и проекты - в одну горизонтальную ленту с прокруткой */
  #accounts, #projects {
    display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity;
  }
  #accounts > li, #projects > li { flex: 0 0 min(260px, 80vw); scroll-snap-align: start; }
  .list > li + li { margin-top: 0; }
  .legend { display: none; }
  .center { height: 85vh; min-height: 60vh; }
  .phones { height: 80vh; }
}
@media (max-width: 768px) {
  .actions { margin-left: 0; width: 100%; }
  .usermenu { margin-left: auto; }
  .msg.user { max-width: 90%; }
  .composer { flex-wrap: wrap; }
  .composer-sel { flex-direction: row; max-width: none; width: 100%; }
  .sel-line { flex: 1 1 0; min-width: 0; }
  .sel-line select { max-width: none; width: 100%; }
  .chat-head h2 { max-width: 50%; }
}

/* Встроенные страницы-вкладки (Подписки, Серии, Компьютеры, Очередь мини) */
.tabs { flex-wrap: wrap; }
.page { padding: 12px 16px 24px; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.page-head .row button { white-space: nowrap; }
.page-status { margin: 0 0 6px; min-height: 1em; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
/* Подсказка-тень по краю у прокручиваемых вбок блоков (шахматка, широкие таблицы): видна, пока есть что листать */
.table-wrap, .board-wrap, .scroll-x {
  background:
    linear-gradient(to right, var(--panel) 30%, transparent) left center / 32px 100% no-repeat local,
    linear-gradient(to left, var(--panel) 30%, transparent) right center / 32px 100% no-repeat local,
    linear-gradient(to right, var(--edge-shade), transparent) left center / 12px 100% no-repeat scroll,
    linear-gradient(to left, var(--edge-shade), transparent) right center / 12px 100% no-repeat scroll,
    var(--panel);
}
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td .bar { min-width: 90px; }
table.data td.acts { white-space: nowrap; text-align: right; }
table.data td.acts button + button { margin-left: 4px; }
table.data tr.soon td { background: color-mix(in srgb, var(--yellow) 16%, var(--panel)); }
table.data tr.overdue td { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); }
table.data tr.soon td:first-child { box-shadow: inset 4px 0 0 var(--yellow); }
table.data tr.overdue td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
table.data tr.archived td { color: var(--muted); text-decoration: line-through; }
table.data tr.archived td.acts { text-decoration: none; }
/* Подписки: компактная таблица, целиком по ширине ноутбука (1280-1440) без горизонтальной прокрутки.
   Остаток - числом без полоски; длинные тексты - до 2 строк с полным текстом в title. */
table.subs th, table.subs td { padding: 6px 7px; }
table.subs td { vertical-align: middle; }
table.subs .clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere;
}
table.subs td.c-name .clamp { max-width: 11em; }
table.subs td.c-acc .clamp { max-width: 10em; }
table.subs td.c-plan .clamp { max-width: 9em; }
table.subs td.c-note { color: var(--muted); }
table.subs td.c-note .clamp { max-width: 15em; }
table.subs td.c-date { min-width: 10em; }
table.subs td.c-date .nw { white-space: nowrap; }
table.subs td.c-price { white-space: normal; }
table.subs td.acts button { padding-left: 8px; padding-right: 8px; }
table.subs.notes-hidden .c-note { display: none; }
/* Телефон: карточки вместо таблицы */
@media (max-width: 768px) {
  .subs-wrap { overflow-x: visible; background: transparent; border: 0; }
  table.subs, table.subs tbody, table.subs tr, table.subs td { display: block; width: 100%; }
  table.subs .clamp { max-width: none !important; }
  table.subs thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.subs tr {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; padding: 4px 0;
  }
  table.subs td { border-bottom: 0; padding: 4px 12px; min-width: 0; }
  table.subs td[data-label] { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 0 8px; justify-items: start; align-items: baseline; }
  table.subs td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  table.subs td[data-label] > * { grid-column: 2; }
  table.subs td.c-name { font-size: 14px; }
  table.subs td.acts { text-align: left; padding-top: 6px; }
  table.subs tr.soon td:first-child, table.subs tr.overdue td:first-child { box-shadow: none; }
  table.subs tr.soon { border-left: 4px solid var(--yellow); }
  table.subs tr.overdue { border-left: 4px solid var(--danger); }
  table.subs tr.soon td, table.subs tr.overdue td { background: transparent; }
  table.subs tr.soon { background: color-mix(in srgb, var(--yellow) 16%, var(--panel)); }
  table.subs tr.overdue { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); }
}
.tag { display: inline-block; border-radius: 10px; padding: 0 8px; font-size: 12px; border: 1px solid var(--border-strong); white-space: nowrap; }
.tag.soon, .tag.stale { border-color: var(--yellow); color: var(--yellow); }
.tag.overdue, .tag.disk, .tag.failed { border-color: var(--danger); color: var(--danger); }
.tag.ok, .tag.done { border-color: var(--green); color: var(--green); }
.tag.running { border-color: var(--accent); color: var(--accent); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.swatch.soon { background: var(--yellow); }
.swatch.overdue { background: var(--danger); margin-left: 10px; }
.total { font-weight: 600; margin: 10px 2px; }
.journal { margin-top: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.journal summary { cursor: pointer; font-weight: 600; }
.journal li { font-size: 12px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.card h3 { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); margin: 0 0 4px; }
.card .meta { font-size: 12px; color: var(--muted); margin: 0 0 6px; overflow-wrap: anywhere; }
.card table.data { font-size: 12px; }
.card table.data th, .card table.data td { padding: 5px 6px; }
.qlist { list-style: none; margin: 0; padding: 0; }
.qlist li { padding: 6px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; }
.qlist li:last-child { border-bottom: 0; }
.qlist .qname { font-weight: 600; overflow-wrap: anywhere; }
.qlist .qsub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 8px 12px; align-items: center; }
.form-grid textarea { grid-column: 2; }
dialog { max-width: min(560px, calc(100vw - 32px)); }
@media (max-width: 768px) {
  .page { padding: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid textarea { grid-column: auto; }
  table.data th, table.data td { padding: 6px; }
}
/* Статистика сериалов с мини (вкладка «Серии») */
.section-title { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); margin: 14px 0 8px; }
.stats { margin-bottom: 8px; }
.tiles { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.tiles li { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.tiles .tile-val { display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tiles .tile-label { font-size: 12px; color: var(--muted); }
.tiles li.warn { box-shadow: inset 4px 0 0 var(--yellow); }
.charts { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); margin-bottom: 10px; }
.chart-box { margin: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.chart-box figcaption { font-size: 12px; color: var(--muted); font-weight: 600; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 10px; }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.frames { stroke: var(--accent); }
.chart .line.clips { stroke: var(--green); }
.chart .pt.frames { fill: var(--accent); }
.chart .pt.clips { fill: var(--green); }
.stats-list { display: grid; gap: 8px; }
.series-block { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.series-block > summary { cursor: pointer; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.series-block > summary strong { font-size: 15px; }
.series-block > summary .meta { font-size: 12px; color: var(--muted); }
.series-block[open] > summary { border-bottom: 1px solid var(--border); }
.series-block .table-wrap { border: 0; border-radius: 0 0 12px 12px; }
.jobs { margin: 0; padding-left: 16px; font-size: 12px; }
.stats-queue-cols { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
@media (forced-colors: active) {
  .tiles li.warn { border-left: 4px solid CanvasText; }
  table.data tr.soon td:first-child, table.data tr.overdue td:first-child { border-left: 4px solid CanvasText; }
}

/* ── шахматка серий (вкладка «Серии») ── */
.board-sec { margin-bottom: 16px; }
.tiles li.st-sent { box-shadow: inset 4px 0 0 var(--sq-done); }
.tiles li.st-ready { box-shadow: inset 4px 0 0 var(--green); }
.tiles li.st-work { box-shadow: inset 4px 0 0 var(--sq-work); }
.tiles li.st-redo { box-shadow: inset 4px 0 0 var(--sq-redo); }
.board-legend { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; }
.board-legend li { display: inline-flex; align-items: center; gap: 6px; }
.sq { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 4px; font-size: 12px; font-weight: 700; position: relative; }
.board-block { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-top: 12px; }
.board-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.board-head h4 { margin: 0; font-size: 15px; font-weight: 600; }
.board-head .meta { font-size: 12px; color: var(--muted); }
.board-n-row { display: flex; margin-left: auto; gap: 8px; align-items: center; }
.board-n { width: 72px; }
.board-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0 0 12px 12px; }
/* Таблица: единый размер кубика, равные промежутки 8px, заголовки ровно над кубиками */
table.board { --cell-w: 52px; --cell-h: 42px; border-collapse: separate; border-spacing: 8px; margin: 0 4px 0 0;
  font-variant-numeric: tabular-nums; }
table.board th { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0; text-align: center; vertical-align: bottom;
  white-space: nowrap; line-height: 1.25; }
table.board thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
/* закреплённая колонка с номером серии при горизонтальной прокрутке */
table.board .ep-col { position: sticky; left: 0; z-index: 2; background: var(--panel); min-width: 40px; text-align: right; padding-right: 4px; color: var(--text); font-size: 13px; vertical-align: middle; }
table.board thead .ep-col { z-index: 3; color: var(--muted); font-size: 12px; vertical-align: bottom; }
table.board td { padding: 0; vertical-align: middle; }
.cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: var(--cell-w); height: var(--cell-h); min-width: 0; padding: 0; margin: 0; box-sizing: border-box;
  border-radius: 6px; border: 1px solid transparent; font: inherit; font-size: 11px; cursor: pointer; line-height: 1.1; }
.cell .l { font-size: 12px; font-weight: 700; }
.cell .v { font-size: 10.5px; font-weight: 500; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: clip; max-width: 100%; opacity: .92; }
.cell.saving { opacity: .75; }
/* Упаковка и Выпуск: один квадрат того же размера, что и остальные, под ним две галочки «РУ» и «КЗ» в один ряд
   (одинаковые, по центру под квадратом); у Выпуска ещё ниже - дата последней отметки (ДД.ММ) */
.split { display: flex; gap: 4px; }
.sq-ticks { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ticks { display: flex; justify-content: center; gap: 4px; }
.tick { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 3px; min-width: 31px; height: 20px;
  padding: 0 3px; border-radius: 5px; font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer;
  user-select: none; -webkit-tap-highlight-color: transparent; }
.tick:hover { background: var(--hover); color: var(--text); }
.tick:has(.tick-in:checked) { color: var(--text); }
.tick .tick-in { width: 14px; height: 14px; margin: 0; }
.tick.warn { outline: 2px dashed var(--warn-border); outline-offset: -1px; }
.tick:focus-within { outline: 2px solid var(--focus); outline-offset: 0; }
.tick-day { min-height: 12px; font-size: 10.5px; line-height: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tick-demo { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; }
.tick-box { display: inline-block; width: 12px; height: 12px; border: 1.5px solid var(--border-strong); border-radius: 3px; }
.tick-box.on { background: var(--accent); border-color: var(--accent); }
.tick-box + span { margin-right: 4px; }
/* брак N (НБ, VD) и ворота «да» (НБ) - мелко внизу квадрата, содержимое поднимается */
.cell[data-stage="nb"], .cell[data-stage="vd"] { justify-content: flex-start; padding-top: 4px; }
.cell .rej { position: absolute; bottom: 2px; left: 3px; font-size: 9px; font-weight: 600; opacity: .9; }
.cell .gate, .gate { display: inline-block; font-size: 9px; font-weight: 700; padding: 0 3px; border-radius: 3px; line-height: 12px;
  border: 1px solid var(--gate-border); }
.cell .gate { position: absolute; bottom: 2px; right: 2px; }
.gate.g-wait { background: var(--sq-wait); color: var(--sq-wait-text); }
.gate.g-yes { background: var(--sq-done); color: var(--sq-done-text); }
.gate.g-no { background: var(--sq-redo); color: var(--sq-redo-text); }
/* предупреждение (КЗ раньше РУ, VD без «да»): «!» и пунктирная рамка - не только цветом */
.cell.warn { border: 2px dashed var(--warn-border); }
.cell .wmark, .sq.warn { font-weight: 800; }
.cell .wmark { position: absolute; top: 1px; left: 4px; font-size: 11px; }
.warn-text { color: var(--warn-text); font-weight: 600; }
.cols-list { display: grid; gap: 6px; max-height: 55vh; overflow: auto; }
.cols-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 8px; align-items: center; border: 1px solid var(--border); border-radius: 8px; }
.cols-row legend { font-weight: 600; }
.cols-row > label:first-of-type { grid-column: 1 / -1; }
.cols-kind label { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.cols-kind input { margin: 0; }
.s-done { background: var(--sq-done); color: var(--sq-done-text); }
.s-work { background: var(--sq-work); color: var(--sq-work-text); }
.s-wait { background: var(--sq-wait); color: var(--sq-wait-text); }
.s-redo { background: var(--sq-redo); color: var(--sq-redo-text); }
/* ручное значение (клик или доска) - уголок справа сверху */
.cell.manual::after, .sq.manual::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid;
  border-width: 0 8px 8px 0; border-color: transparent currentColor transparent transparent; border-top-right-radius: 5px; opacity: .8; }
.cell:hover { filter: brightness(.95); border-color: var(--border-strong); }
.cell:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; z-index: 1; }
tr.row-wait .ep-col { color: var(--muted); font-weight: 400; }
/* заметки сериала - сворачиваемый блок под шапкой */
.board-notes { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.board-notes summary { cursor: pointer; color: var(--muted); font-size: 12px; width: max-content; }
.board-notes .notes-text { display: block; width: 100%; box-sizing: border-box; margin-top: 8px; font: inherit; font-size: 13px;
  min-height: 72px; resize: vertical; }
.board-notes-acts { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
/* мини-окошко квадрата: подписи слева фиксированной ширины, поля одной высоты */
.cell-pop { position: fixed; z-index: 50; width: 320px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  overflow: auto; box-sizing: border-box; background: var(--panel); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 10px 12px 12px; font-size: 13px; }
.cell-pop[hidden], .cell-pop [hidden] { display: none !important; }
.cell-pop.sheet { left: 8px; right: 8px; bottom: 8px; top: auto; width: auto; max-height: 75vh; }
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pop-head h2 { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.3; }
.pop-close { flex: 0 0 auto; width: 28px; height: 28px; padding: 0; border-radius: 6px; background: transparent; border: 1px solid transparent;
  font-size: 18px; line-height: 1; color: var(--muted); cursor: pointer; }
.pop-close:hover { border-color: var(--border); }
.pop-sub { margin: 2px 0 10px; font-size: 12px; color: var(--muted); }
.pop-warn { margin: 0 0 10px; font-size: 12px; }
.pop-grid { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; align-items: center; }
.pop-grid > label { font-size: 12px; color: var(--muted); }
.pop-grid input, .pop-grid textarea { width: 100%; min-width: 0; box-sizing: border-box; height: 30px; padding: 4px 8px; font: inherit; font-size: 13px; margin: 0; }
.pop-grid textarea { height: auto; min-height: 52px; resize: vertical; }
.pop-grid > label[for="cell-note"] { align-self: start; padding-top: 7px; }
.pop-pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 6px; align-items: center; }
.pop-of { font-size: 12px; color: var(--muted); }
.pop-line { display: flex; gap: 6px; align-items: center; min-width: 0; }
.pop-line input { flex: 1 1 auto; }
.pop-checks { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
.pop-checks legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 6px; }
#cell-checks { display: grid; gap: 4px; }
.pop-checks .chk { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 8px; align-items: center; min-height: 24px; font-size: 13px; cursor: pointer; }
.pop-checks .chk input { margin: 0; width: 16px; height: 16px; }
.pop-gate { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.pop-gate-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pop-gate-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
.pop-gate-state { font-size: 12px; color: var(--muted); }
.pop-gate-acts { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
.pop-hist { margin-top: 12px; font-size: 12px; }
.pop-hist summary { cursor: pointer; color: var(--muted); width: max-content; }
.pop-hist ol { max-height: 140px; overflow: auto; margin: 6px 0 0; padding: 0; }
.pop-hist li { padding: 2px 0; overflow-wrap: anywhere; }
.pop-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; }
.cell-pop .error { margin: 8px 0 0; font-size: 12px; }
/* тост шахматки: «Серия 3 · МТ: З» + «Отменить» */
.btoast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 12px;
  box-sizing: border-box; max-width: calc(100vw - 24px); padding: 6px 6px 6px 14px; border-radius: 8px; background: var(--text);
  color: var(--panel); font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.btoast[hidden], .btoast-undo[hidden] { display: none; }
.btoast.err { background: var(--sq-redo); color: var(--sq-redo-text); }
.btoast-text { min-width: 0; overflow-wrap: anywhere; }
.btoast-undo { flex: 0 0 auto; background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 6px;
  padding: 4px 10px; font: inherit; font-weight: 600; cursor: pointer; }
@media (max-width: 768px) {
  table.board { --cell-w: 46px; --cell-h: 40px; border-spacing: 6px; }
  .board-n-row { margin-left: 0; }
}
@media (forced-colors: active) {
  .cell, .sq { border: 1px solid CanvasText; }
  .cell.s-done { border-width: 3px; }
  .cell.s-redo { border-style: dashed; border-width: 3px; }
  .gate { border: 1px solid CanvasText; }
  .gate.g-yes { border-width: 2px; }
  .gate.g-no { border-style: dashed; }
}

/* Полоса «Ждут вашего да» (под шапкой; скрыта, когда ждущих нет) */
.gatebar { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 4px 14px;
  background: var(--gatebar-bg); color: var(--gatebar-text); border-bottom: 1px solid var(--gatebar-border); }
.gatebar[hidden] { display: none; }
.gatebar-toggle { font-weight: 600; background: transparent; color: inherit; border-color: var(--gatebar-border); }
.gatebar-toggle::after { content: " ▸"; }
.gatebar-toggle[aria-expanded=true]::after { content: " ▾"; }
.gatebar-hint { font-size: 12px; color: inherit; opacity: .85; }
.gatebar-list { flex: 1 1 100%; list-style: none; margin: 0; padding: 0 0 4px; max-height: 40vh; overflow-y: auto; }
.gatebar-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 5px 0;
  border-top: 1px solid var(--gatebar-border); min-width: 0; }
.gatebar-list .g-go { font-weight: 600; background: transparent; color: inherit; border: none; padding: 0;
  text-decoration: underline; cursor: pointer; }
.gatebar-list .g-age { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gatebar-list .g-anim { font-size: 12px; overflow-wrap: anywhere; min-width: 0; flex: 1 1 200px; }
.gatebar-list .g-anim code { font-size: 12px; }
.gatebar-list .g-anim a { color: inherit; }
.gatebar-list .g-acts { display: flex; gap: 6px; margin-left: auto; }
@media (max-width: 768px) { .gatebar-list .g-acts { margin-left: 0; } .gatebar-hint { display: none; } }
@media (forced-colors: active) { .gatebar { border-bottom: 1px solid CanvasText; } .gatebar-list li { border-top-color: CanvasText; } }

/* ── «Генерации»: очередь центра генерации ── */
.gen-attention { margin: 6px 0 10px; padding: 8px 12px; border: 2px solid var(--danger); border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 10%, var(--panel)); }
.gen-attention[hidden] { display: none; }
.gen-attention h3 { margin: 0 0 4px; font-size: 15px; color: var(--danger); }
.gen-attention ul { margin: 0; padding-left: 18px; }
.gen-attention li { overflow-wrap: anywhere; }
.gen-summary { margin: 4px 0 8px; font-weight: 600; }
.gen-filters { flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 8px; }
table.gen td { vertical-align: top; }
table.gen .gen-prompt { max-width: 22em; }
table.gen .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere; }
table.gen .gen-prio .num { min-width: 1.2em; text-align: right; }
table.gen .gen-prio button { min-width: 28px; padding: 2px 6px; }
table.gen code { font-size: 12px; overflow-wrap: anywhere; }
.gen-err { display: block; color: var(--danger); max-width: 18em; overflow-wrap: anywhere; }
table.gen tr.attn td { background: color-mix(in srgb, var(--danger) 12%, var(--panel)); }
table.gen tr.attn td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.tag.st-queued { border-color: var(--border-strong); color: var(--muted); }
.tag.st-claimed, .tag.st-running { border-color: var(--accent); color: var(--accent); }
.tag.st-done { border-color: var(--green); color: var(--green); }
.tag.st-failed, .tag.st-needs_human { border-color: var(--danger); color: var(--danger); font-weight: 600; }
.tag.st-cancelled { border-color: var(--gray); color: var(--muted); text-decoration: line-through; }
@media (max-width: 768px) {
  table.gen .gen-prompt { max-width: 14em; }
}
@media (forced-colors: active) {
  .gen-attention, table.gen tr.attn td:first-child { border: 2px solid CanvasText; }
}

/* ── просмотр файлов с мини (модальный плеер) ── */
dialog.viewer { max-width: min(1100px, calc(100vw - 32px)); width: min(1100px, calc(100vw - 32px)); padding: 10px 12px; }
.viewer-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.viewer-title { flex: 1 1 auto; margin: 0 !important; font-size: 16px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.viewer-zoom[hidden] { display: none; }
.viewer-body { display: flex; justify-content: center; align-items: flex-start; max-height: 75vh; overflow: auto;
  background: #000; border-radius: var(--radius); }
.viewer-body:empty { display: none; }
.viewer-video { display: block; width: 100%; max-height: 75vh; background: #000; }
.viewer-img { display: block; max-width: 100%; max-height: 75vh; cursor: zoom-in; }
.viewer-img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-msg { margin: 6px 0; }
.viewer-msg:empty { display: none; }
.viewer-msg.error { color: var(--danger); font-weight: 600; }
.viewer-path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 0; }
.viewer-path code { overflow-wrap: anywhere; }
@media (max-width: 768px) {   /* телефон: просмотр во весь экран */
  dialog.viewer { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0;
    border-radius: 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
  dialog.viewer:not([open]) { display: none; }
  dialog.viewer .viewer-body { flex: 1 1 auto; max-height: none; align-items: center; }
  dialog.viewer .viewer-video, dialog.viewer .viewer-img:not(.zoomed) { max-height: 100%; }
}

/* ── шахматка: сворачиваемые блоки сериалов, закреплённые шапка и первый столбец ── */
.board-head .blk-toggle { flex: 0 0 auto; width: 28px; height: 28px; min-height: 28px; padding: 0; border-radius: var(--r-sm);
  border-color: transparent; background: transparent; color: var(--muted); }
.board-head .blk-toggle:hover { background: var(--hover); color: var(--text); }
.blk-toggle .chev { display: block; transition: transform .15s; }
.board-block.collapsed .blk-toggle .chev { transform: rotate(-90deg); }
.board-block.collapsed .board-body { display: none; }
.board-block.collapsed .board-head { border-bottom: 0; }
.board-wrap { max-height: 75vh; max-height: 75dvh; overscroll-behavior-x: contain; }
@media (prefers-reduced-motion: reduce) { .blk-toggle .chev { transition: none; } }

/* ── нижние листы (телефон): «Ещё», «Все аккаунты», модальные окна, мини-окошко квадрата ── */
.sheet-scrim { position: fixed; inset: 0; z-index: 65; background: var(--scrim); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; max-height: 85vh; max-height: 85dvh; overflow-y: auto;
  overscroll-behavior: contain; background: var(--panel); color: var(--text); border-top: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-3); padding: 0 var(--sp-3) calc(var(--sp-3) + var(--safe-b)); }
.sheet-bar { position: relative; display: flex; align-items: center; gap: var(--sp-2); padding: 18px 0 var(--sp-2) var(--sp-1);
  touch-action: none; }
.sheet-handle { position: absolute; top: 6px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px;
  background: var(--border-strong); opacity: .7; }
.sheet-title { flex: 1 1 auto; min-width: 0; margin: 0; font-size: var(--fs-lg); font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.sheet-close { flex: 0 0 auto; width: var(--touch); height: var(--touch); background: transparent; border-color: transparent; }
.sheet-close:hover { background: var(--hover); }
.sheet-list { list-style: none; margin: 0; padding: 0 0 var(--sp-1); display: grid; gap: var(--sp-1); }
.sheet-item { display: flex; align-items: center; justify-content: flex-start; gap: var(--sp-3); width: 100%; min-height: 52px;
  padding: 0 var(--sp-3); border-color: transparent; background: transparent; border-radius: var(--r-lg);
  font-size: var(--fs-md); text-align: left; }
.sheet-item .ti { display: block; flex: 0 0 auto; color: var(--muted); }
.sheet-item:hover { background: var(--hover); }
.sheet-item.on { background: var(--selected); color: var(--accent); font-weight: 600; }
.sheet-item.on .ti { color: var(--accent); }
.dragging { transition: none !important; }
@media (min-width: 769px) {     /* на широком экране листов нет: ручки и крестики листов скрыты */
  .sheet-bar.dlg-bar, .left > .sheet-bar { display: none; }
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ── телефон и узкие экраны (<= 768px) ──
   Ничего не выходит за экран: страница вбок не прокручивается, широкое (шахматка, таблицы) - внутри своих блоков с
   тенью-подсказкой по краю. Нижняя панель разделов фиксирована и учитывает safe-area; зона касания >= 44x44px,
   между кнопками >= 8px; модальные окна - нижние листы; высота - по видимой области (100dvh / --vvh). */
@media (max-width: 768px) {
  :root { --fs-base: 15px; --ctl-h: 44px; }
  body { font-size: 15px; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }   /* iOS не увеличивает */
  button:not(.chip):not(.cell):not(.g-go), select, input:not([type=checkbox]):not([type=radio]) { min-height: 44px; }
  button.small { padding: 4px 12px; font-size: 13px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  label.inline { min-height: 44px; }
  .row { gap: var(--sp-2); }
  .m-only { display: block; }
  li.m-only { display: list-item; }
  .left:not(.sheet-open) > .sheet-bar { display: none; }

  /* окно = видимая область; внизу - место под панель разделов */
  #app-view { height: 100vh; height: var(--vvh, 100dvh); min-height: 0;
    padding-bottom: calc(var(--nav-h) + var(--safe-b)); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  #app-view > main { min-height: 0; }
  body.kb-open #app-view { padding-bottom: 0; }

  /* шапка: название и меню пользователя */
  .top { flex-wrap: nowrap; gap: var(--sp-2); min-height: 52px; padding: 4px 4px 4px 14px;
    padding-top: max(4px, env(safe-area-inset-top)); }
  .brand strong { font-size: 17px; }
  .brand #summary { display: none; }
  .actions { margin-left: auto; width: auto; gap: var(--sp-2); }
  #btn-account, #btn-task { display: none; }
  .top .icon-btn { width: 44px; height: 44px; }
  .menu-pop { min-width: 240px; right: 4px; }
  .menu [role=menuitem] { min-height: 44px; font-size: var(--fs-md); }

  /* нижняя панель разделов: иконка + подпись, активная подсвечена, лишние - в «Ещё» */
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; align-items: stretch;
    height: calc(var(--nav-h) + var(--safe-b)); padding: 0 env(safe-area-inset-right) var(--safe-b) env(safe-area-inset-left);
    background: var(--panel); border-top: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(0, 0, 0, .06); }
  body.kb-open .nav { display: none; }
  .tabs { flex: 4 1 0; display: flex; flex-wrap: nowrap; gap: 0; min-width: 0; }
  .tabs [role=tab], .tab-more { flex: 1 1 0; min-width: 0; height: var(--nav-h); min-height: 44px; padding: 6px 2px 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: var(--fs-xs); font-weight: 500; }
  .tab-more { flex: 1 1 0; }
  .tabs .tab-extra { display: none; }
  .ti { display: block; box-sizing: content-box; width: 24px; height: 24px; padding: 2px 14px; border-radius: var(--r-pill); }
  .tab-l { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 14px; }
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .tabs [role=tab][aria-selected=true], .tab-more.on { color: var(--accent); background: transparent; font-weight: 600; }
  .tabs [role=tab][aria-selected=true] .ti, .tab-more.on .ti { background: var(--selected); }
  .tabs [role=tab]:hover:not([aria-selected=true]), .tab-more:hover { background: transparent; color: var(--text); }
  .tabs [role=tab]:active .ti, .tab-more:active .ti { background: var(--press); }
  .tabs [role=tab]:focus-visible, .tab-more:focus-visible { outline-offset: -3px; }

  /* «Ждут вашего да»: компактно, кнопки удобно нажимаются */
  .gatebar { padding: 4px 12px; gap: 4px 8px; }
  .gatebar-toggle { min-height: 40px; padding: 4px 12px; }
  .gatebar-list li { gap: 8px; padding: 8px 0; }
  .gatebar-list .g-go { min-height: 32px; text-align: left; }
  .gatebar-list .g-anim { flex: 1 1 100%; }
  .gatebar-list .g-acts { width: 100%; gap: var(--sp-2); }
  .gatebar-list .g-acts button { flex: 1 1 0; min-height: 44px; }

  /* «Мозг»: лента чипов аккаунтов сверху, чат на весь экран */
  #view-brain.grid { display: flex; flex-direction: column; padding: 0; gap: 0; overflow: hidden; }
  .left { flex: 0 0 auto; padding: 8px 0; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; overflow: visible; }
  .col-toggle { display: none; }
  .left.collapsed .col-body, .left > .col-body { display: block; overflow: visible; }
  .left .seg, .left .legend, .left .queue-box, .left #project-filter { display: none; }
  .acc-strip { display: flex; align-items: center; gap: var(--sp-2); padding: 0 12px; min-width: 0; }
  #accounts, #projects { flex: 1 1 auto; min-width: 0; display: flex; gap: var(--sp-2); overflow-x: auto; padding: 0;
    scroll-snap-type: x proximity; scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent); }
  #accounts::-webkit-scrollbar, #projects::-webkit-scrollbar { display: none; }
  #accounts > li, #projects > li { flex: 0 0 auto; scroll-snap-align: start; }
  .list > li + li { margin-top: 0; }
  #accounts .acc { border: 1px solid var(--border-strong); border-radius: var(--r-pill); background: var(--panel); }
  #accounts .acc:has(> .item[aria-current=true]) { background: var(--selected); border-color: var(--selected-border); }
  #accounts .item, #projects .item { display: flex; align-items: center; gap: 8px; width: auto; min-height: 44px;
    padding: 0 14px 0 12px; border-radius: var(--r-pill); white-space: nowrap; }
  #accounts .item .name { display: block; }
  #accounts .item .sub, #accounts .lims, #accounts .acc-meta, #projects .item .sub { display: none; }
  #accounts .chip-lim { display: block; flex: 0 0 auto; width: 26px; height: 4px; border-radius: 2px; }
  #accounts .chip-lim.none { opacity: .5; }
  .all-acc { flex: 0 0 auto; min-height: 44px; padding: 0 14px; border-radius: var(--r-pill); font-size: 13px; white-space: nowrap; }
  /* «Все аккаунты» - та же колонка нижним листом: полный список и полоски лимитов 5 ч / неделя */
  .left.sheet-open { position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; display: flex; flex-direction: column;
    max-height: 85vh; max-height: 85dvh; padding: 0 0 var(--safe-b); background: var(--panel);
    border: 1px solid var(--border); border-bottom: 0; border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-3);
    animation: sheet-in .22s ease-out; }
  .left.sheet-open .sheet-bar { display: flex; padding: 18px 8px 8px 16px; }
  .left.sheet-open > .col-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 12px; }
  .left.sheet-open .seg { display: flex; }
  .left.sheet-open .seg button { min-height: 44px; }
  .left.sheet-open .legend { display: flex; }
  .left.sheet-open .queue-box { display: block; margin: 0; padding: 4px 12px 8px; }
  .left.sheet-open #project-filter:not([hidden]) { display: flex; }
  .left.sheet-open .acc-strip { display: block; padding: 0; }
  .left.sheet-open .all-acc { display: none; }
  .left.sheet-open #accounts, .left.sheet-open #projects { display: block; overflow: visible; -webkit-mask-image: none; mask-image: none; }
  .left.sheet-open .list > li + li { margin-top: 4px; }
  .left.sheet-open #accounts .acc { border-color: transparent; border-radius: var(--r-md); background: transparent; }
  .left.sheet-open #accounts .acc:has(> .item[aria-current=true]) { background: var(--panel-2); border-color: var(--border); }
  .left.sheet-open #accounts .item, .left.sheet-open #projects .item { display: grid; width: 100%; padding: 8px;
    border-radius: var(--r-md); white-space: normal; }
  .left.sheet-open #accounts .item .name { display: flex; }
  .left.sheet-open #accounts .item .sub, .left.sheet-open #projects .item .sub { display: flex; }
  .left.sheet-open #accounts .lims { display: grid; }
  .left.sheet-open #accounts .acc-meta { display: inline; }
  .left.sheet-open #accounts .chip-lim { display: none; }
  body.sheet-lock { overflow: hidden; }

  .center { flex: 1 1 auto; height: auto; min-height: 0; border: 0; border-radius: 0; }
  /* шапка чата одной строкой: имя, статус, иконки «стоп» / «передать» */
  .chat-head { min-height: 52px; gap: 6px; padding: 4px 4px 4px 12px; }
  .chat-head h2 { font-size: var(--fs-lg); max-width: 42%; }
  .chat-head select { max-width: 30%; }
  .chat-tools { gap: 0; }
  .tool-btn { width: 44px; height: 44px; border-radius: var(--r-md); border-color: transparent; background: transparent; }
  .tool-btn:hover { background: var(--hover); }
  .transcript { padding: 12px 12px 16px; gap: 8px; }
  .msg.user { max-width: 86%; }
  .chip { max-width: 100%; padding: 3px 10px; }
  .newer { bottom: 12px; right: 12px; min-height: 36px; }
  /* поле ввода прилипает над нижней панелью: «Кому» / «Проект» - компактный ряд, поле растёт, отправка справа */
  .composer { flex-wrap: wrap; gap: var(--sp-2); padding: 8px 12px; align-items: flex-end; }
  .composer-sel { flex: 1 1 100%; flex-direction: row; gap: var(--sp-2); max-width: none; width: 100%; }
  .sel-line { flex: 1 1 0; min-width: 0; gap: 6px; }
  .sel-line > span { width: auto; font-size: var(--fs-sm); }
  .sel-line select { flex: 1 1 auto; width: 100%; max-width: none; min-width: 0; min-height: 40px; padding: 4px 8px; font-size: 15px; }
  .composer textarea { flex: 1 1 0; min-width: 0; min-height: 44px; max-height: 40vh; max-height: 40dvh; padding: 10px 14px;
    border-radius: 22px; font-size: 16px; line-height: 1.35; }
  .composer button[type=submit].send-btn { flex: 0 0 44px; width: 44px; height: 44px; max-height: none; min-height: 44px;
    align-self: flex-end; padding: 0; border-radius: 50%; font-size: 0; }
  .send-ic { display: block; }

  /* «Телефоны»: плеер на всю доступную высоту над нижней панелью */
  .phones { height: auto; padding: 0; }
  .phones iframe { border: 0; border-radius: 0; }
  .hint { margin: 12px; padding: 16px; }

  /* встроенные страницы */
  .page { padding: 12px 12px 24px; }
  .page-head { gap: var(--sp-2); margin-bottom: var(--sp-2); }
  .page-head h2 { font-size: 18px; }
  .page-head .row { gap: var(--sp-2); }
  .section-title { margin: 16px 0 8px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); }
  table.data td.acts button + button { margin-left: var(--sp-2); }
  .journal summary { min-height: 44px; display: flex; align-items: center; }
  .card h3 { overflow-wrap: anywhere; }
  .qlist .qname { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
  /* фильтры - в один ряд с прокруткой */
  .gen-filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .gen-filters label { flex: 0 0 auto; }
  .gen-filters select { flex: 0 0 auto; width: auto; min-width: 140px; }
  .gen-attention { padding: 8px 12px; }

  /* «Компьютеры», «Генерации»: карточки вместо таблиц - ключевые поля сверху, остальное по «Подробнее»,
     подсветка сроков и ошибок полосой слева, кнопки действий внизу карточки */
  .table-wrap:has(> table.mcards) { overflow: visible; background: transparent; border: 0; border-radius: 0; }
  table.mcards, table.mcards tbody, table.mcards td { display: block; width: 100%; }
  table.mcards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.mcards tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--sp-2); margin-bottom: var(--sp-2);
    padding: 8px 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); }
  table.mcards td { flex: 1 1 100%; min-width: 0; padding: 4px 12px; border-bottom: 0; }
  table.mcards td[data-label] { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 0 8px; align-items: baseline; }
  table.mcards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-sm); }
  table.mcards td[data-label] > * { grid-column: 2; min-width: 0; }
  table.mcards td.m-title { font-size: var(--fs-md); font-weight: 600; }
  table.mcards td.m-more { display: none; }
  table.mcards tr.m-open td.m-more { display: grid; }
  table.mcards td.m-acts, table.mcards td.m-toggle { display: block; flex: 0 0 auto; width: auto; padding-top: 8px; }
  table.mcards td.m-acts:empty { display: none; }
  table.mcards td[colspan] { flex: 1 1 100%; }
  table.mcards tr.soon, table.mcards tr.overdue, table.mcards tr.attn { border-left-width: 4px; }
  table.mcards tr.soon { border-left-color: var(--yellow); background: color-mix(in srgb, var(--yellow) 14%, var(--panel)); }
  table.mcards tr.overdue, table.mcards tr.attn { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--panel)); }
  table.mcards tr.soon td, table.mcards tr.overdue td, table.mcards tr.attn td { background: transparent; box-shadow: none; }
  table.gen .gen-prompt { max-width: none; -webkit-line-clamp: 3; line-clamp: 3; }
  table.gen .gen-err { max-width: none; }
  table.gen .gen-prio button { min-width: 44px; }
  table.mcards td .bar { min-width: 0; }

  /* «Серии»: блок сериала - шапка с кнопкой свернуть, шахматка с прокруткой и закреплёнными шапкой и номером */
  .board-head { padding: 8px 12px; gap: 4px 8px; }
  .board-head .blk-toggle { width: 44px; height: 44px; min-height: 44px; margin: -4px 0 -4px -8px; }
  .board-head h4 { flex: 1 1 auto; min-width: 0; font-size: var(--fs-md); overflow-wrap: anywhere; }
  .board-head .meta { flex: 1 1 100%; order: 3; }
  .board-n-row { flex: 1 1 100%; order: 4; flex-wrap: wrap; gap: var(--sp-2); }
  .board-n { width: 88px; }
  .board-legend { gap: 6px 12px; font-size: var(--fs-sm); }
  .board-help { font-size: var(--fs-sm); }
  .board-wrap { max-height: 70vh; max-height: 70dvh; }
  .cell .l { font-size: 12px; }
  .cell .v { font-size: 11px; }
  /* галочки РУ / КЗ: зона касания 44x44 */
  .ticks { gap: 4px; }
  .sq-ticks { gap: 4px; }
  .tick { min-width: 44px; height: 36px; gap: 4px; font-size: 12px; border-radius: var(--r-md); }
  .tick::after { content: ""; position: absolute; inset: -4px 0; }   /* зона касания 44x44 при видимых 36px */
  .tick .tick-in { width: 18px; height: 18px; }
  .tick-day { font-size: 11px; }
  /* мини-окошко квадрата - нижний лист во всю ширину */
  .cell-pop.sheet { left: 0; right: 0; bottom: 0; max-width: 100vw; max-height: 85vh; max-height: 85dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0; padding: 18px 16px calc(16px + var(--safe-b)); font-size: 15px;
    box-shadow: var(--shadow-3); animation: sheet-in .22s ease-out; }
  .cell-pop.sheet .pop-handle { display: block; position: absolute; top: 6px; }
  .cell-pop .pop-head { touch-action: none; }
  .pop-close { width: 44px; height: 44px; }
  .pop-grid { grid-template-columns: 92px minmax(0, 1fr); }
  .pop-grid input, .pop-grid textarea { height: 44px; font-size: 16px; }
  .pop-grid textarea { height: auto; }
  .pop-checks .chk { min-height: 44px; grid-template-columns: 20px minmax(0, 1fr); }
  .pop-checks .chk input { width: 20px; height: 20px; }
  .pop-gate-acts, .pop-actions { gap: var(--sp-2); flex-wrap: wrap; }
  .pop-gate-acts button, .pop-actions button { flex: 1 1 0; min-height: 44px; }
  .pop-hist summary { min-height: 44px; display: flex; align-items: center; }
  /* тосты - над нижней панелью */
  .btoast { bottom: calc(var(--nav-h) + var(--safe-b) + 8px); width: calc(100vw - 24px); }
  .btoast-undo { min-height: 40px; }

  /* модальные окна - нижние листы во всю ширину: ручка, крестик, кнопки снизу */
  dialog:not(.viewer) { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; margin: auto 0 0; overflow-y: auto;
    overscroll-behavior: contain; padding: 0 16px calc(16px + var(--safe-b)); border-width: 1px 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-3); }
  dialog:not(.viewer)[open] { animation: sheet-in .22s ease-out; }
  dialog .dlg-bar { display: flex; justify-content: flex-end; position: sticky; top: 0; z-index: 1; margin: 0 -16px 4px;
    padding: 14px 4px 0 16px; background: var(--panel); }
  dialog form { gap: var(--sp-2); }
  dialog .row.end { position: sticky; bottom: calc(-16px - var(--safe-b)); margin: 8px -16px 0; padding: 8px 16px; background: var(--panel);
    border-top: 1px solid var(--border); }
  dialog .row.end > button { flex: 1 1 0; }
  fieldset label.inline { margin-right: 16px; }
}
@media (max-width: 380px) {      /* 360px: подписи в нижней панели и чипы - плотнее */
  .tabs [role=tab], .tab-more { font-size: 10.5px; }
  .ti { padding: 2px 10px; }
  .chat-head h2 { max-width: 36%; }
  .all-acc { padding: 0 10px; }
}
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .left.sheet-open, .cell-pop.sheet, dialog:not(.viewer)[open] { animation: none; }
}
@media (max-width: 768px) and (forced-colors: active) {
  .nav { border-top: 1px solid CanvasText; }
  .tabs [role=tab][aria-selected=true], .tab-more.on { outline: 2px solid CanvasText; }
  table.mcards tr { border: 1px solid CanvasText; }
}
