/* Values come from tokens.css; avoid raw colors and sizes here. */

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.4;
  background: var(--surface-app);
  color: var(--text);
}
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

.icon-btn {
  width: var(--control-md);
  height: var(--control-md);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--surface-control); color: var(--text); }

.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-on-avatar);
  font-weight: var(--weight-bold);
}
.avatar { position: relative; }
.avatar .presence {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 40%;
  height: 40%;
  min-width: 9px;
  min-height: 9px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid var(--presence-ring, var(--surface-sidebar));
  background: var(--text-muted);
}
.avatar .presence.online { background: var(--success); }
.avatar .presence.idle { background: var(--warning); }
.avatar .presence.dnd { background: var(--danger); }
.avatar .presence.invisible { background: var(--surface-main); box-shadow: inset 0 0 0 2px var(--text-muted); }
.avatar-sm { width: 22px; height: 22px; font-size: var(--text-xs); }
.avatar-md { width: 34px; height: 34px; font-size: var(--text-md); }
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-base); }
.avatar-xl { width: 64px; height: 64px; font-size: var(--text-avatar-xl); }
.avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.section-label {
  margin: 0;
  padding: 0 var(--space-3) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  height: 44px;
  padding: 0 var(--space-9);
  border: none;
  border-radius: var(--radius-lg);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-control); color: var(--text); }
.btn-secondary:hover { background: var(--surface-control-hover); }
.btn-danger { background: var(--danger); color: var(--text-on-danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.6; cursor: default; }

.field { display: flex; flex-direction: column; gap: var(--space-4); }
.field > label, .field > span { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-secondary); }
.field input, .field textarea, .field select {
  width: 100%;
  height: 46px;
  padding: 0 var(--space-7);
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  outline: none;
}
.field textarea { height: auto; padding: var(--space-5) var(--space-7); resize: vertical; }
.field input:focus-visible, .field textarea:focus-visible, .field select:focus-visible { border-color: var(--focus-ring); }
.field select { color: var(--text); }
.field input[readonly] { color: var(--text-secondary); font-family: var(--font-mono); font-size: var(--text-sm); }
.field-row { display: flex; gap: var(--space-4); }
.field-row input { flex: 1; min-width: 0; }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-4); }
.field-label-row label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-secondary); }
.field-hint { margin: 0; font-size: var(--text-sm); color: var(--text-muted); }
.form-error { margin: 0; color: var(--danger-text); font-size: var(--text-md); }
.form-error:empty { display: none; }

.select {
  width: 100%;
  height: 46px;
  padding: 0 var(--space-7);
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  outline: none;
}
.select:focus-visible { border-color: var(--focus-ring); }
.range { width: 100%; margin: 0; accent-color: var(--accent); }

.mic-meter {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-input);
}
.mic-meter-fill { height: 100%; background: var(--text-muted); transition: width 50ms linear; }
.mic-meter.open .mic-meter-fill { background: var(--success); }
.mic-meter-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text-strong);
}

.ptt-key-row { align-items: center; }
.key-cap {
  min-width: var(--control-lg);
  height: var(--control-lg);
  padding: 0 var(--space-6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-bottom-width: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-input);
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: var(--text-md);
}

.segmented {
  margin: 0;
  padding: var(--space-2);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-xl);
  background: var(--surface-input);
}
.segmented-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  height: var(--control-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-badge);
  color: var(--text-secondary);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.segmented input:checked + span { background: var(--surface-selected); color: var(--text-strong); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.btn-ghost {
  height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
}
.btn-ghost:hover { background: var(--surface-control); color: var(--text); }

/* Dialogs */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: var(--space-8);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-scrim);
}
.dialog {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-4xl);
  box-shadow: var(--shadow-dialog);
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-6);
  padding: var(--space-10) var(--space-10) 0;
}
.dialog-header h2 { margin: 0; font-size: var(--text-title); color: var(--text-strong); }
.dialog-subtitle { margin: var(--space-2) 0 0; color: var(--text-secondary); font-size: var(--text-md); }
.dialog-body { padding: 22px var(--space-10); display: flex; flex-direction: column; gap: 22px; }
.dialog-section {
  padding: var(--space-9) var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.dialog-section + .dialog-section { border-top: 1px solid var(--border); }
.dialog-section h3 { margin: 0; font-size: var(--text-base); }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-6); }
.dialog-status { flex: 1; color: var(--success); font-size: var(--text-md); }
.data-export-ready { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); margin: 0; }
.data-export-ready a { display: inline-flex; align-items: center; text-decoration: none; }
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-5);
  padding: var(--space-8) var(--space-10);
  background: var(--surface-panel);
  border-top: 1px solid var(--border);
}
.dialog-error {
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: var(--text-md);
}

.dialog.dialog-wide { max-width: 760px; }

/* Server status */
.status-panel { min-height: 0; overflow-y: auto; }
.status-muted { margin: 0; color: var(--text-muted); font-size: var(--text-md); }
.status-build { margin: 0; color: var(--text-secondary); font-size: var(--text-md); }
.status-build code, .status-footer code { font-family: var(--font-mono); font-size: var(--text-sm); }
.status-tiles {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-5);
}
.status-tile {
  padding: var(--space-6);
  background: var(--surface-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.status-tile dt { color: var(--text-muted); font-size: var(--text-sm); }
.status-tile dd { margin: var(--space-2) 0 0; display: flex; align-items: baseline; gap: var(--space-4); }
.status-tile-value { color: var(--text-strong); font-size: var(--text-title); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.status-tile-detail { color: var(--text-muted); font-size: var(--text-sm); }
.status-tile-alert { border-color: var(--danger); }
.status-tile-alert .status-tile-value { color: var(--danger-text); }
.status-table-wrap { overflow-x: auto; }
.status-table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.status-table th {
  padding: 0 var(--space-4) var(--space-4);
  text-align: left;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}
.status-table td { padding: var(--space-4); border-top: 1px solid var(--border); white-space: nowrap; }
.status-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.status-tag {
  margin-left: var(--space-4);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-control);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}
.status-state[data-state="connected"] { color: var(--success); }
.status-state[data-state="connecting"], .status-state[data-state="securing"] { color: var(--warning); }
.status-log { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-4); font-size: var(--text-md); }
.status-log li { display: grid; grid-template-columns: auto auto 1fr; gap: var(--space-5); align-items: baseline; }
.status-log time { color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; font-variant-numeric: tabular-nums; }
.status-log-scope { color: var(--warning); font-family: var(--font-mono); font-size: var(--text-sm); }
.status-log li[data-level="error"] .status-log-scope { color: var(--danger-text); }
.status-log-msg { overflow-wrap: anywhere; }
.status-footer { margin: 0; justify-content: flex-start; color: var(--text-secondary); font-size: var(--text-md); }
@media (max-width: 768px) {
  .status-log li { grid-template-columns: 1fr; gap: var(--space-2); }
}

.kind-picker { margin: 0; padding: 0; border: none; display: flex; flex-direction: column; gap: var(--space-5); }
.kind-picker legend {
  padding: 0;
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
}
.kind-option {
  display: flex;
  align-items: center;
  gap: var(--space-7);
  padding: var(--space-7);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-input);
  cursor: pointer;
}
.kind-option:has(input:checked) { border-color: var(--accent); background: var(--surface-selected); }
.kind-option:has(input:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.kind-option-icon {
  width: var(--control-lg);
  height: var(--control-lg);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  color: var(--text-secondary);
}
.kind-option:has(input:checked) .kind-option-icon { color: var(--accent); }
.kind-option-text { flex: 1; display: flex; flex-direction: column; gap: var(--space-1); }
.kind-option-text span { font-size: var(--text-sm); color: var(--text-secondary); }
.kind-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.people-picker {
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  --presence-ring: var(--surface-raised);
}
.person-option {
  min-height: var(--control-md);
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.person-option:hover { background: var(--surface-control); }
.person-option:has(input:checked) { background: var(--surface-selected); }
.person-option:has(input:disabled) { cursor: not-allowed; opacity: 0.6; }
.person-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.person-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-note, .person-status { color: var(--text-muted); font-size: var(--text-sm); }

/* Sign in */
.auth {
  min-height: 100%;
  padding: 48px var(--space-8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-11);
  background: var(--surface-sunken);
}
.auth-header { display: flex; flex-direction: column; align-items: center; gap: var(--space-7); }
.auth-header h1 { margin: 0; font-size: var(--text-xl); letter-spacing: -0.02em; }
.auth-host { margin: 0; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-secondary); }
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-11);
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-4xl);
}
.auth-card .btn-primary { height: 48px; border-radius: var(--radius-xl); }
.auth .err {
  padding: var(--space-6) var(--space-7);
  border-radius: var(--radius-lg);
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: var(--text-md);
}

/* Shell */
.main {
  display: flex;
  height: 100%;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--surface-app);
}

