/*
 * Две темы, два лица.
 *
 *   тёмная «Графит»  — по умолчанию: монохромный графит, весь цвет собран
 *                      в одном латунном акценте, шрифт Golos Text.
 *   светлая «Бумага» — тёплый лист и чернила: заголовки серифом PT Serif,
 *                      текст PT Sans, акцент чернильно-синий.
 *
 * Всё оформление живёт в этих переменных; ниже по файлу цветов нет.
 * Тема ставится атрибутом data-theme на <html> (см. theme.js), по умолчанию
 * тёмная. Шрифты самостоятельно размещены в /fonts — аудитория в России,
 * где Google Fonts то работает, то нет.
 */
:root {
  --bg: #121316;
  --bg-2: #16171b;
  --bg-3: #1d1e23;
  --line: #26272d;
  --fg: #e8e9ec;
  --fg-dim: #8b8e98;
  --fg-faint: #6b6e78;
  --accent: #d3aa63;
  --accent-fg: #17130a;
  --accent-dim: #3b3323;
  --ok: #58c98a;
  --warn: #e0b355;
  --err: #ef6d6d;
  --font: "Golos Text", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Golos Text", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #faf9f5;
  --bg-2: #f3f1ea;
  --bg-3: #ffffff;
  --line: #e3e0d6;
  --fg: #23241f;
  --fg-dim: #7b7a70;
  --fg-faint: #a3a196;
  --accent: #2b4a8c;
  --accent-fg: #f7f8fb;
  --accent-dim: #dbe3f2;
  --ok: #2e7d4f;
  --warn: #9a6b14;
  --err: #b3372c;
  --font: "PT Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "PT Serif", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 var(--font);
}

/*
 * Заголовочный шрифт: в тёмной теме тот же гротеск, в светлой — сериф.
 * Названия проектов входят сюда намеренно: в «Бумаге» они — оглавление
 * рукописи, а не пункты меню.
 */
.logo,
.pname,
.project-name,
.empty-state h2,
.modal h3,
.modal h4,
.gate-box h2 {
  font-family: var(--font-display);
}

#app { display: flex; height: 100%; }

/* ------------------------------------------------------------- sidebar */

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.logo { font-weight: 600; letter-spacing: 0.2px; }

.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

.project-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.project-item:hover { background: var(--bg-3); }
.project-item.active { background: var(--bg-3); border-color: var(--line); }
.project-item .pname { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item .pmeta { font-size: 11px; color: var(--fg-faint); display: flex; justify-content: space-between; gap: 6px; }
.admin-others {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--fg-faint);
  cursor: pointer;
  user-select: none;
}
.admin-others input { accent-color: var(--accent); }

.project-item .powner {
  font-size: 10.5px;
  color: var(--warn, #c90);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-item .del { opacity: 0; font-size: 11px; color: var(--fg-faint); }
.project-item:hover .del { opacity: 1; }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 8px; }
.conn { font-size: 11px; }
.conn.online { color: var(--ok); }
.conn.offline { color: var(--err); }

/* --------------------------------------------------------------- main */

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

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.spacer { flex: 1; }

.project-name {
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 140px;
  max-width: 260px;
}
.project-name:hover { border-color: var(--line); }
.project-name:focus { border-color: var(--accent); outline: none; background: var(--bg); }

.model-select, .modal select {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  max-width: 340px;
  font-size: 13px;
}

.meters { display: flex; gap: 14px; font-size: 11px; color: var(--fg-dim); align-items: center; }
.meter b { color: var(--fg); font-weight: 600; }
.meter.warnish b { color: var(--warn); }
.bar { width: 90px; height: 5px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.hot { background: var(--warn); }

/* --------------------------------------------------------- transcript */

.transcript { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.empty-state { max-width: 460px; margin: 80px auto; text-align: center; color: var(--fg-dim); }
.empty-state h2 { color: var(--fg); font-size: 17px; }

.msg { max-width: 860px; margin: 0 auto 18px; }
.msg .role { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--fg-faint); margin-bottom: 5px; }
.msg.user .body {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  white-space: pre-wrap;
}
.msg.assistant .body { padding: 0 2px; }
.msg.summary .body { border-left: 3px solid var(--warn); background: var(--bg-2); color: var(--fg-dim); font-size: 13px; }

.body p { margin: 0 0 10px; }
.body pre {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
}
.body code { font-family: var(--mono); font-size: 12.5px; background: var(--bg-3); padding: 1px 5px; border-radius: 4px; }
.body pre code { background: none; padding: 0; }

details.thinking, details.tool {
  max-width: 860px;
  margin: 0 auto 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}
details.thinking summary { color: var(--fg-faint); cursor: pointer; }
details.thinking .txt {
  color: var(--fg-dim);
  white-space: pre-wrap;
  font-size: 12.5px;
  padding-top: 6px;
  /* Рассуждение бывает на десятки тысяч знаков: без потолка открытый блок
     раздувает ленту так, что до соседних сообщений не домотаться. */
  max-height: 48vh;
  overflow-y: auto;
}

details.tool summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
details.tool .tname { font-family: var(--mono); color: var(--accent); }
details.tool .targ { color: var(--fg-dim); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
details.tool .tstatus { font-size: 11px; color: var(--fg-faint); }
details.tool.ok .tstatus { color: var(--ok); }
details.tool.err .tstatus { color: var(--err); }
details.tool pre { margin: 8px 0 4px; max-height: 320px; }

.approval {
  max-width: 860px;
  margin: 0 auto 14px;
  border: 1px solid var(--warn);
  background: rgba(224, 179, 85, 0.07);
  border-radius: 10px;
  padding: 12px 14px;
}
.approval h4 { margin: 0 0 6px; font-size: 13px; color: var(--warn); }
.approval pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; overflow-x: auto; margin: 0 0 10px; }
.approval .row { display: flex; gap: 8px; }

.sys-note {
  max-width: 860px;
  margin: 0 auto 12px;
  font-size: 12px;
  color: var(--fg-faint);
  border-left: 2px solid var(--line);
  padding-left: 10px;
}
.sys-note.err { color: var(--err); border-color: var(--err); }
.failed-note button { margin-top: 6px; }

/* Полоса сбоев для администратора: баланс или ключ поставщика. */
.admin-alerts {
  background: color-mix(in srgb, var(--err) 12%, transparent);
  border-bottom: 1px solid var(--err);
  color: var(--err);
  font-size: 13px;
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
}
.admin-alerts > div { flex: 1 1 100%; }

/* --------------------------------------------------- edit & regenerate */

.msg .role { display: flex; align-items: center; gap: 8px; }
.msg .role .edit {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg-dim);
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 9px;
  text-transform: none;
  letter-spacing: 0;
}
.msg .role .edit:hover { color: var(--accent); border-color: var(--accent); }

/* Action row under the last exchange - where the eye already is. */
.tail-actions {
  max-width: 860px;
  margin: -4px auto 24px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.tail-actions button {
  font-size: 12px;
  padding: 5px 12px;
  background: transparent;
  color: var(--fg-dim);
}
.tail-actions button:hover { color: var(--fg); border-color: var(--accent); }
.tail-actions .note { color: var(--fg-faint); font-size: 11px; margin-left: 4px; }

.edit-box { display: grid; gap: 8px; }
.edit-box textarea {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  min-height: 90px;
}
.edit-box .row { display: flex; gap: 8px; align-items: center; }
.edit-box .hint { color: var(--fg-faint); font-size: 11px; }

/* -------------------------------------------------------- files pane */

.files-pane {
  width: 330px;
  flex: 0 0 330px;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.files-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
}
.grow { flex: 1; }

.files-path {
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fg-faint);
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.files-tree { flex: 1; overflow-y: auto; padding: 8px 6px 20px; }

.files-dir {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-faint);
  padding: 8px 8px 3px;
  letter-spacing: .02em;
}

.file-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 8px 4px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
}
.file-row:hover { background: var(--bg-3); }
.file-row.active { background: var(--bg-3); color: var(--accent); }
.file-row .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fsize { color: var(--fg-faint); font-size: 10.5px; font-variant-numeric: tabular-nums; }

