/* Theme, shared elements, and feature styles. Responsive overrides are grouped at the end. */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --muted: color-mix(in srgb, var(--on-surface) 65%, var(--outline));
  --rail: color-mix(in srgb, var(--background) 75%, black);
  --sidebar: color-mix(in srgb, var(--background) 45%, var(--surface));
  --chat: color-mix(in srgb, var(--surface) 65%, var(--surface-hover));
}

body {
  margin: 0;
  background: var(--background);
  color: var(--on-surface);
  font:
    15px/1.5 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
}

button,
.button-label {
  border: 0;
  border-radius: 5px;
  padding: 8px 14px;
  background: var(--primary);
  color: var(--on-primary);
  cursor: pointer;
  font-weight: 600;
  transition:
    background 0.15s,
    color 0.15s;
}

button:hover,
.button-label:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.secondary {
  background: var(--surface-hover);
  color: var(--on-surface);
}

input,
textarea {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 10px 12px;
  background: var(--background);
  color: var(--on-surface);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
.button-label:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

a {
  color: var(--primary);
  text-decoration: none;
  overflow-wrap: anywhere;
}

a:hover {
  text-decoration: underline;
}

small,
.muted {
  color: var(--muted);
}

.auth-panel {
  width: min(440px, calc(100% - 32px));
  margin: 8vh auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--surface-hover);
  border-radius: 12px;
  box-shadow: 0 24px 70px #0004;
}

.auth-panel h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 8px;
}

.auth-panel p {
  margin: 12px 0;
  color: var(--muted);
}

.auth-panel label {
  display: block;
  margin: 16px 0 6px;
  font-weight: 600;
  font-size: 13px;
}

.auth-panel label input {
  display: block;
  width: 100%;
  margin-top: 7px;
}

.auth-panel small {
  font-size: 11px;
}

#auth-form button {
  margin-top: 16px;
  width: 100%;
}

#auth-status {
  color: var(--primary);
}

.chat-layout {
  display: grid;
  grid-template-columns: 72px 248px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.server-rail {
  background: var(--rail);
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
}

.home-button {
  height: 48px;
  width: 48px;
  border-radius: 16px;
  font-size: 29px;
  padding: 0;
  position: relative;
}

.home-button::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 10px;
  height: 28px;
  width: 4px;
  background: var(--on-surface);
  border-radius: 0 4px 4px 0;
}

.rail-divider {
  width: 32px;
  height: 2px;
  background: var(--surface-hover);
}

.rail-lock {
  color: var(--primary);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: var(--surface);
  border-radius: 50%;
  font-size: 30px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  min-height: 0;
}

.sidebar-heading {
  height: 65px;
  flex-shrink: 0;
  padding: 12px 18px;
  box-shadow: 0 1px 3px #0004;
  font-weight: 750;
  font-size: 16px;
}

.tiny-label {
  display: block;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-top: 1px;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 10px 10px;
  text-align: left;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
}

.nav-button span {
  font-size: 15px;
}

.selected,
.nav-button.selected {
  background: var(--surface-hover);
  color: var(--on-surface);
}

.badge {
  margin-left: auto;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 11px !important;
  padding: 0 6px;
  border-radius: 10px;
}

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.7px;
  color: var(--muted);
}

.sidebar .dm-section-heading {
  padding: 8px 17px 4px;
}

.icon-button {
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  font-size: 23px;
  padding: 2px 6px;
  font-weight: 400;
  line-height: 1.3;
}

.icon-button:hover {
  color: var(--on-surface);
  background: var(--surface-hover);
}

.dm-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px;
}

.dm-button {
  display: flex;
  width: 100%;
  gap: 11px;
  align-items: center;
  padding: 8px;
  margin-bottom: 3px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 500;
}

.dm-button:hover {
  background: var(--surface);
  color: var(--on-surface);
}

.dm-button.selected {
  background: var(--surface-hover);
  color: var(--on-surface);
}

.dm-button span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 14px 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 750;
  vertical-align: middle;
  position: relative;
  overflow: visible;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar.large {
  height: 78px;
  width: 78px;
  font-size: 28px;
}

.account-bar {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 8px;
  gap: 2px;
  background: #0002;
}

.account-profile {
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  color: var(--on-surface);
  text-align: left;
  min-width: 0;
  flex: 1;
  padding: 4px;
}

.account-profile > span:last-child {
  min-width: 0;
}

.account-profile strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-profile small {
  font-size: 10px;
  font-weight: 400;
  display: block;
}

.workspace {
  background: var(--chat);
  position: relative;
  min-width: 0;
  min-height: 0;
}

.friends-view,
.conversation {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.friends-header,
.conversation-header {
  min-height: 65px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 10px 24px;
  gap: 14px;
  border-bottom: 1px solid #0003;
  box-shadow: 0 1px 2px #0002;
}

.friends-header h2,
.conversation-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.friends-header h2 {
  padding-right: 20px;
  border-right: 1px solid var(--outline);
  white-space: nowrap;
}

.tab-list {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tab {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 4px 10px;
}

.tab.active {
  background: var(--surface-hover);
  color: var(--on-surface);
}

.add-friend {
  font-size: 13px;
  padding: 5px 10px;
}

.friends-content {
  padding: 28px 32px;
  overflow-y: auto;
  flex: 1;
}

#add-friend-panel {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--surface-hover);
  margin-bottom: 24px;
}

#add-friend-panel h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

#add-friend-panel p {
  font-size: 13px;
  color: var(--muted);
}

.add-friend-form {
  display: flex;
  align-items: center;
  padding: 7px;
  border: 1px solid var(--outline);
  background: var(--background);
  border-radius: 8px;
  gap: 10px;
  margin-top: 20px;
}

.add-friend-form:focus-within {
  border-color: var(--primary);
}

.add-friend-form input {
  flex: 1;
  border: 0;
  background: transparent;
}

.add-friend-form button {
  font-size: 13px;
  white-space: nowrap;
}

#friends-label {
  margin-bottom: 14px;
}