.sidebar {
  position: relative;
  width: calc(var(--sidebar-width) + var(--server-rail-width));
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-sidebar);
  font-size: var(--text-md);
}
.sidebar-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -4px;
  z-index: 5;
  width: 8px;
  cursor: ew-resize;
  touch-action: none;
}
.sidebar-resizer::after {
  content: "";
  position: absolute;
  inset: 0 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.sidebar-resizer:hover::after, .sidebar-resizer:focus-visible::after, .resizing-sidebar .sidebar-resizer::after { opacity: 1; }
.sidebar-resizer:focus-visible { outline: none; }
.resizing-sidebar { cursor: ew-resize; user-select: none; }
/* The rail and the channel list, over the dock that spans both. */
.sidebar-top { flex: 1; min-height: 0; display: flex; }
.sidebar-dock {
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-4) env(safe-area-inset-bottom);
  background: var(--surface-panel);
  border-top: 1px solid var(--border);
}
.sidebar-dock .voice-bar { margin: var(--compose-margin) 0 0; }
.sidebar-dock .user-panel { height: calc(var(--compose-height) + 2 * var(--compose-margin)); }
.dock-off { color: var(--danger-text); }
.sidebar-column {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.server-rail {
  width: var(--server-rail-width);
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-6) 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.server-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}
.server-pill {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--surface-control);
  color: var(--text);
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  cursor: pointer;
  transition: border-radius 0.15s ease, background 0.15s ease;
}
.server-pill:hover { border-radius: var(--radius-3xl); background: var(--surface-control-hover); }
.server-pill.active { border-radius: var(--radius-3xl); background: var(--accent); color: var(--text-on-accent); }
.server-pill.active::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-5) - 2px);
  width: 4px;
  height: 28px;
  border-radius: 0 4px 4px 0;
  background: var(--text);
}
.server-pill.unread:not(.active)::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--space-5) - 2px);
  width: 4px;
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: var(--text);
}
.server-badge {
  position: absolute;
  right: -4px;
  bottom: -2px;
  box-shadow: 0 0 0 3px var(--surface-sidebar);
}
.home-pill { flex: none; }
.rail-divider { width: 32px; height: 2px; flex: none; border-radius: 1px; background: var(--border); }
.rail-dm { padding: 0; background: transparent; }
.rail-dm:hover { background: transparent; }
.rail-dm .avatar, .rail-dm .dm-group-icon { width: 44px; height: 44px; font-size: var(--text-subtitle); }
.server-add { background: transparent; color: var(--text-secondary); border: 1px dashed var(--border-strong); }
.server-add:hover { color: var(--text); }
.server-place { text-decoration: none; color: var(--text-secondary); border: 1px solid var(--border-strong); background: transparent; }
.server-place:hover { color: var(--text); }
.auth-home-toggle { align-self: center; }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  height: var(--header-height);
  padding: 0 var(--space-8);
  flex: none;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-badge);
  background: var(--accent);
  color: var(--text-on-accent);
}
.brand-mark-lg { width: 56px; height: 56px; border-radius: var(--radius-3xl); }
.brand-name { font-size: var(--text-subtitle); font-weight: var(--weight-bold); letter-spacing: -0.01em; }
.sidebar-brand .brand-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-action { flex: none; margin-right: calc(-1 * var(--space-4)); }
.sidebar-brand { position: relative; padding: 0 var(--space-4); }
.server-menu-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-strong);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.server-menu-btn:hover, .server-menu-btn[aria-expanded="true"] { background: var(--surface-control); }
.server-menu-btn .brand-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-menu-pop { top: calc(100% - var(--space-2)); left: var(--space-4); right: var(--space-4); z-index: 20; }
.context-menu-pop { position: fixed; top: auto; right: auto; z-index: 65; }
.channel-menu-pop button.accent { color: var(--accent); font-weight: var(--weight-semibold); }

/* Inviting friends: a searchable list of them, then the link. */
.invite-dialog { gap: var(--space-4); }
.invite-search { width: 100%; }
.invite-friends { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-2); }
.invite-friend { display: flex; align-items: center; gap: var(--space-5); padding: var(--space-3) var(--space-2); border-radius: var(--radius-md); }
.invite-friend:hover { background: var(--surface-control); }
.invite-friend-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.invite-friend-name span { font-size: var(--text-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-send { height: 32px; }
.invite-settings { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }
.invite-settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: var(--space-4); }
.invite-link-footer { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-8) var(--space-10) var(--space-10); background: var(--surface-panel); border-top: 1px solid var(--border); }
.invite-link-footer .field-hint { margin: 0; }
.invite-link-row { display: flex; gap: var(--space-4); }
.invite-link { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--text-sm); }

/* An invite posted in a message. */
.invite-card {
  width: min(100%, 420px);
  margin-top: var(--space-3);
  padding: var(--space-6) var(--space-7);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.invite-card-title { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.invite-card-row { display: flex; align-items: center; gap: var(--space-6); }
.invite-card-icon {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xl);
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
}
.invite-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.invite-card-text strong { display: flex; align-items: center; gap: var(--space-4); color: var(--text-strong); }
.invite-card-channel { display: inline-flex; align-items: center; gap: var(--space-1); font-weight: var(--weight-regular); color: var(--text-secondary); }
.invite-card-counts { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.invite-card-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); margin-left: var(--space-3); }
.invite-card-dot.online { background: var(--success); margin-left: 0; }
.invite-card-join { height: 36px; }
.invite-card-problem { font-size: var(--text-sm); color: var(--danger-text); }

.channels {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-7) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.channel-section { display: flex; flex-direction: column; gap: var(--space-1); }
.section-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: var(--space-3); }
.section-header .section-label { padding-bottom: 0; }
.category-header { padding-bottom: 0; }
.channel-section + .category-section { margin-top: var(--space-3); }
.section-add {
  width: var(--control-sm);
  height: var(--control-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.section-add:hover { background: var(--surface-control); color: var(--text); }
.section-header .section-label { flex: 1; min-width: 0; }
.section-toggle {
  padding: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.section-toggle:hover { color: var(--text); }
.section-menu { position: relative; opacity: 0; transition: opacity var(--transition-fast); }
.section-header:hover .section-menu, .section-header:focus-within .section-menu, .section-menu:has(.channel-menu-pop) { opacity: 1; }
.channel-tools { display: flex; gap: var(--space-2); }
.channel-tools .btn-ghost { flex: 1; }
.channel-private { flex: none; display: flex; color: var(--text-muted); }
.channel-group { display: flex; flex-direction: column; }
.channel {
  min-height: var(--control-md);
  padding: 0 var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}
.channel-link {
  flex: 1;
  min-width: 0;
  align-self: stretch;
  padding: 0;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.channel-link:focus-visible { outline: none; }
.channel:has(.channel-link:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.channel:hover { background: var(--surface-control); color: var(--text); }
.channel.active { background: var(--surface-selected); color: var(--text-strong); font-weight: var(--weight-semibold); }
.channel .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-icon { flex: none; opacity: 0.75; }
.dm-call { flex: none; display: flex; color: var(--success); }
.dm-group-icon {
  width: 32px;
  height: 32px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-control);
  color: var(--text-secondary);
}
.home-header {
  height: var(--header-height);
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
}
.home-search {
  flex: 1;
  min-width: 0;
  height: 32px;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-input);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.home-search:focus-within { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.home-search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--text); font: inherit; }
.home-nav { gap: var(--space-2); }
.home-nav .channel-section { margin-top: var(--space-6); }
.channel.home-friends { min-height: var(--control-lg); font-size: var(--text-base); }
.home-friends .channel-link { gap: var(--space-6); }
.channel.kind-dm { min-height: 44px; }
.kind-dm .channel-link { gap: var(--space-5); }
.kind-dm .avatar { width: 32px; height: 32px; font-size: var(--text-md); }
.channel.active .avatar .presence { border-color: var(--surface-selected); }
.dm-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.dm-text .name { flex: none; }
.dm-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-caption); font-weight: var(--weight-regular); color: var(--text-muted); }
.dm-subtitle.in-voice { color: var(--success); }
.home-empty { margin: 0; padding: var(--space-4) var(--space-5); color: var(--text-muted); font-size: var(--text-sm); }
.home-empty .link-btn { font-size: var(--text-sm); }
.channel.unread { color: var(--text-strong); font-weight: var(--weight-semibold); }
.badge {
  flex: none;
  min-width: 20px;
  height: 18px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-badge);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}
