
:root {
  color-scheme: dark;
  --bg: #0e1621;
  --sidebar: #17212b;
  --sidebar-2: #111b24;
  --chat: #0e1621;
  --panel: #182533;
  --panel-soft: #202b36;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef3f8;
  --muted: #8ea2b5;
  --accent: #5eb5f7;
  --accent-2: #2b5278;
  --green: #54d698;
  --red: #ff6b7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

input, textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

a { color: #9bd4ff; text-decoration: none; font-weight: 800; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.auth-panel {
  width: min(460px, calc(100vw - 28px));
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  box-shadow: var(--shadow);
}

.brand, .profile, .chat-head, .head-actions, .inbox-head, .archive-head, .favorites-head {
  display: flex;
  align-items: center;
}

.brand { gap: 14px; }

.mark, .avatar, .mini-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  font-weight: 950;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.mark, .avatar {
  width: 46px;
  height: 46px;
}

.mini-avatar {
  width: 34px;
  height: 34px;
  font-size: 0.9rem;
}

.avatar.owner-crown,
.mini-avatar.owner-crown {
  overflow: hidden;
  color: #fff8dc;
}

.avatar.owner-crown .crown-svg {
  width: 92%;
  height: 92%;
}

.mini-avatar.owner-crown .crown-svg {
  width: 94%;
  height: 94%;
}

.avatar.uploaded-avatar,
.mini-avatar.uploaded-avatar {
  overflow: hidden;
  background: transparent;
}

.avatar img,
.mini-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.eyebrow, .muted, label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

h1, h2 { margin: 0; letter-spacing: 0; line-height: 1.08; }
h1 { font-size: 2rem; }
h2 { margin-top: 3px; font-size: 1.45rem; }

.lead {
  margin: 0;
  color: #c9d6e2;
  line-height: 1.55;
}

.auth-form, .search {
  display: grid;
  gap: 10px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.input-row {
  height: 44px;
  display: flex;
  align-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.input-row span {
  width: 40px;
  text-align: center;
  color: var(--accent);
  font-weight: 900;
}

input { height: 100%; }

.login-button, .auth-form button, .search button, .composer button {
  min-height: 44px;
  color: #fff;
  background: #2aabee;
}

.search .open-peer-btn {
  padding: 0;
  border-radius: 8px;
  font-size: 1rem;
}

.hint, .microcopy {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.legal-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.messenger {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  background: var(--chat);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.profile {
  gap: 12px;
  padding: 6px 4px 12px;
  border-bottom: 1px solid var(--line);
}

.profile > div:not(.avatar) {
  min-width: 0;
  flex: 1;
}

.profile-key {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}

.profile strong { display: block; margin-top: 2px; }

.inbox-card, .archive-card, .groups-card, .channels-card, .favorites-card, .safety-card {
  display: grid;
  gap: 8px;
}

.card-title {
  margin: 0;
  color: #dce8f4;
  font-weight: 900;
}

.section-badge {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  color: #fff;
  background: #2aabee;
  font-size: 0.74rem;
  vertical-align: middle;
}

.inbox-head, .archive-head, .groups-head, .channels-head, .favorites-head {
  justify-content: space-between;
  gap: 10px;
}

.notify-toggle, .ghost, .favorite-remove {
  min-height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.archive-toggle {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--sidebar-2);
}

.archive-title {
  font-weight: 950;
}

.archive-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.archive-chevron {
  color: var(--muted);
  font-weight: 950;
}

.archive-card.open .archive-toggle,
.archive-card.has-items .archive-toggle {
  background: rgba(42, 171, 238, 0.1);
}

.inbox-total {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--sidebar-2);
  font-weight: 800;
}

.inbox-total.has-unread {
  color: #fff;
  background: #2aabee;
}

.inbox-list, .archive-list, .favorites-list, .user-search-results {
  display: grid;
  gap: 4px;
}

.inbox-item, .group-item, .channel-item, .favorite-open, .user-search-item {
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.inbox-item:hover, .group-item:hover, .channel-item:hover, .favorite-open:hover, .user-search-item:hover {
  background: var(--panel);
}

.inbox-item small, .group-item small, .channel-item small, .favorite-open small, .favorite-open em, .user-search-item small {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-item b, .group-item b, .channel-item b, .archive-meta #archiveCount, .favorites-head span {
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: #2aabee;
  font-size: 0.78rem;
}

.inbox-item.unread, .group-item.unread, .channel-item.unread {
  background: rgba(42, 171, 238, 0.12);
}

.group-avatar-mini {
  width: 34px;
  height: 34px;
  font-size: 0.88rem;
  background: linear-gradient(135deg, #2aabee, #55efc4);
}

.inbox-item.archived {
  color: #c9d6e2;
  background: rgba(255, 255, 255, 0.035);
}

.inbox-item.archived:hover {
  background: rgba(42, 171, 238, 0.12);
}

.favorite-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  gap: 4px;
}

.favorite-open {
  grid-template-columns: 34px minmax(0, 1fr);
}

.favorite-remove {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
}

.favorite-remove:hover {
  color: var(--red);
  background: rgba(255, 107, 122, 0.12);
}

.favorites-drop {
  min-height: 38px;
  display: grid;
  place-items: center;
  padding: 8px 10px;
  border: 1px dashed rgba(42, 171, 238, 0.42);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(42, 171, 238, 0.07);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.favorites-drop.drag-over {
  color: #fff;
  border-color: #2aabee;
  background: rgba(42, 171, 238, 0.18);
}
.favorites-empty, .inbox-empty, .user-search-empty { color: var(--muted); font-size: 0.88rem; }

.user-search-results {
  max-height: 230px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar-2);
}

.user-search-item {
  grid-template-columns: 34px minmax(0, 1fr);
  min-height: 50px;
  background: transparent;
}

.user-search-empty {
  padding: 10px;
}

.safety-card {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--sidebar-2);
  line-height: 1.45;
}

.safety-card p { margin: 0; }

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background:
    linear-gradient(rgba(14, 22, 33, 0.94), rgba(14, 22, 33, 0.94)),
    radial-gradient(circle at 50% 40%, rgba(94, 181, 247, 0.13), transparent 34rem);
}

.chat-head {
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--line);
}

.chat-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.peer-avatar {
  width: 42px;
  height: 42px;
}

.head-actions { gap: 8px; }

.icon-action {
  min-width: 36px;
  padding: 0;
  font-size: 1rem;
}

.icon-action.active {
  color: #fff;
  border-color: rgba(42, 171, 238, 0.7);
  background: rgba(42, 171, 238, 0.22);
}

.status {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-size: 0.82rem;
  font-weight: 800;
}

.chat-tools {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 10px 18px 12px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--line);
}

.message-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
}

