/**
 * Canonical HUMAN chat origin colors — message ORIGIN, not viewing surface.
 *
 * WhatsApp → green · Pardna/client app → blue · PRDNA Business → purple
 * Geometry unchanged; color tokens only (+ typography normalization).
 *
 * Classes:
 *   .bubble-origin-whatsapp  (alias: .bubble-wa)
 *   .bubble-origin-pardna
 *   .bubble-origin-business  (alias for Business fill: .bubble-out remapped)
 * Interactive .choice-btn stays brand-accent (not origin-painted).
 */
:root {
  /* Light-mode origin fills */
  --mg-msg-whatsapp-bg: #0f9f6e;
  --mg-msg-whatsapp-text: #ffffff;
  --mg-msg-whatsapp-meta: rgba(255, 255, 255, 0.78);
  --mg-msg-whatsapp-tick: rgba(220, 252, 231, 0.95);
  --mg-msg-whatsapp-link: #ffffff;
  --mg-msg-whatsapp-border: rgba(0, 0, 0, 0.12);
  --mg-msg-whatsapp-shadow: 0 3px 14px rgba(15, 159, 110, 0.28);

  --mg-msg-pardna-bg: #2563eb;
  --mg-msg-pardna-text: #ffffff;
  --mg-msg-pardna-meta: rgba(255, 255, 255, 0.78);
  --mg-msg-pardna-tick: rgba(219, 234, 254, 0.95);
  --mg-msg-pardna-link: #ffffff;
  --mg-msg-pardna-border: rgba(0, 0, 0, 0.12);
  --mg-msg-pardna-shadow: 0 3px 14px rgba(37, 99, 235, 0.28);

  --mg-msg-business-bg: #7c3aed;
  --mg-msg-business-text: #ffffff;
  --mg-msg-business-meta: rgba(255, 255, 255, 0.78);
  --mg-msg-business-tick: rgba(237, 233, 254, 0.95);
  --mg-msg-business-link: #ffffff;
  --mg-msg-business-border: rgba(0, 0, 0, 0.12);
  --mg-msg-business-shadow: 0 3px 14px rgba(124, 58, 237, 0.28);

  --mg-msg-ai-bg: #f9fafb;
  --mg-msg-ai-text: #1f2937;
  --mg-msg-ai-meta: #6b7280;
  --mg-msg-ai-tick: #6b7280;
  --mg-msg-ai-link: #4f46e5;
  --mg-msg-ai-border: #e5e7eb;
  --mg-msg-ai-shadow: 0 3px 14px rgba(15, 23, 42, 0.08);

  /* Geometry + type (Pardna reference) */
  --mg-human-bubble-max: min(82%, 22rem);
  --mg-human-bubble-pad: 12px 14px;
  --mg-human-bubble-radius: 16px;
  --mg-human-bubble-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
  --mg-human-font: inherit;
  --mg-human-body-size: 14px;
  --mg-human-body-line: 1.5;
  --mg-human-body-weight: 400;
  --mg-human-bold-weight: 700;
  --mg-human-meta-size: 11px;
  --mg-human-time-size: 10px;

  /* Legacy aliases kept for any residual references */
  --mg-human-green: var(--mg-msg-whatsapp-bg);
  --mg-human-wa: var(--mg-msg-pardna-bg);
}

body.app-theme-dark {
  /* Dark-mode: deeper, premium fills — not neon */
  --mg-msg-whatsapp-bg: #0b6b4a;
  --mg-msg-whatsapp-text: #f0fdf4;
  --mg-msg-whatsapp-meta: rgba(220, 252, 231, 0.78);
  --mg-msg-whatsapp-tick: #bbf7d0;
  --mg-msg-whatsapp-link: #f0fdf4;
  --mg-msg-whatsapp-border: rgba(255, 255, 255, 0.1);
  --mg-msg-whatsapp-shadow: 0 3px 16px rgba(0, 0, 0, 0.35);

  --mg-msg-pardna-bg: #1e40af;
  --mg-msg-pardna-text: #eff6ff;
  --mg-msg-pardna-meta: rgba(191, 219, 254, 0.8);
  --mg-msg-pardna-tick: #bfdbfe;
  --mg-msg-pardna-link: #eff6ff;
  --mg-msg-pardna-border: rgba(255, 255, 255, 0.1);
  --mg-msg-pardna-shadow: 0 3px 16px rgba(0, 0, 0, 0.35);

  --mg-msg-business-bg: #5b21b6;
  --mg-msg-business-text: #f5f3ff;
  --mg-msg-business-meta: rgba(221, 214, 254, 0.8);
  --mg-msg-business-tick: #ddd6fe;
  --mg-msg-business-link: #f5f3ff;
  --mg-msg-business-border: rgba(255, 255, 255, 0.1);
  --mg-msg-business-shadow: 0 3px 16px rgba(0, 0, 0, 0.35);

  --mg-msg-ai-bg: #1f2937;
  --mg-msg-ai-text: #e5e7eb;
  --mg-msg-ai-meta: #9ca3af;
  --mg-msg-ai-tick: #9ca3af;
  --mg-msg-ai-link: #a5b4fc;
  --mg-msg-ai-border: rgba(255, 255, 255, 0.1);
  --mg-msg-ai-shadow: 0 3px 16px rgba(0, 0, 0, 0.35);
}

