:root {
  --bg-0: #18191c;
  --bg-1: #232428;
  --bg-2: #2c2d32;
  --bg-3: #383a40;
  --hover: rgba(255, 255, 255, 0.05);
  --active: rgba(255, 255, 255, 0.1);
  --text: #e3e5e8;
  --muted: #9a9ea6;
  --accent: #6c7bff;
  --green: #2fbf71;
  --red: #e5484d;
  --radius: 8px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

#app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 230px;
  height: 100vh;
  height: 100dvh;
}

#channels-toggle { display: none; }
.channels-backdrop { display: none; }

@media (max-width: 760px) {
  body #app { grid-template-columns: minmax(0, 1fr); }
  #channels-toggle { display: grid; }
  #channels-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(290px, calc(100vw - 48px));
    z-index: 16;
    visibility: hidden;
    transform: translateX(-100%);
  }
  .channels-open #channels-sidebar { visibility: visible; transform: translateX(0); }
  .channels-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 15;
  }
}

/* ---------- shared ---------- */

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--muted);
  flex: none;
}
.icon-btn:hover {
  background: var(--active);
  color: var(--text);
}
.icon-btn.small {
  width: 20px;
  height: 20px;
}
.icon-btn.off {
  color: var(--red);
}
.icon-btn.danger:hover {
  color: var(--red);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  flex: none;
  user-select: none;
  transition: box-shadow 0.1s;
}
.avatar.sm {
  width: 22px;
  height: 22px;
  font-size: 11px;
}
.avatar.lg {
  width: 84px;
  height: 84px;
  font-size: 34px;
}

.category {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 8px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- sidebar ---------- */

.sidebar {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.server-header {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--bg-0);
}

.channel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.channel {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  margin: 1px 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
.channel:hover {
  background: var(--hover);
  color: var(--text);
}
.channel.active {
  background: var(--active);
  color: #fff;
}
.channel.connected {
  color: var(--green);
}
.channel.unread {
  color: #fff;
  font-weight: 600;
}
.channel.unread::before {
  content: '';
  position: absolute;
  left: -8px;
  width: 4px;
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: #fff;
}
.channel-icon {
  display: grid;
  opacity: 0.8;
}
.channel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-members {
  margin: 0 0 6px 26px;
}
.voice-member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--muted);
}
.voice-member.speaking .avatar {
  box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--green);
}
.member-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-badges {
  display: flex;
  align-items: center;
  gap: 4px;
}
.badge-icon {
  display: grid;
}
.badge-live {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
}

.voice-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--bg-0);
  background: var(--bg-1);
}
.voice-status-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}
.voice-status-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}
.voice-action {
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--bg-2);
  border-radius: 7px;
  color: var(--text);
}
.voice-action:hover:not(:disabled) { background: var(--bg-3); }
.voice-action.on { background: rgba(47, 191, 113, 0.16); color: var(--green); }
.voice-quality {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 7px;
  background: rgba(47, 191, 113, 0.08);
  color: var(--muted);
}
.voice-quality[data-level='3'] { color: var(--green); }
.voice-quality[data-level='2'] { color: #f0b232; }
.voice-quality[data-level='1'] { color: var(--red); }
.signal-bars { display: flex; align-items: flex-end; gap: 3px; height: 16px; }
.signal-bars i { width: 3px; height: 6px; border-radius: 1px; background: currentColor; opacity: 0.25; }
.signal-bars i:nth-child(2) { height: 11px; }
.signal-bars i:nth-child(3) { height: 16px; }
.voice-quality[data-level='1'] .signal-bars i:first-child,
.voice-quality[data-level='2'] .signal-bars i:nth-child(-n+2),
.voice-quality[data-level='3'] .signal-bars i { opacity: 1; }
.voice-quality-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  width: max-content;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--bg-0);
  color: var(--text);
  text-align: left;
  font-size: 12px;
  white-space: pre-line;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 41;
}
.voice-quality { cursor: pointer; }
.voice-quality.open .voice-quality-tooltip { display: none !important; }
.voice-quality:hover .voice-quality-tooltip,
.voice-quality:focus-visible .voice-quality-tooltip { display: block; animation: ui-fade var(--motion-fast) ease-out; }
.voice-status-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-width: 0;
  padding: 2px 4px;
  border-radius: 6px;
}
.voice-status-info:hover {
  background: var(--hover);
}
.voice-status-title {
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
}
.voice-status-channel {
  color: var(--muted);
  font-size: 12px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px;
  background: var(--bg-0);
}
.self {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px;
  border-radius: 6px;
  text-align: left;
}
.self:hover {
  background: var(--hover);
}
.self-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.main-header {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--bg-0);
}
.main-icon {
  display: grid;
  color: var(--muted);
}

