/* ============================================================
   Чат-сборщик контактов: пузырь первым в столбце кнопок
   (чат · MAX · Telegram · кнопка каталога Домопланера),
   подсказка у пузыря и окно-чат в углу — не на весь экран.
   Цвета и шрифты — токены сайта из style.css.
   ============================================================ */

/* ---------- Пузырь: над кнопками мессенджеров, тот же размер и шаг ---------- */
.chat-launch-wrap { position: fixed; right: 32px; bottom: 302px; z-index: 90; }  /* 166 (низ мессенджеров) + 124 (их высота) + 12 (шаг) */
.chat-launch {
  display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; padding: 0;
  color: #FFFFFF; background: var(--ink); border: 0; border-radius: 16px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(20, 16, 12, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chat-launch:focus-visible { outline: 2px solid #FFFFFF; outline-offset: -7px; box-shadow: 0 0 0 3px var(--ink), 0 6px 20px rgba(20, 16, 12, 0.28); }
@media (hover: hover) {
  .chat-launch:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(20, 16, 12, 0.34); }
}

/* ---------- Подсказка слева от пузыря ---------- */
.chat-teaser {
  position: absolute; right: calc(100% + 12px); top: 50%; transform: translateY(-50%);
  display: flex; align-items: flex-start; width: 256px;
  background: #FFFFFF; border-radius: 14px;          /* как кнопки мессенджеров: только тень, без рамки */
  box-shadow: 0 10px 30px rgba(20, 16, 12, 0.18);
  animation: chat-fade 0.25s ease-out both;
}
.chat-teaser[hidden] { display: none; }
.chat-teaser-open {
  flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 12px 0 12px 16px;
  text-align: left; color: var(--ink); background: none; border: 0; cursor: pointer; font-family: var(--font-text);
}
.chat-teaser-title { font-size: 14.5px; font-weight: 700; line-height: 1.3; }
.chat-teaser-text { font-size: 13.5px; line-height: 1.4; color: var(--grey); }
.chat-teaser-close {
  flex: none; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  color: var(--grey); background: none; border: 0; border-radius: 12px; font-size: 22px; line-height: 1; cursor: pointer;
}
.chat-teaser :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- Окно ---------- */
.chat-panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 2147483000;   /* выше кнопки каталога (100), ниже окна квиза (максимум) */
  display: flex; flex-direction: column; width: 384px; height: min(620px, calc(100vh - 120px));
  font-family: var(--font-text); color: var(--ink); background: var(--white);
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(20, 16, 12, 0.3);
}
.chat-panel[hidden] { display: none; }
html.chat-open .msg-widget, html.chat-open .chat-launch-wrap { visibility: hidden; }   /* окно встаёт на место столбца кнопок */

