:root {
  --bg: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #232428;
  --bg-floating: #111214;
  --bg-modifier-hover: rgba(79, 84, 92, 0.16);
  --bg-modifier-active: rgba(79, 84, 92, 0.24);
  --bg-modifier-selected: rgba(79, 84, 92, 0.32);
  --text: #dbdee1;
  --text-muted: #949ba4;
  --text-faint: #80848e;
  --border: #1e1f22;
  --border-subtle: rgba(78, 80, 88, 0.48);
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --mention: rgba(88, 101, 242, 0.3);
  --mention-text: #c9cdfb;
  --link: #00a8fc;
  --shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
  --server-icon-size: 48px;
  --sidebar-width: 240px;
  --member-width: 240px;
  --header-height: 48px;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f2f3f5;
  --bg-tertiary: #ebedef;
  --bg-floating: #ffffff;
  --bg-modifier-hover: rgba(29, 35, 40, 0.06);
  --bg-modifier-active: rgba(29, 35, 40, 0.12);
  --bg-modifier-selected: rgba(29, 35, 40, 0.18);
  --text: #313338;
  --text-muted: #5c5e66;
  --text-faint: #80848e;
  --border: #e3e5e8;
  --border-subtle: #d9dce0;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --mention: rgba(88, 101, 242, 0.15);
  --mention-text: #3f47c9;
  --link: #0068e0;
  --shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "gg sans", "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea { outline: none; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg-modifier-active); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

#app { height: 100vh; }
.hidden { display: none !important; }

/* Auth */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(88, 101, 242, 0.25), transparent 35%),
    radial-gradient(circle at 85% 80%, rgba(35, 165, 90, 0.18), transparent 35%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--bg-floating);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
  color: var(--text);
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-logo svg { width: 40px; height: 40px; }
.auth-logo h1 { font-size: 24px; margin: 0; }
.auth-card h2 { font-size: 20px; margin: 0 0 8px; }
.auth-sub { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 14px;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.auth-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.auth-switch { color: var(--text-muted); font-size: 14px; }
.auth-switch button { color: var(--link); font-weight: 600; }
.remember-row { display: flex; align-items: center; gap: 8px; margin: 12px 0; font-size: 13px; color: var(--text-muted); }
.remember-row input { accent-color: var(--accent); }
.error-text { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.05s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--bg-modifier-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border-subtle); }
.btn-outline:hover { background: var(--bg-modifier-hover); }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-modifier-hover); color: var(--text); }
.icon-btn.active { background: var(--bg-modifier-selected); color: var(--text); }

