/* ============================================================
   ВДСка — AI-виджет поддержки v2 (p40)
   Дизайн: индиго-градиент бренда, тёмная шапка, пузыри,
   пульсирующая кнопка, перетаскивание, тёмная тема сайта.
   Всё скоупится через #aiw-root.
   ============================================================ */
#aiw-root, #aiw-root * { box-sizing: border-box; }
#aiw-root { font: inherit; z-index: 2147483000; }

/* ---------- кнопка-лаунчер ---------- */
#aiw-root .aiw-fab {
  position: fixed; right: 16px; bottom: 84px;
  width: 60px; height: 60px; border: none; border-radius: 50%;
  background: linear-gradient(135deg, #818cf8 0%, #4f46e5 55%, #4338ca 100%);
  box-shadow: 0 8px 26px rgba(67, 56, 202, .45);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .16s ease, box-shadow .2s ease, opacity .15s ease;
  touch-action: none; -webkit-user-select: none; user-select: none;
  animation: aiwPulse 3.2s ease-out infinite;
}
#aiw-root .aiw-fab:hover { transform: scale(1.07); box-shadow: 0 10px 32px rgba(67, 56, 202, .55); }
#aiw-root .aiw-fab:active { transform: scale(.97); }
#aiw-root .aiw-fab.aiw-dragging { animation: none; transition: none; cursor: grabbing; transform: scale(1.1); box-shadow: 0 14px 40px rgba(67, 56, 202, .6); z-index: 2147483001; }
#aiw-root .aiw-fab.aiw-fab-open { animation: none; }
#aiw-root .aiw-fab svg { transition: transform .2s ease; pointer-events: none; }
#aiw-root .aiw-fab.aiw-fab-open svg { transform: rotate(90deg); }
@keyframes aiwPulse {
  0%   { box-shadow: 0 8px 26px rgba(67,56,202,.45), 0 0 0 0 rgba(99,102,241,.42); }
  70%  { box-shadow: 0 8px 26px rgba(67,56,202,.45), 0 0 0 15px rgba(99,102,241,0); }
  100% { box-shadow: 0 8px 26px rgba(67,56,202,.45), 0 0 0 0 rgba(99,102,241,0); }
}
/* зелёный бейдж «онлайн» */
#aiw-root .aiw-fab-badge {
  position: absolute; right: 2px; bottom: 2px; width: 15px; height: 15px;
  border-radius: 50%; background: #22c55e; border: 2.5px solid #fff;
  pointer-events: none;
}

/* ---------- тизер «есть вопрос?» ---------- */
#aiw-root .aiw-teaser {
  position: fixed; max-width: 230px; padding: 10px 32px 10px 14px;
  background: #0f172a; color: #e2e8f0; font-size: 13px; line-height: 1.4;
  border-radius: 14px 14px 14px 4px; box-shadow: 0 10px 30px rgba(15, 23, 42, .35);
  cursor: pointer; opacity: 0; transform: translateY(6px) scale(.96); pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#aiw-root .aiw-teaser.aiw-show { opacity: 1; transform: none; pointer-events: auto; }
#aiw-root .aiw-teaser-close {
  position: absolute; top: 4px; right: 6px; width: 20px; height: 20px;
  border: none; background: transparent; color: #94a3b8; font-size: 14px;
  line-height: 1; cursor: pointer; border-radius: 6px;
}
#aiw-root .aiw-teaser-close:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }

/* ---------- панель ---------- */
#aiw-root .aiw-panel {
  position: fixed; width: 380px; max-width: calc(100vw - 24px); height: 560px;
  max-height: min(74vh, 640px);
  background: #fff; border: 1px solid #e7eaf3; border-radius: 20px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .32);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; pointer-events: none; transform: translateY(14px) scale(.97);
  transition: opacity .18s ease, transform .18s ease;
  transform-origin: bottom right;
}
#aiw-root .aiw-panel.aiw-open { opacity: 1; pointer-events: auto; transform: none; }

/* шапка */
#aiw-root .aiw-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px; flex: 0 0 auto; color: #fff;
  background: linear-gradient(130deg, #1e1b4b 0%, #312e81 60%, #4338ca 135%);
}
#aiw-root .aiw-head-l { display: flex; align-items: center; gap: 11px; }
#aiw-root .aiw-ava {
  width: 40px; height: 40px; border-radius: 13px; flex: 0 0 auto;
  background: linear-gradient(135deg, #818cf8, #4f46e5);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
#aiw-root .aiw-title { font-weight: 700; font-size: 15px; line-height: 1.25; }
#aiw-root .aiw-sub { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 6px; margin-top: 1px; }
#aiw-root .aiw-dot { width: 7px; height: 7px; border-radius: 50%; background: #34d399; display: inline-block; animation: aiwDot 2s ease infinite; }
@keyframes aiwDot { 0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,.5);} 50% { box-shadow: 0 0 0 4px rgba(52,211,153,0);} }
#aiw-root .aiw-close {
  background: rgba(255,255,255,.14); color: #fff; border: none; width: 30px; height: 30px;
  border-radius: 9px; font-size: 18px; line-height: 1; cursor: pointer;
  transition: background .15s ease;
}
#aiw-root .aiw-close:hover { background: rgba(255,255,255,.28); }

