/* ═══════════════════════════════════════════════════════════════════
   Nexus — единый CSS
   Токены в tokens.css. Здесь только стили компонентов.
   ═══════════════════════════════════════════════════════════════════ */

/* ─── 1. RESET + BASE ─────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(ellipse 800px 600px at 20% 10%, rgba(124, 92, 255, 0.08), transparent 60%),
    radial-gradient(ellipse 800px 600px at 80% 90%, rgba(255, 184, 77, 0.05), transparent 60%);
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  position: relative;
  z-index: 1;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  transition: transform var(--t-fast);
}

button:not(:disabled):active { transform: scale(0.97); }
button:disabled { cursor: not-allowed; opacity: 0.45; }

input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--t-fast);
}
a:hover { color: var(--accent-primary-hover); }

img { display: block; max-width: 100%; }
ul, ol { list-style: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Утилиты */
.hidden { display: none !important; }
.muted { color: var(--text-secondary); }
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Одно-блочные view (auth, invite, 404) — растягиваем на весь #app */
#app > :only-child {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  flex: 1 1 100%;
}

/* ─── 2. КНОПКИ ───────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-base);
  user-select: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(124, 92, 255, 0.25);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.45);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(248, 113, 113, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  box-shadow: 0 6px 20px rgba(248, 113, 113, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ─── 3. ИНПУТЫ ───────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field + .field { margin-top: 18px; }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
.field-label .req { color: var(--accent-secondary); }

.input {
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  transition: all var(--t-base);
  width: 100%;
}
.input:hover { border-color: var(--border-strong); }
.input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-elevated);
}
.input::placeholder { color: var(--text-muted); }

textarea.input {
  resize: vertical;
  min-height: 90px;
  font-family: inherit;
  line-height: 1.5;
}

.input-error {
  color: var(--danger);
  font-size: 12px;
  padding: 10px 14px;
  background: var(--danger-bg);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--danger);
}

/* Select */
select.input {
  background: var(--bg-raised);
  padding: 10px 36px 10px 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a8adc9' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select.input option {
  background: var(--bg-raised);
  color: var(--text-primary);
}

/* Range */
input[type="range"] {
  height: 6px;
  background: var(--bg-raised);
  border-radius: var(--r-pill);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gradient-accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.2);
  transition: all var(--t-fast);
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(124, 92, 255, 0.3);
  transform: scale(1.1);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--gradient-accent);
  cursor: pointer;
}

/* Checkbox */
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}
input[type="checkbox"]:checked::after {
  content: "✓";
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* ─── 4. AVATAR ───────────────────────────────────────────────────── */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  object-fit: cover;
  background: var(--gradient-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color var(--t-fast);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ─── 5. ICON BUTTON ──────────────────────────────────────────────── */

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: 18px;
  transition: all var(--t-base);
  border: 1px solid transparent;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.icon-btn.active {
  color: var(--accent-secondary);
  background: rgba(255, 184, 77, 0.1);
  border-color: rgba(255, 184, 77, 0.3);
}
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover {
  background: var(--danger-bg);
  border-color: rgba(248, 113, 113, 0.3);
}

/* ─── 6. SPINNER ──────────────────────────────────────────────────── */

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-top-color: var(--accent-primary);
  border-right-color: var(--accent-secondary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 7. MODAL ────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 12, 0.7);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn var(--t-base);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn var(--t-spring);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(24px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  padding: 24px 24px 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
}
.modal-sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}
.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-tertiary);
  font-size: 22px;
  line-height: 1;
  transition: all var(--t-fast);
}
.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
  transform: rotate(90deg);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-actions {
  padding: 16px 24px 24px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.15);
}
.modal-actions .btn { min-width: 100px; }

/* ─── 8. TOAST ────────────────────────────────────────────────────── */

