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

:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --border: #e4e6eb;
  --text: #050505;
  --text-muted: #65676b;
  --accent: #0084ff;
  --accent-hover: #006fd6;
  --msg-me: #0084ff;
  --msg-other: #e4e6eb;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

.screen { display: none; height: 100dvh; }
.screen.active { display: flex; }
.hidden { display: none !important; }
.mobile-only { display: none; }

/* ==== Экран логина ==== */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: var(--panel);
  padding: 40px 36px;
  border-radius: 20px;
  width: 360px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin-bottom: 24px; font-weight: 600; }
.login-card input {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: #f8f9fa;
}
.login-card input:focus { outline: none; border-color: var(--accent); background: #fff; }
.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }
.login-card button:disabled { opacity: 0.5; cursor: wait; }
.error { color: #e0245e; font-size: 13px; min-height: 18px; margin-top: 8px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 12px; }

/* ==== Основной экран ==== */
#app-screen { flex-direction: row; overflow: hidden; }

.sidebar {
  width: 340px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-info { min-width: 0; }
.me-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 12px; color: #31a24c; }

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar.small { width: 32px; height: 32px; font-size: 13px; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg); }

.search-box {
  padding: 10px 12px;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-box input {
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: 18px;
  background: var(--bg);
  font-size: 16px;
}
.search-box input:focus { outline: none; background: #e4e6eb; }

.search-results {
  position: absolute;
  top: 100%; left: 12px; right: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  max-height: 280px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.search-results.active { display: block; }
.search-result {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer;
}
.search-result:hover { background: var(--bg); }
.search-result .name { font-weight: 500; font-size: 14px; }
.search-empty { padding: 14px; color: var(--text-muted); font-size: 13px; text-align: center; }

.chats-title {
  padding: 14px 16px 6px;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.chats-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; cursor: pointer;
  border-left: 3px solid transparent;
}
.chat-item:hover { background: var(--bg); }
.chat-item.active { background: #e7f3ff; border-left-color: var(--accent); }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.chat-item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-left: 6px; }
.chat-item-preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty-list { padding: 30px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ==== Область чата ==== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  position: relative;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.6; }

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-info { min-width: 0; flex: 1; }
.chat-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 12px; color: var(--text-muted); min-height: 15px; }
.chat-status.online { color: #31a24c; }

/* ==== Лента сообщений ==== */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: #fafbfc;
}

/* Пузырь — компактный, по размеру текста */
.message {
  flex-shrink: 0;
  display: block;
  width: fit-content;
  max-width: 65%;
  height: auto;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  align-self: flex-start;
  margin: 0;
}

/* Исходящие — справа, синие */
.message.mine {
  align-self: flex-end;
  margin-left: auto;
  margin-right: 0;
  background: var(--msg-me);
  color: #fff;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 16px;
  text-align: left;
}

/* Входящие — слева, серые */
.message.other {
  align-self: flex-start;
  margin-left: 0;
  margin-right: auto;
  background: var(--msg-other);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 16px;
  text-align: left;
}

/* Внутри сообщения пробелы и переносы сохраняются */
.message .text {
  display: block;
  width: auto;
  height: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message .time {
  display: block;
  font-size: 11px;
  opacity: 0.7;
  margin-top: 3px;
  text-align: right;
  white-space: nowrap;
}

.message .sender {
  display: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.date-sep {
  align-self: center;
  width: auto;
  background: rgba(0,0,0,0.06);
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 8px 0;
  white-space: nowrap;
}

/* ==== Композер ==== */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  background: #f8f9fa;
}
.composer textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.send-btn {
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }

.hamburger {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 22px;
  z-index: 10;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ==== Адаптив ==== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar.open::after {
    content: '';
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0,0,0,0.4);
    z-index: -1;
    margin-left: 320px;
  }

  .mobile-only { display: inline-flex; }
  .message { max-width: 80%; }
  .empty-icon { font-size: 52px; }

    /* Компактный композер на мобилке */
  .composer {
    gap: 4px;
    padding: 8px 10px;
  }
  .attach-btn,
  .voice-btn,
  .video-note-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    font-size: 16px;
  }
  .composer textarea {
    font-size: 15px;
    padding: 8px 12px;
    min-height: 36px;
  }
  .send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    font-size: 16px;
  }
}

/* ==== Онлайн-статусы ==== */
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.avatar-wrap .online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  background: #31a24c;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05);
}

/* Точка на аватарке в шапке чата */
.chat-header .avatar.online {
  position: relative;
}
.chat-header .avatar.online::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  background: #31a24c;
  border: 2px solid #fff;
  border-radius: 50%;
}