.friend-row {
  border-top: 1px solid #ffffff0c;
  padding: 14px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.friend-row:hover {
  background: var(--surface-hover);
  border-radius: 7px;
}

.friend-identity {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.friend-identity strong {
  overflow-wrap: anywhere;
}

.friend-identity small {
  display: block;
  font-size: 12px;
}

.friend-actions {
  display: flex;
  gap: 8px;
}

.friend-actions button {
  font-size: 12px;
}

.empty-state {
  text-align: center;
  margin: 10vh auto 0;
  color: var(--muted);
  max-width: 380px;
}

.empty-icon {
  font-size: 62px;
  color: var(--primary);
  background: var(--surface);
  width: 126px;
  height: 126px;
  display: grid;
  place-items: center;
  margin: 0 auto 24px;
  border-radius: 36px;
  transform: rotate(-5deg);
}

.empty-state h2 {
  font-size: 20px;
  color: var(--on-surface);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
}

.friends-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 32px 24px;
  padding-top: 20px;
  border-top: 1px solid #ffffff0c;
  color: var(--muted);
  font-size: 13px;
}

.friends-footer > span {
  font-size: 34px;
  color: var(--primary);
}

.friends-footer small {
  font-size: 12px;
}

.conversation-header p {
  color: var(--muted);
  font-size: 11px;
}

.key-details {
  margin-left: auto;
  font-size: 12px;
  position: relative;
}

.key-details summary {
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.key-popover {
  position: absolute;
  right: 0;
  top: 28px;
  width: 320px;
  max-width: 80vw;
  border: 1px solid var(--outline);
  background: var(--sidebar);
  box-shadow: 0 8px 30px #0006;
  border-radius: 8px;
  padding: 16px;
  z-index: 5;
}

.key-popover pre {
  white-space: pre-wrap;
  font-size: 11px;
}

main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 0 8px;
  scrollbar-color: var(--rail) transparent;
  scrollbar-width: thin;
}

.conversation-welcome {
  padding: 14px 24px 28px;
  border-bottom: 1px solid #ffffff0b;
  margin-bottom: 12px;
}

.conversation-welcome h2 {
  font-size: 30px;
  margin-top: 16px;
}

.conversation-welcome p {
  color: var(--muted);
  margin-top: 5px;
  font-size: 14px;
}

.message {
  display: flex;
  align-items: start;
  gap: 16px;
  padding: 2px 24px;
  position: relative;
}

.message:not(.grouped) {
  margin-top: 14px;
}

.message:hover {
  background: #00000012;
}

.message > .avatar {
  margin-top: 3px;
  height: 40px;
  width: 40px;
}

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

.message-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}

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

.message time {
  color: var(--muted);
  font-size: 10px;
}