#toast-root {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  max-width: 90vw;
  animation: toastIn var(--t-spring);
  pointer-events: auto;
  border: 1px solid var(--glass-border);
  border-left: 4px solid var(--accent-primary);
  font-weight: 500;
}
.toast.success { border-left-color: var(--success); box-shadow: var(--shadow-md), 0 0 20px rgba(74, 222, 128, 0.15); }
.toast.error { border-left-color: var(--danger); box-shadow: var(--shadow-md), 0 0 20px rgba(248, 113, 113, 0.15); }
.toast.warn { border-left-color: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-16px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.leaving { animation: toastOut var(--t-base) forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-16px) scale(0.9); }
}

/* ─── 9. RAIL ─────────────────────────────────────────────────────── */

.rail {
  width: var(--rail-width);
  background: var(--bg-deep);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 10px;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 3;
}
.rail::-webkit-scrollbar { width: 0; }

.rail-item {
  width: 52px;
  height: 52px;
  border-radius: var(--r-lg);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--t-base);
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.rail-item img { width: 100%; height: 100%; object-fit: cover; }

.rail-item:hover {
  background: var(--bg-raised);
  transform: translateY(-2px);
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}
.rail-item.active {
  background: var(--gradient-accent);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-glow);
}

.rail-item::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 4px;
  height: 32px;
  background: var(--accent-secondary);
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  transition: transform var(--t-spring);
  transform-origin: left center;
  box-shadow: 0 0 12px var(--accent-secondary);
}
.rail-item:hover::before { transform: translateY(-50%) scaleY(0.5); }
.rail-item.active::before { transform: translateY(-50%) scaleY(1); }

.rail-item.rail-dm { font-size: 20px; }
.rail-item.rail-add {
  color: var(--success);
  font-size: 26px;
  font-weight: 300;
}
.rail-item.rail-add:hover {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}
.rail-item.rail-explore { font-size: 18px; }

.rail-sep {
  width: 32px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-default), transparent);
  margin: 6px 0;
}

/* ─── 10. SIDEBAR ─────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--glass-border);
  position: relative;
  z-index: 2;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
  position: relative;
}
.sidebar-header::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 18px;
  right: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
  opacity: 0;
  transition: opacity var(--t-base);
}
.sidebar-header:hover { background: rgba(255, 255, 255, 0.03); }
.sidebar-header:hover::after { opacity: 0.6; }

.server-name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.header-action {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
}
.header-action:hover {
  color: var(--text-primary);
  background: var(--bg-raised);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

/* ─── 11. КАНАЛЫ ──────────────────────────────────────────────────── */

.channels-group { margin-bottom: 20px; }