/* ── Bubble geometry (side corners — not origin-encoded) ── */
.bubble {
  max-width: var(--mg-human-bubble-max);
  padding: var(--mg-human-bubble-pad);
  border-radius: var(--mg-human-bubble-radius);
  font-family: var(--mg-human-font);
  font-size: var(--mg-human-body-size);
  font-weight: var(--mg-human-body-weight);
  line-height: var(--mg-human-body-line);
  word-break: break-word;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--mg-human-bubble-shadow);
  white-space: normal;
}

/* Alignment corners: customer/outgoing-end vs agent/incoming-start */
.chat-msg.staff .bubble,
.cc-human-message--outgoing .bubble,
.flex.flex-col.items-end > .bubble {
  border-bottom-right-radius: 5px;
}

.chat-msg.client .bubble,
.cc-human-message--incoming .bubble,
.flex.flex-col.items-start > .bubble {
  border-bottom-left-radius: 5px;
}

/* ── Origin fills (authoritative) ── */
.bubble-origin-whatsapp,
.bubble-wa {
  background: var(--mg-msg-whatsapp-bg);
  color: var(--mg-msg-whatsapp-text);
  border-color: var(--mg-msg-whatsapp-border);
  box-shadow: var(--mg-msg-whatsapp-shadow);
}

.bubble-origin-pardna {
  background: var(--mg-msg-pardna-bg);
  color: var(--mg-msg-pardna-text);
  border-color: var(--mg-msg-pardna-border);
  box-shadow: var(--mg-msg-pardna-shadow);
}

.bubble-origin-business,
.bubble-out {
  /* .bubble-out remapped: Business purple fill (NOT green). No purple-outline approximation. */
  background: var(--mg-msg-business-bg);
  color: var(--mg-msg-business-text);
  border-color: var(--mg-msg-business-border);
  box-shadow: var(--mg-msg-business-shadow);
}

.bubble-origin-ai {
  background: var(--mg-msg-ai-bg);
  color: var(--mg-msg-ai-text);
  border-color: var(--mg-msg-ai-border);
  box-shadow: var(--mg-msg-ai-shadow);
}

/* Neutral shell only when no origin class (rare fallback / system) */
.bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business):not(.bubble-wa):not(.bubble-out) {
  background: #fff;
  color: #111827;
  border-color: rgba(0, 0, 0, 0.08);
}

body.app-theme-dark .bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business):not(.bubble-wa):not(.bubble-out) {
  background: #374151 !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  color: #e5e7eb !important;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.35) !important;
}

/* Meta / ticks / links on origin fills — light, readable; bubble carries origin */
.bubble-origin-whatsapp .chat-time,
.bubble-wa .chat-time,
.bubble-origin-whatsapp .text-\[9px\],
.bubble-wa .text-\[9px\],
.bubble-origin-whatsapp .cc-human-message-meta {
  color: var(--mg-msg-whatsapp-meta) !important;
}

.bubble-origin-pardna .chat-time,
.bubble-origin-pardna .text-\[9px\],
.bubble-origin-pardna .cc-human-message-meta {
  color: var(--mg-msg-pardna-meta) !important;
}

.bubble-origin-ai .chat-time,
.bubble-origin-ai .text-\[9px\],
.bubble-origin-ai .cc-human-message-meta {
  color: var(--mg-msg-ai-meta) !important;
}

.bubble-origin-ai .chat-tick,
.bubble-origin-ai .cc-delivery-ticks {
  color: var(--mg-msg-ai-tick) !important;
}

.bubble-origin-business .chat-time,
.bubble-out .chat-time,
.bubble-origin-business .text-\[9px\],
.bubble-out .text-\[9px\],
.bubble-origin-business .cc-human-message-meta,
.bubble-out .cc-human-message-meta {
  color: var(--mg-msg-business-meta) !important;
}