.chat-tools input {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel);
}

.search-scope {
  display: flex;
  gap: 6px;
}

.search-scope button {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 850;
}

.search-scope button.active {
  color: #fff;
  background: #2aabee;
  border-color: #2aabee;
}

.message-search-results {
  position: absolute;
  z-index: 20;
  left: 18px;
  right: 18px;
  top: calc(100% - 4px);
  display: grid;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

.message-search-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.message-search-item:hover {
  background: var(--panel);
}

.message-search-item small {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-search-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  scroll-behavior: smooth;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.welcome-empty {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px;
}

.welcome-empty h3 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

.welcome-empty p {
  max-width: 430px;
  margin: 0;
  line-height: 1.45;
}

.welcome-mark {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #2aabee, #55efc4);
  font-size: 2rem;
  font-weight: 950;
  box-shadow: 0 12px 38px rgba(42, 171, 238, .24);
}

.welcome-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

.welcome-actions button {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  color: var(--text);
  background: var(--panel);
  font-weight: 850;
  cursor: pointer;
}

.welcome-actions button:first-child {
  color: #fff;
  background: #2aabee;
  border-color: transparent;
}

.welcome-actions button:hover {
  transform: translateY(-1px);
  border-color: rgba(42, 171, 238, .45);
}

.messenger.no-active-chat .composer-wrap {
  display: none;
}

.messenger.no-active-chat .chat-head .head-actions button,
.messenger.no-active-chat .chat-head .head-actions .status {
  opacity: .42;
}

.messenger.no-active-chat .chat-head #messageSearchToggle {
  opacity: .25;
}

.pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2aabee;
  opacity: 0.55;
}

.message {
  position: relative;
  width: fit-content;
  max-width: min(620px, 78%);
  margin: 6px 0;
  padding: 9px 11px 7px;
  border-radius: 8px;
  line-height: 1.42;
  overflow-wrap: anywhere;
  animation: rise 160ms ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.in {
  color: var(--text);
  background: #182533;
  border-bottom-left-radius: 3px;
}

.message.out {
  margin-left: auto;
  color: #fff;
  background: var(--accent-2);
  border-bottom-right-radius: 3px;
}

.message-media {
  display: block;
  max-width: min(420px, 70vw);
  max-height: 360px;
  margin-bottom: 6px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.18);
  cursor: zoom-in;
}

.message-video {
  width: min(520px, 72vw);
  max-height: 420px;
  cursor: default;
}

.message-media:focus {
  outline: 2px solid rgba(94, 181, 247, 0.82);
  outline-offset: 3px;
}

.message-sender {
  display: block;
  margin-bottom: 3px;
  color: #7dd3fc;
  font-size: 0.72rem;
  font-weight: 900;
}

.message-text { display: block; padding-right: 2px; }

.message-edited {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 0.68rem;
  font-weight: 700;
}

.message.search-hidden { display: none; }

.message.favorited {
  box-shadow: 0 0 0 1px rgba(94, 181, 247, 0.44);
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 5px;
  opacity: 0.92;
}

.message.dragging {
  opacity: 0.55;
}

.message-actions button {
  width: 28px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.11);
  font-size: 0.92rem;
  line-height: 1;
}

.message-actions button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.message-fav.active {
  color: #ffd166;
}

.message-more {
  font-weight: 950;
}

.message-drag { display: none; }

.composer-wrap {
  padding: 10px 18px 14px;
  background: var(--sidebar);
  border-top: 1px solid var(--line);
}

.ai-note {
  min-height: 20px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.ai-note.bad { color: var(--red); }
.ai-note.good { color: var(--green); }

.composer {
  display: grid;
  grid-template-columns: 44px 44px 44px minmax(0, 1fr) 136px;
  gap: 8px;
}

.emoji-toggle, .media-original-toggle {
  min-height: 44px;
  padding: 0;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-size: 1.25rem;
}

.media-original-toggle {
  font-size: 0.82rem;
  font-weight: 950;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.emoji-toggle.active {
  color: #fff;
  background: #2aabee;
}

.media-original-toggle.active {
  color: #fff;
  border-color: rgba(244, 114, 182, 0.92);
  background: linear-gradient(135deg, #ec4899, #2aabee);
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.18), 0 8px 22px rgba(42, 171, 238, 0.22);
  transform: translateY(-1px);
}

.media-preview {
  position: relative;
  width: fit-content;
  max-width: 240px;
  margin-bottom: 8px;
}

.media-preview img,
.media-preview video {
  display: block;
  max-width: 240px;
  max-height: 160px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.24);
}

.media-preview button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  color: #fff;
  background: rgba(7, 15, 24, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.emoji-panel {
  display: grid;
  gap: 10px;
  max-height: 230px;
  margin-bottom: 8px;
  padding: 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar-2);
}

.emoji-group p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(32px, 1fr));
  gap: 5px;
}

