/* Mobile Channels presentation. Desktop Direct Messages retains its original styles. */
:root body .channel-chat-window {
  position: fixed;
  inset: auto 18px 18px auto;
  width: min(410px, calc(100vw - 24px));
  height: min(600px, calc(100dvh - var(--rx-size-topbar) - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - var(--rx-size-topbar) - 24px);
  margin: 0;
  padding: var(--rx-space-3);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  z-index: var(--rx-layer-chat);
  border: 1px solid var(--rx-color-border);
  border-radius: var(--rx-radius-panel);
  background: radial-gradient(circle at 12% -8%, rgba(var(--rx-color-accent-rgb),.16), transparent 46%), linear-gradient(150deg, rgba(var(--rx-color-accent-secondary-rgb),.07), transparent 62%), var(--rx-color-overlay-solid);
  color: var(--rx-color-text);
  box-shadow: var(--rx-shadow-overlay);
}

.channel-chat-window .chat-overlay-top { align-items: center; }
.channel-chat-window .channel-chat-inbox,
.channel-chat-window .channel-chat-conversation {
  display: flex;
  flex-direction: column;
  gap: var(--rx-space-2);
  min-height: 0;
  flex: 1;
}
.channel-chat-window [hidden] { display: none !important; }
.channel-chat-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px; }
.channel-chat-list > div + div { margin-top: var(--rx-space-2); }
.channel-chat-row {
  min-height: 64px;
  background: var(--rx-color-surface-subtle);
  border-color: var(--rx-color-border);
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.channel-chat-row > :not(.channel-chat-banner) { position: relative; z-index: 1; }
.channel-chat-row > .channel-chat-banner {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  opacity: 0;
  /* Fade the existing picture away behind the avatar and text. The theme's
     original card surface remains the base, including every colour tint. */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 100%);
  mask-image: linear-gradient(90deg, transparent, #000 100%);
}
.channel-chat-row > .channel-chat-banner.is-loaded { opacity: .24; }
.channel-chat-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-chat-row .dm-thread-preview { display: block; }
.channel-chat-avatar { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 40px; }
.channel-chat-avatar > * { max-width: 40px; max-height: 40px; width: 40px; height: 40px; }
.channel-chat-avatar img { object-fit: cover; border-radius: var(--rx-radius-avatar); }
.channel-chat-avatar svg { width: 24px; height: 24px; }
.channel-chat-unread { font-size: var(--rx-font-size-xs); color: var(--rx-color-accent); flex-shrink: 0; }
.channel-chat-back { align-self: flex-start; display: inline-flex; align-items: center; gap: var(--rx-space-2); min-height: 44px; }
.channel-chat-back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.channel-chat-launcher[hidden] { display: none !important; }
.channel-chat-launcher { display: flex; flex-direction: column; gap: var(--rx-space-3); }
.channel-chat-launcher .channel-chat-list { flex: 1; max-height: 460px; }
.channel-chat-mobile-entry { display: none; }

/* The existing conversation becomes content of a window. It no longer owns
   the dashboard's fixed heights, channel rail, or saved Home placement. */
:root body #channelChatOverlay #globalChatPanel {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  box-shadow: none;
}
#channelChatOverlay #globalChatPanel > .panel-title-row { display: none !important; }
#channelChatOverlay #chatChannelRail,
#channelChatOverlay .chat-toolbar { display: none !important; }
#channelChatOverlay .chat-layout-actions,
#channelChatOverlay #globalChatPanel .panel-title { display: none !important; }
#channelChatOverlay #globalChatArea {
  display: flex;
  flex-direction: column;
  gap: var(--rx-space-2);
  flex: 1 1 auto !important;
  min-height: 0;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
/* History uses the space left by the composer, regardless of message count.
   Letting its full content compete with a shrinking picker row collapses the
   picker in busy conversations. Only the choices need a viewport-sized cap. */
#channelChatOverlay #globalChatMessages {
  flex: 1 1 0 !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto;
  margin-bottom: 0;
}
#channelChatOverlay .chat-input-row { flex: 0 0 auto; }
#channelChatOverlay .chat-emoji-docked:not(.chat-emoji-searching) {
  /* Controls set their own height; only the scrollable choices are capped. */
  height: auto;
  grid-template-rows: auto auto auto minmax(var(--rx-size-tap-min), 1fr);
}
#channelChatOverlay .chat-emoji-docked:not(.chat-emoji-searching) .chat-emoji-grid {
  min-height: var(--rx-size-tap-min);
  max-height: min(10rem, 20dvh);
}
#channelChatOverlay #globalChatArea > .muted.small:last-child { display: none; }