.channels-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 10px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.channels-group-title button {
  color: var(--text-tertiary);
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.channels-group-title button:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.channel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-fast);
  font-size: 14px;
  margin-bottom: 2px;
  position: relative;
}
.channel::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 60%;
  background: var(--accent-primary);
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  transition: transform var(--t-base);
  box-shadow: 0 0 8px var(--accent-primary);
}
.channel:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}
.channel.active {
  background: var(--gradient-glass);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.channel.active::before { transform: translateY(-50%) scaleY(1); }

.channel .icon {
  color: var(--text-tertiary);
  font-size: 18px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  transition: color var(--t-fast);
}
.channel.active .icon,
.channel:hover .icon { color: var(--accent-secondary); }

.channel .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-action {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  border-radius: var(--r-sm);
  opacity: 0;
  transition: opacity 0.15s;
}
.channel:hover .channel-action { opacity: 1; }
.channel-action:hover {
  color: var(--danger);
  background: var(--bg-raised);
}

.empty-mini {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ─── 12. VOICE USERS ПОД КАНАЛОМ ─────────────────────────────────── */

.channel-voice-users {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 4px 0;
  padding-left: 22px;
}
.channel-voice-users:empty { display: none; }

.channel-voice-user {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.12s ease;
  font-size: 13px;
  color: var(--text-secondary);
}
.channel-voice-user:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}
.channel-voice-user.speaking {
  background: rgba(124, 92, 255, 0.12);
  color: var(--text-primary);
}
.channel-voice-user.speaking .avatar {
  box-shadow: 0 0 0 2px var(--accent-primary);
}
.channel-voice-user .avatar { flex-shrink: 0; }

.channel-voice-user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-voice-user-mute {
  font-size: 11px;
  opacity: 0.7;
}

/* ─── 13. DM ДИАЛОГИ В SIDEBAR ────────────────────────────────────── */

.dm-dialog {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}
.dm-avatar { flex-shrink: 0; }
.dm-meta { min-width: 0; flex: 1; }
.dm-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-preview {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── 14. MAIN ────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  min-width: 0;
  position: relative;
}

#main-slot {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.main-header {
  height: var(--header-height);
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 2;
  background: rgba(16, 18, 30, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.main-header .icon {
  color: var(--accent-secondary);
  font-size: 20px;
}
.main-header .title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.main-header .actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.main-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ─── 15. CHAT ────────────────────────────────────────────────────── */

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.chat-message {
  display: flex;
  gap: 14px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  position: relative;
  transition: background var(--t-fast);
  animation: msgIn var(--t-base) backwards;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-message:hover { background: rgba(255, 255, 255, 0.03); }

.chat-message-author {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.chat-message-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.chat-message-username {
  color: var(--text-muted);
  font-size: 12px;
}
.chat-message-time {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: auto;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.chat-message:hover .chat-message-time { opacity: 1; }

.chat-message-body { flex: 1; min-width: 0; }
.chat-message-content {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}

.chat-composer {
  padding: 0 24px 20px;
  flex-shrink: 0;
}
.chat-composer-inner {
  background: var(--bg-raised);
  border-radius: var(--r-lg);
  padding: 12px 18px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  border: 1px solid var(--border-subtle);
  transition: all var(--t-base);
}
.chat-composer-inner:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  line-height: 24px;
  color: var(--text-primary);
  font-size: 14px;
}
.chat-composer textarea::placeholder { color: var(--text-muted); }
.chat-composer button {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  font-size: 18px;
  transition: all var(--t-fast);
}
.chat-composer button:hover:not(:disabled) {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 0 16px var(--accent-glow);
}
.chat-composer button:disabled { color: var(--text-muted); }

.typing-indicator {
  height: 22px;
  padding: 0 24px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
}

/* ─── 16. VOICE VIEW (в main) — карточки как в Discord ────────────── */

.voice-view {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.voice-view-grid {
  display: grid;
  gap: 16px;
  align-content: center;
  justify-content: center;
  justify-items: center;
  transition: grid-template-columns var(--t-base);
}

/* ─── Сетка по количеству участников ──────────────────────────────── */
/* Используем ФИКСИРОВАННЫЕ размеры колонок — так grid точно их соблюдает */

/* 1 участник — одно большое по центру */
.voice-view-grid[data-count="1"] {
  grid-template-columns: 420px;
}

/* 2 участника — две колонки */
.voice-view-grid[data-count="2"] {
  grid-template-columns: repeat(2, 320px);
}

/* 3-4 — две колонки */
.voice-view-grid[data-count="3"],
.voice-view-grid[data-count="4"] {
  grid-template-columns: repeat(2, 280px);
}

/* 5-6 — три колонки */
.voice-view-grid[data-count="5"],
.voice-view-grid[data-count="6"] {
  grid-template-columns: repeat(3, 240px);
}

/* 7-9 — три колонки компактнее */
.voice-view-grid[data-count="7"],
.voice-view-grid[data-count="8"],
.voice-view-grid[data-count="9"] {
  grid-template-columns: repeat(3, 200px);
}

/* 10-12 — четыре колонки */
.voice-view-grid[data-count="10"],
.voice-view-grid[data-count="11"],
.voice-view-grid[data-count="12"] {
  grid-template-columns: repeat(4, 180px);
}

/* 13+ — четыре колонки ещё плотнее */
.voice-view-grid[data-count="13"],
.voice-view-grid[data-count="14"],
.voice-view-grid[data-count="15"],
.voice-view-grid[data-count="16"] {
  grid-template-columns: repeat(4, 160px);
}

/* ─── Карточка участника ──────────────────────────────────────────── */

.voice-card {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-xl);
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--t-base);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: voiceCardIn var(--t-spring);
}

@keyframes voiceCardIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.voice-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Свечение для говорящего */
.voice-card.speaking {
  border-color: var(--success);
  box-shadow:
    0 0 0 3px rgba(74, 222, 128, 0.25),
    0 0 32px rgba(74, 222, 128, 0.35),
    var(--shadow-md);
}

.voice-card.speaking::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgba(74, 222, 128, 0.18),
    transparent 70%
  );
  pointer-events: none;
  animation: speakPulseCard 1.6s ease-in-out infinite;
}

@keyframes speakPulseCard {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.voice-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  position: relative;
  z-index: 1;
  max-width: 100%;
}

/* ─── Размер аватара зависит от размера сетки ─────────────────────── */

.voice-card-avatar .avatar {
  width: 128px;
  height: 128px;
  font-size: 42px;
  transition: all var(--t-base);
}

.voice-view-grid[data-count="2"] .voice-card-avatar .avatar { width: 112px; height: 112px; font-size: 38px; }
.voice-view-grid[data-count="3"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="4"] .voice-card-avatar .avatar { width: 88px; height: 88px; font-size: 30px; }
.voice-view-grid[data-count="5"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="6"] .voice-card-avatar .avatar { width: 72px; height: 72px; font-size: 24px; }
.voice-view-grid[data-count="7"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="8"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="9"] .voice-card-avatar .avatar { width: 60px; height: 60px; font-size: 20px; }
.voice-view-grid[data-count="10"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="11"] .voice-card-avatar .avatar,
.voice-view-grid[data-count="12"] .voice-card-avatar .avatar { width: 52px; height: 52px; font-size: 18px; }

.voice-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.voice-view-grid[data-count="5"] .voice-card-name,
.voice-view-grid[data-count="6"] .voice-card-name { font-size: 13px; }
.voice-view-grid[data-count="7"] .voice-card-name,
.voice-view-grid[data-count="8"] .voice-card-name,
.voice-view-grid[data-count="9"] .voice-card-name { font-size: 12px; }
.voice-view-grid[data-count="10"] .voice-card-name,
.voice-view-grid[data-count="11"] .voice-card-name,
.voice-view-grid[data-count="12"] .voice-card-name { font-size: 11px; }

.voice-card-mute {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(248, 113, 113, 0.5);
}

/* ─── Пусто ───────────────────────────────────────────────────────── */

.voice-view-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.voice-view-empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.voice-view-empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.voice-view-empty-sub {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ─── Мобилка ─────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .voice-view { padding: 16px; }

  .voice-view-grid[data-count="1"],
  .voice-view-grid[data-count="2"],
  .voice-view-grid[data-count="3"],
  .voice-view-grid[data-count="4"],
  .voice-view-grid[data-count="5"],
  .voice-view-grid[data-count="6"],
  .voice-view-grid[data-count="7"],
  .voice-view-grid[data-count="8"],
  .voice-view-grid[data-count="9"],
  .voice-view-grid[data-count="10"],
  .voice-view-grid[data-count="11"],
  .voice-view-grid[data-count="12"] {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .voice-card-avatar .avatar {
    width: 72px !important;
    height: 72px !important;
    font-size: 24px !important;
  }
}

/* ─── 17. VOICE SIDEBAR PANEL ─────────────────────────────────────── */

.voice-sidebar-panel {
  margin: 8px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.06), rgba(124, 92, 255, 0.06));
  border: 1px solid rgba(74, 222, 128, 0.2);
  border-radius: var(--r-lg);
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.08);
  animation: voicePanelIn var(--t-slow);
}
@keyframes voicePanelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.voice-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.voice-sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
  text-shadow: 0 0 8px var(--success-glow);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-sidebar-ping {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.3);
}
.voice-sidebar-quality {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.voice-sidebar-quality.good { color: var(--success); }
.voice-sidebar-quality.ok   { color: #a3e635; }
.voice-sidebar-quality.warn { color: var(--warning); }
.voice-sidebar-quality.bad  { color: var(--danger); }

.voice-sidebar-actions {
  display: flex;
  gap: 4px;
  justify-content: space-between;
}
.voice-sidebar-actions .icon-btn {
  flex: 1;
  height: 36px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--r-md);
}

/* ─── 18. USER PANEL (низ sidebar) ────────────────────────────────── */

.user-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.user-panel-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast);
}
.user-panel-info:hover { background: rgba(255, 255, 255, 0.04); }