/* ==== Непрочитанные ==== */
.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chat-item-bottom .chat-item-preview {
  flex: 1;
  min-width: 0;
}

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  min-width: 20px;
  text-align: center;
  line-height: 16px;
}

.chat-item.unread .chat-item-name {
  font-weight: 700;
}
.chat-item.unread .chat-item-preview {
  color: var(--text);
  font-weight: 600;
}

.new-divider {
  align-self: center;
  background: rgba(0, 132, 255, 0.1);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
  margin: 8px 0;
  white-space: nowrap;
}

/* ==== Печатает в списке чатов ==== */
.typing-preview {
  color: var(--accent);
  font-style: italic;
  font-weight: 500;
}

/* ==== Создание группы ==== */
.actions-row {
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}
.new-group-btn {
  width: 100%;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.new-group-btn:hover { background: var(--accent-hover); }
.new-group-btn span { font-size: 18px; line-height: 1; }

/* Модалка */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.modal-content {
  position: relative;
  background: #fff;
  border-radius: 16px;
  width: 420px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-content h3 {
  font-size: 18px;
  margin-bottom: 16px;
}
.modal-content input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: #f8f9fa;
}
.modal-content input:focus { outline: none; border-color: var(--accent); background: #fff; }

.group-members-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.group-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  min-height: 24px;
}
.group-chip {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.group-chip button {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
}
.group-chip button:hover { opacity: 1; }

.group-search-results {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}
.group-search-results:empty { display: none; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.btn-cancel, .btn-primary {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-cancel { background: var(--bg); color: var(--text); }
.btn-cancel:hover { background: #e4e6eb; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

/* Счётчик участников в превью группы */
.members-hint {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 400;
  margin-left: 6px;
}

.avatar.group {
  background: linear-gradient(135deg, #31a24c, #1e7a37);
  font-size: 18px;
}

/* ==== Информация о группе ==== */
.group-info-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.group-info-members {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  max-height: 260px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
}
.member-item:hover { background: var(--bg); }
.member-item .name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}
.member-item .role {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 8px;
}
.member-item .remove-btn {
  background: none;
  border: none;
  color: #e0245e;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 8px;
  opacity: 0.7;
}
.member-item .remove-btn:hover { opacity: 1; }

.btn-danger {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #e0245e;
  color: #fff;
}
.btn-danger:hover { background: #c81e4d; }

/* ==== Аватарки ==== */
.avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;   /* скрываем инициалы, если они остались */
  text-indent: -9999px; /* на всякий случай */
}
.avatar.has-image::after {
  /* убираем буквы */
  content: '';
}

/* Аватарка в сайдбаре кликабельна */
#me-avatar {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
#me-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 0 0 2px var(--accent);
}

.member-item .transfer-btn {
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  opacity: 0.7;
  color: #f5a623;
}
.member-item .transfer-btn:hover { opacity: 1; }

/* ==== Аватарка группы в модалке ==== */
.group-info-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.group-avatar {
  width: 64px;
  height: 64px;
  font-size: 26px;
  border-radius: 50%;
}
.group-avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.group-info-header-text {
  flex: 1;
  min-width: 0;
}
.group-info-header-text h3 {
  margin-bottom: 4px;
}

/* курсор для владельца */
.group-avatar.editable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.group-avatar.editable:hover {
  transform: scale(1.05);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ==== Кнопка прикрепить ==== */
.attach-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: background 0.15s;
}
.attach-btn:hover { background: var(--bg); }
.attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ==== Медиа в сообщениях ==== */
.message .media-image {
  display: block;
  max-width: 280px;
  max-height: 320px;
  border-radius: 10px;
  cursor: pointer;
  margin: -2px -4px 4px;
  object-fit: cover;
}
.message .media-video {
  display: block;
  max-width: 280px;
  border-radius: 10px;
  margin: -2px -4px 4px;
}
.message .media-audio {
  display: block;
  width: 260px;
  margin: -2px -4px 4px;
}
.message .media-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  text-decoration: none;
  color: inherit;
}
.message .media-file-icon {
  font-size: 28px;
  flex-shrink: 0;
}
.message .media-file-info {
  flex: 1;
  min-width: 0;
}
.message .media-file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message .media-file-size {
  font-size: 11px;
  opacity: 0.75;
}
.message.me .media-file { color: #fff; }
.message.me .media-file-size { color: rgba(255,255,255,0.8); }

/* Прогресс загрузки */
.upload-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 13px;
  margin: 6px 0;
  align-self: flex-end;
}
.upload-progress .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Лайтбокс для просмотра картинки */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
}
.lightbox.hidden { display: none; }

/* ==== Голосовые сообщения ==== */
.voice-message {
  min-width: 220px;
}
.voice-message audio {
  width: 100%;
  max-width: 280px;
  margin-bottom: 6px;
}
.voice-transcript {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 2px 0;
  border-top: 1px solid rgba(0,0,0,0.08);
  margin-top: 4px;
  color: var(--text);
}
.message.me .voice-transcript {
  color: #fff;
  border-top-color: rgba(255,255,255,0.2);
}
.voice-transcript.empty {
  font-style: italic;
  opacity: 0.6;
  font-size: 12px;
}

/* ==== Голосовое сообщение ==== */
/* ==== Голосовая кнопка ==== */
.voice-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}
.voice-btn:hover { background: var(--bg); }
.voice-btn:active { transform: scale(0.95); }
.voice-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.voice-btn.recording {
  background: #e0245e;
  color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(224, 36, 94, 0.5); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 8px rgba(224, 36, 94, 0); }
}

