/* ai-widget.css - global (не scoped Astro) для совместимости с динамически создаваемыми
   через ai-assistant.js элементами. Astro scoped CSS добавляет [data-astro-cid-...] селекторы
   которые не матчатся на JS-созданных div'ах - поэтому держим здесь как plain CSS. */

.ai-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 101;
}

/* FAB */
.ai-widget__fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(22, 163, 74, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: transform 200ms ease, box-shadow 200ms ease;
  position: relative;
}
.ai-widget__fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(22, 163, 74, 0.45), 0 3px 8px rgba(0, 0, 0, 0.15);
}
.ai-widget__fab--bounce {
  animation: ai-fab-bounce 0.6s ease-in-out 0s 3;
}
@keyframes ai-fab-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.08); }
}
.ai-widget__fab:focus-visible {
  outline: 2px solid #16a34a;
  outline-offset: 4px;
}
.ai-widget__fab-icon { display: block; }
.ai-widget__fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(22, 163, 74, 0.5);
  animation: ai-pulse 2.4s ease-out infinite;
}
@keyframes ai-pulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Panel */
.ai-widget__panel {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  width: 340px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 140px);
  background: #fafaf9;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: ai-panel-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes ai-panel-in {
  from { opacity: 0; transform: scale(0.85) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ai-widget[data-state="closed"] .ai-widget__panel { display: none; }

.ai-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: linear-gradient(135deg, rgba(22,163,74,0.08), rgba(22,163,74,0));
}
.ai-widget__title-wrap { display: flex; align-items: center; gap: 8px; }
.ai-widget__title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
  animation: ai-online-blink 2.4s ease-in-out infinite;
}
@keyframes ai-online-blink { 50% { opacity: 0.5; } }
.ai-widget__title { font-size: 14px; font-weight: 600; color: #18181b; margin: 0; }
.ai-widget__close {
  background: transparent; border: none; cursor: pointer;
  color: #71717a; width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background 150ms ease;
}
.ai-widget__close:hover { background: rgba(0, 0, 0, 0.05); }

.ai-widget__intro {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}
.ai-widget__intro p {
  font-size: 13px; line-height: 1.45; color: #52525b; margin: 0 0 10px;
}
.ai-widget__quick { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-widget__chip {
  background: rgba(22, 163, 74, 0.08);
  color: #15803d;
  border: 1px solid rgba(22, 163, 74, 0.2);
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 150ms ease;
}
.ai-widget__chip:hover { background: rgba(22, 163, 74, 0.15); }

/* Messages */
.ai-widget__messages {
  list-style: none;
  margin: 0;
  padding: 12px 16px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Row - flex-контейнер для bubble + avatar */
.ai-widget__row {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.ai-widget__row--user { align-items: flex-end; }
.ai-widget__row--ai   { align-items: flex-start; }
.ai-widget__row--error{ align-items: flex-start; }

/* Sender label "Менеджер" / "Вы" над сообщением (стандартный паттерн Intercom/Drift) */
.ai-widget__sender {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #52525b;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}
.ai-widget__row--user .ai-widget__sender { padding-right: 4px; }
.ai-widget__row--ai .ai-widget__sender   { padding-left: 4px; }
.ai-widget__sender-name { color: #15803d; }
.ai-widget__row--user .ai-widget__sender-name { color: #16a34a; }

/* Avatar в kit-form (логотип GrizzlyLab "Г") */
.ai-widget__avatar {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(22, 163, 74, 0.3);
  font-family: 'Manrope', system-ui, sans-serif;
}

/* Bubble */
.ai-widget__msg {
  max-width: 88%;
  padding: 10px 13px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* USER: brand-зелёный bubble справа, белый текст, "хвостик" в правый нижний */
.ai-widget__msg--user {
  background: #16a34a;
  color: #ffffff;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.18);
}

/* AI: белый bubble слева, ТЁМНЫЙ нейтральный текст (Intercom/Drift паттерн).
   Зелёный остаётся только для брендинга: avatar, sender label, bullets, user-bubble.
   Контраст #14110b on #ffffff = 19.7:1 (AAA). */
.ai-widget__msg--ai {
  background: #ffffff;
  color: #14110b;
  font-weight: 400;
  border: 1px solid #e7e5e0;
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  position: relative;
}

/* Структурированный AI-ответ: параграфы и bullet-list */
.ai-widget__msg--ai .ai-widget__p {
  margin: 0 0 8px 0;
  line-height: 1.45;
}
.ai-widget__msg--ai .ai-widget__p:last-child { margin-bottom: 0; }
.ai-widget__msg--ai .ai-widget__list {
  list-style: none;
  margin: 0 0 8px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-widget__msg--ai .ai-widget__list:last-child { margin-bottom: 0; }
.ai-widget__msg--ai .ai-widget__list li {
  position: relative;
  padding-left: 16px;
  line-height: 1.4;
  word-break: break-all;
}
.ai-widget__msg--ai .ai-widget__list li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #16a34a;
}
.ai-widget__msg--ai.is-typing::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 1em;
  background: #16a34a;
  margin-left: 3px;
  animation: ai-typing-cursor 0.8s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes ai-typing-cursor { 50% { opacity: 0; } }

.ai-widget__msg--error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 10px 13px;
  max-width: 88%;
  font-size: 13.5px;
  line-height: 1.45;
}

/* Form */
.ai-widget__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: #fafaf9;
}
.ai-widget__input-wrap { flex: 1; display: block; }
.ai-widget__input-wrap textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.4;
  color: #18181b;
  resize: none;
  min-height: 36px;
  max-height: 96px;
  font-family: inherit;
  box-sizing: border-box;
}
.ai-widget__input-wrap textarea:focus {
  outline: none;
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}
.ai-widget__send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #16a34a;
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, transform 150ms ease;
}
.ai-widget__send:hover { background: #15803d; transform: translateY(-1px); }
.ai-widget__send:disabled { background: #a1a1aa; cursor: not-allowed; transform: none; }

.ai-widget__pdn-notice {
  padding: 5px 16px 4px;
  font-size: 11px;
  line-height: 1.4;
  color: #9ca3af;
  margin: 0;
  text-align: center;
  border-top: 1px solid #f3f4f6;
}

.ai-widget__footer-note {
  padding: 6px 16px 10px;
  font-size: 10.5px;
  line-height: 1.4;
  color: #71717a;
  margin: 0;
  text-align: center;
}
.ai-widget__footer-note a { color: #16a34a; }

.ai-widget .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;
}

/* Mobile: panel занимает почти весь экран */
@media (max-width: 480px) {
  .ai-widget__panel {
    width: calc(100vw - 24px);
    bottom: calc(100% + 8px);
    right: -12px;
    height: 70vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-widget__fab-pulse { animation: none; opacity: 0.4; }
  .ai-widget__title-dot { animation: none; }
  .ai-widget__panel    { animation: none; }
}