.emoji-item {
  min-height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel);
  font-size: 1.12rem;
}

.emoji-item:hover {
  border-color: rgba(42, 171, 238, 0.55);
  background: rgba(42, 171, 238, 0.14);
}

textarea {
  min-height: 44px;
  max-height: 132px;
  resize: none;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--panel);
  line-height: 1.35;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202b36;
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 850;
}

.toast.good { border-color: rgba(84, 214, 152, 0.55); }
.toast.bad { border-color: rgba(255, 107, 122, 0.6); }

.viewer-open {
  overflow: hidden;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 54px 18px 22px;
  background: rgba(4, 10, 18, 0.88);
  backdrop-filter: blur(8px);
}

.image-viewer img {
  display: block;
  max-width: min(1180px, 96vw);
  max-height: calc(100dvh - 92px);
  border-radius: 8px;
  object-fit: contain;
  background: #000;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.image-viewer-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  color: #fff;
  background: rgba(24, 37, 51, 0.9);
  font-size: 1.55rem;
  line-height: 1;
}

.image-viewer-close:hover {
  border-color: rgba(94, 181, 247, 0.56);
  background: rgba(42, 171, 238, 0.24);
}

.legal-page {
  width: min(920px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0;
}

.legal-hero, .legal-section {
  padding: 24px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
}

.legal-hero p, .legal-section p, .legal-section li {
  color: #c9d6e2;
  line-height: 1.65;
}

@media (max-width: 860px) {
  .messenger {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .safety-card { display: none; }
  .chat { min-height: 58vh; }
  .message { max-width: 88%; }
  .composer { grid-template-columns: 44px 44px 44px 1fr; }
  .composer button[type="submit"] { grid-column: 1 / -1; }
  .emoji-grid { grid-template-columns: repeat(8, minmax(32px, 1fr)); }
}


.message.deleted {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-style: italic;
  box-shadow: none;
}

.message.deleted .message-text {
  opacity: 0.86;
}


.message-menu {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202b36;
  box-shadow: var(--shadow);
}

.message-menu button,
.message-menu-note {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 7px;
  color: var(--text);
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.message-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.message-menu button.danger {
  color: var(--red);
}

.message-menu-note {
  color: var(--muted);
  cursor: default;
}


.mobile-back {
  display: none;
}

@media (max-width: 860px) {
  body {
    overflow: hidden;
    background: var(--sidebar);
  }

  .shell {
    min-height: 100dvh;
    display: block;
  }

  .messenger {
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    overflow: hidden;
  }

  .sidebar {
    height: 100dvh;
    max-height: none;
    gap: 8px;
    padding: 10px;
    overflow-y: auto;
    border: 0;
  }

  .messenger.mobile-chat-open .sidebar {
    display: none;
  }

  .messenger:not(.mobile-chat-open) .chat {
    display: none;
  }

  .profile {
    min-height: 58px;
    padding: 6px 2px 10px;
    gap: 10px;
  }

  .profile .avatar {
    width: 42px;
    height: 42px;
  }

  .profile-key {
    min-width: 42px;
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.9rem;
  }

  .search {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 6px 0 8px;
    background: var(--sidebar);
  }

  .search-line {
    grid-template-columns: minmax(0, 1fr) 42px;
  }

  .input-row {
    height: 42px;
    border-radius: 999px;
    background: var(--sidebar-2);
  }

  .search .open-peer-btn {
    border-radius: 50%;
  }

  .inbox-card,
  .archive-card,
  .favorites-card {
    gap: 6px;
  }

  .inbox-head {
    margin-top: 2px;
  }

  .notify-toggle {
    min-height: 32px;
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .inbox-total,
  .favorites-drop {
    min-height: 34px;
    font-size: 0.86rem;
  }

  .inbox-item,
  .group-item,
  .channel-item,
  .favorite-open,
  .user-search-item {
    min-height: 62px;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 9px 8px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.055);
  }

  .inbox-item:hover,
  .group-item:hover,
  .channel-item:hover,
  .favorite-open:hover,
  .user-search-item:hover {
    background: rgba(255,255,255,0.045);
  }

  .mini-avatar {
    width: 42px;
    height: 42px;
  }

  .archive-toggle {
    min-height: 40px;
    border-radius: 8px;
  }

  .favorites-card {
    margin-top: 4px;
  }

  .safety-card {
    display: none;
  }

  .chat {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    background: var(--chat);
  }

  .chat-head {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 58px;
    gap: 8px;
    padding: 8px 10px;
  }

  .mobile-back {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
    border-radius: 50%;
    color: var(--accent);
    background: transparent;
    font-size: 2rem;
    line-height: 1;
  }

  .chat-identity {
    flex: 1;
    gap: 9px;
    min-width: 0;
  }

  .peer-avatar {
    width: 38px;
    height: 38px;
  }

  h2 {
    max-width: 46vw;
    overflow: hidden;
    font-size: 1.15rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-head .muted {
    display: none;
  }

  .head-actions {
    flex: 0 0 auto;
    gap: 5px;
  }

  .status {
    display: none;
  }

  .head-actions .ghost {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    overflow: hidden;
    border-radius: 50%;
    font-size: 0;
  }

  #messageSearchToggle::before {
    content: "\2315";
    font-size: 1rem;
  }

  #groupInviteBtn::before {
    content: "+";
    font-size: 1.15rem;
  }

  #groupManageBtn::before {
    content: "\22EF";
    font-size: 1.1rem;
  }

  #channelInviteBtn::before {
    content: "+";
    font-size: 1.15rem;
  }

  #channelManageBtn::before {
    content: "\22EF";
    font-size: 1.1rem;
  }

  #archiveBtn::before {
    content: "\25A3";
    font-size: 0.95rem;
  }

  #blockBtn::before {
    content: "\26D4";
    font-size: 0.95rem;
  }

  #blockBtn:disabled::before {
    content: "\1F512";
  }

  .chat-tools {
    padding: 8px 10px 10px;
  }

  .message-search-results {
    left: 10px;
    right: 10px;
  }

  .messages {
    padding: 12px 10px 10px;
  }

  .empty {
    min-height: 48vh;
    padding: 24px;
  }

  .message {
    max-width: 86%;
    margin: 5px 0;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 0.98rem;
  }

  .message.in {
    border-bottom-left-radius: 4px;
  }

  .message.out {
    border-bottom-right-radius: 4px;
  }

  .message-actions {
    display: none;
  }

  .composer-wrap {
    position: sticky;
    bottom: 0;
    z-index: 12;
    padding: 7px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .ai-note {
    min-height: 0;
    margin: 0 0 5px;
    padding: 0 4px;
    font-size: 0.74rem;
    line-height: 1.25;
  }

  .composer {
    grid-template-columns: 40px 40px 40px minmax(0, 1fr) 46px;
    gap: 6px;
    align-items: end;
  }

  .emoji-toggle,
  .media-original-toggle,
  .composer button[type="submit"] {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    font-size: 1.05rem;
  }

  .composer button[type="submit"] {
    grid-column: auto;
    width: 46px;
    min-width: 46px;
    font-size: 0;
  }

  .composer button[type="submit"]::before {
    content: "\27A4";
    font-size: 1.05rem;
  }

  textarea {
    min-height: 40px;
    max-height: 118px;
    padding: 10px 12px;
    border-radius: 20px;
  }

  .emoji-panel {
    max-height: 38vh;
    margin-bottom: 6px;
    padding: 8px;
    border-radius: 12px;
  }

  .emoji-grid {
    grid-template-columns: repeat(7, minmax(32px, 1fr));
  }

  .toast {
    left: 10px;
    right: 10px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    max-width: none;
  }

  .message-menu {
    left: 8px !important;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    top: auto !important;
    width: auto;
    border-radius: 12px;
  }
}


