/* Mesh Messenger — Neumorphic Scandinavian theme (v5)
   Тёмная тема сохранена отдельно: style_dark_v4_backup.css.
   Принцип: кнопки/карточки ВЫПУКЛЫЕ (--raised), поля ввода ВДАВЛЕННЫЕ (--inset).
   Нажатие кнопки = инверсия тени в --inset + scale. */

:root {
  --bg: #e8e4dc;            /* тёплый серо-бежевый фон */
  --surface: #edeae3;       /* поверхность карточек */
  --shadow-dark: rgba(166, 157, 141, 0.55);
  --shadow-light: rgba(255, 255, 255, 0.95);
  --accent: #bf6b45;        /* терракота */
  --accent-soft: #e7c9b8;   /* пастельная терракота — мои пузыри */
  --green: #7d9c72;         /* шалфейный «в сети» */
  --text: #4a453d;
  --text-dim: #9a9184;
  --danger: #b3574e;
  --radius: 18px;

  --raised: 6px 6px 14px var(--shadow-dark), -6px -6px 14px var(--shadow-light);
  --raised-sm: 3px 3px 8px var(--shadow-dark), -3px -3px 8px var(--shadow-light);
  --inset: inset 4px 4px 9px var(--shadow-dark), inset -4px -4px 9px var(--shadow-light);
  --press: box-shadow 0.13s ease, transform 0.13s ease, color 0.13s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;   /* мобильные: учитывает адресную строку — иначе низ уезжает за экран */
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== SCREENS ===== */
.screen { height: 100vh; height: 100dvh; width: 100%; }

/* ===== LOGIN SCREEN ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius);
  width: 400px;
  max-width: 90vw;
  box-shadow: var(--raised);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo h1 { font-size: 28px; color: var(--accent); }

.tagline {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 28px;
  font-size: 14px;
}

/* Tabs — вдавленная дорожка, активная вкладка выпуклая */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  background: var(--surface);
  border-radius: 14px;
  padding: 6px;
  box-shadow: var(--inset);
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
  font-family: inherit;
  transition: var(--press);
}

.tab:active { transform: scale(0.97); }

.tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--raised-sm);
}

/* Auth forms */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: none;
  border-radius: 14px;
  box-shadow: var(--inset);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: var(--press);
}

.auth-form input::placeholder { color: var(--text-dim); }
.auth-form input:focus { box-shadow: var(--inset), 0 0 0 2px var(--accent-soft); }

/* Главная кнопка — выпуклая, при нажатии вдавливается */
.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: 14px;
  color: #fdf9f4;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--raised-sm);
  transition: var(--press);
}

.btn-primary:hover { background: #b06039; }
.btn-primary:active { box-shadow: var(--inset); transform: scale(0.98); }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
}

/* ===== CHAT SCREEN ===== */
.chat-screen {
  display: flex;
  flex-direction: row;
  background: var(--bg);
  gap: 18px;
  padding: 18px;
}

/* Sidebar — выпуклая панель */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--raised);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 36px);
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.avatar.small {
  width: 36px;
  height: 36px;
  font-size: 14px;
}

.user-name { font-weight: 700; font-size: 15px; }
.user-status { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.user-status.online { color: var(--green); }

/* Зелёная точка-индикатор перед любым online-статусом */
.user-status.online::before,
.contact-status.online::before,
.chat-status.online::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 6px;
  vertical-align: baseline;
}

/* Иконки-кнопки (выход, скрепка) */
.icon-btn {
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow: var(--raised-sm);
  transition: var(--press);
}
.icon-btn:hover { color: var(--accent); }
.icon-btn:active { box-shadow: var(--inset); transform: scale(0.94); }

/* Search */
.search-bar { padding: 6px 16px 12px; }

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  box-shadow: var(--inset);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-dim); }

/* Add contact */
.add-contact-bar {
  padding: 0 16px 14px;
  display: flex;
  gap: 8px;
}