.user-panel-avatar-wrap { position: relative; flex-shrink: 0; }
.user-panel-status {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-elevated);
  background: var(--text-tertiary);
}
.user-panel-status.online { background: var(--success); box-shadow: 0 0 8px var(--success-glow); }

.user-panel-meta { flex: 1; min-width: 0; }
.user-panel-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.user-panel-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.user-panel-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.user-panel-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-tertiary);
  font-size: 15px;
  transition: all var(--t-fast);
  border: 1px solid transparent;
}
.user-panel-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}
.user-panel-btn.muted {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: rgba(248, 113, 113, 0.3);
}
.user-panel-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ─── 19. WELCOME ─────────────────────────────────────────────────── */

.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
}
.welcome-inner { max-width: 520px; text-align: center; }
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.welcome-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.welcome-sub {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}
.welcome-quote {
  background: rgba(124, 92, 255, 0.06);
  border-left: 3px solid var(--accent-primary);
  padding: 16px 20px;
  border-radius: var(--r-md);
  text-align: left;
  margin-bottom: 24px;
}
.welcome-quote-text {
  font-style: italic;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
}
.welcome-quote-author {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent-secondary);
}
.welcome-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── 20. HOME / EXPLORE ──────────────────────────────────────────── */

.home {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  min-height: 0;
}
.home-section {
  margin-bottom: 40px;
  animation: sectionIn var(--t-slow) backwards;
}
.home-section:nth-child(1) { animation-delay: 0ms; }
.home-section:nth-child(2) { animation-delay: 80ms; }

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

