/* =====================================================================
   Direct Messages: Active Conversation Thread & Bubbles
   ===================================================================== */

/* =====================================================================
   Utilities (declared first, but !important so component display
   rules like `.media-item img { display:block }` can't override them)
   ===================================================================== */

.hidden { display: none !important; }

/* =====================================================================
   Layout Containers
   ===================================================================== */
   
dm-messages-module {
  display: block;
  width: 100%;
  height: 100%;
  background-color: var(--page-outer-bg, #0b0f19); /* Outer backdrop color */
}


#dm-messages-component.dm-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 720px;                              
  margin: 0 auto;                                 
  position: relative;
  overflow: hidden;
  background-color: var(--theme-bg, #ffffff);     
  border-left: 1px solid var(--border-subtle, #edebe6);
  border-right: 1px solid var(--border-subtle, #edebe6);
}

panel-header {
  flex: 0 0 52px;
}

dm-message-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
}

dm-message-list {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
  padding: 16px;
  flex: 0 0 auto;
  margin-top: auto;                             /* Pushes list to bottom */
}

/* =====================================================================
   Read Markers & Status Area
   ===================================================================== */

dm-read-marker {
  display: block;
  font-size: 11px;
  color: var(--text-muted, #656f77);
  text-align: right;
  margin-top: 2px;
  margin-right: 6px;
  animation: fadeIn 0.25s ease;
}

dm-read-marker.avatar-style {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-size: cover;
  float: right;
}

dm-status-area {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  min-height: 18px;
  padding: 0 12px;
}

message-container.is-last-sent dm-status-area {
  display: flex;
}

/* Participant Avatar Mini-Markers */
dm-user-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  border: 1.5px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  cursor: help;
}

dm-user-marker + dm-user-marker {
  margin-left: -6px;
}

dm-user-marker:hover {
  transform: scale(1.35);
  z-index: 10;
  position: relative;
}

/* =====================================================================
   Message Containers & Rows
   ===================================================================== */

message-container {
  display: flex;
  position: relative;
  flex-direction: column;
  margin-bottom: 14px;
  padding: 4px 8px;
  background-color: transparent;
  transition: background-color 0.2s ease;
  animation: fadeIn 0.25s ease;
}

message-container.is-highlighted {
  background-color: rgba(79, 70, 229, 0.08);
  border-radius: 12px;
}

message-container.is-deleting {
  animation: fadeOut 0.25s ease forwards;
  background-color: rgba(239, 68, 68, 0.15);
}

message-time {
  align-self: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted, #656f77);
  margin-bottom: 6px;
}

message {
  display: flex;
  margin-top: 4px;
}

message-container.owner message {
  flex-direction: row-reverse;
}

message-photo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  margin-right: 10px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle, #edebe6);
  transform: translateY(4px);
}

message-container.owner message-photo {
  display: none;
}

message-details {
  position: relative;
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

message-container.owner message-details {
  align-items: flex-end;
}

message-container.owner dm-status-area {
  justify-content: flex-end;
}

message-nickname {
  padding: 1px 12px;
  background-color: transparent;
  color: var(--text-muted, #656f77);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 2px;
}

/* =====================================================================
   Message Bubbles (Text & Media)
   ===================================================================== */

message-bubble {
  position: relative;
  padding: 4px 6px;
  border-radius: 18px;
  max-width: 72%;
}

message-bubble:not(:has(dm-reaction-list:not(.hidden))) {
  padding-bottom: 6px;
}

message-bubble.no-reactions {
  padding-bottom: 6px;
}

/* Incoming Visitor Bubble */
message-text {
  padding: 10px 16px;
  border-radius: 18px;
  background-color: #f2f0eb;                   /* Warm paper tone */
  color: var(--text-main, #16181b);
  font-size: 0.95rem;
  line-height: 1.45;
  word-wrap: break-word;
  max-width: 100%;
  cursor: pointer;
}

message-text a.yt-link {
  color: inherit;
  text-decoration: underline;
}

/* Outgoing Owner Bubble */
message-container.owner message-text {
  background-color: var(--accent, #4f46e5);     /* Signature indigo */
  color: #ffffff;
}

/* Legacy single image attachment */
message-image img.picture {
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  margin-bottom: 4px;
  cursor: pointer;
  border: 1px solid var(--border-subtle, #edebe6);
}

/* Connected Media Corners (only when the text bubble is actually shown) */
message-text.has-media {
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}

.media-stack:has(+ message-text:not(.hidden)) {
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  margin-bottom: 0;
}

/* =====================================================================
   Reply Quote (inside a bubble)
   ===================================================================== */

reply-quote {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 100%;
  padding: 4px 8px;
  margin-bottom: 4px;
  border-left: 3px solid var(--accent, #4f46e5);
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

reply-info {
  margin-bottom: 5px;
  color: var(--text-muted, #656f77);
}

reply-icon {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 5px;
  vertical-align: middle;
  background-image: url(/images/reply.gif);
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.7;
}

reply-content {
  min-width: 70px;
  margin: 0;
  padding: 5px 12px;
  border-radius: 30px;
  background-color: #f2f0eb;
  color: var(--dm-reply-text, var(--text-muted, #656f77));
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-media-item {
  width: 40%;
  margin-right: 8px;
  margin-bottom: 5px;
  border-radius: 12px;
}

.reply-media-preview {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  margin-right: 8px;
  border-radius: 8px;
  background: #f7f6f2;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reply-media-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reply-media-preview span {
  font-size: 18px;
}

.mini-play-hint {
  position: absolute;
  width: 16px;
  height: 16px;
  padding-left: 1px;
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.45);
  color: #ffffff;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =====================================================================
   Reactions & Emoji Stacks
   ===================================================================== */

dm-reaction-list {
  position: absolute;
  bottom: -10px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border-subtle, #edebe6);
  border-radius: 16px;
  padding: 2px 8px;
  gap: 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  z-index: 10;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.emoji-stack {
  display: flex;
  align-items: center;
}

.emoji-stack span {
  display: inline-block;
  margin-right: -2px;
  font-size: 13px;
  line-height: 1;
  transform-origin: center;
}

.emoji-stack span:first-child {
  animation: emojiPop 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes emojiPop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.total-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted, #656f77);
  display: inline-block;
  line-height: 1;
}

/* Includes Current User State */
dm-reaction-list.includes-me {
  background: #d7d7d7;
  border-color: rgba(79, 70, 229, 0.3);
}

dm-reaction-list.includes-me .total-count {
  color: var(--accent, #4f46e5);
}

/* Quick-React Hover Trigger (+) */
message-container .quick-react-trigger {
  display: none;
  position: absolute;
  top: 50%;
  background: none;
  border: none;
  cursor: pointer;
  width: 30px;
  height: 30px;
  color: var(--text-muted, #8e98a0);
  font-size: 16px;
  z-index: 5;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, transform 0.15s ease;
}

message-container:not(.owner) .quick-react-trigger {
  left: calc(100% + 8px);
  transform: translateY(-50%);
}

message-container.owner .quick-react-trigger {
  right: calc(100% + 8px);
  transform: translateY(-50%);
}

message-container:hover .quick-react-trigger {
  display: flex;
}

.quick-react-trigger:hover {
  color: var(--accent, #4f46e5);
  transform: translateY(-50%) scale(1.15);
}

.quick-react-trigger span {
  font-size: 11px;
  margin-left: 2px;
  font-weight: 700;
}

/* =====================================================================
   Input Dock & Compose Bar
   ===================================================================== */

#dmMessageForm {
  width: 95%;
  max-width: 650px;
  margin: 0 auto;
  background: var(--theme-input-bg, #f5f4f0);
  border-radius: 14px;
  border: 1px solid var(--border-subtle, #edebe6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#dmMessageForm:focus-within {
  background: #ffffff;
  border-color: var(--accent, #4f46e5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.chat-input-bar {
  display: grid;
  grid-template-areas:
    "upload text"
    ".      controls";
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 10px;
  width: 100%;
}

.uploadForm {
  grid-area: upload;
  display: flex;
  align-items: center;
}

.btn-icon {
  cursor: pointer;
  font-size: 1.5rem;
  padding: 5px;
}

input#sendMessage {
  background-color: var(--accent, #4f46e5);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 7px 18px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  transition: all 0.15s ease;
  float: right;
}

input#sendMessage:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
  filter: brightness(1.04);
}

/* Reply Strip */
dm-reply-preview {
  display: flex;
  align-items: center;
  background: #f7f6f2;
  padding: 8px 12px;
  border-left: 3px solid var(--accent, #4f46e5);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-in-out, opacity 0.2s;
  opacity: 0;
}

dm-reply-preview.is-visible {
  max-height: 60px;
  opacity: 1;
}

.replying-to {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent, #4f46e5);
}

.reply-text {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 88%;
  color: var(--text-main, #16181b);
}

dm-reply-preview #cancelReply {
  border-radius: 50%;
  width: 22px;
  height: 22px;
  border: none;
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-muted, #656f77);
  cursor: pointer;
  margin-left: auto;
  display: grid;
  place-items: center;
  transition: background-color 0.12s;
}

dm-reply-preview #cancelReply:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* =====================================================================
   Message Action Context Popover
   ===================================================================== */

dm-message-actions {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
}

dm-message-actions.active {
  display: block;
}

dm-message-actions .overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  backdrop-filter: blur(4px);
}

dm-message-actions .panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  border: 1px solid var(--border-subtle, #edebe6);
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.16);
  min-width: 260px;
  overflow: hidden;
}

dm-message-actions .reactions-bar {
  display: flex;
  justify-content: space-around;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  background: #fbfbfa;
}

dm-message-actions .reactions-bar span {
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}

dm-message-actions .reactions-bar span:hover {
  transform: scale(1.3);
}

dm-message-actions .preview-text {
  padding: 12px 16px;
  background: #fbfbfa;
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  font-size: 0.85rem;
  color: var(--text-muted, #656f77);
  max-height: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

dm-message-actions ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

dm-message-actions li {
  padding: 11px 16px;
  color: var(--text-main, #16181b);
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  background-color: #ffffff;
  transition: background-color 0.12s;
  background-position: 95% center;
  background-repeat: no-repeat;
  background-size: 16px;
  user-select: none;
  -webkit-user-select: none;
}

dm-message-actions li.reply  { background-image: url(/images/reply.gif); }
dm-message-actions li.copy   { background-image: url(/images/copy.gif); }
dm-message-actions li.unsend { background-image: url(/images/remove_red.gif); color: #ef4444; }

dm-message-actions li:hover {
  background-color: var(--surface-hover, #f7f6f2);
}

dm-message-actions li:last-child {
  border-bottom: none;
}

/* System Notifications */
dm-system-message {
  display: block;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted, #656f77);
  padding: 4px 14px;
  margin: 8px auto;
  background: #f2f0eb;
  border-radius: 20px;
  width: fit-content;
  max-width: 80%;
}

/* Typing Indicator Dots */
dm-typing-indicator {
  display: block;
  order: 9999;
  font-size: 12px;
  color: var(--text-muted, #656f77);
  padding: 4px 16px;
  margin-bottom: 8px;
  min-height: 18px;
}

.dots span {
  animation: dotFade 1.4s infinite both;
  font-weight: bold;
}

.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotFade {
  0%, 80%, 100% { opacity: 0.2; }
  40%           { opacity: 1; }
}

/* Feed tags */
feed-tags {
  display: block;
  margin-top: 5px;
  font-size: 1rem;
}

feed-tag {
  display: inline-block;
  margin-left: 5px;
  cursor: pointer;
}

feed-tag:hover {
  text-decoration: underline;
}

/* =====================================================================
   Media Stacks & Attachment Cards
   ===================================================================== */

.media-stack {
  display: grid;
  gap: 2px;
  width: 100%;
  max-width: 320px;
  border-radius: 14px;
  overflow: hidden;
  margin-top: 6px;
  border: 1px solid var(--border-subtle, #edebe6);
}

.media-stack.grid-1 { grid-template-columns: 1fr; max-height: 400px; }
.media-stack.grid-2 { grid-template-columns: 1fr 1fr; min-height: 150px; }
.media-stack.grid-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1.5fr 1fr; height: 250px; }
.media-stack.grid-3 .media-item:first-child { grid-column: span 2; }
.media-stack.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: 250px; }

.media-item {
  position: relative;
  max-width: 320px;
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #f7f6f2;
  overflow: hidden;
  display: block;
}

.media-stack.grid-2 .media-item { height: 100%; aspect-ratio: unset; }

.media-item.is-portrait  { max-width: 220px; }
.media-item.is-landscape { max-width: 320px; }

.media-item img,
.media-item video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  content-visibility: auto;
}

.media-stack.grid-1 .media-item img {
  object-fit: contain;
  max-height: 400px;
  background: #ffffff;
}

/* Video tiles */
.media-item.video {
  background-color: #000000;
}

.media-item.video video {
  object-fit: contain;
  background: #000000;
}

/* Play button overlay */
.media-item.video .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 44px;
  height: 44px;
  background: rgba(13, 17, 23, 0.65);
  border-radius: 50%;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.media-item.video .play-icon::after {
  content: '';
  display: block;
  margin-left: 3px;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #ffffff;
}

/* ---------------------------------------------------------------------
   Audio / voice notes & documents: size to content, no tile chrome
   --------------------------------------------------------------------- */

.media-item.audio,
.media-item.is-document {
  aspect-ratio: auto;
  height: auto;
  background: transparent;
  overflow: visible;
}

.media-stack:has(> .media-item.audio),
.media-stack:has(> .media-item.is-document) {
  max-height: none;
  min-height: 0;
  height: auto;
  border: none;
  overflow: visible;
}

/* Shrink-to-fit bubbles would otherwise squeeze the voice note to its
   min-content width, wrapping the play button above the waveform */
.media-stack:has(> .media-item.audio) {
  width: 260px;
  max-width: 100%;
}

/* <voice-note> lays itself out (shadow :host is display:flex).
   Page rules beat :host, so never set display/width here — only theme it. */
.media-item.audio {
  --vn-accent: var(--accent, #4f46e5);
  --vn-hover: rgba(79, 70, 229, 0.08);
  color: var(--text-main, #16181b);
}

.media-item audio {
  display: block;
  width: 100%;
}

/* PDF Document Attachment Card */
.media-item .pdf-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fbfbfa;
  border: 1px solid var(--border-subtle, #edebe6);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 80ms ease;
}

@media (hover: hover) {
  .media-item .pdf-wrapper:hover {
    background: #f7f6f2;
    border-color: #ded9cf;
  }
}

.media-item .pdf-wrapper:active {
  transform: scale(0.98);
}

.reply-media-preview .pdf-icon,
.media-item .pdf-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border-radius: 8px;
  background: #ef4444;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.25);
}

.media-item .pdf-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.media-item .pdf-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-main, #16181b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-item .pdf-size {
  font-size: 11px;
  color: var(--text-muted, #656f77);
}

.media-item .pdf-arrow {
  order: 3;                                     /* Arrow sits after meta in the DOM order fix */
  margin-left: auto;
  color: var(--text-muted, #656f77);
  opacity: 0.6;
}

/* =====================================================================
   Animations & Media Queries
   ===================================================================== */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-4px); }
}

/* =====================================================================
   Chat Profile (one-to-one chats)
   The header's avatar and name open a short version of the other
   person's profile, which slides in over the chat; back slides it out
   (DmMessagesModule.js, profile/chat-profile.html). Banner, avatar,
   name and details use the profile's own styles.
   ===================================================================== */
message-profile {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    justify-content: center;
    background-color: rgb(0 0 0 / 0.7);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease,
                visibility 0s linear 0.25s;
}

message-profile.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease,
                visibility 0s;
}

message-profile-sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    background-color: #fff;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

message-profile.is-open message-profile-sheet {
    transform: translateX(0);
}

message-profile-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

dm-chat-profile {
    display: block;
    padding-bottom: 24px;
}

dm-chat-profile .chat-profile-open {
    display: block;
    width: calc(100% - 32px);
    margin: 8px 16px 0;
}

@media (max-width: 600px) {
  message { max-width: 95%; }
  dm-message-actions .panel { width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  message-container,
  dm-read-marker,
  .emoji-stack span:first-child {
    animation: none;
  }

  message-profile,
  message-profile.is-open {
    transition: none;
  }
}




@media (max-width: 720px) {
  #dm-messages-component.dm-wrapper {
    border-left: none;
    border-right: none;
    max-width: 100%;
  }
}
