.ai-chat {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
  --ai-chat-icon-btn-border: 1px solid #d1d5db;
  --ai-chat-icon-btn-bg: #ffffff;
  --ai-chat-icon-btn-color: #111827;
  --ai-chat-icon-btn-hover-bg: #f3f4f6;
  --ai-chat-icon-btn-hover-color: #111827;
  --ai-chat-icon-btn-hover-border: #d1d5db;
  --ai-chat-user-font-size: 14px;
  --ai-chat-user-line-height: 24px;
  --ai-chat-assistant-font-size: 16px;
  --ai-chat-assistant-line-height: 24px;
  --message-list-max-width: 840px;
}

.ai-chat-page-wrapper {
  min-height: 0;
  height: auto;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.main > .ai-chat-page-wrapper {
  display: block;
}

@media (max-width: 1023px) {
  .ai-chat {
    --message-list-max-width: 712px;
  }
}

.ai-chat__icon-button {
  border: var(--ai-chat-icon-btn-border);
  background: var(--ai-chat-icon-btn-bg);
  color: var(--ai-chat-icon-btn-color);
  cursor: pointer;
  transition: background 0.2s;
}

.ai-chat__icon-button:hover,
.ai-chat__icon-button[aria-expanded="true"] {
  background: var(--ai-chat-icon-btn-hover-bg);
  color: var(--ai-chat-icon-btn-hover-color);
  border-color: var(--ai-chat-icon-btn-hover-border);
}

.ai-chat__shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 600px;
  min-width: 0;
  overflow: hidden;
}

.ai-chat__sidebar {
  border-right: 1px solid #e5e7eb;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.ai-chat__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-chat__brand-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.ai-chat__brand-logo {
  display: block;
  width: auto;
  height: 34px;
  flex: 0 0 34px;
  object-fit: contain;
  object-position: center;
}

.ai-chat__brand-title {
  font-weight: 600;
  font-size: 2.4rem;
  color: #111827;
  font-family: Oranienbaum, serif;
  text-transform: uppercase;
  letter-spacing: -0.1rem;
}

.ai-chat__collapse {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}


.ai-chat__collapse svg {
  flex-shrink: 0;
}

.ai-chat__new-row {
  display: block;
}

.ai-chat__new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background 0.2s;
  line-height: 1;
  box-sizing: border-box;
}

.ai-chat__new:hover {
  background: #f3f4f6;
}

.ai-chat__new:active {
  transform: translateY(0);
}

.ai-chat__new svg {
  flex-shrink: 0;
}

.ai-chat__new-text {
  white-space: nowrap;
}

.ai-chat__sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-xs);
  color: #6b7280;
}

.ai-chat__sidebar-meta {
  display: block;
}

/* Свёрнутая боковая панель — базовая (для ≤1023px) */
.ai-chat__sidebar.is-collapsed {
  width: 96px;
  min-width: 96px;
  padding: 12px 8px;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 8px;
}

.ai-chat__sidebar.is-collapsed .ai-chat__brand-title {
  display: none;
}

.ai-chat__sidebar.is-collapsed .ai-chat__brand-logo {
  display: none;
}

.ai-chat__sidebar.is-collapsed .ai-chat__brand {
  flex: 0 0 auto;
  justify-content: center;
}

.ai-chat__sidebar.is-collapsed .ai-chat__collapse {
  width: 36px;
  min-width: 36px;
  flex-shrink: 0;
  margin-left: 0;
}

.ai-chat__sidebar.is-collapsed .ai-chat__new-row {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
}

.ai-chat__sidebar.is-collapsed .ai-chat__new {
  width: 36px;
  min-width: 36px;
  padding: 8px;
  justify-content: center;
  flex-shrink: 0;
}

.ai-chat__sidebar.is-collapsed .ai-chat__new-text {
  display: none;
}

.ai-chat__sidebar.is-collapsed .ai-chat__history,
.ai-chat__sidebar.is-collapsed .ai-chat__sidebar-footer {
  display: none;
}

.ai-chat__shell.is-sidebar-collapsed {
  grid-template-columns: 96px 1fr;
}

.ai-chat__main {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
}

