/* =====================================================================
   Community — styles.css
   Themes: deep-space (default) | dark | light   (html[data-theme])
   Font size: html { font-size: var(--fs) }  — JS sets --fs (12..20px)
   ===================================================================== */

/* ---------- 1. THEME TOKENS ---------- */
:root,
html[data-theme="deep-space"] {
  color-scheme: dark;
  --bg1: #05010d;
  --bg2: #080312;
  --panel: rgba(16, 8, 30, 0.72);
  --panel-solid: #0e071d;
  --main-bg: rgba(8, 3, 18, 0.45);
  --panel-2: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f0fa;
  --muted: #8e85a3;
  --accent: #8b5cf6;
  --accent-2: #c4b5fd;
  --accent-soft: rgba(139, 92, 246, 0.18);
  --bubble-in: rgba(255, 255, 255, 0.06);
  --bubble-in-text: #f4f0fa;
  --bubble-out: linear-gradient(135deg, #5b21b6, #7c3aed);
  --bubble-out-text: #ffffff;
  --input-bg: rgba(255, 255, 255, 0.06);
  --danger: #ff6b81;
  --ok: #34d399;
  --tick-read: #7dd3fc;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --star-opacity: 1;
  --fs: 15px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg1: #0e1014;
  --bg2: #171a21;
  --panel: rgba(24, 27, 34, 0.9);
  --panel-solid: #1a1d25;
  --main-bg: rgba(14, 16, 20, 0.5);
  --panel-2: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eceef3;
  --muted: #8f96a8;
  --accent: #6d7cff;
  --accent-2: #a5b0ff;
  --accent-soft: rgba(109, 124, 255, 0.22);
  --bubble-in: #232733;
  --bubble-in-text: #eceef3;
  --bubble-out: linear-gradient(135deg, #5b6cf0, #4152d6);
  --bubble-out-text: #ffffff;
  --input-bg: rgba(255, 255, 255, 0.07);
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.55);
  --star-opacity: 0;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg1: #eef0f8;
  --bg2: #e2e5f4;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --main-bg: rgba(255, 255, 255, 0.35);
  --panel-2: rgba(40, 30, 90, 0.07);
  --border: rgba(40, 30, 90, 0.14);
  --text: #1c1936;
  --muted: #6b6890;
  --accent: #7c3aed;
  --accent-2: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.14);
  --bubble-in: #ffffff;
  --bubble-in-text: #1c1936;
  --bubble-out: linear-gradient(135deg, #8b5cf6, #6d28d9);
  --bubble-out-text: #ffffff;
  --input-bg: rgba(40, 30, 90, 0.07);
  --danger: #e11d48;
  --ok: #059669;
  --tick-read: #bae6fd;
  --shadow: 0 14px 40px rgba(40, 30, 90, 0.18);
  --star-opacity: 0;
}

/* ---------- 2. BASE ---------- */
[hidden] { display: none !important; }

html { font-size: var(--fs, 15px); -webkit-text-size-adjust: 100%; }

*, *::before, *::after { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 100%) fixed;
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.font-head { font-family: 'Orbitron', system-ui, sans-serif; letter-spacing: 0.02em; }

.brand {
  margin: 0;
  font-family: 'Gravitas One', 'Orbitron', serif;
  font-size: 2.1rem;
  line-height: 1.1;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, #c4b5fd, #f0abfc 55%, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.brand-sm { font-size: 1.2rem; }
html[data-theme="light"] .brand {
  background: linear-gradient(90deg, #6d28d9, #c026d3 55%, #2563eb);
  -webkit-background-clip: text;
  background-clip: text;
}

.muted { color: var(--muted); }
.relative { position: relative; }
.grow { flex: 1; min-width: 0; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(160, 140, 230, 0.3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(160, 140, 230, 0.5); }
* { scrollbar-width: thin; scrollbar-color: rgba(160, 140, 230, 0.35) transparent; }

/* ---------- 3. ICONS ---------- */
.ic {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-sm { width: 0.9rem; height: 0.9rem; }
.ic-xl { width: 3rem; height: 3rem; }

/* ---------- 5. SCREENS ---------- */
.screen { position: relative; z-index: 1; }
.center-screen {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: calc(1rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right))
           calc(1rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left));
}
.center-screen > * { margin: auto; }

.loader-box { display: flex; flex-direction: column; align-items: center; gap: 1rem; color: var(--muted); }

.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.glass-panel {
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

/* ---------- 6. AUTH ---------- */
.auth-card {
  width: min(26rem, 100%);
  padding: 1.75rem;
  border-radius: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.auth-head { text-align: center; display: flex; flex-direction: column; gap: 0.35rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.9rem; }
.form-title { margin: 0; font-size: 1.1rem; }

.tabs { display: flex; gap: 0.25rem; padding: 0.25rem; background: var(--input-bg); border-radius: 0.9rem; }
.tab {
  flex: 1;
  padding: 0.55rem 0.5rem;
  border: 0;
  border-radius: 0.7rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.tab.is-active { background: var(--accent); color: #fff; }

/* ---------- 7. FORM CONTROLS ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.field > span { font-weight: 600; }
.hint { font-size: 0.75rem; color: var(--muted); opacity: 0.85; }

.field input,
.field textarea,
.field select,
.setting-row select,
.rename-row input,
.setting-row input[type="number"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.setting-row select { width: auto; max-width: 55%; padding: 0.45rem 0.7rem; }
.setting-row select option { background: var(--panel-solid); color: var(--text); }
.field input:focus,
.field textarea:focus,
.rename-row input:focus,
.setting-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 4rem; }

.form-error,
.form-info {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 0.7rem;
  font-size: 0.85rem;
}
.form-error { color: var(--danger); background: rgba(255, 107, 129, 0.12); border: 1px solid rgba(255, 107, 129, 0.3); }
.form-info  { color: var(--ok); background: rgba(52, 211, 153, 0.12); border: 1px solid rgba(52, 211, 153, 0.3); }

.notice {
  margin: 0 0 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.7rem;
  font-size: 0.8rem;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  border: 1px dashed rgba(251, 191, 36, 0.45);
}

/* ---------- 8. BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 0.85rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s, transform 0.05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; border-radius: 0.65rem; }
.btn-primary { background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); }
.btn-danger { background: #e11d48; color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid #fff;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.link {
  align-self: center;
  padding: 0.25rem;
  border: 0;
  background: none;
  color: var(--accent-2);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s, filter 0.15s;
  text-decoration: none;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn-sm { width: 2rem; height: 2rem; }
.icon-btn-accent { background: var(--accent); color: #fff; }
.icon-btn-accent:hover { background: var(--accent); filter: brightness(1.15); }

.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 2.2rem; height: 2.2rem; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 9. POPOVERS & MENUS ---------- */
.popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 60;
  min-width: 13rem;
  padding: 0.35rem;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 0.95rem;
  box-shadow: var(--shadow);
}
.popover-right { left: auto; right: 0; }
.popover-up { top: auto; bottom: calc(100% + 0.5rem); }

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--accent-soft); }
.menu-danger { color: var(--danger); }
.menu-danger:hover { background: rgba(255, 107, 129, 0.15); }

.msg-menu { position: fixed; top: 0; left: 0; z-index: 120; min-width: 12rem; max-width: 18rem; }
.msg-menu-reactions {
  display: flex;
  gap: 0.15rem;
  padding: 0.25rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.msg-menu-reactions button {
  flex-shrink: 0;
  width: 2.2rem;
  height: 2.2rem;
  border: 0;
  border-radius: 0.6rem;
  background: transparent;
  font-size: 1.3rem;
  cursor: pointer;
}
.msg-menu-reactions button:hover { background: var(--accent-soft); }

.emoji-picker { width: min(21rem, 92vw); padding: 0.4rem; }
.emoji-tabs { display: flex; gap: 0.15rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.emoji-tabs button {
  flex-shrink: 0;
  padding: 0.3rem 0.5rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
  opacity: 0.65;
}
.emoji-tabs button.is-active { background: var(--accent-soft); opacity: 1; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.1rem;
  max-height: 14rem;
  padding-top: 0.3rem;
  overflow-y: auto;
}
.emoji-grid button {
  aspect-ratio: 1;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.emoji-grid button:hover { background: var(--accent-soft); }

/* ---------- 10. APP SHELL ---------- */
.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(18rem, 25rem) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0.75rem 0.5rem;
  padding: 0.2rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--muted);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.search-box input:focus { outline: none; }
.search-box input::-webkit-search-cancel-button { display: none; }
.modal-body > .search-box,
.info-add-panel .search-box { margin-left: 0; margin-right: 0; }

.list-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 0.5rem; }
.list-scroll-sm { max-height: 12rem; overflow-y: auto; }
.list { margin: 0; padding: 0; list-style: none; }
.list-heading {
  margin: 0.6rem 0.9rem 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-2);
}

.state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem 1rem;
  color: var(--muted);
  text-align: center;
}
.state-empty, .state-error { flex-direction: column; }
.state-error { color: var(--danger); }
.state-overlay {
  position: absolute;
  inset: 0;
  flex-direction: column;
  pointer-events: none;
  z-index: 5;
}
.state-overlay > * { pointer-events: auto; }
.empty-pill {
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}
.badge.is-muted { background: var(--muted); }

/* ---------- 11. AVATARS ---------- */
.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #7c3aed, #db2777);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-lg { width: 4.2rem; height: 4.2rem; font-size: 1.4rem; }
.avatar-xl { width: 6rem; height: 6rem; font-size: 2rem; }
.avatar.is-online::after {
  content: '';
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--panel-solid);
}
.avatar.pulse { animation: avatarPulse 1.6s ease-out infinite; }
@keyframes avatarPulse {
  0%   { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.6); }
  100% { box-shadow: 0 0 0 1.6rem rgba(139, 92, 246, 0); }
}

.avatar-upload { position: relative; display: inline-block; cursor: pointer; }
.avatar-upload-center { align-self: center; }
.avatar-upload-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--panel-solid);
}