/* Отображение голосового сообщения */
.voice-message {
  min-width: 220px;
}
.voice-message audio {
  width: 100%;
  max-width: 280px;
  margin-bottom: 6px;
}
.voice-transcript {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 2px 0;
  border-top: 1px solid rgba(0,0,0,0.08);
  margin-top: 4px;
  color: var(--text);
  white-space: pre-wrap;
}
.message.mine .voice-transcript {
  color: #fff;
  border-top-color: rgba(255,255,255,0.2);
}
.voice-transcript.empty {
  font-style: italic;
  opacity: 0.6;
  font-size: 12px;
}

/* Кнопка расшифровки — иконка справа от плеера */
.transcribe-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.transcribe-btn:hover {
  background: rgba(0,132,255,0.12);
  color: var(--accent);
}
.transcribe-btn:disabled {
  cursor: wait;
  color: var(--accent);
}
.transcribe-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Спиннер внутри кнопки (когда идёт распознавание) */
.transcribe-btn .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Тёмная тема для моих сообщений */
.message.mine .transcribe-btn {
  color: rgba(255,255,255,0.7);
}
.message.mine .transcribe-btn:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.message.mine .transcribe-btn:disabled {
  color: #fff;
}

/* ==== Голосовой плеер ==== */
.voice-message {
  min-width: 240px;
  max-width: 320px;
}

.voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.voice-play-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.08);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
}
.voice-play-btn:hover { background: rgba(0,0,0,0.15); }
.voice-play-btn:active { transform: scale(0.95); }

.message.mine .voice-play-btn {
  background: rgba(255,255,255,0.25);
  color: #fff;
}
.message.mine .voice-play-btn:hover {
  background: rgba(255,255,255,0.35);
}

.voice-play-btn .icon-play,
.voice-play-btn .icon-pause {
  width: 18px;
  height: 18px;
}

.voice-wave {
  flex: 1;
  min-width: 80px;
  height: 24px;
  background: rgba(0,0,0,0.08);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s;
}
.voice-wave:hover { background: rgba(0,0,0,0.12); }

.message.mine .voice-wave {
  background: rgba(255,255,255,0.25);
}
.message.mine .voice-wave:hover {
  background: rgba(255,255,255,0.35);
}

.voice-progress {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  border-radius: 12px;
  transition: width 0.05s linear;
}
.message.mine .voice-progress {
  background: #fff;
  opacity: 0.9;
}

.voice-seek {
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  cursor: pointer;
}