.bubble-origin-whatsapp .chat-tick,
.bubble-wa .chat-tick,
.bubble-origin-whatsapp .cc-delivery-ticks {
  color: var(--mg-msg-whatsapp-tick) !important;
}

.bubble-origin-pardna .chat-tick,
.bubble-origin-pardna .cc-delivery-ticks {
  color: var(--mg-msg-pardna-tick) !important;
}

.bubble-origin-business .chat-tick,
.bubble-out .chat-tick,
.bubble-origin-business .cc-delivery-ticks,
.bubble-out .cc-delivery-ticks {
  color: var(--mg-msg-business-tick) !important;
}

/* Rich-text body inside origin bubbles */
.bubble .cc-human-message-body,
.bubble .mg-human-message-body {
  font-family: var(--mg-human-font);
  font-size: var(--mg-human-body-size);
  line-height: var(--mg-human-body-line);
  font-weight: var(--mg-human-body-weight);
  color: inherit;
}

.bubble .cc-human-message-body strong,
.bubble .cc-human-message-body b,
.bubble .mg-human-message-body strong,
.bubble .mg-human-message-body b {
  font-weight: var(--mg-human-bold-weight);
}

.bubble .cc-human-message-body p,
.bubble .mg-human-message-body p {
  margin: 0 0 0.4em;
}

.bubble .cc-human-message-body p:last-child,
.bubble .mg-human-message-body p:last-child {
  margin-bottom: 0;
}

.bubble .cc-human-message-body ul,
.bubble .cc-human-message-body ol,
.bubble .mg-human-message-body ul,
.bubble .mg-human-message-body ol {
  margin: 0.35em 0;
  padding-left: 1.25em;
}

.bubble-origin-whatsapp .cc-human-message-body a,
.bubble-wa .cc-human-message-body a,
.bubble-origin-pardna .cc-human-message-body a,
.bubble-origin-business .cc-human-message-body a,
.bubble-out .cc-human-message-body a,
.bubble-origin-whatsapp .mg-human-message-body a,
.bubble-origin-pardna .mg-human-message-body a,
.bubble-origin-business .mg-human-message-body a {
  color: inherit;
  text-decoration: underline;
}

.cc-human-message-sender {
  font-size: var(--mg-human-meta-size);
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.92;
}

.cc-human-message-meta,
.chat-time {
  font-size: var(--mg-human-meta-size);
}

/* Time / ticks / sender sit under the bubble canvas (Pardna SoT) — muted thread meta */
.mg-human-msg > .chat-time,
.mg-human-msg > .cc-human-message-meta,
.mg-human-msg > .mg-human-msg__footer {
  display: block;
  margin-top: 4px;
  padding: 0 4px;
  font-size: var(--mg-human-time-size);
  line-height: 1.3;
  color: #6b7280 !important;
  opacity: 1;
}
.mg-human-msg.mg-human-msg--out > .chat-time,
.mg-human-msg.mg-human-msg--out > .cc-human-message-meta,
.mg-human-msg.mg-human-msg--out > .mg-human-msg__footer,
.mg-human-msg.cc-human-message--outgoing > .chat-time,
.mg-human-msg.cc-human-message--outgoing > .cc-human-message-meta,
.mg-human-msg.cc-human-message--outgoing > .mg-human-msg__footer,
.mg-human-msg.chat-msg.staff > .chat-time {
  text-align: right;
}
.mg-human-msg > .chat-time .chat-tick,
.mg-human-msg > .mg-human-msg__footer .chat-tick,
.mg-human-msg > .chat-time .cc-delivery-ticks,
.mg-human-msg > .mg-human-msg__footer .cc-delivery-ticks {
  color: #9ca3af !important;
}
body.app-theme-dark .mg-human-msg > .chat-time,
body.app-theme-dark .mg-human-msg > .cc-human-message-meta,
body.app-theme-dark .mg-human-msg > .mg-human-msg__footer {
  color: #9ca3af !important;
}

/* Interactive choice buttons (Pardna) — brand accent, not origin-painted */
.choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin-top: 6px;
  border: 1px solid #00a854;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.choice-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* On neutral/light shells keep classic green choice chrome */
.bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business) .choice-btn {
  border-color: #00a854;
  background: rgba(0, 168, 84, 0.08);
  color: #00a854;
}

.bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business) .choice-btn:hover {
  background: #00a854;
  color: #fff;
}

.choice-btn[disabled],
.choice-btn.is-static {
  cursor: default;
  opacity: 0.95;
}

