:root {
  --bg-rail: #1e1f22;
  --bg-sidebar: #2b2d31;
  --bg-profile: #232428;
  --bg-chat: #313338;
  --bg-composer: #383a40;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-input: #1e1f22;
  --border-hairline: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --green-hover: #1a8647;
  --danger: #da373c;
  --danger-soft: rgba(218, 55, 60, 0.16);
  --amber: #f0b232;
  --amber-soft: rgba(240, 178, 50, 0.16);
  --emerald-soft: rgba(35, 165, 90, 0.16);
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg-chat);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

button,
input {
  font-family: inherit;
}

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

/* ==================== Авторизация ==================== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background-color: var(--bg-rail);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.auth-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.auth-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background-color: var(--bg-input);
  border-radius: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  min-height: 38px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, color 140ms ease;
}

.auth-tab.is-active {
  background-color: var(--bg-active);
  color: var(--text-primary);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-input {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
}

.field-input:focus {
  border-color: var(--accent);
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background-color: var(--danger-soft);
  color: #fca5a5;
  font-size: 13px;
}

.btn-primary {
  min-height: 42px;
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  background-color: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
}

.auth-hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ==================== Discord 4-зонный макет ==================== */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-chat);
}

.left-navigation {
  display: flex;
  flex-shrink: 0;
  height: 100%;
  z-index: 30;
}

/* 1. Крайняя левая панель групп (Server Rail ~72px) */
.group-rail {
  width: 72px;
  background-color: var(--bg-rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  flex-shrink: 0;
}

.group-rail::-webkit-scrollbar {
  display: none;
}

.group-rail-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.rail-item-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-pill {
  position: absolute;
  left: 0;
  width: 4px;
  height: 0;
  border-radius: 0 4px 4px 0;
  background-color: #ffffff;
  transition: height 160ms ease, opacity 160ms ease;
  opacity: 0;
}

.rail-item-wrap:hover .rail-pill {
  height: 20px;
  opacity: 1;
}

.rail-item-wrap.is-active .rail-pill {
  height: 40px;
  opacity: 1;
}

.rail-icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: var(--bg-chat);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-radius 180ms ease, background-color 180ms ease, color 180ms ease, transform 120ms ease;
}

.rail-item-wrap:hover .rail-icon-btn,
.rail-item-wrap.is-active .rail-icon-btn {
  border-radius: 16px;
  background-color: var(--accent);
  color: #ffffff;
}

.rail-icon-btn:active {
  transform: translateY(1px);
}

.rail-dm-btn {
  color: var(--text-secondary);
}

.rail-item-wrap:hover .rail-dm-btn,
.rail-item-wrap.is-active .rail-dm-btn {
  background-color: var(--accent);
  color: #ffffff;
}

.rail-dm-icon {
  display: block;
}

.rail-unread-badge {
  position: absolute;
  right: 8px;
  bottom: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background-color: #f23f43;
  color: #ffffff;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 3px var(--bg-rail);
  pointer-events: none;
}

.rail-divider {
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background-color: rgba(255, 255, 255, 0.08);
  margin: 2px 0;
  flex-shrink: 0;
}

.rail-add-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: var(--bg-chat);
  color: var(--green);
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-radius 180ms ease, background-color 180ms ease, color 180ms ease;
}

.rail-add-btn:hover {
  border-radius: 16px;
  background-color: var(--green);
  color: #ffffff;
}

/* 2. Вторая панель слева (Каналы ~240px) */
.channel-sidebar {
  width: 240px;
  background-color: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  height: 100%;
  border-right: 1px solid var(--border-hairline);
}

.channel-sidebar-header {
  height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.active-group-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 8px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 6px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.btn-add-channel {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-add-channel:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.channels-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.channel-btn {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.channel-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-secondary);
}

.channel-btn.is-active {
  background-color: var(--bg-active);
  color: var(--text-primary);
  font-weight: 600;
}

.channel-btn-hash {
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 500;
  line-height: 1;
}

.channel-btn.is-active .channel-btn-hash {
  color: var(--text-secondary);
}

.channel-btn-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Список диалогов ЛС во второй колонке */
.dm-conversations-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dm-conv-btn {
  width: 100%;
  min-height: 46px;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background-color 120ms ease, color 120ms ease;
}

.dm-conv-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.dm-conv-btn.is-active {
  background-color: var(--bg-active);
  color: var(--text-primary);
}

.dm-conv-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.dm-conv-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-conv-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background-color: #f23f43;
  color: #ffffff;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  flex-shrink: 0;
}

