/* Мессенджер и чат поддержки.
 * Сюда выносятся статические inline-style (пункт 2 правок).
 * Префикс: chat-* для элементов чата; .msg-* — существующие базовые классы.
 *
 * Task-13: плотнее шапка/лента/поле ввода (без пустых зон), без аватара в шапке.
 * Task-15: шапка чата — имя + категория + локация, бегущая строка длинной
 * категории (только при переполнении, только телефон); кнопки отправки/вложения
 * на телефоне — иконки с aria-label; textarea.grow до 5 строк со скроллом и
 * кнопками по низу; бейдж «Гость #…».
 */

/* ---------- шапка и служебные элементы ---------- */
.chat-more { text-align: center; }
.chat-loading { min-height: 0; padding-top: 0; }
.chat-contents { display: contents; }

/* Плотнее шапка чата: без аватара название и подзаголовок занимают всю ширину. */
.chat-head {
  padding: 8px 11px;
  min-height: 48px;
  gap: 8px;
}

.chat-head-title {
  flex: 1;
  min-width: 0;
}

/* Имя + бейдж «Гость #N» (сторона организации): имя сжимается, бейдж — нет. */
.chat-head-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.chat-head-name-row .chat-head-name {
  min-width: 0;
}

.chat-head-guest {
  flex-shrink: 0;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--secondary);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chat-head-name {
  font-size: 14px;
  line-height: 1.25;
}