/* ---------- 12. CHAT LIST ---------- */
.chat-item,
.user-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.1rem 0.4rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-item:hover,
.user-row:hover { background: var(--panel-2); }
.chat-item.is-active { background: var(--accent-soft); }
.chat-item.is-active:hover { background: var(--accent-soft); }
.chat-item.is-pinned { background-image: linear-gradient(90deg, var(--panel-2), transparent); }

.chat-item-body,
.user-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.chat-item-row { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.chat-name,
.user-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.chat-time { flex-shrink: 0; font-size: 0.75rem; color: var(--muted); }
.chat-preview,
.user-row-sub {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  color: var(--muted);
}
.chat-flag { color: var(--muted); }
.chat-preview .is-typing { color: var(--accent-2); font-style: italic; }
.chat-preview .preview-sender { color: var(--accent-2); }

.role-tag {
  flex-shrink: 0;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}
.user-row-actions { display: flex; align-items: center; gap: 0.15rem; flex-shrink: 0; }

/* ---------- 13. MAIN PANE ---------- */
.main-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--main-bg);
}
.splash { flex: 1; display: grid; place-items: center; padding: 1rem; }
.splash-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding: 1.6rem 2.2rem;
  border-radius: 1.4rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  text-align: center;
}
.splash-badge p { margin: 0; }

