:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --hover: #f5f5f5;
  --line: #e6e6e6;
  --line-strong: #cfcfcf;
  --text: #1a1a1a;
  --text-2: #5c5c5c;
  --text-3: #9a9a9a;
  --accent: #2f6fde;
  /* Inline tokens: dim hues so they read as structure, not as links shouting for attention. */
  --c-user: #5f6c9a;      /* @user  - muted indigo */
  --c-channel: #4d8577;   /* #channel - muted teal */
  --c-tag: #9a7b45;       /* $tag - muted ochre */
  --c-self: #2457e6;      /* @you - bright */
  --c-self-bg: rgb(36 87 230 / 0.08);
  --c-group: #876b91;     /* @group - muted plum */
  --c-group-self: #8e2bbf; /* @group you're in - bright */
  --c-group-self-bg: rgb(142 43 191 / 0.08);
  --danger: #c4372f;
  --online: #2e9e5b;
  --hair: 1px;
  --radius: 4px;
  --font: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --bg-soft: #181818;
    --hover: #1e1e1e;
    --line: #2a2a2a;
    --line-strong: #3a3a3a;
    --text: #ececec;
    --text-2: #a8a8a8;
    --text-3: #6b6b6b;
    --accent: #6b9cff;
    --c-user: #8d97bb;
    --c-channel: #7fa99d;
    --c-tag: #b9a07a;
    --c-self: #9dbaff;
    --c-self-bg: rgb(157 186 255 / 0.12);
    --c-group: #a993b2;
    --c-group-self: #d49cff;
    --c-group-self-bg: rgb(212 156 255 / 0.12);
    --danger: #ff7b72;
    --online: #4cc47e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- Controls ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-2); }
.input {
  height: 36px;
  padding: 0 10px;
  background: transparent;
  border: var(--hair) solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.12s;
}
.input:hover { border-color: var(--text-3); }
.input:focus { border-color: var(--text); }
.btn {
  height: 36px;
  padding: 0 14px;
  background: transparent;
  border: var(--hair) solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { background: var(--hover); border-color: var(--text-3); }
.btn:focus-visible, .icon-btn:focus-visible { outline: var(--hair) solid var(--text); outline-offset: 2px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: 0.88; }
.btn[aria-busy="true"] { opacity: 0.6; pointer-events: none; }
.icon-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--radius);
  color: var(--text-3); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--hover); }
.error-text { color: var(--danger); font-size: 13px; min-height: 20px; margin: 0; }

