/* =====================================================================
   Чат-консультант MarketGIS — плавающая кнопка и окно диалога
   ===================================================================== */

.chat-launcher {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 28px -10px rgba(16,24,40,.5);
  transition: transform .16s ease, opacity .2s ease, visibility .2s ease, background-color .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-launcher:hover { background: #000; }
.chat-launcher:active { transform: translateY(1px); }

/* is-away — посетитель смотрит на квиз или финальный блок;
   is-hidden — чат открыт. В обоих случаях кнопка уезжает плавно. */
.chat-launcher.is-away,
.chat-launcher.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
}

.chat-launcher__dot {
  width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #e8a06f 100%);
  display: grid; place-items: center;
}
.chat-launcher__dot svg { width: 16px; height: 16px; }
.chat-launcher__text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.chat-launcher__sub { font-size: 11px; font-weight: 500; color: #9aa3af; }

/* ------------------------------------------------------------- окно */

.chat-window {
  position: fixed;
  z-index: 70;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
}
.chat-window.is-open { opacity: 1; visibility: visible; transform: none; }

.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--ink);
  color: #fff;
  flex: none;
}
.chat-head__avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #e8a06f 100%);
  display: grid; place-items: center;
}
.chat-head__avatar svg { width: 20px; height: 20px; }
.chat-head__title { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.chat-head__sub   { font-size: 12px; color: #9aa3af; }
.chat-head__spacer { margin-left: auto; }
.chat-close {
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.chat-close:hover { background: rgba(255,255,255,.16); }

.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 10px;
  background: var(--sand);
  display: flex; flex-direction: column; gap: 12px;
}

.chat-msg { max-width: 86%; font-size: 15px; line-height: 1.5; white-space: pre-line; }
.chat-msg__bubble {
  padding: 12px 15px;
  border-radius: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.chat-msg--user { align-self: flex-end; }
.chat-msg--user .chat-msg__bubble {
  background: var(--ink); color: #fff; border-color: var(--ink);
  border-bottom-right-radius: 6px;
}
.chat-msg--bot .chat-msg__bubble { border-bottom-left-radius: 6px; }

.chat-typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.chat-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #c6c2ba; display: block;
  animation: chatDot 1s infinite ease-in-out;
}
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chatDot { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.chat-quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 6px; }
.chat-quick button {
  font: inherit; font-size: 14px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--paper);
  color: var(--accent-dk);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-quick button:hover { background: var(--accent); color: #fff; }

/* форма контакта внутри чата */
.chat-form {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 10px;
}
.chat-form__title { font-size: 15px; font-weight: 700; }
.chat-form input[type="text"], .chat-form input[type="tel"] {
  width: 100%; box-sizing: border-box;
  padding: 13px 14px;
  font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fbfaf8; color: var(--text);
}
.chat-form input:focus { outline: none; border-color: var(--accent); background: #fff; }
.chat-form input.is-invalid { border-color: #d14343; background: #fff7f7; }
.chat-form__methods { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-form__methods label {
  font-size: 14px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); cursor: pointer; background: #fbfaf8;
}
.chat-form__methods input { position: absolute; width: 100%; height: 100%; left: 0; top: 0; margin: 0; opacity: 0; cursor: pointer; }
.chat-form__methods label { position: relative; }
.chat-form__methods input:checked + span { color: var(--accent-dk); font-weight: 600; }
.chat-form__methods label:has(input:checked) { border-color: var(--accent); background: var(--accent-sft); }
.chat-form__consent { display: flex; gap: 9px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.chat-form__consent input { width: 17px; height: 17px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.chat-form__consent a { color: var(--accent); }
.chat-form__error { color: #c0392b; font-size: 13px; }
.chat-form button[type="submit"] {
  padding: 14px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
}
.chat-form button[type="submit"]:hover { background: var(--accent-dk); }
.chat-form button[disabled] { opacity: .6; cursor: default; }

/* строка ввода */
.chat-foot {
  flex: none;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.chat-foot textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 110px;
  padding: 12px 14px;
  font: inherit; font-size: 16px;      /* 16px — iOS не зумит поле */
  line-height: 1.4;
  border: 1px solid var(--line); border-radius: 14px;
  background: #fbfaf8; color: var(--text);
}
.chat-foot textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.chat-send {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.chat-send:hover { background: var(--accent-dk); }
.chat-send svg { width: 18px; height: 18px; }

.chat-note { font-size: 11px; color: var(--muted); text-align: center; padding: 0 16px 8px; background: var(--paper); }

/* ------------------------------------------------------- десктоп */

@media (min-width: 640px) {
  .chat-launcher { right: 24px; bottom: 24px; }
  .chat-window {
    inset: auto 24px 24px auto;
    width: 420px;
    height: min(680px, calc(100vh - 48px));
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 24px 60px -20px rgba(16,24,40,.45);
    border: 1px solid var(--line);
  }
  .chat-head { border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-window, .chat-launcher { transition: none; }
  .chat-typing i { animation: none; }
}

/* ---------------------------------------------------------------------
 *  ДОРАБОТКА 08.10.2026
 *  Помощник назван автоматическим, ссылка на политику — рядом с полем
 *  ввода, на телефоне окно не должно перекрывать форму и таблицу.
 * ------------------------------------------------------------------- */

/* Плашки статуса в шапке больше нет: зелёный кружок рядом с названием
   читается как «менеджер на связи», а в чате отвечает автомат. */

.chat-note a { color: inherit; text-decoration: underline; }

.chat-form__links {
  margin: -6px 0 10px;
  font-size: 11px;
  line-height: 1.5;
  opacity: .8;
}
.chat-form__links a { color: inherit; text-decoration: underline; }

/* ---------------------------------------------------------------------
 *  Телефон: кнопка сворачивается до компактного круга, окно занимает
 *  экран почти целиком и уезжает вместе с экранной клавиатурой
 *  (dvh учитывает её высоту в мобильных браузерах).
 * ------------------------------------------------------------------- */
@media (max-width: 560px) {
  /* компактная кнопка: подпись скрыта, остаётся иконка */
  .chat-launcher__text { display: none; }
  .chat-launcher {
    padding: 0;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    justify-content: center;
  }

  .chat-window {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 82vh;
  }
}

@supports (height: 100dvh) {
  @media (max-width: 560px) {
    /* когда открыта экранная клавиатура, dvh уменьшается — окно не уезжает
       под неё и поле ввода остаётся видимым */
    .chat-window { max-height: 82dvh; }
  }
}

/* Условия работы помощника в самой ленте: видно до того, как человек
   начнёт писать. Намеренно не похоже на реплику — это служебный текст. */
.chat-disclosure {
  margin: 2px 0 10px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #5b6472;
  background: #f2f3f5;
  border-radius: 10px;
}
