/* ============================================
   MOB — чат (личные сообщения)
   ============================================ */

.mob-chat {
  position: fixed;
  top: var(--mob-head-h);
  left: 0;
  right: 0;
  bottom: var(--mob-bottom-h);
  background: var(--mob-bg);
  z-index: 1300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   Поиск / шапка списка
   ═══════════════════════════════════════════ */
.chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--mob-border);
  background: var(--mob-bg);
  flex-shrink: 0;
}
.chat-search__icon {
  color: var(--mob-text-muted);
  font-size: 14px;
  flex-shrink: 0;
}
.chat-search__input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--mob-bg-elevated);
  border: 1px solid var(--mob-border);
  border-radius: 999px;
  color: var(--mob-text);
  font-size: 13px;
  outline: none;
  transition: .15s;
}
.chat-search__input:focus { border-color: var(--mob-accent); }
.chat-search__input::placeholder { color: var(--mob-text-muted); }
.chat-search__new {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mob-accent-grad);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: .15s;
}
.chat-search__new:hover { opacity: .9; }

/* ═══════════════════════════════════════════
   Список диалогов
   ═══════════════════════════════════════════ */
#chat-dialogs {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
#chat-dialogs.hidden { display: none; }

.chat-list__date {
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--mob-text-muted);
  text-transform: uppercase;
}
.chat-list__date--center {
  text-align: center;
  padding: 12px 0 4px;
}

.chat-dialog {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: .15s;
  background: transparent;
}
.chat-dialog:hover { background: var(--mob-bg-surface); }
.chat-dialog:active { transform: scale(.985); }
.chat-dialog--unread .chat-dialog__name { font-weight: 700; }
.chat-dialog--unread .chat-dialog__preview { color: var(--mob-text); font-weight: 500; }

.chat-dialog__avatar-wrap {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}
.chat-dialog__avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--mob-bg-elevated);
  display: block;
}
.chat-dialog__online {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 13px;
  height: 13px;
  background: #22c55e;
  border: 2px solid var(--mob-bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, .3);
}

.chat-dialog__body { flex: 1; min-width: 0; }
.chat-dialog__top,
.chat-dialog__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-dialog__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--mob-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-dialog__time {
  font-size: 11px;
  color: var(--mob-text-muted);
  flex-shrink: 0;
}
.chat-dialog__preview {
  font-size: 12.5px;
  color: var(--mob-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chat-dialog__badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--mob-accent-grad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   Окно диалога
   ═══════════════════════════════════════════ */
#chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#chat-window.hidden { display: none; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--mob-border);
  background: var(--mob-bg);
  flex-shrink: 0;
}
.chat-header__back {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none;
  color: var(--mob-text-2);
  cursor: pointer; border-radius: 50%;
  font-size: 18px; transition: .15s; padding: 0; flex-shrink: 0;
}
.chat-header__back:hover { background: var(--mob-bg-elevated); color: var(--mob-text); }
.chat-header__avatar {
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.chat-header__title {
  font-size: 14px; font-weight: 600;
  color: var(--mob-text);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 85%;
}
.chat-msg--mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg__avatar {
  width: 28px; height: 28px;
  border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.chat-msg__body {
  background: var(--mob-bg-surface);
  border: 1px solid var(--mob-border);
  border-radius: 14px;
  padding: 8px 12px;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg--mine .chat-msg__body {
  background: var(--mob-accent-grad);
  border-color: transparent;
  color: #fff;
}
.chat-msg__text { font-size: 14px; line-height: 1.4; color: var(--mob-text); }
.chat-msg--mine .chat-msg__text { color: #fff; }
.chat-msg__time {
  font-size: 10px;
  color: var(--mob-text-muted);
  margin-top: 3px; text-align: right;
}
.chat-msg--mine .chat-msg__time { color: rgba(255,255,255,.7); }

.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--mob-border);
  background: var(--mob-bg);
  flex-shrink: 0;
}
.chat-form__input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  background: var(--mob-bg-elevated);
  border: 1px solid var(--mob-border);
  border-radius: 999px;
  color: var(--mob-text);
  font-size: 14px; outline: none; transition: .15s;
}
.chat-form__input:focus { border-color: var(--mob-accent); }
.chat-form__input::placeholder { color: var(--mob-text-muted); }
.chat-form__send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--mob-accent-grad);
  border: none; color: #fff; font-size: 16px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: .15s; padding: 0;
}
.chat-form__send:hover { opacity: .9; }
.chat-form__send:disabled { opacity: .5; cursor: not-allowed; }