@media (max-width: 860px) {
  .chat {
    position: relative;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .chat-tools {
    position: absolute;
    z-index: 30;
    top: 58px;
    left: 0;
    right: 0;
    box-shadow: 0 16px 34px rgba(0,0,0,.24);
  }

  .messages {
    grid-row: 2;
  }

  .composer-wrap {
    grid-row: 3;
    align-self: end;
    height: auto;
  }
}


@media (max-width: 860px) {
  .messenger.mobile-chat-open .mobile-back {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    z-index: 80;
    display: grid;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(94, 181, 247, .28);
    background: rgba(23, 33, 43, .96);
    box-shadow: 0 8px 24px rgba(0,0,0,.24);
  }

  .messenger.mobile-chat-open .chat-head {
    padding-left: 58px;
  }

  .messenger.mobile-chat-open .chat-identity {
    min-width: 0;
  }
}


@media (max-width: 860px) {
  .messenger.mobile-chat-open .chat {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    grid-template-rows: minmax(0, 1fr) auto;
    padding-top: calc(58px + env(safe-area-inset-top));
  }

  .messenger.mobile-chat-open .chat-head {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 75;
    height: calc(58px + env(safe-area-inset-top));
    min-height: calc(58px + env(safe-area-inset-top));
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: 58px;
    background: rgba(23, 33, 43, .98);
  }

  .messenger.mobile-chat-open .mobile-back {
    top: calc(8px + env(safe-area-inset-top));
    left: 8px;
    z-index: 90;
  }

  .messenger.mobile-chat-open .chat-tools {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top));
    left: 0;
    right: 0;
  }

  .messenger.mobile-chat-open .messages {
    grid-row: 1;
    height: auto;
    padding-top: 12px;
    padding-bottom: 10px;
  }

  .messenger.mobile-chat-open .composer-wrap {
    grid-row: 2;
    position: relative;
    bottom: auto;
    min-height: 72px;
    max-height: 48dvh;
  }
}


.avatar-button,
.settings-avatar {
  border: 0;
  padding: 0;
}

.avatar-button:hover {
  filter: brightness(1.08);
}

.settings-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--panel);
  font-size: 1.05rem;
}

.settings-button:hover {
  border-color: rgba(94, 181, 247, .55);
  background: rgba(94, 181, 247, .13);
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 18, .62);
  backdrop-filter: blur(10px);
}

.manage-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 10, 18, .62);
  backdrop-filter: blur(10px);
}