.files-empty { color: var(--fg-faint); font-size: 12px; padding: 14px; }

.files-view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg-2); }
.files-pane { position: relative; }

.files-view-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
}
.files-view-head .meta { font-weight: 400; font-size: 10.5px; color: var(--fg-faint); }
.files-view-head .meta.updated { color: var(--ok); transition: color .2s; }
.files-view #files-view-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }

.files-view pre {
  flex: 1;
  margin: 0;
  overflow: auto;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre;
  color: var(--fg-dim);
}
.files-view pre.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.icon-btn.on { color: var(--accent); }

/* Полноэкранный просмотр: тот же блок, но поверх всего окна. */
.files-view.fullscreen { position: fixed; inset: 0; z-index: 15; background: var(--bg); }
.files-view.fullscreen .files-view-head { padding: 12px 18px; }
.files-view.fullscreen #files-view-name { max-width: 55vw; }
.files-view.fullscreen pre#files-view-body {
  font-size: 12.5px;
  padding: 18px max(24px, calc(50vw - 480px)) 60px;
}

/* Режим «книга» для .md: заголовки и абзацы вместо моноширинной простыни. */
.file-md {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 40px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--fg-dim);
}
.files-view.fullscreen .file-md {
  padding: 26px max(28px, calc(50vw - 430px)) 80px;
  font-size: 15px;
}
.file-md h2, .file-md h3, .file-md h4, .file-md h5 {
  color: var(--fg);
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
}
.file-md h2 { font-size: 1.35em; }
.file-md h3 { font-size: 1.15em; }
.file-md h4, .file-md h5 { font-size: 1em; }
.file-md p { margin: 0 0 0.8em; }
.file-md code {
  background: var(--bg-3);
  border-radius: 4px;
  padding: 1px 4px;
  font-family: var(--mono);
  font-size: 0.9em;
}
.file-md pre {
  background: var(--bg-3);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
}
.file-md pre code { background: none; padding: 0; }
.file-md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.file-md table {
  border-collapse: collapse;
  margin: 0.4em 0 1em;
  font-size: 0.92em;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.file-md th, .file-md td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
}
.file-md th { background: var(--bg-3); color: var(--fg); font-weight: 600; }

/* На узком экране кнопкам шапки важнее уместиться, чем метке размера. */
@media (max-width: 640px) {
  .files-view #files-view-name,
  .files-view.fullscreen #files-view-name { max-width: 32vw; }
  .files-view-head .meta { display: none; }
}

@media (max-width: 1100px) {
  .files-pane { width: 280px; flex-basis: 280px; }
}

/* -------------------------------------------------- навигатор запросов */

.msg-nav {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  opacity: 0.55;
  transition: opacity 0.15s;
  z-index: 5;
}
.msg-nav:hover { opacity: 1; }

.msg-nav-panel {
  position: absolute;
  right: 56px;
  top: 50%;
  transform: translateY(-50%);
  width: min(420px, 70vw);
  max-height: 62vh;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  padding: 6px;
  z-index: 6;
}

