/* Диалог ИИ — размеры как в примере, цвета из CRM (--crm-*) + html.dark */

.ai-chat-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1 1 auto;
  min-height: 0;
  /* Не фиксировать 750px: на ноутбуках 13" не влезает вместе с шапкой CRM */
  --ai-chat-vpad: 13rem;
  --ai-chat-panel-height: min(750px, calc(100vh - var(--ai-chat-vpad)));
  --ai-chat-panel-height: min(
    750px,
    calc(
      100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--ai-chat-vpad)
    )
  );
}

.ai-chat-panel .chat-container {
  width: 100%;
  max-width: 800px;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: var(--ai-chat-panel-height);
  max-height: var(--ai-chat-panel-height);
  min-height: 0;
  border: 1px solid var(--crm-gray-200);
}

.dark .ai-chat-panel .chat-container {
  background: var(--crm-gray-800);
  border-color: var(--crm-gray-700);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.ai-chat-panel .chat-header {
  background: #fff;
  color: var(--crm-gray-900);
  padding: 18px 20px 16px;
  text-align: center;
  border-bottom: 1px solid var(--crm-slate-200);
  flex-shrink: 0;
}

.dark .ai-chat-panel .chat-header {
  background: var(--crm-gray-950, #0f172a);
  color: #fff;
  border-bottom: 1px solid var(--crm-gray-700);
}

.ai-chat-panel .chat-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 4px;
  line-height: 1.2;
}

.ai-chat-panel .chat-header p {
  font-size: 0.85rem;
  margin: 0;
  color: var(--crm-gray-600);
}

.dark .ai-chat-panel .chat-header p {
  color: rgba(255, 255, 255, 0.88);
}

/* Одна строка: выбор модели + подпись */
.ai-chat-panel .chat-header .ai-chat-header-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 10px 0 0;
  width: 100%;
}

/* Компактный выпадающий список модели */
.ai-chat-panel .chat-header .ai-chat-provider-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
  margin: 0;
  max-width: 100%;
  flex-shrink: 0;
}

.ai-chat-panel .chat-header .ai-chat-provider-subtitle {
  font-size: 0.85rem;
  margin: 0;
  line-height: 1.35;
  text-align: center;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--crm-gray-600);
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-subtitle {
  color: rgba(255, 255, 255, 0.88);
}

.ai-chat-panel .chat-header .ai-chat-provider-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  flex-shrink: 0;
  color: var(--crm-gray-500);
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-label {
  color: rgba(255, 255, 255, 0.65);
}

.ai-chat-panel .chat-header .ai-chat-provider-select-wrap {
  position: relative;
  display: inline-block;
  max-width: min(220px, 72vw);
}

.ai-chat-panel .chat-header .ai-chat-provider-select-wrap::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -2px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--crm-gray-600);
  pointer-events: none;
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-select-wrap::after {
  border-top-color: rgba(255, 255, 255, 0.55);
}

.ai-chat-panel .chat-header .ai-chat-provider-select {
  display: block;
  width: 100%;
  min-height: 34px;
  padding: 6px 28px 6px 11px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--crm-gray-900, #0f172a);
  background: var(--crm-slate-50);
  border: 1px solid var(--crm-gray-300);
  border-radius: 999px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.ai-chat-panel .chat-header .ai-chat-provider-select:hover {
  border-color: var(--crm-gray-400);
  background: #fff;
}

.ai-chat-panel .chat-header .ai-chat-provider-select:focus {
  border-color: var(--crm-primary-500);
  box-shadow: 0 0 0 2px rgb(139 92 246 / 0.25);
}

.ai-chat-panel .chat-header .ai-chat-provider-select:focus-visible {
  border-color: var(--crm-primary-500);
  box-shadow: 0 0 0 2px rgb(139 92 246 / 0.35);
}

.ai-chat-panel .chat-header .ai-chat-provider-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-select {
  color: #f1f5f9;
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(148, 163, 184, 0.35);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-select:hover {
  border-color: rgba(148, 163, 184, 0.5);
}

.dark .ai-chat-panel .chat-header .ai-chat-provider-select:focus-visible {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.55);
}

/* --- Композер: DeepSeek у поля ввода + вложения --- */
.ai-chat-panel .ai-chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ai-chat-panel .ai-chat-composer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--crm-slate-200);
}

