﻿:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #111b26;
  --card: #1f2c3a;
  --line: #263649;
  --text: #e5f2ff;
  --muted: #88a3bf;
  --primary: #4ea4f6;
  --primary-2: #3c92e6;
  --danger: #ef4b5a;
  --mine: #2b5278;
  --theirs: #182533;
}

body.dark {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #111b26;
  --card: #1f2c3a;
  --line: #263649;
  --text: #e5f2ff;
  --muted: #88a3bf;
  --primary: #4ea4f6;
  --primary-2: #3c92e6;
  --danger: #ef4b5a;
  --mine: #2b5278;
  --theirs: #182533;
}

body {
  --bg: #ecf1f8;
  --panel: #ffffff;
  --panel-2: #f5f8fd;
  --card: #edf2fa;
  --line: #d5e0ef;
  --text: #102135;
  --muted: #6481a0;
  --primary: #3a8de0;
  --primary-2: #2e78c5;
  --danger: #dc3f4f;
  --mine: #d9ebff;
  --theirs: #f6f8fc;
}

html { font-size: calc(16px * var(--ui-scale, 1)); }
* { box-sizing: border-box; }

/* Hide visible scrollbars; keep wheel/touch/trackpad scrolling working */
* {
  scrollbar-width: none; /* Firefox */
}
*::-webkit-scrollbar {
  width: 0;
  height: 0;
}
*::-webkit-scrollbar-thumb {
  background: transparent;
}

body {
  margin: 0;
  font-family: "Segoe UI", "SF Pro Text", sans-serif;
  background: var(--app-bg, linear-gradient(145deg, #1c3147 0%, #101824 48%, #0c121b 100%));
  background-size: 180% 180%;
  animation: bgShift 18s ease-in-out infinite;
  color: var(--text);
}
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }

input, select, button {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  transition: background .18s ease, border-color .18s ease, transform .14s ease, box-shadow .18s ease;
}

button { cursor: pointer; background: var(--primary); color: #fff; border: none; }
button:hover { background: var(--primary-2); }
button:active { transform: translateY(1px) scale(0.99); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger { background: var(--danger); }
.link-btn {
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
}
.link-btn:hover { color: var(--text); background: transparent; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(560px, 100%);
  background: color-mix(in srgb, var(--panel) 92%, black 8%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, .25);
}
.auth-hint { color: var(--muted); margin-top: 4px; margin-bottom: 10px; font-size: 13px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.tab { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.tab.active { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 28%, transparent); }
.auth-error { min-height: 20px; color: #ff6b73; margin-bottom: 8px; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.password-row button { min-width: 104px; }
.auth-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.primary-auth { width: 100%; }
.auth-card input { width: 100%; margin-bottom: 8px; }

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 420px 1fr;
  background: var(--app-bg, linear-gradient(145deg, #1c3147 0%, #101824 48%, #0c121b 100%));
}

.left-panel {
  display: grid;
  grid-template-columns: 92px 1fr;
  column-gap: 0;
  border-right: 1px solid var(--line);
  min-width: 0;
  height: 100vh;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}

.left-rail {
  width: 92px;
  min-width: 92px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel-2) 92%, #0a1119 8%) 0%, color-mix(in srgb, var(--panel) 88%, #0a1119 12%) 100%);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  overflow-x: hidden;
}

.rail-btn {
  width: 100%;
  min-height: 52px;
  height: auto;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.05;
  display: grid;
  place-items: center;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  padding: 8px 5px;
  flex: 0 0 auto;
}

.rail-folders {
  margin-top: 8px;
  border-top: 1px solid #20324a;
  padding-top: 8px;
  display: grid;
  gap: 6px;
}
body.folders-top .rail-folders {
  display: none;
}
.rail-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.rail-folder-list {
  display: grid;
  gap: 6px;
}
.rail-folder-item {
  width: 100%;
  min-height: 30px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  padding: 6px 3px;
  text-align: center;
  cursor: pointer;
  word-break: break-word;
}
.rail-folder-item.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.rail-add-folder {
  width: 100%;
  min-height: 30px;
  border-radius: 10px;
  padding: 4px 2px;
  font-size: 11px;
}

.dialogs-panel {
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 94%, transparent) 0%, color-mix(in srgb, var(--panel-2) 92%, transparent) 100%);
  box-shadow: inset 1px 0 0 var(--line);
  padding: 10px;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.brand-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.me-badge { display: flex; gap: 10px; align-items: center; min-width: 0; }
.me-badge { cursor: pointer; }
.me-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #2f4d6d;
  display: grid;
  place-items: center;
  font-weight: 700;
  overflow: hidden;
}
.me-meta { min-width: 0; }
.me-name { font-size: 21px; font-weight: 700; line-height: 1.05; }
#me { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.top-tools { display: flex; gap: 8px; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-top: 12px;
}
.card input { width: 100%; }
.top-folders {
  margin-bottom: 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}
.top-folder-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.top-folder-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.list {
  margin-top: 8px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
#users, #chats {
  overflow-x: hidden;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.section-title, .muted { color: var(--muted); font-size: 13px; }

.user-item, .chat-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, transform .14s ease;
}

.user-item:hover, .chat-item:hover { background: color-mix(in srgb, var(--card) 85%, transparent); }
.user-item:hover, .chat-item:hover { transform: translateX(1px); }
.chat-item.active {
  border-color: var(--line);
  background: color-mix(in srgb, var(--card) 92%, var(--primary) 8%);
  overflow: hidden;
}

.chat-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #0a1119;
}

.chat-main { min-width: 0; }
.chat-title-line { display: flex; justify-content: space-between; gap: 8px; }
.chat-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--muted); font-size: 12px; }
.chat-preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-folder-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}
.unread-pill {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  font-size: 12px;
  color: white;
  background: var(--primary);
}
.chat-folder-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 80%, #09131f 20%) 0%, color-mix(in srgb, var(--bg) 82%, #070d15 18%) 100%);
  overflow: hidden;
}
.chat-wallpaper-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.chat-wallpaper-blur {
  background-image: var(--chat-wallpaper-image, none);
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  filter: blur(30px) saturate(1.06);
  transform: scale(1.08);
  opacity: var(--chat-wallpaper-blur-opacity, 0.72);
  transition: opacity .16s ease;
}
.chat-wallpaper-main {
  background-image: var(--chat-wallpaper-image, none);
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  opacity: var(--chat-wallpaper-opacity, 0.98);
  transition: opacity .16s ease;
}
.chat-panel > * {
  position: relative;
  z-index: 1;
}

