/* Yapper encrypted DMs - layout, requests, typing */

.notifications-button,
.dm-account-button {
  position: relative;
}

.dm-unread-badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border: 1px solid rgba(0, 0, 0, 0.26);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

/* Keep the fifth account action from falling onto a lonely second row. */
@media (min-width: 641px) {
  .card.account-bar .account-buttons,
  #authenticatedAccountButtons {
    display: flex !important;
    flex-wrap: nowrap !important;
    width: auto !important;
    gap: 8px !important;
  }

  .card.account-bar .account-buttons button,
  #authenticatedAccountButtons button {
    width: 92px !important;
    min-width: 82px !important;
  }
}

.dm-overlay {
  padding: 16px;
}

.dm-modal {
  width: min(760px, calc(100vw - 28px));
  height: min(740px, calc(100dvh - 32px));
  max-height: 740px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 30px;
  background: var(--card);
  color: var(--text);
}

.dm-modal-header,
.dm-conversation-header,
.dm-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dm-modal-header {
  min-height: 76px;
  box-sizing: border-box;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
  justify-content: space-between;
}

.dm-modal-header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.dm-modal-title-wrap,
.dm-panel-header-copy,
.dm-conversation-person-copy {
  min-width: 0;
  flex: 1;
}

.dm-modal-title-wrap h2,
.dm-panel-header h3 {
  margin: 0;
}

.dm-modal-title-wrap p,
.dm-panel-header p {
  margin: 3px 0 0;
  color: var(--secondary-text);
  font-size: 12px;
}