.voice-time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: right;
}
.message.mine .voice-time {
  color: rgba(255,255,255,0.85);
}

/* Текст расшифровки */
.voice-transcript {
  font-size: 13.5px;
  line-height: 1.45;
  padding: 8px 0 2px;
  margin-top: 6px;
  border-top: 1px solid rgba(0,0,0,0.08);
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.message.mine .voice-transcript {
  color: #fff;
  border-top-color: rgba(255,255,255,0.25);
}

/* Кнопка расшифровки */
.transcribe-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0,0,0,0.03);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.transcribe-btn:hover {
  background: rgba(0,132,255,0.08);
  border-color: var(--accent);
  color: var(--accent);
}
.transcribe-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}
.transcribe-btn .spinner {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.message.mine .transcribe-btn {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: #fff;
}
.message.mine .transcribe-btn:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
}

/* Убираем старые стили для audio, если они были */
.voice-message > audio {
  display: none;
}

/* ==== Кнопка видео-сообщения ==== */
.video-note-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.video-note-btn:hover { background: var(--bg); }

/* ==== Модалка записи ==== */
#video-note-modal {
  background: rgba(0,0,0,0.85);
}
.video-note-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 1;
}
.video-note-circle {
  width: 280px;
  height: 280px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  background: #000;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.video-note-circle video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-note-timer {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.video-note-timer.recording {
  background: #e0245e;
  animation: blink 1s infinite;
}
@keyframes blink {
  50% { opacity: 0.5; }
}
.video-note-actions {
  display: flex;
  align-items: center;
  gap: 24px;
}
.video-note-cancel,
.video-note-flip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.video-note-cancel:hover,
.video-note-flip:hover { background: rgba(255,255,255,0.25); }
.video-note-record {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s;
}
.video-note-record:hover { transform: scale(1.05); }
.video-note-record::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #e0245e;
  transition: all 0.15s;
}
.video-note-record.recording::after {
  inset: 20px;
  border-radius: 6px;
  background: #e0245e;
}

/* ==== Кружок видео-сообщения в чате ==== */
.video-note-message {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  flex-shrink: 0;
}
.message .video-note-message {
  margin: -2px 0;
}
.video-note-message video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.video-note-message .vn-progress {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.video-note-message .vn-progress circle {
  fill: none;
  stroke: #0084ff;
  stroke-width: 4;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 0.05s linear;
}
.video-note-message .vn-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.video-note-message:hover .vn-play-icon,
.video-note-message.paused .vn-play-icon {
  opacity: 1;
}
.video-note-message .vn-play-icon svg {
  width: 48px;
  height: 48px;
  color: #fff;
}

@media (max-width: 768px) {
  .video-note-message { width: 160px; height: 160px; }
  .video-note-circle { width: 220px; height: 220px; }
}

/* ==== Видео-сообщение (кружок) — без пузыря ==== */
.message.video-note,
.message.video-note.mine,
.message.video-note.other {
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  border: none;
  max-width: none;
  width: auto;
  display: inline-block;
  align-self: flex-start;
}

/* Свои видео-кружки — справа */
.message.video-note.mine {
  align-self: flex-end;
  margin-left: auto;
  margin-right: 0;
}

/* Чужие — слева */
.message.video-note.other {
  align-self: flex-start;
  margin-left: 0;
  margin-right: auto;
}

/* Убираем отступ у внутренней структуры */
.message.video-note .time {
  display: none;
}

/* Кнопка уведомлений */
#notify-btn.enabled {
  color: var(--accent);
}
#notify-btn.denied {
  color: #e0245e;
  opacity: 0.5;
  cursor: not-allowed;
}

#sound-btn.muted {
  color: var(--text-muted);
  opacity: 0.5;
}

/* Кнопка админки */
.admin-link {
  text-decoration: none;
  color: var(--accent);
}
.admin-link:hover {
  background: rgba(59,130,246,0.1);
}

/* ==== Избранное ==== */
.saved-hint {
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 100%;
  width: 100%;
  padding: 40px 20px;
  color: var(--text-muted);
}
.saved-hint-icon {
  font-size: 72px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.saved-hint-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}
.saved-hint-text {
  font-size: 14px;
  line-height: 1.6;
  max-width: 400px;
}