.dark .ai-chat-panel .ai-chat-composer {
  background: var(--crm-gray-800);
  border-top-color: var(--crm-gray-700);
}

.ai-chat-panel .ai-chat-deepseek-toolbar {
  padding: 8px 16px 14px;
  width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.ai-chat-panel .ai-chat-deepseek-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

/* Единая капсула: Thinking + (только при включении) разделитель и High/Max */
.ai-chat-panel .ai-chat-deepseek-fusion {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  max-width: 100%;
  min-height: 40px;
  box-sizing: border-box;
  border-radius: 14px;
  border: 1px solid var(--crm-gray-200);
  background: linear-gradient(180deg, #fff 0%, var(--crm-slate-50) 100%);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.05);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion {
  border-color: rgba(148, 163, 184, 0.28);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.55) 0%, rgba(15, 23, 42, 0.75) 100%);
  box-shadow: none;
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) {
  border-color: rgb(139 92 246 / 0.42);
  box-shadow: 0 0 0 1px rgb(139 92 246 / 0.12), 0 2px 10px rgb(99 102 241 / 0.12);
  background: linear-gradient(180deg, rgb(139 92 246 / 0.1) 0%, rgb(139 92 246 / 0.04) 100%);
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) {
  border-color: rgb(167 139 250 / 0.45);
  box-shadow: 0 0 0 1px rgb(99 102 241 / 0.2);
  background: linear-gradient(180deg, rgb(99 102 241 / 0.22) 0%, rgb(30 41 59 / 0.9) 100%);
}

.ai-chat-panel .ai-chat-thinking-wrap {
  display: flex;
  align-items: center;
}

.ai-chat-panel .ai-chat-thinking-face {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 0 12px 0 10px;
  min-height: 38px;
  box-sizing: border-box;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--crm-gray-600);
  cursor: pointer;
  user-select: none;
  line-height: 1.2;
  transition: color 0.15s, background 0.15s;
}