.mnav-row {
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-dim);
}
.mnav-row:hover { background: var(--bg-3); color: var(--fg); }

.msg.user.mnav-flash {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}

/* ----------------------------------------------------------- composer */

.composer-wrap { border-top: 1px solid var(--line); background: var(--bg-2); padding: 8px 16px 10px; }
.composer { display: flex; gap: 10px; align-items: flex-end; }

/* ----------------------------------------------------------- standards */

.standards-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
}
.standards-bar:empty { display: none; }

.std-chip {
  flex: 0 0 auto;
  padding: 4px 11px;
  font-size: 12px;
  border-radius: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.std-chip:hover { color: var(--fg); border-color: var(--accent); }
.std-chip.manage { color: var(--fg-faint); border-style: dashed; }
.std-chip.manage:hover { color: var(--accent); }

.modal-wide { width: min(760px, 94vw); }

.standards-list { display: grid; gap: 6px; margin: 14px 0 6px; }
.standards-list:empty { display: none; }

.std-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.std-row.editing { border-color: var(--accent); }
.std-row .std-name { font-weight: 600; font-size: 13px; }
.std-row .std-preview {
  color: var(--fg-faint);
  font-size: 12px;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.std-row .std-meta { color: var(--fg-faint); font-size: 11px; margin-top: 4px; }
.std-row .row { display: flex; gap: 6px; }

.checkline {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 14px !important;
  color: var(--fg) !important;
  font-size: 13px !important;
}
.checkline input { width: auto !important; margin: 0 !important; }
.composer textarea {
  flex: 1;
  resize: vertical;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  min-height: 56px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer-actions { display: flex; flex-direction: column; gap: 6px; }

/* -------------------------------------------------------- attachments */

.attach-bar { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }

.attach-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px 6px 3px 11px;
  font-size: 12px;
  color: var(--fg-dim);
  max-width: 260px;
}
.attach-chip .an { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .as { color: var(--fg-faint); font-size: 10.5px; }
.attach-chip button {
  border: none;
  background: none;
  color: var(--fg-faint);
  padding: 0 4px;
  font-size: 11px;
  cursor: pointer;
}
.attach-chip button:hover { color: var(--err); }
.attach-chip.static { cursor: pointer; padding: 3px 11px; }
.attach-chip.static:hover { border-color: var(--accent); color: var(--fg); }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.attach-btn { align-self: flex-end; margin-bottom: 8px; font-size: 17px; }

.composer.dragover textarea { border-color: var(--accent); background: var(--bg-3); }

/* ------------------------------------------------------------ buttons */

button {
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg);
  border-radius: 7px;
  padding: 7px 14px;
  cursor: pointer;
  font: inherit;
}
button:hover { border-color: var(--fg-faint); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: transparent; border-color: var(--err); color: var(--err); }
button.ghost { background: transparent; }
button.block { width: 100%; }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { background: transparent; border: none; font-size: 16px; padding: 4px 6px; color: var(--fg-dim); }
.icon-btn:hover { color: var(--fg); }

/* -------------------------------------------------------------- modal */

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; width: min(560px, 92vw); max-height: 86vh; overflow-y: auto; }
.modal h3 { margin: 0 0 10px; }
.modal label { display: block; margin: 12px 0 0; font-size: 12px; color: var(--fg-dim); }
.modal input, .modal select, .modal textarea { width: 100%; margin-top: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--fg); border-radius: 7px; padding: 8px 10px; font: inherit; }
.modal textarea { resize: vertical; font-size: 13px; line-height: 1.5; }
.modal h4 { margin: 20px 0 0; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.key-row { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.key-row:first-child { border-top: none; }
.key-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.key-state { font-size: 11px; font-weight: 400; color: var(--fg-faint); }
.key-state.on { color: var(--ok); }
.key-row .row { display: flex; gap: 8px; margin-top: 6px; }
.key-row input { flex: 1; font-family: var(--mono); font-size: 12px; }
.key-err { color: var(--err); font-size: 11px; margin-top: 5px; }

.muted { color: var(--fg-dim); font-size: 12px; }
.hidden { display: none !important; }

/* ------------------------------------------------- план и список задач */

.tasks-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.5;
  max-height: 180px;
  overflow-y: auto;
}

.tasks-bar.hidden { display: none; }

.tasks-head {
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .55;
  margin-bottom: 4px;
}

.tasks-bar .task { display: flex; gap: 8px; align-items: baseline; }
.tasks-bar .task .tm { width: 12px; flex: 0 0 12px; text-align: center; opacity: .7; }
.tasks-bar .task.done { opacity: .45; text-decoration: line-through; }
.tasks-bar .task.active { font-weight: 600; }
.tasks-bar .task.active .tm { opacity: 1; }

#btn-plan.on {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}

.meter.warn { color: var(--warn); }

/* --------------------------------------------------------------- MCP */

.mcp-head { margin-top: 22px; }

.mcp-status { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; font-size: 13px; }
.mcp-row.ok { color: var(--ok); }
.mcp-row.bad { color: var(--err); cursor: help; }

.mcp-config {
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  resize: vertical;
}

.mcp-error {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--err);
  white-space: pre-wrap;
}
.mcp-error.hidden { display: none; }

.key-balance { font-size: 12.5px; opacity: .8; margin-top: 2px; }
.key-balance.err { color: var(--err); }

.key-balance.good { color: var(--ok); }

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

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.gate.hidden { display: none; }