.chat-header {
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#chatTitle { font-size: 28px; font-weight: 700; line-height: 1; }
.right-tools { gap: 6px; }
.right-tools button, .right-tools select { height: 40px; }

.mobile-back {
  width: 34px;
  height: 34px;
  padding: 0;
  margin-right: 8px;
}

.call-status, .typing { min-height: 22px; padding: 2px 12px; color: var(--muted); }
.call-participants { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 12px; min-height: 30px; }
.participant-pill { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 8px; font-size: 12px; }
.participant-pill.talking { border-color: #3ddc84; box-shadow: 0 0 0 1px #3ddc84 inset; }
.participant-pill.muted { opacity: 0.7; }
.remote-video { margin: 0 12px; max-height: 220px; border-radius: 12px; border: 1px solid var(--line); background: #000; }
.call-window {
  margin: 10px 12px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 96%, black 4%);
  overflow: hidden;
}
.call-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.call-window-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.call-window .remote-video {
  margin: 0;
  width: 100%;
  max-height: min(45vh, 420px);
  border: none;
  border-radius: 0;
}
.call-local-preview {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, black 12%);
}
.call-local-title {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
}
.call-local-preview .remote-video {
  max-height: min(34vh, 300px);
}

.messages {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: transparent;
  min-height: 0;
}

.msg {
  background: var(--theirs);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 10px;
  max-width: min(700px, 72%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
  animation: msgIn .16s ease-out;
}

.msg.me { margin-left: auto; background: var(--mine); border-bottom-right-radius: 8px; }
.msg.selected { outline: 2px solid var(--primary); }
.msg .msg-meta { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.msg.media-visual {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  max-width: min(560px, 82%);
}
.msg.media-visual .msg-meta {
  margin-top: 6px;
  padding: 0 4px;
}
.msg.media-visual img,
.msg.media-visual video {
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  display: block;
}
.audio-file-card {
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-2) 84%, transparent);
  padding: 8px 10px;
  min-width: 240px;
}
.audio-file-title {
  font-weight: 700;
  line-height: 1.2;
}
.audio-file-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  margin-bottom: 6px;
}
.audio-file-card audio {
  width: 100%;
  height: 34px;
}
.audio-file-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 10px;
  color: var(--text);
  text-decoration: none;
}
.forwarded-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.forwarded-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #2f4d6d;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.forwarded-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.forwarded-label {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0;
  margin: 0;
  font-size: 13px;
  cursor: pointer;
}
.forwarded-label:hover { color: var(--text); text-decoration: underline; }
.msg .row button.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 22%, transparent);
}
.msg-comments-inline {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel-2) 90%, transparent);
}
.msg-comments-header {
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  cursor: pointer;
}
.msg-comments-inline.open .msg-comments-header {
  border-bottom-color: var(--line);
  color: var(--text);
}
.msg-comments-body {
  display: none;
  padding: 8px;
  gap: 8px;
}
.msg-comments-inline.open .msg-comments-body {
  display: grid;
}
.msg-comments-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}
.msg-comment-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
}
.msg-comment-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.msg-comment-author { font-weight: 700; }
.msg-comment-time { color: var(--muted); }
.msg-comment-text { margin-top: 4px; color: var(--text); }
.msg-comments-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.msg-mention {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
}
.msg-mention:hover { text-decoration: underline; }
.msg-link {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
}