/* App shell */
.app { display: flex; height: 100vh; }
.server-rail {
  width: 72px;
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  overflow-y: auto;
  flex-shrink: 0;
}
.server-icon {
  position: relative;
  width: var(--server-icon-size);
  height: var(--server-icon-size);
  border-radius: 50%;
  background: var(--bg-modifier-active);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  transition: border-radius 0.15s ease, background-color 0.15s ease;
  flex-shrink: 0;
}
.server-icon:hover { border-radius: 16px; background: var(--accent); }
.server-icon.active { border-radius: 16px; background: var(--accent); }
.server-icon.add { border: 2px dashed var(--text-faint); background: transparent; color: var(--green); font-size: 24px; }
.server-icon.add:hover { background: var(--green); color: #fff; }
.server-icon .unread-dot {
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 20px;
  border-radius: 0 4px 4px 0;
  background: var(--text);
}
.server-separator { width: 32px; height: 2px; background: var(--border-subtle); border-radius: 1px; margin: 4px 0; }

.channel-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
}
.server-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(2, 2, 2, 0.2);
  user-select: none;
}
.server-header:hover { background: var(--bg-modifier-hover); }
.server-header .chevron { color: var(--text-muted); font-size: 12px; }
.channel-list { flex: 1; overflow-y: auto; padding: 8px; }
.channel-category {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: none;
}
.channel-category:hover { color: var(--text); }
.channel-category .add { opacity: 0; }
.channel-category:hover .add { opacity: 1; }
.channel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
}
.channel-item:hover { background: var(--bg-modifier-hover); color: var(--text); }
.channel-item.active { background: var(--bg-modifier-selected); color: var(--text); }
.channel-item .hash { font-size: 18px; line-height: 1; opacity: 0.8; }
.channel-item .voice-icon { font-size: 14px; }
.channel-item .channel-name { flex: 1; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-item .unread-count {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.channel-item .mention-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); }
.user-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 6px;
  cursor: pointer;
}
.user-panel:hover { background: var(--bg-modifier-active); }
.user-panel .user-info { flex: 1; min-width: 0; }
.user-panel .username { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel .status-text { font-size: 11px; color: var(--text-muted); }

/* Chat */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(2, 2, 2, 0.2);
  flex-shrink: 0;
}
.chat-title { font-weight: 700; font-size: 15px; white-space: nowrap; }
.chat-topic { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 1px solid var(--border-subtle); padding-left: 8px; }
.chat-header-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}
.message-group { padding: 0 16px; }
.message-group:hover { background: var(--bg-modifier-hover); }
.message { display: flex; gap: 14px; padding: 2px 0; position: relative; }
.message.avatar-hidden .avatar-wrap { visibility: hidden; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  user-select: none;
}
.avatar.emoji-avatar { font-size: 22px; background: var(--bg-tertiary); }
.status-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  background: var(--text-faint);
}
.status-dot.online { background: var(--green); }
.status-dot.idle { background: var(--yellow); }
.status-dot.dnd { background: var(--red); }
.status-dot.invisible { background: var(--text-faint); }
.message-main { flex: 1; min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message-author { font-weight: 600; font-size: 15px; cursor: pointer; }
.message-author:hover { text-decoration: underline; }
.message-time { font-size: 11px; color: var(--text-faint); }
.message-text { font-size: 15px; line-height: 1.375; word-wrap: break-word; white-space: pre-wrap; }
.message-text .mention { background: var(--mention); color: var(--mention-text); border-radius: 3px; padding: 0 2px; font-weight: 600; }
.message-text code { background: var(--bg-tertiary); border-radius: 3px; padding: 2px 4px; font-family: "Consolas", "Courier New", monospace; font-size: 13px; }
.message-text pre { background: var(--bg-tertiary); border-radius: 4px; padding: 8px; overflow-x: auto; }
.message-text pre code { background: transparent; padding: 0; }
.message-text a { color: var(--link); }
.message-edited { font-size: 10px; color: var(--text-faint); margin-left: 6px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachment { max-width: 400px; border-radius: 8px; overflow: hidden; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); }
.attachment img { display: block; max-width: 100%; max-height: 300px; }
.attachment.file { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: var(--text); }
.attachment.file .file-icon { font-size: 24px; }
.attachment.file .file-name { font-weight: 600; font-size: 14px; }
.attachment.file .file-size { font-size: 12px; color: var(--text-muted); }
.reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 14px;
  cursor: pointer;
}
.reaction:hover { border-color: var(--accent); }
.reaction.active { background: var(--mention); border-color: var(--accent); }
.reaction .count { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.reaction.active .count { color: var(--mention-text); }
.message-actions {
  position: absolute;
  top: -14px;
  right: 16px;
  display: none;
  background: var(--bg-floating);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 4px;
  gap: 2px;
}
.message-group:hover .message-actions, .message:hover .message-actions { display: flex; }
.message-actions .icon-btn { width: 28px; height: 28px; }

.message-input-wrap { padding: 0 16px 24px; flex-shrink: 0; }
.message-input-box {
  background: var(--bg-tertiary);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  padding: 0 12px;
  min-height: 44px;
}
.message-input-box:focus-within { border: 1px solid var(--accent); }
.message-input {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  padding: 11px 0;
  font-size: 15px;
  line-height: 1.375;
  max-height: 200px;
  min-height: 44px;
}
.message-input::placeholder { color: var(--text-faint); }
.input-tools { display: flex; align-items: center; gap: 4px; padding-bottom: 8px; }
.input-tools .icon-btn { width: 28px; height: 28px; }
.typing-indicator { height: 18px; padding: 0 16px 4px; font-size: 12px; color: var(--text-muted); }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); padding: 24px; text-align: center; }
.empty-state h2 { color: var(--text); margin-bottom: 8px; }