.ai-chat__content {
box-sizing: border-box;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 840px;
  margin: auto;
  padding: 0 32px 64px;
  display: flex;
  position: relative;
}

.ai-chat__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.ai-chat__topbar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
}


.ai-chat__topbar-new {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
}


.ai-chat__topbar-new svg {
  flex-shrink: 0;
}

.ai-chat__topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat__header {
  margin: 0;
  font-weight: 500;
  font-size: var(--text-h1);
  color: #111827;
  flex: 1 1 auto;
  min-width: 0;
}

.ai-chat__topbar-meta {
  font-size: var(--text-sm);
  color: #6b7280;
}

.ai-chat__welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 36px 12px 12px;
  color: #111827;
}

.ai-chat__welcome[hidden] {
  display: none;
}

.ai-chat__welcome-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

strong {
font-weight: 500;
}

.ai-chat__welcome-icon {
  flex: 0 0 40px;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  line-height: 0;
  color: #1d4ed8;
}

.ai-chat__welcome-icon svg {
  display: block;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: 0;
}

.ai-chat__welcome-icon img {
  display: block;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: 0;
  object-fit: contain;
}

.ai-chat__welcome-icon i {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.ai-chat__welcome-title {
  align-self: center;
  margin: 0;
  padding: 0;
  height: 40px;
  font-size: 2.5rem;
  font-weight: 400;
  line-height: 40px;
  font-family: BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ai-chat__messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 240px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  border-radius: 10px;
  /*border: 1px solid #e5e7eb;*/
  justify-content: flex-end;
}

.ai-chat__messages:empty {
  min-height: 0;
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  border: none;
}

.ai-chat__message {
  padding: 8px 10px;
  border-radius: 22px;
  line-height: 1.4;
}

.ai-chat__message--user {
  align-self: flex-end;
  background: #eef6ff;
  color: #1f2937;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 22px;
  max-width: calc(100% - 88px);
  padding: 10px 16px;
  font-size: var(--ai-chat-user-font-size);
  line-height: var(--ai-chat-user-line-height);
  transition: background .3s;
  position: relative;
}

.ai-chat__message--assistant {
  align-self: flex-start;
  background: #ffffff;
  color: #1f2937;
  font-size: var(--ai-chat-assistant-font-size);
  line-height: var(--ai-chat-assistant-line-height);
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  word-break: break-word;
}

/* Контент ассистента — стили 1:1 как в DeepSeek (main.0892b2234f.css, сверено) */
.ai-chat__message--user,
.ai-chat__message--assistant .ds-markdown {
  --ds-md-zoom: 1.143;
  --ds-markdown-font: 14px / 1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ds-markdown-color: #1f2937;
  --ds-markdown-border: #e5e7eb;
  --ds-markdown-code-bg: #f3f4f6;
  --ds-font-code: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font: var(--ds-markdown-font);
  font-size: calc(14px * var(--ds-md-zoom));
  line-height: 1.5;
  color: var(--ds-markdown-color);
}
.ai-chat__message--assistant .ds-markdown > :first-child { margin-top: 0 !important; }
.ai-chat__message--assistant .ds-markdown > :last-child { margin-bottom: 0 !important; }
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph:first-child,
.ai-chat__message--assistant .ds-markdown p:first-child { margin-top: 0 !important; }
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph:last-child,
.ai-chat__message--assistant .ds-markdown p:last-child { margin-bottom: 0 !important; }

.ai-chat__message--assistant .ds-markdown strong { font-weight: 600; }
.ai-chat__message--assistant .ds-markdown em { font-style: italic; }
.ai-chat__message--assistant .ds-markdown img { max-width: 100%; }

/* Заголовки: h1,h2,h3 margin 32px 0 16px; h4,h5,h6 и paragraph — 16px 0 (DeepSeek) */
.ai-chat__message--assistant .ds-markdown h1,
.ai-chat__message--assistant .ds-markdown h2,
.ai-chat__message--assistant .ds-markdown h3 {
  margin: 32px 0 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ds-markdown-color);
}
.ai-chat__message--assistant .ds-markdown h4,
.ai-chat__message--assistant .ds-markdown h5,
.ai-chat__message--assistant .ds-markdown h6 {
  margin: 16px 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ds-markdown-color);
}
.ai-chat__message--assistant .ds-markdown h1 strong,
.ai-chat__message--assistant .ds-markdown h2 strong,
.ai-chat__message--assistant .ds-markdown h3 strong,
.ai-chat__message--assistant .ds-markdown h4 strong,
.ai-chat__message--assistant .ds-markdown h5 strong,
.ai-chat__message--assistant .ds-markdown h6 strong { font-weight: inherit; }
.ai-chat__message--assistant .ds-markdown h1 { font-size: 1.5em; }
.ai-chat__message--assistant .ds-markdown h2 { font-size: 1.3em; }
.ai-chat__message--assistant .ds-markdown h3 { font-size: 1.15em; }
.ai-chat__message--assistant .ds-markdown h4 { font-size: 1.05em; }
.ai-chat__message--assistant .ds-markdown h5,
.ai-chat__message--assistant .ds-markdown h6 { font-size: 1em; }
.ai-chat__message--assistant .ds-markdown h1:first-child,
.ai-chat__message--assistant .ds-markdown h2:first-child,
.ai-chat__message--assistant .ds-markdown h3:first-child { margin-top: 0; }
/* h3+список: зазор 4px; h4,h5,h6+список: зазор 8px (DeepSeek) */
.ai-chat__message--assistant .ds-markdown h3:has(+ ul),
.ai-chat__message--assistant .ds-markdown h3:has(+ ol) { margin-bottom: 4px; }
.ai-chat__message--assistant .ds-markdown h4:has(+ ul),
.ai-chat__message--assistant .ds-markdown h5:has(+ ul),
.ai-chat__message--assistant .ds-markdown h6:has(+ ul),
.ai-chat__message--assistant .ds-markdown h4:has(+ ol),
.ai-chat__message--assistant .ds-markdown h5:has(+ ol),
.ai-chat__message--assistant .ds-markdown h6:has(+ ol) { margin-bottom: 8px; }
.ai-chat__message--assistant .ds-markdown h3 + ul,
.ai-chat__message--assistant .ds-markdown h3 + ol { margin-top: 4px; }
.ai-chat__message--assistant .ds-markdown h4 + ul,
.ai-chat__message--assistant .ds-markdown h5 + ul,
.ai-chat__message--assistant .ds-markdown h6 + ul,
.ai-chat__message--assistant .ds-markdown h4 + ol,
.ai-chat__message--assistant .ds-markdown h5 + ol,
.ai-chat__message--assistant .ds-markdown h6 + ol { margin-top: 8px; }

