/* Shared channel and private-message surfaces. Workspace colors come from the active theme. */
[data-screen=chat], [data-screen=dm] {
  --chat-edge: clamp(.8rem, 1.5vw, 1.5rem);
  --chat-rule: color-mix(in srgb, var(--line) 70%, transparent);
  --chat-tint: color-mix(in srgb, var(--selected) 46%, var(--bg));
  min-width: 0;
  container: chat-page / inline-size;
}

.messages-heading, [data-screen=dm] > .heading { margin-bottom: .85rem; }
.messages-heading { grid-template-columns: minmax(0, 1fr); }
.messages-heading h1, #dm-title {
  font-size: clamp(1.65rem, 2.2vw, 2.25rem);
  line-height: 1.12;
  letter-spacing: -.045em;
}
#new-channel { font-weight: 650; }
.new-channel-symbol { display: none; }
#find-channels-mobile .browse-label { display: none; }
#channel-tabs { gap: .3rem; margin-block-start: .4rem; }
#channel-tabs button {
  padding: .55rem .8rem;
  border-radius: .45rem .45rem 0 0;
  font-size: .88rem;
}
#channel-tabs button[aria-selected=true] { color: var(--accent); }

#channel-layout .chat-shell, .dm-conversation {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
}
#channel-layout .chat-shell { container: conversation / inline-size; }
#channel-layout .chat-top, .dm-header {
  padding: .7rem var(--chat-edge);
  background: var(--panel);
  border-bottom: 1px solid var(--chat-rule);
}
#channel-chat .chat-heading {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  letter-spacing: -.025em;
}
.channel-symbol {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.95rem;
  height: 1.95rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--chat-tint);
  color: var(--accent);
  font-size: 1.17rem;
  line-height: 1;
}
#channel-layout .chat-top .row { align-items: center; gap: .3rem; }
#channel-layout .chat-top .btn { min-height: 2rem; }
#channel-layout .channel-action { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
#channel-layout .channel-action svg {
  width: 1rem;
  height: 1rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#channel-layout .chat-top .btn:not([data-new-thread]):not(:hover,:focus-visible) {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}
#channel-layout .chat-top [data-new-thread] {
  color: var(--ink);
  background: var(--bg);
  font-weight: 650;
}