.conn-banner {
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: 4px;
  font-size: 13px;
  font-weight: 600;
}
.update-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.update-banner button {
  padding: 2px 10px;
  border-radius: 4px;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
}

/* ---------- chat ---------- */

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
}

.channel-intro {
  padding: 16px 16px 24px;
}
.channel-intro h1 {
  margin: 0 0 4px;
  font-size: 28px;
}
.channel-intro p {
  margin: 0;
  color: var(--muted);
}

/* Text of every message (first in a group or not) starts at the same x:
   side padding + avatar + gap. */
.message {
  --msg-pad: 16px;
  --msg-avatar: 36px;
  --msg-gap: 14px;
  padding: 2px var(--msg-pad);
  margin-top: 14px;
  position: relative;
}
.message-main {
  display: flex;
  gap: var(--msg-gap);
}
.message.grouped {
  margin-top: 0;
  padding-left: calc(var(--msg-pad) + var(--msg-avatar) + var(--msg-gap));
}
.message:hover {
  background: rgba(0, 0, 0, 0.08);
}
.message .avatar {
  width: var(--msg-avatar);
  height: var(--msg-avatar);
  margin-top: 2px;
}
.msg-body {
  min-width: 0;
}
.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.msg-author {
  font-weight: 600;
}
.msg-time {
  font-size: 12px;
  color: var(--muted);
}
.msg-time-hover {
  position: absolute;
  left: var(--msg-pad);
  width: calc(var(--msg-avatar) + 4px);
  top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  visibility: hidden;
}
.message.grouped:hover .msg-time-hover {
  visibility: visible;
}
.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-text a {
  color: #4ea5ff;
}

.composer {
  padding: 0 16px 20px;
}
.composer-box {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  background: var(--bg-3);
  border-radius: var(--radius);
  padding: 4px 6px;
}
.composer-box .icon-btn {
  margin-top: 4px;
}
.composer textarea {
  flex: 1;
  width: 100%;
  resize: none;
  max-height: 40vh;
  background: transparent;
  color: var(--text);
  border: 0;
  padding: 10px 6px;
  font: inherit;
  outline: none;
}

/* ---------- voice stage ---------- */

.voice-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-0);
}

/* Column count and tile width are computed in JS (layoutStage) so the
   tiles fill the available space without scrolling. */
.stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(var(--cols, 1), var(--tile-w, 320px));
  justify-content: center;
  align-content: center;
}
.stage.has-focus {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
}
.stage.has-focus .tile {
  flex: none;
  width: 200px;
}
.stage.has-focus .tile:not(.focus) .avatar {
  width: 44px;
  height: 44px;
  font-size: 18px;
}
.stage.has-focus .tile.focus {
  flex: 1 0 100%;
  width: auto;
  height: calc(100% - 140px);
  aspect-ratio: auto;
}

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-2);
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color 0.1s;
}
.tile.speaking {
  outline-color: var(--green);
}
.tile.connecting {
  opacity: 0.55;
}
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.tile.screen video {
  object-fit: contain;
}
.tile.mirror video {
  transform: scaleX(-1);
}
.tile:not(.has-video) video {
  display: none;
}
.tile.has-video .avatar {
  display: none;
}
.tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 16px);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
  font-weight: 600;
}
.tile-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-label svg {
  color: var(--red);
  flex: none;
}
.tile-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.15s;
}
.tile-toolbar .icon-btn {
  color: #fff;
}
.tile:hover .tile-toolbar,
.tile:focus-within .tile-toolbar {
  opacity: 1;
}
@media (hover: none) {
  .tile-toolbar {
    opacity: 1; /* touch screens can't hover */
  }
}