.chat-head-sub {
  font-size: 11.5px;
  line-height: 1.25;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Локация запроса в шапке: «Кемерово (Центральный)», одна строка с многоточием. */
.chat-head-loc {
  font-size: 10.5px;
  line-height: 1.25;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================================
   Бегущая строка длинной категории (по аналогии с .pub-cat-path на главной):
   включается только при переполнении на телефоне, цвета наследуются — тёмная
   тема и обычный чат не затрагиваются.
   ============================================================================ */

.chat-cat-marquee {
  display: block;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.chat-cat-marquee-track {
  display: inline-block;
  white-space: nowrap;
  will-change: transform;
}

/* Если путь категории не влезает — справа видно многоточие, даже когда
   строка прокручивается/обрезана. */
.chat-cat-marquee.is-overflow::after {
  content: '…';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding-left: 14px;
  color: var(--secondary);
  font-weight: 700;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0, var(--surface) 65%);
}

@keyframes chat-cat-marquee {
  0%,
  12% {
    transform: translateX(0);
  }

  46%,
  58% {
    transform: translateX(var(--chat-cat-shift, -80px));
  }

  94%,
  100% {
    transform: translateX(0);
  }
}

@media (max-width: 860px) {
  .chat-cat-marquee.is-overflow .chat-cat-marquee-track {
    animation-name: chat-cat-marquee;
    animation-duration: var(--chat-cat-duration, 12s);
    animation-timing-function: linear;
    animation-iteration-count: infinite;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-cat-marquee.is-overflow .chat-cat-marquee-track {
    animation: none;
    transform: none;
  }

  .chat-cat-marquee {
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
  }
}

/* ---------- сообщения ---------- */
.chat-messages {
  padding: 10px 11px;
  gap: 5px;
}

/* Desktop: лента не растягивается во всю ширину панели — колонка сообщений
   по центру (как в Telegram), пустые края по бокам. Mobile не меняется. */
@media (min-width: 861px) {
  .chat-messages {
    padding-left: max(13px, calc((100% - 780px) / 2));
    padding-right: max(13px, calc((100% - 780px) / 2));
  }

  .msg-bubble {
    max-width: min(72%, 620px);
  }
}

.msg-bubble {
  padding: 7px 11px;
  font-size: 14px;
  line-height: 1.38;
}

.msg-row-labeled { flex-direction: column; align-items: flex-start; }
.msg-row-labeled.mine { align-items: flex-end; }
.chat-sender-label {
  font-size: 11px; font-weight: 700; color: var(--tertiary);
  margin: 0 0 2px 4px; letter-spacing: 0.02em;
}
.chat-text { white-space: pre-wrap; }
.chat-edited { opacity: 0.6; }
.chat-failed { font-weight: 700; }
.chat-file-fallback {
  display: inline-block; padding: 5px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.10);
  font-size: 12.5px; margin: 3px 0; word-break: break-word;
}
.chat-retry-btn { width: auto; height: auto; padding: 0 3px; font-size: 11px; color: var(--accent); }
.chat-act-btn { width: auto; padding: 0 6px; font-size: 11px; }
.chat-edit-box { gap: 6px; }
.chat-row-end { justify-content: flex-end; }
.chat-confirm-row { gap: 6px; margin-top: 6px; }
.chat-upload-row { padding: 6px 0; }
.chat-send-btn { height: 36px; flex-shrink: 0; }

/* ---------- поле ввода: компактнее, safe-area не съедает место ---------- */
.chat-input {
  padding: 8px 10px;
  gap: 7px;
  /* По умолчанию кнопки прижаты к низу: выросшая textarea не сдвигает их вверх.
     Пока поле односрочное — кнопки выравниваются по центру textarea. */
  align-items: flex-end;
}

.chat-attach-btn,
.chat-send-btn {
  align-self: center;
}

.chat-input--multiline .chat-attach-btn,
.chat-input--multiline .chat-send-btn {
  align-self: flex-end;
}

.chat-input .textarea {
  min-height: 34px;
  /* Высоту считает JS (до 5 строк), дальше — вертикальный скролл.
     line-height фиксируем числом: тогда JS и рендер совпадают по высоте
     строки и в поле видно ровно 5 строк, без «половинки» шестой. */
  max-height: none;
  line-height: 1.42;
}

/* Кнопки отправки/вложения: на desktop у вложения — иконка-скрепка,
   у отправки — текст; на телефоне у обеих — иконка (самолётик/скрепка). */
.chat-btn-ico {
  display: none;
  align-items: center;
  justify-content: center;
}

.chat-btn-ico svg {
  display: block;
}

/* Скрепка — иконка на всех ширинах: подписи в кнопке вложения нет. */
.chat-attach-btn .chat-btn-ico {
  display: inline-flex;
}

.chat-attach-btn,
.chat-send-btn {
  justify-content: center;
}

.chat-attach-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
}

.chat-readonly-note {
  min-width: 0;
  line-height: 1.35;
}

/* ---------- системные карточки (без иконок, компактно) ---------- */
.chat-system-row { display: flex; justify-content: center; margin: 2px 0; }
.chat-system-card {
  max-width: min(440px, 100%); padding: 9px 13px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border); text-align: center; font-size: 13px;
}
.chat-system-pill {
  max-width: min(440px, 100%); padding: 4px 12px; border-radius: 999px; font-size: 12.5px;
  color: var(--secondary); background: var(--surface-2); border: 1px solid var(--border);
  text-align: center; line-height: 1.35; white-space: pre-wrap;
}
.chat-rating-title { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.chat-rating-sub { font-size: 12.5px; color: var(--secondary); margin-bottom: 8px; }
.chat-rating-sub.is-done { margin-bottom: 6px; }
.chat-rating-done { font-weight: 800; font-size: 13.5px; color: var(--accent); }
.chat-rating-grid {
  display: grid; grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px; max-width: 360px; margin: 0 auto;
}
.chat-rating-btn { padding: 0; height: 28px; min-width: 0; font-size: 12.5px; font-weight: 700; }
.chat-rating-wait { font-size: 12.5px; color: var(--secondary); }
.chat-rating-busy { font-size: 12px; color: var(--tertiary); margin-top: 6px; }

/* ============================================================================
   Мобильный мессенджер: ещё плотнее, без пустых полос, safe-area и клавиатура
   ============================================================================ */

@media (max-width: 860px) {
  .chat-head {
    padding: 4px 6px;
    min-height: 40px;
    gap: 4px;
  }

  /* Кнопки «назад»/«три точки» — компактные, но с удобной зоной нажатия. */
  .chat-back-arrow,
  .chat-actions-trigger {
    width: 34px;
    min-width: 34px;
    height: 34px;
    padding: 0;
  }

  .chat-head-name {
    font-size: 13.5px;
  }

  .chat-head-sub {
    font-size: 11px;
  }

  .chat-messages {
    padding: 6px 6px 4px;
    gap: 4px;
  }

  .msg-bubble {
    max-width: min(82%, 560px);
    padding: 6px 9px;
    font-size: 13.5px;
    line-height: 1.35;
  }

  .msg-date-sep {
    padding: 3px 0;
    font-size: 11px;
  }

  .msg-meta {
    font-size: 10px;
    margin-top: 2px;
    gap: 4px;
  }

  .chat-input {
    padding: 5px 6px;
    gap: 5px;
    padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
  }

  /* Пока открыта клавиатура, нижнее меню скрыто — safe-area не нужен. */
  body.keyboard-open .chat-input {
    padding-bottom: 5px;
  }

  .chat-input .textarea {
    min-height: 32px;
    max-height: none;
    font-size: 14px;
  }

  .chat-input .btn {
    min-height: 32px;
  }

  /* Телефон: у кнопок отправки/вложения — иконки (самолётик/скрепка), подписи скрыты. */
  .chat-btn-label {
    display: none;
  }

  .chat-btn-ico {
    display: inline-flex;
  }

  .chat-attach-btn,
  .chat-send-btn {
    width: 34px;
    min-width: 34px;
    height: 32px;
    padding-left: 0;
    padding-right: 0;
  }

  .chat-system-card {
    padding: 7px 10px;
    font-size: 12.5px;
  }

  .chat-system-pill {
    font-size: 12px;
    padding: 3px 10px;
  }

  .chat-file-fallback {
    font-size: 12px;
  }

  .chat-upload-row {
    padding: 2px 0;
  }
}
