/* ═══════════════════════════════════════════════════════════════════════
   Чат ЧОП «Барк»: плавающая кнопка и панель разговора.

   Раньше разметка, стили и логика лежали прямо в index.html и вторым
   экземпляром в посадочной под стройки. Копии разошлись, и починку хука
   перенесли только в одну. Теперь файл один.
   ═══════════════════════════════════════════════════════════════════════ */

.bark-dock {
  position: fixed;
  right: 24px;
  bottom: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 8000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.bark-dock > * {
  pointer-events: auto;
}

/* ── Кнопки связи над основной ─────────────────────────────────────── */
.bark-dock-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.bark-dock-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #0f1115;
  background: #fff;
  box-shadow: 0 12px 28px -12px rgba(0, 0, 0, .6);
  transition: transform .18s ease, background-color .18s ease;
}

.bark-dock-link:hover {
  transform: translateY(-2px);
  background: #f2f2f2;
}

/* ── Основная кнопка ───────────────────────────────────────────────── */
.bark-fab {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 20px 13px 16px;
  border: 0;
  border-radius: 40px;
  cursor: pointer;
  background: #c9922e;
  color: #150e02;
  font-family: 'Onest', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
  box-shadow: 0 18px 40px -14px rgba(0, 0, 0, .75);
  transition: transform .2s ease;
}

.bark-fab:hover {
  transform: translateY(-2px);
}

.bark-fab[hidden] {
  display: none;
}

/* ── Панель ────────────────────────────────────────────────────────── */
.bark-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 9000;
  display: none;
  flex-direction: column;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  background: #0f1115;
  border-radius: 20px;
  overflow: hidden;
  color: #c3cbd8;
  font-family: 'Onest', system-ui, sans-serif;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, .85), 0 0 0 1px rgba(255, 255, 255, .06);
}

.bark-chat.on {
  display: flex;
  animation: barkUp .32s cubic-bezier(.16, .84, .28, 1);
}

@keyframes barkUp {
  from { opacity: 0; transform: translateY(18px) }
  to   { opacity: 1; transform: none }
}

.bark-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .045);
  flex: none;
}

.bark-head-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #0d1420;
  object-fit: contain;
  padding: 4px;
  flex: none;
}

.bark-head-text b {
  display: block;
  font-size: 14.5px;
  color: #fff;
  font-weight: 600;
  letter-spacing: -.01em;
}

.bark-head-text span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 10.5px;
  color: #8b94a3;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.bark-online {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #56c26a;
}

.bark-x {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, .08);
  color: #9aa4b3;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.bark-x:hover {
  background: rgba(255, 255, 255, .16);
  color: #fff;
}

.bark-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* Разговор прижат к полю ввода, как в любом мессенджере. Без этого короткая
   переписка висела вверху, а между ней и полем зияла пустая половина экрана. */
.bark-log > :first-child { margin-top: auto }

.bark-log::-webkit-scrollbar { width: 5px }
.bark-log::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 3px }

.bark-msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: barkPop .26s ease;
}

@keyframes barkPop {
  from { opacity: 0; transform: translateY(5px) }
  to   { opacity: 1; transform: none }
}

.bark-msg.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, .06);
  border-bottom-left-radius: 4px;
}

.bark-msg.me {
  align-self: flex-end;
  background: #c9922e;
  color: #150e02;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

/* Курсор набора: показывается, пока ответ ещё идёт словами. */
.bark-msg.typing::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: currentColor;
  opacity: .55;
  animation: barkCaret 1s steps(2) infinite;
}

@keyframes barkCaret {
  0%, 49% { opacity: .55 }
  50%, 100% { opacity: 0 }
}

.bark-dots {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 13px 15px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  border-bottom-left-radius: 4px;
}

.bark-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8b94a3;
  animation: barkBlink 1.3s infinite;
}

.bark-dots i:nth-child(2) { animation-delay: .18s }
.bark-dots i:nth-child(3) { animation-delay: .36s }

@keyframes barkBlink {
  0%, 60%, 100% { opacity: .25 }
  30% { opacity: 1 }
}

/* ── Ошибка: не тупик, а выход ─────────────────────────────────────── */
.bark-fail {
  align-self: stretch;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(250, 36, 42, .12);
  border: 1px solid rgba(250, 36, 42, .3);
  font-size: 13.5px;
  line-height: 1.45;
  color: #ffb9bb;
}

.bark-fail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.bark-fail button,
.bark-fail a {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 8px 13px;
  border-radius: 20px;
  border: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  text-decoration: none;
}

.bark-fail button:hover,
.bark-fail a:hover {
  background: rgba(255, 255, 255, .22);
}

/* ── Подсказки ─────────────────────────────────────────────────────── */
/* Ровно один ряд, который при нехватке места прокручивается вбок. С переносом
   четыре подсказки вставали в три ряда и закрывали половину разговора. */
.bark-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 16px 4px;
  flex: none;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* Правый край растворяется: видно, что ряд продолжается за границей. */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 34px), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - 34px), transparent);
}

.bark-chips::-webkit-scrollbar { display: none }
.bark-chips:empty { display: none }

.bark-chip {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 11px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 0;
  background: rgba(255, 255, 255, .07);
  color: #b9c2cf;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  flex: none;
}

.bark-chip:hover {
  background: rgba(255, 255, 255, .15);
  color: #fff;
}

/* ── Согласие и ввод ───────────────────────────────────────────────── */
.bark-privacy {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px 8px;
  font-size: 10.5px;
  line-height: 1.4;
  color: #7e8899;
  flex: none;
  cursor: pointer;
}

/* Согласие спрошено один раз: дальше остаётся только ссылка, чтобы её можно было
   открыть, но она не занимала строку с галочкой над каждым сообщением. */
.bark-privacy.done { cursor: default }
.bark-privacy.done input,
.bark-privacy.done .bark-privacy-ask { display: none }
.bark-privacy .bark-privacy-done { display: none }
.bark-privacy.done .bark-privacy-done { display: inline }

.bark-privacy input {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin: 1px 0 0;
  accent-color: #c9922e;
}

.bark-privacy a {
  color: inherit;
  text-decoration: underline;
}

.bark-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, .3);
  flex: none;
}

.bark-input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 22px;
  border: 0;
  background: rgba(255, 255, 255, .07);
  color: #eaeef4;
  /* 16px обязательно: при меньшем размере iOS увеличивает страницу,
     как только человек ставит курсор в поле, и обратно уже не уменьшает */
  font-size: 16px;
  line-height: 1.35;
  outline: none;
  font-family: inherit;
  resize: none;
  max-height: 110px;
}

.bark-input::placeholder { color: #5a6474 }
.bark-input:focus { background: rgba(255, 255, 255, .11) }

.bark-send {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: #c9922e;
  color: #150e02;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
}

.bark-send:disabled {
  opacity: .4;
  cursor: default;
}

/* ── Телефон ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .bark-dock {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .bark-fab {
    padding: 12px 17px 12px 14px;
  }

  .bark-chat {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    /* Высоту подменяет скрипт по видимой области: на iOS клавиатура
       не сжимает окно, и нижняя строка с полем ввода уезжала под неё */
    height: var(--bark-vh, 100dvh);
  }

  .bark-msg { max-width: 92% }
}

@media (prefers-reduced-motion: reduce) {
  .bark-chat.on, .bark-msg { animation: none }
  .bark-msg.typing::after { animation: none }
}