.badge.mention { background: var(--danger); color: var(--text-on-danger); }
.channel .channel-menu { position: relative; opacity: 0; transition: opacity var(--transition-fast); }
.channel:hover .channel-menu, .channel:focus-within .channel-menu, .channel .channel-menu:has(.channel-menu-pop) { opacity: 1; }
.channel-menu-btn {
  width: var(--control-sm);
  height: var(--control-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.channel-menu-btn:hover { color: var(--text); background: var(--surface-control-hover); }
.channel-menu-pop {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 10;
  min-width: 160px;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.channel-menu-pop button {
  padding: var(--space-4) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  font-weight: var(--weight-regular);
}
.channel-menu-pop button:hover { background: var(--surface-control); }
.channel-menu-pop button.danger { color: var(--danger-text); }
.channel-menu-pop button.danger:hover { background: var(--danger); color: var(--text-on-danger); }

.voice-users {
  list-style: none;
  margin: var(--space-1) 0 var(--space-2);
  padding: 0 0 0 30px;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.voice-user { position: relative; }
.voice-user-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  text-align: left;
}
.voice-user-row:hover, .voice-user-row[aria-expanded="true"] { background: var(--surface-control); color: var(--text); }
.voice-user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-user-muted { display: inline-flex; color: var(--danger-text); }
.voice-user-pop {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.voice-user-pop .field-label-row { display: flex; justify-content: space-between; }
.voice-user-pop output { color: var(--text); font-variant-numeric: tabular-nums; }
.voice-user-pop .btn-secondary { height: var(--control-md); }
.live-badge {
  margin-left: auto;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--danger);
  color: var(--text-on-danger);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
}

button.live-badge { border: none; cursor: pointer; }
button.live-badge:hover, button.live-badge[aria-expanded="true"] { background: var(--danger-hover); }
.voice-watchers {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-caption);
}
.stream-preview {
  position: fixed;
  z-index: 20;
  max-width: calc(100vw - 16px);
  overflow: hidden;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.stream-preview-still {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-panel);
}
.stream-preview-still img { width: 100%; height: 100%; object-fit: contain; }
.stream-preview-empty { color: var(--text-muted); font-size: var(--text-sm); }
.stream-preview-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
}
.stream-preview-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); color: var(--text); }
.stream-preview-foot .btn-primary { flex-shrink: 0; height: var(--control-md); padding: 0 var(--space-6); }
.vb-join { font-size: var(--text-sm); font-weight: var(--weight-semibold); }

.user-panel {
  --presence-ring: var(--surface-panel);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-2);
}
.user-panel-profile {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: var(--space-2);
  border: none;
  border-radius: var(--radius-md);
  background: none;
  text-align: left;
  cursor: pointer;
}
.user-panel-profile:hover { background: var(--surface-control); }
.user-panel-text { flex: 1; min-width: 0; margin: 0 var(--space-3); display: flex; flex-direction: column; }
.user-panel .icon-btn { width: 30px; height: 30px; }
.user-panel-name { font-weight: var(--weight-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel-role { font-size: var(--text-caption); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-panel:has(.notify-menu) { position: relative; }
.notify-menu-pop {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: var(--space-5);
  right: var(--space-5);
  z-index: 10;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
/* A person's right-click menu, at the pointer. */
.user-menu {
  position: fixed;
  z-index: 65;
  width: 220px;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.user-menu button {
  padding: var(--space-4) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.user-menu button:hover, .user-menu button:focus-visible { background: var(--accent-soft); color: var(--text-strong); outline: none; }
.user-menu-divider { height: 1px; margin: var(--space-2) var(--space-3); border: none; background: var(--border); }
.notify-menu-title { padding: var(--space-3) var(--space-5); font-size: var(--text-caption); color: var(--text-muted); }
.notify-menu-pop button {
  padding: var(--space-4) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
}
.notify-menu-pop button:hover { background: var(--surface-control); }
.notify-menu-pop button[aria-checked="true"] { color: var(--accent); font-weight: var(--weight-semibold); }
.notify-menu-section { margin-top: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.notify-menu-hint { margin: 0; padding: 0 var(--space-5) var(--space-3); font-size: var(--text-sm); color: var(--text-secondary); }

/* Voice connection card in the sidebar */
.voice-bar {
  margin: 0 var(--space-5) var(--space-5);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  background: var(--surface-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}
.voice-bar-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.voice-bar-info { min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.voice-bar-status {
  align-self: flex-start;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--success);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  cursor: pointer;
}
.voice-bar-status:hover .voice-bar-status-text { text-decoration: underline; }
.voice-bar-status-text { display: flex; align-items: center; gap: var(--space-3); }
.voice-bar-status.pending { color: var(--warning); }
.voice-bar-channel { color: var(--text-secondary); font-size: var(--text-caption); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-bar-ptt { color: var(--text-muted); font-size: var(--text-caption); }
.voice-bar-ptt.talking { color: var(--success); font-weight: var(--weight-semibold); }
.voice-bar-buttons { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-3); }
.vb-btn {
  height: var(--control-md);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: var(--surface-control);
  color: var(--text);
}
.vb-btn:hover { background: var(--surface-control-hover); }
.vb-btn.off { background: var(--danger-soft); color: var(--danger-text); }
.vb-btn.on { background: var(--accent-soft); color: var(--accent-hover); }
.vb-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.vb-btn:disabled:hover { background: var(--surface-control); }
.voice-bar-notice {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--warning);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--warning);
  font: inherit;
  font-size: var(--text-caption);
  text-align: left;
  cursor: pointer;
}
/* Share Screen and its quality menu, one button split by a hairline. */
.vb-split { position: relative; display: flex; gap: 1px; min-width: 0; }
.vb-split > .vb-btn { flex: 1; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.quality-menu { display: flex; }
.vb-caret { width: var(--control-md); flex: none; color: var(--text-muted); border-top-left-radius: 0; border-bottom-left-radius: 0; }
.vb-split:has(> .vb-btn.on) .vb-caret { background: var(--accent-soft); color: var(--accent-hover); }
.quality-menu-pop {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  right: 0;
  z-index: 10;
  width: 220px;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.quality-menu-title { padding: var(--space-3) var(--space-5); font-size: 12px; color: var(--text-muted); }
.quality-menu-note { padding: var(--space-3) var(--space-5); font-size: 12px; color: var(--text-muted); }
.quality-menu-pop button {
  padding: var(--space-4) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
}
.quality-menu-pop button:hover { background: var(--surface-control); }
.quality-menu-pop button[aria-checked="true"] { color: var(--accent); font-weight: var(--weight-semibold); }
.vb-leave {
  width: var(--control-md);
  height: var(--control-md);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--danger);
  color: var(--text-on-danger);
}
.vb-leave:hover { background: var(--danger-hover); }

/* Channel area */
.main main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface-main);
}
.channel-header {
  --presence-ring: var(--surface-app);
  height: var(--header-height);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-9);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.call-btn, .in-call-pill { margin-left: auto; }
.call-btn {
  flex: none;
  height: var(--control-md);
  padding: 0 var(--space-5);
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  cursor: pointer;
}
.call-btn:hover { background: var(--surface-control); }
.call-btn.ongoing { border-color: var(--success); color: var(--success); }
.call-btn:disabled { opacity: 0.6; cursor: default; }
.channel-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); color: var(--text-muted); }
.channel-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text);
}
.connection-banner {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-9);
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--warning);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}

.instance-health-banner {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-9);
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.instance-health-banner strong { color: var(--text); font-weight: var(--weight-semibold); }
.instance-health-banner svg { flex: none; color: var(--warning); }

.header-pill {
  padding: 3px var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.call-btn ~ .header-actions, .in-call-pill ~ .header-actions { margin-left: 0; }
.mute-btn.on { color: var(--warning); }
.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 220px;
  height: var(--control-md);
  padding: 0 var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-input);
  color: var(--text-muted);
}
.search-box:focus-within { border-color: var(--focus-ring); }
.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
}

