/* Переписка «John Connor»: админка чата. Вырезка из CMS Bodymanual Shop. */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* hidden должен скрывать элемент даже там, где класс задаёт display */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #212121;
  background: #eef1f4;
}

/* Каркас панели: страница ровно в экран и сама не прокручивается. Шапка и
   строка ответа — обычные полосы сверху и снизу, прокручивается только
   середина. Иначе в длинной переписке поле ввода уезжает под низ страницы,
   и чтобы ответить, приходится сначала долистать до конца. */
html { height: 100%; }
body {
  /* Три рубежа по убыванию точности: видимая часть окна от браузера (её
     сообщает даже старый Safari), динамический dvh и, для совсем древних
     движков, 100vh. Только 100vh врёт: это высота БЕЗ панелей браузера, и
     строка ответа уезжает под них, а прокрутки у страницы больше нет. */
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
html.has-visible-height body { height: var(--visible-height); }
.topbar, .build-notice, .mode-banner, .archive-banner, .import-banner { flex: 0 0 auto; }
main { flex: 1 1 auto; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 100%;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #dde3e9;
  /* z-index оставлен: под шапкой проезжают пузыри и палитра эмодзи */
  position: relative;
  z-index: 5;
}
.topbar h1 { font-size: 17px; }
.refresh-state { color: #8a949e; font-size: 12px; margin-left: auto; }

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

.chats {
  display: flex;
  gap: 12px;
  padding: 16px 20px 24px;
  min-height: 0;
  align-items: stretch;
}
.chat-list {
  flex: 0 0 300px;
  min-height: 0;
  background: #fff;
  border-radius: 12px;
  overflow-y: auto;
  padding: 6px;
}
.chat-item {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1.45;
}
.chat-item:hover { background: #eef1f4; }
.chat-item.is-active { background: #e3f4ec; }
/* overflow-wrap: имя из одного длинного слова (почта, ник) уходило за край строки, а
   content-visibility ниже обрезало его без «…» */
.chat-item .who { font-weight: 700; overflow-wrap: anywhere; }
.chat-item .preview {
  color: #66707a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item .when { color: #99a3ad; font-size: 11.5px; }

.chat-view {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
/* Шапка переписки и строка ответа не сжимаются — они всегда на экране. Потолки
   в долях окна срабатывают только на совсем низком окне (телефон боком): там
   полоса начинает прокручиваться сама, но не выталкивает соседей за экран.
   Потолок шапки высокий: при 40% за её край уезжали «Служебные события» и
   «Отметить прочитанными», а прокрутка внутри шапки ничем не обозначена и
   оператор кнопок просто не видел. На низком экране шапку ужимает media ниже. */
.chat-header {
  flex: 0 0 auto;
  max-height: 60%;
  overflow-y: auto;
  padding: 12px 16px;
  border-bottom: 1px solid #eef1f4;
  font-weight: 700;
}
.chat-header .sub { font-weight: 400; font-size: 12.5px; color: #7b8794; margin-top: 2px; }
/* Единственное, что прокручивается в переписке: лента сообщений */
.chat-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 16px; }
.bubble {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: 12px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.in { background: #eef1f4; }
.bubble.out { background: #d7f0e4; margin-left: auto; }
.bubble .meta { font-size: 11.5px; color: #7b8794; margin-top: 4px; }
/* Внутри строки ответа жмётся только палитра эмодзи — поле ввода и кнопки
   остаются на месте. Сжимать саму строку нельзя: flex-basis ленты сообщений
   равен её полной высоте, и при пропорциональном сжатии flex отдаёт строке
   ответа почти нулевую высоту — проверено, кнопки уезжали за экран. */
.chat-form { flex: 0 0 auto; max-height: 45%; overflow-y: auto;
             display: flex; gap: 8px; padding: 12px 16px;
             border-top: 1px solid #eef1f4; }
.chat-form > .reply-strip, .chat-form > textarea,
.chat-form > .chat-form-row { flex: 0 0 auto; }
.chat-form textarea {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  border: 1.5px solid #cfd7df;
  border-radius: 10px;
  padding: 9px 11px;
  resize: none;
  min-height: 44px;
}
.chat-empty { color: #8a949e; padding: 24px 16px; }

.chat-back {
  display: none;
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: #46525e;
  cursor: pointer;
  padding: 0 10px 0 0;
  align-self: center;
}

.btn {
  display: inline-block;
  background: #00ac6e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  margin: 4px 6px 4px 0;
}
.btn:hover { background: #009860; }
.btn.danger { background: #d9534f; }
.btn.danger:hover { background: #c9433f; }
.btn.secondary { background: #e3e8ee; color: #212121; }
.btn.secondary:hover { background: #d5dce4; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* Модальные окна */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 30, 0.5);
  z-index: 30;
}
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 420px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  z-index: 31;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
  /* Страница не прокручивается, значит окно обязано прокручиваться само:
     длинная форма (адрес, возврат по нескольким платежам) иначе уносит
     кнопку «Сохранить» за край экрана, и нажать её нечем. */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.modal h2 { font-size: 16px; margin-bottom: 12px; }
.modal p { line-height: 1.55; margin-bottom: 10px; }
.modal label { display: block; font-weight: 600; margin: 10px 0 4px; }
.modal input, .modal textarea, .modal select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  border: 1.5px solid #cfd7df;
  border-radius: 8px;
  padding: 9px 10px;
}
/* Кнопки прилипают к низу окна: в длинной форме до них иначе надо долистать */
.modal .actions {
  position: sticky;
  bottom: -22px;
  margin: 16px -22px -22px;
  padding: 12px 22px 22px;
  background: #fff;
  text-align: right;
}
.modal .warn { color: #b3402f; font-weight: 600; }
.modal ul { margin: 8px 0 8px 18px; line-height: 1.6; }

.chat-empty .hint {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #6b7671;
}
.chat-empty .hint:first-of-type { margin-top: 12px; font-weight: 600; color: #3d4a44; }

/* ---------------------------------------- переписка: непрочитанное и профиль */

.tab-badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 9px;
  background: #d9534f;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.who-am-i { color: #4b5560; font-size: 12.5px; }

.avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #cfd8e0;
  color: #46525e;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-item { display: flex; align-items: flex-start; gap: 10px; }
.chat-item-body { min-width: 0; flex: 1; }
.chat-item.is-unread .who { color: #00a86b; }
.chat-item .badge {
  flex: 0 0 auto;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #00a86b;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}

/* Шапка переносится на вторую строку, когда кнопки и переключатель
   перестают помещаться: имя собеседника важнее, чем один ряд. */
.chat-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 8px; }
.chat-titles { flex: 1 1 240px; min-width: 0; }
.chat-header .name { font-weight: 700; overflow-wrap: anywhere; }
.chat-header .sub, .chat-titles .answered { overflow-wrap: anywhere; }
.chat-header .btn { flex: 0 0 auto; }

.bubble { position: relative; }
.bubble.in.is-unread { box-shadow: inset 3px 0 0 #00a86b; }
.bubble .quote {
  font-size: 12px;
  color: #5d6b78;
  border-left: 2px solid #b9c6d1;
  padding-left: 8px;
  margin-bottom: 4px;
}

.btn.ghost {
  background: #e3e8ee;
  color: #46525e;
  display: block;
  margin: 0 auto 10px;
}
.btn.ghost:hover { background: #d5dce4; }

/* ------------------------------------------------------- ответ и эмодзи */

.chat-form { flex-direction: column; align-items: stretch; }
.chat-form-row { display: flex; align-items: center; gap: 8px; }
.chat-form-row .btn { margin-left: auto; }
.emoji-toggle {
  border: 1px solid #dde3e9;
  background: #fff;
  border-radius: 8px;
  font-size: 17px;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
}
.emoji-toggle:hover { background: #f3f6f9; }
.emoji-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  margin-bottom: 8px;
  background: #f3f6f9;
  border-radius: 8px;
  /* Единственная часть строки ответа, которой можно пожертвовать: когда места
     не хватает, сжимается и прокручивается она, а не кнопки. */
  flex: 0 1 auto;
  min-height: 0;
  max-height: 22vh;
  overflow-y: auto;
}
.emoji-palette button {
  border: 0;
  background: none;
  font-size: 19px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 6px;
  cursor: pointer;
}
.emoji-palette button:hover { background: #e0e7ee; }

/* -------------------------------------------- фильтр и страницы переписки */

/* Поиск и вкладки стоят над списком и не уезжают при прокрутке. */
.chat-list-head {
  position: sticky;
  top: 0;
  margin: -6px -6px 0;     /* на всю ширину, поверх отступов самого списка */
  padding: 6px 6px 0;
  background: #fff;
  z-index: 1;
  border-bottom: 1px solid #eef1f4;
}
.chat-search { position: relative; margin: 4px 6px 0; }
.chat-search input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #dde3e9;
  border-radius: 18px;
  background: #f5f7f9;
  padding: 8px 54px 8px 34px;
  font: inherit;
  font-size: 13.5px;
  color: #1f2a33;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.chat-search input:focus { border-color: #00a86b; background: #fff; box-shadow: 0 0 0 3px rgba(0, 168, 107, .12); }
.chat-search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
/* Лупа нарисована рамками: без картинок и без отдельного запроса. */
.chat-search::before, .chat-search::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.chat-search::before {
  left: 13px;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-top: -7px;
  border: 2px solid #99a3ad;
  border-radius: 50%;
}
.chat-search::after {
  left: 23px;
  top: 50%;
  width: 2px;
  height: 6px;
  margin-top: 2px;
  background: #99a3ad;
  border-radius: 1px;
  transform: rotate(-45deg);
}
.chat-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  width: 26px;
  height: 26px;
  margin-top: -13px;
  display: none;
  border: none;
  border-radius: 50%;
  background: none;
  color: #8a949e;
  font-size: 18px;
  line-height: 26px;
  padding: 0;
  cursor: pointer;
}
.chat-search-clear:hover { background: #eef1f4; color: #3d4a44; }
.chat-search.has-text .chat-search-clear { display: block; }
.chat-search-busy {
  position: absolute;
  right: 34px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -8px;
  display: none;
  border: 2px solid #d5dce2;
  border-top-color: #00a86b;
  border-radius: 50%;
  animation: chat-search-spin .7s linear infinite;
}
.chat-search.is-busy .chat-search-busy { display: block; }
@keyframes chat-search-spin { to { transform: rotate(360deg); } }
.chat-found { padding: 8px 12px 2px; font-size: 12px; color: #8a949e; }
.chat-item mark {
  background: #ffe27a;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}
.chat-match {
  font-size: 12.5px;
  color: #4b5560;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-match-label { color: #8a949e; }
.chat-item .preview.is-quiet { color: #99a3ad; }
.chat-list .btn.chat-more { display: block; }

.chat-filters {
  display: flex;
  gap: 4px;
  padding: 8px 6px 10px;
}
.chat-filter {
  border: 1px solid #dde3e9;
  background: #fff;
  border-radius: 16px;
  padding: 5px 9px;
  white-space: nowrap;
  font: inherit;
  font-size: 12px;
  color: #4b5560;
  cursor: pointer;
}
.chat-filter:hover { background: #f3f6f9; }
.chat-filter.is-active { background: #00a86b; border-color: #00a86b; color: #fff; }
.chat-list .btn.ghost { margin: 10px auto; }

.modal select {
  padding: 9px 11px;
  border: 1px solid #dde3e9;
  border-radius: 8px;
  font: inherit;
  width: 100%;
}
.modal .hint { color: #5d6b78; font-size: 12.5px; }

.bubble .delivery.sending { color: #a08b3a; }
.bubble .delivery.sent { color: #4b8f6b; }
.bubble .delivery.failed { color: #d9534f; font-weight: 600; }
.bubble .delivery.cancelled { color: #99a3ad; }
.bubble .delivery.unknown { color: #c77c1e; font-weight: 600; }
/* Галочки: серая — на сервере, зелёная — в Telegram, две — видел. */
.bubble .ticks { font-size: 13px; font-weight: 700; letter-spacing: -3px; margin-right: 3px; cursor: help; }
.bubble .delivery-error { margin-left: 4px; }
.bubble .ticks.is-queued { color: #aab4bd; }
.bubble .ticks.is-sent { color: #4b8f6b; }
.bubble .ticks.is-seen { color: #1e88e5; }
.bubble .ticks.is-clock { letter-spacing: 0; font-weight: 400; }
.bubble.is-pending { opacity: .75; }
.bubble .delivery-error { color: #8a6d3b; }
.bubble-tool.is-resend { color: #d9534f; font-weight: 600; }

/* Имя кейфрейма осталось от оригинала (окно возврата); его использует спиннер диктовки */
@keyframes refund-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .dictation-status.is-working::before { animation: none; }
  .dictation-status.is-live::before { animation: none; }
}

/* Кто написал сообщение: оператор — своим именем и цветом, бот — пометкой */

.bubble .author {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 3px;
}
.bubble .author.system { color: #7b8794; font-weight: 600; }
.chat-titles .answered {
  font-size: 11.5px;
  font-weight: 400;   /* иначе наследует жирность шапки и спорит с именем */
  color: #7b8794;
  margin-top: 2px;
}
.chat-item .preview .by { color: #1f6b4a; font-weight: 700; }
.chat-item .preview .by.system { color: #7b8794; font-weight: 600; }

/* Вложения в переписке */

.bubble .media { margin: 2px 0 6px; }
.bubble .media-image img {
  display: block;
  max-width: min(320px, 100%);
  max-height: 320px;
  border-radius: 8px;
}
.bubble .media video { max-width: min(320px, 100%); border-radius: 8px; display: block; }
.bubble .media audio { width: min(260px, 100%); display: block; }
.bubble .media-file { max-width: 100%; }
.bubble .media-file {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  color: #1f4b7a;
  text-decoration: none;
  font-size: 13px;
}
.bubble .media-file:hover { text-decoration: underline; }
.bubble .media-name { font-weight: 600; overflow-wrap: anywhere; }
.bubble .media-size { color: #7b8794; font-size: 11.5px; }
.bubble .media-note { font-size: 12px; color: #5d6b78; margin-top: 3px; }

/* Ответ на конкретное сообщение */

.reply-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 6px 10px;
  border-left: 3px solid #00a86b;
  background: #f1f5f8;
  border-radius: 6px;
  font-size: 12.5px;
  color: #46525e;
}
.reply-strip-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-strip-drop {
  border: 0;
  background: none;
  color: #8a949e;
  font-size: 14px;
  cursor: pointer;
}

/* Действия над сообщением: одной строкой, появляются при наведении */

.bubble-tools {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity .12s;
}
.bubble:hover .bubble-tools, .bubble:focus-within .bubble-tools { opacity: 1; pointer-events: auto; }
/* Невидимые действия не должны ловить нажатие: на телефоне первое касание
   только показывает строку, а не ставит собеседнику реакцию вслепую. */
.bubble-tools { pointer-events: none; }
.bubble-tool {
  border: 0;
  background: none;
  color: #8a949e;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.bubble-tool:hover { color: #00875a; text-decoration: underline; }
.bubble .meta .edited { color: #7b8794; }
.bubble .meta .deleted { color: #b35b00; }
.bubble.is-deleted .text { text-decoration: line-through; color: #7b8794; }

.chat-body .history-start {
  margin: 4px auto 12px;
  padding: 7px 12px;
  max-width: 80%;
  border-radius: 8px;
  background: #f5f7f9;
  color: #7b8794;
  font-size: 12px;
  text-align: center;
}

/* Расшифровка вложения прямо в сообщении: голос — текстом, фото — словами */

.media-text {
  margin-top: 6px;
  padding: 8px 10px;
  border-left: 3px solid #b9c6d1;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 0 8px 8px 0;
}
.bubble.out .media-text { background: rgba(255, 255, 255, 0.45); }
.media-text-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #7b8794;
  margin-bottom: 3px;
}
.media-text-body {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.media-text-body.is-short {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.media-wait { margin-top: 6px; font-size: 12px; color: #8a949e; font-style: italic; }
.media-text-more {
  margin-top: 4px;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: #00694a;
  text-decoration: underline;
  cursor: pointer;
}

/* Диктовка: одно окно на всю работу — говорим, причёсываем, правим */

.modal.is-dictation { width: 560px; }
.dictation-meter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.dictation-wave {
  flex: 1;
  min-width: 0;
  height: 44px;
  background: #f5f7f9;
  border-radius: 8px;
}
.dictation-timer {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 700;
  color: #46525e;
  flex: 0 0 auto;
}

/* Окно проверки: строка состояния, расшифровка и готовый текст */
.dictation-status {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
}
.dictation-status.is-live { color: #00694a; }
.dictation-status.is-live::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  vertical-align: 0;
  border-radius: 50%;
  background: #d9534f;
  animation: dictation-pulse 1.4s ease-in-out infinite;
}
@keyframes dictation-pulse { 50% { opacity: 0.25; } }
.dictation-status.is-working { color: #a08b3a; }
.dictation-status.is-working::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid #e0d3a0;
  border-top-color: #a08b3a;
  border-radius: 50%;
  animation: refund-spin 0.8s linear infinite;
}
.dictation-status.is-ready { color: #00694a; }
.dictation-status.is-failed { color: #d9534f; }

.dictation-raw {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-left: 3px solid #cfd7df;
  background: #f5f7f9;
  border-radius: 0 8px 8px 0;
  max-height: 7em;
  overflow-y: auto;
}
.dictation-raw-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #8a949e;
  margin-bottom: 2px;
}
.dictation-raw-text { font-size: 13px; line-height: 1.45; color: #46525e; }
.dictation-text[readonly] { background: #f8fafb; color: #46525e; }
/* Пока текст набирается моделью, поле подсвечено: видно, что он ещё пишется */
.dictation-text.is-writing { border-color: #9fdcc0; background: #fbfffd; }

.dictation-text {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  border: 1.5px solid #cfd7df;
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
}
.dictation-raw {
  font-size: 12px;
  color: #7b8794;
  margin-top: 8px;
  line-height: 1.45;
}

/* Входы: мои устройства, все входы и журнал безопасности */

.who-am-i {
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  color: #4b5560;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.who-am-i:hover { background: #eef1f4; }
.login-remember { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 12px; }
.login-remember input { width: auto; }
/* Ловушка для ботов: убрана с экрана, но не display:none — такое боты пропускают */
.login-trap { position: absolute; left: -10000px; width: 1px; height: 1px; opacity: 0; }
.sessions { margin: 6px 0 4px; }
.session { border-top: 1px solid #eef1f4; padding: 10px 0; }
.session.is-current { background: #f5fbf8; margin: 0 -8px; padding: 10px 8px; border-radius: 8px; }
.session-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.session-device { font-weight: 600; }
.session-flag { font-size: 11.5px; color: #00694a; }
.session-meta { font-size: 12.5px; color: #7b8794; margin: 3px 0 6px; line-height: 1.45; }
.session .btn { padding: 4px 10px; font-size: 12.5px; }

.no-access {
  margin: 40px auto;
  max-width: 420px;
  padding: 18px 20px;
  background: #fff;
  border-radius: 12px;
  text-align: center;
  color: #46525e;
  line-height: 1.5;
}

/* «Панель обновилась»: вкладка живёт неделями, код в ней успевает устареть */
.build-notice {
  padding: 8px 20px;
  background: #e8f1fb;
  border-bottom: 1px solid #c3daf2;
  color: #1f4d7a;
  font-size: 13px;
}
.link-button {
  border: 0;
  background: none;
  font: inherit;
  font-weight: 700;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* Низкое окно (телефон боком, маленькое окно на ноутбуке): режем высоту самой
   шапки чата, иначе она съедает переписку и упирается в свой потолок. */
@media (max-height: 430px) {
  .chats { padding: 8px; }
  .chat-header { padding: 8px 12px; row-gap: 4px; }
  .chat-header .sub, .chat-titles .answered { display: none; }
  .chat-header .btn { padding: 4px 8px; font-size: 12px; }
  .chat-body { padding: 8px 12px; }
  .chat-form { padding: 8px 12px; }
}

/* ------------------------------------ агенты в переписке: черновики и подписи */

/* Всё, что сделал ИИ-агент, — в одном сиреневом цвете: пузырь, подпись,
   черновик, пометка в списке. Цвет не зелёный (это люди и бот) и не
   рыжий (это предупреждения), поэтому «писал не человек» читается сразу,
   но не пугает. */

.bubble.out.is-agent { background: #ebe6f7; }
.bubble .author.is-agent { color: #5b3fa0; }
.chat-item .preview .by.is-agent { color: #5b3fa0; }

/* Пометка «черновик» в списке — в строке времени, чтобы не спорить с именем
   и счётчиком непрочитанных. */
.chat-draft-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 20px;
  background: #efe9fb;
  color: #5b3fa0;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
}

/* Черновики над полем ответа. Не сжимаются, а прокручиваются внутри своего
   потолка — по той же причине, что и строка ответа (см. .chat-form): при
   пропорциональном сжатии длинная лента отдала бы им почти нулевую высоту. */
.chat-drafts {
  flex: 0 0 auto;
  max-height: 40%;
  overflow-y: auto;
  padding: 10px 16px 0;
  border-top: 1px solid #eef1f4;
}
.agent-draft {
  margin-bottom: 10px;
  padding: 8px 12px 10px;
  border: 1px solid #ddd3f3;
  border-left: 3px solid #7b5cc4;
  border-radius: 10px;
  background: #f7f4fd;
}
.agent-draft-head { font-size: 12px; font-weight: 700; color: #5b3fa0; overflow-wrap: anywhere; }
.agent-draft-when { font-weight: 400; color: #8a949e; }
/* Длинный черновик читается внутри карточки: кнопки под ним всегда видны */
.agent-draft-text {
  margin: 4px 0 8px;
  max-height: 9em;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.agent-draft-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.agent-draft-actions .btn { margin: 0; padding: 5px 12px; font-size: 12.5px; }
/* «Отклонить» — в стороне от «Отправить», чтобы не промахнуться */
.agent-draft-actions .agent-draft-drop { margin-left: auto; }

/* Полоса над полем, пока в нём правят черновик: как «в ответ на», но в цвете агента */
.reply-strip.is-draft { border-left-color: #7b5cc4; background: #f7f4fd; }
.reply-strip.is-draft.is-gone { border-left-color: #d9534f; background: #fdf0ee; color: #b3402f; }

@media (max-height: 430px) {
  .chat-drafts { max-height: 35%; padding-top: 6px; }
  .agent-draft { padding: 6px 10px 8px; margin-bottom: 6px; }
  .agent-draft-text { max-height: 4.5em; }
}
@media (max-width: 760px) {
  .chat-drafts { padding: 8px 12px 0; }
  /* На телефоне кнопку жмут пальцем: чуть крупнее, «Отклонить» остаётся справа */
  .agent-draft-actions .btn { padding: 7px 12px; }
}

/* Сообщение оператора, отправленное по черновику агента: пометка тише подписи,
   чтобы не спорить с именем того, кто на самом деле решил отправить. */
.bubble .author .author-draft {
  color: var(--muted, #8a8f98);
  font-weight: 400;
}

/* Меню «⋯» в шапке переписки: редкие действия, чтобы шапка не разрасталась */
.chat-menu { position: relative; flex: 0 0 auto; }
.chat-menu-toggle { font-size: 18px; line-height: 1; padding: 6px 12px; letter-spacing: 1px; }
.chat-menu-list {
  position: fixed; z-index: 60; width: min(290px, calc(100vw - 16px));
  background: #fff; border: 1px solid #e3e8ec; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20, 30, 40, 0.14); padding: 6px;
  /* высоту ограничивает JS по месту в окне; что не влезло — прокручивается */
  overflow-y: auto; overscroll-behavior: contain;
}
.chat-menu-item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  border-radius: 8px; padding: 9px 10px; cursor: pointer; font: inherit;
}
.chat-menu-item:hover, .chat-menu-item:focus-visible { background: #f2f5f4; outline: none; }
.chat-menu-label { font-weight: 600; font-size: 13.5px; color: #1f2a33; }
.chat-menu-hint { font-weight: 400; font-size: 12px; color: #7b8794; margin-top: 2px; }
.chat-menu-item.danger .chat-menu-label { color: #c0392b; }

/* Кнопки под сообщением — так, как их увидел собеседник в Telegram */
.msg-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-button {
  flex: 1 1 160px; background: rgba(255, 255, 255, 0.75); border: 1px solid #cfd8d3;
  border-radius: 10px; padding: 7px 10px; text-align: center;
}
.msg-button-text { font-weight: 600; color: #2f7d5a; font-size: 13.5px; }
.msg-button-target {
  color: #7a8680; font-size: 11.5px; margin-top: 2px; overflow-wrap: anywhere;
}

.modal.wide { width: 760px; max-height: 80vh; overflow-y: auto; }

/* Реакции: под текстом сообщения, как в Telegram. Собеседника — просто значок,
   наша — кнопка (нажать — убрать). */
.bubble .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; white-space: normal; }
.bubble .reaction {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .75);
  border: 1px solid #d5dde4;
}
.bubble .reaction.is-ours { border-color: #9fdcc0; background: #e3f4ec; cursor: pointer; font-family: inherit; }
.bubble .reaction.is-ours:hover { border-color: #00a86b; }
.bubble-tools .react-bar { display: inline-flex; gap: 2px; margin-left: 2px; }
.react-pick {
  border: 0;
  background: none;
  font-size: 15px;
  line-height: 1;
  padding: 1px 3px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.react-pick:hover { background: #e3f4ec; }
.react-pick.is-on { background: #cdeedd; box-shadow: inset 0 0 0 1px #00a86b; }
.react-pick.react-more { font-size: 12px; color: #8a949e; }
.reaction-picker {
  position: fixed;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(9, 30px);
  gap: 2px;
  padding: 8px;
  background: #fff;
  border: 1px solid #dfe5ea;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 40, 60, .16);
  max-width: calc(100vw - 16px);
}
.reaction-picker .react-pick { font-size: 19px; padding: 4px 0; }

/* Проверка набранного ответа перед отправкой */
.check-anchor {
  font-size: 12.5px;
  color: #46525e;
  border-left: 3px solid #00a86b;
  background: #f1f5f8;
  padding: 6px 10px;
  border-radius: 0 6px 6px 0;
  margin: 0 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.check-original, .check-diff {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 10px 12px;
  background: #f8fafb;
  border: 1.5px solid #e3e8ed;
  border-radius: 10px;
  max-height: 14em;
  overflow-y: auto;
  margin-bottom: 10px;
}
.check-diff-wrap .dictation-raw-label, .check-fixed-label { margin-bottom: 4px; }
.check-diff del { color: #b3261e; background: #fdecea; text-decoration: line-through; }
.check-diff ins { color: #00694a; background: #d9f3e6; text-decoration: none; }
/* Убранное и вставленное рядом не должны слипаться в одно слово */
.check-diff del + ins { margin-left: 3px; }
@media (max-width: 640px) {
  .reaction-picker { grid-template-columns: repeat(7, 34px); }
  .bubble-tools { flex-wrap: wrap; }
}

/* ------------------------------------------- John Connor: новое в интерфейсе */

/* Плашки под шапкой. Режим отправки виден всегда: это единственный признак того,
   уходят ли ответы живым людям. */
.mode-banner {
  padding: 7px 20px;
  background: #eef1f4;
  border-bottom: 1px solid #dde3e9;
  color: #4b5560;
  font-size: 13px;
  font-weight: 600;
}
.mode-banner.is-dryrun { background: #f3f0dc; border-bottom-color: #e3dcae; color: #5d5630; }
.mode-banner.is-off { background: #e8ebee; border-bottom-color: #d5dbe0; color: #4b5560; }
.mode-banner.is-live { background: #d9534f; border-bottom-color: #a93226; color: #fff; }
.archive-banner {
  padding: 8px 20px;
  background: #fdecea;
  border-bottom: 1px solid #f3c6c1;
  color: #8a1f17;
  font-size: 13px;
  font-weight: 600;
}
.import-banner {
  padding: 8px 20px;
  background: #e8f1fb;
  border-bottom: 1px solid #c3daf2;
  color: #1f4d7a;
  font-size: 13px;
}

/* Фильтры списка: бот, статус, «покупатели (Leeloo)» */
.chat-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 6px 10px;
}
.chat-filter-select {
  flex: 1 1 110px;
  min-width: 0;
  border: 1px solid #dde3e9;
  background: #fff;
  border-radius: 16px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
  color: #4b5560;
}
.chat-filter-toggle { flex: 0 0 auto; }
.chat-search-hint { padding: 3px 14px 0; font-size: 12px; color: #8a7a2f; }
.chat-empty .chat-reset { margin-top: 12px; }

/* Длинные списки: строки вне экрана браузер не раскладывает. Оценка высоты — близкая к
   настоящей (строка с метками и превью ≈ 84 px, измерено в Chrome): список перерисовывается
   целиком, «запомненные» высоты теряются, и с оценкой 64 px место чтения уезжало на 5 строк. */
.chat-item { content-visibility: auto; contain-intrinsic-size: auto 84px; }

/* Метки: бот, статус, канал, «ID неизвестен», «покупатель (Leeloo)», замок */
.chat-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.chip {
  display: inline-block;
  padding: 0 7px;
  border-radius: 20px;
  background: #eef1f4;
  color: #5d6b78;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  /* название бота пишет владелец: слишком длинное не должно раздвигать строку */
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-bot { background: #e6eefb; color: #2b4f86; }
.chip-life { background: #eceff2; color: #5d6b78; }
.chip-noid { background: #fff0d6; color: #8a5200; }
.chip-channel { background: #e0eff2; color: #24616d; }
.chip-buyer { background: #e3f4ec; color: #00694a; }
.chip-lock { background: #fdecea; color: #8a1f17; }

/* Теги человека в шапке чата: цветная точка и название */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px 0 6px;
  border: 1px solid #e3e8ec;
  border-radius: 20px;
  background: #f7f9fb;
  color: #46525e;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.6;
}
.tag.is-important { font-weight: 700; }
/* «+N» открывает карточку; виден только там, где лишние теги спрятаны (узкий экран) */
.tag-more { display: none; font-family: inherit; cursor: pointer; }
.tag-more:hover { background: #eef1f4; }
.tag-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #99a3ad; }

/* Короткое подтверждение («скопировано»): поверх всего, включая окна */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: #26323d;
  color: #fff;
  font-size: 13.5px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(20, 30, 40, 0.25);
  pointer-events: none;
}

.service-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 400;
  color: #4b5560;
  cursor: pointer;
  user-select: none;
}

/* Лента: разделители дней и служебные строки (подписка, паузы воронок) */
.day-sep {
  width: fit-content;
  max-width: 90%;
  margin: 14px auto 10px;
  padding: 3px 12px;
  border-radius: 20px;
  background: #f1f4f7;
  color: #7b8794;
  font-size: 12px;
  text-align: center;
}
.bubble-service {
  max-width: 88%;
  margin: 4px auto 10px;
  color: #7b8794;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
}
.bubble-service .service-when { color: #99a3ad; }
.bubble-service.is-hidden-event { color: #aab4bd; font-size: 11.5px; font-style: italic; }
.bubble-service.is-hidden-event .service-when { color: #bcc4cb; }

/* Сообщения бота (воронки, рассылки): исходящие, но без зелёного акцента операторских */
.bubble.out.is-bot { background: #f3f5f7; border: 1px solid #e3e8ec; }

/* Режим dryrun: ответ сохраняется только в админке */
.bubble .ticks.is-local { color: #8a949e; font-size: 11.5px; font-weight: 600; letter-spacing: 0; }
.dry-hint { font-size: 12px; color: #8a7a2f; }
/* live: под полем ответа — через какого бота уйдёт сообщение */
.live-hint { font-size: 12px; color: #b3402f; font-weight: 600; }

/* Боты и токены (администратор) */
.modal.is-bots { width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; }
.bots-admin { margin: 6px 0 4px; }
.bot-admin { border-top: 1px solid #eef1f4; padding: 10px 0; }
.bot-admin.is-live { background: #fdf4f2; margin: 0 -8px; padding: 10px 8px; border-radius: 8px; }
.bot-admin-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.bot-admin-name { font-weight: 600; overflow-wrap: anywhere; }
.bot-admin-user { font-size: 12.5px; color: #5d6b78; overflow-wrap: anywhere; }
.bot-admin-flag { margin-left: auto; font-size: 11.5px; color: #7b8794; }
.bot-admin-flag.is-on { color: #b3402f; font-weight: 600; }
.bot-admin-meta { font-size: 12.5px; color: #7b8794; margin: 3px 0 6px; line-height: 1.45; }
.bot-admin-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bot-admin-tools .btn { padding: 4px 10px; font-size: 12.5px; }

/* Вложение, которого нет на диске: причина словами */
.bubble .media-note.is-unavailable {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed #c8d0d7;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
}
.media-note-icon { flex: 0 0 auto; font-size: 16px; line-height: 1.2; }
.media-note-text { min-width: 0; }
.media-note-title { color: #46525e; font-size: 12.5px; font-weight: 700; }
.media-note-reason { margin-top: 2px; }
/* Видео, которое ещё не подгружено: рамка вместо пустого места */
.bubble .media video:not([src]) { min-width: 220px; min-height: 120px; background: #dfe5ea; }

/* Вместо поля ответа, когда писать в диалог нельзя */
.send-blocked {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid #eef1f4;
  background: #f8fafb;
  color: #46525e;
  line-height: 1.45;
}
.send-blocked-icon { flex: 0 0 auto; font-size: 18px; line-height: 1.2; }
.send-blocked-text { min-width: 0; }
.send-blocked-sub { margin-top: 2px; color: #7b8794; font-size: 12.5px; }

/* Окна «Карточка», «Покупки», «Другие чаты», «Оригинал» */
.modal .card-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 4px 0 8px;
}
.card-grid dt { color: #7b8794; }
.card-grid dd { overflow-wrap: anywhere; }

.modal.is-card { overflow-wrap: anywhere; }
.card-telegram-access { min-width: 0; margin-top: 16px; }
.card-telegram-access h3 { margin: 0 0 6px; font-size: 14px; }
.card-telegram-access .card-bot-access-identity { margin: 0 0 8px; }
.card-bot-access-list { min-width: 0; }
.card-bot-access {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 170px);
  gap: 4px 12px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid #e3e8ec;
  font-size: 13px;
  line-height: 1.45;
}
.card-bot-access > *, .card-bot-access-bot > * { min-width: 0; overflow-wrap: anywhere; }
.card-bot-access-name, .card-bot-access-username { display: block; }
.card-bot-access-name, .card-bot-access-status { font-weight: 600; }
.card-bot-access-username, .card-bot-access-time { color: #5d6b78; font-size: 12px; }
.card-bot-access[data-status="action-accepted"] .card-bot-access-status { color: #237441; }
.card-bot-access[data-status="bot-blocked"] .card-bot-access-status,
.card-bot-access[data-status="user-deactivated"] .card-bot-access-status { color: #b3402f; }
.card-properties { min-width: 0; margin-top: 16px; }
.card-property-scope { padding: 14px 0; border-top: 1px solid #e3e8ec; }
.card-property-scope h3 { margin: 0 0 6px; font-size: 14px; overflow-wrap: anywhere; }
.card-property { margin-top: 14px; min-width: 0; }
.card-property h4 { margin: 0 0 6px; font-size: 13px; }
.card-property-meta {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 3px 12px;
  margin: 6px 0;
  font-size: 12px;
  line-height: 1.45;
}
.card-property-meta dt { color: #5d6b78; }
.card-property-meta dd { margin: 0; }
.card-property-meta dt, .card-property-meta dd, .card-scope-identity { overflow-wrap: anywhere; }
.card-property-value { min-width: 0; }
.modal .card-raw-value {
  margin: 4px 0 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.card-property-tags { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 8px 0; }
.card-property-tag { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px; min-width: 0; max-width: 100%; }
.card-property-tag span { overflow-wrap: anywhere; min-width: 0; }
.card-tag-swatch { flex: 0 0 8px; width: 8px; height: 8px; border: 1px solid #7b8794; background: #fff; }
.card-tag-id, .card-field-type { color: #5d6b78; font-size: 12px; }
.card-field-list { margin: 8px 0; padding-left: 24px; }
.card-field { margin: 0 0 8px; padding-left: 4px; min-width: 0; }
.card-field-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.card-field-name { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.card-field-type { overflow-wrap: anywhere; }
.card-property-versions, .card-field-original { margin: 8px 0; font-size: 12px; }
.card-property-versions summary, .card-field-original summary { cursor: pointer; color: #46525e; overflow-wrap: anywhere; }
.card-property-version { margin: 10px 0; padding-left: 10px; border-left: 2px solid #e3e8ec; min-width: 0; }
.modal .card-version-label { font-weight: 600; margin-bottom: 4px; }

.purchases-scroll { margin: 6px 0 10px; overflow-x: auto; }
.modal .purchases-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.modal .purchases-table th {
  padding: 6px 8px;
  border-bottom: 1px solid #e3e8ec;
  color: #7b8794;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.modal .purchases-table td { padding: 7px 8px; border-bottom: 1px solid #f0f3f5; vertical-align: top; }
.modal .purchases-table td.num { text-align: right; white-space: nowrap; }
.purchases-sub { color: #7b8794; font-size: 12px; }
.modal .purchases-heading { margin: 14px 0 4px; font-size: 14px; }
.modal .purchases-note { font-style: italic; }

.related-list { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 8px; }
.related-item {
  display: grid;
  grid-template-columns: minmax(80px, 130px) 1fr auto auto;
  gap: 4px 10px;
  align-items: baseline;
  padding: 8px 10px;
  border: 1px solid #e3e8ec;
  border-radius: 10px;
  background: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.related-item:hover { border-color: #00a86b; background: #f5fbf8; }
.related-bot { color: #2b4f86; font-size: 12.5px; font-weight: 600; }
.related-who { font-weight: 600; overflow-wrap: anywhere; }
.related-when, .related-life { color: #7b8794; font-size: 12px; white-space: nowrap; }

.modal .source-json {
  margin: 6px 0 8px;
  padding: 10px 12px;
  max-height: 55vh;
  overflow: auto;
  border: 1px solid #e3e8ec;
  border-radius: 8px;
  background: #f7f9fb;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Узкий экран: список и переписка не помещаются рядом. Показываем что-то
   одно во весь экран, а из переписки возвращаемся кнопкой «←». */
@media (max-width: 760px) {
  /* Каркас тот же, что и на большом экране (см. начало файла): страница в
     экран, прокручивается середина. Здесь только поля поуже. */
  .chats {
    flex-direction: column;
    padding: 0;
    gap: 0;
  }
  .chat-list, .chat-view { border-radius: 0; }
  .chat-list {
    flex: 1;
    max-height: none;
    min-height: 0;
  }
  .chat-view { display: none; }
  .chats.is-chat-open .chat-list { display: none; }
  .chats.is-chat-open .chat-view {
    display: flex;
    flex: 1;
    min-height: 0;
  }
  .chats.is-chat-open .chat-back { display: block; }
  /* Кнопки уезжают на вторую строку, чтобы имя собеседника не обрезалось */
  .chat-header { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 12px; }
  .chat-header .btn { font-size: 12px; padding: 6px 10px; }
  /* Первая строка: «←», аватар, имя и «⋯»; «Отметить прочитанными» и «Служебные
     события» — второй. Раньше имя занимало отдельную строку, и шапка съедала
     четверть экрана ещё до тегов. */
  .chat-titles { flex: 1 1 0; min-width: 40%; }
  .chat-header .chat-menu { order: 1; }
  .chat-header > .btn, .chat-header .service-toggle { order: 2; }
  .chat-titles .name, .chat-titles .sub, .chat-titles .answered {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bubble { max-width: 92%; }
  .chat-item .preview { font-size: 13px; }
  /* 16px — порог, ниже которого iOS при клике в поле сам увеличивает страницу */
  .chat-form textarea, .modal input, .modal textarea, .modal select,
  .chat-search input, .chat-filter-select { font-size: 16px; }
  .chat-body { padding: 12px; }
  .chat-form { padding: 10px 12px; }

  /* Шапка */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    row-gap: 6px;
  }
  .topbar h1 { font-size: 15px; flex: 0 0 auto; }
  .tab-badge { margin-left: 4px; min-width: 16px; padding: 1px 4px; font-size: 10px; }
  /* Время обновления и логин на узком экране только мешают. Сбой («Нет связи с
     сервером», «Переписка не загрузилась») прятать нельзя: он отдельной строкой. */
  .refresh-state { display: none; }
  .refresh-state.is-alert {
    display: block;
    order: 3;
    flex: 1 0 100%;
    margin-left: 0;
    color: #b3261e;
    font-weight: 600;
    font-size: 12.5px;
  }
  /* Теги: три важнейших и «+N» (карточка), остальные не занимают экран */
  .chat-chips .tag-extra { display: none; }
  .chat-chips .tag-more { display: inline-flex; }
  .who-am-i { margin-left: auto; padding: 4px 6px; font-size: 12.5px; }
  .mode-banner, .archive-banner, .import-banner { padding: 7px 12px; font-size: 12.5px; }

  /* Окно во весь экран: меньше некуда, и кнопки всегда под рукой */
  .modal {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    padding: 14px 14px 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }
  .modal.wide { width: 100%; max-height: none; }
  .modal .actions {
    position: sticky;
    bottom: 0;
    margin: 12px -14px 0;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #eef1f4;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    text-align: left;
  }
  .modal .actions .btn { width: 100%; margin: 0; }
  .modal .dictation-text { flex: 1; min-height: 40vh; }
  .modal .card-grid { grid-template-columns: 1fr; gap: 0; }
  .card-grid dd { margin-bottom: 8px; }
  .card-bot-access { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 10px; }
  .card-bot-access-bot { grid-row: span 2; }
  .card-bot-access-time { grid-column: 2; }
  .card-property-meta { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .card-property-meta dd { margin-bottom: 6px; }
  .related-item { grid-template-columns: 1fr auto; }
}

/* Низкое окно (ноутбук с малой высотой, телефон боком): лента сообщений не должна
   пропадать. Шапка — в одну строку и без тегов, поле ответа — в одну строку,
   подсказка dryrun остаётся в плашке режима над списком, черновики — не выше
   четверти окна (дальше прокручиваются). Блок в конце файла: он должен
   перебить и общий, и мобильный блоки. */
@media (max-height: 430px) {
  .chat-header { flex-wrap: nowrap; gap: 8px; padding: 6px 12px; }
  .chat-titles { flex: 1 1 0; min-width: 0; }
  .chat-titles .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-titles .chat-chips { display: none; }
  .chat-header .avatar { width: 30px; height: 30px; }
  .chat-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 6px; padding: 6px 12px; }
  .chat-form > textarea { flex: 1 1 200px; min-height: 36px; padding: 6px 10px; }
  .chat-form > .reply-strip, .chat-form > .emoji-palette { flex: 1 1 100%; }
  .dry-hint { display: none; }
  .chat-drafts { max-height: 25%; }
}