.chat-view { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-top {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  z-index: 3;
}
.btn-back { display: none; }
.chat-head-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex: 1;
  min-width: 0;
  padding: 0.15rem 0.3rem;
  border: 0;
  border-radius: 0.8rem;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.chat-head-info:hover { background: var(--panel-2); }
.chat-head-info .avatar { width: 2.7rem; height: 2.7rem; font-size: 0.95rem; }
.chat-head-text { display: flex; flex-direction: column; min-width: 0; }
.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}
.chat-status { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.is-online { color: var(--accent-2); }
.chat-status.is-typing { color: var(--accent-2); font-style: italic; }
.chat-actions { display: flex; align-items: center; gap: 0.1rem; flex-shrink: 0; }

.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  z-index: 3;
}
.chat-search-bar input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 0.7rem;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.chat-search-bar input:focus { outline: 2px solid var(--accent); }
.chat-search-bar input::-webkit-search-cancel-button { display: none; }

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid var(--border);
  z-index: 3;
}
.pinned-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  padding: 0.2rem 0.3rem;
  border: 0;
  border-left: 3px solid var(--accent);
  border-radius: 0.3rem;
  background: none;
  color: var(--accent-2);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pinned-main:hover { background: var(--panel-2); }
.pinned-body { display: flex; flex-direction: column; min-width: 0; }
.pinned-label { font-size: 0.78rem; font-weight: 700; color: var(--accent-2); }
.pinned-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; color: var(--text); }

/* ---------- 14. MESSAGES ---------- */
.messages-wrap { position: relative; flex: 1; display: flex; min-height: 0; }
.messages-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 0.75rem 0.5rem;
}
.messages-list {
  display: flex;
  flex-direction: column;
  max-width: 48rem;
  margin: 0 auto;
}

