/* Direct messages: the persistent page and shared unread badge.
   Theme tokens only (no literal colours), so every app theme and accent applies. */

/* ─── Entry points ─── */
.dmOpenBtn {
  flex: none;
  gap: 6px;
}

.dmOpenBtn svg {
  flex: none;
}

.dmUnreadBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid rgb(var(--danger-rgb) / 0.36);
  border-radius: 999px;
  background: rgb(var(--danger-strong-rgb) / 0.22);
  color: var(--danger-text);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.dmUnreadBadge.hidden {
  display: none;
}

/* The room top bar is tight on small screens: keep the icon and the badge, drop the word. */
@media (max-width: 720px) {
  #roomView .dmOpenBtn .dmOpenLabel {
    display: none;
  }
}

/* The profile card footer holds the quick-message box (other accounts) or the market action (you). */
.cosmProfileFooter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Quick message: one rounded field, like the chat composer. */
.cosmProfileMessageBox {
  display: flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 3px 3px 3px 12px;
  border-radius: 10px;
  background: var(--input-bg);
  box-shadow: inset 0 0 0 1px var(--border-hover);
  transition: box-shadow var(--transition-fast), background-color var(--transition-fast);
}

.cosmProfileMessageBox[hidden] {
  display: none;
}

.cosmProfileMessageBox:focus-within {
  background: var(--card-strong);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.cosmProfileMessageBox .cosmProfileMessageInput {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font-size: var(--text-base);
}

.cosmProfileMessageBox .cosmProfileMessageInput:focus {
  outline: none;
  background: transparent;
  box-shadow: none;
}

.cosmProfileMessageBtn {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 120ms ease-out, color 120ms ease-out;
}

.cosmProfileMessageBtn svg {
  width: 17px;
  height: 17px;
}

.cosmProfileMessageBtn:hover,
.cosmProfileMessageBox:focus-within .cosmProfileMessageBtn {
  background: var(--accent-fill);
  color: var(--on-accent-fill);
}

.cosmProfileMessageBtn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ─── Page layout ─── */
.dmPage { display: flex; flex: 1; min-width: 0; min-height: 0; }

.dmPageContent {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-height: none;
  padding: 0;
  overflow: hidden;
}

.dmPageHeader {
  flex: none;
  margin: 0;
  padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
}

.dmHeaderActions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dmNewBtn .dmIcon {
  width: 14px;
  height: 14px;
}

/* Back controls in the page headers. */
.dmBackBtn {
  width: 32px;
  height: 32px;
  border-color: transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
}

.dmBackBtn:hover {
  border-color: transparent;
  background: var(--surface-hover);
  color: var(--text);
}

.dmBackBtn .dmIcon {
  width: 18px;
  height: 18px;
}

.dmBody {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.dmListPane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  background: rgb(var(--shadow-rgb) / 0.12);
}

.dmRightPane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* Empty states: a soft icon disc, a title, one line and the next step. */
.dmPlaceholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 320px;
  margin: auto;
  padding: 24px;
  text-align: center;
}

.dmEmptyArt {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.dmEmptyArt .dmIcon {
  width: 30px;
  height: 30px;
  stroke-width: 1.5;
}

.dmEmptyTitle {
  font-size: var(--text-lg);
  font-weight: 600;
}

.dmEmptyText {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-md);
}

/* The start of a conversation's history. */
.dmIntro {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 20px 12px 8px;
  text-align: center;
}

.dmIntro.hidden {
  display: none;
}

.dmAvatar.dmIntroAvatar {
  flex: none;
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
  font-size: var(--text-xl);
}

.dmAvatarWrap.dmIntroAvatarWrap {
  flex: none;
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
}

.dmIntroAvatarWrap .dmIntroAvatar { margin-bottom: 0; }

.dmIntroName {
  font-size: var(--text-lg);
  font-weight: 700;
}

