/* Единая палитра и шкала размеров для всех поверхностей интерфейса. */
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  font-size: 14px;
  color: #24262b;
  background: #faf9f6;
  --surface: #fff;
  --surface-sidebar: #fafafa;
  --surface-subtle: #f1f2f5;
  --surface-hover: #eceef2;
  --surface-selected: #edf4fc;
  --surface-message: #f5f5f7;
  --text: #24262b;
  --text-secondary: #656b76;
  --text-muted: #69717d;
  --accent: #0866db;
  --accent-hover: #0759bd;
  --border: #e3e6eb;
  --focus: #0866db;
  --danger: #a04438;
  --success: #34714d;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --type-small: 11px;
  --type-meta: 12px;
  --type-label: 13px;
  --type-topic: 14px;
  --type-body: 18px;
  --type-heading: 22px;
  --body-leading: 1.6;
  --chat-inset: var(--space-8);
  --column-width: 680px;
  --column-inset: max(var(--chat-inset), calc((100% - var(--column-width)) / 2));
  --warning: #85561c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea, select { font: inherit; }
button, input, textarea, select, summary {
  -webkit-tap-highlight-color: transparent;
}
button { border: 0; cursor: pointer; }
input, textarea, select { color: inherit; }
button:disabled, select:disabled, textarea:disabled { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, summary:focus-visible, a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* Каркас и навигация. */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  padding: 0;
  height: 100dvh;
  width: 100%;
  background: var(--surface);
  overflow: hidden;
}
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--space-6) var(--space-4);
  color: var(--text);
  background: var(--surface);
  border-left: 1px solid #e4e2dc;
  order: 2;
}
.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 var(--space-2) var(--space-3);
}
.topic-total { font-size: var(--type-label); color: var(--text-muted); letter-spacing: 0; }
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.4px;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #e9ecf1;
  color: #536174;
  font-size: 27px;
  font-weight: 500;
  letter-spacing: -2px;
  line-height: 1;
  padding-right: 2px;
}
.brand-mark.large {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-lg);
  font-size: 48px;
}
.sidebar .brand-mark { display: none; }
.icon-button {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 22px;
}
.icon-button:hover { background: var(--surface-hover); }
.search-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  flex: 1;
  min-width: 0;
  max-width: 220px;
  padding: 0 var(--space-2);
  margin: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
}
.search-wrap svg { flex-shrink: 0; }
.search-wrap input {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  background: transparent;
  border: 0;
  font-size: var(--type-label);
}
.thread-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: var(--space-3);
  margin-bottom: var(--space-1);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
}
.thread-item:hover { background: var(--surface-hover); }
.thread-item.selected { background: #eeece6; }
.avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: #e9edf4;
  color: #53698c;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -2px;
  padding-right: 2px;
}
.thread-item:not(.is-main) .avatar { display: none; }
.thread-details { flex: 1; min-width: 0; }
.thread-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.thread-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--type-topic);
  font-weight: 500;
  line-height: 1.5;
}
.thread-time {
  flex-shrink: 0;
  font-size: var(--type-small);
  color: var(--text-muted);
  white-space: nowrap;
}
.thread-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--type-meta);
  color: var(--text-secondary);
  line-height: var(--body-leading);
}
.thread-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 18px;
  margin-top: var(--space-2);
}
.is-main .thread-meta .status { display: none; }
.is-main .thread-meta { justify-content: flex-end; }
.is-main .thread-meta:not(:has(.unread)) { display: none; }
.status {
  display: inline-flex;
  align-items: center;
  font-size: var(--type-small);
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
}
.status.waiting_user { color: var(--warning); }
.status.failed { color: var(--danger); }
.status.completed { color: var(--success); }
.unread {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--surface);
  font-size: var(--type-small);
  font-weight: 550;
  flex-shrink: 0;
}
.thread-groups {
  overflow-y: auto;
  min-height: 0;
  margin-top: 0;
}
.view-switch {
  display: flex;
  flex-shrink: 0;
  gap: var(--space-3);
  padding: 0;
  margin: 0 0 var(--space-3);
  background: transparent;
}
.view-switch button {
  min-height: 36px;
  padding: var(--space-2);
  border-radius: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--type-label);
  white-space: nowrap;
}
.view-switch button[aria-pressed="true"] {
  border-bottom-color: #718096;
  color: var(--text);
}
.status-list { overflow-y: auto; min-height: 0; }
.status-group { margin-bottom: var(--space-4); }
.status-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-1);
  padding: var(--space-3) var(--space-4) var(--space-2);
  border-bottom: 1px solid #eeeef0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
}
.state-count { color: var(--text-muted); font-size: var(--type-label); }
.status-topic { padding: 14px var(--space-4); }
.status-topic .thread-top { align-items: flex-start; margin-bottom: var(--space-1); }
.status-topic .thread-title {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
  font-size: 16px;
  font-weight: 500;
}
.status-topic .thread-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 var(--space-2) 2px 0;
  border-radius: var(--radius-pill);
  background: #65758c;
}
.status-topic.waiting_user .thread-title::before { background: #bd862b; }
.status-topic.failed .thread-title::before { background: #b25245; }
.status-topic.working .thread-title::before { background: #4f83bf; }
.status-topic.completed .thread-title::before { background: #528364; }
.status-topic .thread-preview { font-size: var(--type-label); }
.topic-location {
  flex-shrink: 0;
  max-width: 35%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: var(--type-meta);
  line-height: 1.5;
}
.topic-summary { display: flex; align-items: baseline; gap: var(--space-2); }
.topic-summary .thread-preview { flex: 1; min-width: 0; }
.thread-group { margin-bottom: var(--space-3); }
.thread-group > summary, .project-group > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
  color: var(--text-secondary);
  font-size: var(--type-meta);
  font-weight: 500;
}
.thread-group > summary::-webkit-details-marker,
.project-group > summary::-webkit-details-marker { display: none; }
.thread-group > summary::before, .project-group > summary::before {
  content: "›";
  width: 8px;
  flex-shrink: 0;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
}
.thread-group[open] > summary::before,
.project-group[open] > summary::before { transform: rotate(90deg); }
.thread-group > summary:hover, .project-group > summary:hover {
  background: var(--surface-hover);
}
.group-count, .project-count {
  margin-left: auto;
  font-size: var(--type-small);
  font-weight: 400;
  color: var(--text-muted);
  flex-shrink: 0;
}
.project-group { margin: var(--space-1) 0 var(--space-2) var(--space-3); }
.thread-group > summary { text-transform: uppercase; letter-spacing: 0.6px; }
.project-group > summary { font-size: var(--type-label); font-weight: 400; }
.project-title {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.project-topics { padding-left: var(--space-3); }
.project-topics .thread-item { padding: var(--space-2) var(--space-3); }
.project-topics .thread-preview, .project-topics .thread-time { display: none; }
.project-topics .thread-top { margin-bottom: 0; }
.project-topics .thread-meta { margin-top: 2px; min-height: 16px; }
.thread-item.is-main { min-height: 64px; padding-block: var(--space-2); }
.sidebar-empty {
  padding: 0 var(--space-3);
  font-size: var(--type-meta);
  color: var(--text-secondary);
  line-height: var(--body-leading);
}
.sidebar-bottom { margin-top: auto; padding: var(--space-3) var(--space-3) 0; }
.notification-button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--type-meta);
}
.notification-button:hover { color: var(--accent); }
.notification-button svg { flex-shrink: 0; }
#notification-note {
  color: var(--text-muted);
  font-size: var(--type-small);
  line-height: var(--body-leading);
  margin: 0 0 var(--space-3);
}
.presence {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--type-small);
  color: var(--text-muted);
}
.presence-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--text-muted);
}
.presence-dot.online { background: var(--success); }
.presence-dot.error { background: var(--danger); }