/* zooming inside a screen share */
.tile.screen {
  touch-action: none; /* pinch zooms the stream, not the page */
}
.tile.screen video {
  transform-origin: 0 0;
}
.tile.screen.zoomed {
  cursor: grab;
}
.tile.screen.zoomed:active {
  cursor: grabbing;
}

.tile-problem {
  font-style: normal;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--red);
  color: #fff;
  flex: none;
}
.tile.failed {
  opacity: 0.8;
}
.tile:fullscreen {
  border-radius: 0;
}
.tile:fullscreen video {
  object-fit: contain;
}

.voice-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px 20px;
}
.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-3);
  color: var(--text);
}
.ctrl-btn:hover {
  filter: brightness(1.2);
}
.ctrl-btn.on {
  background: #fff;
  color: #111;
}
.ctrl-btn.off {
  background: rgba(229, 72, 77, 0.2);
  color: var(--red);
}
.ctrl-btn.danger {
  background: var(--red);
  color: #fff;
}

/* ---------- members ---------- */

.members {
  background: var(--bg-1);
  overflow-y: auto;
  padding: 0 8px;
}
.member-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--muted);
}
.member-list li:hover {
  background: var(--hover);
  color: var(--text);
}
.member-list li.away {
  opacity: 0.45;
}
.member-list .you {
  font-size: 12px;
  opacity: 0.7;
}

/* ---------- dialog + toasts ---------- */

.dialog {
  border: 0;
  border-radius: 12px;
  background: var(--bg-2);
  color: var(--text);
  padding: 24px;
  width: min(400px, calc(100vw - 32px));
}
.dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}
.dialog h2 {
  margin: 0 0 16px;
  font-size: 20px;
}
.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.dialog input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 0;
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
  outline: none;
}
.form-error {
  margin: -6px 0 16px;
  color: var(--red);
  font-size: 14px;
}
.primary,
.secondary,
.danger-btn {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-weight: 600;
}
.primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}
.primary.inline {
  width: auto;
}
.secondary:hover {
  text-decoration: underline;
}
.danger-btn {
  color: var(--red);
  padding-left: 0;
}
.danger-btn:hover {
  text-decoration: underline;
}
.primary:hover {
  filter: brightness(1.1);
}
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.spacer {
  flex: 1;
}

.channel-edit {
  margin-left: auto;
  width: 22px;
  height: 22px;
  opacity: 0;
}
.channel:hover .channel-edit,
.channel-edit:focus-visible {
  opacity: 1;
}

.history-loader {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
.toast {
  background: var(--bg-3);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: min(480px, calc(100vw - 32px));
}

@media (max-width: 1000px) {
  #app {
    grid-template-columns: 230px minmax(0, 1fr);
  }
  .members {
    display: none;
  }
}

/* ---------- shared bits ---------- */

.muted {
  color: var(--muted);
}
.small {
  font-size: 12px;
}
.notice {
  background: rgba(108, 123, 255, 0.12);
  border: 1px solid rgba(108, 123, 255, 0.35);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
}
.link-btn {
  color: #4ea5ff;
  padding: 0;
}
.link-btn:hover {
  text-decoration: underline;
}
.link-btn:disabled {
  color: var(--muted);
  text-decoration: none;
}
.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--bg-3);
  font-weight: 600;
  font-size: 14px;
}
.secondary-btn:hover:not(:disabled) {
  filter: brightness(1.2);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 0;
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
}
.owner-badge {
  display: inline-grid;
  color: #f0b232;
  flex: none;
}

/* ---------- auth ---------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, #2e335c, var(--bg-0) 60%);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--bg-2);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.auth-form h1 {
  margin: 0 0 4px;
  font-size: 24px;
}
.auth-form > p {
  margin: 0 0 18px;
}
.auth-form input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 0;
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
  outline: none;
}
.auth-form .form-error {
  margin: 0 0 16px;
}
.auth-form > p.auth-switch {
  margin: 16px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- user panel ---------- */

