/* Direct messages. Two ridge-bordered panels like Identity's dashboard: conversations on the left
   as plain rows with underlined names, the open conversation on the right. Messages are plain
   square boxes. Greyscale; Southbag blue only marks your own messages and unread conversations.
   Buttons, inputs and fonts come from southbag.css and are not restyled here.
   Everything is scoped under .dm (and .dm-picker for the "New message" dialog). */

.dm { display: flex; flex-direction: column; min-width: 0; box-shadow: none; }
.dm-page-head { margin-bottom: 10px; }
.dm-panes {
  display: grid; grid-template-columns: minmax(220px, 320px) minmax(0, 1fr); gap: 1rem; align-items: stretch;
  height: calc(100dvh - var(--dm-top, 240px) - 20px); min-height: 480px; box-shadow: none;
}
.dm-list, .dm-chat {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border: 2px ridge var(--sb-ridge); background: var(--sb-panel);
}
.dm-pad { padding: 10px 12px; box-shadow: none; }
.dm .center { text-align: center; }

/* Wrappers that only arrange things don't get the halo. */
.dm-list-scroll, .dm-item-main, .dm-item-top, .dm-conv, .dm-scroll-wrap, .dm-scroll, .dm-msgs, .dm-row, .dm-col,
.dm-line, .dm-av, .dm-item-excerpt, .dm-head-text, .dm-head-actions, .dm-older, .dm-sentinel, .dm-composer-row, .dm-input-wrap,
.dm-placeholder, .dm-empty, .dm-status, .dm-seen, .dm-day, .dm-note, .dm-items, .dm-item, .dm-attachment .grow,
.dm-picker .row, .dm-chips, .dm-results, .dm-result, .dm-result .grow, .dm-page-head { box-shadow: none; }

