/* ═══════════════════════════════════════════════════════════════════
   ДЕЛЕКТУС — ИИ-консультант по каталогу (виджет чата)
   Фичефлаг: site_settings.search.ai_agent_enabled (default OFF).
   Панель — drawer по образцу #watchlist-panel (.cabinet-overlay/.cabinet-panel).
   ═══════════════════════════════════════════════════════════════════ */

.aic-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  --aic-accent: #6C4FD6;
  --aic-accent-soft: rgba(108, 79, 214, 0.12);
}
[data-theme="dark"] .aic-shell {
  --aic-accent: #9B8AFB;
  --aic-accent-soft: rgba(155, 138, 251, 0.16);
}
#ai-chat-panel .aic-shell {
  font-family: 'Segoe UI Variable', 'Segoe UI', 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.aic-shell__header {
  flex-shrink: 0;
}
.aic-shell__mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--aic-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(108, 79, 214, 0.35);
}
[data-theme="dark"] .aic-shell__mark {
  box-shadow: 0 1px 4px rgba(155, 138, 251, 0.32);
}
.aic-shell__mark svg {
  width: 17px;
  height: 17px;
}
.aic-shell__titles {
  flex: 1;
  min-width: 0;
}
.aic-shell__title {
  line-height: 1.2;
}
.aic-shell__subtitle {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.3;
}

/* ── Тело панели: лента / композер / футер ── */
.aic-shell__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.aic-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px 10px;
}
/* Square / Circle / Win11 по умолчанию: подложка ленты = --bg (как у #watchlist-panel) */
html[data-theme="light"][data-style="square"] #ai-chat-panel .aic-messages,
html[data-theme="light"][data-style="circle"] #ai-chat-panel .aic-messages,
html[data-theme="light"]:not([data-style]) #ai-chat-panel .aic-messages,
html[data-theme="dark"][data-style="square"] #ai-chat-panel .aic-messages,
html[data-theme="dark"][data-style="circle"] #ai-chat-panel .aic-messages,
html[data-theme="dark"]:not([data-style]) #ai-chat-panel .aic-messages {
  background: var(--bg);
}

/* ── Пустое состояние: приветствие + чипы-подсказки ── */
.aic-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 34px 16px 10px;
  gap: 10px;
}
.aic-empty__icon {
  width: 40px;
  height: 40px;
  color: var(--aic-accent);
}
.aic-empty__icon svg {
  width: 100%;
  height: 100%;
}
.aic-empty__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.aic-empty__text {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 380px;
}
.aic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
}
.aic-chip {
  border: 1px solid var(--card-border);
  background: var(--row-hover);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 100%;
}
.aic-chip:hover {
  background: var(--aic-accent-soft);
  border-color: var(--aic-accent);
}
.aic-chip:focus-visible {
  outline: 2px solid var(--aic-accent);
  outline-offset: 2px;
}

/* ── Тизер для гостя (ТЗ §6.7, V1: гостю — приглашение войти, не чат) ──
   Переключатель — .aic-shell--guest на #ai-chat-panel .aic-shell (ai-chat.js).
   Композер/чипы прячем целиком: лента (.aic-messages, содержит и чипы) и
   композер скрыты через display:none + textarea/кнопка задизейблены в JS. */