.self-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.self-username {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- members panel ---------- */

.member-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.member-list li.away {
  opacity: 0.6;
}
.member-list li.offline {
  opacity: 0.4;
}
.badge-icon.server {
  color: var(--red);
}
.badge-icon.local {
  color: #f0b232;
}

/* ---------- messages: actions + attachments ---------- */

.msg-actions {
  position: absolute;
  top: -12px;
  right: 16px;
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--bg-0);
  border-radius: 6px;
  padding: 2px;
}
.message:hover .msg-actions {
  display: flex;
}
.msg-actions .icon-btn {
  width: 28px;
  height: 28px;
}
.msg-actions .danger-hover:hover {
  color: var(--red);
}
.emoji-quick {
  font-size: 16px;
  color: inherit;
}

/* someone replied to you */
.message.mentions-me {
  background: rgba(240, 178, 50, 0.08);
  box-shadow: inset 2px 0 0 #f0b232;
}
.message.mentions-me:hover {
  background: rgba(240, 178, 50, 0.12);
}
/* the message you're replying to */
.message.replying {
  background: rgba(108, 123, 255, 0.1);
  box-shadow: inset 2px 0 0 var(--accent);
}
/* jumped to from a reply */
.message.flash {
  animation: flash 1.6s ease-out;
}
@keyframes flash {
  0%,
  30% {
    background: rgba(108, 123, 255, 0.28);
  }
  100% {
    background: transparent;
  }
}

.avatar.xs {
  width: 16px;
  height: 16px;
  font-size: 9px;
  margin-top: 0;
}
.reply-ref {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px 18px;
  padding-left: 32px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  min-width: 0;
}
.reply-ref::before {
  /* the curved line from the avatar up to the quoted message */
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 26px;
  height: 12px;
  border-left: 2px solid var(--bg-3);
  border-top: 2px solid var(--bg-3);
  border-top-left-radius: 6px;
}
.reply-ref .avatar.xs {
  width: 16px;
  height: 16px;
}
.reply-author {
  font-weight: 600;
  color: var(--text);
  flex: none;
}
.reply-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-ref:hover .reply-text {
  color: var(--text);
}
.reply-ref.deleted {
  font-style: italic;
  cursor: default;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--bg-1);
  border: 1px solid transparent;
  font-size: 14px;
}
.reaction:hover {
  border-color: var(--bg-3);
}
.reaction.mine {
  background: rgba(108, 123, 255, 0.18);
  border-color: var(--accent);
}
.reaction-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.reaction.mine .reaction-count {
  color: #c9cfff;
}
.reaction.add {
  color: var(--muted);
  opacity: 0;
}
.message:hover .reaction.add {
  opacity: 1;
}

.emoji-picker {
  position: fixed;
  z-index: 40;
  width: 320px;
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-0);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.emoji-section {
  padding: 4px 4px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin-bottom: 6px;
}
.emoji-btn {
  height: 36px;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
}
.emoji-btn:hover {
  background: var(--bg-3);
}

.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  background: var(--bg-1);
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 14px;
  color: var(--muted);
}
.reply-bar strong {
  color: var(--text);
}
.reply-bar:not([hidden]) + .composer-box {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.message .msg-body {
  min-width: 0;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.attachment {
  border-radius: var(--radius);
  overflow: hidden;
  max-width: min(420px, 100%);
}
.attachment.image {
  padding: 0;
  background: var(--bg-0);
  cursor: zoom-in;
}
.attachment.image img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
}
.attachment.video {
  display: block;
  max-height: 340px;
  background: #000;
}
.attachment.audio,
.attachment.file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-1);
  border: 1px solid var(--bg-0);
  padding: 10px 12px;
  width: 420px;
}
.attachment.audio {
  flex-direction: column;
  align-items: stretch;
}
.attachment.audio audio {
  width: 100%;
}
.attachment.expired {
  opacity: 0.6;
}
.file-icon {
  display: grid;
  color: var(--muted);
  flex: none;
}
.file-info {
  flex: 1;
  min-width: 0;
}
.file-name {
  display: block;
  color: #4ea5ff;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.attachment.expired .file-name,
.attachment.audio .file-name {
  color: var(--text);
}
.file-meta {
  font-size: 12px;
  color: var(--muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 76px 24px 20px;
  cursor: zoom-out;
}
.lightbox-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
}
.lightbox img {
  flex: none;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}
.lightbox.zoomed img {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}
.lightbox-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--bg-3);
  border-radius: 12px;
  background: var(--bg-1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  cursor: default;
}
.lightbox-toolbar .icon-btn,
.lightbox-close {
  width: 36px;
  height: 36px;
  color: var(--text);
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--bg-1);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
}
.lightbox-caption {
  flex: none;
  align-self: center;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 14px;
  cursor: default;
}