.dmIntroText {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.dmIntro + .dmChatState {
  margin-top: 4px;
}

.dmChatPane,
.dmPickerPane {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.dmChatPane.hidden,
.dmPickerPane.hidden {
  display: none;
}

/* ─── Avatars and presence ─── */
.dmAvatarWrap {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
}

.dmAvatar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--text-sm);
  font-weight: 700;
  user-select: none;
}

.dmChatAvatarWrap {
  flex-basis: 38px;
  width: 38px;
  height: 38px;
}

.dmAvatarImg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dmPresenceDot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  border: 2.5px solid var(--popover-bg);
  border-radius: 50%;
  background: var(--status-offline);
}

.dmPresenceDot.online {
  background: var(--success);
}

/* ─── Conversation list and picker rows ─── */
.dmConversationList,
.dmPickerList {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}

.dmPickerList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 8px 10px;
}

.dmConversation,
.dmPickerRow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.dmConversation:hover,
.dmPickerRow:hover {
  background: var(--surface-hover);
}

.dmConversation:focus-visible,
.dmPickerRow:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmConversationItem.is-selected .dmConversation {
  background: var(--surface-active);
}

/* The row hover ring around the presence dot follows the row colour. */
.dmConversation:hover .dmPresenceDot,
.dmPickerRow:hover .dmPresenceDot,
.dmConversationItem.is-selected .dmPresenceDot {
  border-color: color-mix(in srgb, var(--popover-bg) 92%, var(--text));
}

.dmConversationText {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}

.dmConversationTop,
.dmConversationBottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.dmConversationName {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-md);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmConversationTime {
  flex: none;
  color: var(--muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.dmConversationPreview {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmConversationPreview.is-online {
  color: var(--success);
}

/* Unread: bolder name and preview, an accent time and a filled count. */
.dmConversationItem.has-unread .dmConversationName {
  font-weight: 700;
}

.dmConversationItem.has-unread .dmConversationPreview {
  color: var(--text);
  font-weight: 500;
}

.dmConversationItem.has-unread .dmConversationTime {
  color: var(--accent-text);
  font-weight: 600;
}

.dmConversationBottom .dmUnreadBadge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border: 0;
  background: var(--accent-fill);
  color: var(--on-accent-fill);
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}

.dmListEmpty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 18px;
  text-align: center;
}

.dmListEmpty.hidden,
.dmListHint.hidden {
  display: none;
}

.dmListStatus {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-md);
  font-weight: 600;
}

.dmListHint,
.dmPickerEmpty {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.dmPickerEmpty {
  padding: 24px 14px;
  text-align: center;
}

.dmListRetry {
  margin-top: 8px;
}

/* Search field of the new-message picker, with its icon inside. */
.dmSearchField {
  position: relative;
  display: block;
  margin: 12px 16px 6px;
}

.dmSearchField > .dmIcon {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
  translate: 0 -50%;
}

.dmSearchField .dmPickerSearch {
  height: 36px;
  padding-left: 34px;
  border-radius: 18px;
  font-size: var(--text-md);
}

/* ─── Chat header ─── */
.dmChatHeader {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 60px;
  box-sizing: border-box;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.dmChatTitle {
  display: grid;
  min-width: 0;
  line-height: 1.3;
}

.dmChatName {
  overflow: hidden;
  font-size: var(--text-base);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmChatStatus {
  color: var(--muted);
  font-size: var(--text-xs);
}

.dmChatStatus.is-online {
  color: var(--success);
}

.dmChatStatus.is-typing {
  color: var(--accent-text);
}

/* "Geri" only exists where the list and the chat cannot sit side by side. */
.dmBackBtn {
  display: none;
}

/* ─── Messages ─── */
.dmMessages {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 12px 16px 14px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dmMessages:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 70%, transparent);
}

.dmOlderBtn,
.dmChatRetry {
  flex: none;
  align-self: center;
}

.dmChatState {
  align-self: center;
  margin: 24px 0;
  font-size: var(--text-md);
  text-align: center;
}

.dmMessageList {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Day separators: a quiet rule with the day in the middle. */
.dmDaySeparator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
}

.dmDaySeparator:first-child {
  margin-top: 4px;
}

.dmDaySeparator::before,
.dmDaySeparator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.dmDaySeparatorLabel {
  flex: none;
}

/* Where the unread part started when the chat was opened: a red rule ending in "Yeni". */
.dmUnreadDivider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 2px;
  color: var(--danger);
  font-size: var(--text-2xs);
  font-weight: 700;
}

.dmUnreadDivider::before {
  content: "";
  flex: 1;
  height: 1px;
  background: rgb(var(--danger-rgb) / 0.55);
}

.dmUnreadDividerLabel {
  flex: none;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--danger);
  color: var(--on-danger);
  letter-spacing: 0.02em;
}