.aic-teaser {
  display: none;
}
.aic-shell--guest .aic-messages,
.aic-shell--guest .aic-composer,
.aic-shell--guest .aic-footer {
  display: none;
}
.aic-shell--guest .aic-teaser {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  min-height: 0;
  justify-content: center;
  padding: 34px 20px calc(34px + env(safe-area-inset-bottom, 0px));
  gap: 12px;
}
.aic-teaser__icon {
  width: 40px;
  height: 40px;
  color: var(--aic-accent);
}
.aic-teaser__icon svg {
  width: 100%;
  height: 100%;
}
.aic-teaser__text {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 340px;
}
.aic-teaser__btn {
  margin-top: 6px;
  border: none;
  background: var(--aic-accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.aic-teaser__btn:hover {
  background: color-mix(in srgb, var(--aic-accent) 88%, #000);
}
.aic-teaser__btn:focus-visible {
  outline: 2px solid var(--aic-accent);
  outline-offset: 2px;
}

/* ── Сообщения ── */
.aic-msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.aic-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}
.aic-msg--agent,
.aic-msg--error {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 96%;
  width: 100%;
}

.aic-msg__bubble {
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 9px 13px;
  border-radius: 14px;
}
.aic-msg__bubble:empty {
  display: none;
}
.aic-msg--user .aic-msg__bubble {
  background: var(--aic-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
/* Тёмная тема: акцент там намеренно светлее (#9B8AFB), и белый текст на нём даёт
   контраст 2.83 — ниже читаемого порога (замер в браузере 28.07.2026). Пузырю
   пользователя даём более глубокий пурпур (белый на нём ≈6:1); акцент для иконок,
   ссылок и фокуса остаётся прежним — там он лежит на тёмном фоне и читается. */
[data-theme="dark"] .aic-msg--user .aic-msg__bubble {
  background: #6849C9;
}
.aic-msg--agent .aic-msg__bubble {
  background: var(--row-hover);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-bottom-left-radius: 4px;
}
.aic-msg--error .aic-msg__bubble {
  background: rgba(255, 59, 48, 0.1);
  border: 1px solid rgba(255, 59, 48, 0.3);
  color: #c62828;
  border-bottom-left-radius: 4px;
}
[data-theme="dark"] .aic-msg--error .aic-msg__bubble {
  background: rgba(255, 59, 48, 0.14);
  border-color: rgba(255, 59, 48, 0.36);
  color: #ffb4ae;
}

.aic-msg__status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  background: var(--row-hover);
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  font-size: 12.5px;
  margin-bottom: 2px;
}
.aic-msg__status[hidden] {
  display: none;
}
.aic-spinner {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.aic-spinner i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-tertiary);
  display: block;
  font-style: normal;
  animation: aic-bounce 1.1s ease-in-out infinite;
}
.aic-spinner i:nth-child(2) { animation-delay: 0.15s; }
.aic-spinner i:nth-child(3) { animation-delay: 0.3s; }
@keyframes aic-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .aic-spinner i { animation: none; opacity: 0.8; }
}

/* ── Карточки позиций под ответом ── */
.aic-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}
.aic-item {
  box-sizing: border-box;
  border: 1px solid var(--card-border);
  background: var(--card-bg, var(--bg));
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.aic-item:hover {
  border-color: rgba(128, 128, 128, 0.28);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .aic-item:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.aic-item__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.aic-item__name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.aic-item__pn {
  font-size: 11px;
  font-family: ui-monospace, Menlo, 'SF Mono', monospace;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}
.aic-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 11px;
  color: var(--text-tertiary);
}
.aic-item__stock {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 12px;
}
.aic-item__price {
  font-weight: 700;
  color: #2f8f56;
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .aic-item__price {
  color: #6bbd86;
}
.aic-item__qty,
.aic-item__transit {
  color: var(--text-secondary);
}
.aic-item__open {
  align-self: flex-start;
  margin-top: 4px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--aic-accent);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.aic-item__open:hover {
  background: var(--aic-accent-soft);
  border-color: var(--aic-accent);
}
.aic-item__open:focus-visible {
  outline: 2px solid var(--aic-accent);
  outline-offset: 2px;
}

/* ── Композер ── */
.aic-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}
.aic-composer__input {
  flex: 1;
  resize: none;
  min-height: 36px;
  max-height: 140px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s;
}
.aic-composer__input:focus {
  border-color: var(--aic-accent);
}
.aic-composer__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.aic-composer__input::placeholder {
  color: var(--text-tertiary);
}
.aic-composer__send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--aic-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.aic-composer__send svg {
  width: 16px;
  height: 16px;
}
.aic-composer__send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--aic-accent) 88%, #000);
}
.aic-composer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.aic-composer__send:focus-visible {
  outline: 2px solid var(--aic-accent);
  outline-offset: 2px;
}

/* ── Футер: квота + дисклеймер ── */
.aic-footer {
  padding: 2px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.aic-quota {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}
.aic-quota[hidden] {
  display: none;
}
.aic-disclaimer {
  font-size: 10.5px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* ── Style packs ── */
[data-style="square"] .aic-shell__mark { border-radius: 6px; }
[data-style="square"] .aic-item { border-radius: 6px; }
[data-style="square"] .aic-msg__bubble,
[data-style="square"] .aic-msg__status { border-radius: 8px; }
[data-style="square"] .aic-composer__input,
[data-style="square"] .aic-composer__send { border-radius: 6px; }
[data-style="square"] .aic-teaser__btn { border-radius: 6px; }
[data-style="circle"] .aic-shell__mark { border-radius: 10px; }
[data-style="circle"] .aic-item { border-radius: 12px; }
[data-style="circle"] .aic-composer__input,
[data-style="circle"] .aic-composer__send { border-radius: 12px; }
[data-style="circle"] .aic-teaser__btn { border-radius: 12px; }

@media (prefers-reduced-motion: reduce) {
  .aic-item,
  .aic-chip,
  .aic-composer__send,
  .aic-composer__input,
  .aic-teaser__btn {
    transition: none;
  }
}

/* ≤600: как #watchlist-panel — контент не клипится у home-indicator */
@media (max-width: 600px) {
  #ai-chat-panel .aic-messages { padding: 14px 14px 8px; }
  #ai-chat-panel .aic-composer { padding: 8px 14px; }
  #ai-chat-panel .aic-footer { padding: 2px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
  #ai-chat-panel .aic-teaser { padding: 28px 14px calc(28px + env(safe-area-inset-bottom, 0px)); }
  .aic-msg { max-width: 100%; }
  .aic-msg--agent, .aic-msg--error { max-width: 100%; }
}