.date-sep {
  position: sticky;
  top: 0.2rem;
  z-index: 2;
  align-self: center;
  margin: 0.6rem 0 0.35rem;
  text-align: center;
}
.date-sep span {
  display: inline-block;
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.unread-divider {
  margin: 0.7rem -0.75rem;
  padding: 0.25rem;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}
.system-msg { align-self: center; margin: 0.4rem 0; text-align: center; }
.system-msg span {
  display: inline-block;
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.8rem;
  color: var(--muted);
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(80%, 32rem);
  margin-top: 0.2rem;
}
.msg.is-first { margin-top: 0.6rem; }
.msg.is-out { align-self: flex-end; align-items: flex-end; }
.msg.is-in { align-self: flex-start; align-items: flex-start; }
.msg.is-pending .bubble { opacity: 0.7; }
.msg.is-failed .bubble { outline: 1px solid var(--danger); }

.bubble {
  position: relative;
  min-width: 4rem;
  max-width: 100%;
  padding: 0.4rem 0.65rem 0.3rem;
  border-radius: 1.05rem;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  -webkit-touch-callout: none;
  -webkit-user-select: text;
  user-select: text;
}
.msg.is-in .bubble { border-bottom-left-radius: 0.3rem; }
.msg.is-out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 0.3rem;
}
.msg.is-highlight .bubble { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%, 40% { box-shadow: 0 0 0 3px var(--accent-2), 0 0 24px var(--accent); }
  100%    { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
}

.msg-sender { margin-bottom: 0.1rem; font-size: 0.82rem; font-weight: 700; color: var(--accent-2); cursor: pointer; }
.msg-forward { display: flex; align-items: center; gap: 0.3rem; margin-bottom: 0.15rem; font-size: 0.8rem; font-style: italic; opacity: 0.85; }

.msg-reply {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-bottom: 0.3rem;
  padding: 0.2rem 0.5rem;
  border: 0;
  border-left: 3px solid var(--accent-2);
  border-radius: 0.35rem;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.msg.is-in .msg-reply { background: var(--accent-soft); }
.msg-reply-name { font-size: 0.8rem; font-weight: 700; color: var(--accent-2); }
.msg.is-out .msg-reply-name { color: #fff; }
.msg-reply-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  opacity: 0.9;
}

.msg-media { margin: 0.1rem 0 0.25rem; }
.msg-media:empty { display: none; }
.media-image { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; }
.media-image img {
  display: block;
  min-width: 8rem;
  min-height: 5rem;
  max-width: 100%;
  max-height: 20rem;
  object-fit: cover;
  border-radius: 0.8rem;
  background: var(--panel-2);
}

.file-card { display: flex; align-items: center; gap: 0.6rem; min-width: 12rem; padding: 0.2rem 0; }
.file-icon {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.msg.is-in .file-icon { background: var(--accent-soft); }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-size { font-size: 0.8rem; opacity: 0.8; }

.voice-card { display: flex; align-items: center; gap: 0.6rem; min-width: 13rem; padding: 0.15rem 0; }
.voice-track {
  flex: 1;
  height: 0.3rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
  cursor: pointer;
}
.msg.is-in .voice-track { background: var(--panel-2); }
.voice-progress { width: 0; height: 100%; border-radius: inherit; background: var(--accent-2); }
.msg.is-out .voice-progress { background: #fff; }
.voice-time { font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.msg.is-out .voice-time { color: rgba(255, 255, 255, 0.85); }
.voice-card .icon-btn-accent { width: 2.4rem; height: 2.4rem; }
.msg.is-out .voice-card .icon-btn-accent { background: rgba(255, 255, 255, 0.25); }

.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.msg-text:empty { display: none; }
.msg-text mark,
.chat-preview mark {
  padding: 0 0.1rem;
  border-radius: 0.2rem;
  background: #facc15;
  color: #1c1936;
}
.msg-text mark.is-current { background: #fb923c; }

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0.05rem;
  font-size: 0.72rem;
  opacity: 0.78;
}
.msg-ticks { color: inherit; }
.msg-ticks.is-read { color: var(--tick-read); opacity: 1; }
.msg-ticks.is-failed { color: var(--danger); }

.msg-reactions { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.msg-reactions:not(:empty) { margin-top: 0.2rem; }
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.reaction-chip.is-mine { background: var(--accent-soft); border-color: var(--accent); }

.typing-dots { display: inline-flex; gap: 0.15rem; vertical-align: middle; margin-left: 0.2rem; }
.typing-dots span {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 50%;
  background: currentColor;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-3px); opacity: 1; } }

.fab {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 2.8rem;
  height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab .badge { position: absolute; top: -0.5rem; right: -0.2rem; }

.drop-overlay {
  position: absolute;
  inset: 0.5rem;
  z-index: 20;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 1.2rem;
  background: var(--accent-soft);
  font-weight: 700;
  pointer-events: none;
}

/* ---------- 15. COMPOSER ---------- */
.composer-wrap { padding: 0.5rem 0.75rem 0.6rem; border-top: 1px solid var(--border); z-index: 3; }
.composer { display: flex; align-items: flex-end; gap: 0.3rem; max-width: 48rem; margin: 0 auto; }
.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 8rem;
  padding: 0.6rem 0.95rem;
  border: 1px solid transparent;
  border-radius: 1.3rem;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.35;
  resize: none;
  transition: border-color 0.2s;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer textarea::placeholder { color: var(--muted); }
.composer .relative { align-self: flex-end; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 48rem;
  margin: 0 auto 0.4rem;
  padding: 0.3rem 0.4rem 0.3rem 0.7rem;
  border-left: 3px solid var(--accent);
  border-radius: 0.6rem;
  background: var(--accent-soft);
  color: var(--accent-2);
}
.reply-bar-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.reply-title { font-size: 0.82rem; font-weight: 700; color: var(--accent-2); }
.reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; color: var(--text); }

.upload-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 48rem;
  margin: 0 auto 0.4rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  color: var(--accent-2);
}
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.record-bar { display: flex; align-items: center; gap: 0.6rem; max-width: 48rem; margin: 0 auto; padding: 0.2rem 0; }
.rec-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: #ef4444; animation: recPulse 1s ease-in-out infinite; }
@keyframes recPulse { 50% { opacity: 0.25; transform: scale(0.8); } }
.record-timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.record-bar .muted { flex: 1; }

/* ---------- 16. CALLS ---------- */
.call-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 30%, #2a1460 0%, #0d0826 70%);
  color: #fff;
}
.call-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.call-stage video { max-width: none; }
#remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.3s;
}
#remote-video.is-live { opacity: 1; }
.call-local {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 3;
  width: 7rem;
  aspect-ratio: 3 / 4;
  height: auto;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 0.9rem;
  background: #111;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
}
.call-local.is-live { opacity: 1; }
.call-local.is-mirrored { transform: scaleX(-1); }

.call-info {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  text-align: center;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.call-info h2 { margin: 0.4rem 0 0; font-size: 1.4rem; }
.call-state { margin: 0; color: rgba(255, 255, 255, 0.8); }
.call-timer { margin: 0; font-size: 1.3rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.call-overlay.has-remote-video .call-info {
  inset: 0 0 auto 0;
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.8rem;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
}
.call-overlay.has-remote-video .call-info .avatar { display: none; }
.call-overlay.has-remote-video .call-info h2 { margin: 0; font-size: 1.05rem; }
.call-overlay.has-remote-video .call-timer { font-size: 1rem; margin-left: auto; margin-right: 8rem; }

.call-error {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  z-index: 4;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: 0;
  padding: 0.55rem 0.9rem;
  border-radius: 0.8rem;
  background: rgba(225, 29, 72, 0.92);
  font-size: 0.9rem;
  text-align: center;
}

.call-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.35);
}
.call-btn {
  display: inline-grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.call-btn .ic { width: 1.55rem; height: 1.55rem; }
.call-btn:hover { background: rgba(255, 255, 255, 0.28); }
.call-btn:active { transform: scale(0.94); }
.call-btn.is-off { background: #fff; color: #1c1936; }
.call-btn-end { background: #ef4444; }
.call-btn-end:hover { background: #dc2626; }
.call-btn-end .ic { transform: rotate(135deg); }
.call-btn-accept { background: #22c55e; }
.call-btn-accept:hover { background: #16a34a; }

.incoming-call {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 2, 20, 0.72);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.incoming-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: min(22rem, 100%);
  padding: 2rem 1.5rem;
  border-radius: 1.6rem;
  text-align: center;
}
.incoming-card h2 { margin: 0.6rem 0 0; font-size: 1.3rem; }
.incoming-card p { margin: 0; }
.incoming-actions { display: flex; gap: 3rem; margin-top: 1.5rem; }
.incoming-actions .call-btn { width: 4rem; height: 4rem; }

/* ---------- 17. SETTINGS SLIDE-OUT ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: rgba(5, 2, 20, 0.55);
  opacity: 0;
  transition: opacity 0.25s;
}
.backdrop.is-open { opacity: 1; }

.settings-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 110;
  display: flex;
  flex-direction: column;
  width: min(26rem, 100%);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--panel-solid);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
}
.settings-panel.is-open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
.settings-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.settings-head h2 { margin: 0; font-size: 1.1rem; }
.settings-body { flex: 1; overflow-y: auto; padding: 0.75rem 1rem 2rem; }

.settings-profile { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; padding: 0.5rem 0 1rem; }
.settings-profile-text { flex: 1; min-width: 8rem; display: flex; flex-direction: column; }
.settings-profile-text strong { font-size: 1.1rem; overflow-wrap: anywhere; }

.settings-section { padding: 0.9rem 0; border-top: 1px solid var(--border); }
.settings-section h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-2);
}
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.4rem 0; }
.setting-col { flex-direction: column; align-items: stretch; }
.settings-section .menu-item { padding-left: 0; padding-right: 0; }

.segmented { display: flex; gap: 0.2rem; padding: 0.2rem; border-radius: 0.85rem; background: var(--input-bg); }
.seg {
  flex: 1;
  padding: 0.45rem 0.4rem;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.seg.is-active,
.seg[aria-checked="true"] { background: var(--accent); color: #fff; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.switch { position: relative; display: inline-block; width: 2.9rem; height: 1.6rem; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(150, 140, 190, 0.4);
  transition: background 0.2s;
}
.slider::before {
  content: '';
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(1.3rem); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: 0.5; }

.proxy-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.5rem 0; }

/* ---------- 18. MODALS ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 115;
  display: grid;
  place-items: center;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
  background: rgba(5, 2, 20, 0.6);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.18s ease-out;
}
.modal-backdrop-dark { background: rgba(0, 0, 0, 0.88); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  display: flex;
  flex-direction: column;
  width: min(30rem, 100%);
  max-height: min(90vh, 90dvh);
  border-radius: 1.3rem;
  overflow: hidden;
  background: var(--panel-solid);
  animation: popIn 0.2s ease-out;
}
.modal-sm { width: min(24rem, 100%); }
.modal-tall { height: min(40rem, 90dvh); }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0.8rem; padding: 1rem; overflow-y: auto; }
.modal-body p { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.8rem 1rem; border-top: 1px solid var(--border); }
.modal-foot:empty { display: none; }
.modal-foot-col { flex-direction: column; }

.group-head-row { display: flex; align-items: center; gap: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.2rem 0.1rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.9rem;
}

.info-top { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; text-align: center; }
.info-title { margin: 0.3rem 0 0; font-family: 'Orbitron', sans-serif; font-size: 1.25rem; overflow-wrap: anywhere; }
.info-bio { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.95rem; }
.info-bio:empty { display: none; }
.rename-row { display: flex; gap: 0.5rem; }
.rename-row input { flex: 1; min-width: 0; }
.section-line { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.section-line .list-heading { margin-left: 0; }
#info-members .user-row,
.modal .user-row { margin-left: 0; margin-right: 0; }

.forward-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent-soft);
  font-size: 0.9rem;
}

.lightbox { position: relative; display: grid; place-items: center; width: 100%; height: 100%; }
.lightbox img { max-width: 96vw; max-height: 88dvh; object-fit: contain; border-radius: 0.5rem; }
.lightbox-actions {
  position: absolute;
  top: calc(0.5rem + env(safe-area-inset-top));
  right: 0.5rem;
  display: flex;
  gap: 0.3rem;
  padding: 0.2rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

/* ---------- 19. TOASTS & CONNECTION BANNER ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: min(26rem, calc(100% - 2rem));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  animation: toastIn 0.25s ease-out;
}
.toast.is-error { border-color: var(--danger); color: var(--danger); }
.toast.is-success { border-color: var(--ok); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.conn-banner {
  position: fixed;
  top: calc(0.6rem + env(safe-area-inset-top));
  left: 50%;
  z-index: 190;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transform: translateX(-50%);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  background: #f59e0b;
  color: #1c1400;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- 20. RESPONSIVE: one pane at a time on mobile ---------- */
@media (max-width: 767.98px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  #chat-screen[data-pane="list"] .main-pane { display: none; }
  #chat-screen[data-pane="chat"] .sidebar { display: none; }
  .sidebar { border-right: 0; }
  .btn-back { display: inline-grid; }
  .msg { max-width: 88%; }
  .settings-panel { width: 100%; border-right: 0; }
  .call-local { width: 5.5rem; }
  .call-overlay.has-remote-video .call-timer { margin-right: 6rem; }
  .proxy-grid { grid-template-columns: 1fr; }
  .modal-tall { height: min(40rem, 92dvh); }
  .composer-wrap { padding-left: 0.4rem; padding-right: 0.4rem; }
  .chat-actions .icon-btn { width: 2.3rem; height: 2.3rem; }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
  .app-shell { grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr); }
}

@media (min-width: 1400px) {
  .app-shell { grid-template-columns: 27rem minmax(0, 1fr); }
}

/* ---------- 21. ACCESSIBILITY ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 22. SIDE MENU (DRAWER), FIELD WARNINGS ---------- */
.drawer-backdrop { z-index: 107; }
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 108;
  display: flex;
  flex-direction: column;
  width: min(20rem, 86vw);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--panel-solid);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
}
.drawer.is-open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
.drawer-profile {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 1.2rem 1rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(160deg, var(--accent-soft), transparent);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.drawer-profile:hover { background: var(--accent-soft); }
.drawer-profile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.drawer-profile-text strong,
.drawer-profile-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-nav { flex: 1; display: flex; flex-direction: column; gap: 0.15rem; padding: 0.5rem; overflow-y: auto; }
.drawer-item {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.75rem 0.85rem;
  border: 0;
  border-radius: 0.8rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.drawer-item:hover { background: var(--accent-soft); }
.drawer-item .ic { color: var(--accent-2); }
.drawer-foot { padding: 0.8rem 1rem; border-top: 1px solid var(--border); text-align: center; }

.field-warn { color: var(--danger); font-size: 0.78rem; font-weight: 600; }
.field input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 107, 129, 0.2);
  animation: shake 0.3s;
}
@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* =====================================================================
   23. UI REFRESH — calm, strict dark-violet minimalism
   (Telegram Desktop layout + macOS dark-mode glass). Uses theme tokens,
   so the Dark and Light themes keep working.
   ===================================================================== */
:root { --r-sm: 10px; --r-md: 14px; --r-lg: 18px; --ease: all 0.2s ease; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', Roboto, sans-serif;
  letter-spacing: -0.005em;
}
html[data-theme="deep-space"] body {
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(91, 33, 182, 0.16), transparent 62%),
    radial-gradient(700px 480px at 100% 110%, rgba(124, 58, 237, 0.10), transparent 60%),
    linear-gradient(160deg, #05010d 0%, #080312 100%) fixed;
}
.font-head, .info-title { font-family: inherit; font-weight: 600; letter-spacing: -0.01em; }
.brand {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 0%, #c4b5fd 100%);
  -webkit-background-clip: text;
  background-clip: text;
}
.brand-sm { font-size: 1.15rem; }

.ic { stroke-width: 1.75; }

/* thin custom scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.26); }
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }

/* ---------- shell: rail | chat list | conversation ---------- */
.app-shell { grid-template-columns: 4.25rem minmax(19rem, 24rem) minmax(0, 1fr); }
@media (min-width: 1400px) { .app-shell { grid-template-columns: 4.25rem 26rem minmax(0, 1fr); } }

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.85rem 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.rail-spacer { flex: 1; }
.rail-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: var(--ease);
}
.rail-btn .ic { width: 1.35rem; height: 1.35rem; }
.rail-btn:hover { background: var(--panel-2); color: var(--text); }
.rail-btn.is-active { background: var(--accent-soft); color: #fff; }
.rail-btn.is-active::before {
  content: '';
  position: absolute;
  left: -0.5rem;
  top: 24%;
  bottom: 24%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.55);
}
.rail-profile { margin-bottom: 0.6rem; }
.rail-profile .avatar { width: 2.5rem; height: 2.5rem; font-size: 0.85rem; box-shadow: 0 0 0 1px var(--border); }
.rail-profile:hover .avatar { box-shadow: 0 0 0 2px var(--accent); }

.sidebar { position: relative; border-right: 1px solid var(--border); }
.sidebar-head { justify-content: flex-start; gap: 0.6rem; padding: 0.9rem 1rem 0.5rem; }
@media (min-width: 768px) { #btn-menu { display: none; } }

/* ---------- search + tabs ---------- */
.search-box {
  margin: 0.25rem 1rem 0.6rem;
  padding: 0.1rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--input-bg);
  transition: var(--ease);
}
.search-box:focus-within { border-color: rgba(168, 85, 247, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { font-size: 0.95rem; }

.chat-tabs { display: flex; gap: 0.1rem; margin: 0 1rem 0.3rem; border-bottom: 1px solid var(--border); }
.sidebar:has(#search-panel:not([hidden])) .chat-tabs { display: none; }
.chat-tab {
  position: relative;
  padding: 0.55rem 0.75rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--ease);
}
.chat-tab:hover { color: var(--text); }
.chat-tab.is-active { color: var(--text); }
.chat-tab.is-active::after {
  content: '';
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---------- chat list ---------- */
.list-scroll { padding-bottom: 5.5rem; }
.chat-item, .user-row {
  margin: 0.1rem 0.5rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  transition: var(--ease);
}
.chat-item:hover, .user-row:hover { background: var(--panel-2); }
.chat-item.is-active, .chat-item.is-active:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.10);
}
.chat-item.is-pinned { background-image: none; }
.chat-name { font-weight: 600; font-size: 0.95rem; }
.chat-preview { font-size: 0.86rem; }
.chat-time { font-size: 0.72rem; }
.badge {
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.38rem;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  font-size: 0.68rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.badge.is-muted { background: rgba(255, 255, 255, 0.16); }

.new-fab-wrap { position: absolute; right: 1.1rem; bottom: 1.1rem; z-index: 6; }
.new-fab {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.38);
  cursor: pointer;
  transition: var(--ease);
}
.new-fab:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(139, 92, 246, 0.5); }
.new-fab:active { transform: translateY(0) scale(0.97); }

/* ---------- conversation ---------- */
.stars-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: var(--star-opacity, 1);
}
.main-pane { background: var(--main-bg); }
.main-pane > .splash, .main-pane > .chat-view { position: relative; z-index: 1; }
.splash-badge { border-radius: var(--r-lg); padding: 1.2rem 1.8rem; font-size: 0.92rem; }

.chat-top { padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
.chat-head-info { border-radius: var(--r-md); transition: var(--ease); }
.chat-title { font-weight: 600; }
.chat-status { font-size: 0.78rem; }
.chat-actions { gap: 0.4rem; }
.chat-actions .icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel-2);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: var(--ease);
}
.chat-actions .icon-btn:hover { background: var(--accent-soft); border-color: rgba(168, 85, 247, 0.3); }
#btn-video-call {
  order: -1;
  border-color: rgba(255, 255, 255, 0.16);
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  box-shadow: 0 4px 18px rgba(124, 58, 237, 0.42);
}
#btn-video-call:hover { background: linear-gradient(135deg, #9b6dff, #7c3aed); box-shadow: 0 6px 24px rgba(139, 92, 246, 0.55); }