.main main { position: relative; container-type: inline-size; }
/* A chat squeezed by side panels keeps its header to icons, as on phones. */
@container (max-width: 880px) {
  .call-btn { padding: 0; width: var(--control-md); justify-content: center; }
  .call-btn-label, .channel-status { display: none; }
  .search-box { width: var(--control-md); padding: 0; justify-content: center; }
  .search-box:focus-within { position: absolute; left: var(--space-6); right: var(--space-6); width: auto; z-index: 25; padding: 0 var(--space-5); background: var(--surface-input); }
  .search-box input { flex: 0 0 0; width: 0; }
  .search-box:focus-within input { flex: 1; width: auto; }
}
.search-panel {
  position: absolute;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  z-index: 20;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface-panel);
  box-shadow: var(--shadow-pop);
}
/* On wide screens the panel sits beside the conversation instead of over it. */
@media (min-width: 1100px) {
  .main main.searching > :not(.channel-header, .search-panel) { margin-right: min(400px, 100%); }
}
.search-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-6) var(--space-4) var(--space-8);
}
.search-scope { display: flex; gap: var(--space-2); min-width: 0; }
.search-scope button {
  max-width: 220px;
  padding: var(--space-2) var(--space-5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}
.search-scope button[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.search-status { margin: 0; padding: 0 var(--space-8); font-size: var(--text-sm); color: var(--text-muted); }
.search-status:empty { display: none; }
.search-results {
  flex: 1;
  margin: 0;
  padding: var(--space-4) var(--space-4) var(--space-6);
  overflow-y: auto;
  list-style: none;
}
.search-result {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-6);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.search-result:hover { background: var(--surface-raised); }
.search-result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-caption);
  color: var(--text-muted);
}
.search-result-place { color: var(--text-secondary); font-weight: var(--weight-semibold); }
.search-result-author { color: var(--text); font-weight: var(--weight-semibold); }
.search-result-body {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: var(--text-md);
}
.search-result-body mark {
  border-radius: var(--space-1);
  background: var(--accent-soft);
  color: var(--text-strong);
}
.search-more {
  margin: 0 var(--space-8) var(--space-8);
  height: var(--control-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}
.search-more:disabled { opacity: 0.6; cursor: default; }

.history-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  margin: 0 var(--space-10);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.history-notice button {
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.channel.muted .name, .channel-link.muted .name { color: var(--text-muted); }
.channel .muted-icon { flex: none; color: var(--text-muted); }

.main main .messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-9) var(--space-10) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.main main .messages:focus-visible { outline-offset: -2px; }
.day-divider {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin: var(--space-4) 0;
  color: var(--text-muted);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
}
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg {
  display: flex;
  gap: var(--space-7);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  line-height: var(--leading);
}
.msg:hover { background: var(--surface-raised); }
.msg-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.msg-header { display: flex; align-items: baseline; gap: var(--space-5); }
.msg .name {
  padding: 0;
  border: none;
  background: none;
  font-weight: var(--weight-bold);
  cursor: pointer;
}
.msg .name:hover { text-decoration: underline; }
.msg-avatar, .header-avatar {
  flex: none;
  align-self: flex-start;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.header-avatar { align-self: center; display: inline-flex; }
.msg .meta { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.msg .body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-row { position: relative; border-radius: var(--radius-sm); transition: background var(--transition-fast); }
.msg-row.msg-flash { background: var(--accent-soft); }
.msg .edited { margin-left: var(--space-3); font-size: var(--text-xs); color: var(--text-muted); }
.pinned-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: var(--space-3);
  font-size: var(--text-xs);
  color: var(--accent);
  vertical-align: baseline;
}

.pins-menu { position: relative; }
.pins-pop {
  position: absolute;
  top: calc(100% + var(--space-4));
  right: 0;
  z-index: 20;
  width: min(420px, calc(100vw - 2 * var(--space-8)));
  max-height: min(560px, 70vh);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  color: var(--text);
}
.pins-title {
  margin: 0;
  padding: var(--space-6) var(--space-8);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}
.pins-empty { margin: 0; padding: var(--space-10) var(--space-8); color: var(--text-muted); text-align: center; }
.pins-list { margin: 0; padding: var(--space-2); list-style: none; overflow-y: auto; }
.pin {
  display: flex;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-sm);
  line-height: var(--leading);
}
.pin:hover { background: var(--surface-raised); }
.pin-content { flex: 1; min-width: 0; }
.pin-header { display: flex; align-items: baseline; gap: var(--space-4); }
.pin-name { font-weight: var(--weight-semibold); }
.pin .meta { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.pin .body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pin-attachments { font-size: var(--text-sm); color: var(--text-muted); }
.pin-actions { display: flex; align-items: flex-start; gap: var(--space-2); }
.pin-actions button {
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-control);
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
}
.pin-jump { padding: 0 var(--space-4); }
.pin-remove { width: 24px; display: flex; align-items: center; justify-content: center; }
.pin-actions button:hover { background: var(--surface-control-hover); color: var(--text); }

.msg-actions {
  position: absolute;
  top: calc(-1 * var(--space-5));
  right: var(--space-6);
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-control);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}
.msg-row:hover .msg-actions, .msg-row:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg-row:focus { outline: none; }
.msg-actions button {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
}
.msg-actions button:hover { background: var(--surface-control-hover); color: var(--text); }
.msg-actions button.danger:hover { background: var(--danger); color: var(--text-on-danger); }

.reactions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-control);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.reaction:hover { background: var(--surface-control-hover); color: var(--text); }
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.reaction-emoji { font-size: var(--text-md); line-height: 1; }
.reaction-add { color: var(--text-muted); opacity: 0; transition: opacity var(--transition-fast); }
.msg-row:hover .reaction-add, .msg-row:focus-within .reaction-add { opacity: 1; }

.emoji-picker {
  position: fixed;
  z-index: 60;
  width: 432px;
  height: 460px;
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.emoji-header { display: flex; padding: var(--space-5); border-bottom: 1px solid var(--border); }
.emoji-search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--control-md);
  padding: 0 var(--space-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-input);
  color: var(--text-muted);
}
.emoji-search-box:focus-within { border-color: var(--focus-ring); }
.emoji-search {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-md);
  outline: none;
}
.emoji-search::-webkit-search-cancel-button { display: none; }
.emoji-body { flex: 1; min-height: 0; display: flex; }
.emoji-rail {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-3);
  border-right: 1px solid var(--border);
  background: var(--surface-sunken);
  overflow-y: auto;
  scrollbar-width: none;
}
.emoji-rail-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 28px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.emoji-rail-button:hover { background: var(--surface-control); color: var(--text); }
.emoji-rail-button.current { background: var(--surface-selected); color: var(--text-strong); }
.emoji-rail-button .custom-emoji { width: 20px; height: 20px; vertical-align: middle; }
.emoji-scroll { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--space-4); }
.emoji-scroll section { position: relative; }
.emoji-section-title {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 32px;
  margin: 0;
  padding: var(--space-6) var(--space-2) 0;
  background: var(--surface-app);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}