.manage-sheet {
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  background: var(--sidebar);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.manage-invite {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.manage-invite button,
.manage-member button,
.manage-leave {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 800;
  cursor: pointer;
}

.manage-invite button {
  background: #2aabee;
  color: #fff;
  border-color: transparent;
}

.manage-members {
  display: grid;
  gap: 4px;
  padding: 10px;
}

.manage-member {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
}

.manage-member:hover {
  background: rgba(255, 255, 255, .045);
}

.manage-member span {
  min-width: 0;
}

.manage-member small {
  display: block;
  color: var(--muted);
}

.manage-member > div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.manage-member button {
  padding: 8px 10px;
}

.manage-member button.danger,
.manage-leave.danger {
  color: var(--red);
  border-color: rgba(255, 107, 122, .35);
}

.manage-leave {
  margin: 8px 18px 18px;
  width: calc(100% - 36px);
}

.switch-field {
  cursor: pointer;
}

.switch-field > span {
  display: grid;
  gap: 4px;
}

.switch-field input {
  appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-field input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.switch-field input:checked {
  background: #2aabee;
  border-color: #2aabee;
}

.switch-field input:checked::after {
  transform: translateX(20px);
  background: #fff;
}

.compact-mode {
  --compact-avatar: 34px;
}

.compact-mode .sidebar {
  gap: 6px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.compact-mode .profile {
  padding-bottom: 10px;
}

.compact-mode .profile-avatar,
.compact-mode .mini-avatar,
.compact-mode .peer-avatar {
  width: var(--compact-avatar);
  height: var(--compact-avatar);
}

.compact-mode .inbox-card,
.compact-mode .archive-card,
.compact-mode .groups-card,
.compact-mode .channels-card,
.compact-mode .favorites-card,
.compact-mode .safety-card {
  padding: 6px;
}

.compact-mode .inbox-item,
.compact-mode .group-item,
.compact-mode .channel-item,
.compact-mode .favorite-open,
.compact-mode .user-search-item {
  min-height: 44px;
  padding: 6px 8px;
  gap: 8px;
}

.compact-mode .inbox-item strong,
.compact-mode .group-item strong,
.compact-mode .channel-item strong {
  font-size: .92rem;
}

.compact-mode .inbox-item small,
.compact-mode .group-item small,
.compact-mode .channel-item small {
  font-size: .72rem;
}

.compact-mode .message {
  max-width: min(520px, 72%);
  padding: 6px 9px;
  font-size: .9rem;
  line-height: 1.25;
}

.compact-mode .message-actions {
  gap: 4px;
}

.compact-mode .message-actions button {
  width: 26px;
  height: 26px;
}

@media (max-width: 860px) {
  .compact-mode .sidebar {
    padding: 8px 12px;
  }

  .compact-mode .inbox-item,
  .compact-mode .group-item,
  .compact-mode .channel-item {
    min-height: 42px;
  }

  .compact-mode .message {
    max-width: 82%;
    padding: 6px 9px;
  }
}

@media (max-width: 860px) {
  .manage-modal {
    padding: 0;
    align-items: stretch;
  }

  .manage-sheet {
    width: 100%;
    max-height: none;
    min-height: 100%;
    border-radius: 0;
  }

  .manage-invite {
    grid-template-columns: 1fr;
  }

  .manage-member {
    grid-template-columns: auto 1fr;
  }

  .manage-member > div {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .manage-member button {
    flex: 1;
  }

  .welcome-empty {
    padding: 18px 14px;
  }

  .welcome-actions {
    display: grid;
    width: 100%;
  }

  .welcome-actions button {
    width: 100%;
  }
}

.settings-sheet {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--sidebar);
  box-shadow: var(--shadow);
}

.settings-head,
.settings-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-profile {
  justify-content: flex-start;
  padding: 12px;
  border-radius: 12px;
  background: var(--sidebar-2);
}

.settings-avatar {
  width: 58px;
  height: 58px;
}

.settings-profile p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.35;
}

.settings-list {
  display: grid;
  gap: 6px;
}

.settings-list button,
.settings-list a,
.settings-field {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.settings-list button:hover,
.settings-list a:hover,
.settings-field:hover {
  background: var(--panel);
  text-decoration: none;
}

.settings-list span {
  font-weight: 900;
}

.settings-list small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.settings-list .danger span {
  color: var(--red);
}

.settings-field {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 0;
}

.settings-field label {
  display: grid;
  gap: 3px;
}

.settings-field select {
  min-height: 38px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: var(--panel);
  font: inherit;
  font-weight: 850;
}

.settings-field select:focus {
  border-color: rgba(94, 181, 247, .68);
  box-shadow: 0 0 0 3px rgba(94, 181, 247, .14);
}

@media (max-width: 860px) {
  .profile {
    position: sticky;
    top: 0;
    z-index: 8;
    background: var(--sidebar);
  }

  .settings-button {
    width: 40px;
    height: 40px;
  }

  .settings-modal {
    align-items: end;
    padding: 0;
  }

  .settings-sheet {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top));
    overflow-y: auto;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 18px 18px 0 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  }
}


/* Stable mobile layout override: list and chat are two full-screen panes. */
@media (max-width: 860px) {
  html,
  body {
    width: 100%;
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    position: fixed;
    inset: 0;
  }

  .shell,
  .messenger {
    width: 100%;
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
  }

  .messenger {
    position: fixed;
    inset: 0;
    display: block;
    background: var(--chat);
  }

  .sidebar,
  .chat {
    position: absolute;
    inset: 0;
    width: 100%;
    height: var(--app-height, 100dvh);
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom));
    border: 0;
    background: var(--sidebar);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .messenger.mobile-chat-open .sidebar {
    display: none;
  }

  .messenger:not(.mobile-chat-open) .chat {
    display: none;
  }

  .profile {
    position: sticky;
    top: calc(-10px - env(safe-area-inset-top));
    z-index: 20;
    min-height: 64px;
    margin: calc(-10px - env(safe-area-inset-top)) -10px 0;
    padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
    background: var(--sidebar);
  }

  .chat {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    padding: 0;
    background: var(--chat);
  }

  .messenger.mobile-chat-open .chat {
    position: absolute;
    inset: 0;
    width: 100%;
    height: var(--app-height, 100dvh);
    padding: 0;
  }

  .chat-head,
  .messenger.mobile-chat-open .chat-head {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    z-index: 40;
    width: 100%;
    height: auto;
    min-height: calc(58px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    padding-left: 10px;
    background: rgba(23, 33, 43, .98);
    border-bottom: 1px solid var(--line);
  }

  .mobile-back,
  .messenger.mobile-chat-open .mobile-back {
    position: relative;
    top: auto;
    left: auto;
    z-index: auto;
    display: grid;
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .chat-identity,
  .messenger.mobile-chat-open .chat-identity {
    min-width: 0;
    flex: 1 1 auto;
  }

  .head-actions {
    max-width: 48vw;
    min-width: 0;
    justify-content: flex-end;
    overflow: hidden;
  }

  .head-actions .ghost {
    flex: 0 0 38px;
  }

  .chat-tools,
  .messenger.mobile-chat-open .chat-tools {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    z-index: 35;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
  }

  .messages,
  .messenger.mobile-chat-open .messages {
    grid-row: auto;
    height: auto;
    min-height: 0;
    padding: 12px 10px 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .composer-wrap,
  .messenger.mobile-chat-open .composer-wrap {
    position: relative;
    bottom: auto;
    grid-row: auto;
    align-self: stretch;
    min-height: 0;
    max-height: 46vh;
    padding: 7px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--sidebar);
  }

  .composer {
    grid-template-columns: 40px 40px 40px minmax(0, 1fr) 46px;
    gap: 6px;
  }

  .composer button[type="submit"] {
    grid-column: auto;
  }

  .empty {
    min-height: 0;
    height: 100%;
  }

  .settings-modal,
  .manage-modal,
  .image-viewer {
    height: var(--app-height, 100dvh);
  }
}


/* Mobile polish: top-aligned chat and thumb-friendly bottom back button. */
@media (max-width: 860px) {
  html,
  body {
    height: var(--app-height, 100svh) !important;
    min-height: var(--app-height, 100svh) !important;
    overflow: hidden !important;
  }

  body {
    position: static !important;
  }

  .shell {
    position: fixed !important;
    inset: 0 !important;
    display: block !important;
    place-items: unset !important;
    width: 100vw !important;
    height: var(--app-height, 100svh) !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .messenger {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 100vw !important;
    height: var(--app-height, 100svh) !important;
    min-height: 0 !important;
    max-height: none !important;
    transform: none !important;
  }

  .messenger.mobile-chat-open .chat {
    position: absolute !important;
    inset: 0 !important;
    display: grid !important;
    grid-template-rows: auto auto minmax(0, 1fr) auto !important;
    align-content: stretch !important;
    justify-content: stretch !important;
    width: 100vw !important;
    height: var(--app-height, 100svh) !important;
    min-height: 0 !important;
    padding: 0 !important;
    transform: none !important;
  }

  .messenger.mobile-chat-open .chat-head {
    grid-row: 1 !important;
    align-self: start !important;
    min-height: calc(56px + env(safe-area-inset-top)) !important;
    padding: calc(7px + env(safe-area-inset-top)) 10px 7px !important;
    padding-left: 10px !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back {
    position: fixed !important;
    left: 12px !important;
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    z-index: 95 !important;
    display: grid !important;
    width: 48px !important;
    min-width: 48px !important;
    height: 48px !important;
    min-height: 48px !important;
    border: 1px solid rgba(94, 181, 247, .32) !important;
    border-radius: 50% !important;
    color: #fff !important;
    background: rgba(42, 171, 238, .96) !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .34) !important;
    font-size: 2rem !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back::before {
    content: "";
  }

  .messenger.mobile-chat-open .chat-identity {
    margin-left: 0 !important;
  }

  .messenger.mobile-chat-open .messages {
    grid-row: 3 !important;
    min-height: 0 !important;
    height: auto !important;
    padding: 12px 10px 10px !important;
  }

  .messenger.mobile-chat-open .composer-wrap {
    grid-row: 4 !important;
    align-self: end !important;
    padding-left: 66px !important;
  }

  .messenger.mobile-chat-open .composer {
    grid-template-columns: 40px 40px minmax(0, 1fr) 46px !important;
  }

  .messenger.mobile-chat-open #mediaOriginalBtn {
    display: none !important;
  }
}


/* Lichka compact menus. */
.chat-menu-btn {
  display: inline-grid;
  place-items: center;
}

.attach-panel {
  display: none;
}

@media (min-width: 861px) {
  #messageSearchToggle,
  #archiveBtn,
  #blockBtn,
  #groupInviteBtn,
  #groupManageBtn,
  #channelInviteBtn,
  #channelManageBtn {
    display: none !important;
  }

  .head-actions {
    gap: 8px;
  }

  .composer {
    grid-template-columns: 44px 44px minmax(0, 1fr) 136px;
  }

  #mediaOriginalBtn {
    display: none !important;
  }
}

@media (max-width: 860px) {
  .head-actions {
    max-width: none !important;
    gap: 0 !important;
  }

  .head-actions #messageSearchToggle,
  .head-actions #archiveBtn,
  .head-actions #blockBtn,
  .head-actions #groupInviteBtn,
  .head-actions #groupManageBtn,
  .head-actions #channelInviteBtn,
  .head-actions #channelManageBtn,
  .head-actions .status {
    display: none !important;
  }

  .chat-menu-btn,
  .head-actions .chat-menu-btn {
    display: grid !important;
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 50% !important;
    font-size: 1.4rem !important;
    line-height: 1 !important;
  }

  .messenger.mobile-chat-open .composer-wrap {
    padding-left: 8px !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back {
    left: 10px !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }

  .messenger.mobile-chat-open .composer {
    grid-template-columns: 42px 42px minmax(0, 1fr) 48px !important;
    padding-left: 50px !important;
  }

  #mediaOriginalBtn {
    display: none !important;
  }

  .attach-toggle {
    font-size: 1.2rem !important;
  }

  .attach-menu {
    z-index: 96;
  }
}


/* Mobile Lichka chat chrome: clean header and single-line composer. */
@media (max-width: 860px) {
  .messenger.mobile-chat-open .chat-head {
    min-height: calc(58px + env(safe-area-inset-top)) !important;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px !important;
    gap: 8px !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back {
    position: relative !important;
    left: auto !important;
    bottom: auto !important;
    top: auto !important;
    z-index: auto !important;
    display: grid !important;
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    border: 1px solid rgba(255, 255, 255, .08) !important;
    border-radius: 50% !important;
    color: #fff !important;
    background: rgba(255, 255, 255, .07) !important;
    box-shadow: none !important;
    font-size: 2rem !important;
  }

  .messenger.mobile-chat-open .peer-avatar {
    width: 42px !important;
    height: 42px !important;
  }

  .messenger.mobile-chat-open .chat-identity h2 {
    max-width: 52vw !important;
  }

  .messenger.mobile-chat-open .composer-wrap {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)) !important;
    background: rgba(17, 27, 36, .98) !important;
  }

  .messenger.mobile-chat-open .ai-note {
    display: none !important;
  }

  .messenger.mobile-chat-open .composer {
    grid-template-columns: 44px minmax(0, 1fr) 48px !important;
    gap: 8px !important;
    padding-left: 0 !important;
    align-items: end !important;
  }

  .messenger.mobile-chat-open #emojiBtn,
  .messenger.mobile-chat-open #mediaOriginalBtn {
    display: none !important;
  }

  .messenger.mobile-chat-open #mediaBtn {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    border-radius: 50% !important;
    color: #fff !important;
    background: rgba(255, 255, 255, .08) !important;
    border-color: rgba(255, 255, 255, .08) !important;
    font-size: 1.35rem !important;
  }

  .messenger.mobile-chat-open textarea {
    min-height: 44px !important;
    max-height: 120px !important;
    padding: 11px 14px !important;
    border-radius: 22px !important;
    background: rgba(255, 255, 255, .06) !important;
  }

  .messenger.mobile-chat-open #sendBtn {
    width: 48px !important;
    min-width: 48px !important;
    height: 44px !important;
    min-height: 44px !important;
    border-radius: 50% !important;
  }
}