.gate-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 300px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.gate-box h2 { margin: 0; font-size: 19px; }
.gate-box .muted { margin: 0 0 4px; font-size: 13px; }
.gate-box input { padding: 9px 10px; font-size: 14px; }
.gate-box button { margin-top: 6px; padding: 9px; }

.gate-error {
  font-size: 13px;
  color: var(--err);
  white-space: pre-wrap;
}
.gate-error.hidden { display: none; }

.whoami { font-size: 12px; opacity: .65; }
.whoami b { font-weight: 600; opacity: 1; }

/* ------------------------------------------------------------------ расход */

.usage-controls {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}
.usage-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--fg-dim);
}
/* Селекты в модальном окне по умолчанию во всю ширину — здесь это лишнее. */
.usage-controls select {
  width: auto;
  min-width: 170px;
  margin-top: 0;
}
.usage-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.usage-card {
  flex: 1 1 110px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
}
.usage-card b {
  font-size: 17px;
}
.usage-card span {
  font-size: 11px;
  color: var(--fg-dim);
}
.usage-note {
  flex-basis: 100%;
  font-size: 12px;
  color: var(--warn);
}
/*
 * .modal-wide объявлен выше .modal, а специфичность у них одинаковая — поэтому
 * побеждала ширина обычного окна, и «широкие» окна широкими не были. Двойной
 * класс снимает вопрос порядка. Это чинит заодно и окно инструкций.
 */
.modal.modal-wide { width: min(820px, 94vw); }

/* Своей прокрутки нет намеренно: окно прокручивается целиком, и полоса одна. */
.usage-body {
  overflow-x: auto;
}
.usage-table {
  margin-bottom: 16px;
}
.usage-table h4 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--fg-dim);
  font-weight: 600;
}
.usage-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.usage-table td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.usage-table td.uname {
  text-align: left;
  width: 42%;
  white-space: normal;
  word-break: break-word;
}
.usage-table tr.uhead td {
  color: var(--fg-dim);
  font-size: 11px;
  border-bottom: 1px solid var(--line);
}

/* --------------------------------------------------------- подписка и счёт */

.wallet-bar {
  /* Панель узкая: в строку остаток и срок подписки не помещаются. */
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-3);
  cursor: pointer;
  font-size: 12px;
}
.wallet-bar:hover { border-color: var(--accent-dim); }
.wallet-tokens { font-weight: 600; }
.wallet-tokens.empty { color: var(--err); }
.wallet-plan { color: var(--fg-faint); }

.plans-wallet { margin-bottom: 10px; font-size: 14px; }
.plans-err { color: var(--err); font-size: 13px; margin-top: 6px; }

.plan-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.plan-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.plan-card.active { border-color: var(--accent-dim); }
.plan-card h4 { margin: 0; font-size: 14px; }
.plan-price { font-size: 19px; font-weight: 600; }
.plan-note {
  flex: 1;
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.45;
}
.plan-card button { margin-top: 4px; }

.pay-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 10px;
}
.pay-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.pay-table td:nth-child(2) { white-space: normal; width: 45%; }

.plans-admin { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.plans-admin summary { cursor: pointer; font-size: 13px; color: var(--fg-dim); }
.plans-admin h4 { margin: 16px 0 4px; font-size: 13px; }

.grant-row { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.grant-row label { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.grant-row input, .grant-row select { width: auto; min-width: 130px; margin-top: 0; }

/* ------------------------------------------------------- низ боковой панели */

.side-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.side-nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--fg-dim);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.side-nav button:hover { background: var(--bg-3); color: var(--fg); }
.side-nav button i {
  font-style: normal;
  width: 16px;
  text-align: center;
  color: var(--fg-faint);
}
.side-nav button:hover i { color: var(--accent); }

.me-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px 8px;
}
.me-row .whoami {
  font-size: 12px;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.me-row .whoami b { color: var(--fg); font-weight: 500; }
.me-row .whoami .role {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 10px;
  color: var(--fg-faint);
}

/* --------------------------------------------------------- пользователи */

#users-list table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#users-list td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
#users-list td:last-child { text-align: right; white-space: nowrap; }
#users-list .off { opacity: 0.55; }
#users-list .role-badge {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 10.5px;
  color: var(--fg-faint);
}
#users-list button { margin-left: 6px; }

#acc-sessions .sess { display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }

/* ------------------------------------------------------------- лендинг */

.gate { overflow-y: auto; align-items: stretch; }
.gate-wrap {
  margin: auto;
  display: flex;
  align-items: center;
  gap: 56px;
  max-width: 900px;
  padding: 48px 24px;
}
.gate-pitch { flex: 1; min-width: 0; }
.gate-brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
  margin-bottom: 22px;
}
.gate-pitch h1 {
  font-family: var(--font-display);
  font-size: 31px;
  line-height: 1.2;
  margin: 0 0 14px;
  text-wrap: balance;
}
.gate-lead { font-size: 15px; line-height: 1.65; color: var(--fg-dim); margin: 0 0 20px; max-width: 52ch; }
.gate-feats { list-style: none; margin: 0 0 22px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.gate-feats li {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--fg-dim);
  padding-left: 14px;
  border-left: 2px solid var(--accent);
  max-width: 54ch;
}
.gate-feats li b { color: var(--fg); font-weight: 600; }
.gate-links { display: flex; gap: 18px; font-size: 13px; }
.gate-links a { color: var(--accent); text-decoration: none; }
.gate-links a:hover { text-decoration: underline; }