/* One header row gives the conversation the remaining height at every size. */
#channelChatOverlay > .chat-overlay-top {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: var(--rx-space-2);
  min-height: 52px;
  padding: 0 0 var(--rx-space-2);
  margin: 0 0 var(--rx-space-2);
  border-bottom: 1px solid var(--rx-color-border);
}
#channelChatOverlay .channel-chat-inbox-title,
#channelChatOverlay .channel-chat-identity { flex: 1; min-width: 0; }
#channelChatOverlay .channel-chat-identity .panel-title { margin: 0; line-height: var(--rx-line-height-tight); }
#channelChatOverlay .channel-chat-identity .chat-active-channel-label {
  display: block;
  min-width: 0;
  max-width: none;
  font-size: var(--rx-font-size-body);
  font-weight: var(--rx-font-weight-strong);
  color: var(--rx-color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#channelChatOverlay .channel-chat-kind { display: block; font-size: var(--rx-font-size-xs); color: var(--rx-color-text-muted); }
#channelChatOverlay .chat-channel-rail-add {
  width: var(--rx-size-tap-min);
  min-width: var(--rx-size-tap-min);
  height: var(--rx-size-tap-min);
  min-height: var(--rx-size-tap-min);
  flex-basis: var(--rx-size-tap-min);
}
#channelChatOverlay > .chat-overlay-top > button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 var(--rx-size-tap-min);
  width: var(--rx-size-tap-min);
  height: var(--rx-size-tap-min);
  min-width: var(--rx-size-tap-min);
  min-height: var(--rx-size-tap-min);
  padding: 0;
}
#channelChatOverlay .channel-chat-settings-trigger svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.channel-chat-settings-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  background: rgba(0,0,0,.48);
  padding-top: var(--rx-space-3);
}
.channel-chat-settings {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--rx-color-border-strong);
  border-radius: var(--rx-radius-panel) var(--rx-radius-panel) 0 0;
  background: var(--rx-color-overlay-solid);
  box-shadow: var(--rx-shadow-overlay);
  color: var(--rx-color-text);
}
.channel-chat-settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--rx-space-2);
  padding: var(--rx-space-3) var(--rx-space-4);
  flex-shrink: 0;
  border-bottom: 1px solid var(--rx-color-border);
}
.channel-chat-settings h2,
.channel-chat-settings h3 { margin: 0; font-size: var(--rx-font-size-body); font-weight: var(--rx-font-weight-strong); }
.channel-chat-settings-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding: 0 var(--rx-space-4) max(var(--rx-space-4), var(--rx-safe-bottom));
}
.channel-chat-setting { padding: var(--rx-space-4) 0; }
.channel-chat-setting + .channel-chat-setting { border-top: 1px solid var(--rx-color-border); }
.channel-chat-setting-row { display: flex; align-items: center; justify-content: space-between; gap: var(--rx-space-2); flex-wrap: wrap; }
.channel-chat-setting p { margin: var(--rx-space-1) 0 0; font-size: var(--rx-font-size-sm); color: var(--rx-color-text-muted); }
.channel-chat-size { display: flex; align-items: center; gap: var(--rx-space-2); }
.channel-chat-size output { min-width: 4ch; text-align: center; font-variant-numeric: tabular-nums; }
.channel-chat-settings .btn { min-width: var(--rx-size-tap-min); min-height: var(--rx-size-tap-min); }
.channel-chat-colors { display: flex; flex-wrap: wrap; gap: var(--rx-space-1); margin-top: var(--rx-space-3); }
.channel-chat-colors .chat-name-color-option { width: var(--rx-size-tap-min); height: var(--rx-size-tap-min); flex: 0 0 var(--rx-size-tap-min); }
.channel-chat-colors .chat-name-color-option span { width: 24px; height: 24px; }
.channel-chat-colors .chat-name-color-option.selected { border-color: var(--rx-color-accent); box-shadow: inset 0 0 0 1px var(--rx-color-accent); }
.channel-chat-management { display: flex; flex-direction: column; gap: var(--rx-space-2); }

@media (max-width: 720px) {
  :root body .chat-workspace {
    inset: max(var(--rx-size-topbar), var(--rx-visual-top, 0px)) 0 var(--rx-keyboard-bottom, 0px);
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: var(--rx-space-3) max(var(--rx-space-3), var(--rx-safe-right)) max(var(--rx-space-3), var(--rx-safe-bottom)) max(var(--rx-space-3), var(--rx-safe-left));
  }
  body:has(.chat-workspace:not(.hidden)) { overflow: hidden; }
}
@media (min-width: 721px) {
  :root[data-rx-keyboard-open] body .chat-workspace {
    top: calc(var(--rx-visual-top) + 12px);
    bottom: calc(var(--rx-keyboard-bottom) + 12px);
    height: auto;
    max-height: calc(var(--rx-visual-height) - 24px);
  }
}

@media (max-width: 900px) {
  body.native-game-active .channel-chat-mobile-entry { display: none !important; }
}