.dm-empty-hint {
  padding: 12px 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Нижняя панель профиля */
.user-panel {
  height: 56px;
  padding: 0 8px;
  background-color: var(--bg-profile);
  border-top: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.user-panel-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-panel-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.user-panel-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-panel-role {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-sound {
  min-width: 28px;
  min-height: 28px;
  padding: 3px 4px;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 120ms ease, color 120ms ease;
}

.btn-sound:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sound.is-muted {
  color: var(--text-muted);
  opacity: 0.78;
}

.btn-ghost {
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-ghost:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

/* Аватарки и статусные кружки */
.avatar-status-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.avatar-box {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
  user-select: none;
}

.avatar-box--sm {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.avatar-box--xs {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.avatar-box--lg {
  width: 68px;
  height: 68px;
  font-size: 24px;
}

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

.status-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2.5px solid var(--bg-profile);
  background-color: #80848e;
  box-sizing: border-box;
  pointer-events: none;
}

.members-sidebar .status-dot {
  border-color: var(--bg-sidebar);
}

.chat-header .status-dot {
  border-color: var(--bg-chat);
}

.status-dot--xs {
  width: 10px;
  height: 10px;
  border-width: 2px;
}

.status-dot--lg {
  width: 18px;
  height: 18px;
  right: 0;
  bottom: 0;
  border-width: 3px;
  border-color: var(--bg-sidebar);
}

.status-dot--online {
  background-color: #23a55a;
}

.status-dot--dnd {
  background-color: #f23f43;
}

.status-dot--invisible,
.status-dot--offline {
  background-color: #80848e;
}

/* 3. Центральная область чата */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-chat);
}

.chat-header {
  height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  background-color: var(--bg-chat);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.channel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dm-header-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.dm-header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dm-header-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.channel-hash {
  font-size: 20px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1;
}

.channel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

.meta-sep {
  color: var(--text-muted);
}

.channel-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.connection-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.connection-label.is-offline {
  color: #fca5a5;
}

.btn-members-toggle {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  background-color: var(--bg-sidebar);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Лента сообщений */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 36px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.empty-state {
  padding: 36px 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.empty-state strong {
  display: block;
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.message-row {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background-color 240ms ease, box-shadow 240ms ease, border-color 240ms ease;
}

.message-row:hover {
  background-color: rgba(0, 0, 0, 0.14);
}

.message-row.message-row--mentioned {
  background-color: rgba(240, 178, 50, 0.12);
  border-color: rgba(240, 178, 50, 0.32);
  box-shadow: inset 3px 0 0 var(--amber);
}

.message-row.message-row--mentioned:hover {
  background-color: rgba(240, 178, 50, 0.18);
}

.message-row.is-highlighted {
  background-color: rgba(88, 101, 242, 0.22);
  box-shadow: inset 3px 0 0 var(--accent);
}

.message-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

/* Блок цитаты (Reply) в стиле Discord с изогнутой линией-связкой */
.message-reply {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 54px;
  min-width: 0;
  font-size: 13px;
  line-height: 1.3;
  color: var(--text-muted);
  user-select: none;
}

.message-reply.is-clickable {
  cursor: pointer;
}

.message-reply::before {
  content: '';
  position: absolute;
  left: 20px;
  top: 50%;
  width: 26px;
  height: 12px;
  border-top: 2px solid #4e5058;
  border-left: 2px solid #4e5058;
  border-top-left-radius: 6px;
  transition: border-color 140ms ease;
}

.message-reply.is-clickable:hover::before {
  border-color: var(--text-secondary);
}

.message-reply.is-clickable:hover .reply-author,
.message-reply.is-clickable:hover .reply-snippet {
  color: var(--text-primary);
}

.reply-mini-avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--accent);
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
}

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

.reply-deleted-icon {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.reply-author {
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 140ms ease;
}

.reply-snippet {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  transition: color 140ms ease;
}

.reply-snippet--deleted {
  font-style: italic;
  color: var(--text-muted);
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 3px;
}

.message-author {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.message-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-muted);
}

.dm-read-receipt {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 2px;
}

.dm-read-receipt.is-read {
  color: #38bdf8;
}

.message-text {
  margin: 0;
  font-size: 15px;
  color: #dbdee1;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.mention-token {
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background-color: rgba(88, 101, 242, 0.25);
  color: #dee0fc;
  font-weight: 600;
}

.mention-token--self {
  background-color: rgba(240, 178, 50, 0.28);
  color: #fde68a;
}

.message-image-wrap {
  margin-top: 6px;
}

.message-image {
  display: block;
  max-width: min(420px, 100%);
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  cursor: zoom-in;
  object-fit: cover;
  background-color: var(--bg-rail);
  transition: opacity 140ms ease;
}

.message-image:hover {
  opacity: 0.92;
}

/* Плашки реакций эмодзи под сообщением */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.message-reactions:empty {
  display: none;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-hairline);
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.reaction-pill:hover {
  background-color: rgba(255, 255, 255, 0.09);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.reaction-pill.is-mine {
  background-color: rgba(88, 101, 242, 0.26);
  border-color: var(--accent);
  color: #ffffff;
}

.reaction-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
}

.role-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.role-tag--admin {
  background-color: rgba(88, 101, 242, 0.24);
  color: #c7d2fe;
}

.role-tag--moderator {
  background-color: var(--emerald-soft);
  color: #86efac;
}

.mod-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 120ms ease;
}

.message-row:hover .mod-actions,
.message-row:focus-within .mod-actions,
.message-row.has-picker-open .mod-actions {
  opacity: 1;
}

.reaction-picker-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.reaction-picker {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border-radius: 10px;
  background-color: var(--bg-rail);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.reaction-emoji-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 110ms ease, transform 110ms ease;
}

.reaction-emoji-btn:hover {
  background-color: var(--bg-active);
  transform: scale(1.14);
}

.btn-mod {
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid var(--border-hairline);
  background-color: var(--bg-sidebar);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.btn-mod--react:hover,
.btn-mod--reply:hover {
  background-color: rgba(88, 101, 242, 0.24);
  color: #c7d2fe;
}

.btn-mod--delete:hover {
  background-color: var(--danger-soft);
  color: #fca5a5;
}

.btn-mod--mute:hover {
  background-color: var(--amber-soft);
  color: #fde68a;
}

.btn-mod--ban {
  border-color: rgba(218, 55, 60, 0.35);
  color: #fca5a5;
}

.btn-mod--ban:hover {
  background-color: var(--danger);
  color: #ffffff;
}

.system-message {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Уведомления */
.notice-bar {
  margin: 0 16px 8px;
  padding: 9px 14px;
  border-radius: 8px;
  background-color: var(--danger-soft);
  border: 1px solid rgba(218, 55, 60, 0.3);
  color: #fecaca;
  font-size: 13px;
  flex-shrink: 0;
}

.notice-bar.is-warning {
  background-color: var(--amber-soft);
  border-color: rgba(240, 178, 50, 0.35);
  color: #fde68a;
}

/* Индикатор «Печатает...» */
.typing-indicator {
  margin: 0 20px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--text-secondary);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingBounce {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.typing-indicator-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Плашка предпросмотра ответа (Reply) */
.reply-preview-bar {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-hairline);
  border-left: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.reply-preview-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

.reply-preview-icon {
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.reply-preview-label {
  white-space: nowrap;
  flex-shrink: 0;
}

.reply-preview-author {
  color: var(--text-primary);
  font-weight: 700;
}

.reply-preview-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

.reply-preview-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background-color: var(--bg-hover);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.reply-preview-close:hover {
  background-color: var(--danger-soft);
  color: #fca5a5;
}

/* Предпросмотр выбранной картинки */
.image-preview-bar {
  margin: 0 16px 8px;
  padding: 10px;
  border-radius: 8px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.image-preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-preview-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background-color: var(--bg-rail);
  flex-shrink: 0;
}

.image-preview-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.image-preview-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-size {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-muted);
}

.image-preview-remove {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background-color: var(--bg-hover);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

.image-preview-remove:hover {
  background-color: var(--danger-soft);
  color: #fca5a5;
}

/* Нижний композер */
.composer-wrapper {
  padding: 0 16px 16px;
  flex-shrink: 0;
}

.composer-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.photo-quota-label {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.photo-quota-label.is-exhausted {
  color: #fca5a5;
}

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  background-color: var(--bg-composer);
  border: 1px solid var(--border-hairline);
}

.btn-attach {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: var(--text-secondary);
  color: var(--bg-composer);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.btn-attach:hover {
  background-color: #ffffff;
}

.btn-attach:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.composer-input {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  padding: 6px 4px;
}

.composer-input:focus {
  outline: none;
}

.composer-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-send {
  min-height: 36px;
  padding: 7px 16px;
  border: none;
  border-radius: 7px;
  background-color: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.btn-send:hover {
  background-color: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 4. Правая панель участников (~240px) */
.members-sidebar {
  width: 240px;
  flex-shrink: 0;
  background-color: var(--bg-sidebar);
  border-left: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 30;
}

.members-header {
  height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.members-header-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.tabular-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.members-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.member-group-title {
  padding: 0 8px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.member-row:hover {
  background-color: var(--bg-hover);
}

.member-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.member-text-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.member-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-custom-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-name--admin {
  color: #a5b4fc;
}

.member-name--moderator {
  color: #86efac;
}

.member-hover-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 120ms ease;
  flex-shrink: 0;
}

.member-row:hover .member-hover-actions,
.member-row:focus-within .member-hover-actions {
  opacity: 1;
}

.btn-member-act {
  border: 1px solid var(--border-hairline);
  background-color: var(--bg-rail);
  color: var(--text-secondary);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-member-act:hover {
  color: var(--text-primary);
  background-color: var(--bg-active);
}

.btn-member-act--mute:hover {
  background-color: var(--amber-soft);
  color: #fde68a;
}

/* ==================== Модалки и Лайтбокс ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 24px;
}

.modal-card--wide {
  max-width: 480px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* ==================== Карточка профиля (Popover) и Настройки профиля ==================== */
.profile-popover {
  position: fixed;
  width: 280px;
  max-width: calc(100vw - 24px);
  background-color: var(--bg-rail);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  z-index: 55;
}

.profile-popover-banner {
  height: 54px;
  background: linear-gradient(135deg, #5865f2 0%, #3b44a8 100%);
}

.profile-popover-body {
  padding: 0 16px 16px;
}

.profile-popover-avatar-row {
  margin-top: -34px;
  margin-bottom: 10px;
}

.profile-popover-avatar-row .status-dot--lg {
  border-color: var(--bg-rail);
}

.profile-popover-identity {
  margin-bottom: 14px;
}

.profile-popover-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.profile-popover-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word;
}

.profile-popover-status {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.profile-popover-status-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.profile-popover-custom {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background-color: var(--bg-sidebar);
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-word;
}

.profile-popover-cta {
  width: 100%;
  min-height: 38px;
}

.profile-avatar-editor {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  margin-bottom: 18px;
  border-radius: 10px;
  background-color: var(--bg-profile);
  border: 1px solid var(--border-hairline);
}

.profile-avatar-controls {
  flex: 1;
  min-width: 0;
}

.profile-avatar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.profile-avatar-hint {
  margin: 2px 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.profile-avatar-btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-upload-feedback {
  margin: 8px 0 0;
  font-size: 12px;
  color: #86efac;
}

.avatar-upload-feedback.is-error {
  color: #fca5a5;
}

.status-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-option-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background-color: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.status-option-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.status-option-btn.is-selected {
  background-color: rgba(88, 101, 242, 0.16);
  border-color: var(--accent);
  color: var(--text-primary);
}

.status-option-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-option-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.status-option-text strong {
  font-size: 13px;
  font-weight: 600;
}

.status-option-text small {
  font-size: 11px;
  color: var(--text-muted);
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-counter {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-muted);
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.lightbox-toolbar {
  position: fixed;
  top: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.lightbox-link,
.lightbox-close {
  padding: 8px 14px;
  border-radius: 6px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.lightbox-link:hover,
.lightbox-close:hover {
  background-color: var(--bg-active);
}

.lightbox-image {
  max-width: 92vw;
  max-height: 84vh;
  border-radius: 8px;
  object-fit: contain;
}

/* ==================== Адаптивность ==================== */
.icon-btn {
  min-width: 36px;
  min-height: 36px;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  background-color: var(--bg-composer);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mobile-only,
.tablet-only {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 25;
}

@media (max-width: 1024px) {
  .tablet-only {
    display: inline-flex;
  }

  .members-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  .members-sidebar.is-open {
    transform: translateX(0);
  }

  .member-hover-actions {
    opacity: 1;
  }
}

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

  .left-navigation {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .left-navigation.is-open {
    transform: translateX(0);
  }

  .channel-desc,
  .meta-sep,
  .composer-hint {
    display: none;
  }

  .messages-container {
    padding: 12px 12px 32px;
  }

  .composer-wrapper {
    padding: 0 12px 12px;
  }

  .typing-indicator,
  .reply-preview-bar,
  .image-preview-bar,
  .notice-bar {
    margin-left: 12px;
    margin-right: 12px;
  }

  .mod-actions {
    opacity: 1;
  }
}

@media (hover: none) {
  .mod-actions {
    opacity: 1;
  }
}