/* Контекстное меню сообщения */
.msg-menu {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  padding: 6px;
  z-index: 1000;
  min-width: 200px;
}
.msg-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.msg-menu button:hover {
  background: var(--bg);
}

/* Тост-уведомление */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 2000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==== Ответ (reply) в сообщении ==== */
.reply-block {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.3;
  max-width: 100%;
}
.reply-block:hover { background: rgba(0,0,0,0.1); }
.message.mine .reply-block {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.7);
}
.message.mine .reply-block:hover {
  background: rgba(255,255,255,0.22);
}
.reply-block-sender {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.message.mine .reply-block-sender { color: #fff; }
.reply-block-text {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message.mine .reply-block-text { color: rgba(255,255,255,0.85); }

/* ==== Пересланное ==== */
.forward-label {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.message.mine .forward-label {
  color: rgba(255,255,255,0.9);
  border-bottom-color: rgba(255,255,255,0.2);
}

/* ==== Превью ответа в композере ==== */
.reply-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  font-size: 13px;
}
.reply-preview-content { flex: 1; min-width: 0; }
.reply-preview-title {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
.reply-preview-text {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 6px;
  line-height: 1;
}

/* ==== Модалка пересылки ==== */
.forward-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.forward-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.forward-modal-content {
  position: relative;
  background: var(--panel);
  border-radius: 16px;
  width: 400px;
  max-width: 92vw;
  max-height: 80vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  z-index: 1;
}
.forward-modal-content h3 {
  font-size: 18px;
  margin-bottom: 12px;
}
.forward-search {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #f8f9fa;
  margin-bottom: 12px;
}
.forward-search:focus { outline: none; border-color: var(--accent); background: #fff; }
.forward-list {
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.forward-item {
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}
.forward-item:hover { background: var(--bg); }
.forward-item-name { font-size: 14px; font-weight: 500; }
.forward-item-badge {
  font-size: 10px;
  background: var(--bg);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 6px;
  text-transform: uppercase;
}
.forward-cancel {
  padding: 10px;
  background: var(--bg);
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.forward-cancel:hover { background: #e4e6eb; }

/* Подсветка сообщения при переходе к оригиналу */
.message.highlight {
  animation: highlight-pulse 1.5s ease-out;
}
@keyframes highlight-pulse {
  0%, 100% { background-color: inherit; }
  20%, 60% { box-shadow: 0 0 0 3px var(--accent); }
}

/* Курсор на reply-блоке */
.reply-block {
  cursor: pointer;
  user-select: none;
}

/* ==== Панель поиска в чате ==== */
.chat-search-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.chat-search-panel input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  min-width: 0;
}
.chat-search-panel input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.search-counter {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 70px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Подсветка найденных сообщений */
.message.search-match {
  background: rgba(245, 158, 11, 0.15) !important;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4);
}
.message.mine.search-match {
  background: rgba(255, 200, 50, 0.3) !important;
}
.message.search-match.active {
  background: rgba(245, 158, 11, 0.35) !important;
  box-shadow: 0 0 0 3px #f59e0b;
  animation: highlight-pulse 0.6s ease-out;
}
.message.mine.search-match.active {
  background: rgba(255, 200, 50, 0.5) !important;
}

/* Подсветка текста внутри */
.message mark.search-hl {
  background: #fde68a;
  color: inherit;
  padding: 1px 2px;
  border-radius: 2px;
}
.message.mine mark.search-hl {
  background: rgba(255,255,255,0.5);
  color: #000;
}

/* Кнопка уведомлений на мобильном */
#notify-btn.denied {
  color: var(--text-muted);
  opacity: 0.5;
}
#notify-btn.enabled {
  color: var(--accent);
}

/* ==== PWA ==== */
.pwa-mode .sidebar-header {
  padding-top: max(12px, env(safe-area-inset-top));
}
.pwa-mode .composer {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

#install-pwa-btn {
  color: var(--accent);
}

/* Установочный баннер для iOS (Safari не показывает beforeinstallprompt) */
.ios-install-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 3000;
  max-width: 90vw;
  text-align: center;
  animation: slideUp 0.3s ease;
}
.ios-install-hint button {
  background: none;
  border: none;
  color: #93c5fd;
  font-weight: 600;
  cursor: pointer;
  margin-left: 8px;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}