/* ═══════════════════════════════════════════
   Пусто / загрузка
   ═══════════════════════════════════════════ */
.chat-empty, .chat-loading {
  padding: 40px 20px;
  text-align: center;
  color: var(--mob-text-muted);
  font-size: 13px;
}
.chat-empty__icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: .35;
  display: block;
  line-height: 1;
}
.chat-empty__icon i { font-size: inherit; }
.chat-empty__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--mob-text);
  margin-bottom: 6px;
}
.chat-empty__sub {
  font-size: 13px;
  color: var(--mob-text-muted);
  margin-bottom: 20px;
}
.chat-empty__cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--mob-accent-grad);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.chat-empty__cta:hover { opacity: .9; transform: scale(1.02); }

/* ═══════════════════════════════════════════
   Модалка "Новый диалог"
   ═══════════════════════════════════════════ */
.chat-new-modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.chat-new-modal.hidden { display: none; }
.chat-new-modal__sheet {
  width: 100%;
  max-width: 600px;
  max-height: 85%;
  background: var(--mob-bg);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSheetUp .25s ease-out;
  box-shadow: 0 -8px 32px rgba(0,0,0,.3);
}
@keyframes chatSheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.chat-new-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--mob-border);
  flex-shrink: 0;
}
.chat-new-modal__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--mob-text);
}
.chat-new-modal__close {
  width: 32px; height: 32px;
  background: transparent; border: none;
  color: var(--mob-text-2);
  cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transition: .15s;
}
.chat-new-modal__close:hover { background: var(--mob-bg-elevated); color: var(--mob-text); }

.chat-new-modal__search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 0;
  padding: 8px 12px;
  background: var(--mob-bg-elevated);
  border: 1px solid var(--mob-border);
  border-radius: 999px;
  flex-shrink: 0;
}
.chat-new-modal__search i {
  color: var(--mob-text-muted); font-size: 14px;
}
.chat-new-modal__search input {
  flex: 1; min-width: 0;
  background: transparent; border: none;
  color: var(--mob-text); font-size: 14px; outline: none;
}
.chat-new-modal__search input::placeholder { color: var(--mob-text-muted); }

.chat-new-modal__tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}
.chat-new-modal__tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--mob-bg-elevated);
  border: 1px solid var(--mob-border);
  color: var(--mob-text-2);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.chat-new-modal__tab.active {
  background: var(--mob-accent-grad);
  border-color: transparent;
  color: #fff;
}

.chat-new-modal__list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 6px 16px;
  min-height: 200px;
}