.gate-box { width: 320px; flex: 0 0 320px; background: var(--bg-2); }
.gate-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 4px;
}
.gate-tabs button {
  flex: 1;
  padding: 6px 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.gate-tabs button.on { background: var(--bg-3); color: var(--fg); font-weight: 500; }
.gate-tabs.hidden { display: none; }
.gate-fine { font-size: 11.5px; line-height: 1.5; margin: 2px 0 0; }

@media (max-width: 760px) {
  .gate-wrap { flex-direction: column; gap: 30px; padding: 28px 18px; }
  .gate-pitch h1 { font-size: 25px; }
  .gate-box { width: 100%; flex: none; }
}

/* ------------------------------------------------------ примеры задач */

.starter-ideas { margin-top: 22px; display: flex; flex-direction: column; gap: 7px; align-items: center; }
.si-title { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-faint); }
.starter-ideas button {
  max-width: 480px;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg-dim);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.starter-ideas button:hover { border-color: var(--accent); color: var(--fg); }

/* ------------------------------------------------------ плавная смена темы */

/*
 * Класс вешается на <html> только на время переключения. Постоянные
 * transition на всём подряд заставляют перекрашиваться каждое наведение
 * мыши; здесь плата разовая — треть секунды при смене темы.
 */
html.theme-fade,
html.theme-fade *,
html.theme-fade *::before,
html.theme-fade *::after {
  transition: background-color 0.3s ease, color 0.3s ease,
    border-color 0.3s ease, fill 0.3s ease, box-shadow 0.3s ease !important;
}
@media (prefers-reduced-motion: reduce) {
  html.theme-fade, html.theme-fade * { transition: none !important; }
}

/* ------------------------------------------------- «глазами пользователя» */

.viewas-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px dashed var(--warn);
  border-radius: 8px;
  color: var(--warn);
  font-size: 12px;
}
.viewas-bar.hidden { display: none; }

/* --------------------------------------------------------- карточки уровней */

.plans-section { margin: 20px 0 6px; font-size: 14px; }
.plans-section:first-child { margin-top: 8px; }

.tier-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 10px 0 6px;
}
.tier {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.tier.active { border-color: var(--accent); }
.tier-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tier-head h4 { margin: 0; font-size: 16px; font-family: var(--font-display); }
.tier-badge {
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 10.5px;
  white-space: nowrap;
}
.tier-sub { font-size: 12px; color: var(--fg-faint); margin-top: -4px; }
.tier-price { font-size: 24px; font-weight: 600; margin: 4px 0 2px; }
.tier-price span { font-size: 12px; font-weight: 400; color: var(--fg-dim); }
.tier button { width: 100%; padding: 8px 0; }
.tier-plus {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--fg-dim);
}
.tier-feats { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tier-feats li {
  position: relative;
  padding-left: 20px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--fg-dim);
}
.tier-feats li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--ok);
}
/* У бесплатного нет кнопки — черта отделяет список и без «плюс»-строки. */
.tier .tier-feats:first-of-type { margin-top: 2px; }

#admin-payments table td:nth-child(3) { white-space: normal; }

/* ------------------------------------------------------ выбор типа проекта */

.ptype-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 4px; }
.ptype {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  text-align: left;
  color: var(--fg-dim);
  cursor: pointer;
}
.ptype b { color: var(--fg); font-size: 13.5px; }
.ptype span { font-size: 12px; line-height: 1.45; }
.ptype.on { border-color: var(--accent); }
.ptype:disabled { opacity: 0.55; cursor: not-allowed; }
.ptype .soon {
  font-style: normal;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 400;
  color: var(--fg-faint);
}
@media (max-width: 500px) { .ptype-cards { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------- диалоги */

.modal.dlg { width: min(400px, 92vw); }
.modal.dlg p { margin: 0 0 4px; line-height: 1.55; }
.modal.dlg .modal-actions { margin-top: 14px; }
button.danger.solid, .modal.dlg button.danger {
  background: var(--err);
  border-color: var(--err);
  color: #fff;
}

/* ------------------------------------------------------------ цикл книг */

.cycle-start {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.cycle-start.hidden { display: none; }
.cycle-card {
  width: min(680px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 26px 28px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.cycle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-display);
}
.cycle-card textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--fg);
  padding: 12px 14px;
  font: inherit;
  font-size: 14px;
  line-height: 1.55;
}
.cycle-card textarea:focus { outline: none; border-color: var(--accent); }
.cycle-row { display: flex; align-items: center; gap: 10px; }
.cycle-row label { font-size: 13px; color: var(--fg-dim); }
.cycle-row input[type="number"] {
  width: 72px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--fg);
  padding: 7px 9px;
  font: inherit;
}
.cycle-row .primary { padding: 9px 22px; }

/* «i» в кружочке с подсказкой по наведению и по фокусу с клавиатуры. */
.info-i {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border: 1px solid var(--fg-faint);
  border-radius: 50%;
  font-size: 11px;
  font-style: italic;
  font-family: Georgia, serif;
  color: var(--fg-faint);
  cursor: help;
  font-weight: 400;
}
.info-i .tip {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: 300px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--fg);
  font: 12.5px/1.5 var(--font);
  font-style: normal;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.info-i:hover .tip, .info-i:focus .tip { opacity: 1; }

/* ------------------------------------------------- цикл: работа и файлы */

.cycle-workcard { align-items: center; text-align: center; }
.cycle-workcard h3 { margin: 4px 0 0; font-family: var(--font-display); }
.cycle-workcard .small { font-size: 12px; max-width: 46ch; }
#cycle-status {
  font-family: var(--mono);
  font-size: 12.5px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cycle-err { color: var(--err); font-size: 13px; white-space: pre-wrap; }
.cycle-err.hidden { display: none; }