#channel-layout .chat-messages, #dm-log {
  padding: .65rem var(--chat-edge);
  scrollbar-gutter: stable;
}
#channel-layout .message, #dm-log .message {
  margin: 0;
  padding: .55rem .45rem;
  grid-template-columns: 2rem minmax(0, 1fr);
  gap: .7rem;
  border: 0;
  border-radius: .45rem;
}
:is(#channel-layout, #dm-log) .message > .avatar,
:is(#channel-layout, #dm-log) .message > .message-profile-avatar .avatar {
  width: 2rem;
  height: 2rem;
  border-radius: .6rem;
}
#channel-layout .message h3, #dm-log .message h3 {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .12rem .55rem;
  margin-bottom: .12rem;
  font-size: .92rem;
  line-height: 1.3;
  font-weight: 700;
}
#channel-layout .message p, #dm-log .message p {
  max-width: 83ch;
  font-size: .94rem;
  line-height: 1.46;
}
#channel-layout .message time, #dm-log .message time {
  margin: 0;
  font-size: .72rem;
  font-weight: 450;
}
.message-copy { min-width: 0; }
:is(#channel-layout, #dm-log) .message-continuation:not([data-search-hit], [data-unread-hit]) {
  position: relative;
  padding-block: .16rem;
}
:is(#channel-layout, #dm-log) .message-continuation:not([data-search-hit], [data-unread-hit]) > :is(.avatar, .message-profile-avatar),
:is(#channel-layout, #dm-log) .message-continuation:not([data-search-hit], [data-unread-hit]) a.message-author { display: none; }
.message-continuation .message-copy { grid-column: 2; }
:is(#channel-layout, #dm-log) .message-continuation:not([data-search-hit], [data-unread-hit]) h3 {
  position: absolute;
  inset-inline-start: .12rem;
  inset-block-start: .39rem;
  width: 2.5rem;
  justify-content: center;
  margin: 0;
}
.message-continuation:not([data-search-hit], [data-unread-hit]) .message-author {
  position: absolute;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
}
:is(#channel-layout, #dm-log) .message-continuation:not([data-search-hit], [data-unread-hit]) h3 time {
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-align: center;
}
#dm-log .message p { white-space: pre-wrap; }
#channel-layout .message-day, #dm-log .message-day {
  margin: .4rem .4rem .55rem;
  gap: .7rem;
}
#channel-layout .message-day time, #dm-log .message-day time {
  padding: .19rem .55rem;
  border: 1px solid var(--chat-rule);
  border-radius: 2rem;
  background: var(--bg);
  font-size: .72rem;
  letter-spacing: .015em;
}
#channel-layout .message-day::before, #channel-layout .message-day::after,
#dm-log .message-day::before, #dm-log .message-day::after { background: var(--chat-rule); }
#channel-layout .message-tools { gap: .24rem .35rem; }
#channel-layout .message-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: .45rem;
  margin-top: .15rem;
}
#channel-layout .message-footer .message-tools,
#channel-layout .message-footer .message-reactions { margin: 0; align-self: center; }
#channel-layout .message-links { order: -1; }
#channel-layout .message-links:empty, #channel-layout .message-actionbar:empty,
#channel-layout .reaction-chips:empty, #channel-layout .message-reactions > small:empty { display: none; }
#channel-layout .read-receipt { order: 2; }
#channel-layout .message-tools .btn {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  min-height: 1.55rem;
  padding: .12rem .28rem;
}
#channel-layout .message-tools :is([data-thread],[data-ticket]) { color: var(--accent); }
#channel-layout .message-tools :is(.has-thread,[data-ticket]) {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  max-width: 100%;
  padding-inline: .42rem;
  background: var(--chat-tint);
  border: 1px solid var(--chat-rule);
  border-radius: .38rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.reply-avatars { display: inline-flex; align-items: center; padding-inline-start: .14rem; }
.reply-avatars .avatar {
  width: 1.04rem;
  height: 1.04rem;
  margin-inline-start: -.14rem;
  border: 1px solid var(--bg);
  border-radius: .3rem;
  font-size: .62rem;
  line-height: 1;
}
#channel-layout .message-tools .btn:where(:hover,:focus-visible) {
  background: var(--chat-tint);
  border-color: var(--line);
}
#channel-layout .message-reactions { margin: .2rem .15rem .08rem 0; }
#channel-layout .message-reactions summary {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}
#channel-layout .message-reactions summary:is(:hover,:focus-visible) { border-color: var(--line); }
#channel-layout .message-actionbar .btn, #channel-layout .message-actionbar summary {
  flex: none;
  border-radius: .32rem;
  white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  @container conversation (min-width: 35rem) {
    #channel-layout article.message:has(.message-actionbar:not(:empty)) {
      position: relative;
      padding-inline-end: 13.3rem;
    }
    #channel-layout .message-actionbar:not(:empty) {
      position: absolute;
      inset-block-start: .1rem;
      inset-inline-end: .35rem;
      z-index: 2;
      gap: .1rem;
      padding: .12rem .2rem;
      background: var(--bg);
      border: 1px solid var(--line-strong);
      border-radius: .5rem;
      box-shadow: 0 3px 10px var(--shadow);
      opacity: 0;
    }
    #channel-layout .message:is(:hover,:focus-within,:has(.tour-highlight-control),:has(.message-actionbar details[open])) .message-actionbar {
      opacity: 1;
    }
    #channel-layout .message:is(:hover,:focus-within):not(.thread-origin,[data-search-hit],[data-unread-hit]) {
      background: color-mix(in srgb, var(--panel-raised) 55%, transparent);
    }
    #channel-layout .message-actionbar details { position: relative; }
    #channel-layout .message-actionbar details[open] .reaction-options {
      position: absolute;
      z-index: 3;
      inset-inline-end: 0;
      inset-block-start: calc(100% + .25rem);
      display: grid;
      gap: .08rem;
      width: max-content;
      max-width: 14rem;
      max-height: min(13rem,40dvh);
      overflow: auto;
      padding: .26rem;
      background: var(--panel);
      border: 1px solid var(--line-strong);
      border-radius: .48rem;
      box-shadow: 0 5px 18px var(--shadow);
    }
    #channel-layout .message-actionbar details.open-above[open] .reaction-options {
      inset-block-start: auto;
      inset-block-end: calc(100% + .25rem);
    }
    #channel-layout .message-actionbar .reaction-options button {
      padding: .33rem .45rem;
      border: 1px solid transparent;
      border-radius: .3rem;
      background: transparent;
      text-align: start;
    }
    #channel-layout .message-actionbar .reaction-options button:is(:hover,:focus-visible,[aria-pressed=true]) {
      color: var(--accent);
      background: var(--chat-tint);
    }
    #channel-layout .message:has(.message-actionbar details[open]) { z-index: 4; }
  }
}
#channel-layout .read-receipt { margin: 0; font-size: .73rem; }
#channel-layout .read-receipt:empty { display: none; }
#channel-layout #thread-chat .thread-origin {
  margin: .05rem 0 .5rem;
  padding: .7rem;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--accent);
  background: var(--panel);
}
#channel-layout #thread-chat .chat-origin { margin-bottom: .15rem; }
.thread-replies-label {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin: .9rem .45rem .35rem;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 650;
}
.thread-replies-label::after { content: ''; flex: 1; height: 1px; background: var(--chat-rule); }
.thread-replies-label:last-child { display: none; }