.chat-new-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: .15s;
}
.chat-new-user:hover { background: var(--mob-bg-surface); }
.chat-new-user__avatar {
  width: 42px; height: 42px;
  border-radius: 50%; object-fit: cover; flex-shrink: 0;
  background: var(--mob-bg-elevated);
}
.chat-new-user__body { flex: 1; min-width: 0; }
.chat-new-user__name {
  font-size: 14px; font-weight: 600; color: var(--mob-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-new-user__sub {
  font-size: 12px; color: var(--mob-text-muted); margin-top: 2px;
}
.chat-new-user__icon {
  color: var(--mob-accent); font-size: 18px; flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   Бейдж на #mob-bottom
   ═══════════════════════════════════════════ */
.mob-bottom__badge {
  position: absolute;
  top: 4px;
  right: 8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Адаптив */
@media (max-width: 375px) {
  .chat-msg { max-width: 90%; }
  .chat-form__input { font-size: 13px; padding: 9px 12px; }
  .chat-dialog__avatar { width: 44px; height: 44px; }
  .chat-dialog__avatar-wrap { width: 44px; height: 44px; }
}

/* ═══════════════════════════════════════════
   ЧАТ v2 — ДОПОЛНЕНИЯ
   ═══════════════════════════════════════════ */

/* Pinned dialog */
.chat-dialog--pinned { background: rgba(255,255,255,.03); }

/* Reply в сообщении */
.chat-msg__reply {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-left: 3px solid var(--mob-accent);
  background: rgba(255,255,255,.05);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
}
.chat-msg__reply b { font-size: 11px; color: var(--mob-accent); }
.chat-msg__reply span { color: var(--mob-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Edited */
.chat-msg__edited { font-size: 10px; color: var(--mob-text-muted); margin-left: 4px; }

/* Read checkmarks */
.chat-msg__read { font-size: 10px; color: rgba(255,255,255,.7); margin-left: 4px; }

/* Meta-row */
.chat-msg__meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 3px; }

/* Вложения */
.chat-msg__img { max-width: 240px; max-height: 240px; border-radius: 10px; margin-bottom: 6px; cursor: pointer; display: block; }
.chat-msg__audio { width: 240px; margin-bottom: 6px; }
.chat-msg__file { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; background: rgba(255,255,255,.05); border-radius: 8px; color: var(--mob-text); text-decoration: none; font-size: 13px; margin-bottom: 6px; }

/* Reactions */
.chat-msg__reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chat-reaction {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 12px;
  color: var(--mob-text);
  cursor: pointer;
  transition: .15s;
}
.chat-reaction:hover { background: rgba(255,255,255,.15); }
.chat-reaction--mine { background: rgba(91,111,214,.25); border-color: var(--mob-accent); }
.chat-reaction span { font-size: 11px; color: var(--mob-text-muted); }

/* Reply-preview над формой */
.chat-reply-preview {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--mob-bg-elevated);
  border-top: 1px solid var(--mob-border);
  border-left: 3px solid var(--mob-accent);
}
.chat-reply-preview__body { flex: 1; min-width: 0; }
.chat-reply-preview__body b { font-size: 11px; color: var(--mob-accent); display: block; }
.chat-reply-preview__body span { font-size: 12px; color: var(--mob-text-muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-reply-preview__close { width: 28px; height: 28px; background: transparent; border: none; color: var(--mob-text-2); cursor: pointer; border-radius: 50%; }

/* Action sheet */
.chat-actions {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1700;
  display: flex; align-items: flex-end;
  backdrop-filter: blur(4px);
}
.chat-actions.hidden { display: none; }
.chat-actions__sheet {
  width: 100%; max-width: 600px;
  margin: 0 auto;
  background: var(--mob-bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 0 16px;
  animation: chatSheetUp .2s ease-out;
}
.chat-actions__emojis {
  display: flex; gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--mob-border);
  overflow-x: auto;
}
.chat-actions__emoji {
  width: 40px; height: 40px;
  background: var(--mob-bg-elevated);
  border: none;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: .15s;
}
.chat-actions__emoji:hover { background: var(--mob-bg-surface); transform: scale(1.1); }
.chat-actions__list { padding: 6px 0; }
.chat-actions__item {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: transparent;
  border: none;
  color: var(--mob-text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: .15s;
}
.chat-actions__item:hover { background: var(--mob-bg-surface); }
.chat-actions__item i { font-size: 16px; color: var(--mob-text-2); }
.chat-actions__item--danger { color: #ef4444; }
.chat-actions__item--danger i { color: #ef4444; }

/* Toast */
.chat-toast {
  position: fixed;
  bottom: calc(var(--mob-bottom-h) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20,20,20,.95);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 9999;
  opacity: 0;
  transition: .3s;
  pointer-events: none;
}
.chat-toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Typing indicator */
.chat-typing {
  display: inline-flex; gap: 4px; padding: 10px 14px;
  background: var(--mob-bg-surface); border-radius: 14px;
  margin: 0 0 6px 36px; align-self: flex-start;
  width: fit-content;
}
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--mob-text-muted);
  animation: typingBounce 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-msg, .chat-dialog {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.chat-msg__text, .chat-msg__reply, .chat-dialog__name, .chat-dialog__preview {
  -webkit-user-select: text;
  user-select: text;
}