/* ============================================================================
   Чат с менеджером — панель, которую открывает плавающая кнопка справа внизу.

   Отдельный файл, а не дописка в components.css: виджет самостоятельный,
   его проще выключить одной строкой в разметке, если что-то пойдёт не так.
   ========================================================================== */

.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 96px;                 /* над плавающей кнопкой, не поверх неё */
  z-index: 1100;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 140px));
  display: flex;
  flex-direction: column;
  background: var(--color-gray-900, #111827);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
  overflow: hidden;

  /* Скрыт по умолчанию. visibility, а не display: none, — чтобы работал
     переход и панель не «прыгала» при первом открытии. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(.98);
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.chat-widget.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ── Шапка ───────────────────────────────────────────────────────────── */
.chat-widget__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .04);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.chat-widget__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}

.chat-widget__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .2);
}

.chat-widget__close {
  background: none;
  border: 0;
  color: rgba(255, 255, 255, .55);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color .15s ease;
}

.chat-widget__close:hover { color: #fff; }

/* ── Лента сообщений ─────────────────────────────────────────────────── */
.chat-widget__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;        /* модель отвечает абзацами */
  word-break: break-word;
}

.chat-msg--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, .07);
  color: rgba(255, 255, 255, .92);
  border-bottom-left-radius: 6px;
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--color-primary, #2f54eb);
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* Три точки, пока идут два вызова модели. Без них пауза в несколько
   секунд читается как «сломалось». */
.chat-msg--typing {
  display: flex;
  gap: 4px;
  padding: 14px;
}

.chat-msg--typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  animation: chat-blink 1.4s infinite ease-in-out both;
}

.chat-msg--typing span:nth-child(2) { animation-delay: .2s; }
.chat-msg--typing span:nth-child(3) { animation-delay: .4s; }

@keyframes chat-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-3px); }
}

/* ── Ввод ────────────────────────────────────────────────────────────── */
.chat-widget__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.chat-widget__input {
  flex: 1;
  resize: none;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  color: #fff;
  padding: 10px 12px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  transition: border-color .15s ease;
}

.chat-widget__input::placeholder { color: rgba(255, 255, 255, .4); }
.chat-widget__input:focus { border-color: var(--color-primary, #2f54eb); }

.chat-widget__send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--color-primary, #2f54eb);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease, transform .15s ease;
}

.chat-widget__send:hover:not(:disabled) { transform: translateY(-1px); }
.chat-widget__send:disabled { opacity: .45; cursor: default; }

.chat-widget__note {
  margin: 0;
  padding: 0 16px 12px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .45);
  text-align: center;
}

.chat-widget__note a { color: rgba(255, 255, 255, .75); }

/* ── Мобильные ───────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .chat-widget {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;             /* dvh, иначе панель уезжает под адресную строку */
    border-radius: 0;
    border: 0;
  }
}

/* Пока открыт чат на телефоне, страница под ним не прокручивается,
   а плавающая кнопка чата прячется — иначе она лежит поверх на весь
   экран открытой панели (z-index кнопки выше, чем у панели). */
@media (max-width: 520px) {
  body.chat-open { overflow: hidden; }
  body.chat-open .sticky-cta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-widget { transition: none; }
  .chat-msg--typing span { animation: none; }
}