.dm-conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  width: 100%;
  max-width: none;
  min-height: 0;
  height: min(40rem, 70dvh);
  padding: 0;
}
.dm-header { gap: .65rem; }
#dm-peer-avatar:empty { display: none; }
#dm-peer-avatar .avatar { width: 2.15rem; height: 2.15rem; border-radius: .65rem; }
#dm-peer-name { font-size: 1.06rem; margin: 0; overflow-wrap: anywhere; }
.dm-workspace {
  display: grid;
  grid-template-columns: minmax(12.5rem, 16.5rem) minmax(0, 1fr);
  gap: .7rem;
  min-width: 0;
  min-height: 0;
  flex: 1;
}
.dm-directory {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: .75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.dm-directory-heading { justify-content: space-between; gap: .45rem; margin-block-end: .65rem; }
.dm-directory-heading h2 { margin: 0; font-size: .88rem; }
.dm-search {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: 0 .58rem;
  min-height: 2.35rem;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: .6rem;
  color: var(--muted);
}
.dm-search:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.dm-search input { min-width: 0; width: 100%; border: 0; padding: .5rem 0; background: transparent; color: var(--ink); font: inherit; box-shadow: none; }
.dm-search input:focus-visible { outline: none; box-shadow: none; }
.dm-people { display: grid; align-content: start; gap: .2rem; margin-block-start: .55rem; overflow: auto; padding: .15rem; }
.dm-person {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .5rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
  min-height: 2.75rem;
}
.dm-person:hover { background: var(--panel-hover); }
.dm-person[aria-pressed=true] { background: var(--selected); border-color: var(--line-strong); }
.dm-person:focus-visible { outline-offset: -2px; }
.dm-person .avatar { width: 2rem; height: 2rem; border-radius: .6rem; }
.dm-person-copy { display: grid; min-width: 0; }
.dm-person-copy strong, .dm-person-preview { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dm-person-copy strong { font-size: .87rem; }
.dm-person-preview { color: var(--muted); font-size: .72rem; }
.dm-person-unread { background: var(--accent); color: var(--accent-ink); border-radius: 1rem; min-width: 1.25rem; padding: .1rem .26rem; font-size: .72rem; font-weight: 660; text-align: center; }
#dm-directory-status { margin: .55rem .15rem .1rem; font-size: .82rem; }
#dm-browse, #dm-return { display: none; }
@media (max-width:740px) {
  .dm-workspace { grid-template-columns: minmax(0,1fr); }
  .dm-workspace:not([data-browsing]) .dm-directory,
  .dm-workspace[data-browsing] .dm-conversation { display: none; }
  #dm-browse, #dm-return { display: inline-flex; align-items: center; min-height: 2.75rem; }
  #dm-browse { margin-inline-end: .15rem; font-size: .8rem; }
  .dm-search input { font-size: max(1rem, 16px); }
}
@media (forced-colors: active) {
  .dm-person[aria-pressed=true] { border: 2px solid Highlight; }
}

#dm-log { min-height: 0; max-height: none; }
#dm-log > .muted:first-child { padding: .6rem .4rem; }
.dm-intro, #channel-layout .channel-intro {
  display: grid;
  align-content: end;
  justify-items: start;
  gap: .3rem;
  min-height: 100%;
  padding: .8rem .45rem 1.15rem;
}
.dm-intro > .avatar, #channel-layout .channel-intro .channel-symbol {
  width: 2.65rem;
  height: 2.65rem;
  margin-bottom: .35rem;
  border-radius: .8rem;
  font-size: 1.35rem;
}
.dm-intro h2, #channel-layout .channel-intro h3 {
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  line-height: 1.2;
  letter-spacing: -.032em;
}
.dm-intro p, #channel-layout .channel-intro p { max-width: 42ch; font-size: .9rem; }
#channel-chat:has(> .channel-intro) {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 15rem;
}
#channel-chat > .channel-intro {
  align-content: center;
  justify-items: center;
  text-align: center;
  padding: 2rem 1.25rem;
}
#channel-chat .channel-intro #new-channel {
  margin-top: .5rem;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

