/* Чат (заготовка app add chat, docs/specs-chat/chat.md §13): после копирования — стили приложения. */
.chat { display: grid; grid-template-columns: 16rem 1fr; gap: 1rem; padding: 1rem; height: calc(100vh - 4rem); box-sizing: border-box; }
.chat-list ul { list-style: none; margin: .5rem 0 0; padding: 0; overflow-y: auto; }
.chat-list button.link { display: block; width: 100%; text-align: start; background: none; border: 0; padding: .4rem .5rem; cursor: pointer; }
.chat-list button.current { font-weight: 600; background: rgba(0, 0, 0, .05); }
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.chat-feed { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .5rem; }
.chat-message { max-width: 80%; padding: .5rem .75rem; border-radius: .5rem; }
.chat-user { align-self: flex-end; background: #e8f0fe; white-space: pre-wrap; }
.chat-assistant { align-self: flex-start; background: #f3f3f3; }
.chat-assistant pre { overflow-x: auto; background: #fff; padding: .5rem; }
.chat-assistant table { border-collapse: collapse; }
.chat-assistant th, .chat-assistant td { border: 1px solid #ccc; padding: .2rem .4rem; }
.chat-tool { font-size: .85rem; color: #666; }
.chat-usage { margin: 0 0 .25rem; font-size: .85em; }
.chat-banner { margin: 0 0 .5rem; padding: .5rem .75rem; border-radius: .5rem; background: #fff4d6; border: 1px solid #e0b000; }
.md-domain, .md-image { color: #777; font-size: .85em; }
.chat-confirm { border: 2px solid #c77700; border-radius: .5rem; padding: .75rem; margin: .5rem 0; background: #fff8ec; }
.chat-confirm pre { max-height: 12rem; overflow: auto; }
.chat-input textarea { width: 100%; box-sizing: border-box; }
.chat-input .actions, .chat-confirm .actions { display: flex; gap: .5rem; margin-top: .5rem; }
.chat-input #chat-mic[data-state="recording"] { color: #b00020; border-color: #b00020; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Вложения (§9): значки у поля ввода и в ленте, подсветка при перетаскивании. */
.chat-attachments { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.3rem 0; padding: 0; }
.chat-attachments li { display: flex; align-items: center; gap: 0.2rem; }
.chat-badge { display: inline-block; max-width: 100%; padding: 0.15rem 0.5rem; border-radius: 1rem; background: #eef1f6; color: #1f2937; font-size: 0.85em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
/* вложение в тёмной теме — как плашки инструментов: тёмный фон, светлый текст (замечание владельца 2026-11-03) */
html.dark .chat-badge { background: #374151; color: #e5e7eb; }
.chat-feed > .chat-badge { margin-block: 0.2rem 0; margin-inline-start: auto; }
.chat-attach { cursor: pointer; }
.chat-drop { outline: 2px dashed #6b8fd6; outline-offset: 2px; }

/* Память (§10.5): панели «Моя память» и «Настройки чата» команды. */
.memory { max-width: 56rem; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.memory-settings, .memory-filter, .memory-edit { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.memory-edit textarea, .memory-edit input { flex: 1 1 100%; box-sizing: border-box; }
.memory-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.memory-item { border: 1px solid #ddd; border-radius: .5rem; padding: .5rem .75rem; }
.memory-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.memory-content { white-space: pre-wrap; margin: .3rem 0; }
.memory-meta { font-size: .85em; margin: 0; }
.memory-inactive { opacity: .6; }
.memory-assumption { background: #fff4d6; }
.memory .actions { display: flex; flex-wrap: wrap; gap: .4rem; }
/* Остановленный ответ (§13): пометка под пришедшим текстом. */
.chat-stopped { margin: 0.3rem 0 0; font-size: 0.85em; color: var(--muted, #656d76); }

/* Панель чата на страницах бизнеса (D-0045): справа (в RTL — слева), поверх страницы; список бесед — только кнопка «новая». */
.chat-panel { position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 50; width: min(28rem, 100vw); display: flex; flex-direction: column;
  background: var(--bg, #fff); box-shadow: 0 0 1rem rgba(0, 0, 0, .2); }
.chat-panel[hidden] { display: none; }
.chat-panel-head { display: flex; gap: .75rem; align-items: center; padding: .5rem .75rem; border-block-end: 1px solid #ddd; }
.chat-panel-head strong { flex: 1; }
.chat-panel .chat { display: flex; flex-direction: column; flex: 1; min-height: 0; height: auto; padding: .5rem; gap: .5rem; }
.chat-panel .chat-list ul { display: none; }
.chat-panel .chat-message { max-width: 95%; }

/* Панель ассистента как у оригинала (виджет BotCraft в колонке справа, D-0105; docs/notes/original-chat.md): 24rem, раздвигает страницу на
   широком экране, во весь экран на узком; шапка 56px, пузыри 18px, история и память — размеры виджета. Перекрывает правила панели выше. */
.chat-panel { position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 50; width: 24rem; min-width: 20rem; display: flex; flex-direction: column;
  background: #fff; border-inline-start: 1px solid #e5e7eb; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -4px rgba(0, 0, 0, .1); }
html.dark .chat-panel { background: #1f2937; border-color: #374151; }
@media (min-width: 64rem) {
  html.chat-open { overflow: hidden; }
  html.chat-open body, html.chat-restore:has(#chat-panel-template) body { height: 100vh; overflow-y: auto; box-sizing: border-box; margin-inline-end: 24rem; }
  html.chat-restore:has(#chat-panel-template) { overflow: hidden; }
  /* место панели до её появления (theme.js → chat-panel.js): фон и рамка панели, без анимации (владелец 2026-11-10) */
  html.chat-restore:has(#chat-panel-template) body::after { content: ''; position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 49; width: 24rem;
    background: #fff; border-inline-start: 1px solid #e5e7eb; }
  html.dark.chat-restore:has(#chat-panel-template) body::after { background: #1f2937; border-color: #374151; }
  /* полоса прокрутки страницы между страницей и панелью не нужна (владелец 2026-11-10): страница прокручивается колесом и клавишами */
  html.chat-open body, html.chat-restore body { scrollbar-width: none; }
  html.chat-open body::-webkit-scrollbar, html.chat-restore body::-webkit-scrollbar { display: none; }
}
@media (max-width: 63.99rem) { .chat-panel { inset-inline: 0; width: auto; min-width: 0; } }
.chat-panel-head { display: flex; align-items: center; gap: .5rem; height: 56px; min-height: 56px; padding: 0 1rem; box-sizing: border-box;
  border-block-end: 1px solid #e5e7eb; background: #fff; }
html.dark .chat-panel-head { background: #2d3748; border-color: #4a5568; }
.cp-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: .5rem; font-size: 1rem; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--fg); }
.cp-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: #28a745; box-shadow: 0 0 0 2px rgba(40, 167, 69, .3); }
.chat-panel[data-view="history"] .cp-dot, .chat-panel[data-view="memory"] .cp-dot { display: none; }
/* .cp-actions портала клиента (app.css) даёт отступ сверху — у шапки чата его нет: значки на одной линии с заголовком */
.chat-panel-head .cp-actions { display: flex; align-items: center; gap: 4px; margin: 0; }
.cp-icon, html.dark .cp-icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px;
  background: none; color: #6b7280; cursor: pointer; }
html.dark .cp-icon { color: #a0aec0; }
.cp-icon:hover { background: rgba(0, 0, 0, .06); }
html.dark .cp-icon:hover { background: rgba(255, 255, 255, .08); }
.cp-icon .icon { width: 22px; height: 22px; }
.cp-close .icon { width: 16px; height: 16px; }
[dir="rtl"] .cp-close .icon { transform: scaleX(-1); }
.chat-panel .chat { display: flex; flex-direction: column; flex: 1; min-height: 0; height: auto; padding: 0; gap: 0; }
.chat-panel .chat-list { display: none; }
.chat-panel[data-view="history"] .chat-list { display: block; flex: 1; overflow-y: auto; }
.chat-panel[data-view="history"] .chat-main { display: none; }
/* лента и пузыри */
.chat-panel .chat-main { flex: 1; min-height: 0; }
.chat-panel .chat-feed { gap: 12px; padding: 1rem; background: var(--canvas, #f9fafb); }
.chat-welcome { margin: 0; padding: 1.25rem; text-align: center; font-style: italic; color: #6b7280; }
.chat-panel .chat-welcome { position: absolute; inset-inline: 0; top: 40%; pointer-events: none; }
.chat-panel .chat-main { position: relative; }
.chat-message { max-width: 85%; padding: 12px 16px; line-height: 1.4; border-radius: 18px; }
.chat-user { align-self: flex-end; background: var(--primary); color: #fff; white-space: pre-wrap; border-end-end-radius: 4px; }
.chat-assistant { align-self: flex-start; background: #fff; color: #333; border: 1px solid #e1e5e9; border-end-start-radius: 4px; }
html.dark .chat-assistant { background: #4a5568; color: #fff; border-color: #718096; }
.chat-assistant a { color: #1f6feb; text-decoration: underline; }
html.dark .chat-assistant a { color: #93c5fd; }
.chat-assistant pre { background: rgba(0, 0, 0, .04); }
.chat-tool { align-self: flex-start; padding: .125rem .5rem; border-radius: 9999px; background: rgba(107, 114, 128, .1); font-size: .75rem; color: #6b7280; }
/* поле ввода */
.chat-panel .chat-input { border-block-start: 1px solid #e5e7eb; padding: 12px; background: #fff; }
html.dark .chat-panel .chat-input { background: #1f2937; border-color: #374151; }
.chat-panel .chat-input textarea { min-height: 60px; max-height: 120px; resize: vertical; padding: .5rem .75rem; border: 1px solid #d1d5db; border-radius: 8px; }
.chat-panel .chat-input textarea:focus { outline: none; box-shadow: 0 0 0 2px var(--primary); }
.chat-panel .chat-input .actions { align-items: center; margin-top: .25rem; }
.chat-panel .chat-usage { flex: 1; margin: 0; font-size: .6875rem; text-align: center; }
.chat-panel .cp-send { color: var(--primary); }
.chat-panel .cp-send .icon, .chat-panel .chat-attach .icon { width: 18px; height: 18px; }
/* нижняя часть ниже: поле и строка значков плотнее, значки 28px */
.chat-panel .chat-input { padding: 8px 12px; }
.chat-panel .chat-input textarea { min-height: 48px; }
.chat-panel .chat-input .actions { margin-top: 4px; }
.chat-panel .chat-input .cp-icon { width: 28px; height: 28px; }
/* история */
.chat-panel .chat-list ul { display: block; margin: 0; }
.chat-list li button.link { display: flex; align-items: center; gap: .5rem; width: 100%; padding: 12px 16px; border: 0; border-block-end: 1px solid #e5e7eb; border-radius: 0;
  background: none; text-align: start; color: var(--fg); cursor: pointer; }
html.dark .chat-list li button.link { border-color: #374151; }
.chat-list li button.link:hover { background: rgba(0, 0, 0, .04); }
html.dark .chat-list li button.link:hover { background: rgba(255, 255, 255, .05); }
.chat-list li button.current { font-weight: 400; background: rgba(74, 222, 128, .08); }
.chat-row-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-row-when { font-size: .75rem; color: #6b7280; }
.chat-row-title { font-size: .8125rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-row-chevron { flex-shrink: 0; width: 16px; height: 16px; color: #9ca3af; }
[dir="rtl"] .chat-row-chevron { transform: scaleX(-1); }
.cp-empty { margin: 0; padding: 1.25rem; text-align: center; color: #6b7280; }
/* память */
.cp-memory { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.cp-memory[hidden] { display: none; }
.cp-mem-top { display: flex; flex-direction: column; gap: .5rem; padding: .75rem; border-block-end: 1px solid #e5e7eb; }
html.dark .cp-mem-top { border-color: #374151; }
.cp-mem-row { display: flex; justify-content: space-between; }
.cp-small, html.dark .cp-small { padding: .25rem .5rem; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: var(--fg); font-size: .75rem; cursor: pointer; }
html.dark .cp-small { background: #374151; border-color: #4b5563; }
.cp-small.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.cp-small.danger { color: #dc2626; }
.cp-mem-search { width: 100%; box-sizing: border-box; }
.cp-mem-chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.cp-chip, html.dark .cp-chip { padding: .125rem .5rem; border: 1px solid #d1d5db; border-radius: 9999px; background: none; color: var(--fg); font-size: .75rem; cursor: pointer; }
.cp-chip.on, html.dark .cp-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.cp-mem-flags { display: flex; gap: 1rem; font-size: .75rem; }
.cp-mem-list { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.cp-mem-hint { margin: 0; text-align: center; font-size: .75rem; color: #6b7280; }
.cp-mem-card { padding: .75rem; border: 1px solid #e1e5e9; border-radius: .5rem; background: #fff; }
html.dark .cp-mem-card { background: #4a5568; border-color: #718096; }
.cp-mem-card.off { opacity: .6; }
.cp-mem-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.cp-mem-title { font-weight: 500; }
.cp-pill { flex-shrink: 0; padding: 0 .375rem; border-radius: 9999px; background: rgba(107, 114, 128, .12); font-size: .6875rem; }
.cp-mem-content { margin: .25rem 0; font-size: .8125rem; white-space: pre-wrap; }
.cp-mem-meta { margin: 0 0 .375rem; font-size: .6875rem; color: #6b7280; }
html.dark .cp-mem-meta { color: #cbd5e0; }
.cp-mem-actions { display: flex; flex-wrap: wrap; gap: .25rem; }
.cp-dialog-back { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(0, 0, 0, .4); }
.cp-dialog { width: 100%; padding: 1rem; border-radius: .5rem; background: #fff; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .2); }
html.dark .cp-dialog { background: #2d3748; }
.cp-dialog h3 { margin: 0 0 .75rem; font-size: 1rem; }
.cp-form { display: flex; flex-direction: column; gap: .5rem; }
.cp-field { display: flex; flex-direction: column; gap: .25rem; font-size: .75rem; }
.cp-dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .75rem; }
.chat-panel [hidden] { display: none !important; }

/* «печатает»: три точки по очереди, пока ответа нет (2026-11-03) */
.chat-typing { display: inline-flex; gap: .3rem; align-items: center; height: 1.25rem; padding: 0 .1rem; }
.chat-typing i { width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; opacity: .35; animation: chat-typing 1.2s infinite ease-in-out; }
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-.25rem); opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .chat-typing i { animation: none; opacity: .6; } }

/* /chat во весь экран (2026-11-03): на всю ширину под шапкой; список бесед прилипает слева и прокручивается сам, лента — прокруткой
   страницы, поле ввода с кнопками-значками (как в панели) прилипает к низу окна */
html main.chat-page, html.in-tenant main.chat-page { max-width: none; margin: 0; padding: 0; height: auto; min-height: calc(100vh - 3.5rem); display: grid; grid-template-columns: 18rem minmax(0, 1fr); gap: 0; }
.chat-page .chat-list { position: sticky; top: 3.5rem; align-self: start; height: calc(100vh - 3.5rem); overflow-y: auto; box-sizing: border-box;
  padding: 1rem .75rem; border-inline-end: 1px solid var(--line); background: var(--surface); }
.chat-page #chat-new { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; width: 100%; }
.chat-page #chat-new .icon { width: 1rem; height: 1rem; }
.chat-page .chat-list ul { margin-top: .75rem; overflow: visible; }
.chat-page .chat-main { display: flex; flex-direction: column; min-height: calc(100vh - 3.5rem); }
.chat-page .chat-feed { flex: 1; overflow: visible; gap: 12px; padding: 1.5rem clamp(1rem, 4vw, 4rem); }
.chat-page .chat-message { max-width: min(85%, 60rem); }
.chat-page .chat-dock { position: sticky; bottom: 0; z-index: 5; padding: .75rem clamp(1rem, 4vw, 4rem) 1rem; background: var(--canvas);
  border-block-start: 1px solid var(--line); }
.chat-page .chat-input textarea { min-height: 60px; max-height: 40vh; resize: vertical; padding: .5rem .75rem; border: 1px solid #d1d5db; border-radius: 8px; }
html.dark .chat-page .chat-input textarea { border-color: #4b5563; }
.chat-page .chat-input textarea:focus { outline: none; box-shadow: 0 0 0 2px var(--primary); }
.chat-page .chat-input .actions { align-items: center; margin-top: .25rem; }
.chat-page .chat-usage { flex: 1; margin: 0; font-size: .75rem; text-align: center; }
.chat-page .cp-send { color: var(--primary); }
/* «Отправить» — значок цвета primary в обеих темах: общее html.dark form button[type='submit'] красит текст кнопки тёмным и даёт фон */
.chat-panel .chat-input .cp-send, .chat-page .chat-input .cp-send, html.dark .chat-panel .chat-input .cp-send, html.dark .chat-page .chat-input .cp-send {
  background: none; border: 0; color: var(--primary); }
.chat-panel .chat-input .cp-send:hover, .chat-page .chat-input .cp-send:hover { background: rgba(0, 0, 0, .06); }
html.dark .chat-panel .chat-input .cp-send:hover, html.dark .chat-page .chat-input .cp-send:hover { background: rgba(255, 255, 255, .08); }
.chat-page .cp-send .icon, .chat-page .chat-attach .icon { width: 18px; height: 18px; }
.chat-page .error:empty { display: none; }
@media (max-width: 48rem) {
  html.in-tenant main.chat-page { grid-template-columns: 1fr; }
  .chat-page .chat-list { position: static; height: auto; max-height: 30vh; border-inline-end: 0; border-block-end: 1px solid var(--line); }
  .chat-page .chat-main { min-height: 0; }
}
/* прокрутка к последнему сообщению не прячет его под прилипшим полем ввода */
html:has(main.chat-page) { scroll-padding-bottom: 11rem; }
.chat-page [hidden] { display: none !important; }
/* «Memory» во весь экран — внизу списка бесед, как кнопка памяти в шапке панели */
.chat-page .chat-list { display: flex; flex-direction: column; }
.chat-page .chat-list ul { flex: 1; }
.chat-list-link { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; padding: .5rem .75rem; border-radius: 8px; color: var(--fg); text-decoration: none; font-size: .875rem; }
.chat-list-link:hover { background: rgba(0, 0, 0, .04); }
html.dark .chat-list-link:hover { background: rgba(255, 255, 255, .05); }
.chat-list-link .icon { width: 1.125rem; height: 1.125rem; }

/* пузыри компактнее (замечание владельца 2026-11-03): у первого и последнего абзаца Markdown нет внешних отступов — пузырь не раздувается
   сверху и снизу; плашка файла — крупнее и читаемее */
.chat-message .chat-body > :first-child { margin-top: 0; }
.chat-message .chat-body > :last-child { margin-bottom: 0; }
.chat-message .chat-body p { margin: .5em 0; }
.chat-badge { padding: .4rem .8rem; font-size: .9rem; line-height: 1.3; border-radius: .75rem; }
.chat-feed > .chat-badge { max-width: min(85%, 28rem); }
/* память во весь экран — в колонке ленты */
.chat-page .chat-page-memory { min-height: calc(100vh - 3.5rem); padding: 1rem clamp(1rem, 4vw, 4rem); box-sizing: border-box; }
.chat-page .chat-main[hidden] { display: none !important; }
.chat-page button.chat-list-link { width: 100%; border: 0; background: none; text-align: start; cursor: pointer; font: inherit; font-size: .875rem; }
/* /chat на всю ширину: лента, поле ввода и память — с отступом 1rem, сообщения — до 85% ширины; у памяти — «← Back  Memory … + Add» */
.chat-page .chat-feed { padding: 1rem; }
.chat-page .chat-dock { padding: .75rem 1rem 1rem; }
.chat-page .chat-message { max-width: 85%; }
.chat-page .chat-page-memory { padding: 1rem; }
.chat-page .cp-mem-row { align-items: center; gap: .75rem; justify-content: flex-start; }
.chat-page .cp-mem-row > button:last-child { margin-inline-start: auto; }
.chat-page-memory-title { margin: 0; font-size: 1.125rem; font-weight: 600; }
/* страница чата: поле ввода такой же высоты, как у бокового чата (владелец 2026-11-09) — отступы 8px, строка значков плотнее, значки 28px */
.chat-page .chat-dock { padding-block: 8px; }
.chat-page .chat-input textarea { min-height: 48px; overflow-y: auto; }  /* как в боковом чате, растёт с текстом (владелец 2026-11-10: 38px — низко) */
.chat-page .chat-input .actions { margin-top: 4px; }
.chat-page .chat-input .cp-icon { width: 28px; height: 28px; }
.chat-page .chat-usage { font-size: .6875rem; }
html:has(main.chat-page) { scroll-padding-bottom: 8rem; }
