/* ============================================================
   Chatterbox — Discord-accurate dark theme
   Colour tokens and layout metrics mirror Discord's own values.
   ============================================================ */

:root {
  --guild-rail: #1e1f22;
  --sidebar: #2b2d31;
  --chat-bg: #313338;
  --user-panel: #232428;
  --input-bg: #383a40;
  --modal-bg: #313338;
  --floating: #111214;

  --brand: #5865f2;
  --brand-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --red-hover: #da373c;

  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-header: #f2f3f5;
  --text-link: #00a8fc;
  --interactive-normal: #b5bac1;
  --interactive-hover: #dbdee1;
  --interactive-active: #ffffff;

  --hover-bg: #35373c;
  --selected-bg: #404249;
  --message-hover: #2e3035;
  --border: #3f4147;
  --divider: #26282c;

  --rail-w: 72px;
  --sidebar-w: 240px;
  --members-w: 240px;
  --header-h: 48px;

  --font: "gg sans", "Noto Sans", -apple-system, BlinkMacSystemFont, system-ui,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Consolas", "Andale Mono WT", "Andale Mono", "Lucida Console", monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--chat-bg);
  color: var(--text-normal);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------------------------------------------------- scrollbars */
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: #1a1b1e transparent; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }
.thin-scroll::-webkit-scrollbar { width: 8px; }
.thin-scroll::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }

/* ================================================================
   Auth screen
   ================================================================ */