.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 20px; color: #FFFFFF; background: var(--dark); }
.chat-title { font-family: var(--font-display); font-size: 18px; line-height: 1.2; }
.chat-sub { margin-top: 4px; font-size: 13px; line-height: 1.3; color: rgba(255, 255, 255, 0.78); }
.chat-close {
  display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-left: auto;
  color: #FFFFFF; background: none; border: 0; border-radius: 12px; font-size: 28px; line-height: 1; cursor: pointer;
}
.chat-head :focus-visible { outline: 2px solid #FFFFFF; outline-offset: 2px; }
@media (hover: hover) { .chat-close:hover { background: rgba(255, 255, 255, 0.12); } }

.chat-log {
  position: relative;                        /* offsetTop реплик считается от ленты */
  flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 18px 16px 16px;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.chat-log :focus-visible, .chat-compose :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Реплики */
.chat-msg {
  align-self: flex-start; max-width: 88%; padding: 11px 14px; font-size: 15px; line-height: 1.45;
  background: #FFFFFF; border: 1px solid var(--line); border-radius: 4px 16px 16px 16px;
  animation: chat-in 0.22s ease-out both;
}
.chat-msg ul { margin: 6px 0 0; padding-left: 18px; list-style: disc; }
.chat-msg li + li { margin-top: 4px; }
.chat-msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.chat-msg--me { align-self: flex-end; color: #FFFFFF; background: var(--ink); border-color: var(--ink); border-radius: 16px 4px 16px 16px; }
.chat-debug { max-width: 100%; font-size: 12.5px; line-height: 1.4; background: #FFF4CC; border-color: #E6CF7E; }

/* Кнопки веток: название и затравка */
.chat-actions { display: grid; gap: 8px; animation: chat-in 0.22s ease-out both; }
.chat-option {
  display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 12px 14px; text-align: left;
  font-family: var(--font-text); color: var(--ink); background: #FFFFFF; border: 1px solid var(--ink); border-radius: 12px; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.chat-option-label { font-size: 15px; font-weight: 700; line-height: 1.3; }
.chat-option-hint { font-size: 13.5px; line-height: 1.35; color: var(--grey); transition: color 0.15s ease; }

/* Короткие ответы — чипсы справа, как реплики человека */
.chat-actions--chips { display: flex; flex-wrap: wrap; justify-content: flex-end; }
.chat-chip {
  min-height: 44px; padding: 10px 16px; font-family: var(--font-text); color: var(--ink);
  background: #FFFFFF; border: 1px solid var(--ink); border-radius: 999px; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.chat-chip .chat-option-label { font-size: 14.5px; font-weight: 500; }
@media (hover: hover) {
  .chat-option:hover, .chat-chip:hover { color: #FFFFFF; background: var(--ink); }
  .chat-option:hover .chat-option-hint { color: rgba(255, 255, 255, 0.82); }
}

/* Контакт */
.chat-form { gap: 10px; padding: 14px; background: #FFFFFF; border: 1px solid var(--line); border-radius: 14px; }
.chat-field input {
  width: 100%; height: 46px; padding: 0 12px; font-family: var(--font-text); font-size: 16px; color: var(--ink);
  background: var(--white); border: 1px solid var(--line); border-radius: 10px;
}
.chat-field input::placeholder, .chat-compose input::placeholder { color: var(--grey); opacity: 1; }
.chat-field input:focus-visible, .chat-compose input:focus-visible { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }   /* одна чёткая обводка вместо рамки + контура */
.chat-field.invalid input { border-color: #B3261E; }
.chat-error { display: none; margin-top: 4px; font-size: 13px; color: #B3261E; }
.chat-field.invalid .chat-error { display: block; }
.chat-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.chat-send {
  height: 46px; font-family: var(--font-text); font-size: 15px; font-weight: 700; color: #FFFFFF;
  background: var(--ink); border: 0; border-radius: 10px; cursor: pointer;
}
.chat-send:disabled { opacity: 0.6; cursor: default; }
.chat-consent { font-size: 12px; line-height: 1.45; color: var(--grey); }
.chat-consent a { color: inherit; text-decoration: underline; }
.chat-failure { display: none; font-size: 13px; line-height: 1.4; color: #B3261E; }
.chat-failure.visible { display: block; }

/* Поле сообщения */
.chat-compose { display: flex; gap: 8px; padding: 10px 12px; background: #FFFFFF; border-top: 1px solid var(--line); }
.chat-compose input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px; font-family: var(--font-text); font-size: 16px; color: var(--ink);
  background: var(--white); border: 1px solid var(--line); border-radius: 10px;
}
.chat-compose input:disabled { opacity: 0.7; }
.chat-compose-send {
  flex: none; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  color: #FFFFFF; background: var(--ink); border: 0; border-radius: 10px; cursor: pointer;
}
.chat-compose-send:disabled { opacity: 0.5; cursor: default; }
.chat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes chat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes chat-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Телефон: пузырь над мессенджерами, окно — лист снизу, верх страницы виден ---------- */
@media (max-width: 767px) {
  .chat-launch-wrap { right: 17px; bottom: 238px; }   /* 114 + 114 + 10 */
  .chat-launch { width: 52px; height: 52px; border-radius: 15px; }
  .chat-teaser { width: min(256px, calc(100vw - 97px)); }
  .chat-panel { left: 8px; right: 8px; bottom: 8px; width: auto; height: min(560px, calc(100vh - 96px)); height: min(560px, calc(100dvh - 96px)); border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-launch, .chat-option, .chat-option-hint, .chat-chip { transition: none; }
  .chat-msg, .chat-actions, .chat-teaser { animation: none; }
}