#channel-layout .composer, #dm-form {
  align-self: end;
  min-width: 0;
  margin: .4rem var(--chat-edge) var(--chat-edge);
  padding: .65rem .72rem .55rem;
  gap: .45rem;
  border: 1px solid var(--line-strong);
  border-radius: .75rem;
  background: var(--bg);
  box-shadow: 0 2px 5px color-mix(in srgb, var(--shadow) 40%, transparent);
}
#channel-layout .composer { grid-template-columns: minmax(0,1fr); }
#channel-layout .composer textarea { min-width: 0; width: 100%; }
#channel-layout .composer:focus-within, #dm-form:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 20%, transparent);
}
#channel-layout .composer textarea, #dm-form textarea {
  display: block;
  min-height: 2.75rem;
  max-height: 30dvh;
  padding: .15rem .08rem;
  margin: 0;
  outline: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
}
@supports (field-sizing: content) {
  #channel-layout .composer textarea, #dm-form textarea {
    field-sizing: content;
    height: auto;
    max-height: min(8.8rem, 20dvh);
    resize: none;
  }
}
.composer .send-icon { display: none; }
#channel-layout .composer [type=submit], #dm-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .34rem;
}
#channel-layout .composer [type=submit]:disabled, #dm-send:disabled {
  opacity: 1;
  color: var(--muted);
  background: var(--panel-raised);
  border-color: var(--line);
}
#channel-layout .composer .send-icon, #dm-send .send-icon {
  display: block;
  flex: none;
  width: .92rem;
  height: .92rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#dm-form label {
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
#channel-layout .composer-actions, #dm-form > .row {
  padding-top: .38rem;
  border-top: 1px solid var(--chat-rule);
}
#channel-layout .composer-shortcut, #dm-form .composer-shortcut { font-size: .72rem; color: var(--muted); }
#channel-layout .composer-shortcut kbd, #dm-form .composer-shortcut kbd {
  padding: .03rem .18rem;
  color: inherit;
  font-size: .92em;
}
#channel-layout .composer-tools { gap: .12rem; }
#channel-layout .compose-tool { border-radius: .38rem; }
#channel-layout .chat-jump, #dm-jump { justify-content: center; padding: .15rem; border: 0; }