.dark .ai-chat-panel .ai-chat-thinking-face {
  color: rgba(226, 232, 240, 0.82);
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-thinking-face {
  color: var(--crm-primary-700, #6d28d9);
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-thinking-face {
  color: #e9d5ff;
}

.ai-chat-panel .ai-chat-thinking-face-icon {
  display: flex;
  color: inherit;
}

.ai-chat-panel .ai-chat-thinking-sparkle {
  display: block;
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-thinking-sparkle {
  color: var(--crm-primary-600, #7c3aed);
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-thinking-sparkle {
  color: #c4b5fd;
}

.ai-chat-panel .ai-chat-thinking-face-text {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ai-chat-panel .ai-chat-thinking-face:focus-visible {
  outline: 2px solid rgb(99 102 241 / 0.55);
  outline-offset: -2px;
  border-radius: 4px;
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:disabled) .ai-chat-thinking-face {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.ai-chat-panel .ai-chat-deepseek-fusion-divider {
  display: none;
  width: 1px;
  align-self: stretch;
  min-height: 26px;
  margin: 0;
  background: linear-gradient(180deg, transparent, var(--crm-gray-300) 12%, var(--crm-gray-300) 88%, transparent);
  flex-shrink: 0;
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion-divider {
  background: linear-gradient(180deg, transparent, rgba(148, 163, 184, 0.35) 20%, rgba(148, 163, 184, 0.35) 80%, transparent);
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-deepseek-fusion-divider {
  display: block;
}

.ai-chat-panel .ai-chat-effort-unit {
  display: none;
  align-items: center;
  /* зазор от вертикального разделителя до сегмента High / Max */
  padding: 0 6px 0 12px;
  box-sizing: border-box;
  min-height: 38px;
}

.ai-chat-panel .ai-chat-deepseek-fusion:has(#aiChatDeepseekThinking:checked) .ai-chat-effort-unit {
  display: inline-flex;
}

.ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-seg {
  display: inline-flex;
  align-items: center;
  padding: 1px;
  border-radius: 9px;
  background: rgb(255 255 255 / 0.92);
  border: 1px solid rgb(139 92 246 / 0.15);
  gap: 1px;
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-seg {
  background: rgba(15, 23, 42, 0.75);
  border-color: rgba(167 139 250, 0.25);
}

.ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill {
  -webkit-appearance: none !important;
  appearance: none !important;
  margin: 0;
  padding: 4px 10px;
  min-height: 30px;
  box-sizing: border-box;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--crm-gray-500);
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s, color 0.12s;
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill {
  color: rgba(203, 213, 225, 0.75);
}

.ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill.is-active {
  background: #fff;
  color: var(--crm-primary-600, #7c3aed);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08);
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill.is-active {
  background: rgba(51, 65, 85, 0.95);
  color: #c4b5fd;
  box-shadow: none;
}

.ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill:hover:not(:disabled):not(.is-active) {
  color: var(--crm-gray-800);
}

.dark .ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill:hover:not(:disabled):not(.is-active) {
  color: #f1f5f9;
}

.ai-chat-panel .ai-chat-deepseek-fusion .ai-chat-effort-pill:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-chat-panel .ai-chat-reasoning {
  width: 100%;
  max-width: min(92%, 42rem);
  box-sizing: border-box;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px dashed var(--crm-gray-300);
  background: var(--crm-slate-50);
  font-size: 0.8125rem;
  color: var(--crm-gray-700);
  overflow-anchor: none;
}

.ai-chat-panel .ai-chat-reasoning--pending {
  display: none;
}

.dark .ai-chat-panel .ai-chat-reasoning {
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.65);
  color: rgba(226, 232, 240, 0.95);
}

/* Шапка спойлера — div[role=button]: у нативного <button> в WebKit при :active внутренний ряд визуально «съезжает к центру». */
.ai-chat-panel .ai-chat-reasoning-toggle {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: 2px 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
  min-height: 2rem;
}

.ai-chat-panel .ai-chat-reasoning-toggle:focus {
  outline: none;
}

.ai-chat-panel .ai-chat-reasoning-toggle:focus-visible {
  outline: 2px solid rgb(99 102 241 / 0.55);
  outline-offset: 0;
  border-radius: 10px;
}

.ai-chat-panel .ai-chat-reasoning-panel {
  margin: 0;
  padding: 0;
}

.ai-chat-panel .ai-chat-reasoning-panel[hidden] {
  display: none !important;
}

.ai-chat-panel .ai-chat-reasoning-summary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 0;
  user-select: none;
}

.ai-chat-panel .ai-chat-reasoning-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(145deg, #3b82f6 0%, #2563eb 100%);
  flex-shrink: 0;
  color: #fff;
  box-shadow: 0 1px 2px rgb(37 99 235 / 0.35);
}

.ai-chat-panel .ai-chat-reasoning-icon-svg {
  width: 12px;
  height: 12px;
  display: block;
}

.ai-chat-panel .ai-chat-reasoning-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #2563eb;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dark .ai-chat-panel .ai-chat-reasoning-label {
  color: #93c5fd;
}

.ai-chat-panel .ai-chat-reasoning-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  color: var(--crm-gray-500);
  opacity: 0.88;
}

.dark .ai-chat-panel .ai-chat-reasoning-chevron {
  color: rgba(226, 232, 240, 0.65);
}

.ai-chat-panel .ai-chat-reasoning-chevron svg {
  display: block;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.ai-chat-panel .ai-chat-reasoning--collapsed .ai-chat-reasoning-chevron svg {
  transform: rotate(0deg);
}

.ai-chat-panel .ai-chat-reasoning:not(.ai-chat-reasoning--collapsed) .ai-chat-reasoning-chevron svg {
  transform: rotate(180deg);
}

.ai-chat-panel .ai-chat-reasoning-body {
  margin: 8px 0 0;
  padding-left: 12px;
  border-left: 3px solid rgb(203 213 225 / 0.95);
  margin-left: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  overflow: visible;
}

.dark .ai-chat-panel .ai-chat-reasoning-body {
  border-left-color: rgb(100 116 139 / 0.55);
}

.ai-chat-panel .messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* Стабильная ширина при появлении скроллбара — без «прыжка» шапки рассуждений */
  scrollbar-gutter: stable;
  padding: 20px;
  background: var(--crm-slate-50);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dark .ai-chat-panel .messages-area {
  background: var(--crm-gray-900);
}

.ai-chat-panel .message {
  display: flex;
  margin-bottom: 8px;
  animation: ai-chat-fadeIn 0.3s ease;
}

.ai-chat-panel .user-message {
  justify-content: flex-end;
}

.ai-chat-panel .ai-message {
  justify-content: flex-start;
  flex-direction: column;
  align-items: stretch;
}

.ai-chat-panel .message-content {
  max-width: 70%;
  padding: 10px 16px;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
  font-size: 0.9375rem;
}

/* Пузырь ассистента (в т.ч. стриминг без --rich): та же ширина, что у блока рассуждений и у готового Markdown */
.ai-chat-panel .ai-message > .message-content {
  max-width: min(92%, 42rem);
}

.ai-chat-panel .user-message .message-content {
  background: var(--crm-primary-500);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-panel .ai-message .message-content {
  background: #fff;
  color: var(--crm-gray-900);
  border: 1px solid var(--crm-slate-200);
  border-bottom-left-radius: 4px;
}

.dark .ai-chat-panel .ai-message .message-content {
  background: var(--crm-gray-700);
  color: var(--crm-gray-100);
  border-color: var(--crm-gray-600);
}

/* Ответы ассистента: Markdown (marked + DOMPurify) */
.ai-chat-panel .ai-message .message-content--rich {
  max-width: min(92%, 42rem);
  overflow-x: auto;
}

.ai-chat-panel .ai-message .message-content--rich > :first-child {
  margin-top: 0;
}

.ai-chat-panel .ai-message .message-content--rich > :last-child {
  margin-bottom: 0;
}

.ai-chat-panel .ai-message .message-content--rich p {
  margin: 0 0 0.65em;
}

.ai-chat-panel .ai-message .message-content--rich h1,
.ai-chat-panel .ai-message .message-content--rich h2,
.ai-chat-panel .ai-message .message-content--rich h3,
.ai-chat-panel .ai-message .message-content--rich h4 {
  margin: 0.85em 0 0.45em;
  font-weight: 700;
  line-height: 1.25;
}

.ai-chat-panel .ai-message .message-content--rich h1 { font-size: 1.2rem; }
.ai-chat-panel .ai-message .message-content--rich h2 { font-size: 1.1rem; }
.ai-chat-panel .ai-message .message-content--rich h3 { font-size: 1.02rem; }

.ai-chat-panel .ai-message .message-content--rich ul,
.ai-chat-panel .ai-message .message-content--rich ol {
  margin: 0.4em 0 0.65em;
  padding-left: 1.35em;
}

.ai-chat-panel .ai-message .message-content--rich li {
  margin: 0.2em 0;
}

.ai-chat-panel .ai-message .message-content--rich blockquote {
  margin: 0.5em 0;
  padding: 0.35em 0 0.35em 0.85em;
  border-left: 3px solid rgb(99 102 241 / 0.45);
  color: var(--crm-gray-700);
}

.dark .ai-chat-panel .ai-message .message-content--rich blockquote {
  color: var(--crm-gray-300);
  border-left-color: rgb(165 180 252 / 0.5);
}

.ai-chat-panel .ai-message .message-content--rich hr {
  margin: 0.75em 0;
  border: none;
  border-top: 1px solid var(--crm-slate-200);
}

.dark .ai-chat-panel .ai-message .message-content--rich hr {
  border-top-color: var(--crm-gray-600);
}

.ai-chat-panel .ai-message .message-content--rich pre {
  margin: 0.5em 0;
  padding: 10px 12px;
  border-radius: 12px;
  overflow-x: auto;
  background: var(--crm-slate-100);
  font-size: 0.85em;
  line-height: 1.45;
}

.dark .ai-chat-panel .ai-message .message-content--rich pre {
  background: rgb(15 23 42 / 0.65);
}

.ai-chat-panel .ai-message .message-content--rich code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.ai-chat-panel .ai-message .message-content--rich p code,
.ai-chat-panel .ai-message .message-content--rich li code {
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: var(--crm-slate-100);
  font-size: 0.9em;
}

.dark .ai-chat-panel .ai-message .message-content--rich p code,
.dark .ai-chat-panel .ai-message .message-content--rich li code {
  background: rgb(15 23 42 / 0.75);
}

.ai-chat-panel .ai-message .message-content--rich pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.ai-chat-panel .ai-message .message-content--rich a {
  color: var(--crm-primary-600);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-chat-panel .ai-message .message-content--rich a:hover {
  color: var(--crm-primary-500);
}

.dark .ai-chat-panel .ai-message .message-content--rich a {
  color: rgb(165 180 252);
}

.dark .ai-chat-panel .ai-message .message-content--rich a:hover {
  color: rgb(199 210 254);
}

.ai-chat-panel .ai-message .message-content--rich table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.88em;
}

.ai-chat-panel .ai-message .message-content--rich th,
.ai-chat-panel .ai-message .message-content--rich td {
  border: 1px solid var(--crm-slate-200);
  padding: 6px 10px;
  text-align: left;
}

.dark .ai-chat-panel .ai-message .message-content--rich th,
.dark .ai-chat-panel .ai-message .message-content--rich td {
  border-color: var(--crm-gray-600);
}

.ai-chat-panel .ai-message .message-content--rich th {
  background: var(--crm-slate-100);
  font-weight: 600;
}

.dark .ai-chat-panel .ai-message .message-content--rich th {
  background: rgb(30 41 59 / 0.85);
}


.ai-chat-panel .ai-chat-composer-surface.input-area {
  padding: 12px 16px 10px;
  background: transparent;
  border-top: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: box-shadow 0.2s, background 0.2s;
}

.ai-chat-panel .ai-chat-composer-surface.ai-chat-composer-surface--dropping {
  background: rgb(139 92 246 / 0.06);
  box-shadow: inset 0 0 0 2px rgb(139 92 246 / 0.35);
  border-radius: 0 0 20px 20px;
}

.dark .ai-chat-panel .ai-chat-composer-surface.ai-chat-composer-surface--dropping {
  background: rgb(99 102 241 / 0.12);
}

.ai-chat-panel .ai-chat-composer-flash {
  font-size: 0.78rem;
  line-height: 1.35;
  color: #b45309;
  padding: 4px 2px 0;
}

.dark .ai-chat-panel .ai-chat-composer-flash {
  color: #fbbf24;
}

.ai-chat-panel .ai-chat-attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-chat-panel .ai-chat-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--crm-slate-100);
  border: 1px solid var(--crm-gray-200);
  color: var(--crm-gray-800);
}

.dark .ai-chat-panel .ai-chat-attachment-chip {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(148, 163, 184, 0.3);
  color: #e2e8f0;
}

.ai-chat-panel .ai-chat-attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12rem;
}

.ai-chat-panel .ai-chat-attachment-chip-meta {
  font-size: 0.68rem;
  color: var(--crm-gray-500);
  flex-shrink: 0;
}

.dark .ai-chat-panel .ai-chat-attachment-chip-meta {
  color: rgba(148, 163, 184, 0.85);
}

.ai-chat-panel .ai-chat-attachment-chip-remove {
  -webkit-appearance: none !important;
  appearance: none !important;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--crm-gray-500);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-panel .ai-chat-attachment-chip-remove:hover {
  background: rgb(0 0 0 / 0.06);
  color: var(--crm-gray-800);
}

.dark .ai-chat-panel .ai-chat-attachment-chip-remove:hover {
  background: rgb(255 255 255 / 0.08);
  color: #fff;
}

.ai-chat-panel .ai-chat-composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-panel .ai-chat-composer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ai-chat-panel .ai-chat-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--crm-gray-500);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-appearance: none !important;
  appearance: none !important;
  touch-action: manipulation;
}

.dark .ai-chat-panel .ai-chat-icon-btn {
  color: rgba(203, 213, 225, 0.85);
}

.ai-chat-panel .ai-chat-icon-btn--ghost:hover:not(:disabled) {
  background: var(--crm-slate-100);
  color: var(--crm-primary-600);
  border-color: var(--crm-gray-200);
}

.dark .ai-chat-panel .ai-chat-icon-btn--ghost:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.65);
  border-color: rgba(148, 163, 184, 0.25);
  color: #c4b5fd;
}

.ai-chat-panel .ai-chat-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-chat-panel #aiChatInput {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--crm-gray-300);
  border-radius: 22px;
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
  color: var(--crm-gray-900);
}

.dark .ai-chat-panel #aiChatInput {
  background: var(--crm-gray-900);
  border-color: var(--crm-gray-600);
  color: var(--crm-gray-100);
}

.ai-chat-panel #aiChatInput::placeholder {
  color: var(--crm-gray-400);
}

.ai-chat-panel #aiChatInput:focus {
  border-color: var(--crm-primary-500);
  box-shadow: 0 0 0 2px rgb(139 92 246 / 0.22);
}