/* ---------- composer uploads ---------- */

.chat-view {
  position: relative;
}
.upload-tray {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  margin-bottom: 6px;
  background: var(--bg-1);
  border-radius: var(--radius);
}
.upload-chip {
  position: relative;
  flex: none;
  width: 150px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--bg-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upload-chip img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
}
.upload-chip .file-icon {
  height: 80px;
  place-items: center;
}
.upload-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-meta {
  font-size: 11px;
  color: var(--muted);
}
.upload-progress {
  height: 3px;
  background: var(--bg-0);
  border-radius: 2px;
  overflow: hidden;
}
.upload-progress div {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}
.upload-chip.done .upload-progress div {
  background: var(--green);
}
.upload-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
}
.upload-remove:hover {
  background: var(--red);
}
.drop-overlay {
  position: absolute;
  inset: 8px;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: rgba(24, 25, 28, 0.85);
  font-size: 20px;
  font-weight: 700;
  pointer-events: none;
}

/* ---------- context menu ---------- */

.menu {
  position: fixed;
  z-index: 40;
  min-width: 220px;
  max-width: 280px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 6px;
  background: var(--bg-0);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.menu-header {
  padding: 6px 8px 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.menu-separator {
  height: 1px;
  margin: 4px 6px;
  background: var(--bg-3);
}
.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 4px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover {
  background: var(--accent);
  color: #fff;
}
.menu-item:hover span {
  color: inherit !important;
}
.menu-item.danger {
  color: var(--red);
}
.menu-item.danger:hover {
  background: var(--red);
  color: #fff;
}
.menu-toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}
.menu-slider {
  padding: 6px 8px 8px;
}
.menu-slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 6px;
}
.menu-slider-value {
  color: var(--muted);
}
.menu-slider input {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- settings ---------- */

.settings {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(0, 3fr);
  background: var(--bg-2);
}
.settings-nav {
  background: var(--bg-1);
  display: flex;
  justify-content: flex-end;
  overflow-y: auto;
}
.settings-nav-inner {
  width: 220px;
  padding: 48px 8px 24px;
}
.settings-group {
  padding: 12px 10px 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-tab {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  margin: 1px 0;
  border-radius: 6px;
  color: var(--muted);
}
.settings-tab:hover {
  background: var(--hover);
  color: var(--text);
}
.settings-tab.active {
  background: var(--active);
  color: #fff;
}
.settings-tab.danger {
  color: var(--red);
}
.settings-separator {
  height: 1px;
  margin: 8px 10px;
  background: var(--bg-3);
}
.settings-content {
  position: relative;
  overflow-y: auto;
}
.settings-inner {
  max-width: 740px;
  padding: 48px 40px 64px;
}
.settings-inner h2 {
  margin: 0 0 20px;
  font-size: 20px;
}
.settings-inner h3 {
  margin: 28px 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.settings-inner input:not([type='checkbox']):not([type='range']):not([type='color']) {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 0;
  background: var(--bg-0);
  color: var(--text);
  font: inherit;
  outline: none;
}
.settings-inner input:disabled {
  opacity: 0.6;
}
.settings-inner input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}
.settings-close {
  position: fixed;
  top: 40px;
  right: 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
  color: var(--muted);
}
.settings-close:hover {
  color: var(--text);
  border-color: var(--text);
}
.settings-form {
  margin-bottom: 8px;
}
.profile-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin-bottom: 20px;
  background: var(--bg-1);
  border-radius: 12px;
}
.profile-name {
  font-size: 20px;
  font-weight: 700;
}
.role-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.role-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-3);
  font-size: 12px;
}
.role-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-3);
  cursor: pointer;
}
.toggle-row.disabled {
  opacity: 0.55;
  cursor: default;
}
.toggle-label {
  font-weight: 600;
}
.switch {
  appearance: none;
  flex: none;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 12px;
  background: #72767d;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch:checked {
  background: var(--green);
}
.switch:checked::after {
  transform: translateX(16px);
}
.switch:disabled {
  cursor: default;
}