#channel-files-panel, #channel-tickets-panel {
  gap: 1rem;
  padding: clamp(1rem, 2vw, 1.65rem);
  border-radius: .8rem;
  background: var(--bg);
}
#channel-files-panel h2, #channel-tickets-panel h2 {
  font-size: 1.17rem;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
}
#channel-files-panel .file-upload {
  justify-items: start;
  padding: .95rem;
  border: 1px solid var(--chat-rule);
  border-radius: .62rem;
  background: var(--panel);
}
#channel-files-panel .file-upload label,
#channel-files-panel .file-search { color: var(--ink); font-size: .84rem; font-weight: 650; }
#channel-files-panel .file-upload input {
  display: block;
  font: inherit;
  color: var(--muted);
  font-size: .86rem;
}
#channel-files-panel .file-upload input::file-selector-button {
  margin-inline-end: .55rem;
  padding: .45rem .65rem;
  border: 1px solid var(--line-strong);
  border-radius: .42rem;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
#channel-files-panel .file-upload input:hover::file-selector-button { background: var(--chat-tint); }
#channel-files-panel .file-upload > small { font-size: .77rem; }
#channel-files-panel .file-search input { font-weight: 450; }
#channel-files-panel .file-list { gap: 0; }
#channel-files-panel .file-item { padding: .7rem 0; border: 0; border-bottom: 1px solid var(--chat-rule); border-radius: 0; }
#channel-files-panel .file-item:first-child { padding-top: .15rem; }
#channel-files-panel .file-item:last-child { border-bottom: 0; }
#channel-files-panel .file-actions [data-preview-file] {
  padding: .3rem .18rem;
  background: transparent;
  border-color: transparent;
  font-weight: 650;
}
#channel-files-panel .file-actions [data-preview-file]:is(:hover,:focus-visible) { color: var(--accent); text-decoration: underline; }
#channel-files-panel .file-item > .btn { color: var(--muted); background: transparent; }
#channel-files-panel .file-empty { padding: .18rem 0; }

@container conversation (max-width: 32rem) {
  #channel-layout .composer-shortcut { display: none; }
  #channel-layout .chat-top .channel-action:not([data-new-thread],[data-archive-key]) > span { display: none; }
  #channel-layout .chat-top .channel-action:not([data-new-thread]) { min-width: 2rem; padding-inline: .35rem; }
}
@container conversation (max-width: 23rem) {
  #channel-layout .chat-top .channel-action { min-width: 2rem; padding-inline: .35rem; }
  #channel-layout .chat-top { display: grid; grid-template-columns: minmax(0,1fr) auto; }
  #channel-chat .chat-heading { gap: .2rem; font-size: 1rem; }
  #channel-chat .chat-heading .channel-symbol { width: auto; height: auto; border: 0; background: transparent; font-size: 1em; }
  #channel-layout .composer-actions { flex-wrap: nowrap; gap: .25rem; }
  #channel-layout .composer-tools { flex: 1; flex-wrap: nowrap; min-width: 0; margin-inline-end: 0; gap: .1rem; }
  #channel-layout .composer-tools .compose-tool { flex: 1; min-width: 0; max-width: 2.75rem; padding-inline: .12rem; }
}
@container conversation (max-width: 20rem) {
  #channel-layout .chat-top .channel-action:not([data-archive-key]) > span { display: none; }
  #channel-layout .chat-top:has([data-archive-key]) { grid-template-columns: minmax(0,1fr); }
}

