/* ============================================================
   MyMessenger — стили в духе Telegram Desktop (светлая тема)
   ============================================================ */
:root {
  --tg-blue: #3390ec;
  --tg-blue-dark: #2b7cd3;
  --sidebar-bg: #ffffff;
  --chat-bg: #e7ebf0;
  --bubble-in: #ffffff;
  --bubble-out: #effdde;
  --bubble-out-meta: #62ac55;
  --text: #000000;
  --text-secondary: #707579;
  --divider: #e4e4e5;
  --hover: #f4f4f5;
  --active: #3390ec;
  --online: #4dcd5e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--chat-bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font: inherit; outline: none; }

/* ---------- Экран входа ---------- */
.auth-screen {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #6db3f2 0%, #3390ec 60%, #2b7cd3 100%);
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  width: 360px; max-width: calc(100vw - 32px);
  box-shadow: 0 12px 40px rgba(0,0,0,.18); text-align: center;
}
.auth-logo { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.auth-card h1 { font-size: 24px; font-weight: 600; }
.auth-sub { color: var(--text-secondary); margin: 6px 0 24px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  border: 1px solid var(--divider); border-radius: 10px;
  padding: 12px 14px; transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--tg-blue); }
.auth-error { color: #e53935; font-size: 13px; min-height: 16px; }
.btn-primary {
  background: var(--tg-blue); color: #fff; border-radius: 10px;
  padding: 12px; font-weight: 600; transition: background .15s;
}
.btn-primary:hover { background: var(--tg-blue-dark); }
.btn-link { color: var(--tg-blue); font-size: 14px; padding: 4px; }

/* ---------- Каркас приложения ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Сайдбар ---------- */
.sidebar {
  width: 380px; min-width: 260px; background: var(--sidebar-bg);
  border-right: 1px solid var(--divider);
  display: flex; flex-direction: column; position: relative;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; color: var(--text-secondary); transition: background .15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); }
.search-wrap { flex: 1; }
.search-wrap input {
  width: 100%; background: #f4f4f5; border: 2px solid transparent;
  border-radius: 22px; padding: 9px 18px; transition: all .15s;
}
.search-wrap input:focus { background: #fff; border-color: var(--tg-blue); }

.menu-dropdown {
  position: absolute; top: 54px; left: 12px; z-index: 30;
  background: #fff; border-radius: 12px; min-width: 240px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18); padding: 8px 0; overflow: hidden;
}
.menu-me { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.menu-me-name { font-weight: 600; }
.menu-me-username { color: var(--text-secondary); font-size: 13px; }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 10px 16px;
}
.menu-item:hover { background: var(--hover); }

/* ---------- Панель приглашений ---------- */
.invite-panel {
  position: absolute; top: 54px; left: 12px; right: 12px; z-index: 31;
  background: #fff; border-radius: 12px; padding: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  display: flex; flex-direction: column; gap: 12px;
}
.invite-title { font-weight: 600; }
.invite-new { display: flex; align-items: center; gap: 8px; }
.invite-code {
  flex: 1; font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  font-size: 17px; font-weight: 600; letter-spacing: 2px;
  background: #f4f4f5; border-radius: 8px; padding: 8px 12px; text-align: center;
  user-select: all;
}
.btn-mini {
  border: 1px solid var(--divider); border-radius: 8px; padding: 8px 12px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.btn-mini:hover { background: var(--hover); }
.btn-mini.primary { background: var(--tg-blue); color: #fff; border-color: var(--tg-blue); }
.btn-mini.primary:hover { background: var(--tg-blue-dark); }
.invite-list { max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.invite-row {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; padding: 5px 8px; border-radius: 6px; background: #fafafa;
}
.invite-row code { font-family: ui-monospace, Consolas, monospace; }
.invite-row .used { color: var(--text-secondary); }
.invite-row .free { color: #4dcd5e; font-weight: 600; }
.invite-row .revoked { color: #e53935; }
.invite-row { align-items: center; }
.invite-row code { flex-shrink: 0; }
.invite-row span { flex: 1; text-align: right; margin-right: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-mini.danger { color: #e53935; border-color: #f3b6b4; }
.btn-mini.danger:hover { background: #fdeceb; }

/* ---------- Список чатов ---------- */
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin: 0 8px; border-radius: 10px; cursor: pointer;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); color: #fff; }
.chat-item.active .chat-item-last,
.chat-item.active .chat-item-time { color: rgba(255,255,255,.85); }

.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 20px; user-select: none;
}
.avatar.has-photo { background-color: var(--divider); }

/* ---------- Прогресс загрузки ---------- */
.upload-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35); border-radius: 10px; pointer-events: none;
}
.upload-ring {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center;
}
.upload-ring .upload-label { color: #fff; font-size: 13px; font-weight: 600; }
.upload-overlay .upload-bar {
  position: absolute; bottom: 8px; left: 10px; right: 10px;
}
.photo-bubble { position: relative; }

.upload-file-progress { margin-top: 6px; }
.upload-bar {
  height: 4px; border-radius: 2px; background: rgba(0,0,0,.12); overflow: hidden;
}
.upload-bar-fill {
  height: 100%; width: 0%; background: var(--tg-blue);
  border-radius: 2px; transition: width .15s;
}
.msg.out .upload-bar-fill { background: #62ac55; }
.upload-file-progress .upload-label {
  font-size: 12px; color: var(--text-secondary); margin-top: 3px; display: block;
}

/* ---------- Профиль ---------- */
.profile-dialog {
  position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.profile-box {
  background: #fff; border-radius: 14px; width: 400px; max-width: calc(100vw - 24px);
  max-height: 90vh; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.profile-header { display: flex; align-items: center; justify-content: space-between; }
.profile-title { font-size: 19px; font-weight: 600; }
.profile-avatar-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative;
}
.profile-avatar { width: 110px; height: 110px; font-size: 42px; }
.avatar-edit {
  position: absolute; top: 74px; left: 50%; margin-left: 18px;
  width: 36px; height: 36px; border-radius: 50%; background: var(--tg-blue);
  color: #fff; font-size: 16px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25); border: 2px solid #fff;
}
.avatar-edit:hover { background: var(--tg-blue-dark); }
.profile-field { display: flex; flex-direction: column; gap: 4px; }
.profile-label { font-size: 13px; color: var(--tg-blue); font-weight: 600; }
.profile-field input, .profile-field textarea {
  border: none; border-bottom: 1px solid var(--divider); padding: 8px 2px;
  font-size: 15px; resize: none; font-family: inherit; outline: none;
}
.profile-field input:focus, .profile-field textarea:focus { border-bottom-color: var(--tg-blue); }
.profile-username { font-size: 15px; color: var(--text-secondary); padding: 8px 2px; }
.profile-error { color: #e53935; font-size: 13px; min-height: 16px; }
.avatar.small { width: 42px; height: 42px; font-size: 16px; }
.avatar-me { width: 42px; height: 42px; font-size: 16px; }

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; margin-left: 8px; }
.chat-item-last {
  color: var(--text-secondary); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.list-caption { padding: 12px 20px 6px; font-size: 13px; color: var(--text-secondary); font-weight: 600; }

/* бейдж непрочитанных */
.chat-item-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.unread-badge {
  background: var(--tg-blue); color: #fff; font-size: 12px; font-weight: 600;
  min-width: 22px; height: 22px; border-radius: 11px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-item.active .unread-badge { background: #fff; color: var(--tg-blue); }

/* ---------- Просмотр фото ---------- */
.photo-viewer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .92);
  display: flex; align-items: center; justify-content: center;
  animation: viewerFade .15s ease;
}
@keyframes viewerFade { from { opacity: 0; } to { opacity: 1; } }
.photo-viewer img {
  max-width: 94vw; max-height: 92vh; object-fit: contain;
  border-radius: 4px; cursor: default;
  animation: viewerZoom .18s ease;
}
@keyframes viewerZoom { from { transform: scale(.94); } to { transform: scale(1); } }
.photo-viewer-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: flex-end; gap: 6px; padding: 12px 16px;
  background: linear-gradient(rgba(0,0,0,.4), transparent); z-index: 2;
}
.viewer-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 19px; text-decoration: none;
  transition: background .15s; cursor: pointer;
}
.viewer-btn:hover { background: rgba(255,255,255,.15); }
.photo-caption {
  position: absolute; bottom: 0; left: 0; right: 0;
  text-align: center; color: #fff; padding: 16px;
  background: linear-gradient(transparent, rgba(0,0,0,.5));
}
.photo-caption:empty { display: none; }

/* ---------- Область чата ---------- */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--chat-bg);
  background-image: radial-gradient(circle at 25% 25%, rgba(51,144,236,.05) 0%, transparent 50%),
                    radial-gradient(circle at 75% 75%, rgba(51,144,236,.05) 0%, transparent 50%);
}
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.empty-state span {
  background: rgba(0,0,0,.25); color: #fff; padding: 6px 14px;
  border-radius: 16px; font-size: 14px;
}

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-header {
  background: #fff; border-bottom: 1px solid var(--divider);
  display: flex; align-items: center; gap: 12px; padding: 7px 16px;
  cursor: default;
}
.chat-header .avatar { width: 42px; height: 42px; font-size: 16px; }
.chat-header-name { font-weight: 600; }
.chat-header-status { font-size: 13px; color: var(--text-secondary); }
.chat-header-status.typing { color: var(--tg-blue); }

/* ---------- Сообщения ---------- */
.messages {
  flex: 1; overflow-y: auto; padding: 12px 8%;
  display: flex; flex-direction: column; gap: 4px;
}
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: 480px; padding: 7px 12px 6px; border-radius: 15px;
  background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,.08);
  position: relative; word-wrap: break-word; overflow-wrap: break-word;
}
.msg.in  .bubble { border-bottom-left-radius: 4px; }
.msg.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; }

.bubble-text { white-space: pre-wrap; }
.bubble-meta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; color: var(--text-secondary);
  float: right; margin: 6px -4px -2px 8px; user-select: none;
}
.msg.out .bubble-meta { color: var(--bubble-out-meta); }

.bubble img.photo {
  max-width: 360px; max-height: 380px; width: 100%;
  border-radius: 10px; display: block; margin: -2px -7px 4px; cursor: pointer;
  object-fit: cover;
}
.bubble.photo-bubble { padding: 5px 10px 6px; }

.file-row { display: flex; align-items: center; gap: 10px; padding: 2px 0; text-decoration: none; color: inherit; }
.file-icon {
  width: 44px; height: 44px; border-radius: 50%; background: var(--tg-blue);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.msg.out .file-icon { background: #62ac55; }
.file-name { font-weight: 600; font-size: 14px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 13px; color: var(--text-secondary); }

.day-divider { align-self: center; background: rgba(0,0,0,.25); color: #fff;
  font-size: 13px; padding: 3px 12px; border-radius: 14px; margin: 8px 0; }

/* ---------- Статусы отправки ---------- */
.msg-status { display: inline-flex; vertical-align: middle; margin-left: 2px; }
.msg-status svg { display: block; }
/* галочки исходящих — в цвет времени (зелёный), видны на светлом пузыре */
.msg.out .msg-status { color: var(--bubble-out-meta); }
.msg.out .msg-status.read { color: var(--bubble-out-meta); opacity: 1; }
.msg.out .bubble-meta { opacity: .85; }
.msg.sending .bubble { opacity: .7; }
.msg.failed .bubble { border: 1px solid #e53935; }
.status-clock { color: var(--bubble-out-meta); }
.status-error { color: #e53935; cursor: pointer; font-weight: 700; }

/* ---------- Метка пересылки ---------- */
.fwd-label {
  font-size: 13px; color: var(--tg-blue); font-weight: 600;
  margin-bottom: 2px; display: block;
}
.msg.out .fwd-label { color: var(--bubble-out-meta); }
.fwd-label small { font-weight: 400; color: var(--text-secondary); display: block; }

/* ---------- Режим выбора сообщений ---------- */
.select-header { background: #fff; }
.msg.selectable { cursor: pointer; }
.msg .select-check {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--text-secondary); align-self: center;
  margin: 0 6px; display: none; position: relative; transition: all .12s;
}
.app.selecting .msg .select-check { display: block; }
.app.selecting .msg.out { flex-direction: row-reverse; }
.msg.selected .select-check { background: var(--tg-blue); border-color: var(--tg-blue); }
.msg.selected .select-check::after {
  content: '✓'; color: #fff; font-size: 15px; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}
.app.selecting .messages { cursor: default; }
.app.selecting .composer { display: none; }

/* ---------- Диалог пересылки ---------- */
.forward-dialog {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.forward-box {
  background: #fff; border-radius: 14px; width: 360px; max-width: calc(100vw - 24px);
  max-height: 70vh; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.forward-title { font-weight: 600; font-size: 17px; }
.forward-search {
  border: 1px solid var(--divider); border-radius: 10px; padding: 10px 12px;
}
.forward-search:focus { border-color: var(--tg-blue); }
.forward-chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.forward-chat {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer;
}
.forward-chat:hover { background: var(--hover); }
.forward-chat .avatar { width: 40px; height: 40px; font-size: 15px; }

/* ---------- Контекстное меню сообщения ---------- */
.msg-menu {
  position: fixed; z-index: 50; background: #fff; border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.2); padding: 6px 0; min-width: 160px;
}
.msg-menu .menu-item.danger { color: #e53935; }
.edited-mark { font-style: normal; }

/* ---------- Панель редактирования ---------- */
.edit-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 8% -4px; padding: 8px 14px;
  background: #fff; border-radius: 12px 12px 0 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  border-left: 3px solid var(--tg-blue);
}
.edit-bar-label { color: var(--tg-blue); font-weight: 600; font-size: 13px; white-space: nowrap; }
.edit-bar-preview {
  flex: 1; color: var(--text-secondary); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Панель эмодзи ---------- */
.emoji-panel {
  position: absolute; bottom: 76px; left: 8%; z-index: 20;
  background: #fff; border-radius: 14px; box-shadow: 0 4px 24px rgba(0,0,0,.18);
  padding: 10px; width: 320px; max-width: calc(100vw - 24px);
  max-height: 260px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.emoji-panel button {
  font-size: 22px; padding: 5px; border-radius: 8px; line-height: 1;
}
.emoji-panel button:hover { background: var(--hover); }

@media (max-width: 720px) {
  .edit-bar { margin: 0 8px -4px; }
  .emoji-panel { left: 8px; bottom: 64px; }
}

/* ---------- Видео в чате ---------- */
.bubble video.video {
  max-width: 360px; max-height: 380px; width: 100%;
  border-radius: 10px; display: block; margin: -2px -7px 4px;
  background: #000;
}

/* ---------- Голосовое сообщение ---------- */
.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0; }
.voice-play {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--tg-blue); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.msg.out .voice-play { background: #62ac55; }
.voice-body { flex: 1; }
.voice-track {
  height: 6px; border-radius: 3px; background: rgba(0,0,0,.12);
  cursor: pointer; position: relative; margin-bottom: 5px;
}
.voice-progress {
  height: 100%; width: 0%; border-radius: 3px; background: var(--tg-blue);
  pointer-events: none;
}
.msg.out .voice-progress { background: #62ac55; }
.voice-time { font-size: 13px; color: var(--text-secondary); }
.voice-text-btn {
  flex-shrink: 0; font-size: 13px; font-weight: 600; color: var(--tg-blue);
  border: 1.5px solid var(--tg-blue); border-radius: 12px; padding: 2px 9px;
}
.msg.out .voice-text-btn { color: #62ac55; border-color: #62ac55; }
.voice-transcript {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(0,0,0,.08);
  font-size: 14px; color: var(--text-secondary); white-space: pre-wrap;
}

/* ---------- Панель записи ---------- */
.record-bar {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 16px; padding: 12px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%; background: #e53935;
  animation: recPulse 1s infinite;
}
@keyframes recPulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
#recTime { font-weight: 600; min-width: 42px; }
.rec-hint { color: var(--text-secondary); flex: 1; font-size: 14px; }
.rec-cancel { color: #e53935; font-weight: 600; padding: 4px 8px; }
.composer.recording #messageInput,
.composer.recording #attachBtn,
.composer.recording #emojiBtn { display: none; }
.composer.recording .record-bar { display: flex; }
/* кнопка отправки при записи ВИДНА — по ней отправляется голосовое */
.composer.recording #sendBtn { display: inline-flex; }
#voiceBtn.recording { background: var(--tg-blue); color: #fff; }

/* ---------- Шапка диалога: кнопки звонков ---------- */
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info { cursor: pointer; }

/* ---------- Панель информации о чате ---------- */
.chat-info-panel { position: fixed; inset: 0; z-index: 70; }
.chat-info-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.3); }
.chat-info-content {
  position: absolute; top: 0; right: 0; bottom: 0; width: 380px; max-width: 100vw;
  background: #fff; display: flex; flex-direction: column;
  box-shadow: -2px 0 16px rgba(0,0,0,.15); animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.chat-info-head {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  border-bottom: 1px solid var(--divider); font-weight: 600; font-size: 17px;
}
.chat-info-profile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 24px 16px; border-bottom: 8px solid var(--chat-bg);
}
.chat-info-avatar { width: 100px; height: 100px; font-size: 38px; }
.chat-info-name { font-size: 20px; font-weight: 600; margin-top: 8px; }
.chat-info-username { color: var(--text-secondary); font-size: 14px; }
.chat-info-bio { text-align: center; margin-top: 8px; font-size: 14px; max-width: 300px; }
.chat-info-tabs { display: flex; border-bottom: 1px solid var(--divider); }
.info-tab {
  flex: 1; padding: 12px; font-size: 14px; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid transparent;
}
.info-tab.active { color: var(--tg-blue); border-bottom-color: var(--tg-blue); }
.chat-info-body { flex: 1; overflow-y: auto; }
.info-tab-content { padding: 8px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.media-grid .media-cell {
  aspect-ratio: 1; background: var(--chat-bg) center/cover; border-radius: 4px;
  cursor: pointer; position: relative; overflow: hidden;
}
.media-grid .media-cell video, .media-grid .media-cell img {
  width: 100%; height: 100%; object-fit: cover;
}
.media-cell .video-mark {
  position: absolute; bottom: 4px; left: 4px; color: #fff; font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.info-file-row {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px;
  text-decoration: none; color: inherit;
}
.info-file-row:hover { background: var(--hover); }
.info-link-row { padding: 8px; border-radius: 8px; }
.info-link-row:hover { background: var(--hover); }
.info-link-row a { color: var(--tg-blue); word-break: break-all; font-size: 14px; }
.info-empty { text-align: center; color: var(--text-secondary); padding: 30px; font-size: 14px; grid-column: 1 / -1; }

@media (max-width: 720px) {
  .chat-info-content { width: 100%; }
}
.chat-header-actions { display: flex; gap: 2px; }

/* ---------- Экран звонка ---------- */
.call-screen {
  position: fixed; inset: 0; z-index: 200; background: #1c2733;
  display: flex; align-items: center; justify-content: center;
}
#remoteVideo {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #1c2733;
}
#localVideo {
  position: absolute; right: 16px; top: 16px; width: 180px; max-width: 32vw;
  border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.4);
  background: #000; z-index: 2; transform: scaleX(-1); /* зеркало для своей камеры */
}
.call-screen.audio-only #remoteVideo,
.call-screen.audio-only #localVideo { display: none; }
.call-info {
  position: relative; z-index: 1; text-align: center; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none;
}
.call-screen:not(.audio-only) .call-info {
  position: absolute; top: 20px; left: 0; right: 0;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.call-screen:not(.audio-only) .call-avatar { display: none; }
.call-avatar { width: 110px; height: 110px; font-size: 40px; }
.call-name { font-size: 22px; font-weight: 600; }
.call-status { font-size: 15px; opacity: .8; }
.call-controls {
  position: absolute; bottom: 36px; left: 0; right: 0; z-index: 3;
  display: flex; justify-content: center; gap: 18px;
}
.call-btn {
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px); transition: background .15s;
}
.call-btn:hover { background: rgba(255,255,255,.3); }
.call-btn.off { background: #fff; color: #1c2733; }
.call-btn.off::after {
  content: ''; position: absolute; width: 34px; height: 2.5px;
  background: #e53935; transform: rotate(-45deg); border-radius: 2px;
}
.call-btn { position: relative; }
.call-btn.hangup { background: #e53935; }
.call-btn.hangup:hover { background: #c62828; }

/* ---------- Входящий вызов ---------- */
.incoming-call {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 300; background: #fff; border-radius: 14px;
  box-shadow: 0 6px 30px rgba(0,0,0,.25); padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px; min-width: 300px;
  animation: incomingSlide .25s ease;
}
@keyframes incomingSlide { from { transform: translate(-50%, -120%); } to { transform: translate(-50%, 0); } }
.incoming-text { font-weight: 600; text-align: center; }
.incoming-actions { display: flex; gap: 10px; }
.incoming-btn { flex: 1; padding: 10px; border-radius: 10px; font-weight: 600; color: #fff; }
.incoming-btn.accept { background: #4dcd5e; }
.incoming-btn.decline { background: #e53935; }

.history-loader {
  align-self: center; color: var(--text-secondary); font-size: 13px;
  padding: 6px 14px; margin: 4px 0;
}

/* ---------- Кнопка «к последним сообщениям» ---------- */
.scroll-down-btn {
  position: absolute; right: 16px; bottom: 80px; z-index: 5;
  width: 50px; height: 50px; border-radius: 50%;
  background: #fff; color: var(--text-secondary);
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; transition: background .15s, transform .15s;
}
.scroll-down-btn:hover { background: var(--hover); transform: translateY(-2px); }
.scroll-down-badge {
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  background: var(--tg-blue); color: #fff; font-size: 12px; font-weight: 600;
  min-width: 21px; height: 21px; border-radius: 11px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Поле ввода ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 8%; background: transparent;
}
.composer textarea {
  flex: 1; background: #fff; border: none; border-radius: 16px;
  padding: 12px 16px; resize: none; max-height: 140px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.composer .icon-btn { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--tg-blue); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.15); transition: background .15s;
}
.send-btn:hover { background: var(--tg-blue-dark); }

/* ---------- Адаптив ---------- */
.back-btn { display: none; }

@media (max-width: 720px) {
  .sidebar { width: 100%; min-width: 0; border-right: none; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat-area { display: none; }

  .back-btn { display: flex; font-size: 22px; }

  .messages { padding: 10px 8px; }
  .composer { padding: 8px; gap: 6px; }
  .bubble { max-width: 86vw; }
  .bubble img.photo { max-width: 72vw; }
  .chat-header { padding: 6px 8px; gap: 8px; }

  /* 16px в полях ввода — iOS не будет приближать страницу при фокусе */
  input, textarea { font-size: 16px; }

  .auth-card { padding: 32px 22px; }
  .file-name { max-width: 55vw; }
}

/* фокус с клавиатуры */
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--tg-blue); outline-offset: 1px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ===== Панель управления пользователями (админ) ===== */
.users-list {
  max-height: 340px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.users-empty {
  text-align: center; color: var(--text-secondary);
  font-size: 14px; padding: 24px 0;
}
.user-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 10px; background: #fafafa; flex-wrap: wrap;
}
.user-row.blocked { background: #fdeceb; }
.user-main { min-width: 140px; flex: 1 1 140px; }
.user-name {
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-meta {
  font-size: 12px; color: var(--text-secondary); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-block-btn {
  flex-shrink: 0; border: 1px solid #f3b6b4; color: #e53935;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  white-space: nowrap; background: #fff; cursor: pointer; transition: background .15s;
}
.user-block-btn:hover { background: #fdeceb; }
.user-block-btn.restore { border-color: var(--tg-blue); color: var(--tg-blue); }
.user-block-btn.restore:hover { background: #eaf3fd; }

/* действия в строке пользователя */
.user-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; flex-wrap: wrap; }
.user-pass-btn {
  border: 1px solid var(--divider); color: var(--text-secondary);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  white-space: nowrap; background: #fff; cursor: pointer; transition: background .15s;
}
.user-pass-btn:hover { background: var(--hover); }

/* ===== SVG-иконки (единый стиль как на доске) ===== */
.icon-btn svg, .send-btn svg { display: block; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.send-btn { display: inline-flex; align-items: center; justify-content: center; }
/* иконка в пунктах меню — выравнивание с текстом */
.menu-item { display: flex; align-items: center; gap: 0; }
.mi-ico { flex-shrink: 0; vertical-align: middle; margin-right: 10px; }

/* ===== Реакции ===== */
/* ряд выбора реакций в меню сообщения */
.reaction-row {
  display: flex; gap: 2px; padding: 6px; margin-bottom: 4px;
  border-bottom: 1px solid var(--divider); flex-wrap: wrap; justify-content: center;
}
.reaction-pick {
  border: none; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; padding: 6px; border-radius: 8px;
  transition: background .12s, transform .12s;
}
.reaction-pick:hover { background: var(--hover); transform: scale(1.2); }
.reaction-pick.active { background: #e7f0fb; }

/* плашки реакций внутри пузыря (стиль Telegram) */
.reactions {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin: 4px 0 0; width: 100%;
}
.reaction {
  display: inline-flex; align-items: center; gap: 3px;
  border: none; cursor: pointer;
  border-radius: 11px; padding: 2px 7px 2px 5px;
  font-size: 12px; line-height: 1.5; transition: background .12s;
}
/* в чужом (входящем) пузыре — светлая плашка */
.msg.in .reaction { background: rgba(0,0,0,.06); }
.msg.in .reaction:hover { background: rgba(0,0,0,.1); }
.msg.in .reaction.mine { background: var(--tg-blue); }
.msg.in .reaction.mine .reaction-count { color: #fff; }
/* в своём (исходящем) пузыре — на фоне синего пузыря */
.msg.out .reaction { background: rgba(255,255,255,.25); }
.msg.out .reaction:hover { background: rgba(255,255,255,.35); }
.msg.out .reaction.mine { background: #fff; }
.msg.out .reaction.mine .reaction-count { color: var(--tg-blue); }
.reaction-emoji { font-size: 13px; }
.reaction-count { font-weight: 600; color: var(--text-secondary); }
.msg.out .reaction-count { color: rgba(255,255,255,.9); }

/* когда есть реакции — мета (время) переносится на свою строку */
.bubble.has-reactions .bubble-meta { display: inline-block; }

/* ===== Ответы (reply) ===== */
/* панель цитаты над полем ввода */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #fff; border-radius: 12px;
  margin-bottom: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.reply-bar-ico { color: var(--tg-blue); flex-shrink: 0; }
.reply-bar-body {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  border-left: 2px solid var(--tg-blue); padding-left: 8px;
}
.reply-bar-author { font-size: 13px; font-weight: 600; color: var(--tg-blue); }
.reply-bar-preview {
  font-size: 13px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* цитата внутри пузыря сообщения */
.reply-quote {
  display: flex; flex-direction: column; gap: 1px;
  border-left: 3px solid var(--tg-blue);
  padding: 3px 8px; margin-bottom: 5px; cursor: pointer;
  background: rgba(0,0,0,.04); border-radius: 4px;
  max-width: 100%;
}
.msg.out .reply-quote { border-left-color: #3a7d31; background: rgba(0,0,0,.06); }
.reply-quote-author { font-size: 12px; font-weight: 600; color: var(--tg-blue); }
.msg.out .reply-quote-author { color: #2f6b28; }
.reply-quote-text {
  font-size: 13px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
}
.reply-quote:hover { background: rgba(0,0,0,.09); }

/* подсветка сообщения при переходе по цитате */
.msg.highlight .bubble {
  animation: replyHighlight 1.5s ease;
}
@keyframes replyHighlight {
  0%, 100% { box-shadow: 0 0 0 0 rgba(51,144,236,0); }
  30% { box-shadow: 0 0 0 3px rgba(51,144,236,.5); }
}

/* ===== Перетаскивание файлов ===== */
.drop-overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(51,144,236,.12); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-overlay-inner {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  color: var(--tg-blue); border: 2.5px dashed var(--tg-blue);
  border-radius: 20px; padding: 40px 60px; background: rgba(255,255,255,.9);
}
.drop-overlay-text { font-size: 17px; font-weight: 600; }

/* ===== Окно предпросмотра файла с подписью ===== */
.file-preview {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.file-preview-dialog {
  background: #fff; border-radius: 16px; width: 100%; max-width: 460px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,.25);
}
.file-preview-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--divider);
}
.file-preview-title { font-size: 16px; font-weight: 600; }
.file-preview-body {
  padding: 16px; display: flex; align-items: center; justify-content: center;
  max-height: 60vh; overflow: auto; background: #fafafa;
}
.file-preview-media { max-width: 100%; max-height: 52vh; border-radius: 10px; display: block; }
.file-preview-card {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px;
  background: #fff; border: 1px solid var(--divider); border-radius: 12px; width: 100%;
}
.file-preview-icon {
  width: 48px; height: 48px; border-radius: 10px; flex-shrink: 0;
  background: var(--tg-blue); color: #fff; display: flex; align-items: center; justify-content: center;
}
.file-preview-info { min-width: 0; flex: 1; }
.file-preview-name {
  font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-preview-size { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.file-preview-foot {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--divider);
}
.file-preview-caption {
  flex: 1; border: none; background: var(--input-bg, #f0f2f5); border-radius: 20px;
  padding: 11px 16px; font-size: 15px; font-family: inherit; outline: none;
}
.file-preview-send {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; border: none;
  background: var(--tg-blue); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.file-preview-send:hover { background: var(--tg-blue-dark); }

/* галерея нескольких файлов в окне предпросмотра */
.file-preview-body.gallery {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  align-content: start;
}
.preview-cell { position: relative; }
.file-preview-body.gallery .preview-cell .file-preview-media {
  width: 100%; height: 110px; object-fit: cover; border-radius: 8px;
}
.file-preview-body.gallery .file-preview-card { padding: 10px; height: 110px; flex-direction: column; justify-content: center; text-align: center; gap: 6px; }
.preview-cell-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.55); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.preview-cell-remove:hover { background: rgba(0,0,0,.75); }
/* одиночный файл — крестик не нужен */
.file-preview-body:not(.gallery) .preview-cell-remove { display: none; }

/* ===== Видео: превью с кнопкой play ===== */
.video-preview { position: relative; cursor: pointer; line-height: 0; border-radius: 12px; overflow: hidden; }
.video-preview .video {
  max-width: 260px; max-height: 320px; width: 100%; display: block;
  border-radius: 12px; background: #000;
}
.video-play-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.video-play-overlay svg {
  width: 60px; height: 60px; padding: 14px;
  background: rgba(0,0,0,.5); border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
/* иконка типа сообщения в списке чатов */
.prev-ico { vertical-align: -2px; margin-right: 4px; opacity: .7; }
/* видео в полноэкранном просмотрщике */
#photoViewerVideo {
  max-width: 92vw; max-height: 82vh; border-radius: 8px; background: #000;
}