.ai-chat-panel .ai-chat-send-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 14px;
  /* Маркер bg-ai-chat-send в classList отключает tailwind-compat reset (background-image: none) */
  background-color: var(--crm-primary-600, #7c3aed);
  background-image: linear-gradient(145deg, var(--crm-primary-500) 0%, var(--crm-primary-600, #7c3aed) 100%);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
  -webkit-appearance: none !important;
  appearance: none !important;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgb(124 58 237 / 0.35);
}

.ai-chat-panel .ai-chat-send-btn svg {
  display: block;
  flex-shrink: 0;
  color: #fff;
}

.ai-chat-panel .ai-chat-send-btn:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.ai-chat-panel .ai-chat-send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.ai-chat-panel .ai-chat-send-btn:disabled {
  background: var(--crm-gray-400);
  cursor: not-allowed;
  opacity: 0.75;
  box-shadow: none;
  transform: none;
}

.dark .ai-chat-panel .ai-chat-send-btn:disabled {
  background: var(--crm-gray-600);
}

.ai-chat-panel .ai-chat-loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--crm-slate-200);
  border-top: 2px solid var(--crm-primary-500);
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 8px;
  animation: ai-chat-spin 1s linear infinite;
}

.dark .ai-chat-panel .ai-chat-loading {
  border-color: var(--crm-gray-600);
  border-top-color: var(--crm-primary-400);
}

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