.dmUnreadDivider + .dmMessage.is-group-start {
  margin-top: 6px;
}

/* One message row. Rows of one sender within a few minutes form a group: tight spacing,
   joined corners and one time at the end of the group. */
.dmMessage {
  --dm-radius: 18px;
  --dm-joined: 5px;
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: min(76%, 560px);
  margin-top: 2px;
  outline: none;
}

.dmMessage.is-group-start {
  margin-top: 14px;
}

.dmDaySeparator + .dmMessage {
  margin-top: 6px;
}

.dmMessage.is-mine {
  align-self: flex-end;
  align-items: flex-end;
}

.dmMessage.is-theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.dmBubble {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 10px;
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  padding: 7px 12px;
  border-radius: var(--dm-radius);
  background: rgb(var(--surface-rgb) / 0.08);
  color: var(--text);
  font-size: var(--text-base);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.dmBubble > .dmBubbleTint.cosmAccent[data-cosm-accent] {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background-image: var(--cosm-accent);
  -webkit-background-clip: border-box;
  background-clip: border-box;
  opacity: 0.14;
  filter: none;
  pointer-events: none;
}

.dmBubbleTint::before,
.dmBubbleTint::after { display: none !important; }
.dmMessage.is-deleted .dmBubbleTint { display: none; }

.dmMessage.is-mine .dmBubble {
  background: var(--accent-fill);
  color: var(--on-accent-fill);
}

/* Joined corners on the sender's side inside a group. */
.dmMessage.is-mine:not(.is-group-start) .dmBubble {
  border-top-right-radius: var(--dm-joined);
}

.dmMessage.is-mine:not(.is-group-end) .dmBubble {
  border-bottom-right-radius: var(--dm-joined);
}

.dmMessage.is-theirs:not(.is-group-start) .dmBubble {
  border-top-left-radius: var(--dm-joined);
}

.dmMessage.is-theirs:not(.is-group-end) .dmBubble {
  border-bottom-left-radius: var(--dm-joined);
}

.dmMessage.is-pending .dmBubble {
  opacity: 0.62;
}

.dmMessage.is-mine.is-failed .dmBubble {
  box-shadow: inset 0 0 0 1px rgb(var(--danger-rgb) / 0.5);
  background: rgb(var(--danger-strong-rgb) / 0.45);
  color: var(--text);
}

.dmMessage.is-deleted .dmBubble {
  box-shadow: inset 0 0 0 1px var(--border-hover);
  background: transparent;
  color: var(--muted);
}

.dmText {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  white-space: pre-wrap;
  /* The app shell disables selection; message text stays copyable. */
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

.dmText.is-deleted {
  font-style: italic;
  cursor: default;
}

.dmText > a[data-chat-external-url]:not(.chatLinkPreview) {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.dmText :is(.chatLinkPreview, .chatXPreview) {
  box-sizing: border-box;
  max-width: 100%;
  color: var(--text);
  white-space: normal;
}

.dmMedia {
  flex: 1 0 100%;
  min-width: 0;
}

.dmText + .dmMedia {
  margin-top: 6px;
}

.dmMedia.hidden {
  display: none;
}

/* Time and delivery state: inline at the end of the last bubble of a group. */
.dmMeta {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding-top: 2px;
  color: var(--muted);
  font-size: var(--text-2xs);
  line-height: 1.6;
  white-space: nowrap;
  user-select: none;
}

.dmMessage.is-mine .dmMeta {
  color: color-mix(in srgb, var(--on-accent-fill) 72%, transparent);
}

.dmMessage.is-mine.is-failed .dmMeta,
.dmMessage.is-deleted .dmMeta {
  color: var(--muted);
}

.dmMessage:not(.is-group-end):not(.is-pending):not(.is-failed) .dmMeta {
  display: none;
}

.dmTime {
  font-variant-numeric: tabular-nums;
}

.dmDelivery {
  display: inline-flex;
}

.dmDelivery .dmIcon {
  width: 13px;
  height: 13px;
  stroke-width: 2.25;
}

.dmDelivery.is-failed {
  color: var(--danger);
}

.dmIcon {
  flex: none;
  width: 16px;
  height: 16px;
}

.dmSrOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A failed send: the reason and the two ways out sit under the bubble. */
.dmFailure {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  margin-top: 4px;
  color: var(--danger-text);
  font-size: var(--text-xs);
}

.dmFailure.hidden {
  display: none;
}

.dmFailure .dmIcon {
  width: 14px;
  height: 14px;
  color: var(--danger);
}

.dmFailureBtn {
  appearance: none;
  padding: 2px 6px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.dmFailureBtn:hover {
  background: var(--surface-hover);
}

.dmFailureBtn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Reply quote: a faded preview of the quoted message, above the bubble. */
.dmReplyQuote {
  display: flex;
  align-items: center;
  gap: 5px;
  box-sizing: border-box;
  max-width: 100%;
  margin-bottom: 3px;
  padding: 4px 10px;
  overflow: hidden;
  border-radius: 12px;
  background: rgb(var(--surface-rgb) / 0.045);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.dmReplyIcon {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--muted);
}

.dmReplyAuthor {
  flex: none;
  font-weight: 600;
}

.dmReplyText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmReplyText.is-deleted {
  color: var(--muted);
  font-style: italic;
}

/* ─── Attachments ─── */
.dmAttachment {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
  margin: 2px -6px 0;
}

.dmImage,
.dmVideo {
  display: block;
  max-width: min(100%, 320px);
  max-height: 320px;
  height: auto;
  border-radius: 12px;
  background: var(--overlay-light);
  object-fit: cover;
}

.dmImage {
  max-width: min(100%, 400px);
  max-height: 400px;
  outline: 1px solid oklch(1 0 0 / 0.1);
  outline-offset: -1px;
}

.dmImageOpen {
  position: relative;
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--on-media);
  cursor: zoom-in;
  transition: transform 120ms cubic-bezier(0.2, 0, 0, 1);
}

.dmImageOpen:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.dmImageOpen:active {
  transform: scale(0.96);
}

.dmImageExpand {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgb(var(--shadow-rgb) / 0.55);
  pointer-events: none;
}

.dmImageOpen:hover .dmImageExpand,
.dmImageOpen:focus-visible .dmImageExpand {
  background: rgb(var(--shadow-rgb) / 0.8);
}

.dmVideo {
  background: var(--media-bg);
  object-fit: contain;
}

/* An image alone is shown bare, the time laid over its corner. */
.dmMessage.is-media-only .dmBubble {
  padding: 0;
  background: transparent;
}

.dmMessage.is-media-only .dmAttachment {
  margin: 0;
}

.dmMessage.is-media-only .dmImageOpen,
.dmImageOpen .dmImage {
  border-radius: inherit;
}

.dmMessage.is-media-only .dmMedia {
  overflow: hidden;
  border-radius: inherit;
}

.dmMessage.is-media-only .dmMeta {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgb(var(--shadow-rgb) / 0.55);
  color: var(--on-media);
  pointer-events: none;
}

.dmMediaPlaceholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  width: 220px;
  max-width: 100%;
  min-height: 124px;
  padding: 10px;
  border-radius: 12px;
  background: var(--overlay-light);
  color: var(--muted);
  font-size: var(--text-xs);
  text-align: center;
}

.dmMediaPlaceholder.is-loading {
  background:
    linear-gradient(100deg, transparent 30%, rgb(var(--surface-rgb) / 0.06) 50%, transparent 70%) 0 0 / 200% 100%,
    var(--overlay-light);
  animation: dmShimmer 1.4s linear infinite;
}

@keyframes dmShimmer {
  from {
    background-position: 100% 0, 0 0;
  }
  to {
    background-position: -100% 0, 0 0;
  }
}

.dmMediaPlaceholder .dmIcon {
  width: 20px;
  height: 20px;
}

/* File card: icon tile, name and size, and a round download button. */
.dmFileChip {
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  width: min(280px, 100%);
  max-width: 100%;
  padding: 6px;
  border-radius: 12px;
  background: rgb(var(--shadow-rgb) / 0.16);
}

.dmFileIcon {
  display: grid;
  flex: none;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 7px;
  background: rgb(var(--surface-rgb) / 0.12);
}

.dmFileIcon .dmIcon {
  width: 18px;
  height: 18px;
}

.dmFileText {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.dmFileName {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmFileSize {
  font-size: var(--text-xs);
  opacity: 0.72;
}

.dmFileDownload {
  display: grid;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(var(--surface-rgb) / 0.12);
  color: inherit;
  cursor: pointer;
  transition-property: background-color, scale;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

.dmFileDownload:hover {
  background: rgb(var(--surface-rgb) / 0.2);
}

.dmFileDownload:active {
  scale: 0.96;
}

.dmFileDownload:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ─── Reactions and message actions ─── */
/* Reaction chips tuck under the bubble's bottom edge, cut out by a ring in the modal colour. */
.dmReactions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 100%;
  margin-top: -5px;
  padding: 0 8px;
}

.dmReactions.hidden {
  display: none;
}

.dmReaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: var(--card-strong);
  box-shadow: 0 0 0 2px var(--popover-bg), inset 0 0 0 1px var(--border-hover);
  color: var(--text-secondary);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
  transition-property: background-color, box-shadow, scale;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

.dmReaction:hover {
  background: color-mix(in srgb, var(--accent) 14%, var(--card-strong));
}

.dmReaction:active {
  scale: 0.96;
}

.dmReaction:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmReaction.is-mine {
  background: color-mix(in srgb, var(--accent) 24%, var(--card-strong));
  box-shadow: 0 0 0 2px var(--popover-bg), inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
  color: var(--accent-text);
}

.dmReactionEmoji {
  font-size: var(--text-sm);
  line-height: 1;
}

.dmReactionCount {
  font-size: var(--text-2xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* The hover toolbar floats above the row, on the sender's side, never over the text. */
.dmActions {
  position: absolute;
  bottom: calc(100% - 8px);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
  /* One row when it fits: a short bubble must not squeeze its toolbar into a column. */
  width: max-content;
  max-width: calc(100vw - 48px);
  padding: 3px;
  border-radius: 10px;
  background: var(--menu-bg);
  box-shadow: var(--shadow-popover);
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease-out;
}

.dmActions.hidden {
  display: none;
}

.dmMessage.is-mine .dmActions {
  right: 4px;
}

.dmMessage.is-theirs .dmActions {
  left: 4px;
}

.dmMessage:hover .dmActions,
.dmMessage:focus-within .dmActions,
.dmMessage.is-confirming .dmActions {
  opacity: 1;
  pointer-events: auto;
}

/* Confirming a delete is a decision about this message: it sits under the bubble, in the flow,
   instead of floating over the message above. */
.dmMessage.is-confirming .dmActions {
  position: static;
  margin-top: 6px;
}

.dmActions .chatMessageActionBtn {
  border-radius: 7px;
}

.dmConfirmText {
  padding: 0 6px;
  font-size: var(--text-sm);
}

.dmQuickReaction {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  appearance: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition-property: background-color, scale;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

.dmQuickReaction:hover {
  background: var(--surface-hover);
}

.dmQuickReaction:active:not(:disabled) {
  scale: 0.96;
}

.dmQuickReaction:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmQuickReaction:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dmEmojiGrid {
  display: grid;
  grid-template-columns: repeat(5, 32px);
  gap: 2px;
  box-sizing: border-box;
  margin-top: 6px;
  padding: 4px;
  border-radius: 10px;
  background: var(--menu-bg);
  box-shadow: var(--shadow-popover);
}

.dmEmojiGrid .dmQuickReaction {
  width: 32px;
  height: 32px;
  font-size: 18px;
}

.dmEmojiGrid.hidden {
  display: none;
}

/* The stream and its floating "new messages" pill. */
.dmStage {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.dmJumpBtn {
  position: absolute;
  bottom: 12px;
  left: 50%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 14px 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-fill);
  box-shadow: var(--shadow);
  color: var(--on-accent-fill);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  translate: -50% 0;
  transition-property: background-color, scale;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

.dmJumpBtn:hover {
  background: var(--accent-fill-hover);
}

.dmJumpBtn:active {
  scale: 0.96;
}

.dmJumpBtn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmJumpBtn.hidden {
  display: none;
}

.dmJumpBtn .dmIcon {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

/* The peer is typing: three dots in a bubble of their own, under the last message. */
.dmTyping {
  display: flex;
  flex: none;
  margin-top: 10px;
}

.dmTyping.hidden {
  display: none;
}

.dmTypingBubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgb(var(--surface-rgb) / 0.08);
}

.dmTypingDot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dmTypingDot 1.2s ease-in-out infinite;
}

.dmTypingDot:nth-child(2) {
  animation-delay: 0.15s;
}

.dmTypingDot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dmTypingDot {
  0%,
  60%,
  100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ─── Composer ─── */
.dmComposer {
  display: grid;
  flex: none;
  gap: 6px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}

/* One rounded field holds the attach button, the text and the send button. */
.dmComposerRow {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 4px;
  border-radius: 20px;
  background: var(--input-bg);
  box-shadow: inset 0 0 0 1px var(--border-hover);
  transition: box-shadow var(--transition-fast), background-color var(--transition-fast);
}

.dmComposerRow:focus-within {
  background: var(--card-strong);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.dmComposerRow .dmInput {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  max-height: 160px;
  padding: 6px 6px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: var(--text-base);
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
}

.dmComposerRow .dmInput:focus {
  background: transparent;
  box-shadow: none;
}

.dmComposerBtn {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition-property: background-color, color, opacity, scale;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
}

.dmComposerBtn .dmIcon {
  width: 18px;
  height: 18px;
}

.dmComposerBtn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.dmComposerBtn:active:not(:disabled) {
  scale: 0.96;
}

.dmComposerBtn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmComposerBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.dmSendBtn {
  background: var(--accent-fill);
  color: var(--on-accent-fill);
}

.dmSendBtn .dmIcon {
  stroke-width: 2.25;
}

.dmSendBtn:hover:not(:disabled) {
  background: var(--accent-fill-hover);
  color: var(--on-accent-fill);
}

/* Nothing to send yet: the button steps back until there is. */
.dmComposer.is-empty .dmSendBtn {
  background: var(--surface-active);
  color: var(--muted);
}

/* Reply and attachment bars above the field. */
.dmReplyBar,
.dmAttachmentChip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 5px 5px 12px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.dmReplyBar > .dmIcon,
.dmAttachmentChip > .dmIcon {
  width: 15px;
  height: 15px;
  color: var(--accent-text);
}

.dmReplyBar.hidden,
.dmAttachmentChip.hidden {
  display: none;
}

.dmReplyBarText,
.dmAttachmentChipName {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dmBarClear {
  flex: none;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.dmBarClear .dmIcon {
  width: 14px;
  height: 14px;
}

.dmBarClear:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.dmBarClear:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.dmCounter {
  justify-self: end;
  padding: 0 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.dmCounter.hidden {
  display: none;
}

.dmCounter.is-over {
  color: var(--danger);
  font-weight: 600;
}

.dmNotice {
  margin: 0;
  padding: 0 6px;
  color: var(--danger-text);
  font-size: var(--text-sm);
}

.dmDisabledNote {
  margin: 0;
  padding: 0 6px;
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* ─── Narrow screens: the list or the chat, one at a time ─── */
@media (max-width: 720px) {
  .dmPageContent {
    width: 100%;
    max-width: none;
    height: 100%;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .dmBody {
    grid-template-columns: minmax(0, 1fr);
  }

  .dmListPane {
    border-right: 0;
  }

  .dmPage[data-screen="chat"] .dmListPane,
  .dmPage[data-screen="new"] .dmListPane { display: none; }
  .dmPage[data-screen="list"] .dmBody { grid-template-rows: minmax(0, 1fr); }
  .dmPage[data-screen="list"] .dmListPane { max-height: none; }
  .dmPage[data-screen="list"] .dmRightPane { display: none; }

  .dmBackBtn {
    display: inline-flex;
    margin-left: -6px;
  }

  /* Inside a chat, people and history remain available through the back control. */
  .dmPage:not([data-screen="list"]) .dmNewBtn {
    display: none;
  }

  .dmMessage {
    max-width: 88%;
  }

  .dmComposer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .dmPage :is(.dmBackBtn, .dmComposerBtn, .dmBarClear, .dmNewBtn, .dmPeopleBtn) {
    min-width: 44px;
    min-height: 44px;
  }

  .dmPage :is(input, textarea, select) { font-size: 16px; }
}

/* Touch screens have no hover: a tapped message (it takes focus) shows its actions. */
@media (hover: none) {
  .dmMessage:focus .dmActions {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dmActions,
  .dmConversation,
  .dmPickerRow,
  .dmReaction,
  .dmComposerRow,
  .dmComposerBtn,
  .dmJumpBtn,
  .dmImageOpen {
    transition: none;
  }

  .dmTypingDot,
  .dmMediaPlaceholder.is-loading {
    animation: none;
  }
}

/* Persistent message page. Existing message and attachment rendering is shared. */
.dmPageHeader { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.dmPageHeader h3 { margin: 0; }
.dmHistorySearch { width: calc(100% - 24px); margin: 12px; flex: none; }
.dmPeopleLink { margin: 0 12px 12px; justify-content: flex-start; }
.dmListTitle { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; }
.dmPeopleCount { padding: 0 18px; color: var(--muted); font-size: var(--text-xs); }
.dmPickerPane { min-height: 0; overflow-y: auto; }
.dmPickerHeader { position: sticky; top: 0; background: var(--bg); z-index: 1; }
.dmPickerList { flex: none; }
.dmPickerRow { padding: 10px 18px; border-bottom: 1px solid var(--border); border-radius: 0; }
.dmPersonRoom { flex: none; padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: var(--text-xs); }
.dmPersonMessage { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-hover); color: var(--text-secondary); }
.dmPageHeader .dmPeopleBtn { display: none; }
.dmBackBtn { display: inline-flex; }
@media (max-width: 720px) {
  .dmPageHeader .dmPeopleBtn { display: inline-flex; }
  .dmPageContent { min-width: 0; }
  .dmPersonRoom { display: none; }
  .dmPage[data-screen="list"] .dmNewBtn { display: inline-flex; }
  .dmPage[data-screen="chat"] .dmPeopleBtn { display: none; }
}
