/* Онлайн-чат: плавающее окно (.site-chat) и страница в кабинете (.chat-panel--page).
   Разметка — common/chat_panel.twig, поведение — catalog/view/javascript/chat.js.
   Палитра сайта: бордовый #6B1F2C, тёплый серый фон #faf7f5. */

.site-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99990;
  width: 370px;
  height: min(600px, calc(100vh - 40px));
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.site-chat[hidden] {
  display: none;
}
.site-chat.is-open {
  opacity: 1;
  transform: translateY(0);
}
/* Кнопки связи в углу прячутся под окном — убираем, чтобы не просвечивали тенью */
body.chat-open .floating-messenger {
  display: none;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  color: #2d2824;
  font-family: 'Open Sans', sans-serif;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}
.chat-panel--page {
  height: clamp(440px, 70vh, 720px);
  border: 1px solid #eee4de;
  box-shadow: none;
}

.chat-panel__head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 12px 12px 12px 16px;
  background: #faf7f5;
  border-bottom: 1px solid #eee4de;
}
.chat-panel__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chat-panel__who {
  flex: 1;
  min-width: 0;
}
.chat-panel__title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.chat-panel__status {
  font-size: 12px;
  line-height: 1.3;
  color: #6f6660;
}
.chat-panel__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: #9a918b;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.chat-panel__close:hover {
  color: #2d2824;
  background: #f1ece8;
}
.chat-panel__close svg {
  width: 20px;
  height: 20px;
}

.chat-panel__list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-day {
  align-self: center;
  margin: 8px 0 4px;
  padding: 2px 10px;
  font-size: 12px;
  color: #9a918b;
  background: #f7f3f0;
  border-radius: 10px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}
.chat-msg--shop {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-msg--me {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg__bubble {
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 16px;
}
.chat-msg--shop .chat-msg__bubble {
  background: #f3eeea;
  border-bottom-left-radius: 4px;
}
.chat-msg--me .chat-msg__bubble {
  color: #fff;
  background: #6B1F2C;
  border-bottom-right-radius: 4px;
}
.chat-msg__bubble a {
  color: #6B1F2C;
  text-decoration: underline;
}
.chat-msg--me .chat-msg__bubble a {
  color: #fff;
}
.chat-msg__meta {
  margin: 2px 4px 0;
  font-size: 11px;
  color: #9a918b;
}
.chat-msg.is-pending .chat-msg__bubble {
  opacity: 0.6;
}
.chat-msg.is-failed .chat-msg__meta {
  color: #c0392b;
  cursor: pointer;
}
.chat-msg.is-failed .chat-msg__bubble {
  opacity: 0.6;
  cursor: pointer;
}

.chat-note {
  align-self: center;
  max-width: 90%;
  margin: 4px 0;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  color: #6f6660;
}

.chat-contact {
  display: grid;
  /* «Имя» короткое — больше места полю «Почта или телефон» */
  grid-template-columns: 2fr 3fr;
  column-gap: 6px;
  flex-shrink: 0;
  margin: 0 12px 10px;
  padding: 12px;
  background: #faf7f5;
  border: 1px solid #eee4de;
  border-radius: 12px;
}
.chat-contact[hidden] {
  display: none;
}
/* Два поля в строку, остальное — на всю ширину: карточка не съедает переписку */
.chat-contact__title,
.chat-contact__agree,
.chat-contact__error,
.chat-contact__actions {
  grid-column: 1 / -1;
}
.chat-contact__title {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.chat-contact__input {
  display: block;
  width: 100%;
  min-width: 0;
  margin-bottom: 6px;
  padding: 8px 11px;
  font-size: 16px; /* 16px — iOS не зумит страницу при фокусе */
  color: #2d2824;
  background: #fff;
  border: 1px solid #d9d1cb;
  border-radius: 10px;
  box-sizing: border-box;
}
/* Поля узкие (два в строку): подсказка мельче, а сам текст остаётся 16px — иначе iOS зумит страницу */
.chat-contact__input::placeholder {
  font-size: 14px;
  color: #9a918b;
}
.chat-contact__input:focus,
.chat-panel__input:focus {
  outline: none;
  border-color: #6B1F2C;
  box-shadow: 0 0 0 3px rgba(107, 31, 44, 0.12);
}
.chat-contact__agree {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin: 4px 0 0;
  font-size: 11px;
  font-weight: normal;
  line-height: 1.4;
  color: #6f6660;
  cursor: pointer;
}
.chat-contact__agree input {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  margin: 1px 0 0;
  accent-color: #6B1F2C;
}
.chat-contact__agree a {
  color: #6B1F2C;
  text-decoration: underline;
}
.chat-contact__error {
  margin-top: 6px;
  font-size: 12px;
  color: #c0392b;
}
.chat-contact__error[hidden] {
  display: none;
}
.chat-contact__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.chat-contact__save {
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #6B1F2C;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.chat-contact__save:hover {
  background: #7C2837;
}
.chat-contact__save:disabled {
  opacity: 0.6;
  cursor: default;
}
.chat-contact__skip {
  padding: 8px 4px;
  font-size: 13px;
  color: #6f6660;
  background: none;
  border: none;
  cursor: pointer;
}
.chat-contact__skip:hover {
  color: #2d2824;
}

.chat-panel__error {
  flex-shrink: 0;
  margin: 0 12px 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #8a2a1f;
  background: #fbeeec;
  border-radius: 8px;
}
.chat-panel__error[hidden] {
  display: none;
}

.chat-panel__form {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  padding: 10px 12px 6px;
  border-top: 1px solid #eee4de;
}
.chat-panel__trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.chat-panel__input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.35;
  color: #2d2824;
  background: #fff;
  border: 1px solid #d9d1cb;
  border-radius: 20px;
  box-sizing: border-box;
  resize: none;
}
.chat-panel__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #fff;
  background: #6B1F2C;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.chat-panel__send:hover {
  background: #7C2837;
}
.chat-panel__send:disabled {
  opacity: 0.45;
  cursor: default;
}
.chat-panel__send svg {
  width: 20px;
  height: 20px;
}
.chat-panel__consent {
  flex-shrink: 0;
  margin: 0;
  padding: 0 14px 10px;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  color: #9a918b;
}
.chat-panel__consent a {
  color: inherit;
  text-decoration: underline;
}

/* Товар или заказ, о котором вопрос, — карточка в начале сообщения */
.chat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  margin: 0 0 6px;
  padding: 6px 8px;
  color: #2d2824 !important;
  text-decoration: none !important;
  background: #fff;
  border-radius: 10px;
}
.chat-card__thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.chat-card__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-card__label {
  font-size: 11px;
  color: #9a918b;
}
.chat-card__title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* Фото в сообщении: место занято заранее по пропорциям снимка */
.chat-msg__photo {
  display: block;
  width: 240px;
  max-width: 100%;
  margin: 2px 0 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 10px;
}
.chat-msg__photo:last-child {
  margin-bottom: 2px;
}
.chat-msg__photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-msg__text + .chat-msg__text,
.chat-msg__photo + .chat-msg__text,
.chat-card + .chat-msg__text {
  margin-top: 2px;
}