/* ---------- status dots ---------- */

.avatar-wrap {
  position: relative;
  display: inline-flex;
  flex: none;
}
/* --ring is the background behind the avatar, used to "cut out" the dot. */
.members {
  --ring: var(--bg-1);
}
.user-panel,
.menu {
  --ring: var(--bg-0);
}
.status-dot {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--ring);
  background: #80848e;
  box-sizing: border-box;
}
.status-dot.inline {
  position: relative;
  right: auto;
  bottom: auto;
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 0;
}
.status-dot.online {
  background: var(--green);
}
.status-dot.idle {
  background: #f0b232;
}
/* crescent moon: a ring-colored circle bites the top-left */
.status-dot.idle::after {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ring);
}
.status-dot.inline.idle::after {
  top: -2px;
  left: -2px;
  width: 8px;
  height: 8px;
}
.status-dot.dnd {
  background: var(--red);
}
/* white-ish bar across the middle */
.status-dot.dnd::after {
  content: '';
  position: absolute;
  left: 1px;
  right: 1px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  border-radius: 1px;
  background: var(--ring);
}
.status-dot.inline.dnd::after {
  left: 2px;
  right: 2px;
  height: 3px;
  margin-top: -1.5px;
}
/* hollow grey ring */
.status-dot.offline,
.status-dot.invisible {
  background: var(--ring);
  box-shadow: inset 0 0 0 2px #80848e;
}
.status-dot.inline.offline,
.status-dot.inline.invisible {
  box-shadow: inset 0 0 0 3px #80848e;
}

.menu-option {
  justify-content: flex-start;
  align-items: flex-start;
  gap: 10px;
}
.menu-option-icon {
  display: grid;
  place-items: center;
  width: 16px;
  height: 20px;
  flex: none;
}
.menu-option-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.menu-option-label {
  font-weight: 600;
}
.menu-option-desc {
  font-size: 12px;
  color: var(--muted);
}
.menu-option:hover .menu-option-desc {
  color: inherit;
}
.menu-option.selected {
  background: var(--active);
}
.menu-option:hover {
  --ring: var(--accent);
}

/* ---------- profile pictures ---------- */

img.avatar.has-picture {
  display: block;
  object-fit: cover;
  background: var(--bg-3);
}
.avatar.xl {
  width: 80px;
  height: 80px;
  font-size: 32px;
}
.avatar-wrap.sm .status-dot {
  width: 11px;
  height: 11px;
  border-width: 2px;
  right: -2px;
  bottom: -2px;
}
.msg-avatar-btn {
  padding: 0;
  border-radius: 50%;
  flex: none;
  align-self: flex-start;
}
.msg-author {
  cursor: pointer;
}
.msg-author:hover {
  text-decoration: underline;
}
.profile-card-text {
  flex: 1;
  min-width: 0;
}
.avatar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

/* ---------- direct messages ---------- */

.dm-item .avatar-wrap {
  margin-right: 2px;
}
.unread-pill {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.dm-empty {
  margin: 0 8px 4px;
  font-size: 12px;
  color: var(--muted);
}
.main-subtitle {
  margin-left: 10px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}
#main-icon .avatar-wrap {
  margin-right: 2px;
}
.dm-intro .avatar {
  margin-bottom: 10px;
}

/* ---------- member list: custom status under the name ---------- */

