/* ============================================================
   Чат-бот «Формула Строительства» — стили виджета
   Версия 1.0 | Чистый CSS, без зависимостей
   Цветовая схема: фирменный красный str-formula.ru
   ============================================================ */

:root {
  --fs-primary: #d42b1e;
  --fs-primary-dark: #b02318;
  --fs-primary-light: #e8564a;
  --fs-bg: #ffffff;
  --fs-text: #2b2b2b;
  --fs-text-light: #777777;
  --fs-border: #e5e5e5;
  --fs-msg-bot: #f4f4f4;
  --fs-radius: 14px;
  --fs-shadow: 0 8px 40px rgba(0, 0, 0, .18);
  --fs-zindex: 999999;
  --fs-font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Плавающая кнопка ---------- */
#fs-chat-btn {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: var(--fs-zindex);
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
  box-shadow: 0 4px 18px rgba(212, 43, 30, .45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
  font-family: var(--fs-font);
}
#fs-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 26px rgba(212, 43, 30, .55);
}
#fs-chat-btn svg { width: 30px; height: 30px; fill: #fff; }
#fs-chat-btn .fs-close-ico { display: none; }
#fs-chat-btn.fs-open .fs-chat-ico { display: none; }
#fs-chat-btn.fs-open .fs-close-ico { display: block; }

/* Подсказка-пузырь рядом с кнопкой */
#fs-chat-hint {
  position: fixed;
  right: 96px;
  bottom: 36px;
  z-index: var(--fs-zindex);
  background: #fff;
  color: var(--fs-text);
  font-family: var(--fs-font);
  font-size: 13px;
  line-height: 1.35;
  padding: 10px 14px;
  border-radius: 12px 12px 2px 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .15);
  max-width: 210px;
  cursor: pointer;
  animation: fs-hint-in .5s ease;
}
#fs-chat-hint b { color: var(--fs-primary); }
@keyframes fs-hint-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Окно чата ---------- */
#fs-chat-win {
  position: fixed;
  right: 22px;
  bottom: 96px;
  z-index: var(--fs-zindex);
  width: 384px;
  max-width: calc(100vw - 24px);
  height: 580px;
  max-height: calc(100vh - 130px);
  background: var(--fs-bg);
  border-radius: var(--fs-radius);
  box-shadow: var(--fs-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--fs-font);
  opacity: 0;
  transform: translateY(24px) scale(.97);
  pointer-events: none;
  transition: opacity .28s ease, transform .28s ease;
}
#fs-chat-win.fs-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Шапка */
#fs-chat-win .fs-head {
  background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}
#fs-chat-win .fs-head-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
#fs-chat-win .fs-head-name { font-weight: 700; font-size: 15px; line-height: 1.25; }
#fs-chat-win .fs-head-status {
  font-size: 12px;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 5px;
}
#fs-chat-win .fs-head-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7dff9a;
  display: inline-block;
}
#fs-chat-win .fs-head-close {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: .75;
  padding: 4px;
}
#fs-chat-win .fs-head-close:hover { opacity: 1; }

/* Тело сообщений */
#fs-chat-win .fs-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: #fafafa;
  scrollbar-width: thin;
  scrollbar-color: #ccc transparent;
}
#fs-chat-win .fs-body::-webkit-scrollbar { width: 5px; }
#fs-chat-win .fs-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.fs-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  margin-bottom: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fs-msg-in .25s ease;
}
@keyframes fs-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.fs-msg-bot {
  background: var(--fs-msg-bot);
  color: var(--fs-text);
  border-bottom-left-radius: 4px;
  margin-right: auto;
}
.fs-msg-user {
  background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
  color: #fff;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}
.fs-msg a {
  color: var(--fs-primary);
  font-weight: 600;
  text-decoration: underline;
}
.fs-msg-user a { color: #fff; }
.fs-msg b { font-weight: 700; }

/* Кнопки-ссылки внутри ответа бота */
.fs-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.fs-links a {
  display: inline-block;
  background: #fff;
  border: 1.5px solid var(--fs-primary);
  color: var(--fs-primary) !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 20px;
  transition: background .2s, color .2s;
}
.fs-links a:hover { background: var(--fs-primary); color: #fff !important; }

/* Быстрые подсказки */
.fs-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
  background: #fafafa;
  flex-shrink: 0;
}
.fs-quick button {
  background: #fff;
  border: 1px solid var(--fs-border);
  color: var(--fs-text);
  font-family: var(--fs-font);
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 16px;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.fs-quick button:hover {
  border-color: var(--fs-primary);
  color: var(--fs-primary);
  background: #fff5f4;
}

/* Индикатор «печатает…» */
.fs-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 12px 14px;
  background: var(--fs-msg-bot);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  margin-bottom: 10px;
}
.fs-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b5b5b5;
  animation: fs-blink 1.2s infinite;
}
.fs-typing span:nth-child(2) { animation-delay: .2s; }
.fs-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes fs-blink {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Футер: поле ввода */
#fs-chat-win .fs-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--fs-border);
  background: #fff;
  flex-shrink: 0;
}
#fs-chat-win .fs-input {
  flex: 1;
  border: 1px solid var(--fs-border);
  border-radius: 22px;
  padding: 10px 15px;
  font-family: var(--fs-font);
  font-size: 13.5px;
  outline: none;
  transition: border-color .2s;
  min-width: 0;
}
#fs-chat-win .fs-input:focus { border-color: var(--fs-primary); }
#fs-chat-win .fs-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--fs-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
}
#fs-chat-win .fs-send:hover { background: var(--fs-primary-dark); transform: scale(1.06); }
#fs-chat-win .fs-send svg { width: 18px; height: 18px; fill: #fff; margin-left: -2px; }

/* Подпись в футере */
.fs-powered {
  text-align: center;
  font-size: 10.5px;
  color: var(--fs-text-light);
  padding: 0 0 7px;
  background: #fff;
  flex-shrink: 0;
}
.fs-powered a { color: var(--fs-text-light); }

/* ---------- Мобильная адаптация: чат во весь экран ---------- */
@media (max-width: 480px) {
  #fs-chat-win {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  #fs-chat-btn { right: 16px; bottom: 16px; }
  #fs-chat-hint { right: 88px; bottom: 30px; }
  .fs-msg { max-width: 90%; }
}