.cycle-spin {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cyclespin 0.9s linear infinite;
}
@keyframes cyclespin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cycle-spin { animation: none; } }

.cycle-list { display: flex; flex-direction: column; gap: 6px; }
.cycle-file {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.cycle-file:hover { border-color: var(--accent); }
.cycle-file i { font-style: normal; color: var(--fg-faint); font-size: 12px; white-space: nowrap; }

/* --------------------------------------------- цикл: живой экран работы */

.cycle-head { display: flex; align-items: center; gap: 12px; }
.cycle-head h3 { margin: 0; font-family: var(--font-display); }
.cycle-head .cycle-spin { width: 22px; height: 22px; border-width: 2.5px; flex: none; }
.cycle-head .cycle-spin.hidden { display: none; }

.cycle-chapters {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
}
.cycle-chapters-head { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.cycle-chapters .chapters-row {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.cycle-chapters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--fg-faint);
}
.cycle-chapters select { min-width: 110px; }
.cycle-chapters #btn-chap-write { white-space: nowrap; }


.stage-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.stage-dot {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--fg-faint);
}
.stage-dot.now { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.stage-dot.done { color: var(--ok, #5a5); border-color: var(--ok, #5a5); }
.stage-arrow { color: var(--fg-faint); font-size: 11px; }
.stage-auto { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--fg-faint); cursor: pointer; }
.stage-auto input { accent-color: var(--accent); }

.cycle-editrow { display: flex; gap: 8px; align-items: flex-end; margin-top: 4px; }
.cycle-editrow textarea { flex: 1; min-height: 44px; }
.cycle-editrow .primary { padding: 10px 16px; white-space: nowrap; }

#cycle-queued { line-height: 1.5; }
.cycle-list:empty::after {
  content: "Файлов пока нет — появятся по мере работы.";
  color: var(--fg-faint);
  font-size: 12.5px;
}

/* ------------------------------------------------ цикл: редактор файла */

.cycle-editor {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.cycle-editor.hidden { display: none; }

.ced-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.ced-name { font-family: var(--mono); font-size: 13px; }
.ced-save { font-size: 12px; color: var(--fg-faint); }
.ced-save.err { color: var(--err); }

#ced-text {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: var(--bg);
  color: var(--fg);
  padding: 22px clamp(16px, 8vw, 90px) 60px;
  font: 14px/1.7 var(--mono);
}

.ced-panel {
  position: absolute;
  top: 44px;
  right: 10px;
  z-index: 20;
  width: min(320px, 80vw);
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.ced-panel.hidden { display: none; }
.ced-row {
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--fg-dim);
  font: 13px/1.4 var(--mono);
  text-align: left;
  cursor: pointer;
}
.ced-row:hover { background: var(--bg-3); color: var(--fg); }
.ced-row.on { color: var(--accent); }

/* --------------------------------------------------------------- телефон */

/*
 * Всё, что ниже, проверено на ширине 375 px и собрано по трём правилам:
 * ничто не шире экрана, палец попадает (цели от 42 px), клавиатура не
 * выскакивает без спроса и не увеличивает страницу (поля от 16 px — иначе
 * iPhone приближает страницу при каждом касании поля).
 */

.menu-btn { display: none; }
.side-backdrop {
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, 0.45);
}
.side-backdrop.hidden { display: none; }

/* Высота по видимой области: 100vh на телефоне — это экран без адресной строки, и низ уезжал под неё. */
#app { height: 100vh; height: 100dvh; }

@media (max-width: 760px) {
  /* Лента, списки и окна прокручиваются сами; страница целиком не дёргается и не перезагружается жестом «потянуть вниз». */
  html, body { overscroll-behavior: none; }
  .transcript, .project-list, .files-tree, .file-md, .files-view pre, .modal,
  .msg-nav-panel, .sidebar, .cycle-start, #ced-text { overscroll-behavior: contain; }

  input, textarea, select, .project-name, .model-select { font-size: 16px; }

  /* ---- ящик проектов */
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: min(320px, 86vw);
    overflow-y: auto;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-105%);
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: none; }
  .project-list { flex: 1 0 auto; }
  .project-item { padding: 10px 12px; }
  .project-item .pname { font-size: 15px; }
  .side-nav button { padding: 11px 10px; font-size: 14px; }
  .me-row { padding: 8px 2px 10px; }

  /* ---- шапка: название сжимается, кнопки остаются на экране */
  .topbar {
    position: relative;
    padding: calc(4px + env(safe-area-inset-top, 0px)) 6px 4px;
    gap: 2px;
  }
  .topbar .spacer { display: none; }
  .project-name {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    padding: 6px;
    text-overflow: ellipsis;
  }
  .model-select {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 32vw;
    padding: 7px 6px;
    text-overflow: ellipsis;
  }
  #btn-refresh-models { display: none; }
  /* Связь с сервером видна и без меню: «нет связи» жил только в спрятанном ящике. Две секунды форы — на обычное переподключение. */
  #app:has(#conn.offline) .topbar::after {
    content: "нет связи — переподключаюсь…";
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 6;
    padding: 3px 10px;
    font-size: 12px;
    text-align: center;
    color: var(--err);
    background: color-mix(in srgb, var(--err) 14%, var(--bg-2));
    border-bottom: 1px solid color-mix(in srgb, var(--err) 30%, var(--line));
    animation: rb-fade 0.2s ease-out 2s both;
  }
  .icon-btn { min-width: 42px; min-height: 42px; padding: 0; }
  .icon-btn .ic { width: 21px; height: 21px; }
  /* От счётчиков остаётся суть — тонкая линия заполнения контекста по нижнему краю шапки. */
  .meters {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    gap: 0;
    pointer-events: none;
  }
  .meters .meter { display: none; }
  .meters .meter:first-child { display: block; flex: 1; font-size: 0; }
  .meters .meter:first-child .bar {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 0;
    background: transparent;
  }

  /* ---- лента */
  .transcript { padding: 14px 12px 76px; }
  .msg { max-width: 100%; margin-bottom: 16px; }
  .msg .body { font-size: 15px; line-height: 1.6; }
  .msg.user .body { padding: 9px 12px; }
  details.thinking, details.tool { padding: 8px 12px; }
  details.tool summary { min-height: 28px; align-items: center; }
  .tail-actions { flex-wrap: wrap; gap: 6px; margin: 0 auto 20px; }
  .tail-actions button { padding: 8px 12px; font-size: 13px; }
  .tail-actions .note { flex-basis: 100%; margin: 2px 0 0; }
  .empty-state { margin: 48px auto; padding: 0 8px; }

  /* ---- навигатор своих запросов: пилюля над полем ввода, а не столбик поверх текста */
  .msg-nav {
    top: auto;
    bottom: calc(var(--composer-h, 120px) + 10px);
    right: 10px;
    transform: none;
    flex-direction: row;
    padding: 3px;
    opacity: 0.94;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  }
  .msg-nav .icon-btn { min-width: 38px; min-height: 38px; }
  .msg-nav-panel {
    left: 8px;
    right: 8px;
    width: auto;
    top: auto;
    bottom: calc(var(--composer-h, 120px) + 58px);
    transform: none;
    max-height: 55dvh;
  }
  .mnav-row { padding: 10px; font-size: 14px; }

  /* ---- поле ввода: строка «текст + отправить», под ней вложения и режимы */
  .composer-wrap { padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .composer { flex-wrap: wrap; gap: 6px 4px; align-items: flex-end; }
  .composer textarea {
    order: 1;
    flex: 1 1 calc(100% - 52px);
    min-width: 0;
    min-height: 44px;
    max-height: 40dvh;
    padding: 10px 12px;
    resize: none;
    border-radius: 12px;
  }
  .composer-actions { display: contents; }
  #btn-send, #btn-stop {
    order: 2;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
  }
  #btn-send .lbl, #btn-stop .lbl { display: none; }
  #btn-send .ic, #btn-stop .ic { width: 22px; height: 22px; stroke-width: 2.2; }
  .attach-btn { order: 3; margin: 0; }
  #btn-plan { order: 4; }
  #btn-regen { order: 5; }
  #btn-plan, #btn-regen { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .standards-bar { padding-bottom: 6px; }
  .std-chip { padding: 6px 12px; }

  /* ---- файлы: во весь экран поверх чата */
  #files-pane:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 48;
    width: 100%;
    flex-basis: auto;
    border-left: 0;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  }
  .files-head, .files-view-head { padding: 4px 4px 4px 14px; font-size: 14px; }
  .files-dir { padding: 12px 10px 4px; }
  .file-row { padding: 10px 10px 10px 18px; font-size: 14px; }
  .file-md { padding: 16px 16px 48px; font-size: 15.5px; }
  .files-view.fullscreen .file-md { padding: 18px 16px 60px; font-size: 16px; }
  .files-view.fullscreen pre#files-view-body { padding: 14px 14px 60px; }

  /* ---- окна: листы снизу, под большой палец */
  .modal-backdrop { align-items: flex-end; }
  .modal, .modal.modal-wide, .modal.dlg {
    width: 100%;
    max-height: calc(100dvh - 32px);
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .modal-backdrop:not(.hidden) > .modal { animation-name: rb-sheet; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions button { flex: 1 1 auto; min-height: 44px; }
  .grant-row label { flex: 1 1 100%; }
  .grant-row input, .grant-row select { width: 100%; min-width: 0; }
  .usage-controls { flex-wrap: wrap; }
  .usage-controls label { flex: 1 1 140px; }
  .usage-controls select { min-width: 0; width: 100%; }
  #users-list { overflow-x: auto; }
  .key-row .row { flex-wrap: wrap; }

  /* ---- цикл книг */
  .cycle-start { padding: 12px; align-items: flex-start; }
  .cycle-card { padding: 16px; border-radius: 12px; gap: 10px; }
  .cycle-row { flex-wrap: wrap; }
  .cycle-editrow { flex-direction: column; align-items: stretch; }
  .ced-bar { padding: 4px 6px; gap: 4px; }
  #ced-text { padding: 14px 14px 40dvh; font-size: 16px; }
  .info-i .tip { width: min(300px, calc(100vw - 48px)); }

  /* ---- вход: форма сразу после заголовка — возвращаться к ней через три экрана рекламы незачем */
  .gate-wrap {
    align-items: stretch;
    gap: 0;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 18px calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .gate-pitch { display: contents; }
  .gate-brand { order: 0; margin-bottom: 14px; }
  .gate-pitch h1 { order: 1; }
  .gate-lead { order: 2; margin-bottom: 18px; }
  .gate-box { order: 3; margin-bottom: 28px; padding: 20px; }
  .gate-feats { order: 4; }
  .gate-links { order: 5; flex-wrap: wrap; gap: 10px 18px; }
  .gate-box input, .gate-box button { min-height: 46px; }

  @media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
  }
}

/* На пальце нет наведения: подсветка «залипала» после касания. */
@media (hover: none) {
  .project-item:hover:not(.active) { background: transparent; }
  .project-item .del { opacity: 0.6; }
  .side-nav button:hover { background: transparent; color: var(--fg-dim); }
  .side-nav button:hover .ic { color: var(--fg-faint); }
  .file-row:hover:not(.active), .mnav-row:hover, .ced-row:hover { background: transparent; }
  button:not(.primary):not(.danger):hover { border-color: var(--line); }
  button.primary:hover { filter: none; }
  .icon-btn:hover { color: var(--fg-dim); }
  .std-chip:hover { color: var(--fg-dim); border-color: var(--line); }
  .tail-actions button:hover { color: var(--fg-dim); border-color: var(--line); }
  .starter-ideas button:hover { border-color: var(--line); color: var(--fg-dim); }
  .cycle-file:hover { border-color: var(--line); }
  .msg-nav { opacity: 0.94; }
}

/* ------------------------------------------ отделка: значки, нажатия, окна */

/* Браузерные мелочи, которые обычно остаются «ничьими»: выделение, каретка, фокус, полосы прокрутки. */
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
::selection { background: color-mix(in srgb, var(--accent) 34%, transparent); color: var(--fg); }
input, textarea { caret-color: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 75%, transparent);
  outline-offset: 2px;
}
.meters, .usage-table td, .usage-card b, .wallet-bar, .pay-table td, .plan-price,
.tier-price, .file-row .fsize, #users-list td { font-variant-numeric: tabular-nums; }