.chat-search-bar, .pinned-bar { border-bottom: 1px solid var(--border); }

.date-sep span { padding: 0.18rem 0.75rem; font-size: 0.74rem; font-weight: 500; background: rgba(255, 255, 255, 0.05); border-color: var(--border); }

.bubble {
  padding: 0.45rem 0.8rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-lg);
  background: var(--bubble-in);
  box-shadow: none;
}
.msg.is-in .bubble { border-bottom-left-radius: 6px; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.msg.is-out .bubble { border-color: rgba(255, 255, 255, 0.08); border-bottom-right-radius: 6px; }
.msg-meta { font-size: 0.7rem; }
.msg-reply { border-radius: 8px; }
.reaction-chip { padding: 0.08rem 0.5rem; background: rgba(255, 255, 255, 0.06); transition: var(--ease); }
.reaction-chip:hover { background: var(--accent-soft); }

/* ---------- composer ---------- */
.composer-wrap { padding: 0.65rem 1rem 0.75rem; border-top: 1px solid var(--border); }
.composer { gap: 0.4rem; align-items: flex-end; }
.composer textarea {
  padding: 0.65rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--input-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: var(--ease);
}
.composer textarea:focus { border-color: rgba(168, 85, 247, 0.5); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .icon-btn { transition: var(--ease); }
.icon-btn { transition: var(--ease); }
.icon-btn-accent {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.32);
}
.icon-btn-accent:hover { background: linear-gradient(135deg, #9b6dff, #7c3aed); filter: none; }
#btn-send:disabled { background: var(--panel-2); color: var(--muted); box-shadow: none; opacity: 1; }
.fab { border-radius: 50%; background: var(--panel-solid); transition: var(--ease); }

/* ---------- surfaces: menus, dialogs, panels ---------- */
.popover { border-radius: var(--r-md); padding: 0.3rem; }
.menu-item { border-radius: var(--r-sm); transition: var(--ease); }
.modal { border-radius: 20px; }
.modal-head { padding: 0.9rem 1.1rem; }
.modal-head h2 { font-size: 1rem; }
.settings-panel, .drawer { background: var(--panel-solid); }
.settings-section h3 { font-size: 0.74rem; letter-spacing: 0.08em; }
.seg { border-radius: 10px; transition: var(--ease); }
.btn { border-radius: var(--r-md); transition: var(--ease); }
.btn-primary { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 4px 16px rgba(124, 58, 237, 0.28); }
.auth-card { border-radius: 22px; }
.field input, .field textarea, .field select, .setting-row select { border-radius: var(--r-md); transition: var(--ease); }
.tab { transition: var(--ease); }
.tab.is-active { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.toast { border-radius: var(--r-md); }
.avatar { background: linear-gradient(135deg, #6d28d9, #a855f7); }

/* ---------- phones: one pane, no rail ---------- */
@media (max-width: 767.98px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .composer-wrap { padding: 0.5rem 0.5rem 0.6rem; }
  .chat-actions .icon-btn { width: 2.3rem; height: 2.3rem; }
}
