/* ТОРТИТОЧКА — виджет ИИ-помощника
   Цвета меняются здесь, в блоке переменных ниже. */
.tb-root {
  --tb-accent: #d63a6f;        /* основной цвет (кнопка, шапка) */
  --tb-accent-dark: #b52a5a;   /* при наведении */
  --tb-accent-soft: #fdebf1;   /* светлый фон подсказок */
  --tb-text: #3b2a2f;          /* цвет текста */
  --tb-muted: #8a767c;
  --tb-bg: #ffffff;
  --tb-bg-chat: #fbf7f5;       /* фон ленты сообщений */
  --tb-bot-bubble: #ffffff;
  --tb-border: #eadfe2;
  --tb-radius: 16px;
  --tb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: var(--tb-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--tb-text);
}
.tb-root *, .tb-root *::before, .tb-root *::after { box-sizing: border-box; }
.tb-root button { font-family: inherit; }

/* ---------- Плавающая кнопка ---------- */
.tb-launcher {
  display: flex; align-items: center; gap: 10px;
  height: 58px; padding: 0 20px 0 16px;
  border: 0; border-radius: 29px; cursor: pointer;
  background: var(--tb-accent); color: #fff;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(214, 58, 111, .35);
  transition: transform .15s ease, background .15s ease;
}
.tb-launcher:hover { background: var(--tb-accent-dark); transform: translateY(-2px); }
.tb-launcher svg { width: 26px; height: 26px; flex: none; }
.tb-launcher .tb-dot {
  position: absolute; top: 6px; left: 42px; width: 10px; height: 10px;
  border-radius: 50%; background: #3ccf6e; border: 2px solid var(--tb-accent);
}
.tb-root.tb-open .tb-launcher { display: none; }

/* ---------- Окно ---------- */
.tb-panel {
  position: absolute; right: 0; bottom: 0;
  width: 390px; height: min(640px, calc(100vh - 40px));
  display: none; flex-direction: column;
  background: var(--tb-bg); border-radius: var(--tb-radius);
  box-shadow: 0 16px 48px rgba(59, 42, 47, .22);
  overflow: hidden;
  animation: tb-pop .18s ease-out;
}
.tb-root.tb-open .tb-panel { display: flex; }
@keyframes tb-pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.tb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--tb-accent); color: #fff;
}
.tb-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.tb-title { flex: 1; min-width: 0; }
.tb-title b { display: block; font-size: 16px; }
.tb-title span { font-size: 12.5px; opacity: .85; }
.tb-icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: #fff; display: flex; align-items: center; justify-content: center;
}
.tb-icon-btn:hover { background: rgba(255,255,255,.18); }
.tb-icon-btn svg { width: 20px; height: 20px; }

.tb-test-banner {
  padding: 6px 14px; font-size: 12px; text-align: center;
  background: #fff4cc; color: #6b5200;
}

/* ---------- Лента сообщений ---------- */
.tb-body {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  background: var(--tb-bg-chat);
  overscroll-behavior: contain;
}
.tb-msg { display: flex; margin-bottom: 12px; }
.tb-msg-user { justify-content: flex-end; }
.tb-bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 16px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.tb-msg-bot .tb-bubble {
  background: var(--tb-bot-bubble); border: 1px solid var(--tb-border);
  border-bottom-left-radius: 4px;
}
.tb-msg-user .tb-bubble {
  background: var(--tb-accent); color: #fff; border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.tb-msg-error .tb-bubble { background: #fff1f0; border-color: #f3c4c0; color: #8a2a22; }
.tb-bubble p { margin: 0 0 8px; }
.tb-bubble p:last-child { margin-bottom: 0; }
.tb-bubble ul, .tb-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.tb-bubble li { margin: 2px 0; }
.tb-bubble a { color: var(--tb-accent-dark); text-decoration: underline; }
.tb-bubble .tb-h { font-weight: 700; margin: 10px 0 4px; }
.tb-bubble .tb-h:first-child { margin-top: 0; }

/* ---------- Карточки товаров ---------- */
.tb-cards {
  display: flex; gap: 10px; overflow-x: auto; margin: -2px 0 14px;
  padding: 2px 2px 8px; scroll-snap-type: x mandatory;
}
.tb-card {
  flex: 0 0 160px; scroll-snap-align: start;
  display: flex; flex-direction: column;
  background: #fff; border: 1px solid var(--tb-border); border-radius: 12px; overflow: hidden;
}
.tb-card-img {
  display: block; height: 120px; background: #fff center/contain no-repeat;
  border-bottom: 1px solid var(--tb-border);
}
.tb-card-img.tb-noimg { background: var(--tb-accent-soft); display: flex; align-items: center; justify-content: center; font-size: 36px; text-decoration: none; }
.tb-card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; flex: 1; }
.tb-card-name {
  font-size: 13px; line-height: 1.3; color: var(--tb-text); text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 6px; min-height: 50px;
}
.tb-card-name:hover { color: var(--tb-accent-dark); }
.tb-card-price { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.tb-card-price small { font-weight: 400; color: var(--tb-muted); font-size: 12px; }
.tb-card-btn {
  margin-top: auto; height: 34px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--tb-accent); color: #fff; font-size: 13px; font-weight: 600;
  text-align: center; text-decoration: none; display: flex; align-items: center; justify-content: center;
}
.tb-card-btn:hover { background: var(--tb-accent-dark); }
.tb-card-btn[disabled] { opacity: .7; cursor: default; }
.tb-card-btn.tb-added { background: #2f9e5b; }
.tb-card-btn.tb-secondary { background: var(--tb-accent-soft); color: var(--tb-accent-dark); }

/* ---------- Подсказки ---------- */
.tb-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.tb-chip {
  border: 1px solid var(--tb-accent); background: #fff; color: var(--tb-accent-dark);
  border-radius: 18px; padding: 7px 12px; font-size: 13.5px; cursor: pointer; text-align: left;
}
.tb-chip:hover { background: var(--tb-accent-soft); }

/* ---------- «Печатает…» ---------- */
.tb-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.tb-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--tb-muted);
  animation: tb-blink 1.2s infinite ease-in-out;
}
.tb-typing i:nth-child(2) { animation-delay: .15s; }
.tb-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tb-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.tb-typing-note { font-size: 12px; color: var(--tb-muted); margin-left: 6px; }