.home-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.home-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border-default), transparent);
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.room-card {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--t-base);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}
.room-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md), 0 0 24px rgba(124, 92, 255, 0.12);
}

.room-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.room-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.room-card-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-card-name {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-card-meta {
  display: flex;
  gap: 14px;
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 6px;
}
.room-card-meta span {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ─── 21. PROFILE ─────────────────────────────────────────────────── */

.profile-head {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px;
  background: var(--gradient-glass);
  border-radius: var(--r-lg);
  margin-bottom: 20px;
  border: 1px solid var(--border-default);
  position: relative;
  overflow: hidden;
}
.profile-head::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -20%;
  width: 60%;
  height: 200%;
  background: radial-gradient(ellipse, var(--accent-glow), transparent 70%);
  pointer-events: none;
}
.profile-head .avatar {
  width: 80px;
  height: 80px;
  font-size: 32px;
  position: relative;
  z-index: 1;
}
.profile-info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.profile-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 3px;
  color: var(--text-primary);
}
.profile-username { color: var(--text-secondary); font-size: 14px; }
.profile-bio {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 14px;
  white-space: pre-wrap;
  line-height: 1.6;
}
.profile-meta {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 14px;
  display: flex;
  gap: 20px;
}

/* ─── 22. AUTH ────────────────────────────────────────────────────── */