.add-contact-bar input {
  flex: 1;
  min-width: 0;   /* иначе flex не даёт полю ужаться и кнопку выдавливает за край */
  padding: 9px 14px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  box-shadow: var(--inset);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.add-contact-bar input::placeholder { color: var(--text-dim); }

.btn-small {
  padding: 9px 14px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  box-shadow: var(--raised-sm);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  font-family: inherit;
  transition: var(--press);
}
.btn-small:active { box-shadow: var(--inset); transform: scale(0.96); }

/* Contacts list — выпуклые карточки, активная вдавлена */
.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.contact-item {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  transition: var(--press);
  flex-shrink: 0;
}

.contact-item:active { transform: scale(0.98); }
.contact-item.active { box-shadow: var(--inset); }
.contact-item.active .contact-name { color: var(--accent); }

.contact-name { font-size: 14px; font-weight: 700; }

/* «Мост» — закреплённый чат между своими устройствами */
.contact-item.bridge { margin-bottom: 4px; }
.bridge-avatar { color: var(--accent); }
.contact-item.bridge .contact-name { color: var(--accent); }
.contact-item.bridge .contact-status.online::before { display: none; } /* это не presence-статус */
.contact-status { font-size: 12px; color: var(--text-dim); margin-top: 2px; font-weight: 600; }
.contact-status.online { color: var(--green); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--raised);
  height: calc(100dvh - 36px);
  overflow: hidden;
}

.no-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 15px;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-name { font-weight: 800; font-size: 16px; }
.chat-status { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.chat-status.online { color: var(--green); }

/* Messages — один столбик слева, как в Telegram */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 72%;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-self: flex-start;
}

.msg-sender {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 3px;
  padding-left: 6px;
}

.message.mine .msg-sender { color: var(--accent); }
.message.theirs .msg-sender { color: var(--green); }

.msg-bubble {
  padding: 11px 16px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: break-word;
  width: fit-content;
  max-width: 100%;
}

.message.mine .msg-bubble { background: var(--accent-soft); }

/* Вложения */
.msg-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 12px;
  margin-bottom: 6px;
}

.msg-file {
  display: inline-block;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  margin-bottom: 4px;
}
.msg-file:hover { text-decoration: underline; }
.msg-file-size { color: var(--text-dim); font-weight: 600; font-size: 12px; }
.msg-plain { font-size: 11px; opacity: 0.7; cursor: help; }

/* ===== Markdown в сообщениях ===== */
.msg-text { line-height: 1.5; }

/* Векторные иконки вместо эмодзи */
.md-icon {
  width: 1.05em;
  height: 1.05em;
  vertical-align: -0.15em;
  margin-right: 3px;
  color: var(--accent);
  flex-shrink: 0;
}
.md-h1 .md-icon, .md-h2 .md-icon { width: 1.15em; height: 1.15em; }
.md-h3 .md-icon { color: var(--accent); opacity: 0.85; }
.message.mine .md-icon { color: var(--text); }

/* Незнакомые эмодзи — обесцвечиваем и красим в палитру, чтобы не выбивались */
.md-emoji {
  filter: grayscale(1) sepia(0.55) saturate(2.2) hue-rotate(-12deg) brightness(0.92);
  font-size: 0.95em;
  opacity: 0.9;
}
.md-h1, .md-h2, .md-h3 { font-weight: 800; margin: 8px 0 4px; line-height: 1.3; }
.md-h1 { font-size: 16px; color: var(--accent); }
.md-h2 { font-size: 15px; }
.md-h3 { font-size: 14px; color: var(--text-dim); text-transform: none; }
.md-h1:first-child, .md-h2:first-child, .md-h3:first-child { margin-top: 0; }

.md-li { padding-left: 16px; position: relative; margin: 3px 0; }
.md-li::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 800;
}
.md-li-num::before { content: attr(data-n); left: 0; font-size: 12px; }

.md-hr { border: none; border-top: 1px solid var(--shadow-dark); margin: 8px 0; opacity: 0.5; }

.md-code {
  background: var(--bg);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12.5px;
  box-shadow: var(--inset);
}

.md-pre {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  box-shadow: var(--inset);
}
.md-pre code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre;
  background: none;
  box-shadow: none;
  padding: 0;
}

.md-link { color: var(--accent); font-weight: 700; }
.md-link:hover { text-decoration: underline; }

.message.mine .md-code,
.message.mine .md-pre { background: rgba(255, 255, 255, 0.45); }
.msg-image { cursor: pointer; }

/* Чип прикреплённого файла над полем ввода */
.pending-chip {
  margin: 0 20px;
  padding: 9px 14px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--inset);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: calc(100% - 40px);
}