.dm-lock-pill {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid color-mix(in srgb, var(--primary) 58%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 13%, transparent);
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.dm-modal .dm-close-button,
.dm-modal .dm-back-button {
  width: 42px !important;
  min-width: 42px !important;
  max-width: 42px !important;
  height: 42px !important;
  min-height: 42px !important;
  max-height: 42px !important;
  flex: 0 0 42px !important;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  padding: 0 !important;
  border-radius: 999px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.dm-modal .dm-send-button {
  width: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  height: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;
  flex: 0 0 48px !important;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  padding: 0 !important;
  border-radius: 999px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.dm-modal .dm-close-button svg,
.dm-modal .dm-back-button svg,
.dm-modal .dm-send-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.dm-modal .dm-send-button svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.9;
}

.dm-main,
.dm-panel {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.dm-panel-header,
.dm-conversation-header {
  padding: 13px 17px;
}

.dm-conversation-header {
  min-height: 68px;
}

.dm-status {
  min-height: 0;
  margin: 5px 18px;
}

.dm-status:empty {
  display: none;
}

.dm-inbox-list,
.dm-search-results {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 6px 12px 18px;
  overscroll-behavior: contain;
}

.dm-inbox-item,
.dm-search-result {
  width: 100%;
  min-height: 68px;
  margin: 6px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 23px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  background: var(--button);
  color: var(--text);
}

.dm-inbox-item:hover,
.dm-search-result:hover {
  background: var(--button-hover);
}

.dm-inbox-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
}

.dm-mark-all-read-button {
  min-height: 40px;
  padding: 8px 12px;
  white-space: nowrap;
}

.dm-mark-all-read-button:disabled {
  opacity: 0.48;
  cursor: default;
}

.dm-inbox-profile-target,
.dm-search-profile-target {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
  cursor: pointer;
}

.dm-inbox-profile-target:hover,
.dm-search-profile-target:hover {
  text-decoration: underline;
}

.dm-inbox-profile-target .verified-badge,
.dm-search-profile-target .verified-badge,
.dm-conversation-name .verified-badge,
.dm-inbox-profile-target .role-badge,
.dm-search-profile-target .role-badge,
.dm-conversation-name .role-badge {
  flex: 0 0 auto;
}

.dm-search-result.is-requested {
  opacity: 0.76;
}

.dm-inbox-copy,
.dm-search-copy {
  min-width: 0;
  flex: 1;
}

.dm-inbox-topline {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.dm-inbox-topline strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-inbox-time {
  margin-left: auto;
  color: var(--muted-text);
  font-size: 11px;
  white-space: nowrap;
}

.dm-inbox-preview,
.dm-search-copy small {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--secondary-text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-inbox-count {
  min-width: 23px;
  height: 23px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 12px;
  font-weight: 850;
}

.dm-empty {
  margin: auto;
  padding: 40px 20px;
  color: var(--secondary-text);
  text-align: center;
}

.dm-search-row {
  display: flex;
  padding: 8px 18px 4px;
}

.dm-search-row input,
.dm-unlock-card input,
.dm-composer textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
}

.dm-search-row input,
.dm-unlock-card input {
  min-height: 46px;
  padding: 10px 15px;
  border-radius: 999px;
}

.dm-ready-label,
.dm-not-ready-label,
.dm-request-label {
  flex: 0 0 auto;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.dm-ready-label {
  border-color: color-mix(in srgb, #2b9b54 60%, var(--border));
  color: #2b9b54;
}

.dm-not-ready-label,
.dm-request-label {
  color: var(--secondary-text);
}

.dm-unlock-panel {
  min-height: 0;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.dm-unlock-card {
  width: min(440px, 100%);
  box-sizing: border-box;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--bubble);
  text-align: center;
}

.dm-unlock-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 70%, var(--border));
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.dm-unlock-icon svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dm-unlock-card h3 { margin: 0; }
.dm-unlock-card p {
  margin: 8px 0 16px;
  color: var(--secondary-text);
  line-height: 1.45;
}

.dm-unlock-card button {
  width: 100%;
  margin-top: 10px;
}

.dm-conversation-profile-button {
  min-width: 0;
  flex: 1;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 18px !important;
  display: flex !important;
  align-items: center;
  gap: 11px;
  background: transparent !important;
  color: var(--text) !important;
  text-align: left;
  box-shadow: none !important;
}

.dm-conversation-profile-button:hover {
  background: color-mix(in srgb, var(--button) 55%, transparent) !important;
}

.dm-conversation-person-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.dm-conversation-name,
.dm-conversation-handle {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-conversation-name {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 18px;
  font-weight: 850;
  line-height: 1.15;
}

.dm-conversation-handle {
  margin-top: 3px;
  color: var(--secondary-text);
  font-size: 12px;
}

.dm-message-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 14px 18px 7px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}

.dm-message-row {
  max-width: min(82%, 560px);
  display: flex;
  flex-direction: column;
}

.dm-message-row.own {
  align-self: flex-end;
  align-items: flex-end;
}

.dm-message-row.incoming {
  align-self: flex-start;
  align-items: flex-start;
}

.dm-message-bubble {
  max-width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 28px;
  display: flex;
  align-items: center;
  background: var(--button);
  color: var(--text);
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dm-message-bubble.is-single-line {
  border-radius: 999px;
  white-space: pre;
}

.dm-message-bubble.is-multi-line {
  border-radius: 28px;
  align-items: flex-start;
}

.dm-message-row.own .dm-message-bubble {
  border-color: color-mix(in srgb, var(--primary) 65%, var(--border));
  background: color-mix(in srgb, var(--primary) 24%, var(--button));
}

.dm-message-meta {
  margin: 3px 5px 0;
  color: var(--muted-text);
  font-size: 10px;
}

.dm-message-error .dm-message-bubble {
  border-style: dashed;
  color: var(--secondary-text);
}

.dm-typing-row {
  flex: 0 0 auto;
  align-self: flex-start;
  margin: 0 18px 5px;
}

.dm-typing-bubble {
  min-width: 54px;
  min-height: 42px;
  box-sizing: border-box;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--button);
}

.dm-typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--secondary-text);
  opacity: 0.22;
  animation: dmTypingDot 1.15s ease-in-out infinite;
}

.dm-typing-bubble span:nth-child(2) { animation-delay: 0.16s; }
.dm-typing-bubble span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dmTypingDot {
  0%, 65%, 100% { opacity: 0.22; transform: translateY(0); }
  32% { opacity: 1; transform: translateY(-2px); }
}

.dm-composer {
  flex: 0 0 auto;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 14px 6px;
  border: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.dm-composer textarea {
  min-width: 0;
  flex: 1 1 auto;
  min-height: 48px !important;
  max-height: 132px;
  box-sizing: border-box;
  padding: 12px 16px !important;
  resize: none;
  line-height: 22px;
  overflow-y: auto;
  border-radius: 999px !important;
}

.dm-composer textarea.is-single-line {
  height: 48px !important;
  overflow-y: hidden;
  border-radius: 999px !important;
}

.dm-composer textarea.is-multi-line {
  border-radius: 27px !important;
}

.dm-modal .dm-send-button {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.dm-security-note {
  padding: 4px 16px max(10px, env(safe-area-inset-bottom));
  border: 0;
  color: var(--muted-text);
  font-size: 10px;
  text-align: center;
}

.profile-message-button {
  min-width: 110px;
}

@media (max-width: 640px) {
  .card.account-bar .account-buttons,
  #authenticatedAccountButtons {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .dm-overlay { padding: 0; }

  .dm-modal {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .dm-modal-header {
    min-height: 70px;
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  }

  .dm-inbox-header {
    align-items: flex-start;
  }

  .dm-inbox-actions {
    gap: 6px;
  }

  .dm-mark-all-read-button {
    padding-inline: 9px;
    font-size: 12px;
  }

  .dm-message-row { max-width: 88%; }
  .dm-lock-pill { display: none; }
  .dm-panel-header,
  .dm-conversation-header { padding-inline: 13px; }
  .dm-message-list { padding-inline: 12px; }
  .dm-typing-row { margin-inline: 12px; }
  .dm-composer { padding-inline: 10px; }
}

@media (max-width: 430px) {
  .card.account-bar .account-buttons,
  #authenticatedAccountButtons {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .dm-modal-title-wrap p,
  .dm-panel-header p { display: none; }

  .dm-new-button {
    min-height: 40px;
    padding-inline: 15px;
  }

  .dm-inbox-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .dm-inbox-actions button {
    min-width: 112px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dm-typing-bubble span { animation-duration: 1.8s; }
}


/* Messages polish v27 */
.dm-conversation-header {
  min-height: 72px;
  padding: 8px 12px;
}

.dm-conversation-profile-button {
  width: 100%;
  min-height: 56px;
  align-self: stretch;
  box-sizing: border-box;
  padding: 5px 10px !important;
  border-radius: 999px !important;
}

.dm-inbox-item {
  min-height: 72px;
}

.dm-inbox-profile-target,
.dm-search-profile-target {
  min-height: 30px;
  box-sizing: border-box;
  padding: 2px 3px;
  border-radius: 999px;
}

/* Profile is intentionally allowed to open above Messages without closing it. */
.profile-overlay:not(.hidden) {
  z-index: 1060;
}

/* Center Messages status, loading, success, and error text. */
.dm-modal .dm-status {
  width: calc(100% - 36px);
  margin: 8px auto 6px;
  box-sizing: border-box;
  align-self: center;
  text-align: center;
  text-wrap: balance;
}

@media (max-width: 540px) {
  .dm-modal .dm-status {
    width: calc(100% - 24px);
    margin-inline: auto;
  }
}

/* Messages row typography fix v31: keep the subtitle directly under the name. */
.dm-inbox-copy .dm-inbox-profile-target,
.dm-search-copy .dm-search-profile-target {
  min-height: 0;
  padding: 0;
  border-radius: 0;
  line-height: 1.1;
}

.dm-inbox-copy,
.dm-search-copy {
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
}

.dm-inbox-topline {
  line-height: 1.1;
}

.dm-inbox-preview,
.dm-search-copy small {
  margin-top: 1px;
  line-height: 1.15;
}

/* Messages subtitle position fix v35: nudge the second line slightly lower. */
.dm-inbox-copy,
.dm-search-copy {
  gap: 0 !important;
  line-height: 1 !important;
}

.dm-inbox-topline,
.dm-search-copy > .dm-search-profile-target {
  min-height: 0 !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1 !important;
}

.dm-inbox-topline strong,
.dm-search-copy > .dm-search-profile-target {
  line-height: 1 !important;
}

.dm-inbox-preview,
.dm-search-copy > small {
  margin-top: 1px !important;
  line-height: 1.08 !important;
  transform: none !important;
}

/* Messages profile click-target fix v34.
   Keep the profile hitbox wrapped tightly around the avatar/name instead of
   letting the name flex item stretch across the empty right side of the row. */
.dm-search-copy {
  align-items: flex-start;
}

.dm-search-copy > .dm-search-profile-target,
.dm-inbox-topline > .dm-inbox-profile-target {
  width: fit-content !important;
  max-width: 100%;
  flex: 0 1 auto;
  align-self: flex-start;
}



/* =========================================================
   MOBILE MESSAGES UI REFRESH (final v36)
   Make mobile Messages feel intentionally designed instead of a squished desktop.
   ========================================================= */
@media (max-width: 640px) {
  .dm-overlay {
    padding: 10px;
    align-items: center;
    justify-content: center;
  }

  .dm-modal {
    width: min(100vw - 10px, 460px);
    height: min(100dvh - 12px, 920px);
    max-height: min(100dvh - 12px, 920px);
    border-width: 1px;
    border-radius: 30px;
    overflow: hidden;
    box-shadow:
      inset 0 1px 0 var(--glass-highlight),
      inset 0 -1px 0 var(--glass-border-soft),
      0 22px 70px var(--glass-shadow-deep);
  }

  .dm-modal-header {
    min-height: 84px;
    padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  }

  .dm-modal-header-actions {
    gap: 8px;
    align-items: flex-start;
  }

  .dm-modal-title-wrap h2 {
    font-size: clamp(18px, 5vw, 24px);
  }

  .dm-modal-title-wrap p,
  .dm-panel-header p {
    display: block !important;
    max-width: none;
    font-size: 12.5px;
    line-height: 1.35;
  }

  .dm-main,
  .dm-panel {
    min-height: 0;
  }

  .dm-panel-header,
  .dm-conversation-header {
    padding: 12px 14px;
  }

  .dm-panel-header h3,
  .dm-conversation-name {
    font-size: 15.5px;
  }

  .dm-inbox-header {
    align-items: center;
  }

  .dm-inbox-actions {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
  }

  .dm-mark-all-read-button,
  .dm-new-button {
    min-height: 42px;
    padding-inline: 12px;
    font-size: 12.5px;
  }

  .dm-inbox-list,
  .dm-search-results {
    gap: 10px;
    padding: 14px;
  }

  .dm-inbox-item,
  .dm-search-result {
    min-height: 82px;
    padding: 11px 12px;
    border-radius: 22px;
  }

  .dm-search-row {
    padding: 0 14px 4px;
  }

  .dm-search-row input,
  .dm-unlock-card input {
    min-height: 52px;
    height: 52px;
    padding-inline: 16px;
    border-radius: 999px;
    font-size: 16px;
  }

  .dm-status {
    font-size: 13px;
  }

  .dm-unlock-panel {
    padding: 14px;
  }

  .dm-unlock-card {
    padding: 20px 18px;
    border-radius: 24px;
  }

  .dm-unlock-icon {
    width: 58px;
    height: 58px;
  }

  .dm-conversation-header {
    min-height: 78px;
    gap: 10px;
  }

  .dm-conversation-profile-button {
    min-height: 58px;
    padding: 7px 10px !important;
  }

  .dm-message-list {
    padding: 14px;
    gap: 10px;
  }

  .dm-message-row {
    max-width: 91%;
  }

  .dm-message-bubble {
    border-radius: 22px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.38;
  }

  .dm-typing-row {
    margin-inline: 14px;
  }

  .dm-composer {
    padding: 12px 14px max(12px, env(safe-area-inset-bottom));
    gap: 10px;
  }

  .dm-composer textarea {
    min-height: 52px;
    max-height: 130px;
    padding: 14px 16px;
    border-radius: 24px;
    font-size: 16px;
    line-height: 1.35;
  }

  .dm-modal .dm-send-button {
    min-width: 52px;
    width: 52px;
    min-height: 52px;
    height: 52px;
    border-radius: 18px;
  }

  .dm-security-note {
    padding: 5px 16px max(10px, env(safe-area-inset-bottom));
    font-size: 10.5px;
  }
}

@media (max-width: 430px) {
  .dm-overlay {
    padding: 7px;
  }

  .dm-modal {
    width: calc(100vw - 8px);
    height: calc(100dvh - 8px);
    max-height: calc(100dvh - 8px);
    border-radius: 26px;
  }

  .dm-modal-header {
    padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  }

  .dm-modal-title-wrap p,
  .dm-panel-header p {
    font-size: 12px;
  }

  .dm-panel-header,
  .dm-conversation-header,
  .dm-search-row,
  .dm-message-list,
  .dm-inbox-list,
  .dm-search-results,
  .dm-composer {
    padding-inline: 12px;
  }

  .dm-inbox-actions {
    flex-direction: row;
    align-items: center;
  }

  .dm-inbox-actions button {
    flex: 1 1 130px;
    min-width: 0;
  }
}



/* =========================================================
   MOBILE MESSAGES — COMPACT, CLEAN, DESKTOP-LIKE (v39)
   ========================================================= */
@media (max-width: 640px) {
  .dm-overlay {
    padding: 10px !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .dm-modal {
    width: min(420px, calc(100vw - 20px)) !important;
    height: auto !important;
    max-height: calc(100dvh - 20px) !important;
    border: 1px solid var(--border) !important;
    border-radius: 25px !important;
    overflow: hidden !important;
    box-shadow:
      inset 0 1px 0 var(--glass-highlight),
      0 20px 60px rgba(0, 0, 0, 0.38) !important;
  }

  /* Conversation needs the available height; inbox/search should stay compact. */
  .dm-modal:has(#dmConversationPanel:not(.hidden)) {
    height: calc(100dvh - 20px) !important;
  }

  .dm-modal:has(#dmUnlockPanel:not(.hidden)),
  .dm-modal:has(#dmInboxPanel:not(.hidden)),
  .dm-modal:has(#dmNewPanel:not(.hidden)) {
    height: auto !important;
  }

  .dm-modal-header {
    min-height: 66px !important;
    padding: 12px 13px 11px !important;
  }

  .dm-modal-title-wrap h2 {
    font-size: 21px !important;
    line-height: 1.08 !important;
  }

  .dm-modal-title-wrap p {
    display: block !important;
    margin-top: 3px !important;
    font-size: 11.5px !important;
    line-height: 1.25 !important;
  }

  .dm-modal .dm-close-button,
  .dm-modal .dm-back-button {
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    flex-basis: 38px !important;
  }

  .dm-modal .dm-close-button svg,
  .dm-modal .dm-back-button svg {
    width: 18px !important;
    height: 18px !important;
  }

  .dm-lock-pill {
    display: none !important;
  }

  .dm-panel,
  .dm-main {
    min-height: 0 !important;
  }

  /* Inbox: remove the pointless duplicate title/paragraph and use one tidy toolbar. */
  #dmInboxPanel {
    flex: 0 1 auto !important;
  }

  .dm-inbox-header {
    min-height: 54px !important;
    padding: 8px 12px !important;
    justify-content: flex-end !important;
    border-bottom: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
  }

  .dm-inbox-header .dm-panel-header-copy {
    display: none !important;
  }

  .dm-inbox-actions {
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
  }

  .dm-mark-all-read-button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 0 !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 10px !important;
    font-size: 11.5px !important;
    white-space: nowrap !important;
  }

  .dm-new-button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 122px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 15px !important;
    border-radius: 999px !important;
    font-size: 12.5px !important;
    white-space: nowrap !important;
  }

  .dm-modal .dm-status {
    width: calc(100% - 24px) !important;
    margin: 7px auto 3px !important;
    font-size: 12px !important;
    line-height: 1.3 !important;
  }

  .dm-inbox-list,
  .dm-search-results {
    flex: 0 1 auto !important;
    max-height: min(390px, calc(100dvh - 185px)) !important;
    padding: 7px 11px 12px !important;
    gap: 0 !important;
  }

  .dm-inbox-item,
  .dm-search-result {
    min-height: 66px !important;
    margin: 6px 0 !important;
    padding: 8px 10px !important;
    gap: 10px !important;
    border-radius: 21px !important;
  }

  .dm-inbox-item .avatar,
  .dm-search-result .avatar,
  .dm-inbox-item [class*="avatar"],
  .dm-search-result [class*="avatar"] {
    flex-shrink: 0 !important;
  }

  .dm-inbox-topline strong,
  .dm-search-profile-target {
    font-size: 14px !important;
  }

  .dm-inbox-preview,
  .dm-search-copy > small {
    margin-top: 3px !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
  }

  .dm-inbox-time {
    font-size: 10px !important;
  }

  /* New-message screen. */
  #dmNewPanel {
    flex: 0 1 auto !important;
  }

  #dmNewPanel > .dm-panel-header {
    min-height: 68px !important;
    padding: 10px 12px !important;
    gap: 10px !important;
  }

  #dmNewPanel .dm-panel-header-copy h3 {
    font-size: 16px !important;
    line-height: 1.15 !important;
  }

  #dmNewPanel .dm-panel-header-copy p {
    display: block !important;
    margin-top: 3px !important;
    font-size: 11px !important;
    line-height: 1.25 !important;
  }

  .dm-search-row {
    padding: 8px 12px 2px !important;
  }

  .dm-search-row input,
  .dm-unlock-card input {
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 14px !important;
    border-radius: 999px !important;
    font-size: 15px !important;
  }

  .dm-ready-label,
  .dm-not-ready-label,
  .dm-request-label {
    padding: 5px 8px !important;
    font-size: 10px !important;
  }

  /* Unlock card stays small and intentional. */
  .dm-unlock-panel {
    flex: 0 1 auto !important;
    padding: 16px !important;
  }

  .dm-unlock-card {
    width: 100% !important;
    max-width: 340px !important;
    padding: 18px !important;
    border-radius: 22px !important;
  }

  .dm-unlock-icon {
    width: 50px !important;
    height: 50px !important;
  }

  /* Conversation screen: compact header, generous chat area, normal composer. */
  #dmConversationPanel {
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  .dm-conversation-header {
    min-height: 62px !important;
    padding: 8px 11px !important;
    gap: 8px !important;
  }

  .dm-conversation-profile-button {
    min-height: 48px !important;
    padding: 4px 7px !important;
    gap: 8px !important;
  }

  .dm-conversation-name {
    font-size: 15px !important;
  }

  .dm-conversation-handle {
    margin-top: 2px !important;
    font-size: 10.5px !important;
  }

  .dm-message-list {
    min-height: 0 !important;
    flex: 1 1 auto !important;
    padding: 10px 12px 6px !important;
    gap: 7px !important;
  }

  .dm-message-row {
    max-width: 84% !important;
  }

  .dm-message-bubble,
  .dm-message-bubble.is-single-line,
  .dm-message-bubble.is-multi-line {
    min-height: 36px !important;
    padding: 8px 12px !important;
    border-radius: 18px !important;
    font-size: 13.5px !important;
    line-height: 1.32 !important;
  }

  .dm-message-bubble.is-single-line {
    border-radius: 999px !important;
  }

  .dm-message-meta {
    margin-top: 2px !important;
    font-size: 9.5px !important;
  }

  .dm-typing-row {
    margin: 0 12px 4px !important;
  }

  .dm-composer {
    padding: 8px 10px 6px !important;
    gap: 8px !important;
  }

  .dm-composer textarea,
  .dm-composer textarea.is-single-line {
    height: 44px !important;
    min-height: 44px !important;
    padding: 10px 14px !important;
    border-radius: 999px !important;
    font-size: 15px !important;
    line-height: 22px !important;
  }

  .dm-composer textarea.is-multi-line {
    min-height: 44px !important;
    max-height: 112px !important;
    border-radius: 22px !important;
  }

  .dm-modal .dm-send-button {
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    flex-basis: 44px !important;
  }

  .dm-modal .dm-send-button svg {
    width: 19px !important;
    height: 19px !important;
  }

  .dm-security-note {
    padding: 3px 12px max(7px, env(safe-area-inset-bottom)) !important;
    font-size: 8.5px !important;
    line-height: 1.25 !important;
  }
}

@media (max-width: 370px) {
  .dm-overlay {
    padding: 6px !important;
  }

  .dm-modal {
    width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    border-radius: 22px !important;
  }

  .dm-modal:has(#dmConversationPanel:not(.hidden)) {
    height: calc(100dvh - 12px) !important;
  }

  .dm-mark-all-read-button {
    padding-inline: 7px !important;
    font-size: 10.5px !important;
  }

  .dm-new-button {
    min-width: 108px !important;
    padding-inline: 12px !important;
  }
}



/* =========================================================
   MESSAGE EDIT + DELETE — v45
   ========================================================= */
.dm-message-row {
  position: relative;
}

.dm-message-row.is-editing .dm-message-bubble,
.dm-message-row.is-editing .dm-message-footer {
  display: none;
}

.dm-message-editor {
  width: min(430px, 72vw);
  padding: 9px;
  display: grid;
  gap: 8px;
  background: var(--glass-control);
  border: 1px solid color-mix(in srgb, var(--primary) 48%, var(--border));
  border-radius: 22px;
  box-shadow: inset 0 1px 0 var(--glass-highlight), 0 10px 28px var(--shadow);
}

.dm-message-editor.hidden {
  display: none;
}

.dm-message-row.is-editing .dm-message-editor {
  display: grid;
}

.dm-message-editor textarea {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  margin: 0;
  padding: 11px 13px;
  resize: none;
  border-radius: 17px;
  line-height: 1.35;
}

.dm-message-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.dm-message-editor-actions button {
  min-width: 76px;
  height: 36px;
  min-height: 36px;
  padding-inline: 13px;
  border-radius: 999px;
  font-size: 12px;
}

.dm-message-footer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 2px;
}

.dm-message-footer .dm-message-meta {
  margin: 0 2px 0 5px;
}

.dm-message-more {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted-text);
  box-shadow: none;
  opacity: 0.56;
}