@media (min-height: 500px), (min-width: 741px) and (min-height: 440px) {
  .app:has(.main:not(.tour-active) > :is([data-screen=dm],[data-screen=chat]):not([hidden])) {
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .app:has(.main:not(.tour-active) > :is([data-screen=dm],[data-screen=chat]):not([hidden])) .side { overflow: auto; }
  .main:not(.tour-active):has(> :is([data-screen=dm],[data-screen=chat]):not([hidden])) { display: flex; min-height: 0; }
  .main:not(.tour-active) > :is([data-screen=dm],[data-screen=chat]):not([hidden]) {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
  }
  .main:not(.tour-active) .dm-conversation { height: auto; }
  .main:not(.tour-active) #channel-layout { flex: 1; min-height: 0; }
  .main:not(.tour-active) #channel-layout .chat-messages { min-height: 0; max-height: none; }
}
@media (max-width: 740px) {
  .app:has(.main:not(.tour-active) > :is([data-screen=dm],[data-screen=chat]):not([hidden])) {
    grid-template-rows: auto auto minmax(0, 1fr);
  }
}

@media (max-width: 740px) {
  [data-screen=chat], [data-screen=dm] { --chat-edge: .55rem; }
  #channel-actions { gap: .4rem; }
  #channel-actions > .row { gap: .35rem; }
  #channel-actions .btn { padding-inline: .55rem; }
  #channels:not(:empty) {
    margin-top: .25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: .2rem;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
  }
  #channels > button { flex: none; max-width: 90%; overflow-wrap: anywhere; }
  #channel-layout .chat-top, .dm-header { padding: .58rem .7rem; }
  #channel-layout .chat-messages, #dm-log { padding: .4rem .38rem; scrollbar-gutter: auto; }
  #channel-layout .message, #dm-log .message { gap: .5rem; }
  #dm-form .composer-shortcut { display: none; }
}
@media (max-width: 420px) {
  #find-channels-mobile .find-label { display: none; }
  #find-channels-mobile .browse-label { display: inline; }
  #channel-actions .btn { min-width: 3.15rem; text-align: center; }
  #channels:not(:empty) { display: none; }
}
@media (min-width: 19em) and (max-width: 740px) and (min-height: 500px) {
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .2rem .25rem;
    margin-block-end: .55rem;
    border-bottom: 1px solid var(--chat-rule);
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #channel-actions { display: contents; }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #chat-title {
    position: absolute;
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #channel-actions > .row {
    order: 2;
    margin-inline-start: auto;
    gap: .16rem;
  }
  .main:not(.tour-active) .messages-heading #channel-tabs:not([hidden]) {
    order: 1;
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    margin: 0;
    gap: 0;
    border-bottom: 0;
  }
  .main:not(.tour-active) .messages-heading #channel-tabs button {
    min-width: 0;
    padding-inline: clamp(.22rem, 1.15vw, .54rem);
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #new-channel {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    min-width: 0;
    padding: 0;
    font-size: 1.2rem;
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) .new-channel-label { display: none; }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) .new-channel-symbol { display: inline; }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #find-channels-mobile .find-label { display: none; }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #find-channels-mobile .browse-label { display: inline; }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #find-channels-mobile {
    padding-inline: .32rem;
    font-size: .8rem;
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #channels { order: 3; flex-basis: 100%; }
}
@media (max-width: 365px) {
  #channel-actions .action-suffix { display: none; }
}
@media (min-width: 540px) and (max-height: 540px) {
  .main:not(.tour-active):has(> :is([data-screen=chat],[data-screen=dm]):not([hidden])) { padding-block: .5rem; }
  .main:not(.tour-active) .messages-heading, .main:not(.tour-active) [data-screen=dm] > .heading { margin-bottom: .4rem; }
  .main:not(.tour-active) #channel-layout .chat-top, .dm-header { min-height: 2.55rem; padding-block: .32rem; }
  .main:not(.tour-active) #channel-layout .composer, #dm-form { margin-block-end: .55rem; padding-block: .38rem; }
  .main:not(.tour-active) #channel-layout .composer textarea, #dm-input { height: 2.05rem; min-height: 2.05rem; }
  .main:not(.tour-active) #channel-layout .composer-actions { padding-top: .2rem; }
}
@media (min-width: 540px) and (max-width: 740px) and (max-height: 460px) {
  .main:not(.tour-active) .messages-heading { grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: .5rem; }
  .main:not(.tour-active) #channels { display: none; }
  .main:not(.tour-active) #channel-tabs { gap: 0; margin: 0; }
  .main:not(.tour-active) #channel-tabs button { padding-inline: .42rem; }
  .main:not(.tour-active) #channel-actions { min-width: 0; }
}
@media (pointer: coarse) {
  #channel-layout .chat-top .btn, #channel-layout .message-tools .btn,
  #new-channel, #find-channels-mobile { min-height: 2.75rem; }
  #channel-layout .message-actionbar summary { display: inline-flex; align-items: center; min-height: 2.75rem; }
  #channel-layout .compose-tool { min-width: 2.5rem; min-height: 2.75rem; }
  #channel-layout .chat-top .channel-action { min-width: 2.75rem; }
}