/* Members */
.member-list {
  width: var(--member-width);
  background: var(--bg-secondary);
  overflow-y: auto;
  padding: 8px;
  flex-shrink: 0;
}
.member-section { margin-bottom: 16px; }
.member-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}
.member-item:hover { background: var(--bg-modifier-hover); }
.member-item .member-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-item .member-sub { font-size: 11px; color: var(--text-muted); }
.member-item .avatar { width: 32px; height: 32px; font-size: 13px; }
.member-item .status-dot { width: 12px; height: 12px; border-width: 2px; }
.member-item.bot-tag, .member-tag {
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 6px;
}

/* Friends */
.friends-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.friends-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(2, 2, 2, 0.2);
}
.friends-header h2 { margin: 0; font-size: 18px; }
.friends-tabs { display: flex; gap: 8px; padding: 12px 16px 0; border-bottom: 1px solid var(--border); }
.friends-tab {
  padding: 10px 8px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.friends-tab:hover { color: var(--text); }
.friends-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.friends-body { flex: 1; overflow-y: auto; padding: 16px; }
.friends-search { max-width: 420px; margin-bottom: 16px; }
.friends-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 10px 12px;
}
.friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.friend-row:hover { background: var(--bg-modifier-hover); }
.friend-row .avatar { width: 36px; height: 36px; font-size: 15px; }
.friend-row .friend-info { flex: 1; min-width: 0; }
.friend-row .friend-name { font-weight: 600; }
.friend-row .friend-sub { font-size: 12px; color: var(--text-muted); }
.friend-actions { display: flex; gap: 6px; }
.empty-list { color: var(--text-muted); text-align: center; padding: 48px 16px; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal {
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-floating);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.modal.wide { width: min(720px, 100%); }
.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal .modal-sub { color: var(--text-muted); font-size: 14px; margin: 0 0 20px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h2 { margin: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.avatar-option {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  border: 2px solid transparent;
}
.avatar-option.selected { border-color: var(--accent); }
.color-option {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-option.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border-subtle); }
.setting-row:last-child { border-bottom: none; }
.setting-row .setting-label { font-weight: 600; }
.setting-row .setting-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.switch { position: relative; width: 40px; height: 20px; background: var(--bg-modifier-active); border-radius: 10px; transition: background 0.15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }
.section-title { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin: 20px 0 8px; }
.member-manage-list { max-height: 260px; overflow-y: auto; margin-top: 8px; }
.manage-member { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; }
.manage-member:hover { background: var(--bg-modifier-hover); }
.manage-member .avatar { width: 32px; height: 32px; font-size: 13px; }
.manage-member .info { flex: 1; min-width: 0; }
.manage-member .name { font-weight: 600; font-size: 14px; }
.manage-member .role { font-size: 12px; color: var(--text-muted); }

/* Context menu */
.context-menu {
  position: fixed;
  min-width: 180px;
  background: var(--bg-floating);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 200;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text);
  text-align: left;
}
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-item.danger:hover { background: var(--red); }
.menu-item .menu-icon { width: 18px; text-align: center; }
.menu-separator { height: 1px; background: var(--border-subtle); margin: 4px 0; }
.menu-label { font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 6px 10px 2px; text-transform: uppercase; }

/* Emoji picker */
.emoji-picker {
  position: absolute;
  bottom: 56px;
  left: 16px;
  width: 320px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-floating);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 50;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-cell { font-size: 22px; padding: 6px; border-radius: 6px; cursor: pointer; text-align: center; }
.emoji-cell:hover { background: var(--bg-modifier-hover); }

/* Toast */
.toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-floating);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  font-size: 14px;
  min-width: 220px;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--bg-floating);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  box-shadow: var(--shadow);
  z-index: 400;
  pointer-events: none;
}