.auth {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  padding: 20px;
  overflow-y: auto;
  position: relative;
}
.auth::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 30% 20%, rgba(124, 92, 255, 0.15), transparent 60%),
    radial-gradient(ellipse 600px 400px at 70% 80%, rgba(255, 184, 77, 0.08), transparent 60%);
  pointer-events: none;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--r-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--glass-border);
  position: relative;
  z-index: 1;
  animation: cardIn var(--t-spring);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-sub {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-footer {
  margin-top: 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ─── 23. EMPTY STATE ─────────────────────────────────────────────── */

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  padding: 40px;
  text-align: center;
}
.empty-icon {
  font-size: 72px;
  margin-bottom: 20px;
  opacity: 0.4;
  filter: grayscale(0.5);
}
.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* ─── 24. INVITE PAGE ─────────────────────────────────────────────── */

.invite-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-deep);
  position: relative;
}
.invite-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 30% 20%, rgba(124, 92, 255, 0.12), transparent 60%),
    radial-gradient(ellipse 600px 400px at 70% 80%, rgba(255, 184, 77, 0.06), transparent 60%);
  pointer-events: none;
}

.invite-card {
  width: 100%;
  max-width: 420px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
  animation: cardIn var(--t-spring);
}
.invite-loading {
  text-align: center;
  color: var(--text-tertiary);
  padding: 20px;
}
.invite-label {
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: 20px;
}
.invite-server {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.invite-server-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--r-md);
  background: var(--gradient-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.invite-server-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.invite-server-meta { flex: 1; min-width: 0; }
.invite-server-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-server-stats {
  font-size: 13px;
  color: var(--text-secondary);
}
.invite-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.invite-error-icon {
  font-size: 42px;
  text-align: center;
  margin-bottom: 12px;
}
.invite-error-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 8px;
}
.invite-error-text {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
}
.invite-error-actions {
  display: flex;
  justify-content: center;
}

/* ─── 25. INVITE MODAL ────────────────────────────────────────────── */

.invite-modal {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.invite-modal-hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.invite-modal-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.invite-modal-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
}
.invite-modal-actions {
  display: flex;
  justify-content: flex-end;
}

/* ─── 26. USER POPOVER ────────────────────────────────────────────── */

#popover-root {
  position: relative;
  z-index: 1200;
}

.user-popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 1200;
}
.user-popover-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.user-popover {
  position: fixed;
  z-index: 1201;
  width: 260px;
  max-width: calc(100vw - 24px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 14px;
  color: var(--text-primary);
  animation: userPopoverIn 0.14s ease-out;
}
@keyframes userPopoverIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.user-popover.mobile {
  top: auto !important;
  left: 12px !important;
  right: 12px;
  bottom: 12px;
  width: auto;
  transform: none !important;
  animation: userPopoverSlideUp 0.2s ease-out;
}
@keyframes userPopoverSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-popover-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.user-popover-avatar { position: relative; flex-shrink: 0; }
.user-popover-status {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg-elevated);
}
.user-popover-status.online { background: var(--success); }
.user-popover-status.muted { background: var(--danger); }