.message-content {
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.message-content p {
  white-space: pre-wrap;
}

.message-content strong {
  font-weight: 750;
}

.message-content h3 {
  font-size: 22px;
}

.message-content h4 {
  font-size: 19px;
}

.message-content h5 {
  font-size: 16px;
}

.message-content ul {
  padding-left: 22px;
  margin: 4px 0;
}

.message-content blockquote {
  margin: 3px 0;
  border-left: 3px solid var(--outline);
  padding: 2px 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.message-content code {
  background: var(--sidebar);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 13px;
  white-space: pre-wrap;
}

.message-content pre {
  margin: 5px 0;
  padding: 12px;
  border: 1px solid #0003;
  background: var(--sidebar);
  border-radius: 6px;
  overflow-x: auto;
}

.message-content pre code {
  padding: 0;
  white-space: pre;
}

.link-embed {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--sidebar);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  padding: 12px 16px;
  margin-top: 8px;
  width: fit-content;
  max-width: min(480px, 100%);
}

.link-embed small {
  font-size: 11px;
}

.link-embed > a {
  font-weight: 600;
}

.link-embed button {
  font-size: 12px;
  margin-top: 8px;
}

.attachment-card {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  background: var(--sidebar);
  border: 1px solid #ffffff0c;
}

.attachment-image {
  display: block;
  max-width: min(440px, 100%);
  max-height: 340px;
  object-fit: contain;
  border-radius: 5px;
}

.attachment-card video {
  max-width: min(440px, 100%);
  max-height: 340px;
  display: block;
}

.attachment-card audio {
  max-width: 100%;
  display: block;
}

.attachment-info {
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

.attachment-info small {
  font-size: 11px;
}

.composer-area {
  margin: 10px 24px 12px;
  position: relative;
}

:is(#message-form, #server-message-form) {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface-hover);
  border-radius: 9px;
  padding: 10px 12px;
}

:is(#message-form, #server-message-form).dragging {
  outline: 2px dashed var(--primary);
}

:is(#message, #server-message) {
  flex: 1;
  min-width: 0;
  resize: none;
  height: 28px;
  min-height: 28px;
  max-height: 180px;
  overflow-y: auto;
  background: transparent;
  padding: 2px 0;
  line-height: 24px;
  border: 0;
  border-radius: 0;
}

:is(#message, #server-message):focus {
  outline: 0;
}

:is(#attach, #server-attach),
:is(#emoji-toggle, #server-emoji-toggle) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 4px;
  color: var(--muted);
}
:is(#attach, #server-attach):hover:not(:disabled),
:is(#emoji-toggle, #server-emoji-toggle):hover:not(:disabled) {
  color: var(--on-surface);
  background: transparent;
}
:is(#attach, #server-attach) svg,
:is(#emoji-toggle, #server-emoji-toggle) svg {
  display: block;
}
:is(#emoji-toggle, #server-emoji-toggle):hover:not(:disabled) svg {
  transform: scale(1.08);
}

:is(#send, #server-send) {
  padding: 4px 9px;
  font-size: 18px;
  background: transparent;
  color: var(--primary);
}

.composer-hint {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 7px 3px 0;
  color: var(--muted);
  font-size: 10px;
}

.attachment-preview {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border-radius: 9px 9px 0 0;
  overflow-x: auto;
}

.pending-attachment {
  position: relative;
  padding: 10px;
  border-radius: 7px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 120px;
  max-width: 200px;
}

.pending-attachment img {
  width: 130px;
  height: 85px;
  object-fit: cover;
  border-radius: 4px;
}

.pending-attachment span {
  font-size: 11px;
  overflow-wrap: anywhere;
  padding-right: 22px;
}

.pending-attachment button {
  position: absolute;
  top: 3px;
  right: 3px;
  background: var(--rail);
  font-size: 15px;
}

.emoji-picker {
  position: absolute;
  right: 0;
  bottom: 90px;
  width: 310px;
  max-width: 85vw;
  padding: 12px;
  border: 1px solid var(--outline);
  border-radius: 9px;
  background: var(--sidebar);
  box-shadow: 0 10px 40px #0006;
  z-index: 6;
}

.emoji-picker input {
  width: 100%;
  margin-bottom: 10px;
}

:is(#emoji-grid, #server-emoji-grid) {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}

:is(#emoji-grid, #server-emoji-grid) button {
  padding: 4px;
  font-size: 23px;
  background: transparent;
}

:is(#emoji-grid, #server-emoji-grid) button:hover {
  background: var(--surface-hover);
}

.status-toast {
  position: absolute;
  bottom: 105px;
  left: 24px;
  right: 24px;
  width: fit-content;
  max-width: calc(100% - 48px);
  padding: 10px 16px;
  border: 1px solid var(--outline);
  background: var(--rail);
  color: var(--primary);
  border-radius: 8px;
  box-shadow: 0 4px 20px #0004;
  z-index: 8;
  font-size: 13px;
  overflow-wrap: anywhere;
}

dialog {
  background: var(--chat);
  color: var(--on-surface);
  border: 1px solid var(--outline);
  border-radius: 12px;
  padding: 24px;
  width: min(420px, 90vw);
  text-align: center;
}

dialog::backdrop {
  background: #0009;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dialog-heading h2 {
  font-size: 20px;
}

.profile-avatar {
  margin-bottom: 12px;
}

#profile-username {
  font-size: 20px;
  font-weight: 700;
}

dialog .muted {
  font-size: 13px;
  margin: 14px 0 24px;
}

.button-label {
  display: inline-block;
  font-size: 13px;
}

#remove-avatar {
  font-size: 13px;
}

#profile-status {
  color: var(--primary);
  margin-top: 16px;
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Consecutive messages share a header; their timestamps appear on hover/focus. */

.message.grouped {
  padding-top: 2px;
  padding-bottom: 2px;
  padding-left: 80px;
}

.grouped-time {
  position: absolute;
  left: 8px;
  top: 5px;
  width: 63px;
  text-align: right;
  opacity: 0;
  font-size: 9px !important;
}

.message.grouped:hover .grouped-time,
.message.grouped:focus-within .grouped-time {
  opacity: 1;
}

.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 3px solid var(--sidebar);
  background: var(--outline);
}

.presence-dot.online {
  background: #59b984;
}

.presence-dot.dnd {
  background: #df706d;
}

.presence-dot.dnd::after {
  content: '';
  position: absolute;
  height: 2px;
  width: 5px;
  background: var(--sidebar);
  left: 1px;
  top: 2px;
}

.presence-dot.offline {
  background: var(--chat);
  box-shadow: inset 0 0 0 2px var(--muted);
}

.avatar.large .presence-dot {
  width: 20px;
  height: 20px;
  border-width: 4px;
}

.avatar.large .presence-dot.dnd::after {
  width: 8px;
  top: 5px;
  left: 2px;
}

.message .presence-dot,
.conversation-welcome .presence-dot {
  display: none;
}

.dm-button > span:nth-child(2) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-button .unread-count {
  flex: 0 0 auto;
  padding: 1px 6px;
  font-size: 11px;
}

.notification-banner {
  position: absolute;
  top: 76px;
  right: 16px;
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  background: var(--sidebar);
  color: var(--on-surface);
  border: 1px solid var(--primary);
  box-shadow: 0 8px 24px #0005;
  font-size: 13px;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.profile-settings {
  margin-top: 24px;
  border-top: 1px solid var(--outline);
  padding-top: 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-settings label {
  font-size: 13px;
  font-weight: 600;
}

.profile-settings small {
  font-size: 11px;
}

.profile-settings .muted {
  font-size: 11px;
  margin: 0;
}

.profile-settings button {
  margin-top: 8px;
}

select {
  font: inherit;
  color: var(--on-surface);
  background: var(--background);
  border: 1px solid var(--outline);
  border-radius: 5px;
  padding: 8px;
  min-width: 0;
}

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

.emoji-picker select {
  width: 100%;
  font-size: 12px;
  margin-bottom: 8px;
}

.emoji-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.emoji-footer small {
  font-size: 10px;
}

.emoji-footer button {
  font-size: 11px;
  padding: 5px 8px;
}

.auth-panel label.remember-option {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 500;
}

.auth-panel label.remember-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.emoji-suggestions {
  position: absolute;
  bottom: 100%;
  margin-bottom: 8px;
  left: 0;
  width: min(450px, 100%);
  padding: 7px;
  max-height: min(360px, 45dvh);
  overflow-y: auto;
  background: var(--sidebar);
  border: 1px solid var(--outline);
  border-radius: 8px;
  box-shadow: 0 10px 30px #0006;
  z-index: 7;
}

.emoji-suggestion-heading {
  padding: 6px 9px;
  font-size: 10px;
  letter-spacing: 0.3px;
  color: var(--muted);
}

.emoji-suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 6px 9px;
  color: var(--on-surface);
  background: transparent;
  text-align: left;
  font-weight: 500;
  font-size: 13px;
}

.emoji-suggestion.active,
.emoji-suggestion:hover {
  background: var(--surface-hover);
  color: var(--primary);
}

.emoji-suggestion-glyph {
  font-size: 25px;
  width: 34px;
  flex-shrink: 0;
  text-align: center;
}

.emoji-suggestion > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* History is fetched one section at a time. The button remains keyboard-accessible. */

.load-older {
  display: block;
  margin: 4px auto 18px;
  font-size: 12px;
}

/* The history controller restores anchors explicitly, including after image decoding. */

.message-list {
  overflow-anchor: none;
}

/* Responsive layouts: compact sidebar first, then the mobile navigation rail. */
@media (max-width: 950px) {
  .chat-layout {
    grid-template-columns: 60px 210px minmax(0, 1fr);
  }

  .friends-header {
    gap: 10px;
    padding: 10px 16px;
  }

  .friends-header h2 {
    padding-right: 10px;
  }

  .tab-list {
    gap: 4px;
  }

  .tab {
    padding: 4px 6px;
  }

  .composer-hint > span:last-child {
    display: none;
  }

  .friends-content {
    padding: 24px 18px;
  }
}

@media (max-width: 650px) {
  .chat-layout {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .server-rail {
    display: none;
  }

  .sidebar-heading,
  .sidebar > .section-label,
  .sidebar-empty,
  .account-profile > span:last-child,
  .dm-button > span:last-child {
    display: none;
  }

  .sidebar {
    align-items: center;
    padding-top: 9px;
  }

  .nav-button {
    width: 44px;
    height: 44px;
    margin: 0 0 12px;
    padding: 8px;
    justify-content: center;
    font-size: 24px;
    position: relative;
  }

  .nav-button > span:not(.badge) {
    display: none;
  }

  .badge {
    position: absolute;
    right: -3px;
    top: -4px;
  }

  .dm-list {
    width: 100%;
    padding: 0 6px;
  }

  .dm-button {
    justify-content: center;
    padding: 7px 0;
    position: relative;
  }

  .account-bar {
    width: 100%;
    padding: 6px;
    flex-direction: column;
    gap: 8px;
  }

  .account-profile {
    padding: 0;
    justify-content: center;
  }

  .friends-header {
    flex-wrap: wrap;
    padding: 12px;
    gap: 8px;
  }

  .friends-header h2 {
    border: 0;
    font-size: 14px;
  }

  .tab-list {
    gap: 2px;
  }

  .tab,
  .add-friend {
    font-size: 11px;
  }

  .friends-content {
    padding: 18px 12px;
  }

  .add-friend-form {
    flex-direction: column;
    align-items: stretch;
  }

  .friend-row {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px 0;
  }

  .friend-actions {
    margin-left: 48px;
  }

  .empty-state {
    margin-top: 5vh;
  }

  .empty-state h2 {
    font-size: 18px;
  }

  .friends-footer {
    margin: 0 12px 16px;
  }

  .conversation-header {
    padding: 10px 12px;
    gap: 9px;
  }

  .key-details summary span {
    display: none;
  }

  .conversation-welcome {
    padding: 14px 16px 20px;
  }

  .conversation-welcome h2 {
    font-size: 25px;
  }

  .message {
    padding: 2px 12px;
    gap: 10px;
  }

  .message > .avatar {
    width: 32px;
    height: 32px;
  }

  .message time {
    font-size: 9px;
  }

  .composer-area {
    margin: 8px 10px;
  }

  :is(#message-form, #server-message-form) {
    gap: 4px;
    padding: 8px;
  }

  :is(#message, #server-message) {
    font-size: 14px;
  }

  .attachment-image {
    max-width: 100%;
  }

  .status-toast {
    left: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
  }

  .message.grouped {
    padding-left: 54px;
  }

  .grouped-time {
    left: 1px;
    width: 47px;
    font-size: 8px !important;
    top: 5px;
  }

  .dm-button > span:nth-child(2) {
    display: none;
  }

  .dm-button .unread-count {
    display: block;
    position: absolute;
    right: 0;
    top: 0;
    font-size: 8px;
    min-width: 14px;
    padding: 0 3px;
  }

  .dm-button > .avatar {
    display: inline-flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Reserve a quiet status line so typing updates do not move the composer. */
.typing-indicator {
  min-height: 1.4em;
  font-size: 0.8rem;
  opacity: 0.8;
  padding: 0 0.4rem;
}

/* Block margins are explicit so Markdown and browser defaults cannot change row spacing. */
.message-content > * {
  margin: 0;
}
.message-content > * + * {
  margin-top: 4px;
}
.message-content.emoji-only {
  font-size: 2.75rem;
  line-height: 1.25;
}
.profile-trigger {
  cursor: pointer;
}
.profile-trigger:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
.message-author:hover {
  text-decoration: underline;
}
.privilege-badge {
  display: inline-block;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 12px;
  padding: 2px 9px;
  font-size: 12px;
  margin: 8px 0;
}
.profile-custom-status {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-top: 12px;
}
.dm-identity {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  text-align: left;
}
.dm-identity > * {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.dm-identity small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}
.youtube-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 200px;
  border: 0;
  border-radius: 6px;
}
.link-embed video,
.link-embed audio {
  width: 100%;
}
#custom-status {
  width: 100%;
  margin: 6px 0;
}

.user-context-menu {
  position: fixed;
  inset: auto;
  margin: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
  width: 220px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: var(--rail);
  color: var(--on-surface);
  box-shadow: 0 8px 30px #0006;
}
.context-menu-title {
  padding: 5px 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.user-context-menu button {
  text-align: left;
  background: transparent;
  color: inherit;
  font-size: 13px;
  padding: 8px;
}
.user-context-menu button:hover,
.user-context-menu button:focus-visible {
  background: var(--surface-hover);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.destructive {
  color: #ff958a !important;
  background: var(--surface);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
#nickname-input {
  width: 100%;
  margin-top: 6px;
}
#remove-friend-confirm {
  margin-top: 20px;
}

/* Settings use a stable navigation column; the content scrolls independently on small screens. */
.settings-dialog {
  width: min(860px, 96vw);
  max-height: 90dvh;
  text-align: left;
  padding: 22px;
}
.settings-layout {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 24px;
}
.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-right: 1px solid var(--outline);
  padding-right: 16px;
}
.settings-nav button {
  text-align: left;
  background: transparent;
  color: var(--on-surface);
  font-size: 14px;
}
.settings-nav button:hover,
.settings-nav button.selected {
  background: var(--surface-hover);
  color: var(--primary);
}
.settings-content {
  min-width: 0;
  max-height: 65dvh;
  overflow-y: auto;
  padding-right: 8px;
}
.settings-content h3 {
  margin-bottom: 16px;
}
.settings-content h4 {
  margin: 0;
}
.settings-content .muted {
  margin: 8px 0 16px;
}
.settings-content .profile-avatar {
  margin-top: 12px;
}
.settings-group {
  padding: 16px 0;
  border-top: 1px solid var(--outline);
}
.settings-group > label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}
.settings-group select {
  width: 100%;
}
.settings-check {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  cursor: pointer;
}
.settings-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  accent-color: var(--primary);
}
.settings-content #logout {
  width: 100%;
}
.message-content {
  font-size: var(--message-font-size, 15px);
}
.compact-messages .message:not(.grouped) {
  margin-top: 8px;
}
.compact-messages .message {
  padding-top: 1px;
  padding-bottom: 1px;
}
.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* Linked GIFs are visual previews, with URLs available only through viewer/menu actions. */
.gif-toggle {
  font-size: 11px;
  font-weight: 800;
  padding: 5px;
}
.gif-picker {
  position: absolute;
  z-index: 12;
  bottom: calc(100% + 8px);
  right: 0;
  width: min(450px, calc(100vw - 32px));
  max-height: min(650px, 70dvh);
  overflow-y: auto;
  padding: 16px;
  background: var(--rail);
  border: 1px solid var(--outline);
  border-radius: 10px;
  box-shadow: 0 8px 25px #0005;
}
.gif-picker h3 {
  margin-bottom: 12px;
}
.gif-search-form {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}
.gif-search-form input {
  min-width: 0;
  flex: 1;
}
.gif-search-form button {
  font-size: 12px;
  padding: 7px 10px;
}
.gif-provider-note,
:is(#gif-status, #server-gif-status) {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0;
}
.gif-results {
  display: flex;
  align-content: start;
  align-items: flex-start;
  gap: 12px;
}
.gif-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gif-result {
  min-width: 0;
}
.gif-result button {
  padding: 0;
  width: 100%;
  background: var(--surface);
  overflow: hidden;
}
.gif-result img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}
.gif-result > a {
  display: block;
  font-size: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
  margin-top: 4px;
}
.gif-embed {
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
}
.gif-credit {
  font-size: 10px;
  color: var(--muted);
  max-width: 440px;
  margin: 4px 0;
}
.gif-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--sidebar);
  border-radius: 8px;
  margin-bottom: 8px;
}
.gif-preview img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}
.gif-preview span {
  min-width: 0;
  overflow-wrap: anywhere;
  flex: 1;
}
.media-preview {
  cursor: zoom-in;
}
.media-preview:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