/* Profile popover */
.profile-card {
  width: min(340px, 100%);
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.profile-banner { height: 60px; background: linear-gradient(135deg, var(--accent), #eb459e); }
.profile-body { padding: 0 16px 16px; margin-top: -28px; }
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--bg-secondary); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; color: #fff; background: var(--accent); }
.profile-name { font-size: 18px; font-weight: 700; margin-top: 8px; }
.profile-username { color: var(--text-muted); font-size: 14px; }
.profile-bio { margin-top: 12px; font-size: 14px; color: var(--text); white-space: pre-wrap; }
.profile-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Voice */
.voice-channel .voice-icon { color: var(--green); }
.voice-users { font-size: 12px; color: var(--text-muted); padding-left: 26px; }
.voice-user { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 13px; }
.voice-connected-bar {
  height: 32px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.voice-connected-bar .channel-name { color: var(--text); font-weight: 600; }
.voice-connected-bar .spacer { flex: 1; }

/* Mobile top bar (hidden on desktop) */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .app { height: calc(100vh - 56px); height: calc(100dvh - 56px); }

  /* Server rail -> bottom bar */
  .server-rail {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    height: 56px;
    flex-direction: row;
    align-items: center;
    padding: 0 8px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid var(--border);
    z-index: 30;
  }
  .server-icon { width: 44px; height: 44px; flex-shrink: 0; }
  .server-icon .unread-dot {
    left: 50%; top: -3px;
    transform: translateX(-50%);
    width: 16px; height: 4px;
    border-radius: 2px;
  }
  .server-separator { width: 2px; height: 24px; margin: 0 2px; flex-shrink: 0; }

  /* Channel sidebar -> slide-over drawer */
  .channel-sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 56px;
    width: min(300px, 85vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 40;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .channel-sidebar { transform: none; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    left: 0; right: 0; top: 0; bottom: 56px;
    background: rgba(0, 0, 0, 0.55);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  /* User panel rides inside the drawer */
  .user-panel {
    left: 0;
    bottom: 56px;
    width: min(300px, 85vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 41;
  }
  body.sidebar-open .user-panel { transform: none; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .mobile-topbar .icon-btn { width: 36px; height: 36px; font-size: 18px; }

  .member-list { display: none; }
  .chat-topic { display: none; }
  .chat-search { width: 90px; font-size: 16px; }
  .chat-header { padding: 0 8px; gap: 4px; }
  .message-input-wrap { padding: 0 8px 12px; }
  .typing-indicator { padding: 0 8px 4px; }
  .day-divider { padding: 0 8px; }
  .friends-header, .friends-tabs, .friends-body { padding-left: 8px; padding-right: 8px; }
  .friends-tabs { overflow-x: auto; }
  .input-tools { overflow-x: auto; padding-bottom: 8px; }
  .input-tools::-webkit-scrollbar { display: none; }
  .message-input { font-size: 16px; }
  .modal-backdrop { padding: 8px; }
  .modal { padding: 16px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; }
  .server-rail { scrollbar-width: none; }
  .server-rail::-webkit-scrollbar { display: none; }
  .modal.wide { width: 100%; }
  .setting-row { flex-wrap: wrap; }
  .channel-item { min-height: 36px; }
  .icon-btn { min-width: 36px; min-height: 36px; }
}

@media (max-width: 620px) {
  .server-header { padding: 0 10px; font-size: 14px; }
  .chat-title { font-size: 14px; }
  .message { gap: 10px; }
  .message .avatar-wrap { display: none; }
  .message.grouped .avatar-wrap { display: none; }
  .message-meta { flex-wrap: wrap; row-gap: 2px; }
  .empty-state h2 { font-size: 18px; }
  .friends-header h2 { font-size: 16px; }
  .poll { max-width: 100%; }
  .reply-quote { max-width: 100%; }
}

/* Chat extras */
.day-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 8px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 32px);
  margin: 8px 16px 0;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}
.pinned-bar:hover { background: var(--bg-modifier-hover); }
.pending-attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0 0; }
.pending-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.pending-attachment .icon-btn { width: 22px; height: 22px; font-size: 12px; }
.attachment.image { padding: 0; background: transparent; border: none; }
.attachment.image img { border-radius: 8px; }
.pinned-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.pinned-item { background: var(--bg-tertiary); border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.pinned-item:hover { background: var(--bg-modifier-hover); }
.pinned-author { font-weight: 700; font-size: 13px; }
.pinned-text { font-size: 14px; margin-top: 4px; }
.deleted-message .message-text { font-style: italic; }
.status-dot.offline { background: var(--text-faint); }
.message.grouped .message-meta .message-author { display: none; }

/* User panel (fixed bottom of channel sidebar) */
.user-panel {
  position: fixed;
  left: 72px;
  bottom: 0;
  width: var(--sidebar-width);
  height: 52px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  z-index: 20;
}
.user-panel .avatar-wrap { width: 32px; height: 32px; flex-shrink: 0; }
.user-panel .avatar { width: 32px; height: 32px; font-size: 13px; }
.user-panel .avatar-wrap .avatar.emoji-avatar { font-size: 18px; }
.user-panel .user-info { flex: 1; min-width: 0; }
.user-panel .username { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel .status-text { font-size: 11px; color: var(--text-muted); }
.user-panel .icon-btn { width: 28px; height: 28px; }
.channel-list { padding-bottom: 68px; }
.voice-connected-bar { flex-shrink: 0; }

/* Categories */
.channel-category .cat-chevron { width: 12px; font-size: 10px; opacity: 0.7; }
.channel-category .cat-name { flex: 1; }
.channel-category.collapsed .cat-chevron { transform: none; }

/* Replies */
.reply-quote {
  display: flex; align-items: center; gap: 6px;
  margin: 0 0 2px; padding: 4px 8px;
  background: var(--bg-modifier-hover); border-radius: 4px;
  font-size: 13px; cursor: pointer; max-width: 520px;
  border-left: 2px solid var(--text-muted);
}
.reply-quote-bar { display: none; }
.reply-author { font-weight: 600; white-space: nowrap; }
.reply-snippet { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-quote:hover .reply-snippet { color: var(--text); }

.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; margin-bottom: 6px;
  background: var(--bg-modifier-hover); border-radius: 8px 8px 0 0;
  font-size: 13px; border-left: 3px solid var(--accent);
}
.reply-bar-label { color: var(--text-muted); white-space: nowrap; }
.reply-bar-snippet { color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

/* Polls */
.poll { margin-top: 8px; max-width: 480px; }
.poll-question { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.poll-option {
  position: relative; display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 8px 12px; margin-bottom: 6px;
  background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  border-radius: 6px; color: var(--text); font-size: 14px; cursor: pointer;
  overflow: hidden; transition: border-color .15s;
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); }
.poll-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--bg-modifier-active); pointer-events: none;
}
.poll-option.voted .poll-fill { background: rgba(88,101,242,.25); }
.poll-check { width: 16px; color: var(--accent); font-weight: 700; flex-shrink: 0; }
.poll-text { position: relative; flex: 1; }
.poll-count { position: relative; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.poll-footer { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* Header search */
.chat-search {
  background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  border-radius: 6px; color: var(--text); font-size: 13px;
  padding: 4px 10px; width: 160px; outline: none;
}
.chat-search:focus { border-color: var(--accent); }
.chat-search::placeholder { color: var(--text-faint); }

.search-note {
  padding: 8px 16px; font-size: 13px; color: var(--text-muted);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 2;
}

/* Jump flash */
.message-group.flash .message {
  animation: msgflash 1.4s ease-out;
  border-radius: 6px;
}
@keyframes msgflash {
  0% { background: rgba(88,101,242,.35); }
  100% { background: transparent; }
}

/* Drag & drop */
.drop-line {
  height: 2px;
  background: #23a55a;
  border-radius: 1px;
  margin: 1px 0;
  box-shadow: 0 0 6px rgba(35,165,90,.8);
  pointer-events: none;
}
.dragging { opacity: .4; }
.channel-category[draggable="true"], .channel-item[draggable="true"] { cursor: grab; }
.channel-category[draggable="true"]:active, .channel-item[draggable="true"]:active { cursor: grabbing; }

/* Voice grid */
.voice-grid {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.voice-grid:not(:empty) { display: flex; }
.voice-tile {
  position: relative;
  width: 160px;
  height: 90px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-video { width: 100%; height: 100%; object-fit: cover; }
.voice-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
}
.voice-tile-name {
  position: absolute; left: 6px; bottom: 4px;
  font-size: 11px; font-weight: 600; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 620px) {
  .voice-tile { width: 110px; height: 70px; }
}