/* ---------- Поле ввода ---------- */
.tb-foot { border-top: 1px solid var(--tb-border); background: #fff; padding: 10px 10px 8px; }
.tb-form { display: flex; align-items: flex-end; gap: 8px; }
.tb-input {
  flex: 1; resize: none; max-height: 120px; min-height: 42px;
  padding: 10px 12px; border: 1px solid var(--tb-border); border-radius: 12px;
  font: inherit; color: var(--tb-text); background: #fff; outline: none;
}
.tb-input:focus { border-color: var(--tb-accent); }
.tb-send {
  width: 42px; height: 42px; flex: none; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--tb-accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.tb-send:hover { background: var(--tb-accent-dark); }
.tb-send[disabled] { opacity: .5; cursor: default; }
.tb-send svg { width: 20px; height: 20px; }
.tb-note { font-size: 11px; color: var(--tb-muted); text-align: center; margin-top: 6px; }

/* ---------- Телефоны ---------- */
@media (max-width: 520px) {
  .tb-root { right: 12px; bottom: 12px; }
  .tb-launcher { height: 54px; padding: 0 14px; }
  .tb-launcher .tb-label { display: none; }
  .tb-launcher .tb-dot { left: auto; right: 8px; }
  .tb-root.tb-open { right: 0; bottom: 0; left: 0; top: 0; }
  .tb-panel { position: fixed; inset: 0; width: 100%; height: 100%; border-radius: 0; }
  .tb-input { font-size: 16px; } /* чтобы iPhone не увеличивал страницу */
}

@media print { .tb-root { display: none !important; } }

/* ---------- Оценка ответа ---------- */
.tb-rate { display: flex; align-items: center; gap: 4px; margin: -4px 0 10px 4px; flex-wrap: wrap; }
.tb-rate-btn { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 2px 6px; font-size: 14px; line-height: 1.2; cursor: pointer; opacity: .45; filter: grayscale(1); transition: opacity .15s, filter .15s; }
.tb-rate-btn:hover { opacity: .9; filter: none; }
.tb-rate-btn.tb-on { opacity: 1; filter: none; background: var(--tb-accent-soft); border-color: var(--tb-border); }
.tb-rate-thanks { font-size: 12px; color: var(--tb-muted); margin-left: 4px; }

/* ---------- Количество и «Добавить всё в корзину» ---------- */
.tb-card-price .tb-qty { color: var(--tb-accent-dark); font-weight: 600; }
.tb-addall { margin: -6px 0 12px; }
.tb-addall-btn {
  width: 100%; border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer;
  background: var(--tb-accent); color: #fff; font-size: 14.5px; font-weight: 700; line-height: 1.3;
  box-shadow: 0 4px 12px rgba(214, 58, 111, .25); transition: background .15s;
}
.tb-addall-btn small { font-weight: 400; opacity: .9; }
.tb-addall-btn:hover { background: var(--tb-accent-dark); }
.tb-addall-btn[disabled] { opacity: .75; cursor: default; }
.tb-addall-btn.tb-added { background: #2f9e5b; box-shadow: none; }

/* ---------- Подсказка над кнопкой чата ---------- */
.tb-nudge {
  position: absolute; right: 0; bottom: 70px; width: max-content; max-width: 280px;
  background: #fff; color: var(--tb-text); border: 1px solid var(--tb-border); border-radius: 14px 14px 4px 14px;
  padding: 11px 34px 11px 14px; font-size: 14px; line-height: 1.4; cursor: pointer;
  box-shadow: 0 10px 30px rgba(59, 42, 47, .18);
  opacity: 0; transform: translateY(8px); transition: opacity .25s ease, transform .25s ease;
}
.tb-nudge.tb-show { opacity: 1; transform: none; }
.tb-nudge:hover { border-color: var(--tb-accent); }
.tb-nudge-close {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; padding: 3px;
  border: 0; background: transparent; color: var(--tb-muted); cursor: pointer; border-radius: 6px;
}
.tb-nudge-close:hover { background: var(--tb-accent-soft); }
.tb-nudge-close svg { width: 16px; height: 16px; display: block; }
.tb-root.tb-open .tb-nudge { display: none; }
@media (max-width: 520px) {
  .tb-nudge { bottom: 64px; max-width: calc(100vw - 40px); }
}

/* ---------- Нет в наличии: «Сообщить о поступлении» ---------- */
.tb-oos { font-size: 12px; color: var(--tb-muted); margin: -4px 0 6px; }
.tb-sub-btn { font-size: 12.5px; padding-left: 6px; padding-right: 6px; }
.tb-sub-form input {
  width: 100%; border: 1px solid var(--tb-border); border-radius: 8px; padding: 7px 8px; margin-bottom: 6px;
  font: inherit; font-size: 13px; color: var(--tb-text); background: #fff; outline: none;
}
.tb-sub-form input:focus { border-color: var(--tb-accent); }
.tb-sub-form.tb-err input { border-color: #d64545; }
.tb-sub-form .tb-card-btn { width: 100%; }
.tb-sub-note { font-size: 11px; color: var(--tb-muted); margin-top: 4px; line-height: 1.3; }