.member-list li {
  cursor: pointer;
}
.member-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.member-activity {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- profile card ---------- */

.profile-pop {
  --ring: var(--bg-0);
  position: fixed;
  z-index: 43;
  width: min(300px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  border-radius: 10px;
  background: var(--bg-0);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  animation: ui-fade 0.12s ease-out;
}
.pc-banner {
  height: 60px;
  border-radius: 10px 10px 0 0;
  filter: saturate(0.85) brightness(0.8);
}
.pc-avatar {
  position: relative;
  width: 88px;
  height: 88px;
  margin: -44px 0 0 14px;
  padding: 4px;
  border-radius: 50%;
  background: var(--bg-0);
}
.pc-avatar .status-dot {
  width: 22px;
  height: 22px;
  border-width: 4px;
  right: 2px;
  bottom: 2px;
}
.pc-body {
  padding: 6px 14px 14px;
}
.pc-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 700;
}
.pc-username {
  margin-bottom: 10px;
  font-size: 13px;
}
.pc-custom {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-1);
  font-size: 14px;
}
.pc-activity {
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg-1);
}
.pc-activity-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
  font-weight: 600;
}
.pc-activity-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--muted);
}
.pc-activity .primary {
  margin-top: 2px;
}
.pc-label {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.pc-section {
  margin-bottom: 10px;
  font-size: 14px;
}
.pc-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pc-message {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  background: var(--bg-1);
  color: var(--text);
  font: inherit;
  outline: none;
}
.pc-message:focus {
  border-color: var(--accent);
}

/* ---------- connection panel (click the signal bars) ---------- */

.conn-panel {
  position: fixed;
  z-index: 42;
  width: min(320px, calc(100vw - 16px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 14px 16px 12px;
  border-radius: 10px;
  background: var(--bg-0);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  font-size: 13px;
}
.conn-panel-title {
  display: inline-block;
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  color: #c9cfff;
  font-weight: 700;
}
.conn-graph {
  padding: 8px 6px 4px;
  margin-bottom: 10px;
  border-radius: 6px;
  background: var(--bg-1);
}
.conn-graph svg {
  display: block;
  overflow: visible;
}
.conn-graph .grid {
  stroke: var(--bg-3);
  stroke-width: 1;
}
.conn-graph .ping {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.conn-graph .dot {
  fill: var(--accent);
}
.conn-graph text {
  fill: var(--muted);
  font-size: 9px;
}
.conn-panel-heading {
  font-weight: 700;
  font-size: 14px;
}
.conn-quality {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
}
.conn-quality.level-3 {
  color: var(--green);
}
.conn-quality.level-2 {
  color: #f0b232;
}
.conn-quality.level-1 {
  color: var(--red);
}
.conn-quality.level-0 {
  color: var(--muted);
}
.conn-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  margin: 0 0 8px;
}
.conn-stats dt {
  color: var(--text);
}
.conn-stats dd {
  margin: 0;
  font-weight: 700;
}
.conn-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}
.conn-panel-subtitle {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.conn-peers {
  margin-bottom: 10px;
}
.conn-peer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.conn-peer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn-route {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-3);
  font-size: 11px;
  font-weight: 600;
}
.conn-route.direct {
  color: var(--green);
}
.conn-route.relay {
  color: #f0b232;
}
.conn-route.failed {
  background: var(--red);
  color: #fff;
}
.conn-actions {
  margin-bottom: 10px;
}
.conn-actions .secondary-btn {
  width: 100%;
  justify-content: center;
}
.conn-encrypted {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(47, 191, 113, 0.1);
  color: var(--green);
  font-size: 12px;
}

.mic-test {
  display: flex;
  align-items: center;
  gap: 16px;
}
.mic-test button {
  flex: none;
}
.mic-meter {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--bg-0);
  overflow: hidden;
}
.mic-meter-fill {
  width: 0;
  height: 100%;
  background: #72767d;
  transition: width 0.05s linear;
}
.mic-meter-fill.loud {
  background: var(--green);
}

.storage-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-0);
  overflow: hidden;
}
.storage-bar div {
  height: 100%;
  background: var(--accent);
}