/* Значки: один штрих, одна толщина, цвет — от текста. */
.ic {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.icon-btn .ic { width: 19px; height: 19px; }
button:has(> .ic) { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
button.block:has(> .ic) { display: flex; }
.side-nav button:has(> .ic) { justify-content: flex-start; gap: 10px; }
.side-nav button .ic { width: 17px; height: 17px; color: var(--fg-faint); }
.side-nav button:hover .ic { color: var(--accent); }
.tail-actions button .ic { width: 15px; height: 15px; }
/* Кнопки под ответом переносятся целиком, а не рвут подпись на две строки. */
.tail-actions { flex-wrap: wrap; }
.tail-actions button { white-space: nowrap; }
.meters { min-width: 0; overflow: hidden; white-space: nowrap; }
.tail-actions button.risky:hover { color: var(--err); border-color: var(--err); }
#btn-plan .ic, #btn-regen .ic { width: 15px; height: 15px; }

/* Удаление проекта — настоящая кнопка: с клавиатуры до неё тоже можно дойти. */
.project-item .del {
  display: inline-flex;
  border: 0;
  background: none;
  padding: 2px;
  margin: -3px -3px -3px 0;
  border-radius: 6px;
  color: var(--fg-faint);
}
.project-item .del .ic { width: 14px; height: 14px; }
.project-item .del:hover, .project-item .del:focus-visible { color: var(--err); opacity: 1; }

/* Нажатие отвечает сразу, на касании, а не когда палец уже ушёл. */
button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.1s ease-out, background-color 0.15s, border-color 0.15s, color 0.15s, filter 0.15s;
}
button:active:not(:disabled) { transform: scale(0.97); }
.icon-btn:active:not(:disabled) { transform: scale(0.9); }

/* Поля входа в тон темы, а не системные серые. */
.gate-box input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
}
.gate-box input:focus { outline: none; border-color: var(--accent); }