/* сообщения */
#aiw-root .aiw-msgs { flex: 1 1 auto; overflow-y: auto; padding: 14px; background: #f5f6fa; scrollbar-width: thin; scrollbar-color: #c7cde0 transparent; }
#aiw-root .aiw-msgs::-webkit-scrollbar { width: 6px; }
#aiw-root .aiw-msgs::-webkit-scrollbar-thumb { background: #c7cde0; border-radius: 3px; }
#aiw-root .aiw-m {
  max-width: 84%; padding: 9px 13px; border-radius: 16px; margin: 0 0 10px;
  font-size: 14px; line-height: 1.5; word-wrap: break-word; white-space: pre-wrap;
  animation: aiwIn .22s ease;
}
@keyframes aiwIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
#aiw-root .aiw-bot { background: #fff; color: #1c2333; border: 1px solid #e6e9f4; border-bottom-left-radius: 5px; box-shadow: 0 1px 2px rgba(14,21,38,.06); }
#aiw-root .aiw-me { background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; margin-left: auto; border-bottom-right-radius: 5px; box-shadow: 0 2px 8px rgba(79,70,229,.3); }
#aiw-root .aiw-typing { display: flex; gap: 4px; align-items: center; padding: 13px 15px; }
#aiw-root .aiw-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #93a1bd;
  animation: aiwBlink 1.2s infinite ease-in-out;
}
#aiw-root .aiw-typing span:nth-child(2) { animation-delay: .2s; }
#aiw-root .aiw-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aiwBlink { 0%, 70%, 100% { opacity: .35; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

/* быстрые вопросы */
#aiw-root .aiw-chips { display: none; flex-wrap: wrap; gap: 7px; padding: 10px 14px 4px; background: #fff; border-top: 1px solid #eef0f6; }
#aiw-root .aiw-chip {
  border: 1px solid #d9def0; background: #fff; color: #2a3554;
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
#aiw-root .aiw-chip:hover { border-color: #6366f1; background: #eef2ff; color: #4f46e5; }

/* ввод */
#aiw-root .aiw-inputrow { display: flex; gap: 8px; padding: 10px 14px 12px; background: #fff; }
#aiw-root #aiw-input {
  flex: 1 1 auto; min-width: 0; border: 1px solid #d9def0; border-radius: 14px; padding: 10px 14px;
  font-size: 14px; outline: none; transition: border-color .15s ease, box-shadow .15s ease; background: #fff; color: #1c2333;
}
#aiw-root #aiw-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.16); }
#aiw-root #aiw-send {
  width: 44px; height: 44px; flex: 0 0 auto; border: none; border-radius: 50%; cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(79,70,229,.35);
  transition: transform .15s ease, opacity .15s ease;
}
#aiw-root #aiw-send:hover { transform: scale(1.06); }
#aiw-root #aiw-send.aiw-busy { opacity: .55; cursor: wait; transform: none; }

/* подвал */
#aiw-root .aiw-foot {
  padding: 7px 14px 9px; font-size: 11.5px; color: #8a94ac; background: #fff;
  border-top: 1px solid #eef0f6; text-align: center;
}
#aiw-root .aiw-foot a { color: #4f46e5; text-decoration: none; }
#aiw-root .aiw-foot a:hover { text-decoration: underline; }

/* ---------- тёмная тема сайта ---------- */
[data-bs-theme="dark"] #aiw-root .aiw-panel { background: #10192e; border-color: #243149; }
[data-bs-theme="dark"] #aiw-root .aiw-msgs { background: #0b1220; }
[data-bs-theme="dark"] #aiw-root .aiw-bot { background: #182238; color: #e2e8f0; border-color: #243149; }
[data-bs-theme="dark"] #aiw-root .aiw-chips { background: #10192e; border-top-color: #243149; }
[data-bs-theme="dark"] #aiw-root .aiw-chip { background: #182238; border-color: #2c3a58; color: #cbd5e1; }
[data-bs-theme="dark"] #aiw-root .aiw-chip:hover { border-color: #6366f1; background: #1e293b; color: #a5b4fc; }
[data-bs-theme="dark"] #aiw-root .aiw-inputrow, [data-bs-theme="dark"] #aiw-root .aiw-foot { background: #10192e; border-top-color: #243149; }
[data-bs-theme="dark"] #aiw-root #aiw-input { background: #0b1220; border-color: #2c3a58; color: #e2e8f0; }
[data-bs-theme="dark"] #aiw-root .aiw-fab-badge { border-color: #0b1220; }

/* ---------- мобильный: bottom-sheet ---------- */
@media (max-width: 480px) {
  #aiw-root .aiw-panel {
    left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important;
    width: 100%; height: 82vh; max-height: 82vh;
    border-radius: 18px 18px 0 0; transform-origin: bottom center;
  }
  #aiw-root .aiw-fab { width: 54px; height: 54px; }
  /* открытая панель — bottom-sheet на весь экран: кнопку и тизер прячем */
  #aiw-root .aiw-panel.aiw-open ~ .aiw-fab,
  #aiw-root .aiw-panel.aiw-open ~ .aiw-teaser { opacity: 0 !important; pointer-events: none; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #aiw-root .aiw-fab { animation: none; }
  #aiw-root .aiw-m, #aiw-root .aiw-dot { animation: none; }
}