.user-popover-meta { flex: 1; min-width: 0; }
.user-popover-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-popover-username {
  font-size: 12px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-popover-close {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: background 0.12s ease, color 0.12s ease;
}
.user-popover-close:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}
.user-popover-note {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 10px;
  text-align: center;
}
.user-popover-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-popover-voice {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-popover-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.user-popover-label {
  font-size: 12px;
  color: var(--text-secondary);
}
.user-popover-vol-value {
  color: var(--accent-secondary);
  font-variant-numeric: tabular-nums;
}
.user-popover-slider {
  width: 100%;
  accent-color: var(--accent-primary);
}
.user-popover-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ─── 27. SETTINGS MODAL ──────────────────────────────────────────── */

.settings-modal-body {
  display: flex;
  min-height: 400px;
}
.settings-tabs {
  width: 160px;
  border-right: 1px solid var(--border-subtle);
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-tab {
  background: none;
  border: none;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.settings-tab:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}
.settings-tab.active {
  background: rgba(124, 92, 255, 0.15);
  color: var(--accent-secondary);
}
.settings-pane {
  flex: 1;
  padding: 0 0 0 20px;
  min-width: 0;
}

/* ─── 28. BURGER / MOBILE DRAWER ──────────────────────────────────── */

.burger {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-secondary);
  border-radius: var(--r-md);
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.burger:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  animation: fadeIn var(--t-base);
}
.backdrop.visible { display: block; }

@media (max-width: 768px) {
  .burger { display: flex; }

  /* rail — самый нижний слой, выезжает слева */
  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--rail-width);
    z-index: 95;
    transform: translateX(-100%);
    transition: transform var(--t-base);
    box-shadow: var(--shadow-lg);
    will-change: transform;
  }
  .rail.open { transform: translateX(0); }

  /* sidebar — второй слой, выезжает поверх rail с отступом на ширину rail */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 82vw;
    max-width: 320px;
    padding-left: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--t-base);
    box-shadow: var(--shadow-lg);
    will-change: transform;
  }
  .sidebar.open { transform: translateX(0); }

  /* когда sidebar открыт — rail сдвигается вправо (виден слева от sidebar) */
  .rail.open ~ .sidebar.open {
    transform: translateX(0);
  }

  /* На мобилке sidebar прижат к левому краю, rail под ним виден сквозь padding */
  .sidebar {
    padding-left: var(--rail-width);
  }

  /* main остаётся под всеми слоями */
  .main { width: 100%; }

  .main-header { padding: 0 12px; }
  .home { padding: 20px 16px; }
  .home-grid { grid-template-columns: 1fr; }
  .chat-messages { padding: 16px; }
  .chat-composer {
    padding: 0 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .voice-panel { padding: 0 12px; gap: 10px; }

  .settings-modal-body { flex-direction: column; min-height: 0; }
  .settings-tabs {
    width: 100%;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 0 8px;
    overflow-x: auto;
  }
  .settings-tab { white-space: nowrap; }
  .settings-pane { padding: 16px 0 0; }
}

/* ─── 29. НАСТРОЙКИ: превью аватара / иконки ──────────────────────── */

.modal-lg {
  max-width: 720px;
}

.settings-avatar-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  padding: 16px;
  background: var(--bg-raised);
  border-radius: var(--r-lg);
  border: 1px solid var(--border-default);
  margin-bottom: 20px;
}

.settings-avatar-preview {
  flex-shrink: 0;
}

.settings-avatar-preview .avatar {
  width: 96px;
  height: 96px;
  font-size: 32px;
}

.avatar-square {
  border-radius: var(--r-lg) !important;
}

.settings-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.settings-avatar-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

/* Настройки — чуть больше места в табах */
.settings-tabs {
  width: 180px;
}

.settings-pane {
  padding-left: 24px;
}

/* Мобилка — колонки в обратную сторону */
@media (max-width: 768px) {
  .settings-avatar-row {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .settings-avatar-actions {
    align-items: stretch;
    width: 100%;
  }
}

/* ─── 30. БАННЕРЫ ─────────────────────────────────────────────────── */

/* Настройки: блок баннера */
.settings-banner-block {
  margin-bottom: 20px;
}

.settings-banner-preview {
  width: 100%;
  height: 140px;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  margin-bottom: 10px;
  position: relative;
}

.settings-banner-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.settings-banner-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-tertiary);
  font-size: 13px;
}

.settings-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Профиль: баннер над шапкой */
.profile-banner {
  width: 100%;
  height: 160px;
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: -60px;
  position: relative;
  z-index: 0;
}

.profile-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-head {
  position: relative;
  z-index: 1;
}

/* Popover: баннер сверху */
.user-popover-banner {
  width: calc(100% + 28px);
  margin: -14px -14px 10px -14px;
  height: 76px;
  overflow: hidden;
  border-radius: var(--r-md) var(--r-md) 0 0;
  background: var(--bg-raised);
}

.user-popover-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Sidebar сервера: баннер за шапкой */
.sidebar-header.with-banner {
  background-size: cover;
  background-position: center;
  position: relative;
}

.sidebar-header.with-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.35) 0%,
    rgba(0, 0, 0, 0.65) 100%
  );
  pointer-events: none;
}

