/* ============================================================
   Виджет AI-поддержки
   Стили изолированы префиксом .efg-chat, чтобы не пересекаться
   с остальной вёрсткой.
   ============================================================ */

.efg-chat {
  position: fixed;
  right: max(clamp(12px, 3vw, 28px), env(safe-area-inset-right));
  bottom: max(clamp(12px, 3vw, 28px), env(safe-area-inset-bottom));
  z-index: 200;
  font-family: var(--font);
}

/* ---------- Кнопка запуска ---------- */
.efg-chat__launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--purple-500);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(23, 11, 33, .32);
  transition: transform .18s ease, background-color .18s ease;
}
.efg-chat__launcher:hover { transform: translateY(-2px); background: var(--purple-400); }
.efg-chat__launcher svg { width: 24px; height: 24px; flex: none; }
.efg-chat__launcher[hidden] { display: none; }

.efg-chat__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--lime);
  flex: none;
}

@media (max-width: 520px) {
  .efg-chat__launcher {
    width: auto;
    max-width: calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    height: 48px;
    padding: 0 15px;
    gap: 8px;
    font-size: 13.5px;
    justify-content: center;
  }
  .efg-chat__launcher svg { width: 20px; height: 20px; }
  .efg-chat__dot { width: 7px; height: 7px; }
}

html[data-nav-open] .efg-chat { visibility: hidden; pointer-events: none; }

/* ---------- Панель ---------- */
.efg-chat__panel {
  position: fixed;
  right: max(clamp(12px, 3vw, 28px), env(safe-area-inset-right));
  bottom: max(clamp(12px, 3vw, 28px), env(safe-area-inset-bottom));
  width: min(390px, calc(100vw - 24px));
  height: min(600px, calc(100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(23, 11, 33, .35);
  overflow: hidden;
  border: 1px solid var(--line);
}
.efg-chat__panel[hidden] { display: none; }

.efg-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 16px 20px;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-800));
  color: #fff;
}
.efg-chat__avatar {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  display: grid; place-items: center;
}
.efg-chat__avatar svg { width: 22px; height: 22px; }
.efg-chat__title { font-size: 15px; font-weight: 500; margin: 0; }
.efg-chat__subtitle { font-size: 12.5px; color: var(--lilac-300); margin: 0; display: flex; align-items: center; gap: 6px; }
.efg-chat__subtitle::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--lime);
}
.efg-chat__close {
  margin-left: auto;
  width: 36px; height: 36px;
  border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 20px; line-height: 1;
  cursor: pointer;
}
.efg-chat__close:hover { background: rgba(255, 255, 255, .22); }

/* ---------- Лента сообщений ---------- */
.efg-chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--lilac-100);
  scrollbar-width: thin;
}

.efg-chat__msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.efg-chat__msg--bot {
  align-self: flex-start;
  background: var(--paper);
  color: var(--ink);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.efg-chat__msg--user {
  align-self: flex-end;
  background: var(--purple-500);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.efg-chat__msg--error { background: #FDECEC; color: #8E2020; align-self: flex-start; }

.efg-chat__typing { display: inline-flex; gap: 4px; align-items: center; }
.efg-chat__typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--purple-300);
  animation: efg-blink 1.2s infinite ease-in-out;
}
.efg-chat__typing i:nth-child(2) { animation-delay: .18s; }
.efg-chat__typing i:nth-child(3) { animation-delay: .36s; }
@keyframes efg-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Быстрые вопросы ---------- */
.efg-chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 0;
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.efg-chat__chip {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.efg-chat__chip:hover { background: var(--lilac-100); }

/* ---------- Ввод ---------- */
.efg-chat__form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 16px 14px;
  background: var(--paper);
}
.efg-chat__input {
  flex: 1;
  font: inherit;
  font-size: 15px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: none;
  max-height: 120px;
  color: var(--ink);
  background: var(--paper);
}
.efg-chat__input:focus { outline: none; border-color: var(--purple-500); box-shadow: 0 0 0 3px rgba(100, 49, 141, .14); }
.efg-chat__send {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 14px;
  background: var(--purple-500);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
}
.efg-chat__send:hover:not([disabled]) { background: var(--purple-400); }
.efg-chat__send[disabled] { opacity: .5; cursor: not-allowed; }
.efg-chat__send svg { width: 20px; height: 20px; }

.efg-chat__foot {
  padding: 0 16px 14px;
  background: var(--paper);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}
.efg-chat__foot a { color: var(--purple-500); }

/* ---------- Без JS ---------- */
.efg-chat__nojs {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  font-size: 13.5px;
  max-width: 300px;
  box-shadow: var(--shadow-md);
}

@media (max-width: 520px) {
  .efg-chat__panel {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right));
    height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 18px;
  }
}