.dm-message-more:hover,
.dm-message-more:focus-visible,
.dm-message-row.message-menu-open .dm-message-more {
  background: var(--button-hover);
  color: var(--text);
  opacity: 1;
  transform: none;
}

.dm-message-more svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.dm-message-menu {
  position: absolute;
  z-index: 20;
  right: 0;
  bottom: 28px;
  width: 132px;
  padding: 6px;
  display: none;
  gap: 4px;
  background: var(--glass-card-strong);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: 0 16px 42px var(--glass-shadow-deep), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.dm-message-row.message-menu-open .dm-message-menu {
  display: grid;
  animation: dmMessageMenuIn 150ms ease both;
}

@keyframes dmMessageMenuIn {
  from { opacity: 0; transform: translateY(5px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dm-message-menu button {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font-size: 12px;
  text-align: left;
}

.dm-message-menu button:hover,
.dm-message-menu button:focus-visible {
  background: var(--button-hover);
  transform: none;
}

.dm-message-menu button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dm-message-menu .dm-message-delete-option {
  color: #d84242;
}

.dm-delete-message-overlay {
  z-index: 1210;
}

.dm-delete-message-modal {
  width: min(430px, calc(100vw - 28px));
  padding: 25px;
  text-align: center;
  border-radius: 28px;
}

.dm-delete-message-modal h2 {
  margin: 0 0 8px;
}

.dm-delete-message-modal > p {
  margin: 0;
  color: var(--secondary-text);
}

.dm-delete-message-preview {
  max-height: 92px;
  margin: 15px 0 0 !important;
  padding: 12px 14px;
  overflow: auto;
  background: var(--glass-control);
  color: var(--text) !important;
  border: 1px solid var(--glass-border);
  border-radius: 17px;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dm-delete-message-buttons {
  margin-top: 17px;
}

.dm-danger-button {
  background: #d84242 !important;
  border-color: #d84242 !important;
  color: #fff !important;
}

@media (max-width: 640px) {
  .dm-message-more {
    width: 27px;
    min-width: 27px;
    height: 27px;
    min-height: 27px;
    opacity: .78;
  }

  .dm-message-menu {
    width: 138px;
    bottom: 31px;
  }

  .dm-message-menu button {
    min-height: 40px;
    font-size: 13px;
  }

  .dm-message-editor {
    width: min(76vw, 390px);
  }

  .dm-delete-message-modal {
    width: calc(100vw - 22px);
    padding: 22px 16px 17px;
    border-radius: 25px;
  }
}