.chip-cancel {
  border: none;
  background: var(--surface);
  border-radius: 50%;
  width: 22px; height: 22px;
  box-shadow: var(--raised-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  transition: var(--press);
  flex-shrink: 0;
}
.chip-cancel:active { box-shadow: var(--inset); }

/* Окно участников группы: на десктопе — рядом с сайдбаром, не по центру */
@media (min-width: 769px) {
  #groupInfoModal {
    align-items: flex-start;
    justify-content: flex-start;
    padding: 0;
    background: rgba(74, 69, 61, 0.18);
  }
  #groupInfoModal .modal-card {
    margin: 190px 0 0 22px;       /* примерно под секцией «Группы» */
    width: 340px;
    max-height: 70vh;
    animation: slide-in-left 0.16s ease-out;
  }
}
@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Квадратные аватары (готовы под фото) */
.avatar-sq {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  color: var(--accent);
  font-weight: 800;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;         /* когда появятся фото — обрежутся по скруглению */
}
.avatar-sq.small-sq { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
.avatar-sq img { width: 100%; height: 100%; object-fit: cover; }

/* Плашка участника — компактнее и «квадратнее», не вытянутая */
.member-item {
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
}
.member-name { font-size: 14px; font-weight: 700; }
.member-role {
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 6px;
  box-shadow: var(--inset);
  margin-left: 4px;
  vertical-align: middle;
}

/* ═══════════════ ГРУППЫ ═══════════════ */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.btn-icon-mini {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--press);
  padding: 0;
}
.btn-icon-mini:active { box-shadow: var(--inset); transform: scale(0.92); }

.groups-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }

.group-avatar {
  background: var(--surface);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.group-avatar svg { width: 18px; height: 18px; }
.avatar.group-avatar svg { width: 20px; height: 20px; }

/* Иконка группы в шапке чата — кликабельна (открывает участников) */
#chatAvatar.group-avatar {
  cursor: pointer;
  transition: var(--press);
}
#chatAvatar.group-avatar:hover { box-shadow: var(--raised); }
#chatAvatar.group-avatar:active { box-shadow: var(--inset); transform: scale(0.94); }
#chatAvatar.group-avatar::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}
#chatAvatar { position: relative; }

/* Выбор участников при создании группы */
.member-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--press);
}
.member-row:hover { box-shadow: var(--raised-sm); }
.member-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.member-row span { font-size: 14px; font-weight: 700; }

/* Имя отправителя в группе — цветное (цвет задаётся инлайн по id) */
.message.theirs .msg-sender { font-weight: 800; }

/* ===== Непрочитанные ===== */
.contact-item { position: relative; }

.unread-badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: #fdf9f4;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--raised-sm);
  flex-shrink: 0;
}

/* ===== Голосовой ввод ===== */
.msg-input-wrap { position: relative; flex: 1; display: flex; min-width: 0; }
.msg-input-wrap input { flex: 1; min-width: 0; padding-right: 44px !important; }

.mic-btn {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--press);
  padding: 0;
}
.mic-btn:hover { color: var(--accent); }
.mic-btn:active { box-shadow: var(--inset); transform: translateY(-50%) scale(0.94); }

.mic-btn.recording {
  color: var(--danger);
  box-shadow: var(--inset);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ===== Поиск людей ===== */
.user-search {
  margin: -6px 16px 12px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--raised);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}

.user-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--press);
}
.user-search-item:hover { box-shadow: var(--raised-sm); }
.user-search-item:active { box-shadow: var(--inset); }
.user-search-item.already { opacity: 0.55; cursor: default; }
.user-search-item.already:hover { box-shadow: none; }

.user-search-name { flex: 1; font-size: 14px; font-weight: 700; }
.user-search-hint { font-size: 11px; color: var(--accent); font-weight: 700; }
.user-search-item.already .user-search-hint { color: var(--text-dim); }
.user-search-empty { padding: 10px; text-align: center; font-size: 13px; color: var(--text-dim); }

/* ===== Пароль: глазик и подтверждение ===== */
.pw-field { position: relative; display: flex; }
.pw-field input { flex: 1; padding-right: 46px !important; }

.pw-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--raised-sm);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--press);
  padding: 0;
}
.pw-eye svg { width: 17px; height: 17px; }
.pw-eye:hover { color: var(--accent); }
.pw-eye:active { box-shadow: var(--inset); transform: translateY(-50%) scale(0.94); }

.pw-hint {
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
  margin: -6px 0 0 4px;
}