/* -- Conversation list -- */
.dm-list-head { padding: 0.75rem 0.75rem 0.4rem; border-bottom: 2px dashed #000; box-shadow: none; }
.dm-list-head h2 { margin: 0; font-size: 1.4rem; }
.dm-list-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.dm-items { list-style: none; margin: 0; padding: 0 0.75rem; }
.dm-items.pinned { border-bottom: 2px dashed #000; }
.dm-item { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; }
.dm-item + .dm-item { border-top: 1px dashed #999; }
.dm-item.active { background: #e4e2db; margin: 0 -0.75rem; padding: 9px 0.75rem; }
.dm-item-main { flex: 1; min-width: 0; }
.dm-item-top { display: flex; align-items: baseline; gap: 6px; }
.dm-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--sb-ink); }
.dm-item.active .dm-item-name { font-weight: 700; }
.dm-item.unread .dm-item-name { font-weight: 700; }
.dm-unread { font-size: 0.75rem; font-weight: 700; color: var(--sb-blue); flex-shrink: 0; }
.dm-item-time, .dm-pin { font-size: 0.75rem; color: var(--sb-muted); flex-shrink: 0; }
.dm-item-excerpt { font-size: 0.85rem; color: var(--sb-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-item.unread .dm-item-excerpt { color: var(--sb-ink); }
.dm-support-av { background: #fff; }
.dm-support-av img { width: 100%; height: 100%; display: block; }

/* -- Conversation pane -- */
.dm-conv { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.dm-placeholder { flex: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 24px; }
.dm-placeholder p { color: var(--sb-muted); margin: 0 0 14px; }

.dm-head {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0; min-height: 64px;
  padding: 0.75rem; border-bottom: 2px dashed #000; box-shadow: none;
}
.dm-head-text { flex: 1; min-width: 0; }
.dm-title { margin: 0; font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-title a { color: var(--sb-ink); }
.dm-head-sub { font-size: 0.8rem; color: var(--sb-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: none; }
.dm-head-loading { color: var(--sb-muted); }
.dm-head-actions { display: flex; gap: 6px; flex-shrink: 0; }
.dm-back { display: none; flex-shrink: 0; }

.dm-scroll-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.dm-scroll { flex: 1; overflow-y: auto; padding: 10px 14px 8px; overscroll-behavior: contain; }
.dm-scroll:focus-visible { outline-offset: -3px; }
.dm-sentinel { height: 1px; }
.dm-older { text-align: center; font-size: 0.78rem; color: var(--sb-muted); }
.dm-older p { margin: 4px 0 8px; }
.dm-older .loading { padding: 8px; }
.dm-msgs { display: flex; flex-direction: column; }

.dm-day { display: flex; align-items: center; gap: 10px; margin: 16px 0 6px; color: var(--sb-muted); font-size: 0.78rem; }
.dm-day::before, .dm-day::after { content: ''; flex: 1; border-top: 2px dashed #000; }
.dm-note { align-self: center; max-width: 85%; text-align: center; font-size: 0.82rem; color: var(--sb-muted); margin: 8px 0; font-style: italic; }

.dm-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 4px; max-width: 100%; }
.dm-row.first { margin-top: 12px; }
.dm-row.mine { justify-content: flex-end; }
.dm-av { width: 32px; flex-shrink: 0; }
.dm-row:not(.last) .dm-av { visibility: hidden; }
.dm-col { display: flex; flex-direction: column; min-width: 0; max-width: min(80%, 560px); }
.dm-row.mine .dm-col { align-items: flex-end; }
.dm-name { font-size: 0.78rem; color: var(--sb-muted); margin: 0 0 2px; box-shadow: none; }
.dm-row:not(.first) .dm-name { display: none; }
.dm-line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.dm-row.mine .dm-line { flex-direction: row-reverse; }
.dm-bubble {
  padding: 6px 10px; min-width: 0; max-width: 100%; border-radius: 0;
  overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.4;
}
.dm-row.theirs .dm-bubble { background: #fff; border: 1px solid #111; color: #111; }
.dm-row.mine .dm-bubble { background: #e4e2db; border: 1px solid #aaa89f; border-left: 4px solid var(--sb-blue); color: #111; }
:root[data-theme='dark'] .dm-row.theirs .dm-bubble { background: #151513; border-color: #777; color: var(--sb-ink); }
:root[data-theme='dark'] .dm-row.mine .dm-bubble { background: #33332f; border-color: #555; border-left-color: var(--sb-blue); color: var(--sb-ink); }
.dm-text a { color: var(--sb-blue); }
.dm-row.pending .dm-bubble { opacity: 0.6; }
.dm-row.failed .dm-bubble { border-style: dashed; border-left-style: dashed; }
.dm-bubble.media-only { padding: 4px; }
.dm-bubble > * + * { margin-top: 6px; }
.dm-bubble > .sr-only + * { margin-top: 0; }
.dm-text { box-shadow: none; }
.dm-time { font-size: 0.72rem; color: var(--sb-muted); white-space: nowrap; padding-bottom: 1px; }
.dm-status { font-size: 0.78rem; color: var(--sb-muted); margin: 4px 0 0; }
.dm-seen { align-self: flex-end; font-size: 0.75rem; color: var(--sb-muted); margin: 3px 0 0; }
.dm-typing em { color: var(--sb-muted); }

/* Photos and videos sit in a box of a fixed shape and are stretched to fill it. */
.dm-img { display: block; width: max-content; max-width: 100%; border: 1px solid #111; background: #000; cursor: zoom-in; }
.dm-img:hover { background: #000; }
.dm-img img { display: block; width: 240px; max-width: 100%; height: 180px; }
.dm-video { background: #000; border: 1px solid #111; }
.dm-video video { display: block; width: 320px; max-width: 100%; height: 180px; }
.dm-bubble audio { max-width: 260px; }

.dm-post {
  display: flex; flex-direction: column; gap: 4px; width: min(280px, 100%); padding: 8px 10px;
  border: 2px inset var(--sb-bevel); background: var(--sb-paper); color: var(--sb-ink);
  text-decoration: none; white-space: normal; font-size: 0.9rem;
}
a.dm-post:hover { font-weight: inherit; background: var(--sb-paper); }
.dm-post > span { box-shadow: none; }
.dm-post-head { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.dm-post-head strong, .dm-post-head .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-post-head .muted { font-size: 0.8rem; }
.dm-post-title { font-weight: 700; }
.dm-post-body { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.dm-post-thumb { position: relative; display: block; width: 100%; height: 150px; background: #000; }
.dm-post-thumb img { width: 100%; height: 100%; display: block; }
.dm-post-play { position: absolute; left: 4px; bottom: 4px; background: #fff; color: #000; font-size: 0.75rem; padding: 0 4px; }
.dm-post-foot { text-decoration: underline; font-size: 0.85rem; }
.dm-post.unavailable { color: var(--sb-muted); font-style: italic; }

.dm-empty { text-align: center; color: var(--sb-muted); margin: auto; padding: 40px 16px; }
.dm-empty p { margin: 4px 0; }

.dm-jump { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); }

/* -- Composer -- */
.dm-composer { flex-shrink: 0; padding: 0.6rem 0.75rem 0.75rem; border-top: 2px dashed #000; box-shadow: none; }
.dm-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.dm-input-wrap { flex: 1; min-width: 0; position: relative; }
.dm-input { resize: none; min-height: 2.6rem; max-height: 160px; line-height: 1.4; }
.dm-input:disabled { opacity: 0.6; }
.dm-counter { position: absolute; right: 6px; bottom: -16px; font-size: 0.7rem; color: var(--sb-muted); box-shadow: none; }
.dm-counter.over { color: var(--sb-ink); font-weight: 700; text-decoration: underline; }
.dm-attach, .dm-send { flex-shrink: 0; }
.dm-composer-note { font-size: 0.85rem; color: var(--sb-muted); margin-bottom: 8px; box-shadow: none; }
.dm-attachment { display: flex; align-items: center; gap: 10px; padding: 6px; margin-bottom: 8px; border: 2px inset var(--sb-bevel); background: var(--sb-paper); }
.dm-attachment-thumb { width: 80px; height: 60px; background: #000; flex-shrink: 0; }
.dm-attachment-thumb img, .dm-attachment-thumb video { width: 100%; height: 100%; display: block; }
.dm-attachment-name { font-size: 0.85rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: none; }
.dm-attachment .fine { margin: 0; box-shadow: none; }
.dm-progress { margin-top: 4px; }

/* -- "New message" dialog -- */
.dm-picker { width: 100%; min-width: 0; box-shadow: none; }
.dm-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 4px 0; }
.dm-chips:empty { display: none; }
.dm-chips-to { font-weight: 700; }
.dm-chip { display: inline-flex; align-items: center; gap: 6px; box-shadow: none; }
.dm-results { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; margin-top: 8px; }
.dm-results .eyebrow { margin: 0 0 4px; }
.dm-result { display: flex; align-items: center; gap: 8px; padding: 6px 2px; }
.dm-result + .dm-result { border-top: 1px dashed #999; }
.dm-result.on .dm-result-name { font-weight: 700; }
.dm-result .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-result-handle { font-size: 0.85rem; color: var(--sb-muted); }

/* -- Phones: the list OR the conversation, which takes the whole screen -- */
@media (max-width: 900px) {
  .dm-panes { grid-template-columns: minmax(180px, 240px) minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .dm { padding: 10px; }
  .dm-panes { display: block; height: auto; min-height: 0; }
  .dm-list { padding-bottom: 24px; }
  .dm-list-scroll { overflow: visible; }
  .dm-chat { display: none; }
  .dm.open .dm-list { display: none; }
  .dm.open .dm-chat {
    display: flex; position: fixed; left: 0; right: 0; top: var(--dm-vvt, 0px); height: var(--dm-vvh, 100dvh); z-index: 70;
    background: var(--sb-bg);
  }
  .dm-back { display: inline-block; }
  .dm-head { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; min-height: 0; }
  .dm-title { font-size: 1.2rem; }
  .dm-scroll { padding: 8px 10px 6px; }
  .dm-col { max-width: 86%; }
  .dm-composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  html.dm-lock, html.dm-lock body { overflow: hidden; }
}