/* The viewer owns a scrollable canvas so original-size images remain pannable at every zoom. */
.media-viewer {
  width: min(1200px, 96vw);
  height: 90dvh;
  max-height: 96dvh;
  padding: 16px;
  text-align: left;
  overflow: hidden;
}
.media-viewer[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.media-viewer::backdrop {
  background: #000d;
}
.media-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.media-toolbar strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-toolbar a {
  color: var(--primary);
  font-size: 13px;
}
.media-viewport {
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: #0003;
  border-radius: 8px;
}
.media-content {
  display: grid;
  place-items: center;
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  height: max-content;
  padding: 20px;
}
.media-content img {
  display: block;
  max-width: none;
  height: auto;
  user-select: none;
  cursor: grab;
}
.media-content img:active {
  cursor: grabbing;
}
.media-content video {
  max-width: min(900px, 85vw);
  max-height: 65dvh;
}
.media-content audio {
  width: min(500px, 80vw);
}
.media-zoom-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.media-zoom-controls input {
  width: min(180px, 30vw);
  padding: 0;
  accent-color: var(--primary);
}
.media-zoom-controls button {
  padding: 5px 10px;
  font-size: 12px;
}
.media-zoom-controls span {
  width: 45px;
  font-size: 12px;
  text-align: center;
}
.media-viewer > small,
#media-viewer-status {
  color: var(--muted);
  font-size: 11px;
}
@media (max-width: 600px) {
  .settings-dialog {
    padding: 14px;
  }
  .settings-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .settings-nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--outline);
    padding: 0 0 10px;
  }
  .settings-nav button {
    font-size: 12px;
    padding: 7px;
  }
  .settings-content {
    max-height: 55dvh;
  }
  .media-viewer {
    padding: 8px;
  }
  .media-toolbar {
    gap: 6px;
    flex-wrap: wrap;
  }
  .media-toolbar strong {
    flex-basis: 50%;
  }
  .media-toolbar button {
    padding: 6px;
    font-size: 12px;
  }
}