/* Параграфы — 16px 0 (DeepSeek) */
.ai-chat__message--assistant .ds-markdown p,
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph {
  margin: 16px 0 !important;
}

/* Списки — переопределяем глобальные ul, ol, li { list-style: none } из style.css */
.ai-chat__message--assistant ul,
.ai-chat__message--assistant ol,
.ai-chat__message--assistant .ds-markdown ul,
.ai-chat__message--assistant .ds-markdown ol {
  list-style-position: outside;
}
.ai-chat__message--assistant ul,
.ai-chat__message--assistant .ds-markdown ul {
  list-style-type: disc !important;
}
.ai-chat__message--assistant ol,
.ai-chat__message--assistant .ds-markdown ol {
  list-style-type: decimal !important;
}
.ai-chat__message--assistant li,
.ai-chat__message--assistant .ds-markdown li {
  list-style: inherit !important;
}
/* Списки — margin 16px 0, padding-left 18px */
.ai-chat__message--assistant .ds-markdown ul,
.ai-chat__message--assistant .ds-markdown ol {
  margin: 16px 0;
  padding-left: 18px;
}
.ai-chat__message--assistant .ds-markdown li::marker {
  color: #6b7280;
  line-height: 28px;
}
.ai-chat__message--assistant .ds-markdown ul ol,
.ai-chat__message--assistant .ds-markdown ol ol {
  padding-left: 0;
  list-style-position: inside;
}
.ai-chat__message--assistant .ds-markdown ul ol li p,
.ai-chat__message--assistant .ds-markdown ol ol li p { display: inline; }
/* параграф + список: зазор 4px */
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph + ul,
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph + ol,
.ai-chat__message--assistant .ds-markdown p + ul,
.ai-chat__message--assistant .ds-markdown p + ol { margin-top: 4px; }
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph:has(+ ul),
.ai-chat__message--assistant .ds-markdown .ds-markdown-paragraph:has(+ ol),
.ai-chat__message--assistant .ds-markdown p:has(+ ul),
.ai-chat__message--assistant .ds-markdown p:has(+ ol) { margin-bottom: 4px; }