.sidebar-header.with-banner > * {
  position: relative;
  z-index: 1;
}

/* ─── 31. ВЛОЖЕНИЯ: composer ──────────────────────────────────────── */

.chat-composer {
  padding: 0 24px 20px;
  flex-shrink: 0;
  position: relative;
}

.chat-composer.drag-over .chat-composer-inner {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(124, 92, 255, 0.06);
}

.attachments-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg-raised);
  border-radius: var(--r-md);
  border: 1px solid var(--border-default);
  animation: attPreviewIn var(--t-base);
}
.attachments-preview.visible { display: flex; }

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

.att-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.att-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.att-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.att-item:hover .att-remove { opacity: 1; }
.att-remove:hover { background: var(--danger); }

.att-progress {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.att-error {
  position: absolute;
  inset: 0;
  background: rgba(248, 113, 113, 0.35);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.composer-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 18px;
  flex-shrink: 0;
  transition: all var(--t-fast);
}
.composer-attach-btn:hover {
  color: var(--accent-primary);
  background: rgba(124, 92, 255, 0.1);
}

/* ─── 32. ВЛОЖЕНИЯ в сообщении ────────────────────────────────────── */

.msg-attachments {
  margin-top: 6px;
  display: grid;
  gap: 4px;
  max-width: 460px;
}

/* 1 фото — крупно */
.msg-attachments.n-1 {
  grid-template-columns: 1fr;
}
.msg-attachments.n-1 .msg-attachment {
  max-width: 400px;
  max-height: 400px;
}

/* 2 фото — рядом */
.msg-attachments.n-2 {
  grid-template-columns: 1fr 1fr;
  max-width: 400px;
}

/* 3-4 фото — плиткой */
.msg-attachments.n-3 {
  grid-template-columns: 1fr 1fr;
  max-width: 400px;
}

/* много — 3 колонки */
.msg-attachments.n-many {
  grid-template-columns: repeat(3, 1fr);
  max-width: 480px;
}

.msg-attachment {
  display: block;
  overflow: hidden;
  border-radius: var(--r-md);
  background: var(--bg-raised);
  aspect-ratio: 1 / 1;
  transition: transform var(--t-fast);
  position: relative;
}

.msg-attachments.n-1 .msg-attachment {
  aspect-ratio: auto;
}

.msg-attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-attachment:hover {
  transform: scale(1.01);
}

.msg-attachments.n-1 .msg-attachment:hover {
  transform: scale(1.005);
}

/* ─── 33. Мобилка: welcome screen с burger ────────────────────────── */

@media (max-width: 768px) {
  .welcome-screen {
    position: relative;
    padding: 64px 24px 24px;
    align-items: flex-start;
  }

  .welcome-screen .burger {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 10;
  }

  /* На мобилке welcome padding-top больше, чтобы burger не наезжал */
  .welcome-inner {
    margin-top: 32px;
  }
}

/* ─── 34. Profile: центр контента ─────────────────────────────────── */

.main-body .home {
  padding: 32px 24px;
}

@media (max-width: 768px) {
  .main-body .home {
    padding: 20px 16px;
  }
}

/* ─── 35. INVITE WIDGET ──────────────────────────────────────────── */

.invite-widget {
  margin-top: 6px;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  overflow: hidden;
  animation: inviteWidgetIn var(--t-base);
}

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

.invite-widget-banner {
  width: 100%;
  height: 100px;
  overflow: hidden;
  background: var(--bg-raised);
}
.invite-widget-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.invite-widget-body {
  padding: 16px;
}

.invite-widget-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.invite-widget-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.invite-widget-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.invite-widget-meta {
  flex: 1;
  min-width: 0;
}
.invite-widget-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-widget-stats {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.invite-widget-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.invite-widget-loading {
  padding: 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

.invite-widget-error {
  padding: 16px;
  text-align: center;
  color: var(--danger);
  font-size: 13px;
}

.invite-widget-join {
  margin-top: 4px;
}