/* Épicerie — чат. Телефон: список переписок → экран переписки с полем внизу.
   ПК (.desk): список слева, переписка справа, лента прокручивается внутри своей панели. */

/* ---------------------------------------------------------------- значки непрочитанного */
.tabbar button { position: relative; }
.tab-badge {
  position: absolute; top: 2px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 700; font-style: normal; line-height: 18px; text-align: center;
}

/* ---------------------------------------------------------------- список переписок */
.chat-list.m { margin-top: 4px; }
.rooms-head { padding: 4px 0 8px; }
.room {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border-radius: 14px; text-align: left; transition: background-color .12s ease-out;
}
.room:hover { background: var(--surface); }
.room.on { background: var(--accent-soft); }
.room .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room-ico {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center;
}
.room-top { display: flex; align-items: baseline; gap: 8px; }
.room-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.room-time { flex: none; font-size: 12px; color: var(--text-3); }
.room-last { font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room.unread .room-last { color: var(--text); font-weight: 500; }
.room-unread {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: var(--on-accent);
  font-size: 12px; font-weight: 700; font-style: normal; line-height: 22px; text-align: center;
}
.dm-pick { max-height: 52vh; overflow-y: auto; margin-top: 8px; }
.dm-pick .room { padding: 8px 10px; }

/* ---------------------------------------------------------------- шапка переписки и переключатель перевода */
.thread-head { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.thread-head .grow { flex: 1; min-width: 0; }
.thread-head b { display: block; font-size: 16px; }
.trtoggle {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; flex: none;
  border-radius: 17px; background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 600;
  transition: background-color .12s ease-out, color .12s ease-out;
}
.trtoggle.on { background: var(--ok-soft); color: var(--ok); }

/* ---------------------------------------------------------------- лента */
.msgs { display: flex; flex-direction: column; padding: 4px 0 16px; }
.msgs.m { padding-bottom: 120px; }
.more { text-align: center; padding: 8px 0; }
.chat-empty { text-align: center; color: var(--text-2); padding: 48px 16px; }
.day-sep { text-align: center; margin: 16px 0 6px; }
.day-sep span { display: inline-block; padding: 3px 10px; border-radius: 10px; background: var(--surface); color: var(--text-3); font-size: 12px; font-weight: 600; }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 86%; margin-top: 10px; }
.msg.cont { margin-top: 2px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-av { width: 32px; flex: none; }
.msg-body { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.msg.mine .msg-body { align-items: flex-end; }
.msg-who { margin: 0 0 2px 12px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.bubble {
  padding: 8px 12px; border-radius: 18px; background: var(--surface);
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4;
}
.msg:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--accent-soft); border-bottom-right-radius: 6px; }
.msg.cont:not(.mine) .bubble { border-top-left-radius: 6px; }
.msg.mine.cont .bubble { border-top-right-radius: 6px; }
.msg-meta .tr-mark { display: inline-flex; align-items: center; gap: 3px; color: var(--ok); }
.msg-meta .tr-mark svg { width: 13px; height: 13px; }
.bubble.del { background: transparent; box-shadow: inset 0 0 0 1px var(--surface-2); color: var(--text-3); font-style: italic; }
.msg-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin: 3px 8px 0;
  font-size: 12px; color: var(--text-3);
}
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-meta button { color: var(--accent); font-size: 12px; font-weight: 600; }
.msg-meta .icb { display: inline-flex; align-items: center; gap: 3px; color: var(--text-3); font-weight: 500; }
.msg-meta .icb:hover { color: var(--accent); }
.msg-meta .icb svg { width: 15px; height: 15px; }
.msg-meta .del-btn:hover { color: var(--danger); }
.spin.xs { width: 14px; height: 14px; border-width: 2px; color: var(--text-3); }

/* ---------------------------------------------------------------- поле ввода */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 8px 12px calc(8px + var(--safe-bottom)); background: var(--bg);
  box-shadow: 0 -1px 0 var(--surface-2);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; min-height: 44px; max-height: 160px; resize: none; padding: 10px 14px;
  border-radius: 22px; border: 2px solid transparent; background: var(--surface); outline: none; line-height: 1.4;
  overflow-y: hidden;
}
.composer textarea:focus { border-color: var(--accent); background: var(--bg); }
.composer .send {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center;
}
.composer .send:active { transform: scale(.96); }
.room-page .thread-head.m { position: sticky; top: calc(var(--safe-top) + 56px); z-index: 5; background: var(--bg); padding: 4px 0 8px; }

/* ---------------------------------------------------------------- ПК: две панели */
.page-chat { max-width: 1400px; }
.dbody .chat-desk {
  display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px;
  height: calc(100vh - 112px); min-height: 420px;
}
.chat-desk .chat-list { overflow-y: auto; padding-right: 4px; }
.chat-desk .chat-thread {
  display: flex; flex-direction: column; min-height: 0;
  padding: 0 20px; border-radius: 20px; background: var(--surface);
}
.chat-desk .thread-head { padding: 14px 0 12px; box-shadow: 0 1px 0 var(--surface-2); }
.chat-desk .msgs { flex: 1; overflow-y: auto; padding: 8px 4px 16px; }
.chat-desk .msg { max-width: 70%; }
.chat-desk .bubble, .chat-desk .day-sep span { background: var(--bg); }
.chat-desk .msg.mine .bubble { background: var(--accent-soft); }
.chat-desk .bubble.del { background: transparent; }
.chat-desk .composer { position: static; padding: 12px 0 16px; background: transparent; box-shadow: none; }
.chat-desk .composer textarea { background: var(--bg); }
.chat-desk .room-ico { width: 40px; height: 40px; }

/* ---------------------------------------------------------------- галочки, «изменено», правка */
.msg-meta .edited { font-style: italic; }
.ticks { display: inline-flex; color: var(--text-3); }
.ticks svg { width: 16px; height: 16px; stroke-width: 2; }
.ticks.read { color: var(--read); }
.edit-bar { display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; font-size: 13px; font-weight: 600; color: var(--accent-ink); }
.edit-bar span { flex: 1; }
.edit-bar button { display: flex; color: var(--text-2); }
.composer.editing textarea { border-color: var(--accent); }

/* ---------------------------------------------------------------- меню сообщения */
.ctx {
  position: fixed; z-index: 80; min-width: 220px; max-width: 280px; padding: 6px;
  border-radius: 14px; background: var(--bg);
  box-shadow: 0 12px 32px rgba(30, 20, 10, .18), 0 0 0 1px var(--surface-2);
}
.ctx-items button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border-radius: 10px; font-size: 14px; font-weight: 500; text-align: left;
}
.ctx-items button:hover { background: var(--surface); }
.ctx-items .danger { color: var(--danger); }
.ctx-sec { margin-top: 4px; padding: 8px 10px 4px; box-shadow: 0 -1px 0 var(--surface-2); }
.ctx-h { margin-bottom: 6px; font-size: 12px; font-weight: 700; color: var(--text-3); }
#ctxReaders { max-height: 220px; overflow-y: auto; }
.ctx-user { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.ctx-status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.ctx-status svg { width: 16px; height: 16px; }
.ctx-status.read { color: var(--read); }
/* на сенсорных экранах долгое нажатие открывает меню, а не выделение текста (копировать — через меню) */
@media (hover: none) {
  .msg .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