/* ---- Login ---- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; }
.brand-mark {
  width: 24px; height: 24px;
  border: var(--hair) solid var(--text);
  border-radius: 50%;
  display: grid; place-items: center;
}
.brand-mark::after { content: ""; width: 8px; height: 8px; border: var(--hair) solid var(--text); border-radius: 50%; }
.login h1 { font-size: 20px; font-weight: 500; margin: 18px 0 0; letter-spacing: -0.01em; }
.login .sub { margin: -10px 0 0; color: var(--text-2); }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login form .btn { width: 100%; margin-top: 4px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: var(--hair) solid var(--line); }
.login-foot { border-top: var(--hair) solid var(--line); padding-top: 14px; font-size: 12px; color: var(--text-3); }

/* ---- App shell ---- */
.app { height: 100%; display: grid; grid-template-columns: 248px minmax(0, 1fr) 220px; }
.sidebar {
  border-right: var(--hair) solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.sidebar-head { height: 52px; padding: 0 12px 0 16px; display: flex; align-items: center; gap: 10px; border-bottom: var(--hair) solid var(--line); }
.sidebar-head .brand { flex: 1; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 0 16px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 4px 16px;
  font-size: 11px; color: var(--text-3); letter-spacing: 0.04em;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 4px 16px;
  background: none; border: 0; border-left: var(--hair) solid transparent;
  text-align: left; color: var(--text-2); cursor: pointer;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { color: var(--text); border-left-color: var(--text); }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.unread .label { color: var(--text); font-weight: 500; }
.nav-item .hash { color: var(--text-3); width: 10px; }
.count { font-size: 11px; color: var(--accent); font-variant-numeric: tabular-nums; }
.topic-item { padding-left: 34px; font-size: 13px; }
.presence-dot { width: 7px; height: 7px; border-radius: 50%; border: var(--hair) solid var(--text-3); flex: none; }
.presence-dot.on { background: var(--online); border-color: var(--online); }
.me {
  border-top: var(--hair) solid var(--line);
  padding: 10px 12px 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.me .who { flex: 1; min-width: 0; line-height: 1.3; }
.me .who .handle { font-size: 12px; color: var(--text-3); }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  border: var(--hair) solid var(--line-strong);
  display: grid; place-items: center;
  font-size: 11px; color: var(--text-2); flex: none;
  text-transform: uppercase;
}

/* ---- Main pane ---- */
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.main-head {
  height: 52px; flex: none;
  padding: 0 16px 0 24px;
  border-bottom: var(--hair) solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.crumbs button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--text-3); }
.crumbs button:hover { color: var(--text); }
.crumbs .sep { color: var(--text-3); }
.crumbs .current { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .desc { color: var(--text-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 8px; padding-left: 12px; border-left: var(--hair) solid var(--line); }

.messages { flex: 1; overflow-y: auto; padding: 8px 0 16px; }
.load-more { display: block; margin: 8px auto; height: 28px; font-size: 12px; color: var(--text-2); }
.day { display: flex; align-items: center; gap: 12px; padding: 14px 24px 6px; font-size: 11px; color: var(--text-3); }
.day::before, .day::after { content: ""; flex: 1; border-top: var(--hair) solid var(--line); }
.topic-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 24px 4px;
  padding-bottom: 4px;
  border-bottom: var(--hair) solid var(--line);
  font-size: 12px; color: var(--text-2);
}
.topic-bar button { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; font-weight: 500; }
.topic-bar button:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.msg { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 12px; padding: 6px 24px; }
.msg:hover { background: var(--bg-soft); }
.msg.cont { padding-top: 1px; padding-bottom: 1px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-head .name { font-weight: 500; }
.msg-head time, .msg .side-time { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.msg-body { color: var(--text); overflow-wrap: anywhere; }
.msg-body p { margin: 0; white-space: pre-wrap; }
.msg-body p + p { margin-top: 6px; }
.msg-body code { font: 12.5px var(--mono); border: var(--hair) solid var(--line); border-radius: 3px; padding: 0 4px; }
.msg-body pre {
  font: 12.5px/1.5 var(--mono);
  border: var(--hair) solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; margin: 4px 0; overflow-x: auto; white-space: pre;
}
.msg-body blockquote { margin: 4px 0; padding-left: 10px; border-left: var(--hair) solid var(--line-strong); color: var(--text-2); }
.msg.pending { opacity: 0.5; }
.empty { padding: 64px 24px; text-align: center; color: var(--text-3); }
.empty strong { display: block; color: var(--text); font-weight: 500; margin-bottom: 4px; }

/* ---- Mentions ---- */
.mention { color: var(--c-user); white-space: nowrap; }
.mention.self { color: var(--c-self); background: var(--c-self-bg); border-radius: 3px; padding: 0 3px; font-weight: 500; }
.channel-link { color: var(--c-channel); white-space: nowrap; }
.channel-link:hover { color: var(--c-channel); text-decoration: underline; text-underline-offset: 3px; }
.channel-link .sep { opacity: 0.6; }
.tag {
  display: inline-block;
  padding: 0 5px;
  border: var(--hair) solid color-mix(in srgb, var(--c-tag) 45%, transparent);
  border-radius: 3px;
  font-size: 0.92em;
  line-height: 1.45;
  color: var(--c-tag);
  white-space: nowrap;
}
.tag-sigil { opacity: 0.6; margin-right: 1px; }
.msg.mentioned { border-left: var(--hair) solid var(--c-self); padding-left: 23px; }
.mention.group { color: var(--c-group); }
.mention.group.self { color: var(--c-group-self); background: var(--c-group-self-bg); }
.msg.mentioned.via-group { border-left-color: var(--c-group-self); }
.avatar.group-icon { border-color: var(--c-group); color: var(--c-group); }
.avatar.group-icon .icon { width: 12px; height: 12px; }

/* ---- Composer ---- */
.composer { flex: none; padding: 0 24px 18px; position: relative; }
.suggest {
  position: absolute; left: 24px; bottom: calc(100% - 4px);
  width: min(360px, calc(100% - 48px));
  background: var(--bg);
  border: var(--hair) solid var(--line-strong);
  border-radius: var(--radius);
  padding: 4px 0;
  z-index: 10;
}
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 5px 12px; cursor: pointer; border-left: var(--hair) solid transparent; }
.suggest-item.active { background: var(--hover); border-left-color: var(--text); }
.suggest-label { white-space: nowrap; }
.suggest-detail { color: var(--text-3); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-hint { border-top: var(--hair) solid var(--line); margin-top: 4px; padding: 6px 12px 2px; font-size: 11px; color: var(--text-3); }
.avatar.small { width: 20px; height: 20px; font-size: 9px; }
.composer-box { border: var(--hair) solid var(--line-strong); border-radius: var(--radius); transition: border-color 0.12s; }
.composer-box:focus-within { border-color: var(--text); }
.composer-topic {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-bottom: var(--hair) solid var(--line);
  font-size: 12px; color: var(--text-3);
}
.composer-topic input { flex: 1; border: 0; outline: none; background: transparent; font-size: 13px; color: var(--text); padding: 0; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; padding: 6px 6px 6px 10px; }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  max-height: 240px; padding: 4px 0; line-height: 1.5;
}
.composer-hint { font-size: 11px; color: var(--text-3); padding: 6px 2px 0; display: flex; justify-content: space-between; }
.composer .error-text { min-height: 0; font-size: 12px; }

/* ---- Dialog ---- */
dialog {
  border: var(--hair) solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg); color: var(--text);
  padding: 20px; width: min(380px, calc(100% - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.25); }
dialog h2 { font-size: 15px; font-weight: 500; margin: 0 0 16px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.conn-status {
  font-size: 11px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.conn-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--online); }
.conn-status.off::before { background: var(--danger); }

/* ---- People (right column) ---- */
.people {
  border-left: var(--hair) solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.people-head {
  justify-content: space-between;
  height: 52px; flex: none;
  padding: 0 16px;
  display: flex; align-items: center; gap: 6px;
  border-bottom: var(--hair) solid var(--line);
  font-size: 12px; color: var(--text-2);
}
.people .nav-item { cursor: pointer; }
.crumbs .avatar.tiny { margin-right: -2px; }
.people .nav-item.offline .label { color: var(--text-3); }
@media (max-width: 1000px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .people { display: none; }
  .narrow-only:not(.hidden) { display: inline-flex; }
}
.no-topic { color: var(--text-3); font-style: italic; }
.nav-item.unread .label.no-topic { color: var(--text-2); }

/* ---- Avatars and badges ---- */
.avatar { position: relative; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.tiny { width: 22px; height: 22px; font-size: 9px; }
.avatar.large { width: 64px; height: 64px; font-size: 18px; }
.avatar .presence-dot { position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border: 1.5px solid var(--bg); background: var(--bg); }
.avatar .presence-dot:not(.on) { box-shadow: inset 0 0 0 1px var(--text-3); }
.avatar .presence-dot.on { background: var(--online); }
.nav-item.person { gap: 10px; padding-top: 5px; padding-bottom: 5px; }
.badge {
  font-size: 10px; line-height: 1; padding: 2px 4px;
  border: var(--hair) solid var(--line-strong); border-radius: 3px;
  color: var(--text-3); letter-spacing: 0.03em;
}
.narrow-only { display: none; }

/* ---- Message actions and inline editing ---- */
.msg { position: relative; }
.msg-actions {
  position: absolute; top: 2px; right: 16px;
  display: none;
  background: var(--bg); border: var(--hair) solid var(--line); border-radius: var(--radius);
}
.msg:hover .msg-actions, .msg-actions:focus-within { display: flex; }
.edited { font-size: 11px; color: var(--text-3); }
.editor { margin-top: 4px; }
.edit-area {
  width: 100%; resize: none; padding: 6px 8px; line-height: 1.5;
  background: transparent; border: var(--hair) solid var(--text); border-radius: var(--radius); outline: none;
}
.editor-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11px; }
.editor-bar .error-text { flex: 1; min-height: 0; font-size: 12px; }
.editor-bar .muted { margin-left: auto; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

/* ---- Admin menu ---- */
.menu-pop {
  position: fixed; z-index: 50; min-width: 200px;
  background: var(--bg); border: var(--hair) solid var(--line-strong); border-radius: var(--radius);
  padding: 4px 0;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 14px; background: none; border: 0; border-left: var(--hair) solid transparent;
  text-align: left; cursor: pointer; color: var(--text);
}
.menu-item .icon { color: var(--text-3); }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); border-left-color: var(--text); outline: none; }

/* ---- Modals ---- */
dialog.modal { padding: 0; width: min(980px, calc(100% - 32px)); height: min(680px, calc(100% - 48px)); flex-direction: column; }
dialog.modal[open] { display: flex; }
.modal-head { height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 20px; border-bottom: var(--hair) solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { flex: 1; min-height: 0; display: flex; }
.split { flex: 1; min-height: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.tabs { border-right: var(--hair) solid var(--line); padding: 10px 0; display: flex; flex-direction: column; }
.tab {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: none; border: 0; border-left: var(--hair) solid transparent;
  text-align: left; color: var(--text-2); cursor: pointer;
}
.tab .icon { color: var(--text-3); }
.tab:hover { background: var(--hover); color: var(--text); }
.tab.active { color: var(--text); border-left-color: var(--text); }
.tab-panel, .md-detail { overflow-y: auto; padding: 20px 24px 24px; }
.tab-panel h3, .md-detail h3 { font-size: 15px; font-weight: 500; margin: 0 0 4px; }
.lead { color: var(--text-2); margin: 0 0 16px; }
.subsection { border-top: var(--hair) solid var(--line); margin-top: 20px; padding-top: 16px; }
.subsection h4 { font-size: 12px; font-weight: 500; color: var(--text-2); margin: 0 0 12px; letter-spacing: 0.02em; }
.small { font-size: 12px; }
.hint { font-size: 11px; color: var(--text-3); }
.empty-line { color: var(--text-3); margin: 8px 0; }
.dim { opacity: 0.55; }

/* Forms */
.field > span:first-child { font-size: 12px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; margin-top: 14px; }
.form-grid.narrow { grid-template-columns: repeat(auto-fill, minmax(280px, 340px)); }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
select.input { padding-right: 6px; background: var(--bg); }
.input:disabled { color: var(--text-3); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-status { font-size: 12px; color: var(--text-3); margin-right: auto; }
.form-status.ok { color: var(--online); }
.form-status.err { color: var(--danger); }
.form-actions .push-left { margin-right: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.field-check { align-self: end; height: 36px; }
.inline-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-form { display: flex; align-items: flex-end; gap: 8px; margin-top: 14px; }
.inline-form .field { flex: 1; max-width: 360px; }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit .input { width: 110px; }
.with-unit span { color: var(--text-3); font-size: 12px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 20px 0 0; padding-top: 14px; border-top: var(--hair) solid var(--line); font-size: 13px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; color: var(--text-3); }

/* Rows (lists of fields and keys) */
.rows { border-top: var(--hair) solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: var(--hair) solid var(--line); }
.row.editing { display: block; padding: 4px 0 14px; }
.row-main { flex: 1; min-width: 0; }
.row-actions { display: flex; gap: 2px; }

/* Shown-once secrets */
.secret { border: var(--hair) solid var(--c-tag); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
.secret p { margin: 0 0 8px; font-size: 12px; color: var(--text-2); }
.secret-row { display: flex; gap: 8px; align-items: center; }
.secret code { flex: 1; font: 12.5px var(--mono); padding: 6px 8px; border: var(--hair) solid var(--line); border-radius: 3px; overflow-x: auto; white-space: nowrap; user-select: all; }

/* Master-detail (groups, users, bots) */
.md-side { border-right: var(--hair) solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.md-tools { display: flex; gap: 8px; padding: 12px; border-bottom: var(--hair) solid var(--line); }
.md-tools .input { flex: 1; min-width: 0; height: 28px; font-size: 12px; }
.md-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.md-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 14px; background: none; border: 0; border-left: var(--hair) solid transparent;
  text-align: left; cursor: pointer; color: var(--text-2);
}
.md-item:hover { background: var(--hover); color: var(--text); }
.md-item.active { color: var(--text); border-left-color: var(--text); }
.md-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.md-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-editor { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.avatar-actions { display: flex; flex-direction: column; gap: 6px; }
.subsection > .input[type="search"] { width: 100%; max-width: 360px; height: 30px; }

/* Profile field groups (server settings) */
.field-group { margin-bottom: 18px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; }
.group-head.editing .input { max-width: 320px; height: 30px; }
.group-head.editing .form-status { margin-right: 0; flex: 1; }
.group-name { flex: 1; font-size: 12px; font-weight: 500; color: var(--text-2); letter-spacing: 0.02em; }
.field-group .rows .row { padding-left: 12px; }
.field-group .rows .row.editing { padding-left: 12px; }
.field-group .empty-line { padding-left: 12px; }

/* People picker and member list (groups) */
.picker { position: relative; max-width: 420px; }
.picker .input { width: 100%; }
.picker-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  background: var(--bg); border: var(--hair) solid var(--line-strong); border-radius: var(--radius); padding: 4px 0;
}
.picker-item { display: flex; align-items: center; gap: 10px; padding: 6px 12px; cursor: pointer; border-left: var(--hair) solid transparent; }
.picker-item.active { background: var(--hover); border-left-color: var(--text); }
.picker-empty { padding: 6px 12px; font-size: 12px; color: var(--text-3); }
.member-list { margin-top: 10px; border-top: var(--hair) solid var(--line); }
.member-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 0; border-bottom: var(--hair) solid var(--line); }
.member-row .muted { flex: 1; }
.member-row .icon-btn { opacity: 0; }
.member-row:hover .icon-btn, .member-row .icon-btn:focus-visible { opacity: 1; }
.subsection > .input[type="search"]:not(.hidden) { margin-top: 10px; }

/* ---- Channels: sidebar, header, dialogs ---- */
.section-actions { display: inline-flex; gap: 2px; }
.nav-item .hash .icon { width: 11px; height: 11px; vertical-align: -1px; }
.crumbs .lock { color: var(--text-3); display: inline-flex; }
.crumbs .lock .icon { width: 13px; height: 13px; }
.member-count { white-space: nowrap; }
.read-only-note {
  flex: none; margin: 0 24px 18px; padding: 10px 12px;
  border: var(--hair) dashed var(--line-strong); border-radius: var(--radius);
  color: var(--text-3); font-size: 13px; text-align: center;
}

dialog.modal.medium { width: min(560px, calc(100% - 32px)); height: fit-content; max-height: calc(100% - 48px); }
.modal.medium .modal-body { display: block; flex: 0 1 auto; overflow-y: auto; padding: 18px 24px 22px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack textarea.input { resize: vertical; }
.checks { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.person-picker { display: flex; flex-direction: column; gap: 8px; }
.chosen-person { display: flex; align-items: center; gap: 10px; min-height: 24px; }
.facts.plain { border-top: 0; padding-top: 0; margin-top: 0; }
.browse-tools { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.browse-tools .input { flex: 1; }
.folder-add { display: flex; align-items: center; gap: 10px; margin: 2px 0 8px 12px; }
.folder-add .picker { flex: 1; }
.folder-add .input { height: 30px; font-size: 12px; }
.picker-item .hash { color: var(--text-3); width: 10px; }
.more-item { color: var(--text-3); font-size: 12px; }
.more-item .icon { width: 12px; height: 12px; margin-left: 4px; }
.more-item .label { color: var(--text-3); }
.more-item:hover .label { color: var(--text); }

/* ---- Attachments ---- */
.main { position: relative; }
.drop-overlay {
  position: absolute; inset: 52px 0 0 0; z-index: 20;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border: var(--hair) dashed var(--text-3);
  pointer-events: none;
}
.drop-overlay span { font-size: 14px; color: var(--text-2); }

.upload-tray {
  display: flex; flex-direction: column;
  border: var(--hair) solid var(--line-strong); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 180px; overflow-y: auto;
}
.upload-tray:not(.hidden) + .composer-box { border-top-left-radius: 0; border-top-right-radius: 0; }
.upload-row {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 10px; font-size: 12px;
  border-bottom: var(--hair) solid var(--line);
}
.upload-row:last-child { border-bottom: 0; }
.upload-icon { color: var(--text-3); display: inline-flex; }
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-status { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.upload-row.failed .upload-status { color: var(--danger); white-space: normal; text-align: right; }
.upload-bar { position: absolute; left: 0; bottom: -1px; height: 1px; width: 0; background: var(--text); transition: width 0.15s; }
.upload-row.done .upload-bar, .upload-row.failed .upload-bar { display: none; }

.att-image { display: block; width: fit-content; max-width: 100%; margin: 6px 0 2px; border: var(--hair) solid var(--line); border-radius: var(--radius); overflow: hidden; line-height: 0; cursor: zoom-in; }
.att-image img { display: block; max-width: 360px; max-height: 280px; width: auto; height: auto; }
.att-media { display: flex; flex-direction: column; gap: 6px; width: min(420px, 100%); margin: 6px 0 2px; padding: 8px 10px; border: var(--hair) solid var(--line); border-radius: var(--radius); }
.att-media.video { width: min(520px, 100%); }
.att-media audio { width: 100%; height: 32px; }
.att-media video { width: 100%; max-height: 360px; border-radius: 3px; background: #000; }
.att-caption { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.att-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.att-size { color: var(--text-3); white-space: nowrap; }
.att-dl { margin-left: auto; color: var(--text-3); display: inline-flex; }
.att-dl:hover { color: var(--text); }
.att-file {
  display: inline-flex; align-items: center; gap: 10px; max-width: min(420px, 100%);
  margin: 4px 0; padding: 7px 10px; border: var(--hair) solid var(--line-strong); border-radius: var(--radius);
  color: var(--text); text-decoration: none; vertical-align: middle;
}
.att-file:hover { border-color: var(--text-3); text-decoration: none; background: var(--hover); }
.att-file .att-icon { color: var(--text-3); display: inline-flex; }
.att-file .att-name { font-size: 13px; }
.att-file .att-size { font-size: 12px; }
.att-file .att-dl { margin-left: 6px; }

dialog.lightbox { padding: 0; border: 0; background: transparent; max-width: 94vw; max-height: 94vh; width: auto; cursor: zoom-out; }
dialog.lightbox::backdrop { background: rgb(0 0 0 / 0.75); }
.lightbox img { display: block; max-width: 94vw; max-height: calc(94vh - 36px); margin: 0 auto; }
.lightbox-bar { display: flex; justify-content: space-between; gap: 16px; padding: 8px 2px 0; color: #ddd; font-size: 12px; }
.lightbox-bar a { color: #fff; }
.files-checks { margin-top: 14px; }

/* ---- Center column tabs: Messages / Files ---- */
.view-tabs { flex: none; display: flex; gap: 18px; padding: 0 24px; border-bottom: var(--hair) solid var(--line); }
.view-tab {
  position: relative; background: none; border: 0; padding: 8px 0 7px;
  font-size: 12px; color: var(--text-3); cursor: pointer;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { color: var(--text); }
.view-tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; border-bottom: var(--hair) solid var(--text); }
.tab-count { font-variant-numeric: tabular-nums; color: var(--text-3); margin-left: 2px; }
.drop-overlay { inset: 86px 0 0 0; }

.files-view { flex: 1; overflow-y: auto; padding: 6px 24px 24px; }
.files-empty { padding: 12px 0; }
.file-list { border-top: 0; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: var(--hair) solid var(--line); }
.file-preview {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: var(--hair) solid var(--line); border-radius: var(--radius); color: var(--text-3); overflow: hidden;
}
.file-preview.image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-name {
  align-self: flex-start; max-width: 100%; background: none; border: 0; padding: 0; text-align: left;
  color: var(--text); font: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.file-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-3); }
.file-owner { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.file-owner .avatar.tiny { width: 16px; height: 16px; font-size: 7px; }
.file-topic { background: none; border: 0; padding: 0; font: inherit; color: var(--text-2); cursor: pointer; }
.file-topic::before { content: "› "; color: var(--text-3); }
.file-topic:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.file-row .row-actions a.icon-btn { text-decoration: none; }
.msg.flash { background: var(--hover); box-shadow: inset 1px 0 0 var(--text); transition: background 0.6s; }

/* ---- Status ---- */
.me .who {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  background: none; border: 0; padding: 2px 4px; margin-left: -4px; border-radius: var(--radius); cursor: pointer;
}
.me .who:hover { background: var(--hover); }
.me .who > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who .handle { display: flex; align-items: center; gap: 5px; }
.me .who .handle > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.set-status { color: var(--text-3); }
.me .who:hover .set-status { color: var(--text-2); }

.status-badge { display: inline-flex; align-items: center; color: var(--text-2); flex: none; }
.status-badge .icon { width: 13px; height: 13px; }
.msg-head .status-badge .icon { width: 12px; height: 12px; }
.crumbs .status-badge .icon { width: 14px; height: 14px; }

dialog.modal.narrow { width: min(440px, calc(100% - 32px)); }
.status-editor {
  display: flex; align-items: center;
  border: var(--hair) solid var(--line-strong); border-radius: var(--radius);
}
.status-editor:focus-within { border-color: var(--text); }
.status-editor .input { border: 0; flex: 1; }
.status-icon-pick {
  width: 36px; height: 34px; flex: none; display: grid; place-items: center;
  background: none; border: 0; border-right: var(--hair) solid var(--line); color: var(--text-2); cursor: pointer;
}
.status-icon-pick:hover { background: var(--hover); color: var(--text); }
.status-icon-empty { width: 14px; height: 14px; border: var(--hair) dashed var(--text-3); border-radius: 50%; }
.status-palette { display: grid; grid-template-columns: repeat(7, 36px); gap: 4px; margin-top: 8px; padding: 6px; border: var(--hair) solid var(--line); border-radius: var(--radius); width: fit-content; }
.status-palette-item { width: 36px; height: 32px; display: grid; place-items: center; background: none; border: var(--hair) solid transparent; border-radius: var(--radius); color: var(--text-2); cursor: pointer; }
.status-palette-item:hover { background: var(--hover); color: var(--text); }
.status-palette-item.active { border-color: var(--text); color: var(--text); }
.status-clear { display: flex; align-items: flex-end; gap: 10px; margin-top: 14px; }
.status-clear .field { flex: 1; }
.status-clear input[type="datetime-local"] { flex: 1; }
.status-heading { font-size: 12px; font-weight: 500; color: var(--text-2); margin: 18px 0 6px; }
.status-presets { display: flex; flex-direction: column; border-top: var(--hair) solid var(--line); }
.status-preset {
  display: flex; align-items: center; gap: 12px; padding: 8px 6px;
  background: none; border: 0; border-bottom: var(--hair) solid var(--line); border-left: var(--hair) solid transparent;
  text-align: left; color: var(--text); cursor: pointer;
}
.status-preset .icon { color: var(--text-2); }
.status-preset:hover { background: var(--hover); border-left-color: var(--text); }

/* Notifications tab */
.notify-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: var(--hair) solid var(--line); }
.notify-toggle { align-items: flex-start; color: var(--text); }
.notify-toggle input { margin-top: 3px; }
.notify-toggle strong { font-weight: 500; }
.hint.block { display: block; margin-top: 2px; }
.notify-sound { display: flex; align-items: center; gap: 8px; flex: none; }
.notify-sound select { width: 160px; }
.notify-volume { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 13px; color: var(--text-2); }
.notify-volume input[type="range"] { width: 220px; accent-color: var(--text); }
.volume-out { font-variant-numeric: tabular-nums; color: var(--text-3); min-width: 36px; }

/* ---- Message action menu ---- */
.msg-menu { min-width: 250px; }
.menu-sep { border-top: var(--hair) solid var(--line); margin: 4px 0; }
.menu-item .menu-hint { margin-left: auto; padding-left: 12px; font-size: 11px; color: var(--text-3); }
.status-preset .menu-hint { margin-left: auto; font-size: 11px; color: var(--text-3); }
.msg-link { color: var(--c-channel); }
.msg-link::before { content: "↪ "; opacity: 0.7; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 60;
  padding: 8px 14px; font-size: 13px;
  background: var(--text); color: var(--bg); border-radius: var(--radius);
  transition: opacity 0.3s;
}
.toast.out { opacity: 0; }
.forward-preview { margin: 0 0 14px; padding: 6px 10px; border-left: var(--hair) solid var(--line-strong); color: var(--text-2); white-space: pre-wrap; max-height: 120px; overflow: hidden; }
.forward-pickers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 14px; }
.forward-pickers .picker { max-width: none; }
.modal.narrow .modal-body .field + .field { margin-top: 12px; }

/* Reminders in the sidebar */
.reminder-item { gap: 8px; cursor: pointer; }
.reminder-item .reminder-when { flex: none; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 52px; }
.reminder-item .label { font-size: 13px; }
.reminder-item .reminder-cancel { width: 22px; height: 22px; opacity: 0; }
.reminder-item:hover .reminder-cancel, .reminder-item .reminder-cancel:focus-visible { opacity: 1; }
.nav-item .hash .icon { width: 12px; height: 12px; }

/* ---- Mentions view ---- */
.mentions-view { flex: 1; overflow-y: auto; padding: 8px 0 24px; }
.mention-item { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 12px; padding: 10px 24px; border-bottom: var(--hair) solid var(--line); border-left: var(--hair) solid transparent; cursor: pointer; }
.mention-item:hover, .mention-item:focus-visible { background: var(--bg-soft); outline: none; }
.mention-item.unread { border-left-color: var(--c-self); }
.mention-item.unread .name { color: var(--text); }
.mention-where { font-size: 12px; color: var(--c-channel); }
.mention-count { color: var(--c-self); }
.mentions-view .load-more { margin: 14px auto; }

/* ---- Stars ---- */
.star-btn.on { color: var(--c-tag); }
.star-btn.on .icon { fill: color-mix(in srgb, var(--c-tag) 35%, transparent); }
.star-mark { position: absolute; top: 8px; right: 20px; color: var(--c-tag); display: inline-flex; pointer-events: none; }
.star-mark .icon { width: 13px; height: 13px; fill: color-mix(in srgb, var(--c-tag) 35%, transparent); }
.msg:hover .star-mark { visibility: hidden; }
.star-count { color: var(--text-3); }
.mention-item .msg-head .star-btn { margin-left: auto; width: 24px; height: 24px; }

/* Preferences */
.zone-picker { display: flex; flex-direction: column; gap: 6px; }
.zone-select { height: auto; padding: 4px; font-size: 13px; }
.zone-select option { padding: 3px 6px; }

/* Date/time in messages (shown in each reader's zone) */
.time-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; white-space: nowrap;
  border: var(--hair) solid var(--line-strong); border-radius: 3px; font-size: 0.92em; line-height: 1.45;
  color: var(--text); font-variant-numeric: tabular-nums; cursor: help;
}
.time-chip .icon { width: 12px; height: 12px; color: var(--text-3); }
.time-preview { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; padding: 10px 12px; border: var(--hair) solid var(--line); border-radius: var(--radius); font-size: 13px; }
.time-row { display: flex; justify-content: space-between; gap: 16px; }

/* ---- Reactions ---- */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 7px;
  background: none; border: var(--hair) solid var(--line-strong); border-radius: 12px;
  font-size: 12px; color: var(--text-2); cursor: pointer;
}
.reaction:hover { border-color: var(--text-3); background: var(--hover); }
.reaction.mine { border-color: var(--c-self); color: var(--c-self); background: var(--c-self-bg); }
.reaction-count { font-variant-numeric: tabular-nums; }
.reaction .emo { width: 16px; height: 16px; object-fit: contain; }
.reaction .emo-std { width: auto; height: auto; font-size: 14px; line-height: 1; }
.add-reaction { color: var(--text-3); padding: 0 6px; opacity: 0; }
.msg:hover .add-reaction, .add-reaction:focus-visible { opacity: 1; }
.add-reaction .icon { width: 14px; height: 14px; }

/* Pickers (emoticons, GIFs) */
.picker-pop { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.picker-pop .picker-search { height: 30px; font-size: 13px; }
.emoji-pop { width: 300px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 240px; overflow-y: auto; }
.emoji-section { grid-column: 1 / -1; font-size: 11px; color: var(--text-3); padding: 4px 2px 2px; }
.emoji-btn { height: 32px; display: grid; place-items: center; background: none; border: 0; border-radius: var(--radius); cursor: pointer; }
.emoji-btn:hover, .emoji-btn:focus-visible { background: var(--hover); outline: none; }
.emoji-btn .emo { width: 22px; height: 22px; object-fit: contain; }
.emoji-btn .emo-std { width: auto; height: auto; font-size: 20px; line-height: 1; }
.emoji-grid .empty-line { grid-column: 1 / -1; }
.gif-pop { width: 360px; }
.gif-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 300px; overflow-y: auto; }
.gif-btn { display: flex; flex-direction: column; gap: 2px; padding: 0; background: none; border: var(--hair) solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.gif-btn:hover, .gif-btn:focus-visible { border-color: var(--text); outline: none; }
.gif-btn img { width: 100%; height: 80px; object-fit: cover; display: block; }
.gif-btn span { font-size: 11px; color: var(--text-2); padding: 0 4px 3px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gif-grid .empty-line { grid-column: 1 / -1; }
.gif-toggle { width: auto; padding: 0 5px; font-size: 10px; font-weight: 500; letter-spacing: 0.04em; border: var(--hair) solid currentColor; height: 18px; margin: 5px 2px; }

/* GIFs in messages */
.msg-gif { display: block; width: fit-content; max-width: 100%; margin: 6px 0 2px; border: var(--hair) solid var(--line); border-radius: var(--radius); overflow: hidden; line-height: 0; }
.msg-gif img { display: block; max-width: 300px; max-height: 240px; width: auto; height: auto; }

/* Reactions manager */
.asset-add { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 8px; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
.asset-card { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: var(--hair) solid var(--line); border-radius: var(--radius); }
.asset-card .btn { align-self: flex-start; }
.asset-preview { height: 90px; display: grid; place-items: center; background: var(--bg-soft); border-radius: 3px; overflow: hidden; }
.asset-preview.gif img { max-width: 100%; max-height: 90px; }
.asset-preview.emoticon img { width: 40px; height: 40px; object-fit: contain; }
.asset-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