#auth {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #5865f2 0%, #404eed 40%, #3b45c4 100%);
}
.auth-card {
  width: 100%; max-width: 480px;
  background: var(--modal-bg);
  border-radius: 5px; padding: 32px;
  box-shadow: 0 8px 24px rgba(0,0,0,.34);
}
.auth-card h1 { font-size: 24px; font-weight: 600; color: var(--text-header); text-align: center; }
.auth-card .sub { color: var(--text-muted); font-size: 16px; text-align: center; margin-top: 8px; }
.field { margin-top: 20px; }
.field label {
  display: block; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: #b5bac1; margin-bottom: 8px;
}
.field input {
  width: 100%; height: 40px; padding: 10px;
  background: var(--floating); border: 1px solid #1e1f22; border-radius: 3px;
  color: var(--text-normal); font-size: 16px;
}
.field input:focus { outline: none; border-color: var(--brand); }
.btn-primary {
  width: 100%; height: 44px; margin-top: 20px;
  background: var(--brand); color: #fff; border-radius: 3px;
  font-size: 16px; font-weight: 500; transition: background .15s;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.auth-switch { margin-top: 8px; font-size: 14px; color: var(--text-muted); }
.auth-switch button { color: var(--text-link); font-size: 14px; padding: 0; }
.auth-error {
  color: var(--red); font-size: 13px; margin-top: 12px; min-height: 16px;
  font-style: italic;
}

/* ================================================================
   App shell
   ================================================================ */
#app { display: none; height: 100%; }
#app.visible { display: flex; }

/* ------------------------------------------------- guild rail */
.rail {
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  background: var(--guild-rail);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 8px; overflow-y: auto; overflow-x: hidden;
}
.rail::-webkit-scrollbar { width: 0; }
.rail-item { position: relative; width: 48px; height: 48px; flex: 0 0 48px; }
.rail-pill {
  position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 0; background: #fff;
  border-radius: 0 4px 4px 0; transition: height .2s ease;
}
.rail-item:hover .rail-pill { height: 20px; }
.rail-item.active .rail-pill { height: 40px; }
.rail-item.unread .rail-pill { height: 8px; }
.rail-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--sidebar); color: var(--text-normal);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 500; overflow: hidden;
  transition: border-radius .15s ease, background .15s ease;
  background-size: cover; background-position: center;
}
.rail-item:hover .rail-btn, .rail-item.active .rail-btn { border-radius: 16px; }
.rail-btn.home { background: var(--brand); color: #fff; }
.rail-item:hover .rail-btn.home { background: var(--brand); }
.rail-btn.add { color: var(--green); font-size: 24px; font-weight: 300; }
.rail-item:hover .rail-btn.add { background: var(--green); color: #fff; }
.rail-sep { width: 32px; height: 2px; background: #35363c; border-radius: 1px; flex: 0 0 2px; }

/* ------------------------------------------------- channel sidebar */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--sidebar); display: flex; flex-direction: column;
}
.sidebar-header {
  height: var(--header-h); flex: 0 0 var(--header-h);
  padding: 0 16px; display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 1px 0 rgba(4,4,5,.2), 0 1.5px 0 rgba(6,6,7,.05);
  font-weight: 600; font-size: 16px; color: var(--text-header);
  cursor: pointer;
}
.sidebar-header:hover { background: var(--hover-bg); }
.sidebar-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels { flex: 1; padding: 8px 8px 0; overflow-y: auto; }

.cat {
  display: flex; align-items: center; gap: 2px;
  padding: 16px 0 4px 0; color: var(--text-muted);
  font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
}
.cat span { flex: 1; cursor: pointer; }
.cat:hover span { color: var(--interactive-hover); }
.cat button { color: var(--text-muted); font-size: 18px; line-height: 1; padding: 0 4px; }
.cat button:hover { color: var(--interactive-active); }

.channel {
  display: flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 8px; margin-bottom: 2px;
  border-radius: 4px; color: var(--text-muted);
  font-size: 16px; cursor: pointer; position: relative;
}
.channel:hover { background: var(--hover-bg); color: var(--interactive-hover); }
.channel.active { background: var(--selected-bg); color: #fff; }
.channel.unread { color: #fff; font-weight: 500; }
.channel.unread::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 8px; background: #fff; border-radius: 0 4px 4px 0;
}
.channel .icon { flex: 0 0 20px; color: var(--text-muted); display: flex; }
.channel .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .badge {
  background: var(--red); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}
.channel .ch-action { opacity: 0; color: var(--text-muted); font-size: 16px; padding: 0 2px; }
.channel:hover .ch-action { opacity: 1; }
.channel .ch-action:hover { color: #fff; }

.voice-members { padding-left: 22px; margin-bottom: 2px; }
.voice-member {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 4px; cursor: pointer;
  color: var(--text-muted); font-size: 14px;
}
.voice-member:hover { background: var(--hover-bg); }
.voice-member .avatar { width: 24px; height: 24px; font-size: 10px; }
.voice-member .vm-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-member.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }
.vm-icons { display: flex; gap: 4px; color: var(--text-muted); }
.vm-icons .muted { color: var(--red); }

/* ------------------------------------------------- voice status panel */
.voice-status {
  padding: 8px; background: var(--user-panel);
  border-bottom: 1px solid rgba(0,0,0,.2);
}
.voice-status .vs-top { display: flex; align-items: center; justify-content: space-between; }
.voice-status .vs-title { font-size: 14px; font-weight: 600; color: var(--green); display: flex; align-items: center; gap: 6px; }
.voice-status .vs-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.voice-status .vs-actions { display: flex; gap: 4px; margin-top: 8px; }
.vs-btn {
  flex: 1; height: 32px; border-radius: 4px; background: #2b2d31;
  color: var(--interactive-normal); display: flex; align-items: center; justify-content: center;
}
.vs-btn:hover { background: var(--hover-bg); color: var(--interactive-active); }
.vs-btn.active { background: #fff; color: #1e1f22; }
.vs-btn.danger:hover { background: var(--red); color: #fff; }

/* ------------------------------------------------- user panel */
.user-panel {
  height: 52px; flex: 0 0 52px; background: var(--user-panel);
  display: flex; align-items: center; padding: 0 8px; gap: 8px;
}
.user-panel .me { display: flex; align-items: center; gap: 8px; flex: 1; padding: 4px; border-radius: 4px; cursor: pointer; min-width: 0; }
.user-panel .me:hover { background: var(--hover-bg); }
.user-panel .info { min-width: 0; }
.user-panel .uname { font-size: 14px; font-weight: 600; color: var(--text-header); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .ustatus { font-size: 12px; color: var(--text-muted); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 4px; color: var(--interactive-normal);
  display: flex; align-items: center; justify-content: center; flex: 0 0 32px;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--interactive-hover); }
.icon-btn.on { color: var(--red); }

/* ------------------------------------------------- avatars */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 600; position: relative;
  background-size: cover; background-position: center;
}
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.avatar .dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 3px solid var(--user-panel); background: var(--text-muted);
}
.avatar .dot.online { background: var(--green); }
.avatar .dot.idle { background: var(--yellow); }
.avatar .dot.dnd { background: var(--red); }
.sidebar .avatar .dot { border-color: var(--sidebar); }
.members .avatar .dot { border-color: var(--sidebar); }

/* ================================================================
   Main column
   ================================================================ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.topbar {
  height: var(--header-h); flex: 0 0 var(--header-h);
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(4,4,5,.2), 0 1.5px 0 rgba(6,6,7,.05); z-index: 2;
}
.topbar .hash { color: var(--text-muted); display: flex; }
.topbar .title { font-weight: 600; font-size: 16px; color: var(--text-header); }
.topbar .topic {
  color: var(--text-muted); font-size: 14px; padding-left: 8px; margin-left: 8px;
  border-left: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .spacer { flex: 1; }

.content-row { flex: 1; display: flex; min-height: 0; }
.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ------------------------------------------------- stage (video grid) */
.stage {
  background: #000; display: none; flex-direction: column;
  padding: 16px; gap: 12px; min-height: 0;
}
.stage.visible { display: flex; flex: 1; }
.tiles {
  flex: 1; display: grid; gap: 12px; min-height: 0;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-content: center; justify-content: center;
}
.tile {
  position: relative; background: #202225; border-radius: 8px; overflow: hidden;
  aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center;
  min-height: 0;
}
.tile.speaking { box-shadow: inset 0 0 0 2px var(--green); }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile .tile-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 30px; font-weight: 600; background-size: cover;
}
.tile .tile-label {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 4px; display: flex; align-items: center; gap: 5px;
  max-width: calc(100% - 16px); overflow: hidden;
}
.tile .tile-label .muted { color: var(--red); display: flex; }
.stage-bar { display: flex; justify-content: center; gap: 8px; flex: 0 0 auto; }
.stage-btn {
  width: 44px; height: 44px; border-radius: 50%; background: #2b2d31;
  color: #fff; display: flex; align-items: center; justify-content: center;
}
.stage-btn:hover { background: #35373c; }
.stage-btn.active { background: #fff; color: #1e1f22; }
.stage-btn.danger { background: var(--red); }
.stage-btn.danger:hover { background: var(--red-hover); }

/* ------------------------------------------------- messages */
.messages { flex: 1; overflow-y: auto; padding-bottom: 8px; min-height: 0; }
.msg-start { padding: 16px 16px 8px; }
.msg-start h2 { font-size: 32px; font-weight: 700; color: var(--text-header); margin-bottom: 8px; }
.msg-start p { color: var(--text-muted); font-size: 16px; }
.msg-start .big-hash {
  width: 68px; height: 68px; border-radius: 50%; background: var(--input-bg);
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}
.load-more { text-align: center; padding: 8px; }
.load-more button { color: var(--text-link); font-size: 13px; }

.divider-date {
  display: flex; align-items: center; gap: 8px; margin: 16px 16px 8px;
  color: var(--text-muted); font-size: 12px; font-weight: 600;
}
.divider-date::before, .divider-date::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg {
  display: flex; padding: 2px 48px 2px 16px; position: relative;
}
.msg:hover { background: var(--message-hover); }
.msg.grouped { margin-top: 0; }
.msg.first { margin-top: 17px; }
.msg .gutter { width: 56px; flex: 0 0 56px; display: flex; justify-content: flex-start; padding-top: 2px; }
.msg .gutter .ts {
  display: none; font-size: 11px; color: var(--text-muted);
  width: 100%; text-align: center; padding-top: 4px;
}
.msg.grouped:hover .gutter .ts { display: block; }
.msg .body { flex: 1; min-width: 0; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-size: 16px; font-weight: 500; color: var(--text-header); cursor: pointer; }
.msg .author:hover { text-decoration: underline; }
.msg .time { font-size: 12px; color: var(--text-muted); }
.msg .edited { font-size: 10px; color: var(--text-muted); }
.msg .text {
  font-size: 16px; line-height: 1.375; color: var(--text-normal);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg .reply-ref {
  display: flex; align-items: center; gap: 6px; font-size: 14px;
  color: var(--text-muted); margin-bottom: 2px; cursor: pointer;
}
.msg .reply-ref .r-name { color: var(--text-normal); font-weight: 500; }
.msg .reply-ref .r-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60ch; }
.msg.mentioned { background: rgba(88,101,242,.1); box-shadow: inset 2px 0 0 var(--brand); }
.msg.mentioned:hover { background: rgba(88,101,242,.16); }
.msg.highlight { animation: flash 2s ease; }
@keyframes flash { 0%,60% { background: rgba(88,101,242,.2); } 100% { background: transparent; } }

.msg-actions {
  position: absolute; right: 16px; top: -16px;
  background: var(--chat-bg); border: 1px solid var(--divider); border-radius: 4px;
  display: none; box-shadow: 0 0 0 1px rgba(4,4,5,.15);
}
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
  width: 32px; height: 32px; color: var(--interactive-normal);
  display: flex; align-items: center; justify-content: center;
}
.msg-actions button:hover { background: var(--hover-bg); color: var(--interactive-hover); }
.msg-actions button.danger:hover { color: var(--red); }

/* markdown */
.text code {
  background: #2b2d31; padding: 2px 4px; border-radius: 3px;
  font-family: var(--mono); font-size: 85%;
}
.text pre {
  background: #2b2d31; border: 1px solid #202225; border-radius: 4px;
  padding: 8px; margin: 4px 0; overflow-x: auto;
}
.text pre code { background: none; padding: 0; font-size: 13px; line-height: 1.4; }
.text blockquote {
  border-left: 4px solid #4f545c; padding-left: 12px; margin: 2px 0;
}
.text .spoiler {
  background: #202225; color: transparent; border-radius: 3px; cursor: pointer; padding: 0 2px;
}
.text .spoiler.revealed { background: rgba(70,72,79,.4); color: var(--text-normal); }
.text .mention {
  background: rgba(88,101,242,.3); color: #dee0fc; border-radius: 3px;
  padding: 0 2px; font-weight: 500; cursor: pointer;
}
.text .mention:hover { background: var(--brand); color: #fff; }
.text .emoji-lg { font-size: 40px; line-height: 1.2; }
.text h1, .text h2, .text h3 { color: var(--text-header); margin: 4px 0; }
.text h1 { font-size: 24px; } .text h2 { font-size: 20px; } .text h3 { font-size: 16px; }

.attachments { margin-top: 4px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.attachments img, .attachments video {
  max-width: 400px; max-height: 300px; border-radius: 4px; cursor: pointer; display: block;
}
.file-card {
  display: flex; align-items: center; gap: 8px; background: #2b2d31;
  border: 1px solid var(--border); border-radius: 4px; padding: 10px; max-width: 400px;
}
.file-card .fname { color: var(--text-link); font-size: 14px; }
.file-card .fsize { color: var(--text-muted); font-size: 12px; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: flex; align-items: center; gap: 4px; height: 24px; padding: 0 6px;
  background: rgba(255,255,255,.04); border: 1px solid transparent; border-radius: 8px;
  font-size: 14px; color: var(--text-muted); cursor: pointer;
}
.reaction:hover { border-color: var(--interactive-normal); }
.reaction.mine { background: rgba(88,101,242,.15); border-color: var(--brand); color: #c9cdfb; }
.reaction .count { font-size: 13px; font-weight: 600; }

/* ------------------------------------------------- composer */
.composer-wrap { padding: 0 16px 24px; flex: 0 0 auto; position: relative; }
.typing {
  position: absolute; bottom: 4px; left: 16px; font-size: 13px; color: var(--text-normal);
  display: flex; align-items: center; gap: 6px; height: 20px;
}
.typing .dots { display: inline-flex; gap: 2px; }
.typing .dots i {
  width: 4px; height: 4px; border-radius: 50%; background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.typing .dots i:nth-child(2) { animation-delay: .2s; }
.typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-3px); opacity: 1; } }

.reply-bar {
  display: none; align-items: center; justify-content: space-between;
  background: #2b2d31; border-radius: 8px 8px 0 0; padding: 6px 12px;
  font-size: 13px; color: var(--text-muted);
}
.reply-bar.visible { display: flex; }
.reply-bar b { color: var(--text-normal); }
.reply-bar button { color: var(--text-muted); font-size: 16px; }

.composer {
  background: var(--input-bg); border-radius: 8px;
  display: flex; align-items: flex-end; padding: 0 16px 0 0;
}
.composer.with-reply { border-radius: 0 0 8px 8px; }
.composer .attach-btn { padding: 11px 16px; color: var(--interactive-normal); display: flex; align-self: flex-start; }
.composer .attach-btn:hover { color: var(--interactive-hover); }
.composer textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  padding: 11px 0; font-size: 16px; line-height: 1.375; color: var(--text-normal);
  max-height: 300px; min-height: 44px;
}
.composer textarea::placeholder { color: var(--text-muted); }
.composer .tools { display: flex; align-self: flex-start; padding: 6px 0; gap: 4px; }
.composer .tools button { color: var(--interactive-normal); padding: 5px; display: flex; }
.composer .tools button:hover { color: var(--interactive-hover); }

.pending-files { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0 0 16px; }
.pending-file {
  background: #2b2d31; border-radius: 4px; padding: 6px 10px; font-size: 13px;
  display: flex; align-items: center; gap: 8px; color: var(--text-normal);
}
.pending-file button { color: var(--red); }

/* ------------------------------------------------- members */
.members {
  width: var(--members-w); flex: 0 0 var(--members-w); background: var(--sidebar);
  padding: 16px 8px; overflow-y: auto;
}
.members.hidden { display: none; }
.members h3 {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
  color: var(--text-muted); padding: 16px 8px 4px;
}
.member {
  display: flex; align-items: center; gap: 12px; padding: 4px 8px;
  border-radius: 4px; cursor: pointer; height: 42px;
}
.member:hover { background: var(--hover-bg); }
.member.offline { opacity: .35; }
.member .mname { font-size: 16px; font-weight: 500; color: var(--text-normal); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .owner { color: var(--yellow); font-size: 12px; }

/* ================================================================
   Modals, menus, toasts
   ================================================================ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--modal-bg); border-radius: 5px; width: 100%; max-width: 440px;
  box-shadow: 0 8px 16px rgba(0,0,0,.24); overflow: hidden;
}
.modal.wide { max-width: 600px; }
.modal-head { padding: 24px 24px 0; }
.modal-head h2 { font-size: 24px; font-weight: 700; color: var(--text-header); text-align: center; }
.modal-head p { color: var(--text-muted); font-size: 16px; text-align: center; margin-top: 8px; }
.modal-body { padding: 16px 24px 24px; }
.modal-foot {
  background: #2b2d31; padding: 16px; display: flex; justify-content: flex-end; gap: 8px;
}
.btn {
  height: 38px; padding: 0 16px; border-radius: 3px; font-size: 14px; font-weight: 500;
  transition: background .15s;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { color: var(--text-normal); }
.btn.ghost:hover { text-decoration: underline; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: var(--red-hover); }
.invite-code {
  display: flex; align-items: center; gap: 8px; background: var(--floating);
  border-radius: 3px; padding: 10px; margin-top: 8px;
}
.invite-code code { flex: 1; font-family: var(--mono); font-size: 16px; color: var(--text-header); }
.select {
  width: 100%; height: 40px; background: var(--floating); border: 1px solid #1e1f22;
  border-radius: 3px; color: var(--text-normal); padding: 0 8px; font-size: 14px;
}

.menu {
  position: fixed; z-index: 300; background: var(--floating); border-radius: 4px;
  padding: 6px 8px; min-width: 188px; box-shadow: 0 8px 16px rgba(0,0,0,.24);
}
.menu.hidden { display: none; }
.menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 6px 8px; border-radius: 2px; font-size: 14px;
  color: var(--interactive-normal); text-align: left;
}
.menu button:hover { background: var(--brand); color: #fff; }
.menu button.danger { color: var(--red); }
.menu button.danger:hover { background: var(--red); color: #fff; }
.menu .sep { height: 1px; background: var(--border); margin: 4px 0; }

.emoji-picker {
  position: fixed; z-index: 300; background: var(--floating); border-radius: 8px;
  padding: 8px; width: 300px; box-shadow: 0 8px 16px rgba(0,0,0,.24);
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 260px; overflow-y: auto;
}
.emoji-picker.hidden { display: none; }
.emoji-picker button { font-size: 22px; padding: 4px; border-radius: 4px; line-height: 1; }
.emoji-picker button:hover { background: var(--hover-bg); }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--floating); color: var(--text-normal); padding: 10px 16px;
  border-radius: 6px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.4);
  animation: rise .2s ease;
}
.toast.error { border-left: 3px solid var(--red); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.lightbox.hidden { display: none; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; border-radius: 4px; }

.banner {
  background: var(--yellow); color: #1e1f22; font-size: 13px; font-weight: 500;
  padding: 6px 16px; text-align: center;
}
.banner.hidden { display: none; }

/* ================================================================
   Responsive — sidebars collapse on narrow screens
   ================================================================ */
.mobile-only { display: none; }

@media (max-width: 900px) {
  .members { display: none; }
}

@media (max-width: 640px) {
  :root { --rail-w: 60px; --sidebar-w: 220px; }
  .mobile-only { display: flex; }
  .rail, .sidebar { position: fixed; top: 0; bottom: 0; z-index: 50; transition: transform .2s ease; }
  .rail { left: 0; }
  .sidebar { left: var(--rail-w); }
  body.nav-closed .rail { transform: translateX(-100%); }
  body.nav-closed .sidebar { transform: translateX(calc(-100% - var(--rail-w))); }
  .main { margin-left: 0; width: 100%; }
  body:not(.nav-closed) .main::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40;
  }
  .msg { padding-right: 16px; }
  .attachments img, .attachments video { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- voice stage sharing space with the channel's text chat ---- */
.stage.visible ~ .messages { flex: 0 0 auto; max-height: 34vh; }
.chat-col.chat-hidden .messages,
.chat-col.chat-hidden .composer-wrap { display: none; }

/* ---- custom logo on the home button ---- */
.rail-btn.home.has-logo { background: var(--sidebar); padding: 0; overflow: hidden; }
.rail-btn.home.has-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rail-item:hover .rail-btn.home.has-logo { background: var(--sidebar); }

/* ---- user profile pictures ---- */
.avatar img {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; display: block;
}
.tile-avatar { overflow: hidden; }
.tile-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