/* The star is separate from GIF selection, so saving never stages a message. */
.gif-tabs {
  display: flex;
  gap: 8px;
}
.gif-tabs button {
  background: var(--surface);
  color: var(--on-surface);
}
.gif-tabs button[aria-pressed='true'] {
  background: var(--primary);
  color: var(--on-primary);
}
.gif-result {
  position: relative;
}
.gif-result .gif-favorite {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  font-size: 22px;
  background: var(--rail);
  color: var(--on-surface);
  cursor: pointer;
}

/* Message tools remain available on keyboard focus and touch as well as hover. */
.message {
  position: relative;
}
.message-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  right: 8px;
  top: 0;
  opacity: 0;
}
.message:hover > .message-actions,
.message:focus-within > .message-actions {
  opacity: 1;
}
.message-actions button[data-message-action] {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 6px;
}
.message-actions svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.message-actions button[data-message-action='delete'] {
  color: #ef7777;
}
.message-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.message-editor textarea {
  width: 100%;
  min-height: 70px;
  resize: none;
}
.message-quote {
  display: block;
  max-width: 100%;
  text-align: left;
  overflow-wrap: anywhere;
  font-size: 12px;
  border-left: 3px solid var(--primary);
  margin: 4px 0;
}
.message-edited {
  color: var(--muted);
  font-size: 11px;
}
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px;
  background: var(--sidebar);
  font-size: 12px;
}
.message-highlight {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
}
/* Dim message content, while keeping attachment progress clear and readable. */
.outgoing-pending:not(.outgoing-failed) > .avatar,
.outgoing-pending:not(.outgoing-failed) > .grouped-time,
.outgoing-pending:not(.outgoing-failed) .message-body > :not(.delivery-state) {
  opacity: 0.55;
}
/* Delivery chrome overlays the shared row instead of reserving extra timeline height. */
.outgoing-pending .message-actions {
  display: none;
}
.delivery-state {
  position: absolute;
  right: 12px;
  bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.outgoing-pending:not(.outgoing-failed) .delivery-state:not(.has-attachments) .delivery-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.delivery-state progress {
  display: block;
  width: 64px;
  height: 4px;
  accent-color: var(--primary);
}
/* The shared attachment bar overlays the preview without moving its final timeline row. */
.outgoing-pending .message-body {
  position: relative;
}
.outgoing-pending:not(.outgoing-failed) .delivery-state.has-attachments {
  left: 0;
  right: auto;
  bottom: 0;
  width: min(440px, 100%);
  flex-direction: column;
  align-items: stretch;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--rail);
  color: var(--on-surface);
  box-shadow: 0 2px 8px #0005;
  pointer-events: none;
}
.delivery-state.has-attachments button {
  pointer-events: auto;
  align-self: flex-end;
  padding: 4px 8px;
  font-size: 12px;
}
.delivery-state.has-attachments .delivery-status {
  font-size: 12px;
  line-height: 1.4;
}
.delivery-state.has-attachments progress {
  width: 100%;
  height: 7px;
  appearance: none;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-hover);
  color: var(--primary);
}
.delivery-state.has-attachments progress::-webkit-progress-bar {
  background: var(--surface-hover);
}
.delivery-state.has-attachments progress::-webkit-progress-value {
  background: var(--primary);
  border-radius: 4px;
}
.delivery-state.has-attachments progress::-moz-progress-bar {
  background: var(--primary);
}

