/* Direct messages modal — conversation list + thread pane */

.dm-modal-card {
  width: min(920px, 96vw);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
}

.dm-modal-card .dialog-header {
  flex-shrink: 0;
}

.dm-layout {
  display: grid;
  grid-template-columns: minmax(220px, 34%) 1fr;
  gap: 0;
  min-height: 420px;
  max-height: calc(88vh - 120px);
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  border-radius: 10px;
  overflow: hidden;
}

.dm-thread-list-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  background: var(--surface-muted, rgba(0, 0, 0, 0.02));
  min-height: 0;
}

.dm-thread-list-heading {
  padding: 0.65rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #666);
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
}

.dm-thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.dm-thread-list__empty {
  padding: 1rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-muted, #666);
}

.dm-thread-list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  background: transparent;
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.dm-thread-list-item:hover {
  background: var(--surface-hover, rgba(0, 0, 0, 0.04));
}

.dm-thread-list-item.is-active {
  background: var(--surface-active, rgba(59, 130, 246, 0.1));
}

.dm-thread-list-item__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.dm-thread-list-item__name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-thread-list-item__time {
  font-size: 0.72rem;
  color: var(--text-muted, #666);
  flex-shrink: 0;
}

.dm-thread-list-item__preview {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted, #666);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-thread-list-item__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  vertical-align: middle;
}

.dm-thread-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface, #fff);
}

.dm-thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  color: var(--text-muted, #666);
  font-size: 0.95rem;
}

.dm-thread-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  font-weight: 600;
}

.dm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.45rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 0;
}

.dm-message {
  max-width: 82%;
  padding: 0.22rem 0.48rem 0.18rem;
  border-radius: 10px;
  font-size: 0.875rem;
  line-height: 1.32;
  white-space: pre-wrap;
  word-break: break-word;
}

.dm-message--mine {
  align-self: flex-end;
  background: var(--accent-soft, rgba(37, 99, 235, 0.12));
  border-bottom-right-radius: 3px;
}

.dm-message--theirs {
  align-self: flex-start;
  background: var(--surface-muted, rgba(0, 0, 0, 0.05));
  border-bottom-left-radius: 3px;
}

.dm-message__body {
  margin: 0;
}

.dm-message__meta {
  margin-top: 0.08rem;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--text-muted, #666);
}

.dm-compose {
  border-top: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  padding: 0.5rem 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dm-compose textarea {
  width: 100%;
  min-height: 52px;
  max-height: 120px;
  resize: vertical;
  font: inherit;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.15));
  box-sizing: border-box;
  line-height: 1.35;
}

.dm-compose__actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
}

.dm-image-attach {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dm-image-attach__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.dm-image-attach__choose,
.dm-image-attach__clear {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
}

.dm-image-attach__name {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
  max-width: min(200px, 55vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-image-attach__preview-img {
  display: block;
  max-width: 100%;
  max-height: 140px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.12));
}

.dm-message__photo-shell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: min(100%, 280px);
  height: 220px;
  max-width: min(100%, 280px);
  max-height: 220px;
  margin-bottom: 0.2rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.1));
  vertical-align: top;
  isolation: isolate;
}

.dm-message__photo-shell--blur {
  cursor: pointer;
}

.dm-message__photo-shell--blur:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

.dm-message__photo-shell--broken {
  display: none;
}

.dm-message__photo {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  object-fit: contain;
  object-position: center;
}

/* Unblurred attachments (no shell) — same restrictive frame */
.dm-message > .dm-message__photo--zoomable {
  width: min(100%, 280px);
  height: 220px;
  max-width: min(100%, 280px);
  max-height: 220px;
}

.dm-message__photo--broken {
  display: none;
}

/* Wrapper + scale keeps blur visible inside glass/backdrop-filter modals */
.dm-message__photo-shell--blur .dm-message__photo {
  filter: blur(22px);
  transform: scale(1.12);
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.dm-message__photo-cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(15, 23, 42, 0.42);
  pointer-events: none;
}

.dm-message__photo-shell--revealed .dm-message__photo-cover {
  display: none;
}

.dm-message__photo-shell--revealed .dm-message__photo {
  filter: none;
  transform: none;
  pointer-events: auto;
}

.dm-message__photo--zoomable,
.dm-message__photo-shell--revealed {
  cursor: zoom-in;
}

/* Max canvas — full-viewport image when a message photo is clicked */
.dm-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100160;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  padding: var(--bb-chrome-top, 152px) 12px 12px;
  box-sizing: border-box;
  background: rgba(8, 12, 20, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.dm-image-lightbox.hidden {
  display: none !important;
}

.dm-image-lightbox__toolbar {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  padding-bottom: 8px;
}

.dm-image-lightbox__stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  cursor: zoom-out;
}

.dm-image-lightbox__img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  cursor: default;
}

body.dm-image-lightbox-open {
  overflow: hidden;
}

.dm-message__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.15rem;
}

.dm-message__action {
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
}

.dm-thread-header__badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent, #2563eb);
  margin-left: 0.35rem;
}

.dm-thread-header__notice {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--danger, #b91c1c);
}

.dm-thread-header__unblock {
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  margin-left: 0.35rem;
}

.dm-safety-row {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
}

.dm-safety-row__blur {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.dm-compose--disabled {
  opacity: 0.55;
  pointer-events: none;
}

.dm-modal-status {
  margin: 0.5rem 0 0;
  min-height: 1.25rem;
  font-size: 0.85rem;
}

.dm-modal-status.is-error {
  color: var(--danger, #b91c1c);
}

/* Full canvas — near viewport height for reading long threads */
#dmModal.dm-modal--full-canvas {
  align-items: stretch;
  padding: var(--bb-chrome-top, 152px) 12px 12px;
}

#dmModal.dm-modal--full-canvas > .dm-modal-card {
  width: 100%;
  max-width: 100%;
  height: calc(100vh - var(--bb-chrome-top, 152px) - 24px);
  max-height: none;
  margin: 0;
  overflow: hidden;
}

#dmModal.dm-modal--full-canvas .dm-layout {
  flex: 1;
  min-height: 0;
  max-height: none;
}

#dmModal.dm-modal--full-canvas .dm-compose textarea {
  max-height: min(28vh, 200px);
}

.dm-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: middle;
}

.pf-member-profile__actions {
  margin-top: 0.75rem;
}

@media (max-width: 720px) {
  .dm-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .dm-thread-list-panel {
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  }
}

html[data-theme="dark"] .dm-message--theirs,
html[data-theme="soft"] .dm-message--theirs {
  background: rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .dm-thread-list-panel,
html[data-theme="soft"] .dm-thread-list-panel {
  background: rgba(255, 255, 255, 0.03);
}

/* Mode-bar DM icon when signed in (top nav / footer FAB intentionally omitted). */
html[data-bizbarrel-signed-in="true"] #btnOpenDmModeBar {
  display: inline-flex !important;
}

#bizbarrelDmFab,
#btnOpenDmHeader,
#btnOpenDmModal {
  display: none !important;
}
