/* Shared chat message interactions — admin inbox + user widget */

.msg-quote {
  border-left: 3px solid rgba(59, 130, 246, 0.75);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.04);
  font-size: 12px;
  line-height: 1.35;
}

.msg-quote__name {
  display: block;
  font-weight: 600;
  color: #2563eb;
  margin-bottom: 2px;
}

.msg-quote__text {
  display: block;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.msg-quote--link {
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.msg-quote--link:hover,
.msg-quote--link:focus-visible {
  background: rgba(59, 130, 246, 0.1);
  outline: none;
}

.msg-quote--link:active {
  transform: scale(0.99);
}

.message-row.msg-target-highlight,
.chat-message.msg-target-highlight {
  position: relative;
  z-index: 2;
  animation: msg-target-row-flash 2.2s ease-out;
}

.chat-messages-page .message-row.msg-target-highlight {
  /* margin-left: -6px; */
  /* margin-right: -6px; */
  /* padding: 4px 6px; */
  box-sizing: border-box;
}

.chat-popup .chat-message.msg-target-highlight {
  /* margin-left: -4px; */
  /* margin-right: -4px; */
  /* padding: 4px; */
  box-sizing: border-box;
}

@keyframes msg-target-row-flash {
  0%,
  12% {
    background: rgba(59, 130, 246, 0.24);
  }
  100% {
    background: rgba(59, 130, 246, 0.06);
  }
}

.dark .msg-quote--link:hover,
.dark .msg-quote--link:focus-visible {
  background: rgba(96, 165, 250, 0.14);
}

.dark .message-row.msg-target-highlight,
.dark .chat-message.msg-target-highlight {
  animation-name: msg-target-row-flash-dark;
}

@keyframes msg-target-row-flash-dark {
  0%,
  12% {
    background: rgba(96, 165, 250, 0.22);
  }
  100% {
    background: rgba(96, 165, 250, 0.08);
  }
}

.message-row .message-stack,
.chat-message .chat-message__content {
  position: relative;
}

/* Interaction shell: menu outermost, reply top corner, react bottom corner */
.msg-interactions {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.msg-interactions.is-own {
  flex-direction: row;
}

.msg-interactions.is-peer {
  flex-direction: row;
}

.message-bubble-wrap {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
}

.msg-menu-outer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  align-self: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.msg-action-reply,
.msg-action-react {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 3;
}

.msg-interactions:hover .msg-menu-outer,
.msg-interactions:hover .msg-action-reply,
.msg-interactions:hover .msg-action-react,
.message-row:hover .msg-interactions .msg-menu-outer,
.message-row:hover .msg-interactions .msg-action-reply,
.message-row:hover .msg-interactions .msg-action-react,
.chat-message:hover .msg-interactions .msg-menu-outer,
.chat-message:hover .msg-interactions .msg-action-reply,
.chat-message:hover .msg-interactions .msg-action-react {
  opacity: 1;
  pointer-events: auto;
}

/* Own (sender): reply top-left, react bottom-left */
.msg-interactions.is-own .msg-action-reply {
  top: -10px;
  left: -10px;
}

.msg-interactions.is-own .msg-action-react {
  bottom: -10px;
  left: -10px;
}

.msg-interactions.is-own .msg-reaction-picker {
  bottom: 22px;
  left: -10px;
}

/* Peer (receiver): reply top-right, react bottom-right */
.msg-interactions.is-peer .msg-action-reply {
  top: -10px;
  right: -10px;
}

.msg-interactions.is-peer .msg-action-react {
  bottom: -10px;
  right: -10px;
}

.msg-interactions.is-peer .msg-reaction-picker {
  bottom: 22px;
  right: -10px;
}

.msg-action-reply,
.msg-action-react,
.msg-menu__toggle {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--msg-action-bg, #fff);
  box-shadow: var(--msg-action-shadow, 0 1px 4px rgba(15, 23, 42, 0.15));
  color: var(--msg-action-color, #64748b);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.msg-action-reply i,
.msg-action-react i,
.msg-menu__toggle i {
  color: currentColor;
}

.msg-action-reply:hover,
.msg-action-react:hover,
.msg-menu__toggle:hover {
  color: var(--msg-action-hover-color, #2563eb);
  background: var(--msg-action-hover-bg, #f8fafc);
}

.msg-menu {
  position: relative;
}

.msg-menu__panel {
  position: absolute;
  top: 100%;
  margin-top: 4px;
  min-width: 100px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  overflow: hidden;
  z-index: 5;
}

.msg-interactions.is-own .msg-menu__panel {
  left: 0;
}

.msg-interactions.is-peer .msg-menu__panel {
  right: 0;
}

.msg-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #334155;
}

.msg-menu__item i {
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  color: #64748b;
}

.msg-menu__item--danger,
.msg-menu__item[data-action="delete"] {
  color: #dc2626;
}

.msg-menu__item[data-action="delete"] i {
  color: #dc2626;
}

.msg-menu__item:hover {
  background: #f1f5f9;
}

.msg-reaction-picker {
  position: absolute;
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  z-index: 5;
}

.msg-reaction-picker__btn {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}

.msg-reaction-picker__btn:hover {
  background: #f1f5f9;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.msg-reaction-chip {
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.msg-reaction-chip.is-mine {
  border-color: #93c5fd;
  background: #eff6ff;
}

.msg-edited-label {
  font-size: 10px;
  color: #94a3b8;
  font-style: italic;
  white-space: nowrap;
}

.message-bubble__footer .msg-edited-label,
.chat-message__meta .msg-edited-label {
  font-size: 11px;
}

.chat-message__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.chat-message__meta .chat-message__time {
  display: inline;
  margin-top: 0;
}

.chat-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.chat-reply-bar__icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2563eb;
  font-size: 14px;
}

.chat-reply-bar__content {
  flex: 1;
  min-width: 0;
}

.chat-reply-bar__label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  margin-bottom: 2px;
}

.chat-reply-bar__close {
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.chat-reply-bar__close:hover {
  background: #e2e8f0;
}

.message-row.is-editing .message-bubble,
.chat-message.is-editing .chat-message__bubble {
  outline: 2px solid #93c5fd;
}

.msg-inline-edit {
  width: 100%;
  min-height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  resize: vertical;
}

.msg-inline-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.msg-inline-edit-actions button {
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.msg-inline-edit-actions .is-save {
  background: #2563eb;
  color: #fff;
}

.msg-inline-edit-actions .is-cancel {
  background: #e2e8f0;
  color: #334155;
}

/* Widget: support icon sits beside bubble for received messages */
.chat-message--support .chat-message__content {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.chat-message--support .msg-interactions.is-peer {
  flex: 1;
  min-width: 0;
}

.chat-popup__footer.has-reply {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.chat-popup__compose-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  width: 100%;
  min-width: 0;
  position: relative;
}

.chat-popup__footer .chat-reply-bar {
  width: 100%;
  box-sizing: border-box;
  border-top: none;
  border-bottom: 1px solid #e2e8f0;
  border-radius: 8px;
  margin: 0;
  flex-shrink: 0;
  background: #f8fafc;
}

.chat-popup__footer .chat-reply-bar .msg-quote {
  margin-bottom: 0;
  max-width: 100%;
}

.chat-popup__footer .chat-reply-bar .msg-quote__text {
  max-width: none;
}

.chat-popup__footer.has-reply .chat-popup__compose-row {
  width: 100%;
}

.chat-popup__footer.has-reply .chat-popup__input-wrapper {
  flex: 1;
  min-width: 0;
}

.chat-message .msg-interactions {
  max-width: 100%;
}

.chat-message .message-bubble-wrap {
  max-width: 100%;
}

.chat-message--user .chat-message__content,
.chat-message--support .chat-message__content {
  overflow: visible;
}

.chat-message .msg-quote {
  margin-bottom: 6px;
}

.chat-message--user .msg-quote {
  border-left-color: rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.12);
}

.chat-message--user .msg-quote__name {
  color: #fde68a;
}

.chat-message--user .msg-quote__text {
  color: rgba(255, 255, 255, 0.85);
}

.chat-message--user .chat-message__meta .msg-edited-label {
  color: rgba(255, 255, 255, 0.72);
}

.chat-messages-page .message-row.right .message-bubble__footer .msg-edited-label {
  color: rgba(255, 255, 255, 0.72);
}

/* Admin own bubble (purple): reply quote needs light text for contrast */
.chat-messages-page .message-row.right .msg-quote {
  border-left-color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.18);
}

.chat-messages-page .message-row.right .msg-quote__name {
  color: #fde68a;
}

.chat-messages-page .message-row.right .msg-quote__text {
  color: rgba(255, 255, 255, 0.92);
}

/* Admin inbox — user message (left): reply quote */
.chat-messages-page .message-row.left .msg-quote {
  border-left-color: rgba(124, 58, 237, 0.55);
  background: rgba(124, 58, 237, 0.08);
}

.chat-messages-page .message-row.left .msg-quote__name {
  color: #6d28d9;
}

.chat-messages-page .message-row.left .msg-quote__text {
  color: #475569;
}

.dark .chat-messages-page .message-row.left .msg-quote {
  border-left-color: rgba(167, 139, 250, 0.7);
  background: rgba(124, 58, 237, 0.15);
}

.dark .chat-messages-page .message-row.left .msg-quote__name {
  color: #c4b5fd;
}

.dark .chat-messages-page .message-row.left .msg-quote__text {
  color: rgba(239, 240, 241, 0.88);
}

/* Admin inbox: floating reply/react/menu — aligned with user widget */
.chat-messages-page .chat-messages {
  overflow-x: hidden;
}

.chat-messages-page .message-bubble-wrap {
  overflow: visible;
}

.chat-messages-page .message-row.right .msg-interactions.is-own .msg-action-reply {
  top: -6px;
  left: 0;
}

.chat-messages-page .message-row.right .msg-interactions.is-own .msg-action-react {
  bottom: -6px;
  left: 0;
}

.chat-messages-page .message-row.left .msg-interactions.is-peer .msg-action-reply {
  top: -6px;
  right: 0;
}

.chat-messages-page .message-row.left .msg-interactions.is-peer .msg-action-react {
  bottom: -6px;
  right: 0;
}

.chat-messages-page .message-row.left .msg-interactions.is-peer .msg-reaction-picker {
  right: 0;
  left: auto;
}

.chat-messages-page .message-row .msg-menu-outer {
  align-self: center;
}

.dark .chat-messages-page .msg-action-reply,
.dark .chat-messages-page .msg-action-react,
.dark .chat-messages-page .msg-menu__toggle {
  --msg-action-bg: #2e404e;
  --msg-action-color: #c7cbd3;
  --msg-action-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  --msg-action-hover-bg: #3d4f5e;
  --msg-action-hover-color: #a78bfa;
}

/* Admin own messages (right): reaction picker opens inward to avoid edge clip */
.chat-messages-page .message-row.right .msg-interactions.is-own .msg-reaction-picker {
  left: 0;
  right: auto;
  bottom: 28px;
  transform: translateX(calc(-100% + 26px));
}

/* Widget: keep floating controls inside scroll area (chat-popup overflow clips negative offsets) */
.chat-popup__body {
  padding-left: 1px;
  padding-right: 1px;
}

.chat-popup__body .message-bubble-wrap {
  overflow: visible;
}

.chat-popup__body .msg-reaction-picker {
  z-index: 20;
  white-space: nowrap;
}

/* User bubble (right): anchor picker above react, expand inward (left) to avoid clipping */
.chat-popup__body .chat-message--user .msg-interactions.is-own .msg-action-reply {
  top: -6px;
  left: 0;
}

.chat-popup__body .chat-message--user .msg-interactions.is-own .msg-action-react {
  bottom: -6px;
  left: 0;
}

.chat-popup__body .chat-message--user .msg-interactions.is-own .msg-reaction-picker {
  left: 0;
  right: auto;
  bottom: 28px;
  transform: translateX(calc(-100% + 26px));
}

/* Support bubble (left): anchor picker inward from right */
.chat-popup__body .chat-message--support .msg-interactions.is-peer .msg-action-reply {
  top: -6px;
  right: 0;
}

.chat-popup__body .chat-message--support .msg-interactions.is-peer .msg-action-react {
  bottom: -6px;
  right: 0;
}

.chat-popup__body .chat-message--support .msg-interactions.is-peer .msg-reaction-picker {
  left: 0;
  right: auto;
  bottom: 28px;
}

.chat-popup__body .chat-message--user .msg-menu-outer,
.chat-popup__body .chat-message--support .msg-menu-outer {
  align-self: center;
}

/* Dark mode — override global `.dark i { color: #fff }` (backend.css) on action buttons */
.dark {
  --msg-action-bg: #242c36;
  --msg-action-color: #c7cbd3;
  --msg-action-hover-bg: #3d4f5e;
  --msg-action-hover-color: #93c5fd;
  --msg-action-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  --msg-action-border: 1px solid #3d4f5e;
  --msg-menu-panel-bg: #242c36;
  --msg-menu-panel-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --msg-menu-item-color: #eff0f1;
  --msg-menu-item-hover-bg: #3d4f5e;
  --msg-reaction-picker-bg: #242c36;
  --msg-reaction-picker-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --msg-reaction-chip-bg: #2e404e;
  --msg-reaction-chip-border: #3d4f5e;
  --msg-reaction-chip-mine-bg: rgba(37, 99, 235, 0.2);
  --msg-reaction-chip-mine-border: #60a5fa;
  --msg-reply-bar-bg: #2e404e;
  --msg-reply-bar-border: #3d4f5e;
  --msg-quote-bg: rgba(255, 255, 255, 0.06);
  --msg-quote-text: #c7cbd3;
}

.dark .msg-action-reply,
.dark .msg-action-react,
.dark .msg-menu__toggle {
  border: var(--msg-action-border);
}

.dark .msg-action-reply i,
.dark .msg-action-react i,
.dark .msg-menu__toggle i {
  color: currentColor;
}

.dark .msg-menu__panel {
  background: var(--msg-menu-panel-bg);
  border: 1px solid #3d4f5e;
  box-shadow: var(--msg-menu-panel-shadow);
}

.dark .msg-menu__item {
  color: var(--msg-menu-item-color);
}

.dark .msg-menu__item:hover {
  background: var(--msg-menu-item-hover-bg);
}

.dark .msg-reaction-picker {
  background: var(--msg-reaction-picker-bg);
  border: 1px solid #3d4f5e;
  box-shadow: var(--msg-reaction-picker-shadow);
}

.dark .msg-reaction-picker__btn:hover {
  background: #3d4f5e;
}

.dark .msg-reaction-chip {
  background: var(--msg-reaction-chip-bg);
  border-color: var(--msg-reaction-chip-border);
  color: #eff0f1;
}

.dark .msg-reaction-chip.is-mine {
  background: var(--msg-reaction-chip-mine-bg);
  border-color: var(--msg-reaction-chip-mine-border);
}

.dark .chat-reply-bar {
  background: var(--msg-reply-bar-bg);
  border-color: var(--msg-reply-bar-border);
}

.dark .chat-reply-bar__close:hover {
  background: #3d4f5e;
}

.dark .chat-popup__footer .chat-reply-bar {
  background: var(--msg-reply-bar-bg);
  border-bottom-color: var(--msg-reply-bar-border);
}

.dark .msg-quote {
  background: var(--msg-quote-bg);
}

.dark .msg-quote__text {
  color: var(--msg-quote-text);
}

.dark .msg-inline-edit {
  background: #2e404e;
  border-color: #3d4f5e;
  color: #eff0f1;
}

.dark .msg-inline-edit-actions .is-cancel {
  background: #3d4f5e;
  color: #eff0f1;
}

.chat-attachment-caption {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-attachment-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
}

.chat-attachment-block .attachment-slot {
  width: 100%;
}