/* Lichka own mobile visual style: familiar mechanics, distinct look. */
@media (max-width: 860px) {
  .messenger.mobile-chat-open .chat {
    background:
      radial-gradient(circle at 18% 12%, rgba(84, 214, 152, .08), transparent 24rem),
      radial-gradient(circle at 92% 0%, rgba(94, 181, 247, .10), transparent 20rem),
      #0e1621 !important;
  }

  .messenger.mobile-chat-open .chat-head {
    background: rgba(18, 29, 39, .96) !important;
    box-shadow: 0 10px 26px rgba(0, 0, 0, .16) !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back,
  .messenger.mobile-chat-open .chat-menu-btn {
    color: #d7e6f2 !important;
    background: rgba(255, 255, 255, .055) !important;
    border-color: rgba(255, 255, 255, .075) !important;
  }

  .messenger.mobile-chat-open .chat-head .mobile-back {
    font-size: 1.85rem !important;
  }

  .messenger.mobile-chat-open .chat-menu-btn {
    font-size: 1.35rem !important;
  }

  .messenger.mobile-chat-open .composer-wrap {
    background: rgba(18, 29, 39, .98) !important;
    box-shadow: 0 -14px 32px rgba(0, 0, 0, .22) !important;
  }

  .messenger.mobile-chat-open #mediaBtn {
    color: #b9ccdc !important;
    background: rgba(255, 255, 255, .055) !important;
    border: 1px solid rgba(255, 255, 255, .075) !important;
    box-shadow: none !important;
    font-size: 1.1rem !important;
  }

  .messenger.mobile-chat-open textarea {
    color: #edf5fb !important;
    background: rgba(255, 255, 255, .055) !important;
    border: 1px solid rgba(255, 255, 255, .045) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.035) !important;
  }

  .messenger.mobile-chat-open textarea::placeholder {
    color: #8799a9 !important;
  }

  .messenger.mobile-chat-open #sendBtn {
    color: #061019 !important;
    background: linear-gradient(135deg, #67e8b9, #5eb5f7) !important;
    border: 0 !important;
    box-shadow: 0 10px 28px rgba(94, 181, 247, .22) !important;
    font-size: 0 !important;
  }

  .messenger.mobile-chat-open #sendBtn::before {
    content: "↑" !important;
    font-size: 1.35rem !important;
    font-weight: 950 !important;
    line-height: 1 !important;
  }

  .messenger.mobile-chat-open .message.out {
    background: linear-gradient(135deg, #2f6f95, #2f806e) !important;
  }

  .messenger.mobile-chat-open .message.in {
    background: rgba(255, 255, 255, .085) !important;
  }

  .attach-menu button,
  #dialogMenu button {
    color: #edf5fb;
  }
}