.emoji-results { padding: var(--space-4) 0; box-sizing: content-box; }
.emoji-rows { position: relative; }
.emoji-row { position: absolute; left: 0; right: 0; height: 40px; display: grid; }
.emoji-cell {
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  font-size: 26px;
  line-height: 1;
}
.emoji-cell.active { background: var(--surface-control); }
.emoji-empty { display: flex; justify-content: center; align-items: center; gap: var(--space-3); margin: var(--space-10) 0; color: var(--text-muted); }
.emoji-retry { padding: 0; border: none; background: none; color: var(--accent); font: inherit; text-decoration: underline; }
.emoji-preview {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  height: 52px;
  padding: 0 var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.emoji-preview-char { display: grid; place-items: center; width: 32px; font-size: 28px; line-height: 1; }
.emoji-preview-char .custom-emoji { width: 32px; height: 32px; }
.emoji-preview-text { display: flex; flex-direction: column; min-width: 0; }
.emoji-preview-name { overflow: hidden; color: var(--text-strong); font-weight: var(--weight-semibold); text-overflow: ellipsis; white-space: nowrap; }
.emoji-preview-name::first-letter { text-transform: uppercase; }
.emoji-preview code { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.emoji-hint { color: var(--text-muted); font-size: var(--text-caption); }
@media (max-width: 480px) {
  .emoji-picker {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(70vh, 480px);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  .emoji-preview { display: none; }
}

.custom-emoji { width: 1.375em; height: 1.375em; object-fit: contain; vertical-align: -0.3em; }
.emoji-cell .custom-emoji { width: 28px; height: 28px; vertical-align: middle; }
.reaction-emoji .custom-emoji { width: 1.25em; height: 1.25em; vertical-align: middle; }

.gif-picker { width: 420px; height: 440px; }
.gif-scroll { flex: 1; overflow-y: auto; padding: 0 var(--space-4) var(--space-4); }
.gif-grid { columns: 2; column-gap: var(--space-3); }
.gif-grid[aria-busy="true"] { opacity: 0.6; }
.gif-cell {
  display: block;
  width: 100%;
  margin-bottom: var(--space-3);
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-control);
  overflow: hidden;
  break-inside: avoid;
}
.gif-cell img { display: block; width: 100%; height: auto; }
.gif-cell:hover, .gif-cell:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.gif-attribution {
  margin: 0;
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-caption);
  text-align: right;
}
@media (max-width: 480px) {
  .gif-picker { width: auto; height: min(70vh, 480px); }
}

.compose-box .gif-btn { width: auto; padding: 0 var(--space-3); font-size: var(--text-xs); font-weight: var(--weight-bold); letter-spacing: 0.04em; }
.emoji-admin-image { width: 32px; height: 32px; }

.reply-quote {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  margin-bottom: var(--space-1);
  padding: 0;
  border: none;
  background: transparent;
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: left;
}
.reply-quote .reply-name { flex: none; font-weight: var(--weight-semibold); color: var(--text-secondary); }
.reply-quote .reply-body { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-quote:hover .reply-body { color: var(--text); }
.reply-quote.deleted { font-style: italic; }

.msg-editor { margin-top: var(--space-2); }
.msg-editor textarea {
  display: block;
  width: 100%;
  min-height: var(--control-md);
  max-height: 40vh;
  field-sizing: content;
  padding: var(--space-4) var(--space-6);
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  line-height: var(--leading);
  resize: none;
  outline: none;
}
.msg-editor textarea:focus-visible { border-color: var(--focus-ring); }
.msg-editor-hint, .msg-editor-error { margin: var(--space-2) 0 0; font-size: var(--text-xs); color: var(--text-muted); }
.msg-editor-hint button { padding: 0; border: none; background: transparent; color: var(--accent); }
.msg-editor-hint button:hover { text-decoration: underline; }
.msg-editor-error { color: var(--danger-text); }
.empty { color: var(--text-muted); text-align: center; margin: auto; }
.new-messages {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin: var(--space-5) 0;
  color: var(--danger-text);
  font-size: 12px;
  font-weight: var(--weight-bold);
}
.new-messages::before { content: ""; flex: 1; height: 1px; background: var(--danger); }
.new-messages::after { content: ""; width: 24px; height: 1px; background: var(--danger); }
.empty { color: var(--text-muted); text-align: center; margin: auto; }
.new-messages {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin: var(--space-5) 0;
  color: var(--danger-text);
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
}
.new-messages::before { content: ""; flex: 1; height: 1px; background: var(--danger); }
.new-messages::after { content: ""; width: 24px; height: 1px; background: var(--danger); }

.main main .compose { position: relative; padding: var(--compose-margin); }
/* Who's typing floats just above the composer, over the end of the messages. */
.main main .compose .compose-footer {
  position: absolute;
  bottom: calc(100% - var(--space-2));
  left: calc(var(--compose-margin) + var(--space-4));
  z-index: 5;
  min-height: 0;
  margin: 0;
}
.main main .compose .typing:not(:empty) {
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-main);
}
.compose-box {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  padding: var(--compose-pad);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
}
.compose-box:focus-within { border-color: var(--focus-ring); }
.compose-box textarea {
  flex: 1;
  min-width: 0;
  margin: 0;
  max-height: 40vh;
  min-height: var(--compose-row);
  padding: calc((var(--compose-row) - var(--leading) * 1em) / 2) 0;
  border: none;
  outline: none;
  background: transparent;
  line-height: var(--leading);
  resize: none;
  overflow-y: auto;
}
.compose-box textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.compose-closed {
  margin: 0;
  padding: var(--space-6) var(--space-10) var(--space-10);
  color: var(--text-muted);
  font-size: var(--text-md);
  text-align: center;
}
.suggestions {
  position: absolute;
  bottom: calc(100% + var(--space-3));
  left: 0;
  right: 0;
  z-index: 20;
  padding: var(--space-2);
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.suggestions-title {
  margin: 0;
  padding: var(--space-3) var(--space-4) var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
}
.suggestions [role="option"] {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.suggestions [role="option"].active { background: var(--surface-selected); }
.suggestion-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-emoji { width: var(--control-sm); text-align: center; font-size: var(--text-lg); line-height: 1; }
.suggestion-detail { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  min-height: 16px;
  margin: var(--space-3) var(--space-2) 0;
  font-size: var(--text-caption);
  color: var(--text-muted);
}
.typing { display: flex; align-items: center; gap: var(--space-3); min-width: 0; color: var(--text-secondary); }
.typing-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing-dots { display: inline-flex; gap: var(--space-1); }
.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: typing-dot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-dot { 0%, 60%, 100% { opacity: 0.35; } 30% { opacity: 1; } }
.reply-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.reply-bar strong { color: var(--text); }
.reply-bar button {
  width: var(--control-sm);
  height: var(--control-sm);
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.reply-bar button:hover { background: var(--surface-control-hover); color: var(--text); }

.compose-box .icon-btn { width: var(--compose-row); height: var(--compose-row); }
.compose-box .icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.compose-status { margin-bottom: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); }

.attachment-tray { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: flex; gap: var(--space-4); overflow-x: auto; }
.attachment-tray > .pending {
  position: relative;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 120px;
  padding: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
}
.attachment-tray > .pending.failed { border-color: var(--danger); }
.pending-thumb {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-control);
}
.pending-file {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-transform: uppercase;
}
.pending-name {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-error { font-size: var(--text-xs); color: var(--danger-text); }
.attachment-tray > .pending progress { width: 100%; height: 4px; accent-color: var(--accent); }
.pending-remove {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  width: var(--control-sm);
  height: var(--control-sm);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-overlay);
  color: var(--text);
  font-size: var(--text-xs);
  line-height: 1;
}
.pending-remove:hover { background: var(--danger); }

/* Attachments and link previews */
.chat { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.drop-overlay {
  position: absolute;
  inset: var(--space-4);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-2xl);
  background: var(--surface-overlay);
  color: var(--text-strong);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  pointer-events: none;
}
.attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 200px));
  gap: var(--space-2);
  max-width: var(--media-max-w);
  margin-top: var(--space-3);
}
.attachments.single { display: block; }
.attachment {
  display: block;
  max-width: 100%;
  max-height: var(--media-max-h);
  padding: 0;
  overflow: hidden;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--surface-control);
  cursor: zoom-in;
}
.attachments.single .attachment { width: min(var(--media-max-w), 100%, var(--media-max-h) * var(--aspect, 1)); }
.attachment img { display: block; width: 100%; height: 100%; object-fit: cover; }
.attachments.single .attachment img { object-fit: contain; }
.video-attachment { width: min(var(--media-max-w), 100%); margin: var(--space-3) 0 0; }
.video-attachment video {
  display: block;
  width: 100%;
  max-height: var(--media-max-h);
  aspect-ratio: 16 / 9;
  object-fit: contain;
  border-radius: var(--radius-lg);
  background: var(--surface-control);
}
.video-attachment figcaption { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.file-card {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  width: min(420px, 100%);
  margin-top: var(--space-3);
  padding: var(--space-5) var(--space-6);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-decoration: none;
}
.file-card:hover { background: var(--surface-control); color: var(--text); }
.file-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.file-card-name {
  color: var(--accent);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-card-size { font-size: var(--text-xs); color: var(--text-muted); }
.msg .body a { color: var(--accent); }
.msg .body a:hover { color: var(--accent-hover); }
.md-code {
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: 0.875em;
}
.md-pre {
  margin: var(--space-2) 0;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  white-space: pre;
  overflow-x: auto;
}
.md-quote {
  margin: var(--space-1) 0;
  padding-left: var(--space-5);
  border-left: 4px solid var(--border-strong);
}
.spoiler { border-radius: var(--radius-sm); background: var(--surface-control); }
.spoiler:not(.revealed) {
  color: transparent;
  background: var(--surface-control-hover);
  cursor: pointer;
  user-select: none;
}
.spoiler:not(.revealed) * { color: transparent; background: transparent; border-color: transparent; }
.msg .body .spoiler:not(.revealed):hover { background: var(--border-strong); }
.link-preview {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: fit-content;
  max-width: min(100%, 520px);
  margin-top: var(--space-3);
  padding: var(--space-5) var(--space-6);
  background: var(--surface-raised);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
}
.link-preview.bare { padding: 0; background: none; border-left: none; }
.link-preview-row { display: flex; gap: var(--space-6); }
.link-preview-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); padding-right: var(--space-8); }
.link-preview-site { font-size: var(--text-xs); color: var(--text-muted); }
.link-preview-title { font-weight: var(--weight-bold); color: var(--accent); text-decoration: none; }
.link-preview-title:hover { color: var(--accent-hover); text-decoration: underline; }
.link-preview-desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.link-preview-image { display: block; flex: none; width: 80px; height: 80px; object-fit: cover; border-radius: var(--radius-sm); }
.link-preview-remove {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-overlay);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
}
.link-preview-remove:hover { color: var(--text-strong); }
.msg-row:hover .link-preview-remove,
.msg-row:focus-within .link-preview-remove,
.link-preview-remove:focus-visible { opacity: 1; }
.embed-media img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 400px);
  max-height: var(--media-max-h);
  border-radius: var(--radius-md);
}
.embed-player {
  position: relative;
  width: 440px;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}
.embed-player.vertical { width: 260px; aspect-ratio: 9 / 16; }
.embed-player iframe,
.embed-player video { display: block; width: 100%; height: 100%; border: 0; background: var(--surface-sunken); }
.embed-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  background: var(--surface-sunken);
  color: var(--text-strong);
  cursor: pointer;
}
.embed-play img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.embed-play-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-overlay);
  transition: transform 0.12s ease;
}
.embed-play-icon svg { margin-left: 3px; fill: currentColor; }
.embed-play:hover .embed-play-icon,
.embed-play:focus-visible .embed-play-icon { transform: scale(1.08); background: var(--accent); color: var(--text-on-accent); }
.embed-file-name {
  position: absolute;
  left: var(--space-6);
  right: var(--space-6);
  bottom: var(--space-5);
  overflow: hidden;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--viewer-backdrop);
}
.lightbox-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 48px;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--viewer-text-secondary);
}
.lightbox-about { display: flex; flex: 1; align-items: center; gap: var(--space-3); min-width: 0; }
.lightbox-sender { color: var(--viewer-text); font-weight: var(--weight-semibold); white-space: nowrap; }
.lightbox-time { white-space: nowrap; }
.lightbox-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-status { color: var(--viewer-text); white-space: nowrap; }
.lightbox-actions { display: flex; align-items: center; gap: var(--space-1); }
.lightbox-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--viewer-text);
  cursor: pointer;
}
.lightbox-action:hover, .lightbox-zoom:hover { background: var(--viewer-control-hover); }
.lightbox-zoom {
  min-width: 56px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--viewer-text);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.lightbox-more { display: none; }