/* li: не первый — margin-top 6px; любой контент (p, strong…) — 8px 0; вложенный список — 4px (DeepSeek) */
.ai-chat__message--assistant .ds-markdown li { margin: 0; }
.ai-chat__message--assistant .ds-markdown li:not(:first-child) { margin-top: 6px; }
.ai-chat__message--assistant .ds-markdown li > *:not(ul):not(ol) { margin: 8px 0; }
.ai-chat__message--assistant .ds-markdown li > :first-child { margin-top: 0; }
.ai-chat__message--assistant .ds-markdown li > :last-child:not(.md-code-block) { margin-bottom: 0; }
.ai-chat__message--assistant .ds-markdown li > ul,
.ai-chat__message--assistant .ds-markdown li > ol { margin-top: 4px; }

/* hr — 32px 0, 1px */
.ai-chat__message--assistant .ds-markdown hr {
  margin: 32px 0;
  height: 1px;
  border: none;
  background: var(--ds-markdown-border);
  display: block;
}

/* blockquote */
.ai-chat__message--assistant .ds-markdown blockquote {
  border-left: 2px solid #9ca3af;
  margin: 16px 0 0;
  padding-left: 14px;
  color: #4b5563;
}

/* pre — как DeepSeek; перенос длинных строк (pre-wrap) */
.ai-chat__message--assistant .ds-markdown pre {
  font-family: var(--ds-font-code);
  margin: 16px 0;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 16px;
  background: var(--ds-markdown-code-bg);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-chat__message--assistant .ds-markdown .md-code-block {
  margin: 16px 0;
  position: relative;
}
.ai-chat__message--assistant .ds-markdown code {
  font-family: var(--ds-font-code);
  font-size: 0.875em !important;
  background-color: var(--ds-markdown-code-bg);
  border-radius: 6px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
}
.ai-chat__message--assistant .ds-markdown pre code {
  padding: 0;
  background: none;
  display: inline;
  font-size: inherit;
}
/* Блок кода: не выходит за край на маленьких экранах */
.ai-chat__message--assistant .ds-markdown .md-code-block.md-code-block-light {
  margin: 16px 0;
  border-radius: 8px;
  background: var(--ds-markdown-code-bg);
  position: relative;
  max-width: 100%;
  min-width: 0;
}
/* Без overflow: hidden на обёртке, иначе position: sticky у шапки не работает */
.ai-chat__message--assistant .ds-markdown .md-code-block-banner-wrap {
  position: relative;
}
/* Шапка: sticky при прокрутке — как в DeepSeek */
.ai-chat__message--assistant .ds-markdown .md-code-block-banner.md-code-block-banner-lite {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 12px;
  border-radius: 8px 8px 0 0;
}
/* Строка баннера: язык слева, кнопки справа; на узких экранах язык обрезается */
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-cell {
  flex-shrink: 0;
}
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-cell:first-child {
  min-width: 0;
  flex-shrink: 1;
}
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-lang {
  font-size: 12px;
  font-family: var(--ds-font-code);
  color: var(--ds-markdown-fg, #1f2937);
  opacity: 0.85;
  text-transform: lowercase;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-cell--buttons {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.ai-chat__message--assistant .ds-markdown .md-code-block .ai-chat__code-banner-buttons {
  display: flex;
  align-items: center;
  gap: 0;
}
.ai-chat__message--assistant .ds-markdown .md-code-block pre {
  margin: 0;
  border-radius: 0 0 8px 8px;
  max-width: 100%;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
/* Декоративные уголки после pre — как в DeepSeek */
.ai-chat__message--assistant .ds-markdown .md-code-block ._9bc997d {
  position: absolute;
  width: 12px;
  height: 12px;
  bottom: 0;
  color: var(--ds-markdown-code-bg);
  pointer-events: none;
}
.ai-chat__message--assistant .ds-markdown .md-code-block ._9bc997d._33882ae {
  right: 0;
}
.ai-chat__message--assistant .ds-markdown .md-code-block ._9bc997d._28d7e84 {
  left: 0;
  transform: scaleX(-1);
}

/* Кнопки Копировать / Скачать в шапке блока кода — цвет как в DeepSeek (приглушённый серый) */
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button.ds-text-button,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button.ds-text-button {
  margin: 0;
  padding: 6px 12px;
  min-height: 32px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ds-label-tertiary, #6b7280);
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: background-color 0.15s ease;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button .ds-icon.ds-atom-button__icon,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button .ds-icon.ds-atom-button__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button .ds-icon.ds-atom-button__icon svg,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button .ds-icon.ds-atom-button__icon svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code .code-info-button-text,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code .code-info-button-text {
  white-space: nowrap;
}
/* Hover / active — как DeepSeek */
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button.ds-text-button:hover,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button.ds-text-button:hover {
  background: rgba(0, 0, 0, 0.04);
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button.ds-text-button:active,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button.ds-text-button:active {
  background: rgba(0, 0, 0, 0.08);
}
/* Focus ring — как DeepSeek */
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button {
  position: relative;
  outline: none;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code .ds-focus-ring,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code .ds-focus-ring {
  position: absolute;
  inset: -2px;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 0 0 2px var(--ds-markdown-fg, #1f2937);
  transition: opacity 0.15s ease;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code:focus-visible .ds-focus-ring,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code:focus-visible .ds-focus-ring {
  opacity: 1;
}
.ai-chat__message--assistant .ds-markdown .ai-chat__copy-code:focus-visible,
.ai-chat__message--assistant .ds-markdown .ai-chat__download-code:focus-visible {
  outline: none;
}

/* На экранах ≤441px — только иконки, без подписей «Копировать» / «Скачать» */
@media (max-width: 441px) {
  .ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button > span,
  .ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button > span {
    display: none;
  }
  .ai-chat__message--assistant .ds-markdown .ai-chat__copy-code.ds-atom-button.ds-text-button,
  .ai-chat__message--assistant .ds-markdown .ai-chat__download-code.ds-atom-button.ds-text-button {
    padding: 6px 8px;
  }
}
.ai-chat__message--assistant .ds-markdown table code { font-size: 13px; }
.ai-chat__message--assistant .ds-markdown h1 code,
.ai-chat__message--assistant .ds-markdown h2 code,
.ai-chat__message--assistant .ds-markdown h3 code,
.ai-chat__message--assistant .ds-markdown h4 code,
.ai-chat__message--assistant .ds-markdown h5 code,
.ai-chat__message--assistant .ds-markdown h6 code {
  font: inherit;
  font-family: var(--ds-font-code);
}

/* Таблицы — max-content, первая ячейка без бокового padding */
.ai-chat__message--assistant .ds-markdown table {
  border-collapse: collapse;
  width: max-content;
  max-width: max-content;
}
.ai-chat__message--assistant .ds-markdown th {
  border-bottom: 1px solid var(--ds-markdown-border);
  font-weight: 600;
  padding: 10px 16px;
  text-align: left;
  border-top: none;
}
.ai-chat__message--assistant .ds-markdown th:first-child { padding-left: 0; }
.ai-chat__message--assistant .ds-markdown td {
  border-bottom: 1px solid var(--ds-markdown-border);
  padding: 10px 16px;
  max-width: min(30vw, 320px);
  min-width: 100px;
}
.ai-chat__message--assistant .ds-markdown td:first-child { padding-left: 0; }
.ai-chat__message--assistant .ds-markdown td:last-child { padding-right: 0; }

/* Ссылки — как в DeepSeek (brand color, underline при hover/focus, focus-visible ring) */
.ai-chat__message--assistant .ds-markdown a {
  color: #2563eb;
  text-decoration: none;
  transition: box-shadow 0.2s ease;
}
.ai-chat__message--assistant .ds-markdown a:hover,
.ai-chat__message--assistant .ds-markdown a:focus {
  text-decoration: underline;
  outline: none;
}
.ai-chat__message--assistant .ds-markdown a:focus-visible {
  box-shadow: 0 0 0 2px #2563eb;
  outline: none;
}

/* Math (KaTeX) — как в DeepSeek, если будет выводиться */
.ai-chat__message--assistant .ds-markdown .ds-markdown-math,
.ai-chat__message--assistant .ds-markdown .katex-display {
  text-align: center;
  max-width: 100%;
  padding: 4px;
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 16px 0;
}
.ai-chat__message--assistant .ds-markdown > * .ds-markdown-math:first-child,
.ai-chat__message--assistant .ds-markdown > * .katex-display:first-child { margin-top: 0; }
.ai-chat__message--assistant .ds-markdown > * .ds-markdown-math:last-child,
.ai-chat__message--assistant .ds-markdown > * .katex-display:last-child { margin-bottom: 0; }

.ai-chat__message--error {
  align-self: flex-start;
  background: #fee2e2;
  color: #991b1b;
}

.ai-chat__message--loader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ai-chat__loader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ai-chat__loader-dot {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: ai-chat-loader 1.1s infinite ease-in-out;
}

.ai-chat__loader-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-chat__loader-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-chat-loader {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}


.ai-chat__form {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  flex-direction: row;
  align-items: center;
}

.ai-chat__form-wrap {
  flex-grow: 1;
  width: 100%;
  position: relative;
}

.ai-chat.is-empty .ai-chat__form {
  justify-content: flex-start;
  width: 100%;
  max-width: none;
  margin: 0;
  flex-wrap: nowrap;
}

.ai-chat.is-empty .ai-chat__input {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  min-width: 0;
}

.ai-chat__input {
  flex: 1 1 auto;
  border: 1px solid #e5e7eb;
  border-radius: 24px;
  padding: 12px 16px;
  background: #ffffff;
  font-size: var(--text-md);
}

.ai-chat__send {
  border: none;
  background: #1d4ed8;
  color: #fff;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 0;
  cursor: pointer;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 20px 20px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ai-chat__send:disabled {
  opacity: 0.6;
  cursor: default;
}

.ai-chat__send.is-loading {
  background-image: none;
  cursor: pointer;
}

.ai-chat__send-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  animation: ai-chat-spin 0.8s linear infinite;
  cursor: pointer;
}

.ai-chat__send.is-loading .ai-chat__send-spinner {
  display: block;
}

.ai-chat__send-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes ai-chat-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.ai-chat__history {
  flex: 1 1 auto;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
}

.ai-chat__history:has(.ai-chat__history-empty) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat__history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}

.ai-chat__history-empty-icon {
  flex-shrink: 0;
  color: #9ca3af;
  margin-bottom: 8px;
}

.ai-chat__history-empty-icon svg {
  display: block;
}

.ai-chat__history-empty-text {
  font-size: var(--text-xs);
  color: #6b7280;
}

.ai-chat__history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-chat__history-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: background 0.2s;
}

.ai-chat__history-item:hover {
  background: #f3f4f6;
}

.ai-chat__history-item.is-active {
  background: #e0f2fe;
  border-color: #7dd3fc;
}

.ai-chat__history-item.is-pending .ai-chat__history-item-title {
  color: #0369a1;
}


.ai-chat__history-item-main {
  flex: 1 1 auto;
  min-width: 0;
}

.ai-chat__history-item-title {
  font-weight: 500;
  font-size: var(--text-xs);
  color: #1f2937;
  margin-bottom: 2px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat__history-item-pin {
  font-size: var(--text-xs);
  color: #9ca3af;
  margin-top: 2px;
}

.ai-chat__history-item-date {
  font-size: 0.85rem;
  color: #6b7280;
}

.ai-chat__history-menu-button {
  border-radius: 6px;
  padding: 2px 6px;
  font-size: var(--text-xs);
  line-height: 1;
}


.ai-chat__history-menu {
  position: absolute;
  right: 6px;
  top: 100%;
  margin-top: 6px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 170px;
  z-index: 10;
}

.ai-chat__history-menu[hidden] {
  display: none;
}

.ai-chat__history-menu-item {
  border: none;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: #111827;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat__history-menu-item:hover {
  background: #f3f4f6;
}

.ai-chat__history-menu-item.is-danger {
  color: #b91c1c;
}

.ai-chat__history-menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.ai-chat__history-menu-icon svg {
  display: block;
  fill: currentColor;
}

.ai-chat__history-menu-icon svg.ai-chat__icon-stroke {
  fill: none;
  stroke: currentColor;
}

.ai-chat__history-menu-icon svg.ai-chat__icon-outline {
  stroke: currentColor;
  stroke-width: 0.7;
  fill: currentColor;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.ai-chat__history-menu-icon i {
  display: block;
  font-size: 16px;
  line-height: 1;
}

.ai-chat__meta {
  margin-top: 6px;
  overflow-x: auto;
  max-width: 100%;
  display: block;
  width: 100%;
  clear: both;
  text-align: center;
}

.ai-chat__meta-table {
  width: auto;
  min-width: 380px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #c3c8d4;
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
  display: inline-table;
  box-shadow: none;
}

.ai-chat__meta-table th,
.ai-chat__meta-table td {
  padding: 2px 10px;
  border-right: 1px solid #d7dbe5;
  border-bottom: 1px solid #d7dbe5;
  vertical-align: middle;
  text-align: left;
  font-size: 10px;
  background: transparent;
  font-weight: normal;
}

.ai-chat__meta-table th:nth-child(1),
.ai-chat__meta-table td:nth-child(1) {
  border-right: none;
}

.ai-chat__meta-table th:nth-child(3),
.ai-chat__meta-table td:nth-child(3) {
  border-right: none;
}

.ai-chat__meta-table th {
  background: linear-gradient(#6f6f8f, #585a7a);
  color: #ffffff;
  font-weight: 600;
  text-transform: none;
}

.ai-chat__meta-table tr:nth-child(2n) td {
  background: #eef6fb;
}

.ai-chat__meta-table tr:nth-child(2n+1) td {
  background: #ffffff;
}

.ai-chat__meta-table tr:last-child td {
  border-bottom: none;
}

.ai-chat__meta-table td:last-child,
.ai-chat__meta-table th:last-child {
  border-right: none;
}

.ai-chat__debug {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: 6px;
  color: #0f172a;
  font-size: 12px;
  line-height: 1.4;
}

.ai-chat__debug-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: #111827;
}

.ai-chat__debug-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  color: #475569;
  font-size: 11px;
}

.ai-chat__debug-meta span {
  display: inline-block;
}

.ai-chat__debug-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: monospace;
  font-size: 11px;
  color: #111827;
}

.ai-chat__response-json-panel {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: 6px;
  color: #0f172a;
  font-size: 12px;
  line-height: 1.4;
}

.ai-chat__response-json-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: #111827;
}

.ai-chat__response-json {
  margin: 0;
  padding: 8px 10px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: monospace;
  font-size: 11px;
  color: #111827;
  background: #f1f5f9;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

/* 768–1023px и ≤767px: панель скрыта по умолчанию */
@media (max-width: 1023px) {
  .ai-chat__shell {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
    position: relative;
    transition: none;
  }
  /* При свёрнутой панели — как при 1024px: main на всю ширину, sidebar скрыт */
  .ai-chat__shell.is-sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__sidebar {
    display: none;
  }
  .ai-chat__main {
    grid-area: main;
  }
  .ai-chat__welcome {
    flex: 1 1 auto;
    width: 100%;
    box-sizing: border-box;
  }
}

/* 768–1023px: «Развернуть боковую панель» — эффект как у модалки корзины (слайд + fade), без затемнения */
@media (max-width: 1023px) and (min-width: 768px) {
  .ai-chat__shell {
    overflow: hidden;
    border-radius: 11px;
  }
  .ai-chat__shell.is-sidebar-open-mobile {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .ai-chat__sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    width: 280px;
    min-width: 280px;
    grid-area: unset;
    border-right: 1px solid #e5e7eb;
    border-top-left-radius: 11px;
    border-bottom-left-radius: 11px;
    transition: transform 0.25s, opacity 0.25s, visibility 0.25s;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-100%);
    pointer-events: none;
    box-shadow: none;
  }
  .ai-chat__sidebar.is-open-mobile {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.08);
  }
  .ai-chat__sidebar-backdrop {
    display: none !important;
  }
}

/* ≤767px: аккордеон — эффект как у модалки корзины (слайд + fade) + затемнение фона */
@media (max-width: 767px) {
  .ai-chat__shell {
    overflow: hidden;
    border-radius: 11px;
  }
  .ai-chat__shell.is-sidebar-open-mobile {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .ai-chat__sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    width: 280px;
    min-width: 280px;
    grid-area: unset;
    border-right: 1px solid #e5e7eb;
    border-top-left-radius: 11px;
    border-bottom-left-radius: 11px;
    transition: transform 0.25s, opacity 0.25s, visibility 0.25s;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-100%);
    pointer-events: none;
    box-shadow: none;
  }
  .ai-chat__sidebar.is-open-mobile {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.08);
  }
  .ai-chat__sidebar-backdrop {
    position: absolute;
    inset: 1px;
    z-index: 15;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 11px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s, visibility 0.25s;
    display: block !important;
  }
  .ai-chat__shell.is-sidebar-open-mobile .ai-chat__sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
}

/* 768–1023px: topbar с toggle и new рядом горизонтально, без mobile bar */
@media (max-width: 1023px) and (min-width: 768px) {
  .ai-chat__mobile-bar {
    display: none;
  }
  .ai-chat__topbar {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
  }
  .ai-chat__topbar-toggle {
    display: flex;
    flex-shrink: 0;
    min-width: 40px;
  }
  .ai-chat__topbar-new {
    display: flex; /* иконка без надписи, рядом с «Развернуть боковую панель» */
    flex-shrink: 0;
    min-width: 40px;
  }
  .ai-chat__header {
    display: none;
  }
  .ai-chat__topbar-meta {
    display: none;
  }
  .ai-chat__topbar-right {
    margin-left: 0;
  }
  /* Скрыть topbar-toggle и topbar-new когда sidebar открыт — collapse и «Новый чат» уже в sidebar */
  .ai-chat__sidebar.is-open-mobile ~ .ai-chat__main .ai-chat__topbar-toggle,
  .ai-chat__sidebar.is-open-mobile ~ .ai-chat__main .ai-chat__topbar-new {
    display: none;
  }
}

/* ≤767px: mobile bar — кнопка аккордеона (гамбургер) слева, «Новый чат» прижат к правому краю */
@media (max-width: 767px) {
  .ai-chat__mobile-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }
  .ai-chat__mobile-accordion {
    flex: 0 0 auto;
  }
  .ai-chat__mobile-accordion-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
  }
  .ai-chat__mobile-accordion-trigger svg {
    flex-shrink: 0;
  }
  .ai-chat__mobile-new {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: var(--text-sm);
    transition: background 0.2s;
    line-height: 1;
    box-sizing: border-box;
  }
  .ai-chat__mobile-new:hover {
    background: #f3f4f6;
  }

  .ai-chat__mobile-new:active {
    transform: translateY(0);
  }
  .ai-chat__mobile-new svg {
    flex-shrink: 0;
  }
  .ai-chat__topbar {
    display: none;
  }
}

@media (min-width: 1024px) {
  .ai-chat__mobile-bar {
    display: none;
  }
  /* Свёрнутая панель: та же структура и кнопки, что при ≤1023px — topbar с toggle и new */
  .ai-chat__shell.is-sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__sidebar {
    display: none;
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__topbar {
    justify-content: flex-start;
    gap: 8px;
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__topbar-toggle,
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__topbar-new {
    display: flex;
    flex-shrink: 0;
    min-width: 40px;
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__header {
    display: none;
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__topbar-meta {
    display: none;
  }
  .ai-chat__shell.is-sidebar-collapsed .ai-chat__topbar-right {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .ai-chat__form {
    gap: 6px;
  }
  .ai-chat__main {
    padding: 12px;
  }
  .ai-chat__meta-table {
    min-width: 280px;
  }
  .ai-chat__shell {
    min-height: 400px;
  }
}

@media (max-width: 360px) {
  .ai-chat__main {
    padding: 8px;
  }
  .ai-chat__meta-table {
    min-width: 240px;
  }
  .ai-chat__mobile-bar {
    gap: 6px;
  }
  .ai-chat__mobile-new {
    padding: 6px 10px;
    font-size: var(--text-xs);
  }
}