.chat-action-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(24, 37, 51, .96);
}

.chat-action-panel button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-soft);
}

.chat-action-panel button.danger {
  color: var(--red);
  border-color: rgba(255, 107, 122, .32);
}

.inbox-item.dragging {
  opacity: .52;
}

.archive-card.drag-over,
.inbox-card.drag-over {
  outline: 2px dashed rgba(94, 181, 247, .7);
  outline-offset: 3px;
}

@media (max-width: 860px) {
  .chat-action-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 8px 10px;
  }

  .chat-action-panel button {
    min-height: 42px;
    border-radius: 12px;
  }
}


/* Legal/start pages must scroll; app fullscreen lock is only for messenger. */
@media (max-width: 860px) {
  body:not(.app-body) {
    position: static !important;
    inset: auto !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  body:not(.app-body) .legal-page {
    min-height: 100vh !important;
    max-height: none !important;
    overflow: visible !important;
  }
}

.inbox-item[draggable="true"] {
  cursor: grab;
  user-select: none;
}

.inbox-item[draggable="true"]:active {
  cursor: grabbing;
}

.chat-action-panel:not(.hidden) {
  display: flex !important;
  position: relative;
  z-index: 60;
  min-height: 54px;
}


.avatar-sheet-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 18, .68);
  backdrop-filter: blur(12px);
}