.outgoing-failed .delivery-state {
  position: static;
  flex-wrap: wrap;
  font-size: 12px;
  margin-top: 6px;
}
.outgoing-failed {
  opacity: 1;
  color: #ef7777;
  border-left: 3px solid #ef7777;
}
.outgoing-failed button {
  margin: 6px 6px 0 0;
}
.gif-embed {
  position: relative;
}
.gif-hover-favorite {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  font-size: 22px;
  padding: 2px 8px;
}
.gif-embed:hover .gif-hover-favorite,
.gif-embed:focus-within .gif-hover-favorite {
  opacity: 1;
}
.message-search-dialog {
  width: min(900px, 95vw);
  max-height: 90vh;
  background: var(--chat);
  color: var(--on-surface);
  border: 1px solid var(--outline);
  border-radius: 10px;
}
.search-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.message-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.message-search-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message-search-form input,
.message-search-form select {
  width: 100%;
  min-width: 0;
}
#message-search-status,
.message-search-dialog > p {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0;
}
@media (hover: none) {
  .message-actions,
  .gif-hover-favorite {
    opacity: 1;
  }
  .message-actions {
    position: static;
    grid-column: 2;
  }
}
@media (max-width: 600px) {
  .message-search-form {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Entry animations keep dialog lifecycle and close/cleanup behavior unchanged. */
@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes backdrop-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes media-enter {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
dialog[open] {
  animation: panel-enter 180ms ease-out;
}
dialog[open]::backdrop {
  animation: backdrop-enter 180ms ease-out;
}
.gif-picker:not([hidden]),
.emoji-picker:not([hidden]) {
  animation: panel-enter 140ms ease-out;
}
#media-content > img,
#media-content > video,
#media-content > audio {
  animation: media-enter 180ms ease-out;
}
.reduced-motion dialog::backdrop {
  animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  dialog::backdrop {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
.youtube-thumbnail {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.link-embed .embed-play {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  overflow: hidden;
  background: var(--rail);
  border-radius: 8px;
}
.embed-play .youtube-thumbnail {
  position: absolute;
  inset: 0;
}
.youtube-play-label {
  position: relative;
  z-index: 1;
  padding: 10px 16px;
  border-radius: 8px;
  background: #000b;
  color: #fff;
}
.attachment-file {
  min-width: 180px;
  padding: 14px;
  text-align: left;
}

/* Keep search and navigation fixed while the GIF grid scrolls independently. */
.gif-picker {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  width: min(460px, calc(100vw - 32px));
}
.gif-picker-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.gif-picker-heading h3 {
  margin: 0;
}
.gif-tabs {
  margin-top: 8px;
}
.gif-tabs button {
  flex: 1;
}
.gif-results {
  overflow-y: auto;
  min-height: 0;
  scrollbar-gutter: stable;
  padding: 3px;
}
.gif-result {
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.gif-result .gif-select {
  display: block;
  border-radius: 8px;
}
.gif-result img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}
.gif-results {
  align-items: start;
}
.gif-select:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}
.gif-result .gif-favorite {
  opacity: 0;
  transition: opacity 120ms;
}
.gif-result:hover .gif-favorite,
.gif-result:focus-within .gif-favorite {
  opacity: 1;
}
.gif-picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--outline);
  padding-top: 8px;
  flex-shrink: 0;
}
.gif-picker-footer .gif-provider-note {
  margin: 0;
  font-size: 10px;
}
.gif-picker-footer :is(#gif-upload, #server-gif-upload) {
  font-size: 12px;
  padding: 6px 10px;
}
@media (hover: none) {
  .gif-result .gif-favorite {
    opacity: 1;
  }
}

.attachment-transfer-status {
  font-size: 12px;
  padding: 0 10px;
  color: var(--muted);
}
.attachment-transfer-status:empty {
  display: none;
}
.attachment-card > progress {
  display: block;
  margin: 8px 10px;
  max-width: calc(100% - 20px);
  accent-color: var(--primary);
}

/* Servers share the app palette and message renderer, with their own navigation and composer. */
#personal-sidebar {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}
#server-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
.server-rail-button {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  padding: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface);
  color: var(--on-surface);
}
.server-rail-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.server-rail-button.selected {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
#server-sidebar {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
#server-settings-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  flex-shrink: 0;
  background: transparent;
  color: var(--on-surface);
}
#server-channels {
  overflow-y: auto;
  padding: 12px 8px;
  flex: 1;
}
.server-channel {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px;
  margin-bottom: 3px;
  background: transparent;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.server-channel.selected,
.server-channel:hover {
  background: var(--surface-hover);
  color: var(--on-surface);
}
.server-category {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 8px 6px;
}
#server-key-status {
  font-size: 12px;
  color: var(--muted);
}
#server-key-status:empty,
.attachment-transfer-status:empty {
  display: none;
}
.server-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: 88dvh;
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--sidebar);
  color: var(--on-surface);
}
.server-dialog::backdrop {
  background: #0009;
}
.server-dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.server-dialog-heading h2 {
  font-size: 20px;
}
.server-dialog form,
.server-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}
.server-dialog label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  font-size: 13px;
}
.server-dialog input:not([type='checkbox']),
.server-dialog select {
  width: 100%;
  min-width: 0;
}
.server-dialog label:has(input[type='checkbox']) {
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: center;
}
.server-dialog p {
  margin: 10px 0;
  overflow-wrap: anywhere;
}
.server-settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--outline);
}
.server-settings-tabs [aria-pressed='true'] {
  background: var(--primary);
  color: var(--on-primary);
}
.server-setting-card {
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
}
.server-setting-card > small {
  display: block;
  color: var(--muted);
  margin: 8px 0;
}
.server-link {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}
.server-link input {
  flex: 1;
}
.server-emoji-management {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.server-emoji-management .server-setting-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
}
.server-emoji-management img,
#custom-emoji-info > img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}
.server-emoji-management code {
  overflow-wrap: anywhere;
  max-width: 100%;
}
.custom-emoji {
  display: inline-block;
  width: 1.5em;
  height: 1.5em;
  object-fit: contain;
  vertical-align: -0.35em;
  cursor: pointer;
}
.emoji-only .custom-emoji {
  width: 1em;
  height: 1em;
}
:is(#emoji-grid, #server-emoji-grid) img,
.emoji-suggestion-glyph img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
@media (max-width: 760px) {
  #server-settings-open {
    padding: 10px 6px;
    font-size: 11px;
    overflow-wrap: anywhere;
  }
  .server-channel {
    padding: 8px 3px;
    font-size: 12px;
  }
  .server-category {
    padding: 14px 2px 4px;
    font-size: 9px;
    overflow-wrap: anywhere;
  }
  .server-dialog {
    padding: 16px;
  }
}

