/* ============================================================
   СветВода 23 — AI-помощник (виджет чата)
   Демо-режим: ответы из базы знаний сайта.
   Подключение настоящего AI: см. assets/js/ai-chat.js (AI_ENDPOINT)
   ============================================================ */

.svai-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px 14px 16px;
  border: none;
  border-radius: 999px;
  background: var(--primary, #ff8a2a);
  color: #071525;
  font: 700 15px/1 "Manrope", system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(255, 138, 42, 0.35);
  transition: transform 0.18s ease-out, box-shadow 0.18s ease-out, background 0.18s ease-out;
}
.svai-launcher:hover { background: var(--primary-dark, #e67412); transform: translateY(-2px); }
.svai-launcher:active { transform: translateY(0); }
.svai-launcher:focus-visible { outline: 3px solid #3dd6c6; outline-offset: 3px; }
.svai-launcher svg { width: 20px; height: 20px; flex: 0 0 auto; }
.svai-launcher::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 2px solid rgba(255, 138, 42, 0.55);
  animation: svai-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes svai-pulse {
  0%   { transform: scale(1); opacity: 0.8; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}
.svai-launcher.is-hidden { display: none; }

/* ---------- Панель чата ---------- */
.svai-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 901;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  background: #0f2744;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  font-family: "Manrope", system-ui, sans-serif;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.svai-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.svai-panel__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #132f52;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.svai-panel__avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(61, 214, 198, 0.15);
}
.svai-panel__avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.svai-panel__titles { flex: 1; min-width: 0; }
.svai-panel__title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: #eef4ff;
}
.svai-panel__status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  font-size: 12px;
  color: #a8bdd9;
}
.svai-panel__status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3dd6c6;
}
.svai-panel__msgr {
  display: inline-flex;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}
.svai-panel__msgr a {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.15s ease, transform 0.15s ease;
}
.svai-panel__msgr a:hover { background: rgba(255, 255, 255, 0.18); transform: translateY(-1px); }
.svai-panel__msgr svg { width: 17px; height: 17px; display: block; }

/* Прячем плавающую кнопку звонка, пока открыт чат */
body.svai-chat-open .float-bar { display: none; }

.svai-panel__close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #a8bdd9;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease-out, color 0.15s ease-out;
}
.svai-panel__close:hover { background: rgba(255, 255, 255, 0.08); color: #eef4ff; }
.svai-panel__close:focus-visible { outline: 2px solid #3dd6c6; outline-offset: 2px; }

/* ---------- Сообщения ---------- */
.svai-panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.svai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
  word-break: break-word;
}
.svai-msg--bot {
  align-self: flex-start;
  background: #132f52;
  color: #eef4ff;
  border-bottom-left-radius: 4px;
}
.svai-msg--user {
  align-self: flex-end;
  background: var(--primary, #ff8a2a);
  color: #071525;
  font-weight: 600;
  border-bottom-right-radius: 4px;
}
.svai-msg a { color: #3dd6c6; }

/* Индикатор «печатает…» */
.svai-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: #132f52;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.svai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a8bdd9;
  animation: svai-blink 1.2s ease-in-out infinite;
}
.svai-typing span:nth-child(2) { animation-delay: 0.15s; }
.svai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes svai-blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Быстрые подсказки */
.svai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  max-width: 100%;
}
.svai-chip {
  padding: 8px 14px;
  border: 1px solid rgba(61, 214, 198, 0.45);
  border-radius: 999px;
  background: rgba(61, 214, 198, 0.08);
  color: #3dd6c6;
  font: 600 13px/1.2 "Manrope", system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s ease-out, border-color 0.15s ease-out;
}
.svai-chip:hover { background: rgba(61, 214, 198, 0.18); border-color: #3dd6c6; }
.svai-chip:active { transform: scale(0.97); }
.svai-chip:focus-visible { outline: 2px solid #3dd6c6; outline-offset: 2px; }

/* ---------- Ввод ---------- */
.svai-panel__form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: #132f52;
}
.svai-panel__input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: #0f2744;
  color: #eef4ff;
  font: 400 14px/1.4 "Manrope", system-ui, sans-serif;
}
.svai-panel__input::placeholder { color: #a8bdd9; }
.svai-panel__input:focus { outline: none; border-color: #3dd6c6; }
.svai-panel__input:focus-visible { outline: 2px solid #3dd6c6; outline-offset: 1px; }
.svai-panel__send {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 12px;
  background: var(--primary, #ff8a2a);
  color: #071525;
  cursor: pointer;
  transition: background 0.15s ease-out, transform 0.15s ease-out;
}
.svai-panel__send:hover { background: var(--primary-dark, #e67412); }
.svai-panel__send:active { transform: scale(0.95); }
.svai-panel__send:disabled { opacity: 0.45; cursor: not-allowed; }
.svai-panel__send:focus-visible { outline: 2px solid #3dd6c6; outline-offset: 2px; }
.svai-panel__send svg { width: 20px; height: 20px; }

.svai-panel__foot {
  padding: 6px 14px 10px;
  background: #132f52;
  font-size: 11px;
  line-height: 1.4;
  color: #a8bdd9;
  text-align: center;
}

/* ---------- Мобильная версия ---------- */
@media (max-width: 480px) {
  .svai-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .svai-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0));
    padding: 14px 16px;
  }
  .svai-launcher__text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .svai-panel,
  .svai-launcher,
  .svai-typing span { transition: none; animation: none; }
  .svai-launcher::after { animation: none; opacity: 0; }
  .svai-panel__body { scroll-behavior: auto; }
}

/* Автоматическое вступление — выделено жирным курсивом */
.svai-msg--intro { font-weight: 700; font-style: italic; }