@keyframes ai-chat-fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chat-panel .error-message {
  background: var(--crm-red-100);
  color: var(--crm-red-700);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  border: 1px solid rgb(239 68 68 / 0.25);
}

.dark .ai-chat-panel .error-message {
  background: rgb(127 29 29 / 0.35);
  color: #fecaca;
  border-color: rgb(248 113 113 / 0.3);
}

/* Список чатов + основная колонка */
.ai-chat-panel .ai-chat-layout {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 1100px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  max-height: var(--ai-chat-panel-height);
}

.ai-chat-panel .ai-chat-sidebar {
  width: 232px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 20px;
  border: 1px solid var(--crm-gray-200);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  max-height: var(--ai-chat-panel-height);
  overflow: hidden;
}

.dark .ai-chat-panel .ai-chat-sidebar {
  background: var(--crm-gray-800);
  border-color: var(--crm-gray-700);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.ai-chat-panel .ai-chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--crm-gray-200);
}

.dark .ai-chat-panel .ai-chat-sidebar-head {
  border-bottom-color: var(--crm-gray-700);
}

.ai-chat-panel .ai-chat-sidebar-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--crm-gray-600);
}

.dark .ai-chat-panel .ai-chat-sidebar-title {
  color: var(--crm-gray-400);
}