#add-server::before {
  display: none;
}

/* Navigation headings stay compact even when their flex wrapper changes. */
.dm-section-heading {
  flex-shrink: 0;
  gap: 8px;
  white-space: nowrap;
  letter-spacing: 0.5px;
}
.dm-section-heading > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-section-heading .icon-button {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 20px;
}
#server-settings-open strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
#server-settings-open {
  gap: 12px;
  cursor: pointer;
}
#server-settings-open:hover {
  background: var(--surface-hover);
}
.server-channel-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 5px;
  margin-bottom: 2px;
}
.server-channel-row:hover,
.server-channel-row.selected {
  background: var(--surface-hover);
}
.server-channel-row .server-channel {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  margin: 0;
  background: transparent;
  padding: 9px 8px;
}
.channel-hash {
  font-size: 20px;
  font-weight: 400;
  color: var(--muted);
}
.channel-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-more {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 20px;
  opacity: 0;
}
.server-channel-row:hover .channel-more,
.server-channel-row:focus-within .channel-more,
.server-category:hover .channel-more,
.server-category:focus-within .channel-more {
  opacity: 1;
}
.server-category {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 16px 0 5px;
}
.category-toggle {
  display: flex;
  gap: 5px;
  align-items: center;
  min-width: 0;
  flex: 1;
  padding: 4px 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.category-toggle:hover {
  color: var(--on-surface);
  background: transparent;
}
.category-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.category-chevron {
  flex: 0 0 12px;
  font-size: 16px;
  text-align: center;
}
.category-add {
  font-size: 20px;
  height: 26px;
  width: 26px;
  flex-shrink: 0;
  padding: 0;
}
.create-channel-shortcut {
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 10px 8px;
  margin-top: 8px;
  text-align: left;
}
.create-channel-shortcut:hover {
  background: var(--surface-hover);
  color: var(--on-surface);
}
.user-context-menu hr {
  border: 0;
  border-top: 1px solid var(--outline);
  margin: 5px 6px;
}
.server-entry-dialog,
.server-editor-dialog {
  width: min(460px, calc(100vw - 24px));
}
.server-entry-dialog .server-dialog-heading {
  align-items: flex-start;
}
.server-entry-description {
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}
.server-entry-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0 8px;
}
.server-entry-choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline);
  padding: 16px;
  text-align: left;
}
.server-entry-choice:hover {
  border-color: var(--primary);
  background: var(--surface-hover);
}
.server-entry-choice > span:nth-child(2) {
  flex: 1;
}
.server-entry-choice strong,
.server-entry-choice small {
  display: block;
}
.server-entry-choice strong {
  font-size: 15px;
}
.server-entry-choice small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.5;
}
.entry-choice-icon {
  display: grid;
  place-items: center;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--rail);
  color: var(--primary);
  font-size: 26px;
}
.server-entry-back {
  margin-top: 12px;
}
.server-entry-dialog form > small {
  color: var(--muted);
  font-size: 12px;
}
.server-entry-dialog form > button {
  margin-top: 8px;
  padding: 12px;
}
.server-join-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 16px;
}
.server-preview-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: var(--surface-hover);
  color: var(--on-surface);
  font-size: 28px;
  margin-bottom: 16px;
  overflow: hidden;
}
.server-preview-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.server-join-preview h3 {
  font-size: 22px;
}
.server-preview-meta {
  font-size: 12px;
  color: var(--muted);
}
.server-preview-description {
  font-size: 14px;
  line-height: 1.5;
}
.server-join-button {
  width: 100%;
  padding: 12px;
  margin-top: 16px;
}
#server-entry-status:empty,
#server-edit-status:empty,
#server-settings-status:empty {
  display: none;
}
#server-entry-status,
#server-edit-status {
  font-size: 13px;
  line-height: 1.5;
}
.server-settings-dialog {
  width: min(940px, calc(100vw - 24px));
}
.server-settings-layout {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 24px;
  min-height: 360px;
}
.server-settings-tabs {
  flex-direction: column;
  align-self: start;
  border: 0;
  gap: 4px;
  position: sticky;
  top: 0;
}
.server-settings-tabs button {
  text-align: left;
}
.server-settings-pane {
  min-width: 0;
}
.server-settings-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.server-setting-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.server-setting-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--outline);
  padding: 12px 0;
}
.server-setting-list-row > :first-child {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.server-setting-list-row button {
  font-size: 12px;
  padding: 5px 8px;
}
.category-setting-row {
  margin-top: 14px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
}
.server-editor-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--outline);
}
.server-editor-advanced {
  color: var(--muted);
  font-size: 12px;
}
.server-editor-advanced summary {
  cursor: pointer;
  margin-bottom: 8px;
}
.server-danger-button {
  background: #b12d3b;
  color: #fff;
}
.server-danger-button:hover {
  background: #962431;
}
.mobile-navigation-bar,
.mobile-nav-scrim {
  display: none;
}
@media (hover: none) {
  .channel-more {
    opacity: 1;
  }
}
@media (max-width: 650px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .workspace {
    display: flex;
    flex-direction: column;
  }
  .workspace > .conversation,
  .workspace > .friends-view {
    flex: 1;
    height: auto;
    min-height: 0;
  }
  .mobile-navigation-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    height: 48px;
    padding: 4px 12px;
    border-bottom: 1px solid var(--outline);
    background: var(--sidebar);
  }
  .mobile-navigation-bar strong {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-navigation-bar .icon-button {
    flex-shrink: 0;
    font-size: 22px;
    width: 32px;
    padding: 0;
  }
  .sidebar {
    display: none;
    align-items: stretch;
    padding-top: 0;
  }
  .mobile-nav-open .server-rail {
    display: flex;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 64px;
    z-index: 31;
  }
  .mobile-nav-open .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 64px;
    width: min(260px, calc(100vw - 64px));
    z-index: 31;
    box-shadow: 8px 0 24px #0006;
  }
  .mobile-nav-open .mobile-nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: #0008;
    z-index: 30;
    border-radius: 0;
  }
  .sidebar .sidebar-heading {
    display: flex;
    height: 65px;
    padding: 12px 18px;
    font-size: 16px;
  }
  #personal-sidebar > .sidebar-heading {
    display: block;
  }
  .sidebar .dm-section-heading {
    display: flex;
    padding: 8px 17px 4px;
    font-size: 11px;
  }
  .sidebar-empty {
    display: block;
  }
  .nav-button {
    width: auto;
    height: auto;
    margin: 18px 10px 10px;
    padding: 8px 14px;
    justify-content: flex-start;
    gap: 12px;
    font-size: 17px;
  }
  .nav-button > span:not(.badge) {
    display: inline;
  }
  .sidebar .badge {
    position: static;
  }
  .dm-list {
    padding: 4px 8px;
  }
  .dm-button {
    justify-content: flex-start;
    padding: 8px;
  }
  .dm-button > span:nth-child(2) {
    display: flex;
  }
  .dm-button > span:last-child {
    display: flex;
  }
  .dm-button .unread-count {
    position: static;
    font-size: 11px;
    padding: 1px 6px;
  }
  .account-bar {
    width: 100%;
    flex-direction: row;
    gap: 8px;
    padding: 8px;
  }
  .account-profile {
    max-width: none;
    padding: 4px;
    justify-content: flex-start;
  }
  .account-profile > span:last-child {
    display: block;
  }
  .server-category {
    padding: 16px 0 5px;
  }
  .server-channel-row .server-channel {
    padding: 9px 8px;
    font-size: 14px;
  }
  .channel-more {
    opacity: 1;
  }
  .server-settings-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
  .server-settings-tabs {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    position: static;
    padding-bottom: 8px;
  }
  .server-settings-tabs button {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 12px;
  }
  .server-link {
    flex-wrap: wrap;
  }
  .server-link input {
    flex-basis: 100%;
  }
}