.composer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  padding: 10px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 8px;
  align-items: center;
}

#messageInput { width: 100%; }
.reply-preview { grid-column: 1 / -1; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; font-size: 13px; color: var(--muted); }
.attach-menu {
  position: fixed;
  right: 16px;
  bottom: 74px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
  z-index: 30;
}

.chat-menu, .main-menu {
  position: fixed;
  background: color-mix(in srgb, var(--panel) 96%, black 4%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, .35);
  z-index: 70;
  display: grid;
  gap: 6px;
  width: min(320px, calc(100vw - 14px));
  animation: popIn .14s ease-out;
}

.chat-menu { top: 68px; right: 12px; }
.main-menu { top: 66px; left: 76px; }
.chat-menu button, .main-menu button { text-align: left; }

.msg-context {
  position: fixed;
  z-index: 140;
  width: min(300px, calc(100vw - 20px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  display: grid;
  gap: 6px;
}

.msg-context button { text-align: left; border-radius: 10px; padding: 8px 10px; }
.msg-reactions { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 4px; }
.msg-reactions button { text-align: center; padding: 6px 0; font-size: 18px; }
.selection-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.selection-count {
  font-weight: 700;
  font-size: 14px;
}
body.selecting-messages,
body.selecting-messages * {
  user-select: none !important;
}

.settings {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, calc(100vw - 24px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  z-index: 50;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.settings-head h3 {
  margin: 0;
}
.settings-close-btn {
  flex: 0 0 auto;
}
.settings-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 12px;
}
.settings-nav {
  display: grid;
  gap: 8px;
  align-content: start;
}
.settings-nav .settings-tab {
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
  line-height: 1.2;
  min-height: 44px;
}
.settings-content {
  min-width: 0;
}
.settings-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.settings-tab.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}
.settings-section { display: none; }
.settings-section.active { display: block; }
.setting-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.folders-hero {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-2) 90%, transparent);
  padding: 10px;
  margin-bottom: 8px;
}
.folders-hero-icon {
  font-size: 36px;
  margin-bottom: 4px;
}
.folder-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.folder-row-main { min-width: 0; }
.folder-row-title { font-weight: 600; }
.settings h4 { margin: 10px 0 8px; font-size: 14px; color: var(--muted); }
.settings label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.settings label select, .settings input, .settings textarea { margin-top: 4px; width: 100%; }
.settings textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.accent-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}
.theme-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.theme-preset {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 8px;
  text-align: left;
}
.theme-preset-title { font-weight: 700; font-size: 13px; }
.theme-preset-preview {
  margin-top: 6px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.theme-preset.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}
.theme-demo {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 190px;
  margin-bottom: 10px;
}
.theme-demo-left {
  border-right: 1px solid var(--line);
  padding: 8px;
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
}
.theme-demo-search {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.theme-demo-chat {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 9px;
  margin-bottom: 4px;
}
.theme-demo-chat.active { background: color-mix(in srgb, var(--card) 88%, var(--primary) 12%); }
.theme-demo-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2f4d6d;
  font-size: 12px;
  font-weight: 700;
}
.theme-demo-title { font-size: 12px; font-weight: 700; }
.theme-demo-text { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme-demo-right {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  position: relative;
  overflow: hidden;
}
.theme-demo-right::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--theme-demo-wallpaper, none);
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  opacity: 0.38;
  pointer-events: none;
}
.theme-demo-right::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--theme-demo-wallpaper, none);
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  filter: blur(24px);
  transform: scale(1.07);
  opacity: 0.22;
  pointer-events: none;
}
.theme-demo-header {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  position: relative;
  z-index: 1;
}
.theme-demo-messages {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1;
}
.theme-demo-bubble {
  max-width: 75%;
  background: var(--theirs);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  font-size: 12px;
}
.theme-demo-bubble.me {
  margin-left: auto;
  background: var(--mine);
}
.theme-demo-composer {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  font-size: 12px;
  position: relative;
  z-index: 1;
}
.theme-contrast-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.theme-contrast-switch button.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}
.accent-chip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
}
.accent-chip.active {
  outline: 2px solid #fff;
}
.security-list {
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: color-mix(in srgb, var(--panel-2) 94%, transparent);
}
.security-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--card) 90%, transparent);
}
.security-item:last-child { margin-bottom: 0; }
.security-item .muted { display: block; margin-top: 2px; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 40; }
.modal-card { width: min(420px, calc(100vw - 20px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.modal-card input, .modal-card select { width: 100%; }
.modal-card h3 { margin: 0 0 10px; }
#appDialogModal { z-index: 120; }
#avatarPreviewModal { z-index: 130; }
.app-dialog-card {
  width: min(520px, calc(100vw - 24px));
}
.app-dialog-card #appDialogText {
  margin-bottom: 10px;
  white-space: pre-wrap;
}
.app-dialog-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

#commentsList .chat-item,
#gsMembersList .chat-item {
  border: 1px solid var(--line);
  border-radius: 10px;
}

#groupSettingsModal .modal-card .row {
  align-items: flex-end;
}
#groupSettingsModal {
  z-index: 95;
}
.group-settings-card {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border-radius: 16px;
  padding: 14px;
}
.group-settings-card h3 {
  margin: 0 0 4px;
}
.group-settings-meta {
  margin-bottom: 10px;
}
.group-settings-fields {
  display: grid;
  gap: 8px;
}
.group-settings-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.group-settings-toggles {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
}
.group-settings-toggles .setting-row {
  margin: 0;
  justify-content: flex-start;
}
.group-members-title {
  margin-top: 12px;
}
.group-member-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.group-members-list {
  max-height: 240px;
}
.group-settings-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.gif-picker-card {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
}
.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: 52vh;
  overflow: auto;
}
.gif-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 6px;
  display: grid;
  gap: 6px;
}
.gif-item img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}
.gif-item-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}
.gif-star {
  min-width: 40px;
  border-radius: 8px;
}