.ai-chat-panel .ai-chat-new-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: var(--crm-primary-500);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  font-weight: 600;
}

.ai-chat-panel .ai-chat-new-btn:hover {
  background: var(--crm-primary-600);
}

.ai-chat-panel .ai-chat-conversation-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.ai-chat-panel .ai-chat-conv-item {
  margin-bottom: 2px;
}

.ai-chat-panel .ai-chat-conv-row {
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 48px;
  padding: 2px;
  border-radius: 14px;
  transition:
    background 0.22s ease,
    box-shadow 0.22s ease;
}

.ai-chat-panel .ai-chat-conv-item:hover .ai-chat-conv-row {
  background: rgb(15 23 42 / 0.04);
}

.dark .ai-chat-panel .ai-chat-conv-item:hover .ai-chat-conv-row {
  background: rgb(255 255 255 / 0.05);
}

.ai-chat-panel .ai-chat-conv-item.is-active .ai-chat-conv-row {
  background: linear-gradient(135deg, rgb(99 102 241 / 0.11), rgb(139 92 246 / 0.08));
  box-shadow:
    inset 0 0 0 1px rgb(99 102 241 / 0.22),
    0 1px 2px rgb(99 102 241 / 0.06);
}

.dark .ai-chat-panel .ai-chat-conv-item.is-active .ai-chat-conv-row {
  background: linear-gradient(135deg, rgb(99 102 241 / 0.18), rgb(139 92 246 / 0.1));
  box-shadow:
    inset 0 0 0 1px rgb(165 180 252 / 0.25),
    0 1px 3px rgb(0 0 0 / 0.2);
}