/* Server invitations use the same readable card in DMs and channels. */
.server-invite-card {
  width: min(400px, 100%);
  box-sizing: border-box;
  margin-top: 8px;
  padding: 18px;
  border: 1px solid var(--outline);
  border-radius: 10px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-wrap: anywhere;
}
.server-invite-card > small {
  color: var(--muted);
}
.server-invite-details {
  display: flex;
  align-items: center;
  gap: 14px;
}
.server-invite-details h3 {
  margin: 0;
  font-size: 18px;
  min-width: 0;
}
.server-invite-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 15px;
  overflow: hidden;
  background: var(--surface-hover);
  font-size: 22px;
  font-weight: bold;
}
.server-invite-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.server-invite-description,
.server-invite-status {
  margin: 0;
  white-space: pre-wrap;
}
.server-invite-status:empty {
  display: none;
}
.server-invite-join {
  width: 100%;
  min-height: 44px;
  font-weight: bold;
}

/* Friend invitations have their own browseable list, separate from link management. */
.friend-invite-section,
.invite-link-section {
  text-align: left;
  padding: 20px;
  border: 1px solid var(--outline);
  border-radius: 10px;
  margin-bottom: 22px;
  background: var(--surface);
}
.friend-invite-section h3,
.invite-link-section h3 {
  margin: 0 0 10px;
}
.friend-invite-section > p,
.invite-link-section > p {
  color: var(--muted);
  line-height: 1.5;
}
.friend-invite-section > small {
  display: block;
  color: var(--muted);
  margin-top: 12px;
}
.friend-invite-picker {
  margin-top: 16px;
}
.friend-invite-search {
  width: 100%;
  margin-bottom: 12px;
}
.friend-invite-list {
  max-height: 320px;
  overflow-y: auto;
}
.friend-invite-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: 6px;
}
.friend-invite-row:hover {
  background: var(--surface-hover);
}
.friend-invite-user {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-wrap: anywhere;
}
.friend-invite-user small {
  color: var(--muted);
}
.friend-invite-row > button {
  min-height: 38px;
  flex-shrink: 0;
}
.server-profile-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}
.message-search-dialog {
  width: min(680px, calc(100vw - 24px));
  text-align: left;
  overflow-y: auto;
  padding: 24px;
  box-sizing: border-box;
}
.message-search-form input,
.message-search-form select,
.message-search-form > button {
  min-height: 44px;
  box-sizing: border-box;
  font-size: 14px;
}
#message-search-results,
#server-message-search-results {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.message-search-dialog .message {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: var(--surface);
}
.message-search-dialog .message-actions {
  position: static;
  grid-column: 2;
  opacity: 1;
  justify-content: flex-start;
  margin-top: 8px;
}
.search-jump {
  display: block;
  margin-top: 14px;
  min-height: 38px;
  width: 100%;
}
@media (max-width: 600px) {
  .message-search-dialog {
    padding: 16px;
  }
  .friend-invite-section,
  .invite-link-section {
    padding: 14px;
  }
}

.search-channel {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}