input.input-error { box-shadow: var(--inset), 0 0 0 2px var(--danger) !important; }

/* ===== Модалка приглашений ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(74, 69, 61, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--raised);
  padding: 22px;
  width: 460px;
  max-width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-title { font-size: 17px; font-weight: 800; }

.modal-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 16px;
}

.invites-list { display: flex; flex-direction: column; gap: 10px; }

.invite-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--raised-sm);
}
.invite-item > div:first-child { flex: 1; min-width: 0; }
.invite-item.used { box-shadow: var(--inset); opacity: 0.75; }

.invite-code {
  font-family: 'Consolas', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  word-break: break-all;
}
.invite-item.used .invite-code { color: var(--text-dim); text-decoration: line-through; }

.invite-note { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.btn-small.danger-btn { color: var(--danger); }

/* Векторные иконки в меню/чипе/файлах */
.mi { vertical-align: -2px; margin-right: 4px; flex-shrink: 0; }
.file-menu-item { display: flex; align-items: center; gap: 8px; }
.file-menu-item .mi { margin-right: 0; }

/* Всплывающее меню действий по файлу */
.file-menu {
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--raised);
  padding: 8px;
  min-width: 200px;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-menu-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  padding: 4px 10px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-menu-item {
  border: none;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--raised-sm);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  transition: var(--press);
}
.file-menu-item:hover { color: var(--accent); }
.file-menu-item:active { box-shadow: var(--inset); transform: scale(0.98); }

.file-menu-sep {
  height: 1px;
  background: var(--shadow-dark);
  opacity: 0.4;
  margin: 2px 6px;
}

.file-menu-item.danger { color: var(--danger); }
.file-menu-item.danger:hover { color: #8f3f38; }

.msg-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  padding-left: 6px;
  font-weight: 600;
}

/* Message input */
.message-input-bar {
  padding: 14px 20px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.message-input-bar input[type="text"] {
  flex: 1;
  padding: 13px 18px;
  background: var(--surface);
  border: none;
  border-radius: 14px;
  box-shadow: var(--inset);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: var(--press);
}

.message-input-bar input[type="text"]::placeholder { color: var(--text-dim); }
.message-input-bar input[type="text"]:focus { box-shadow: var(--inset), 0 0 0 2px var(--accent-soft); }

/* Кнопка отправки — выпуклая, как скрепка: тени читаются на цвете поверхности */
.btn-send {
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--surface);
  border: none;
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  box-shadow: var(--raised-sm);
  transition: var(--press);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send:hover { color: #b06039; }
.btn-send:active { box-shadow: var(--inset); transform: scale(0.92); }

/* Кнопка «назад» — только на мобильном */
.back-btn { display: none; }

/* ===== МОБИЛЬНАЯ ВЁРСТКА (два экрана: контакты <-> чат) ===== */
@media (max-width: 768px) {
  .chat-screen {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));  /* жесты/вырезы снизу */
    gap: 0;
  }

  /* Экран 1: список контактов на всю ширину, чат скрыт */
  .sidebar {
    width: 100%;
    min-width: 0;
    height: calc(100dvh - 20px);
  }
  .chat-area { display: none; }

  /* Экран 2 (body.mobile-chat-open): чат на всю ширину, список скрыт */
  body.mobile-chat-open .sidebar { display: none; }
  body.mobile-chat-open .chat-area {
    display: flex;
    width: 100%;
    height: calc(100dvh - 20px);
  }

  .back-btn { display: flex; }

  /* Компактнее на узком экране */
  .message { max-width: 85%; }
  .messages { padding: 8px 12px 14px; }
  .chat-header { padding: 10px 12px; }
  .message-input-bar {
    padding: 10px 12px;
    gap: 8px;                /* было 10 — на узком экране кнопка выдавливалась */
    flex-shrink: 0;          /* не сжимается, когда сообщений много */
  }
  .message-input-bar input[type="text"] {
    min-width: 0;            /* КЛЮЧЕВОЕ: иначе flex не даёт полю ужаться и выдавливает кнопку */
    padding: 12px 14px;
  }
  .btn-send { width: 42px; height: 42px; }
  .messages { min-height: 0; }   /* иначе flex не даёт ленте ужаться и выдавливает ввод */
  .login-card { padding: 28px 22px; }
}

/* Уважение к reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--shadow-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