.choice-btn[disabled]:hover,
.choice-btn.is-static:hover {
  background: rgba(255, 255, 255, 0.14);
}

body.app-theme-dark .bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business) .choice-btn {
  border-color: rgba(0, 168, 84, 0.45) !important;
  background: rgba(0, 168, 84, 0.12) !important;
  color: #34d399 !important;
}

body.app-theme-dark .bubble-in:not(.bubble-origin-whatsapp):not(.bubble-origin-pardna):not(.bubble-origin-business) .choice-btn:hover:not([disabled]):not(.is-static) {
  background: #00a854 !important;
  color: #fff !important;
}

/* ── Canonical chat preview (list row foundation) ── */
.mg-human-preview {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: stretch;
  text-align: left;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}

.mg-human-msg--has-avatar {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}
.mg-human-msg--has-avatar.mg-human-msg--in {
  align-items: flex-end;
}
.mg-human-msg__avatar-col {
  flex: 0 0 auto;
  align-self: flex-end;
}
.mg-human-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  overflow: hidden;
  background: #059669;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mg-human-msg__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.mg-human-msg__avatar img:not([src]),
.mg-human-msg__avatar img[src=""] { display: none !important; }
.mg-human-msg__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.mg-human-preview__avatar {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  background: #ccfbf1;
  color: #115e59;
  margin: 10px 0 10px 12px;
}

.mg-human-preview__body {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px 10px 10px;
}

.mg-human-preview__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.mg-human-preview__name {
  font-weight: 600;
  font-size: 15px;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mg-human-preview__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mg-human-preview__time {
  font-size: 12px;
  color: #6b7280;
}

.mg-human-preview__unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #00a854;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mg-human-preview__snippet {
  font-size: 14px;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.mg-human-preview__tags {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

body.app-theme-dark .mg-human-preview {
  background: #111827;
  border-bottom-color: #374151;
}
body.app-theme-dark .mg-human-preview:hover {
  background: #1f2937;
}

body.app-theme-dark .mg-human-preview__name {
  color: #f3f4f6;
}

body.app-theme-dark .mg-human-preview__snippet,
body.app-theme-dark .mg-human-preview__time {
  color: #9ca3af;
}

/* Command media-only flush: keep photo without bubble chrome */
.mg-human-msg--media-only .bubble {
  padding: 0;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  max-width: min(75%, 240px);
}

@media (min-width: 768px) {
  .bubble {
    max-width: min(72%, 28rem);
  }
}

@media (min-width: 1024px) {
  .bubble {
    max-width: min(65%, 32rem);
  }
}


/* STRICT canonical extras */
.chat-swipe-wrap > .mg-human-preview {
  border-bottom: none;
  background: inherit;
}
.mg-human-tag {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.2;
  padding: 2px 6px;
  border-radius: 999px;
  color: #fff;
  background: #6b7280;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mg-human-tag--green, .mg-human-tag--emerald { background: #00a854; }
.mg-human-tag--amber { background: #d97706; }
.mg-human-tag--purple { background: #7c3aed; }
.mg-human-tag--red { background: #dc2626; }
.mg-human-tag--teal { background: #0d9488; }
.mg-human-tag--cyan { background: #0891b2; }
.mg-human-tag--gray { background: #4b5563; color: #fff; }
.mg-human-tag--rose { background: #e11d48; }
.mg-human-tag--sky { background: #0284c7; }
.mg-human-tag--blue { background: #2563eb; }
body.app-theme-dark .mg-human-tag--gray { background: #6b7280; }

.mg-human-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.mg-human-inbox { min-height: 0; }
.mg-human-operator {
  /* shell marker — scope tools plug into this panel */
}
.mg-human-operator__banner { /* staff internal / scope banners */ }

/* Pardna: hide global bottom nav the entire time a thread is open */
body.pardna-thread-open #pardnaBottomNav {
  display: none !important;
}
body.pardna-thread-open.mg-chat-active #tab-chat {
  bottom: 0 !important;
  padding-bottom: 0 !important;
}
/* PRDNA mobile thread: drop logo + Sign out so chrome matches PRDNA Business (header is the thread header). */
@media (max-width: 767px) {
  body.pardna-thread-open #mainNav {
    display: none !important;
  }
  body.pardna-thread-open.mg-chat-active #tab-chat {
    top: env(safe-area-inset-top, 0px) !important;
    bottom: 0 !important;
    padding-bottom: 0 !important;
  }
}
.mg-human-msg[data-canonical-msg="1"] {
  /* shared message row owner */
}