.avatar-sheet {
  position: relative;
  width: min(340px, calc(100vw - 32px));
  aspect-ratio: 1 / 1;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(24,37,51,.98), rgba(17,27,36,.98));
  box-shadow: var(--shadow);
}

.avatar-sheet-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255,255,255,.06);
}

.avatar-sheet-preview {
  width: 112px;
  height: 112px;
  font-size: 2.6rem;
}

.avatar-sheet h2 {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-sheet p {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
  text-align: center;
}

.avatar-sheet-actions {
  width: 100%;
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.avatar-sheet-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel);
}

.avatar-sheet-actions button:first-child {
  color: #061019;
  background: linear-gradient(135deg, #67e8b9, #5eb5f7);
  border-color: transparent;
}

.avatar-sheet-actions .hidden {
  display: none !important;
}

.avatar-sheet-actions .danger {
  color: var(--red);
  border-color: rgba(255,107,122,.35);
}

.peer-avatar,
.avatar-button {
  cursor: pointer;
}

@media (max-width: 860px) {
  .avatar-sheet-modal {
    align-items: end;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  }

  .avatar-sheet {
    width: 100%;
    max-width: 360px;
    border-radius: 20px;
  }
}


/* Mobile settings: full-screen, compact, clearly tappable rows. */
@media (max-width: 860px) {
  .settings-modal {
    display: flex !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    height: var(--app-height, 100svh) !important;
    min-height: var(--app-height, 100svh) !important;
    padding: 0 !important;
    background: var(--sidebar) !important;
    backdrop-filter: none !important;
  }

  .settings-modal.hidden {
    display: none !important;
  }

  .settings-sheet {
    width: 100% !important;
    height: var(--app-height, 100svh) !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: calc(10px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom)) !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: var(--sidebar) !important;
    box-shadow: none !important;
  }

  .settings-head {
    position: sticky;
    top: calc(-10px - env(safe-area-inset-top));
    z-index: 4;
    min-height: 58px;
    padding: 2px 0 10px;
    border-bottom: 1px solid var(--line);
    background: var(--sidebar);
  }

  .settings-head .eyebrow {
    margin: 0 0 2px;
    font-size: .78rem;
  }

  .settings-head h2 {
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.1;
  }

  #settingsCloseBtn {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 14px !important;
  }

  .settings-profile {
    position: relative;
    gap: 12px !important;
    padding: 10px 12px !important;
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 16px !important;
    background: rgba(9, 19, 29, .78) !important;
  }

  .settings-profile::after {
    content: "›";
    margin-left: auto;
    color: var(--muted);
    font-size: 1.8rem;
    line-height: 1;
  }

  .settings-avatar {
    width: 54px !important;
    height: 54px !important;
    min-width: 54px !important;
  }

  .settings-profile strong {
    display: block;
    font-size: 1.05rem;
    line-height: 1.1;
  }

  .settings-profile p {
    margin: 4px 0 0 !important;
    font-size: .8rem !important;
    line-height: 1.25 !important;
  }

  .settings-list {
    gap: 0 !important;
    padding: 4px 0 0;
  }

  .settings-list button,
  .settings-list a,
  .settings-field {
    width: 100%;
    min-height: 50px !important;
    padding: 9px 0 !important;
    border-radius: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, .055);
    background: transparent !important;
  }

  .settings-list button:hover,
  .settings-list a:hover,
  .settings-field:hover {
    background: transparent !important;
  }

  .settings-list span,
  .settings-field strong,
  .settings-field label span {
    font-size: 1rem !important;
    line-height: 1.15;
  }

  .settings-list small,
  .settings-field small {
    margin-top: 3px;
    font-size: .74rem !important;
    line-height: 1.22;
  }

  .settings-field {
    grid-template-columns: minmax(0, 1fr) minmax(112px, auto) !important;
    gap: 12px !important;
  }

  .settings-field select {
    min-height: 38px !important;
    max-width: 150px;
    border-radius: 12px !important;
    font-size: .95rem !important;
  }

  .switch-field input {
    width: 50px !important;
    min-width: 50px !important;
    height: 30px !important;
  }

  .switch-field input::after {
    width: 24px !important;
    height: 24px !important;
  }

  .switch-field input:checked::after {
    transform: translateX(20px) !important;
  }
}