/* Keep the controls readable when the browser's default text is large relative to the screen. */
@media (max-width: 17em) {
  .main:has(> [data-screen=chat]:not([hidden])) { padding-inline: min(.75rem, 3.5vw); }
  .messages-heading { gap: .2rem; margin-bottom: .5rem; }
  #channel-actions .action-suffix, #find-channels-mobile .find-label, #channels:not(:empty) { display: none; }
  #find-channels-mobile .browse-label { display: inline; }
  #channel-actions, #channel-actions > .row { gap: .22rem; }
  #channel-actions .btn { min-width: 0; padding: .16rem .35rem; }
  #channel-tabs { flex-wrap: wrap; gap: 0 .16rem; }
  #channel-tabs button { padding: .2rem .12rem; }
}
@container conversation (max-width: 16rem) {
  #channel-layout .chat-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .16rem .35rem;
    padding: .2rem min(.55rem, 3cqi);
  }
  #channel-layout .chat-top .channel-action {
    min-width: max(44px, 1.35em);
    min-height: max(44px, 1.35em);
    padding: .08rem .16rem;
  }
  #channel-layout .composer { margin: .22rem; padding: .26rem min(.45rem, 3cqi); gap: .2rem; }
  #channel-layout .composer textarea { min-height: 1.8rem; height: 2.1rem; }
  #channel-layout .composer-actions { flex-wrap: wrap; gap: .16rem; padding-top: .2rem; }
  #channel-layout .composer-tools { flex: 1 1 auto; flex-wrap: wrap; }
  #channel-layout .composer-tools .compose-tool {
    flex: 0 0 max(44px, 1.35em);
    min-height: max(44px, 1.35em);
    max-width: none;
  }
}
@container chat-page (max-width: 17rem) {
  .main:not(.tour-active) .messages-heading #channel-tabs button {
    min-height: max(44px,1.5rem);
    padding: .16rem .12rem;
    font-size: .82rem;
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #new-channel {
    width: max(44px,1.6rem);
    min-height: max(44px,1.6rem);
  }
  .main:not(.tour-active) .messages-heading:has(#channel-tabs:not([hidden])) #find-channels-mobile {
    min-height: max(44px,1.6rem);
    padding-block: .08rem;
  }
  .main:not(.tour-active) #channel-layout, .main:not(.tour-active) .dm-workspace {
    flex: 0 0 auto;
    height: auto;
  }
  .main:not(.tour-active) #channel-layout .chat-messages, .main:not(.tour-active) #dm-log {
    height: min(9.5rem, 42dvh);
    min-height: 0;
    max-height: none;
  }
}
@media (min-height: 500px) and (max-height: 30em) and (max-width: 48em) {
  .app:has(.main:not(.tour-active) > [data-screen=chat]:not([hidden])) { height: auto; }
  .main:not(.tour-active) #channel-layout .chat-messages {
    min-height: min(9rem, 40dvh);
    max-height: 54dvh;
  }
}
@media (forced-colors: active) {
  #channel-layout .composer:focus-within, #dm-form:focus-within { outline: 2px solid Highlight; }
}
@media (prefers-reduced-motion: no-preference) {
  #channel-layout .composer, #dm-form {
    transition: border-color 140ms var(--ease-ui), box-shadow 140ms var(--ease-ui);
  }
  #channel-tabs button, #channel-layout .compose-tool {
    transition: background-color 120ms var(--ease-ui), color 120ms var(--ease-ui);
  }
  .main:not(.tour-active) #channel-layout.thread-open #thread-chat {
    animation: desk-thread-reveal 155ms var(--ease-ui);
  }
}
@keyframes desk-thread-reveal {
  from { opacity: .65; transform: translateX(3px); }
  to { opacity: 1; transform: translateX(0); }
}
#channel-layout .chat-top .channel-action.tour-highlight-control > span { display: inline; }
#channel-layout .composer textarea.tour-highlight-control {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.compose-editor { position: relative; min-width: 0; }
.compose-editor textarea { position: relative; }
.compose-mention-preview {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  scrollbar-gutter: stable;
  border-style: solid;
  border-color: transparent;
  color: var(--ink);
}
.compose-draft-mention {
  background: var(--panel-raised);
  color: var(--accent);
  border-radius: .24rem;
}
#channel-layout .compose-editor.has-draft-mention textarea {
  color: transparent;
  background: transparent;
  caret-color: var(--ink);
}
.compose-editor textarea::selection { color: var(--ink); background: var(--selected); }
.compose-picker .compose-suggestion-active { background: var(--selected); border-color: var(--line-strong); color: var(--ink); }
@media (forced-colors: active) {
  .compose-mention-preview { display: none; }
  #channel-layout .compose-editor.has-draft-mention textarea { color: CanvasText; }
}

