:root {
  --accent: #2AABEE;
  --accent-dark: #229ED9;
  --bg: #f4f4f5;
  --sidebar-bg: #ffffff;
  --border: #e4e4e7;
  --bubble-out: #effdde;
  --bubble-in: #ffffff;
  --text: #18181b;
  --text-muted: #71717a;
  --danger: #e5484d;
  --success: #30a46c;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}
.hidden { display: none !important; }

/* ---- AUTH ---- */
.auth-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: white;
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  width: 320px;
}
.auth-logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 10px; }
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 14px; font-weight: 700; }
.auth-dark-toggle { justify-content: center; margin-bottom: 16px; }
.tabs { display: flex; margin-bottom: 16px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.tab { flex: 1; padding: 8px; border: none; background: white; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--accent); color: white; }
.auth-card input {
  width: 100%; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.primary-btn {
  width: 100%; padding: 10px; background: var(--accent); color: white;
  border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.primary-btn:hover { background: var(--accent-dark); }
.secondary-btn {
  width: 100%; padding: 8px; background: #eee; border: none; border-radius: 8px;
  cursor: pointer; margin-top: 8px;
}
.error { color: var(--danger); font-size: 13px; text-align: center; min-height: 16px; }

/* ---- APP LAYOUT ---- */
.app-screen { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 300px; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
  background: rgba(255,255,255,0.72); backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}
.sidebar-header button {
  background: none; border: none; font-size: 18px; cursor: pointer; color: var(--accent);
}
.chat-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

/* ---- РУЧКА ДЛЯ ОТКРЫТИЯ ЛЕНТЫ ИСТОРИЙ ---- */
.stories-handle {
  display: flex; justify-content: center; align-items: center; padding: 3px 0;
  cursor: pointer; border-bottom: 1px solid var(--border); background: var(--sidebar-bg);
  touch-action: none;
}
.stories-handle-chevron {
  font-size: 13px; color: var(--text-muted); transition: transform 0.25s ease; display: inline-block;
}
.stories-handle-chevron.open { transform: rotate(180deg); }

/* ---- ЛЕНТА ИСТОРИЙ (сворачиваемая) ---- */
.stories-bar {
  display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden;
  max-height: 0; padding: 0 14px; border-bottom: 0 solid var(--border);
  transition: max-height 0.28s ease, padding 0.28s ease;
}
.stories-bar.expanded { max-height: 92px; padding: 10px 14px; border-bottom-width: 1px; }
.story-ring-item { display: flex; flex-direction: column; align-items: center; gap: 4px; flex-shrink: 0; width: 58px; cursor: pointer; }
.story-ring {
  width: 54px; height: 54px; border-radius: 50%; padding: 2.5px;
  background: linear-gradient(45deg, #f9ce34, #ee2a7b, #6228d7);
}
.story-ring.seen { background: var(--border); }
.story-ring.add-story { background: none; }
.story-ring-inner {
  width: 100%; height: 100%; border-radius: 50%; background: var(--sidebar-bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative;
}
.story-ring-label { font-size: 11px; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
.story-add-plus {
  position: absolute; bottom: -1px; right: -1px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 13px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--sidebar-bg);
}

/* ---- ПРОСМОТРЩИК ИСТОРИЙ ---- */
.story-viewer {
  position: fixed; inset: 0; background: black; z-index: 90;
  display: flex; flex-direction: column;
}
.story-viewer.hidden { display: none !important; }
.story-progress-row {
  display: flex; gap: 4px; padding: 8px 8px 0; padding-top: max(8px, env(safe-area-inset-top));
}
.story-progress-track { flex: 1; height: 2.5px; background: rgba(255,255,255,0.3); border-radius: 2px; overflow: hidden; }
.story-progress-fill { height: 100%; width: 0%; background: white; }
.story-viewer-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: white;
}
.story-viewer-name { font-weight: 600; font-size: 14px; }
.story-viewer-time { font-size: 12px; color: rgba(255,255,255,0.6); flex: 1; }
.story-viewer-btn { background: none; border: none; color: white; font-size: 16px; cursor: pointer; padding: 4px 8px; }
.story-media-wrap { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.story-media-wrap img, .story-media-wrap video { max-width: 100%; max-height: 100%; object-fit: contain; }
.story-caption { color: white; text-align: center; padding: 10px 20px 20px; font-size: 14px; }
.story-tap-zone { position: absolute; top: 40px; bottom: 60px; width: 35%; }
.story-tap-prev { left: 0; }
.story-tap-next { right: 0; }

.story-create-preview { margin: 10px 0; text-align: center; }
.story-create-preview img, .story-create-preview video { max-width: 100%; max-height: 200px; border-radius: 8px; }
.chat-item {
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f2f2f3;
  display: flex; align-items: center; gap: 10px;
}
.chat-item-texts { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.chat-item:hover, .chat-item.active { background: #f0f7ff; }
.chat-item .chat-item-title { font-weight: 600; font-size: 14px; }
.chat-item .chat-item-preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- CHAT WINDOW ---- */
.chat-window { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.empty-state { margin: auto; color: var(--text-muted); }
.active-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.72); backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  position: relative; z-index: 15;
}
.chat-header-info {
  display: flex; align-items: center; gap: 8px; background: none; border: none;
  cursor: pointer; font-weight: 600; font-size: 15px; color: var(--text); padding: 0;
}
.chat-header-info:hover { opacity: 0.8; }
.chat-header-texts { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.presence-label { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.chat-header #chat-title { flex: 0 0 auto; }
.typing-indicator { font-size: 12px; font-weight: 400; color: var(--accent); flex: 1; }
.call-header-btn {
  margin-left: auto; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--success);
}
.back-btn {
  display: none; background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px 4px 0; color: var(--text);
}
.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }

.msg-row { display: flex; align-items: flex-end; gap: 4px; animation: msgIn 0.22s ease-out; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.date-divider { display: flex; justify-content: center; margin: 10px 0; }
.date-divider span {
  background: rgba(0,0,0,0.08); color: var(--text-muted); font-size: 12px;
  padding: 4px 12px; border-radius: 12px;
}
body.dark-theme .date-divider span { background: rgba(255,255,255,0.1); }

/* ---- ЗАКРЕПЛЁННОЕ СООБЩЕНИЕ ---- */
.pinned-banner {
  display: flex; align-items: center; gap: 8px; padding: 8px 20px;
  border-bottom: 1px solid var(--border); background: rgba(42,171,238,0.08); cursor: pointer;
}
.pinned-banner-text { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-banner button { background: none; border: none; font-size: 14px; cursor: pointer; color: var(--text-muted); }

/* ---- УПОМИНАНИЯ ---- */
.mention { color: var(--accent-dark); font-weight: 600; }
.mention-suggestions {
  position: absolute; bottom: 100%; left: 14px; right: 14px; margin-bottom: 6px;
  background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25); max-height: 180px; overflow-y: auto; z-index: 20;
}
.mention-suggestions .user-result-item { padding: 10px 14px; }
.msg-row.out { justify-content: flex-end; }
.bubble {
  max-width: 60%; padding: 6px 8px; border-radius: 12px; font-size: 14px;
  background: var(--bubble-in); box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-row.out .bubble { background: var(--bubble-out); }
.bubble .sender { font-size: 12px; font-weight: 600; color: var(--accent-dark); display: block; margin: 2px 4px 0; }
.bubble img { max-width: 100%; border-radius: 8px; display: block; }

.bubble-text-wrap { padding: 2px 4px; word-wrap: break-word; }
/* Время внутри пузыря, справа от текста — если помещается на строке, "подтягивается"
   к последней строке (классический приём с float), иначе уходит на свою строку. */
.time-inline {
  float: right; margin: 2px 0 0 8px; font-size: 11px; color: var(--text-muted);
  white-space: nowrap; user-select: none;
}
.msg-row.out .time-inline { color: rgba(255,255,255,0.7); }
body.dark-theme .time-inline { color: var(--text-muted); }

.time-block { text-align: right; font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 4px; }

.media-wrap { position: relative; margin: 0 -4px; }
.media-time-overlay {
  position: absolute; bottom: 6px; right: 8px; background: rgba(0,0,0,0.55); color: white;
  font-size: 11px; padding: 2px 6px; border-radius: 8px; white-space: nowrap;
}

.msg-status { letter-spacing: -1px; }
.msg-status.read { color: var(--accent); }
.msg-row.out .time-inline .msg-status.read,
.media-time-overlay .msg-status.read { color: #7cd9ff; }

.message-form {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: rgba(255,255,255,0.72); backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  position: relative; z-index: 15;
}

.input-pill {
  flex: 1; display: flex; align-items: center; gap: 2px;
  background: #eeeef0; border-radius: 24px; padding: 4px 6px 4px 10px; min-width: 0;
}
body.dark-theme .input-pill { background: #232327; }

.input-pill input {
  flex: 1; min-width: 0; border: none; background: transparent; outline: none;
  font-size: 15px; color: var(--text); padding: 8px 4px;
}
.input-pill input::placeholder { color: var(--text-muted); }

.pill-icon-btn {
  background: none; border: none; font-size: 19px; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; padding: 4px; flex-shrink: 0;
}

.emoji-wrapper, .attach-menu-wrapper { position: relative; flex-shrink: 0; }

.send-circle-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; border: none;
  background: var(--accent); color: white; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.send-circle-btn.recording-mode { background: var(--danger); }

/* ---- ATTACH MENU ---- */
.attach-btn {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 18px; background: none; border: none; padding: 4px; width: 32px; height: 32px;
}
.attach-menu {
  position: absolute; bottom: 44px; right: 0; left: auto;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.25); display: flex; flex-direction: column;
  min-width: 170px; max-width: calc(100vw - 24px); overflow: hidden; z-index: 30;
}
.attach-menu-item {
  padding: 10px 14px; text-align: left; background: none; border: none; cursor: pointer;
  font-size: 14px; width: 100%; color: var(--text); white-space: nowrap;
}
.attach-menu-item:hover { background: #f0f7ff; }
body.dark-theme .attach-menu-item:hover { background: #232327; }

.chat-menu-wrapper { position: relative; }
.chat-menu { right: 0; left: auto; bottom: auto; top: 40px; }

.emoji-panel {
  position: absolute; bottom: 44px; left: 0;
  background: var(--sidebar-bg); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.25); z-index: 30;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; padding: 8px; width: 240px;
  max-width: calc(100vw - 24px);
}
.emoji-panel button {
  background: none; border: none; font-size: 20px; cursor: pointer; padding: 6px; border-radius: 6px;
}
.emoji-panel button:hover { background: #f0f7ff; }
body.dark-theme .emoji-panel button:hover { background: #232327; }

/* ---- LOCATION CARD ---- */
.location-card { display: flex; flex-direction: column; gap: 6px; }
.location-map { width: 220px; height: 140px; border: none; border-radius: 8px; }
.location-card a { font-size: 12px; color: var(--accent-dark); text-decoration: none; }

/* ---- CALLS ---- */
.call-card { text-align: center; }
.call-avatar { font-size: 40px; margin-bottom: 10px; }
.call-actions { display: flex; gap: 10px; margin-top: 16px; }
.call-btn { flex: 1; padding: 10px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; color: white; }
.call-btn.accept { background: var(--success); }
.call-btn.decline { background: var(--danger); }

.active-call-bar {
  position: fixed; top: 0; left: 0; right: 0; background: var(--success); color: white;
  display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; z-index: 30;
}
.active-call-controls { display: flex; gap: 12px; }
.active-call-controls button {
  background: rgba(255,255,255,0.2); border: none; border-radius: 50%; width: 34px; height: 34px;
  font-size: 16px; cursor: pointer; color: white;
}

/* ---- MODAL ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 40;
  animation: fadeIn 0.15s ease-out;
}
.modal-card {
  background: rgba(255,255,255,0.85); backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: 20px; border-radius: 16px; width: 320px;
  animation: popIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
button { transition: transform 0.1s ease, opacity 0.15s ease, background-color 0.15s ease; }
button:active { transform: scale(0.94); }
.attach-menu, .emoji-panel, .chat-menu { animation: popIn 0.15s cubic-bezier(0.34, 1.56, 0.64, 1); transform-origin: bottom left; }
.modal-card input {
  width: 100%; padding: 10px; margin: 10px 0; border-radius: 8px; border: 1px solid var(--border);
}
.user-results { max-height: 200px; overflow-y: auto; }
.user-result-item {
  padding: 8px; cursor: pointer; border-radius: 6px; font-size: 14px;
}
.user-result-item:hover { background: #f0f7ff; }

.selected-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  background: var(--accent); color: white; padding: 4px 6px 4px 10px; border-radius: 14px;
  font-size: 12px; display: flex; align-items: center; gap: 4px;
}
.chip button { background: none; border: none; color: white; cursor: pointer; font-size: 13px; padding: 0 2px; }

.group-members-list { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.member-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.member-row .remove-member-btn { margin-left: auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }
.group-title-input { text-align: center; font-weight: 600; font-size: 16px; border: none; background: none; width: 100%; margin: 4px 0; }
.leave-btn { color: var(--danger); }

/* ---- МОБИЛЬНАЯ АДАПТАЦИЯ ---- */
@media (max-width: 768px) {
  .app-screen { position: relative; overflow: hidden; }
  .sidebar { width: 100%; }
  .chat-window {
    display: flex; position: absolute; inset: 0; width: 100%; z-index: 2;
    transform: translateX(100%); transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .app-screen.chat-open .chat-window { transform: translateX(0); }
  .back-btn { display: inline-flex; align-items: center; }

  /* крупнее тап-зоны под палец */
  .attach-btn { width: 40px; height: 40px; font-size: 20px; }
  .call-header-btn { font-size: 22px; padding: 6px; }
  .chat-item { padding: 14px 16px; }

  /* шрифт 16px в полях — иначе iOS зумит страницу при фокусе */
  .message-form input[type="text"],
  .auth-card input,
  .modal-card input { font-size: 16px; }

  .modal-card { width: 88vw; max-width: 340px; }
  .location-map { width: 100%; max-width: 260px; }
  .active-call-bar { padding: 10px 14px; }
}

/* ---- АВАТАРЫ ---- */
.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0; overflow: hidden;
  background-size: cover; background-position: center;
}
.avatar-circle.large { width: 72px; height: 72px; font-size: 28px; margin: 0 auto; }
.sidebar-header #me-username { flex: 1; margin-left: 8px; }
.avatar-upload { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 16px; }
.avatar-upload-label { width: auto; padding: 8px 16px; }

.avatar-circle.xlarge { width: 96px; height: 96px; font-size: 34px; }
.avatar-camera-wrap { position: relative; }
.avatar-camera-btn {
  position: absolute; bottom: -2px; right: -2px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: white; display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; border: 2px solid var(--sidebar-bg);
}
.profile-name-input {
  border: none; background: none; text-align: center; font-size: 19px; font-weight: 700;
  color: var(--text); width: 100%; margin-top: 4px;
}
.profile-username-label { font-size: 13px; color: var(--text-muted); }

.profile-settings-card { max-height: 85vh; overflow-y: auto; }

/* ---- ПРОФИЛЬ КАК ОТДЕЛЬНАЯ СТРАНИЦА (не всплывающее окно) ---- */
.page-panel {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  overflow-y: auto; animation: none;
}
.page-panel.hidden { display: none !important; }
.page-header {
  position: sticky; top: 0; z-index: 2; padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(255,255,255,0.85); backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
body.dark-theme .page-header { background: rgba(24,24,27,0.85); }
.page-back-btn {
  background: none; border: none; font-size: 15px; font-weight: 600; color: var(--accent);
  cursor: pointer; padding: 4px 0;
}
.page-panel .modal-card {
  background: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
  box-shadow: none; border-radius: 0; width: 100%; max-width: 480px; margin: 0 auto;
  padding: 24px 20px 60px; animation: none; max-height: none;
}

.profile-info-list { display: flex; flex-direction: column; gap: 2px; margin: 14px 0; text-align: left; }
.profile-info-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--border);
}
.profile-info-row:last-child { border-bottom: none; }
.profile-info-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.profile-info-field { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.profile-info-caption { font-size: 11px; color: var(--text-muted); }
.profile-info-field input {
  border: none; background: none; font-size: 14px; color: var(--text); padding: 2px 0; width: 100%;
}
.profile-info-value { font-size: 14px; color: var(--text); }

/* ---- ПРЕВЬЮ ВЫБРАННОГО ФОТО ---- */
.attachment-preview {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  border-top: 1px solid var(--border); background: #fafafa;
}
.attachment-preview img,
.attachment-preview video { height: 56px; width: 56px; object-fit: cover; border-radius: 8px; }
.attachment-preview-file { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.attachment-preview-file-icon { font-size: 24px; }
#attachment-preview-file-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-preview button {
  background: var(--danger); color: white; border: none; border-radius: 50%;
  width: 22px; height: 22px; cursor: pointer; font-size: 12px; line-height: 1;
}

/* ---- ФАЙЛ В ЧАТЕ ---- */
.file-bubble {
  display: flex; align-items: center; gap: 10px; padding: 6px 4px; min-width: 190px; text-decoration: none; color: inherit;
}
.file-bubble-icon {
  width: 38px; height: 38px; border-radius: 8px; background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.file-bubble-info { display: flex; flex-direction: column; min-width: 0; }
.file-bubble-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.file-bubble-size { font-size: 11px; color: var(--text-muted); }

/* ---- ОТВЕТ НА СООБЩЕНИЕ ---- */
.reply-preview {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  border-top: 1px solid var(--border); background: rgba(255,255,255,0.6);
  border-left: 3px solid var(--accent);
}
body.dark-theme .reply-preview { background: rgba(255,255,255,0.05); }
.reply-preview-info { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.reply-preview-info span:first-child { font-size: 12px; font-weight: 600; color: var(--accent-dark); }
.reply-preview-info span:last-child { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview button {
  background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted);
}

.reply-quote {
  display: flex; flex-direction: column; border-left: 3px solid var(--accent);
  padding: 2px 8px; margin-bottom: 4px; background: rgba(0,0,0,0.04); border-radius: 4px;
}
body.dark-theme .reply-quote { background: rgba(255,255,255,0.06); }
.reply-quote-sender { font-size: 11px; font-weight: 600; color: var(--accent-dark); }
.reply-quote-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

/* ---- ЗНАЧОК ВЕРИФИКАЦИИ ---- */
.verified-badge { display: inline-flex; vertical-align: middle; margin-left: 3px; cursor: pointer; }
.verified-badge svg { display: block; }

.premium-badge {
  display: inline-flex; vertical-align: middle; margin-left: 2px; cursor: pointer;
  font-size: 14px; line-height: 1;
  animation: premiumPulse 2.2s ease-in-out infinite;
  filter: drop-shadow(0 0 2px rgba(168,85,247,0.6));
}
@keyframes premiumPulse {
  0%, 100% { transform: scale(1) rotate(0deg); filter: drop-shadow(0 0 2px rgba(168,85,247,0.5)); }
  50% { transform: scale(1.18) rotate(8deg); filter: drop-shadow(0 0 5px rgba(168,85,247,0.9)); }
}

.bubble { position: relative; transition: transform 0.2s ease; cursor: pointer; }
.msg-row.swipe-armed .bubble { box-shadow: 0 0 0 2px var(--accent) inset; }

/* ---- МНОЖЕСТВЕННЫЙ ВЫБОР СООБЩЕНИЙ ---- */
.select-checkbox {
  display: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--text-muted); flex-shrink: 0; align-items: center; justify-content: center;
  font-size: 12px; color: white; margin-top: auto; margin-bottom: auto;
}
.select-checkbox.checked { background: var(--accent); border-color: var(--accent); }
#messages.selection-mode .select-checkbox { display: flex; }
#messages.selection-mode .msg-row { justify-content: flex-start !important; }
#messages.selection-mode .bubble { max-width: calc(100% - 60px); }

.selection-bar {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}
.selection-bar #selection-count { flex: 1; font-weight: 600; }
.selection-bar button { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text); }

/* ---- РЕАКЦИИ ---- */
.reactions-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-pill {
  background: rgba(0,0,0,0.06); border: 1px solid transparent; border-radius: 12px;
  padding: 1px 7px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 3px;
  animation: popIn 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
body.dark-theme .reaction-pill { background: rgba(255,255,255,0.1); }
.reaction-pill.mine { border-color: var(--accent); background: rgba(42,171,238,0.15); }

.message-edited-tag { font-size: 9px; color: var(--text-muted); }
.message-deleted { font-style: italic; color: var(--text-muted); }

/* ---- ТАП-МЕНЮ СООБЩЕНИЯ ---- */
.message-menu-card { text-align: left; }
.message-menu-reactions {
  display: flex; justify-content: space-between; gap: 4px; padding: 6px 0 14px;
  border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.message-menu-reactions button { background: none; border: none; font-size: 24px; cursor: pointer; padding: 2px; }
.message-menu-actions { display: flex; flex-direction: column; }
.message-menu-actions .attach-menu-item { padding: 12px 4px; font-size: 15px; }
.message-menu-status { font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; }

/* ---- ФОН ЧАТА ---- */
.wallpaper-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.wallpaper-swatch {
  height: 52px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; padding: 0;
  background-size: cover; background-position: center;
}
.wallpaper-swatch.selected { border-color: var(--accent); }

/* ---- ПОИСК ПО ЧАТУ ---- */
.chat-search-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.85); backdrop-filter: blur(16px);
}
body.dark-theme .chat-search-bar { background: rgba(24,24,27,0.85); }
.chat-search-bar input { flex: 1; border: none; background: transparent; outline: none; font-size: 14px; color: var(--text); }
.chat-search-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.chat-search-bar button { background: none; border: none; font-size: 15px; cursor: pointer; color: var(--text-muted); padding: 4px; }
.msg-row.search-highlight .bubble { outline: 2px solid var(--accent); }

/* ---- ВИДЕО/ГОЛОСОВЫЕ В ЧАТЕ ---- */
.video-bubble {
  max-width: 220px; max-height: 220px; border-radius: 16px; display: block;
}
.voice-bubble { display: flex; align-items: center; gap: 8px; padding: 4px 2px; min-width: 180px; }
.voice-play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--accent); color: white;
  font-size: 13px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.voice-play-btn::before { content: '▶'; transform: translateX(1.5px); }
.voice-play-btn.playing::before { content: '❚❚'; transform: none; }
.voice-progress {
  flex: 1; height: 4px; background: rgba(0,0,0,0.15); border-radius: 2px; cursor: pointer; position: relative;
}
body.dark-theme .voice-progress { background: rgba(255,255,255,0.2); }
.voice-progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; }
.voice-duration { font-size: 11px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; min-width: 32px; text-align: right; }
.missed-call { color: var(--danger); font-weight: 600; }

/* ---- ТОСТ-УВЕДОМЛЕНИЕ ---- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(24,24,27,0.9); color: white; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  max-width: 85vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- ЗАПИСЬ ГОЛОСОВОГО ---- */
.recording-bar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--danger); color: white;
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; z-index: 45;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.recording-dot {
  width: 10px; height: 10px; border-radius: 50%; background: white; animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
.recording-bar span:nth-child(3) { flex: 1; }
.recording-bar .secondary-btn, .recording-bar .primary-btn { width: auto; padding: 8px 14px; margin: 0; }

/* ---- ПРОФИЛЬ ---- */
.profile-card { text-align: center; }
.profile-username { color: var(--text-muted); font-size: 14px; margin-top: -8px; margin-bottom: 16px; }

/* ---- ЛАЙТБОКС ФОТО ---- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; z-index: 60; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
.bubble img { cursor: zoom-in; }

/* ---- НАСТРОЙКИ ТЕМЫ ---- */
.settings-label { font-size: 13px; color: var(--text-muted); margin: 12px 0 6px; }
.theme-swatches { display: flex; gap: 10px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0;
}
.swatch.selected { border-color: var(--text); }
.custom-swatch {
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red) !important;
  display: flex; align-items: center; justify-content: center; font-size: 14px; position: relative;
  cursor: pointer;
}
.custom-swatch input[type="color"] { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.saved-themes-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.saved-theme-chip {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 14px;
  border: 1px solid var(--border); background: none; cursor: pointer; font-size: 12px; color: var(--text);
}
.saved-theme-chip .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.saved-theme-chip .remove-theme { color: var(--danger); font-size: 12px; margin-left: 2px; }
.dark-mode-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 14px; }

/* ---- ТЁМНАЯ ТЕМА ---- */
body.dark-theme {
  --bg: #0f0f10;
  --sidebar-bg: #18181b;
  --border: #2a2a2e;
  --bubble-out: #1f3a2b;
  --bubble-in: #1f1f23;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
}
body.dark-theme .auth-card,
body.dark-theme .modal-card { background: rgba(24,24,27,0.8); color: var(--text); }
body.dark-theme .chat-header,
body.dark-theme .sidebar-header,
body.dark-theme .message-form { background: rgba(24,24,27,0.7); }
body.dark-theme .tab { background: #18181b; color: var(--text); }
body.dark-theme .attachment-preview { background: #18181b; }
body.dark-theme .secondary-btn {
  background: #2a2a2e; color: var(--text);
}
body.dark-theme .avatar-upload-label { color: var(--text); }
body.dark-theme .chat-item:hover, body.dark-theme .chat-item.active { background: #1c2733; }
body.dark-theme .user-result-item:hover { background: #1c2733; }

#username-readonly { background: #f2f2f3; color: var(--text-muted); }
body.dark-theme #username-readonly { background: #232327; }

/* Поля ввода наследовали белый фон браузера по умолчанию — в тёмной теме
   текст на нём становился нечитаемым. Задаём явно. */
input[type="text"], input[type="password"] { color: var(--text); }
body.dark-theme input[type="text"],
body.dark-theme input[type="password"] {
  background: #232327; border-color: var(--border);
}
body.dark-theme input::placeholder { color: var(--text-muted); }