/* Заголовок разговора и общие действия. */
.conversation {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: #faf9f6;
  order: 1;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 84px;
  padding: var(--space-3) var(--column-inset);
  background: #faf9f6;
  border-bottom: 1px solid #e9e6df;
}
.chat-header .avatar { display: none; }
.chat-heading { flex: 1; min-width: 0; }
.chat-heading h1 {
  margin: 0;
  font-size: var(--type-heading);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -0.25px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-subheading { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.chat-heading p {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--type-meta);
  line-height: 1.5;
}
.back { display: none; }
.thread-category, .retry-thread {
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid #dddcd8;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: var(--type-meta);
  color: var(--text-secondary);
  cursor: pointer;
}
.thread-category {
  min-width: 132px;
  max-width: none;
  min-height: 28px;
  padding: 2px var(--space-1);
  border: 0;
  background: transparent;
}
.thread-category:hover, .retry-thread:hover { background: var(--surface-hover); }
.retry-thread { color: var(--accent); white-space: nowrap; }
.thread-category:disabled, .retry-thread:disabled { opacity: 0.6; }
.header-status { padding: var(--space-2) var(--space-3); }

/* Переписка и безопасный Markdown. */
.messages {
  flex: 1;
  overflow: auto;
  padding: var(--space-6) var(--column-inset) var(--space-4);
  overscroll-behavior: contain;
  scroll-behavior: auto;
}
.day-separator {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-2) 0 var(--space-8);
  text-align: center;
  font-size: var(--type-small);
  color: var(--text-muted);
}
.day-separator::before, .day-separator::after {
  content: "";
  height: 1px;
  flex: 1;
  background: #e6e3dd;
}
.message-author {
  margin-bottom: var(--space-3);
  font-size: var(--type-meta);
  font-weight: 500;
  color: var(--text-muted);
}
.message-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 40px;
}
.message-row.user { align-items: flex-end; }
.bubble {
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: var(--type-body);
  line-height: var(--body-leading);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.user .bubble {
  max-width: 88%;
  padding: 10px 14px;
  border: 0;
  background: #eeece6;
  color: var(--text);
  border-radius: var(--radius-md);
}
.message-time {
  margin: var(--space-1) var(--space-2) 0;
  font-size: var(--type-small);
  color: var(--text-muted);
}
.read-receipt {
  margin-left: var(--space-2);
  color: var(--success);
  font-size: var(--type-small);
  white-space: nowrap;
}
.message-row.pending { opacity: 0.65; }
.message-row.failed .message-time { color: var(--danger); }
.retry-message {
  min-height: 44px;
  padding: var(--space-2);
  background: transparent;
  color: var(--danger);
  font-size: var(--type-meta);
  border-radius: var(--radius-sm);
}
.message-content { white-space: normal; line-height: var(--body-leading); }
.user .message-content { white-space: pre-wrap; }
.message-content p { margin: 0 0 20px; white-space: pre-wrap; }
.message-content strong { font-weight: 600; }
.summary-topic-title { display: block; margin-bottom: var(--space-2); font-weight: 600; }
.message-content h3, .message-content h4,
.message-content h5, .message-content h6 {
  margin: var(--space-6) 0 var(--space-2);
  font-size: 1em;
  font-weight: 650;
  line-height: 1.45;
}
.message-content ul, .message-content ol {
  margin: var(--space-2) 0 var(--space-4);
  padding-left: var(--space-6);
}
.message-content li { margin: var(--space-1) 0; padding-left: var(--space-1); }
.message-content li::marker { color: var(--text-secondary); }
.message-content blockquote {
  margin: var(--space-4) 0;
  padding: 1px 0 1px var(--space-4);
  border-left: 2px solid #bcc5d1;
  color: var(--text-secondary);
}
.message-content a {
  color: var(--accent);
  text-decoration-color: #91b3dc;
  text-underline-offset: 3px;
}
.message-content a:hover { text-decoration-color: currentColor; }
.message-content code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.88em;
  background: #e5e8ee;
  border-radius: var(--space-1);
  padding: 2px var(--space-1);
}
.message-content pre {
  margin: var(--space-4) 0;
  padding: var(--space-3);
  overflow-x: auto;
  white-space: pre;
  background: #e7eaf0;
  border-radius: var(--radius-sm);
}
.message-content pre code { background: none; padding: 0; font-size: 0.86em; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child, .message-content blockquote > :last-child {
  margin-bottom: 0;
}
.thread-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  width: fit-content;
  max-width: 100%;
  min-height: 34px;
  margin-top: var(--space-3);
  padding: 6px 10px;
  border: 1px solid #dededb;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #38648f;
  text-align: left;
  white-space: normal;
}
.thread-link:hover { background: #f4f3ef; border-color: #b6bec6; }
.message-content .inline-thread-link {
  display: inline-block;
  margin: 2px 0;
  padding: 6px 10px;
  min-height: 34px;
  line-height: 1.4;
  font-size: 14px;
  color: #38648f;
  text-decoration: none;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.thread-link-info { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.thread-link-info .status { display: none; }
.thread-link-title { font-size: 14px; font-weight: 400; }
.thread-link-arrow { font-size: 20px; flex-shrink: 0; }

/* Поле ввода, уведомления и состояния. */
.compose { padding: var(--space-3) var(--column-inset) var(--space-6); }
.compose-box {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
  border: 1px solid var(--border);
  min-height: 60px;
  border-radius: 16px;
  background: var(--surface);
}
.compose-box:focus-within { border-color: var(--accent); }
.compose textarea {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 160px;
  resize: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 6px 0;
  font-size: var(--type-body);
  line-height: 24px;
}
.compose textarea:disabled { opacity: 0.65; }
.send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0 0 2px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--surface);
  font-size: 26px;
  font-weight: 500;
}
.send:hover:not(:disabled) { background: var(--accent-hover); }
.send:disabled { background: #d4d9e1; color: #616a78; }
.compose-footer {
  display: none;
  justify-content: flex-end;
  margin: var(--space-2) var(--space-4) 0;
  font-size: var(--type-small);
  color: var(--text-muted);
}
.archive-note {
  margin: 0 var(--space-4) var(--space-3);
  font-size: var(--type-meta);
  color: var(--text-secondary);
  line-height: var(--body-leading);
}
.typing {
  display: flex;
  gap: var(--space-1);
  width: 52px;
  margin: 0 var(--column-inset) var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--surface-message);
}
.typing > span:not(.sr-only) {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--text-muted);
  animation: pulse 1.4s infinite;
}
.typing > span:nth-child(2) { animation-delay: 0.2s; }
.typing > span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 50% { opacity: 0.3; } }
.connection-error, .health-error {
  padding: var(--space-3) var(--column-inset);
  font-size: var(--type-meta);
  line-height: var(--body-leading);
  background: #fff3e7;
  color: #85561c;
  border-bottom: 1px solid #f1e4d6;
}
.health-error {
  background: var(--surface-sidebar);
  color: var(--text-secondary);
  border-color: var(--border);
}
.message-load-error { padding: var(--space-4); background: #fff4ee; border-radius: var(--radius-md); }
.message-load-error p { margin: 0 0 var(--space-2); color: var(--danger); font-size: var(--type-topic); }
.load-retry { min-height: 44px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--surface); color: var(--accent); }
.new-messages {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  font-size: var(--type-meta);
  white-space: nowrap;
}
.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  max-width: 440px;
  margin: auto;
  padding: var(--space-8);
  text-align: center;
}
.empty-state .avatar { width: 60px; height: 60px; font-size: 42px; }
.empty-state h2 {
  margin: var(--space-6) 0 var(--space-3);
  font-size: var(--type-heading);
  font-weight: 550;
}
.empty-state p {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--type-topic);
  line-height: var(--body-leading);
}
.login, .boot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--surface-sidebar);
}
.login-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(360px, calc(100% - 48px));
}
.login-card .brand-mark { margin: 0 auto var(--space-3); }
.login-card h1 {
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.login-card > p {
  margin-top: 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--type-topic);
  line-height: var(--body-leading);
}
.login-card label {
  margin: var(--space-6) 0 var(--space-2);
  color: var(--text-secondary);
  font-size: var(--type-label);
}
.login-card input {
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: var(--type-body);
}
.primary {
  min-height: 48px;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--surface);
  font-weight: 550;
}
.primary:hover { background: var(--accent-hover); }
.login-card #login-error, #send-error, #context-send-error {
  margin: var(--space-3) 0 0;
  color: var(--danger);
  font-size: var(--type-meta);
}
.boot { flex-direction: column; color: var(--text-secondary); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Просмотр главного разговора рядом с открытой темой. */
.main-context {
  display: none;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  order: 1;
  background: #faf9f6;
}
.context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 84px;
  padding: var(--space-3) var(--column-inset);
  border-bottom: 1px solid #e9e6df;
}
.context-heading { min-width: 0; }
.context-header h2 { margin: 0; font-size: var(--type-heading); font-weight: 500; }
.context-heading p { margin: var(--space-1) 0 0; font-size: var(--type-meta); color: var(--text-secondary); }
.context-return {
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--type-meta);
}
.context-return:hover { background: #eeece6; }
.context-messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--space-6) var(--column-inset);
}
.close-topic {
  display: none;
  min-width: 76px;
  flex-shrink: 0;
  font-size: var(--type-label);
  padding: var(--space-2);
  color: var(--text-secondary);
  background: transparent;
}
@media (min-width: 1100px) {
  #main-list { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr) minmax(360px, 42%); }
  .shell.topic-open { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .topic-open .sidebar { display: none; }
  .topic-open .main-context { display: flex; }
  .topic-open .conversation {
    order: 2;
    background: var(--surface);
    border-left: 1px solid #e4e2dc;
    overflow: hidden;
  }
  .topic-open .close-topic { display: block; order: -1; }
  .topic-open .chat-header { flex-wrap: nowrap; gap: var(--space-2); background: var(--surface); }
}

/* Адаптация сохраняет ту же типографику и шкалу отступов. */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr) 300px; }
  .chat-header { gap: var(--space-3); }
  .header-status { display: none; }
}
@media (max-width: 640px) {
  :root { --chat-inset: var(--space-4); --type-body: 16px; --type-heading: 20px; }
  .shell { display: block; padding: 0; }
  .sidebar {
    height: 100dvh;
    border: 0;
    border-radius: 0;
    padding-top: max(var(--space-6), env(safe-area-inset-top));
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  }
  .sidebar-heading { flex-wrap: wrap; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; min-height: 44px; }
  .search-wrap input { font-size: var(--type-body); }
  .conversation { display: none; height: 100dvh; }
  .shell.chat-open .sidebar { display: none; }
  .shell.chat-open .conversation { display: flex; }
  .back { display: block; font-size: 34px; color: var(--accent); padding: 0; }
  .chat-header {
    min-height: 72px;
    gap: var(--space-2);
    padding: var(--space-3) var(--chat-inset);
    padding-top: max(var(--space-3), env(safe-area-inset-top));
  }
  .chat-subheading { flex-wrap: wrap; gap: 0 var(--space-2); }
  .thread-category { min-height: 44px; padding: var(--space-2) 0; }
  .retry-thread { padding: var(--space-2); }
  .messages { padding-block: var(--space-6); }
  .message-row { margin-bottom: var(--space-8); }
  .user .bubble { max-width: 89%; }
  .compose {
    padding: var(--space-2) var(--chat-inset);
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }
  .thread-group > summary, .project-group > summary,
  .notification-button { min-height: 44px; }
  .view-switch button { min-height: 44px; }
  .send { width: 44px; height: 44px; }
  .new-messages { bottom: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  .typing > span { animation: none; }
}
