/* ═══════════════════════════════════════════════════════════════════════════
   Виджет онлайн-чата. Отдельный файл: подключается на всех страницах,
   переменные берёт из styles.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/*
  Атрибут hidden прячет элемент через display:none из стилей браузера, а любое
  наше display:flex/grid его перебивает — панель оставалась открытой навсегда.
  Поэтому внутри виджета hidden всегда сильнее.
*/
.chat-widget [hidden] {
  display: none !important;
}

.chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ─────────────────────────────── Кнопка ────────────────────────────────── */

.chat-fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  background: var(--grad);
  color: #05060f;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  position: relative;
  order: 2;
  transition: transform 0.25s var(--ease);
}

.chat-fab:hover { transform: scale(1.06); }
.chat-fab.is-open { transform: scale(0.94); }

.chat-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--err);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg);
}

/* ─────────────────────────────── Панель ────────────────────────────────── */

.chat-panel {
  order: 1;
  width: min(370px, calc(100vw - 32px));
  max-height: min(600px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: chat-in 0.25s var(--ease);
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(12px); }
}

.chat-panel__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

/*
  Логотип из /img — тот же файл, что в шапке сайта, чтобы знак читался целиком.
  36px — это коробка под две строки текста рядом, а padding уменьшает саму
  картинку внутри коробки: логотип не упирается в края и не выглядит раздутым.
  object-fit: contain вписывает его в оставшееся место без искажения пропорций.
*/
.chat-panel__avatar {
  width: 36px;
  height: 36px;
  padding: 4px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  object-fit: contain;
  display: block;
  flex: none;
}


.chat-panel__who { flex: 1; min-width: 0; line-height: 1.3; }
.chat-panel__who b { display: block; font-size: 14.5px; }
.chat-panel__who span { font-size: 12.5px; color: var(--text-faint); }

.chat-panel__close {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  line-height: 1;
}

.chat-panel__close:hover { color: var(--text); background: var(--surface-strong); }

/* ────────────────────────── Форма знакомства ───────────────────────────── */

.chat-intro {
  padding: 18px 16px;
  overflow-y: auto;
}

.chat-intro__lead {
  font-size: 13.5px;
  color: var(--text-dim);
  margin: 0 0 16px;
  line-height: 1.5;
}

.chat-intro__note {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 12px 0 0;
  line-height: 1.5;
}

.chat-intro__note a { color: var(--brand); }

.chat-field { display: grid; gap: 5px; margin-bottom: 12px; }
.chat-field label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.chat-field .req { color: var(--brand-3); }

.chat-field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
}

.chat-field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

.chat-field.has-error input { border-color: var(--err); }
.chat-field__error { font-size: 12px; color: var(--err); }

/* Ловушка для спам-ботов: человеку поле не видно и в табуляцию не попадает */
.chat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ───────────────────────────── Переписка ───────────────────────────────── */

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.chat-msg {
  max-width: 85%;
  padding: 9px 13px 6px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.45;
  border: 1px solid var(--border);
  background: var(--surface);
}

.chat-msg--in { align-self: flex-start; border-bottom-left-radius: 5px; }

.chat-msg--out {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--grad);
  border-color: transparent;
  color: #05060f;
}

.chat-msg--system {
  align-self: stretch;
  max-width: 100%;
  background: var(--grad-soft);
  font-size: 13.5px;
  color: var(--text-dim);
}

.chat-msg__author {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 3px;
}

.chat-msg__text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Быстрые ответы помощника: нажатие отправляет тот же текст, что и вручную */
.chat-quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.chat-quick {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s;
}

.chat-quick:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.chat-msg time {
  display: block;
  font-size: 10.5px;
  opacity: 0.65;
  text-align: right;
  margin-top: 2px;
}

.chat-msg__files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.chat-photo img {
  width: 116px;
  height: 116px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  border: 1px solid var(--border);
}

.chat-file {
  font-size: 12.5px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

/* ──────────────────────── Оценка работы оператора ──────────────────────── */

.chat-rate {
  flex: none;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  gap: 9px;
}

.chat-rate__title { font-size: 13.5px; font-weight: 600; }

.chat-rate__scale {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chat-rate__dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

/* Закрашиваем шкалу до выбранной отметки — так видно «на сколько из десяти» */
.chat-rate__dot.is-on {
  background: var(--grad);
  border-color: transparent;
  color: #05060f;
  font-weight: 700;
}

.chat-rate textarea {
  width: 100%;
  resize: none;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}

.chat-rate__hint { font-size: 12px; color: var(--err); min-height: 14px; }
.chat-rate__done { font-size: 13.5px; color: var(--ok, var(--brand)); }

/* ───────────────────────────── Поле ввода ──────────────────────────────── */

.chat-composer {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  background: var(--surface);
}

.chat-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
}

.chat-composer textarea:focus {
  outline: none;
  border-color: var(--brand);
}

.chat-attach,
.chat-send {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  transition: color 0.2s, border-color 0.2s;
}

.chat-attach:hover,
.chat-send:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); }

.chat-send {
  background: var(--grad);
  border-color: transparent;
  color: #05060f;
}

.chat-send:disabled { opacity: 0.5; cursor: default; }

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chat-attachments:empty { display: none; }

.chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  color: var(--text-dim);
}

.chat-chip button {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px;
}

.chat-chip button:hover { color: var(--err); }

.chat-composer__hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 6px;
  min-height: 14px;
}

.chat-composer__hint.is-err { color: var(--err); }

@media (max-width: 480px) {
  .chat-widget {
    right: 12px;
    bottom: 12px;
    left: 12px;
    align-items: stretch;
  }

  /* На телефоне окно занимает всю ширину — набирать текст в узкой колонке неудобно */
  .chat-panel {
    width: 100%;
    max-height: calc(100vh - 96px);
    max-height: calc(100dvh - 96px);
  }

  .chat-fab {
    align-self: flex-end;
    width: 54px;
    height: 54px;
  }

  .chat-intro { padding: 16px 14px; }
  .chat-thread { padding: 14px 12px; }
  .chat-msg { max-width: 92%; }
  .chat-photo img { width: 96px; height: 96px; }
}

/* Пальцу нужна цель побольше */
@media (hover: none) {
  .chat-attach,
  .chat-send {
    width: 44px;
    height: 44px;
  }

  .chat-panel__close {
    padding: 8px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel { animation: none; }
  .chat-fab { transition: none; }
}