.roles-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.role-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.role-list .secondary-btn {
  margin-bottom: 8px;
}
.role-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  text-align: left;
  color: var(--muted);
}
.role-row span:nth-child(2) {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.role-row:hover {
  background: var(--hover);
  color: var(--text);
}
.role-row.active {
  background: var(--active);
  color: #fff;
}
.role-editor .notice {
  margin-top: 0;
}
.role-editor-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
}
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
}
.color-row input[type='color'] {
  width: 48px;
  height: 36px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.role-editor .dialog-actions {
  margin-top: 20px;
}

.member-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.member-row {
  border-radius: var(--radius);
  background: var(--bg-1);
}
.member-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.member-row-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  font-weight: 600;
}
.member-row-main .role-chips {
  margin: 0;
  justify-content: flex-end;
}
.member-row-details {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 4px 12px 12px 56px;
}
.role-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.role-check input {
  accent-color: var(--accent);
}
.member-row-details .danger-btn {
  margin-left: auto;
  padding: 6px 0;
}

@media (max-width: 760px) {
  .settings {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .settings-nav-inner {
    width: 100%;
    padding: 16px 8px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .settings-group,
  .settings-separator {
    display: none;
  }
  .settings-tab {
    width: auto;
  }
  .settings-inner {
    padding: 24px 16px 48px;
  }
  .settings-close {
    top: 12px;
    right: 12px;
  }
  .roles-layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- subtle interaction feedback ---------- */

:root {
  --motion-fast: 120ms;
  --motion-open: 180ms;
  --motion-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

:where(button, [role='button'], a.icon-btn):not(.channels-backdrop) {
  transition: background-color var(--motion-fast), color var(--motion-fast),
    box-shadow var(--motion-fast), filter var(--motion-fast),
    scale var(--motion-fast) var(--motion-ease);
}

:where(button, [role='button'], a.icon-btn):not(.channels-backdrop):not(.attachment.image):not(:disabled):active {
  scale: 0.98;
}

:where(button, [role='button'], a.icon-btn):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.composer-box,
.auth-form input,
.dialog input,
.settings-inner input:not([type='checkbox']):not([type='range']):not([type='color']),
select {
  transition: box-shadow var(--motion-fast);
}

.composer-box:focus-within,
.auth-form input:focus-visible,
.dialog input:focus-visible,
.settings-inner input:focus-visible,
select:focus-visible {
  box-shadow: 0 0 0 2px rgba(108, 123, 255, 0.3);
}

.channel-edit,
.msg-actions {
  transition: opacity var(--motion-fast);
}

.attachment.image {
  transition: box-shadow var(--motion-fast), filter var(--motion-fast);
}

@media (hover: hover) {
  .attachment.image:hover {
    box-shadow: 0 0 0 2px rgba(108, 123, 255, 0.25);
    filter: brightness(1.04);
  }
}

/* Animate openings only: content refreshes and incoming messages stay still. */
.menu,
.emoji-picker,
.toast,
.auth-card,
.dialog[open] {
  animation: ui-reveal var(--motion-open) var(--motion-ease);
}

.settings:not([hidden]),
.lightbox:not([hidden]),
.channels-backdrop:not([hidden]),
.dialog[open]::backdrop {
  animation: ui-fade var(--motion-open) ease-out;
}

.lightbox:not([hidden]) img {
  animation: image-reveal 200ms var(--motion-ease);
}

.lightbox.closing:not([hidden]) {
  pointer-events: none;
  animation: image-viewer-out 160ms ease-in both;
}

.lightbox.closing:not([hidden]) img {
  animation: image-dismiss 160ms ease-in both;
}

@keyframes image-viewer-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes image-dismiss {
  from { transform: scale(1); }
  to { transform: scale(0.985); }
}

@keyframes ui-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ui-reveal {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes image-reveal {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 760px) {
  #channels-sidebar {
    transition: transform var(--motion-open) var(--motion-ease),
      visibility 0s var(--motion-open);
  }
  .channels-open #channels-sidebar {
    transition-delay: 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  :where(button, [role='button'], a.icon-btn):active {
    scale: none !important;
  }
}