.ai-chat-panel .ai-chat-conv-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 8px 4px 8px 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: color 0.15s ease;
}

.ai-chat-panel .ai-chat-conv-delete {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 2px 0 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--crm-gray-400);
  cursor: pointer;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    opacity 0.2s ease,
    transform 0.18s ease;
}

.ai-chat-panel .ai-chat-conv-delete-icon {
  display: block;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .ai-chat-panel .ai-chat-conv-delete {
    opacity: 0;
    transform: scale(0.92);
  }

  .ai-chat-panel .ai-chat-conv-item:hover .ai-chat-conv-delete,
  .ai-chat-panel .ai-chat-conv-delete:focus-visible {
    opacity: 1;
    transform: scale(1);
  }

  .ai-chat-panel .ai-chat-conv-item.is-active .ai-chat-conv-delete {
    opacity: 0.55;
    transform: scale(1);
  }

  .ai-chat-panel .ai-chat-conv-item.is-active:hover .ai-chat-conv-delete {
    opacity: 1;
  }
}

@media (hover: none), (pointer: coarse) {
  .ai-chat-panel .ai-chat-conv-delete {
    opacity: 0.45;
  }

  .ai-chat-panel .ai-chat-conv-item.is-active .ai-chat-conv-delete {
    opacity: 0.65;
  }
}

.ai-chat-panel .ai-chat-conv-delete:hover {
  background: rgb(239 68 68 / 0.1);
  color: var(--crm-red-600);
}

.ai-chat-panel .ai-chat-conv-delete:focus-visible {
  outline: 2px solid rgb(99 102 241 / 0.45);
  outline-offset: 1px;
}

.dark .ai-chat-panel .ai-chat-conv-delete {
  color: var(--crm-gray-500);
}

.dark .ai-chat-panel .ai-chat-conv-delete:hover {
  background: rgb(239 68 68 / 0.18);
  color: #fca5a5;
}

.ai-chat-panel .ai-chat-conv-title {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-panel .ai-chat-conv-meta {
  display: block;
  font-size: 0.7rem;
  opacity: 0.65;
  margin-top: 4px;
}

.ai-chat-panel .ai-chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
}

@media (max-width: 768px) {
  .ai-chat-panel .ai-chat-layout {
    flex-direction: column;
  }
  .ai-chat-panel .ai-chat-sidebar {
    width: 100%;
    max-height: 200px;
  }
}