/* Вложения над полем ввода */
.chat-attach {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  padding: 8px 12px 0;
  border-top: 1px solid #eee4de;
}
.chat-attach[hidden] {
  display: none;
}
.chat-attach + .chat-panel__form {
  border-top: none;
}
.chat-attach__chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 4px 5px 6px;
  background: #faf7f5;
  border: 1px solid #eee4de;
  border-radius: 10px;
}
.chat-attach__thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.chat-attach__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-attach__label {
  font-size: 11px;
  color: #9a918b;
}
.chat-attach__title {
  max-width: 220px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-attach__remove {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: #9a918b;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.chat-attach__remove:hover {
  color: #2d2824;
  background: #f1ece8;
}

/* Стили темы показывают input[type=file] даже с hidden */
.chat-panel__file {
  display: none !important;
}
.chat-panel__clip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #9a918b;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.chat-panel__clip:hover {
  color: #6B1F2C;
  background: #f7f3f0;
}
.chat-panel__clip svg {
  width: 20px;
  height: 20px;
}

/* Телефон: окно на весь экран, страница под ним не прокручивается */
@media (max-width: 767px) {
  .site-chat {
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    transform: translateY(24px);
  }
  .site-chat .chat-panel {
    border-radius: 0;
    box-shadow: none;
  }
  body.chat-open {
    overflow: hidden;
  }
  .chat-panel--page {
    height: calc(100dvh - 140px);
    min-height: 420px;
  }
}

/* Страница «Чат с магазином» в кабинете. Кнопки связи в углу закрывали бы «Отправить»,
   а написать можно прямо здесь */
body:has(.account-chat) .floating-messenger {
  display: none;
}
.account-chat__lead {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: #6f6660;
}

/* «Задать вопрос» на странице заказа в кабинете — в пару кнопке «Отменить заказ» */
.order-detail__chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #6B1F2C;
  background: #fff;
  border: 1px solid rgba(107, 31, 44, 0.25);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.order-detail__chat-btn:hover {
  background: rgba(107, 31, 44, 0.05);
  border-color: rgba(107, 31, 44, 0.45);
}