.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #6b7280; }
.online-dot.on { background: #22c55e; }
.profile-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: grid;
  place-items: center;
  z-index: 90;
}
.profile-card {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.profile-head {
  display: flex;
  justify-content: space-between;
}
.profile-main { text-align: center; padding: 6px 0 12px; }
.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #2f4d6d;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 34px;
  margin: 0 auto 8px;
  cursor: pointer;
}
.profile-name { font-size: 34px; font-weight: 700; }
.profile-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.profile-actions button { min-height: 48px; }
.profile-info {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.profile-music {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.profile-music-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.profile-music-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}
.profile-music-artist,
.profile-music-file {
  font-size: 12px;
  line-height: 1.2;
}
.profile-music-file {
  max-width: 44%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.profile-music-player {
  width: 100%;
  margin-top: 6px;
  max-height: 34px;
}
.profile-local-avatar {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}
.profile-stats {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.profile-stat-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 56px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
}
.profile-stat-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}
.profile-stat-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}
.avatar-preview-card {
  width: min(520px, calc(100vw - 24px));
}
.avatar-preview-body {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 240px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--panel-2) 94%, transparent);
}
.avatar-preview-img {
  max-width: 100%;
  max-height: min(72vh, 560px);
  border-radius: 12px;
  object-fit: contain;
}
.avatar-preview-fallback {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 92px;
  font-weight: 700;
  background: #2f4d6d;
}
.call-mini {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 95;
  max-width: min(58vw, 360px);
  border-radius: 999px;
  padding: 10px 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1024px) {
  .shell { grid-template-columns: 360px 1fr; }
  .right-tools { flex-wrap: wrap; justify-content: flex-end; }
  #chatTitle { font-size: 24px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .left-panel {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(420px, 100%);
    z-index: 40;
    background: var(--panel);
    transform: translateX(0);
  }

  body.mobile-chat-open .left-panel {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .chat-panel {
    height: 100vh;
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
  }
  .mobile-back { display: inline-grid !important; place-items: center; }
  .chat-header { position: sticky; top: 0; z-index: 20; }
  .composer {
    position: static;
    z-index: 20;
    grid-template-columns: auto auto 1fr auto auto;
    padding: 8px;
    margin-top: 0;
  }
  .messages { padding: 8px; }
  .msg { max-width: 92%; }
  .main-menu { left: 10px; top: 58px; }
  .chat-menu { right: 8px; top: 58px; }
  .settings {
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    transform: none;
    width: auto;
    max-height: none;
  }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { grid-template-columns: repeat(2, 1fr); }
  .settings-tabs { grid-template-columns: repeat(2, 1fr); }
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
  .group-settings-grid { grid-template-columns: 1fr; }
  .group-settings-toggles { grid-template-columns: 1fr; }
  .group-settings-actions button { flex: 1 1 auto; }
  .theme-demo { grid-template-columns: 1fr; }
  .theme-demo-left { border-right: none; border-bottom: 1px solid var(--line); }
}

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

@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bgShift {
  0% { background-position: 0% 0%; }
  50% { background-position: 100% 20%; }
  100% { background-position: 0% 0%; }
}