.lightbox-stage { position: relative; flex: 1; overflow: hidden; touch-action: none; }
.lightbox-picture { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.lightbox-picture img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
  user-select: none;
}
.lightbox-stage.zoomed .lightbox-picture img { cursor: grab; }
.lightbox-stage.zoomed .lightbox-picture img:active { cursor: grabbing; }
.lightbox-preview { filter: blur(6px); }
.lightbox-failed {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  color: var(--viewer-text);
  pointer-events: none;
}
.lightbox-failed button { pointer-events: auto; }
.lightbox-step {
  position: absolute;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--viewer-control);
  color: var(--viewer-text);
  transform: translateY(-50%);
  cursor: pointer;
}
.lightbox-step.prev { left: var(--space-4); }
.lightbox-step.next { right: var(--space-4); }
.lightbox-step:hover:not(:disabled) { background: var(--viewer-control-hover); }
.lightbox-step:disabled { opacity: 0.35; cursor: default; }
.lightbox-count {
  position: absolute;
  bottom: var(--space-4);
  left: 50%;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--viewer-control);
  color: var(--viewer-text);
  font-size: var(--text-sm);
  transform: translateX(-50%);
}
@media (max-width: 600px) {
  .lightbox-time, .lightbox-name { display: none; }
  .lightbox-more { display: inline-flex; }
  .lightbox-actions { display: none; }
  .lightbox-actions.open {
    position: absolute;
    top: 100%;
    right: var(--space-4);
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-2);
    border-radius: var(--radius-lg);
    background: var(--viewer-raised);
    box-shadow: var(--shadow-pop);
  }
  .lightbox-step { display: none; }
}

.nav-toggle, .nav-scrim, .compose-send { display: none; }

.call-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}
.call-bar .vb-btn, .call-bar .vb-leave { width: 44px; height: 44px; }
.call-bar-channel {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: var(--weight-semibold);
  text-align: left;
}
.call-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-bar-status { display: flex; color: var(--success); }
.call-bar-status.pending { color: var(--warning); }

@media (max-width: 768px) {
  .sidebar-resizer { display: none; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(calc(var(--sidebar-width) + var(--server-rail-width)), 92vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s 0.2s;
  }
  .nav-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-dialog);
  }
  .nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    border: none;
    background: var(--surface-scrim);
  }
  .nav-toggle { display: inline-flex; width: 44px; height: 44px; margin-left: calc(-1 * var(--space-4)); }
  .channel-header { padding: 0 var(--space-6); gap: var(--space-3); }
  .search-box { width: 44px; padding: 0; justify-content: center; }
  .search-box:focus-within { position: absolute; left: var(--space-6); right: var(--space-6); width: auto; z-index: 25; padding: 0 var(--space-5); background: var(--surface-input); }
  .search-box input { flex: 0 0 0; width: 0; }
  .search-box:focus-within input { flex: 1; width: auto; }
  .history-notice { margin: 0 var(--space-6); }
  .connection-banner { padding: var(--space-3) var(--space-6); }
  .instance-health-banner { padding: var(--space-2) var(--space-6); }
  .channel, .voice-user { min-height: 44px; }
  .section-add { width: 44px; height: 44px; margin: -10px -10px -10px 0; }
  .main main .messages { padding: var(--space-6) var(--space-6) var(--space-2); }
  .msg { gap: var(--space-5); padding: var(--space-3) var(--space-2); }
  .main main .compose { padding: var(--space-4) var(--space-6) var(--space-10); }
  .compose-box { --compose-row: 44px; border-radius: var(--radius-pill); }
  .compose-footer:has(.typing:empty) { display: none; }
  .compose-send { display: inline-flex; color: var(--accent); }
  .call-btn { padding: 0; width: 44px; height: 44px; justify-content: center; }
  .call-btn-label, .channel-status { display: none; }
  .header-pill { flex: none; }
  .header-pill:not(.in-call-pill) { display: none; }
  input, select, textarea { font-size: 16px; }
  .msg-actions button { width: 40px; height: 40px; }
  .pins-pop { position: fixed; top: var(--header-height); left: var(--space-4); right: var(--space-4); width: auto; }
  .pin-actions button { height: 36px; }
  .pin-remove { width: 36px; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: var(--space-6); }
}

/* Touch screens have no hover, so menus that appear on hover stay visible. */
@media (hover: none) {
  .channel .channel-menu { opacity: 1; }
  .section-menu { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner, .tile-connecting { animation-duration: 1.5s !important; animation-iteration-count: infinite !important; }
}

/* Video */
.video-area { display: flex; flex-direction: column; background: var(--surface-sunken); }
.voice-stage { padding: var(--space-9) var(--space-9) 0; }
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-6);
  padding: var(--space-9);
  background: var(--surface-sunken);
}
.video-grid video {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--surface-raised);
}
.video-tile {
  position: relative;
  margin: 0;
  overflow: hidden;
  background: var(--surface-raised);
  border: 2px solid var(--border);
  border-radius: var(--radius-2xl);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.video-tile video { transform: scaleX(-1); }
.video-tile.speaking {
  border-color: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 22%, transparent);
}
.video-tile.no-video video { visibility: hidden; }
.video-tile.connecting .avatar { filter: brightness(0.45) saturate(0.7); }
.tile-connecting {
  position: absolute;
  width: 80px;
  height: 80px;
  box-sizing: border-box;
  border: 3px solid var(--surface-control);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.tile-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-tile .label {
  position: absolute;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  left: var(--space-4);
  bottom: var(--space-4);
  padding: 3px var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-overlay);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
}
.label-muted { color: var(--danger-text); }

.video-grid.strip { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.screen-tile {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  background: var(--surface-raised);
}
.voice-stage .screen-tile { height: min(60vh, 56vw); }
.screen-tile video { width: 100%; height: 100%; display: block; object-fit: contain; background: var(--surface-sunken); }
.screen-tile.thumbnail video { aspect-ratio: 16 / 10; }
.screen-tile:fullscreen { border: none; border-radius: 0; }
.screen-tile .label {
  position: absolute;
  left: var(--space-6);
  bottom: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-overlay);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.screen-tile .label svg { color: var(--accent); }
.screen-stats {
  position: absolute;
  top: var(--space-6);
  right: var(--space-6);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-overlay);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.screen-fullscreen,
.screen-popout {
  position: absolute;
  right: var(--space-6);
  bottom: var(--space-6);
  width: var(--control-md);
  height: var(--control-md);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: var(--surface-overlay);
  color: var(--text);
}
.screen-popout { right: calc(var(--space-6) + var(--control-md) + var(--space-3)); }
.screen-fullscreen:hover, .screen-popout:hover { background: var(--surface-control-hover); }
.screen-popout[aria-pressed="true"] { color: var(--accent); }
.pip-host { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.screen-select { position: absolute; inset: 0; border: none; background: transparent; }

/* Error overlay */
#error-log {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  padding: var(--space-4);
  max-height: 40vh;
  overflow: hidden;
  pointer-events: none;
}
.error-toast {
  pointer-events: auto;
  max-width: 420px;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--danger);
  color: var(--text-on-danger);
  font: var(--text-caption)/1.3 var(--font-mono);
  overflow-wrap: anywhere;
  animation: toast-in 0.2s ease-out, toast-out 0.4s ease-in 7.6s forwards;
}
.error-toast.warn { background: var(--surface-selected); }
.error-toast.info { background: var(--surface-raised); color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; } }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface-control);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 13px; height: 13px; border-width: 2px; border-color: color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }

.center { display: flex; justify-content: center; align-items: center; height: 100%; }
/* Over the app while its first lists load, then fades away. */
.boot-cover {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--surface-app);
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
}
.boot-cover.done { opacity: 0; visibility: hidden; pointer-events: none; }

/* Sign-in notices */
.auth-notice {
  margin: 0;
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  font-size: var(--text-md);
}
.auth-hint { margin: 0; color: var(--text-muted); font-size: var(--text-md); }

/* Server settings */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  background: var(--surface-overlay);
}
.modal {
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-pop);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-8) var(--space-8) var(--space-4) var(--space-10);
}
.modal-header h2 { margin: 0; font-size: var(--text-lg); }
.tabs { display: flex; gap: var(--space-2); padding: 0 var(--space-10); border-bottom: 1px solid var(--border); }
.tabs button {
  padding: var(--space-4) var(--space-5);
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text-strong); border-bottom-color: var(--accent); }
.modal-body { overflow-y: auto; padding: var(--space-8) var(--space-10) var(--space-10); }

.invite-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-6); margin-bottom: var(--space-8); }
.invite-form label { display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-secondary); }
.invite-form select,
.emoji-form input:not([type="file"]) {
  height: var(--control-md);
  padding: 0 var(--space-4);
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}

.primary, .secondary-btn, .danger-btn {
  height: var(--control-md);
  padding: 0 var(--space-7);
  flex: none;
  border: none;
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
}
.primary { background: var(--accent); color: var(--text-on-accent); }
.primary:hover { background: var(--accent-hover); }
.secondary-btn { background: var(--surface-control); color: var(--text); }
.secondary-btn:hover { background: var(--surface-control-hover); }
.danger-btn { background: var(--danger-soft); color: var(--danger-text); }
.danger-btn:hover { background: var(--danger); color: var(--text-strong); }

.admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.admin-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-panel);
}
.admin-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.admin-row-meta { font-size: var(--text-sm); color: var(--text-muted); }
.admin-empty { color: var(--text-muted); padding: var(--space-4) 0; }
.invite-code { font-family: var(--font-mono); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-name { display: flex; align-items: center; gap: var(--space-3); font-weight: var(--weight-semibold); }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }

/* Password recovery */
.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: var(--text-md);
}
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }
.auth input[hidden] { display: none; }
.auth-note { margin: 0; max-width: 400px; color: var(--text-secondary); font-size: var(--text-md); }
.auth-note strong { color: var(--text-strong); }
div.auth-note { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-3); }
div.auth-note p { margin: 0; }

.field-label-row .link-btn { font-size: var(--text-sm); }

/* Moderation */
.compose-locked { color: var(--danger-text); }
.timeout-select {
  height: var(--control-md);
  padding: 0 var(--space-4);
  background: var(--surface-control);
  color: var(--text);
  border: none;
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
}
.audit-more { margin-top: var(--space-6); }
.danger-zone h3 { color: var(--danger-text); }

.channel-notify-menu { position: relative; }
.channel-notify-menu .notify-menu-pop { top: calc(100% + var(--space-2)); bottom: auto; left: auto; right: 0; width: 240px; }
.notify-menu-pop button[role="menuitemcheckbox"]::after { content: ""; float: right; }
.notify-menu-pop button[role="menuitemcheckbox"][aria-checked="true"]::after { content: "✓"; }

.friend-btn { flex: none; }
.tab-badge { margin-left: var(--space-3); }
.add-friend { display: flex; flex-direction: column; gap: var(--space-6); align-items: flex-start; max-width: 560px; }
.add-friend .field { align-self: stretch; }
.add-friend-title { margin: 0; font-size: var(--text-lg); color: var(--text-strong); }

/* Home: the friends page */
.friends-header .channel-icon { color: var(--text-muted); }
.friends-header .channel-title { flex: none; font-size: var(--text-subtitle); }
.header-divider { width: 1px; height: 22px; flex: none; background: var(--border-strong); }
.friends-tabs { display: flex; gap: var(--space-2); min-width: 0; overflow-x: auto; }
.friends-tabs button {
  height: 28px;
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-md);
  cursor: pointer;
}
.friends-tabs button:hover { background: var(--surface-control); color: var(--text); }
.friends-tabs button[aria-selected="true"] { background: var(--surface-selected); color: var(--text-strong); font-weight: var(--weight-semibold); }
.add-friend-btn {
  height: 28px;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-6);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--text-on-accent);
  font: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}
.add-friend-btn:hover { background: var(--accent-hover); }
.add-friend-btn[aria-pressed="true"] { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.friends-page { flex: 1; min-height: 0; display: flex; }
.friends-main {
  --presence-ring: var(--surface-main);
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: var(--space-8) var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.friends-search {
  height: var(--control-md);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding: 0 var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-input);
  color: var(--text-muted);
}
.friends-search:focus-within { border-color: var(--focus-ring); }
.friends-search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--text); font: inherit; }
.friends-count {
  margin: 0;
  padding: var(--space-2) 0 var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.friends-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.friends-empty { padding: var(--space-6) 0; color: var(--text-muted); font-size: var(--text-md); }
.friend-row {
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-5);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.friend-row:hover { background: var(--surface-raised); }
.friend-row .avatar, .friend-row .dm-group-icon { width: 36px; height: 36px; font-size: var(--text-md); }
.friend-text, .active-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.friend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-semibold); color: var(--text-strong); }
.friend-username { font-weight: var(--weight-regular); color: var(--text-muted); }
.friend-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-caption); color: var(--text-muted); }
.friend-sub.in-voice { color: var(--success); }
.friend-actions { flex: none; display: flex; align-items: center; gap: var(--space-4); }
.friend-actions .btn-primary, .friend-actions .btn-secondary, .friend-actions .btn-ghost { height: 32px; }
.round-btn {
  width: var(--control-md);
  height: var(--control-md);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-control);
  color: var(--text);
  cursor: pointer;
}
.round-btn:hover, .round-btn[aria-expanded="true"] { background: var(--surface-control-hover); }
.more-menu { position: relative; }
.more-menu .channel-menu-pop { right: 0; left: auto; top: calc(100% + var(--space-2)); }
.active-now {
  width: 300px;
  flex: none;
  overflow-y: auto;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  border-left: 1px solid var(--border);
}
.active-now h2 { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text-strong); }
.active-now-empty { margin: 0; color: var(--text-muted); font-size: var(--text-sm); line-height: var(--leading); }
.active-card {
  --presence-ring: var(--surface-sidebar);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-7);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-sidebar);
}
.active-card-head { display: flex; align-items: center; gap: var(--space-5); }
.active-card-head .avatar { width: 32px; height: 32px; }
.active-card-head .live-badge { flex: none; }
.active-card-with { margin: 0; display: flex; align-items: center; gap: var(--space-3); color: var(--text-secondary); font-size: var(--text-caption); }
.active-card-here { margin: 0; color: var(--success); font-size: var(--text-sm); }
.active-card .btn-secondary { height: 32px; }
@media (max-width: 1100px) {
  .active-now { display: none; }
}
@media (max-width: 768px) {
  .friends-header .channel-icon, .header-divider, .add-friend-label { display: none; }
  .add-friend-btn { width: 44px; height: 44px; justify-content: center; padding: 0; }
  .friends-tabs button { height: 44px; }
  .friends-main { padding: var(--space-6); }
  .friend-row { gap: var(--space-5); }
}

/* Home: the profile beside a conversation */
.dm-profile {
  width: 280px;
  flex: none;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-left: 1px solid var(--border);
  background: var(--surface-panel);
}
.dm-profile-banner { height: 96px; flex: none; display: flex; justify-content: flex-end; align-items: flex-start; padding: var(--space-4); }
.dm-profile-close { display: none; background: var(--surface-overlay); }
.dm-profile-body {
  --presence-ring: var(--surface-panel);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: 0 var(--space-8) var(--space-8);
}
.dm-profile-body > .avatar {
  width: 80px;
  height: 80px;
  margin-top: -40px;
  font-size: 32px;
  box-shadow: 0 0 0 6px var(--surface-panel);
}
.dm-profile-body > .avatar .presence { width: 16px; height: 16px; border-width: 3px; right: 2px; bottom: 2px; }
.dm-profile-names { display: flex; flex-direction: column; gap: var(--space-1); }
.dm-profile-name { margin: 0; font-size: var(--text-title); color: var(--text-strong); overflow-wrap: anywhere; }
.dm-profile-handle { margin: 0; color: var(--text-secondary); overflow-wrap: anywhere; }
.dm-profile-status { margin: 0; overflow-wrap: anywhere; }
.dm-profile-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--surface-sidebar);
}
.dm-profile-card h3 {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.dm-profile-bio { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.dm-profile-call, .dm-profile-servers button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.dm-profile-call { color: var(--success); }
.dm-profile-call:hover span, .dm-profile-servers button:hover { text-decoration: underline; }
.dm-profile-servers { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-4); }
.dm-profile-none { color: var(--text-muted); }
@media (max-width: 768px) {
  .dm-profile {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 50;
    width: min(300px, 85vw);
    border-left: none;
    box-shadow: var(--shadow-dialog);
  }
  .dm-profile-close { display: inline-flex; width: 44px; height: 44px; }
  /* Phones reach the profile from the header avatar instead. */
  .profile-toggle { display: none; }
}
.request-banner {
  margin: 0 var(--space-8) var(--space-4);
  padding: var(--space-6) var(--space-8);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-6);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}
.request-banner p { flex: 1 1 240px; margin: 0; }
.request-actions { display: flex; flex-wrap: wrap; gap: var(--space-4); }

.profile-card {
  position: fixed;
  z-index: 60;
  width: 300px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-pop);
  outline: none;
}
.profile-card-banner { height: 56px; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
.profile-card-body {
  --presence-ring: var(--surface-app);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: 0 var(--space-8) var(--space-8);
}
.profile-card-body > .avatar {
  margin-top: -36px;
  box-shadow: 0 0 0 4px var(--surface-app);
}
.profile-card-name {
  margin: 0;
  font-size: var(--text-title);
  color: var(--text-strong);
  overflow-wrap: anywhere;
}
.profile-card-username {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-md);
}
.profile-card-handle { min-width: 0; overflow-wrap: anywhere; }
.profile-card-copy {
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-control);
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
}
.profile-card-copy:hover { color: var(--text); }
.profile-card-badge {
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}
.profile-card-status {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  overflow-wrap: anywhere;
}
.profile-card-section { display: flex; flex-direction: column; gap: var(--space-2); }
.profile-card-section h3 {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.profile-card-section p { margin: 0; font-size: var(--text-md); }
.profile-card-bio { white-space: pre-wrap; overflow-wrap: anywhere; }
.profile-card .btn-primary, .profile-card .btn-secondary { height: var(--control-md); }

.profile-picture-row { display: flex; align-items: center; gap: var(--space-6); flex-wrap: wrap; }
.profile-picture-row .btn-secondary { height: var(--control-md); }

/* Threads */
.msg-deleted { margin: 0; font-style: italic; color: var(--text-muted); }
.thread-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.thread-chip:hover { border-color: var(--border-strong); color: var(--text); }
.thread-chip-count { font-weight: var(--weight-semibold); color: var(--accent); }
.thread-chip-unread {
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: var(--text-on-danger);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}
.thread-chip-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }

.threads-menu { position: relative; }
.threads-menu .icon-btn { position: relative; }
.threads-menu-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: var(--text-on-danger);
  font-size: 10px;
  font-weight: var(--weight-bold);
  line-height: 16px;
}
.threads-menu-pop {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 20;
  width: min(360px, calc(100vw - 2 * var(--space-6)));
  max-height: 60vh;
  overflow-y: auto;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.threads-menu-title { padding: var(--space-3) var(--space-5); font-size: var(--text-caption); font-weight: var(--weight-semibold); color: var(--text-muted); }
.threads-menu-empty { margin: 0; padding: var(--space-4) var(--space-5); font-size: var(--text-sm); color: var(--text-muted); }
.threads-menu-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.threads-menu-item:hover { background: var(--surface-control); }
.threads-menu-root { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads-menu-meta { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-xs); color: var(--text-muted); }

.thread-panel {
  position: relative;
  width: var(--thread-panel-width, 400px);
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-left: 1px solid var(--border);
  background: var(--surface-main);
}
.thread-header {
  height: var(--header-height);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: 0 var(--space-6) 0 var(--space-8);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.thread-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: var(--space-4); }
.thread-title h2 { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text); }
.thread-channel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); }
.thread-follow {
  height: var(--control-md);
  padding: 0 var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.thread-follow:hover { background: var(--surface-control); }
.thread-follow[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.thread-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-6) var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.thread-messages:focus-visible { outline-offset: -2px; }
.thread-divider {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin: var(--space-2) 0;
  color: var(--text-muted);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
}
.thread-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.thread-compose { padding: var(--space-4) var(--space-6) var(--space-8); }
.thread-compose .compose-footer:has(.typing:empty) { display: none; }

@media (max-width: 1100px) {
  .thread-panel { --thread-panel-width: 340px; }
}

@media (max-width: 768px) {
  .thread-panel {
    position: fixed;
    inset: 0;
    z-index: 45;
    width: auto;
    border-left: none;
  }
  .thread-header .icon-btn { width: 44px; height: 44px; }
  .thread-compose { padding: var(--space-4) var(--space-6) var(--space-10); }
}

/* Member list */
.member-list {
  --presence-ring: var(--surface-sidebar);
  width: 248px;
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-left: 1px solid var(--border);
  background: var(--surface-sidebar);
}
.member-list-header {
  height: var(--header-height);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6) 0 var(--space-8);
  border-bottom: 1px solid var(--border);
}
.member-list-header h2 { margin: 0; font-size: var(--text-md); font-weight: var(--weight-bold); }
.member-list-close, .member-scrim { display: none; }
.member-list-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-6) var(--space-4); }
.member-group + .member-group { margin-top: var(--space-8); }
.member-group-label {
  margin: 0;
  padding: 0 var(--space-4) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}
.member-group ul { margin: 0; padding: 0; list-style: none; }
.member-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.member-row:hover { background: var(--surface-control); }
.member-row.offline .member-name { color: var(--text-muted); font-weight: var(--weight-regular, 400); }
.member-row.offline .avatar { filter: grayscale(1); }
.member-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.member-name, .member-activity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-name { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.member-activity {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.member-activity > span:not(.live-badge) { overflow: hidden; text-overflow: ellipsis; }
.member-activity .live-badge { margin-left: var(--space-2); flex: none; }

.presence-picker { display: flex; flex-direction: column; gap: var(--space-1); }
.presence-option {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-md);
  text-align: left;
  cursor: pointer;
}
.presence-option:hover { background: var(--surface-control); }
.presence-option[aria-checked="true"] { background: var(--surface-selected); }
.presence-option-text { display: flex; flex-direction: column; }
.presence-option-hint { font-size: var(--text-xs); color: var(--text-muted); }
.presence-option-hint:empty { display: none; }
.presence-swatch { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--success); }
.presence-swatch.idle { background: var(--warning); }
.presence-swatch.dnd { background: var(--danger); }
.presence-swatch.invisible { background: transparent; box-shadow: inset 0 0 0 2px var(--text-muted); }

@media (max-width: 768px) {
  .member-list {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 50;
    width: min(300px, 85vw);
    border-left: none;
    box-shadow: var(--shadow-dialog);
  }
  .member-list-close { display: inline-flex; width: 44px; height: 44px; }
  .member-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    border: none;
    background: var(--surface-scrim);
  }
  .member-row { min-height: 44px; }
}

/* Roles */
.role-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; }
.role-chip {
  margin-left: var(--space-3);
  padding: 0 var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border-radius: var(--radius-badge);
  background: var(--surface-control);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.check-row { display: flex; align-items: center; gap: var(--space-4); cursor: pointer; }
/* Settings behind the gear: the list on the left, the open page beside it. */
.settings-window {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  background: var(--surface-main);
}
.settings-nav {
  flex: 1 0 220px;
  display: flex;
  justify-content: flex-end;
  padding: calc(var(--space-10) * 2) var(--space-5) var(--space-6);
  background: var(--surface-sidebar);
  overflow-y: auto;
}
.settings-nav-list { width: 200px; display: flex; flex-direction: column; gap: var(--space-1); }
.settings-nav-group {
  margin: var(--space-5) 0 var(--space-2);
  padding: 0 var(--space-5);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.settings-nav-item {
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.settings-nav-item:hover { background: var(--surface-control); color: var(--text); }
.settings-nav-item.active { background: var(--surface-selected); color: var(--text-strong); font-weight: var(--weight-semibold); }
.settings-nav-item.danger { color: var(--danger-text); }
.settings-nav-divider { width: 100%; height: 1px; margin: var(--space-3) 0; border: none; background: var(--border); }
.settings-page { flex: 2 1 0; min-width: 0; overflow-y: auto; }
.settings-page-inner { max-width: 760px; padding: calc(var(--space-10) * 2) var(--space-10) calc(var(--space-10) * 2); display: flex; flex-direction: column; gap: var(--space-8); }
.settings-page-header { display: flex; align-items: center; justify-content: space-between; }
.settings-page-header h1 { margin: 0; font-size: var(--text-title); }
.settings-fieldset { display: flex; flex-direction: column; gap: var(--space-4); margin: 0; padding: 0; border: none; }
.settings-fieldset legend { margin-bottom: var(--space-4); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-secondary); }
@media (max-width: 768px) {
  .settings-window { flex-direction: column; }
  .settings-nav { flex: none; justify-content: stretch; padding: var(--space-6) var(--space-5); }
  .settings-nav-list { width: auto; }
  .settings-page-inner { padding: var(--space-8) var(--space-6); }
}
.check-row input { flex: none; margin: 0; accent-color: var(--accent); }
.check-row input:disabled + * { opacity: 0.6; }
.role-picker {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}
.role-picker legend { padding: 0 var(--space-2); font-weight: var(--weight-semibold); }
.member-roles { position: relative; }
.member-roles-pop {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 10;
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--space-2);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.role-row .role-dot { width: 14px; height: 14px; }
.role-editor {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  border-radius: var(--radius-md);
  background: var(--surface-panel);
}
.role-color-row { display: flex; align-items: center; gap: var(--space-5); }
.role-color-row label { display: flex; align-items: center; gap: var(--space-4); }
.role-color-row input[type="color"] {
  width: var(--control-md);
  height: var(--control-sm);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: none;
}
.role-editor-actions { display: flex; justify-content: flex-end; gap: var(--space-4); }

/* Two-factor sign-in */
.two-factor-form { display: flex; flex-direction: column; gap: var(--space-6); }
.two-factor-scan { display: flex; align-items: center; gap: var(--space-8); flex-wrap: wrap; }
.qr-code { flex: none; border-radius: var(--radius-md); }
.two-factor-key { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.two-factor-key code { font-family: var(--font-mono); font-size: var(--text-md); overflow-wrap: anywhere; user-select: all; }
.recovery-codes {
  margin: 0;
  padding: var(--space-6) var(--space-8);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-8);
  list-style: none;
  border-radius: var(--radius-lg);
  background: var(--surface-panel);
  font-family: var(--font-mono);
  font-size: var(--text-md);
}

/* Connection details dialog */
.conn-stats { gap: var(--space-8); }
.conn-stats-summary {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-8);
  font-size: var(--text-md);
}
.conn-stats-summary dt { color: var(--text-secondary); }
.conn-stats-summary dd { margin: 0; color: var(--text-strong); }
.conn-stats-section h3 { margin: 0 0 var(--space-3); font-size: var(--text-base); }
.conn-stats-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-4); }
.conn-stats-list li { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-md); }
.conn-stats-name { color: var(--text-strong); font-weight: var(--weight-semibold); }
.conn-stats-values { color: var(--text-secondary); overflow-wrap: anywhere; }