/* Цветная полоса слева — примета шаблона; разделяем строкой, а выделяем фоном и рамкой. */
.gate-feats li { border-left: 0; padding-left: 0; padding-top: 12px; border-top: 1px solid var(--line); }
.gate-feats li:first-child { border-top: 0; padding-top: 0; }
.msg.summary .body {
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  border-radius: 10px;
  padding: 10px 14px;
}
.sys-note { border-left-width: 1px; }

/* Таблицы в ответах агента: раньше выходили без рамок и за край экрана. */
.body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 4px 0 12px;
  font-size: 13px;
}
.body th, .body td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
}
.body th { background: var(--bg-3); font-weight: 600; }
.body td { font-variant-numeric: tabular-nums; }

/* Книжный режим — для чтения глав: текст почти в полный контраст, а не приглушённый серый служебных подписей. */
.file-md { color: color-mix(in srgb, var(--fg) 90%, var(--bg)); }

/* Заголовки и списки в ответах — спокойнее, чем в файле-книге: это реплика, а не глава. */
.body h2, .body h3, .body h4, .body h5 {
  margin: 16px 0 6px;
  line-height: 1.3;
  font-family: var(--font-display);
  color: var(--fg);
}
.body h2 { font-size: 17px; }
.body h3 { font-size: 15.5px; }
.body h4, .body h5 { font-size: 14.5px; }
.body > h2:first-child, .body > h3:first-child { margin-top: 2px; }
.body ul, .body ol, .file-md ul, .file-md ol { margin: 0 0 10px; padding-left: 22px; }
.body li, .file-md li { margin: 3px 0; }
.body li::marker, .file-md li::marker { color: var(--fg-faint); }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Окна появляются, а не выпрыгивают: одна короткая дуга, на телефоне — выезд листа снизу. */
@keyframes rb-fade { from { opacity: 0; } }
@keyframes rb-rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
@keyframes rb-sheet { from { opacity: 0.4; transform: translateY(28px); } }
.modal-backdrop:not(.hidden) { animation: rb-fade 0.16s ease-out; }
.modal-backdrop:not(.hidden) > .modal { animation: rb-rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@media (prefers-reduced-motion: reduce) {
  .modal-backdrop:not(.hidden), .modal-backdrop:not(.hidden) > .modal { animation: none; }
  button, button:active:not(:disabled) { transition: none; transform: none; }
}