.formatted-message a.composer-mention {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, currentColor 55%, transparent);
  text-underline-offset: .14em;
}
.formatted-message a.composer-mention:hover,
.formatted-message a.composer-mention:focus-visible {
  text-decoration-color: currentColor;
  background: var(--selected);
}

@media (min-width:741px) {
  .main:not(.tour-active) .messages-heading:has(#chat-title[data-open-channel]) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .55rem;
    border-block-end: 1px solid var(--line);
  }
  .main:not(.tour-active) #channel-actions:has(#chat-title[data-open-channel]) { display: contents; }
  .main:not(.tour-active) #chat-title[data-open-channel] { position:absolute; clip-path:inset(50%); width:1px; height:1px; overflow:hidden; }
  .main:not(.tour-active) #channel-actions:has(#chat-title[data-open-channel]) > .row { order: 1; margin-inline-start: auto; }
  .main:not(.tour-active) .messages-heading:has(#chat-title[data-open-channel]) #channel-tabs { margin: 0; border: 0; }
}

.conversation-preference {
  display: inline-grid;
  place-items: center;
  min-inline-size: 2rem;
  min-block-size: 2rem;
  padding: .25rem;
}
.conversation-preference svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.conversation-preference[aria-pressed="true"] {
  color: var(--accent);
  background: var(--selected);
}
.conversation-preference[aria-pressed="true"] use { fill: currentColor; }
#dm-log .message:has(.conversation-preference) {
  grid-template-columns: 2rem minmax(0,1fr) auto;
}
#dm-log .message > .conversation-preference {
  grid-column: 3;
  grid-row: 1;
  align-self: start;
}
@media (hover: hover) and (pointer: fine) {
  #dm-log .message:not(:hover,:focus-within) > .conversation-preference[aria-pressed="false"] { opacity: 0; }
}
#saved-messages { width: min(34rem, calc(100% - 1.5rem)); }
#saved-messages .dialog-header p { margin: .35rem 0 0; font-size: .84rem; }
#saved-messages-list { list-style: none; display: grid; gap: 0; padding: 0; margin: 0; }
.saved-message {
  display: grid;
  gap: .55rem;
  padding: .75rem 0;
  border-block-end: 1px solid var(--line);
}
.saved-message:first-child { padding-block-start: 0; }
.saved-message:last-child { border-block-end: 0; padding-block-end: 0; }
.saved-message-copy { min-width: 0; overflow-wrap: anywhere; }
.saved-message-copy p { margin: .25rem 0 0; white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.saved-message-actions { flex-wrap: wrap; }
.team-post-actions { display: flex; flex-wrap: wrap; gap: .25rem .5rem; }
.team-post-actions .btn { width: auto; }
.team-ticket-source {
  padding: .5rem .75rem;
  border-inline-start: 3px solid var(--accent);
  background: var(--selected);
  border-radius: .25rem;
  overflow-wrap: anywhere;
}
.team-ticket-source strong { font-size: .8rem; }
.team-ticket-source blockquote { margin: .25rem 0 0; }
@media (pointer: coarse) {
  .conversation-preference, .saved-message-actions .btn { min-width: 44px; min-height: 44px; }
  .team-post-actions .btn { min-height: 44px; }
}
