/* ========================================
   HOLON GARDENS — MESSAGING SYSTEM CSS
   All 3 Phases: Core, Contextual, Social
   ======================================== */

/* ─── MESSAGING VARIABLES ─── */
:root {
  --msg-sidebar-w: 360px;
  --msg-header-h: 60px;
  --msg-composer-h: 64px;
  --msg-bubble-max: 70%;
  --msg-amber: #F59E0B;
  --msg-amber-light: #FEF3C7;
  --msg-red: #EF4444;
  --msg-red-light: #FEE2E2;
  --msg-purple: #8B5CF6;
  --msg-purple-light: #EDE9FE;
  --msg-blue-info: #3B82F6;
  --msg-blue-light: #DBEAFE;
  --msg-green-trust: #10B981;
  --msg-anim-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── MESSAGING PANEL (MAIN CONTAINER) ─── */
.msg-container {
  display: flex;
  /* Use explicit height since parent .tool-panel has no set height */
  height: calc(100vh - 220px);
  min-height: 500px;
  max-height: 800px;
  background: var(--warm-white);
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--light-gray, rgba(0,0,0,0.08));
}

/* ─── LEFT: CONVERSATION LIST ─── */
.msg-list-panel {
  width: var(--msg-sidebar-w);
  min-width: var(--msg-sidebar-w);
  border-right: 1px solid var(--light-gray);
  display: flex;
  flex-direction: column;
  background: var(--white);
  overflow-y: auto;
}

.msg-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--light-gray);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.msg-list-header h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.msg-compose-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--green);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.msg-compose-btn:hover { background: var(--green-dark); }
.msg-compose-btn svg { width: 18px; height: 18px; }

/* ─── TABS (Inbox / Requests) ─── */
.msg-tabs {
  display: flex;
  gap: 0;
  border-radius: var(--border-radius-sm);
  background: var(--light-gray);
  padding: 3px;
}

.msg-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--msg-anim-ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.msg-tab.active {
  background: var(--white);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.msg-tab-badge {
  background: var(--msg-red);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

/* ─── SEARCH ─── */
.msg-search {
  position: relative;
}

.msg-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--warm-white);
  outline: none;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}
.msg-search input:focus { border-color: var(--green); }
.msg-search input::placeholder { color: var(--text-light); }

.msg-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-light);
  pointer-events: none;
}

/* ─── FILTER ─── */
.msg-filter-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.msg-filter-chip {
  padding: 4px 10px;
  border: 1px solid var(--light-gray);
  border-radius: 999px;
  font-size: 0.75rem;
  font-family: var(--font-body);
  color: var(--text-secondary);
  background: var(--white);
  cursor: pointer;
  transition: all 0.15s ease;
}
.msg-filter-chip:hover,
.msg-filter-chip.active {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
}

/* ─── CONVERSATION ROWS ─── */
.msg-conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  list-style: none;
  margin: 0;
  padding: 0;
}

.msg-conv-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.15s ease;
  position: relative;
}
.msg-conv-row:hover { background: var(--warm-white); }
.msg-conv-row.active { background: var(--green-light); }
.msg-conv-row.unread { font-weight: 600; }

.msg-conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--light-gray);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-secondary);
  overflow: hidden;
}
.msg-conv-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-conv-info { flex: 1; min-width: 0; }

.msg-conv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-conv-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-conv-row.unread .msg-conv-name { font-weight: 700; }

.msg-conv-time {
  font-size: 0.75rem;
  color: var(--text-light);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-conv-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-conv-preview {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.msg-conv-row.unread .msg-conv-preview { color: var(--text-primary); }

/* Context badges */
.msg-context-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
.msg-badge-trade { background: #FEF3C7; color: #92400E; }
.msg-badge-verification { background: #DBEAFE; color: #1E40AF; }
.msg-badge-visit { background: #D1FAE5; color: #065F46; }
.msg-badge-event { background: #EDE9FE; color: #5B21B6; }
.msg-badge-group { background: #E0E7FF; color: #3730A3; }
.msg-badge-direct { background: var(--light-gray); color: var(--text-secondary); }

.msg-unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

/* ─── EMPTY STATES ─── */
.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  height: 100%;
}

.msg-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--green-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--green);
}
.msg-empty-icon svg { width: 32px; height: 32px; }

.msg-empty h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.msg-empty p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
  max-width: 260px;
  line-height: 1.5;
}

/* ─── RIGHT: CONVERSATION VIEW ─── */
.msg-view-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--warm-white);
  min-width: 0;
}

/* Conversation header */
.msg-view-header {
  height: var(--msg-header-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--light-gray);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  flex-shrink: 0;
}

.msg-back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.msg-back-btn:hover { background: var(--light-gray); }

.msg-view-header-info {
  flex: 1;
  min-width: 0;
}
.msg-view-header-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-view-header-sub {
  font-size: 0.78rem;
  color: var(--text-light);
}

.msg-header-actions {
  display: flex;
  gap: 4px;
}

.msg-header-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s ease;
}
.msg-header-btn:hover { background: var(--light-gray); }

/* ─── CONTEXT CARD (pinned top) ─── */
.msg-context-card {
  margin: 12px 20px 0;
  padding: 12px 16px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--light-gray);
  background: var(--white);
  display: flex;
  align-items: center;
  gap: 12px;
}

.msg-context-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--light-gray);
  flex-shrink: 0;
  overflow: hidden;
}
.msg-context-thumb img { width: 100%; height: 100%; object-fit: cover; }

.msg-context-details { flex: 1; min-width: 0; }
.msg-context-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
}
.msg-context-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ─── MESSAGE AREA ─── */
.msg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

/* Message groups by date */
.msg-date-divider {
  text-align: center;
  margin: 16px 0 8px;
  position: relative;
}
.msg-date-divider span {
  background: var(--warm-white);
  padding: 0 12px;
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 500;
  position: relative;
  z-index: 1;
}
.msg-date-divider::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--light-gray);
}

/* Message bubbles */
.msg-bubble-wrap {
  display: flex;
  gap: 8px;
  max-width: var(--msg-bubble-max);
  animation: msgFadeIn 0.2s var(--msg-anim-ease);
}

.msg-bubble-wrap.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-bubble-wrap.received { align-self: flex-start; }

.msg-bubble-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--light-gray);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  overflow: hidden;
  align-self: flex-end;
}
.msg-bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
  word-wrap: break-word;
  position: relative;
}

.msg-bubble-wrap.sent .msg-bubble {
  background: var(--green);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.msg-bubble-wrap.received .msg-bubble {
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-bottom-left-radius: 4px;
}

.msg-bubble-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 2px;
}
.msg-bubble-wrap.sent .msg-bubble-sender { color: rgba(255,255,255,0.85); }

.msg-bubble-time {
  font-size: 0.68rem;
  margin-top: 4px;
  opacity: 0.65;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-bubble-wrap.sent .msg-bubble-time { justify-content: flex-end; }

.msg-bubble-edited {
  font-size: 0.68rem;
  font-style: italic;
  opacity: 0.6;
}

/* Reply thread indicator */
.msg-reply-ref {
  padding: 6px 10px;
  margin-bottom: 6px;
  border-left: 3px solid var(--green);
  border-radius: 4px;
  background: rgba(0,0,0,0.04);
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.msg-bubble-wrap.sent .msg-reply-ref {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.85);
}

/* Image attachments */
.msg-attachment-grid {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
}
.msg-attachment-grid.cols-1 { grid-template-columns: 1fr; max-width: 260px; }
.msg-attachment-grid.cols-2 { grid-template-columns: 1fr 1fr; max-width: 320px; }
.msg-attachment-grid.cols-3,
.msg-attachment-grid.cols-4 { grid-template-columns: 1fr 1fr; max-width: 320px; }

.msg-attachment-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.15s;
}
.msg-attachment-img:hover { opacity: 0.9; }

/* System messages */
.msg-system {
  text-align: center;
  padding: 8px 16px;
  font-size: 0.78rem;
  color: var(--text-light);
  font-style: italic;
}

/* Typing indicator */
.msg-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--text-light);
  animation: msgFadeIn 0.15s ease;
}

.msg-typing-dots {
  display: flex;
  gap: 3px;
}
.msg-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-light);
  border-radius: 50%;
  animation: msgTypingBounce 1.2s ease-in-out infinite;
}
.msg-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.msg-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Scroll to bottom button */
.msg-scroll-bottom {
  position: absolute;
  bottom: 80px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--light-gray);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}
.msg-scroll-bottom.visible { opacity: 1; pointer-events: auto; }
.msg-scroll-bottom .msg-new-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--green);
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ─── MESSAGE COMPOSER ─── */
.msg-composer {
  padding: 12px 20px;
  border-top: 1px solid var(--light-gray);
  background: var(--white);
  flex-shrink: 0;
}

.msg-composer-reply {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--warm-white);
  border-left: 3px solid var(--green);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  animation: msgSlideUp 0.2s ease-out;
}

.msg-composer-reply-close {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
}

.msg-composer-attachments {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.msg-attachment-preview {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--light-gray);
}
.msg-attachment-preview img { width: 100%; height: 100%; object-fit: cover; }
.msg-attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}

.msg-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.msg-composer-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--warm-white);
  border: 1px solid var(--light-gray);
  border-radius: 20px;
  padding: 8px 14px;
  transition: border-color 0.2s ease;
  position: relative;
}
.msg-composer-input-wrap:focus-within { border-color: var(--green); }

.msg-composer-input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 0;
}
.msg-composer-input::placeholder { color: var(--text-light); }

.msg-char-count {
  position: absolute;
  bottom: -18px;
  right: 4px;
  font-size: 0.68rem;
  color: var(--text-light);
}
.msg-char-count.warn { color: var(--msg-amber); }
.msg-char-count.over { color: var(--msg-red); }

.msg-composer-btns {
  display: flex;
  gap: 4px;
  align-items: center;
}

.msg-emoji-btn,
.msg-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s ease;
}
.msg-emoji-btn:hover,
.msg-attach-btn:hover { background: var(--light-gray); }

.msg-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.msg-send-btn:hover { background: var(--green-dark); transform: scale(1.05); }
.msg-send-btn:disabled { background: var(--light-gray); color: var(--text-light); cursor: not-allowed; transform: none; }
.msg-send-btn svg { width: 18px; height: 18px; }

/* NLP Warning inline */
.msg-nlp-warning {
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--msg-amber-light);
  border: 1px solid var(--msg-amber);
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  color: #92400E;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: msgSlideUp 0.2s ease-out;
}
.msg-nlp-warning svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.msg-nlp-warning-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: #92400E;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ─── SAFETY WARNING BANNERS ─── */
.msg-safety-banner {
  padding: 12px 16px;
  margin: 8px 20px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.84rem;
  line-height: 1.5;
  animation: msgSlideDown 0.3s ease-out;
}
.msg-safety-banner svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }

.msg-safety-banner.first_contact { background: var(--msg-amber-light); color: #92400E; }
.msg-safety-banner.payment_keywords { background: var(--msg-red-light); color: #991B1B; }
.msg-safety-banner.new_account { background: var(--msg-amber-light); color: #92400E; }
.msg-safety-banner.visit_safety { background: var(--msg-blue-light); color: #1E40AF; }
.msg-safety-banner.minor_interaction { background: var(--msg-purple-light); color: #5B21B6; }
.msg-safety-banner.scam_pattern { background: var(--msg-red-light); color: #991B1B; }

.msg-safety-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.6;
  color: inherit;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Trust score arc */
.msg-trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.msg-trust-low { background: var(--msg-red-light); color: #991B1B; }
.msg-trust-med { background: var(--msg-amber-light); color: #92400E; }
.msg-trust-good { background: #D1FAE5; color: #065F46; }
.msg-trust-high { background: #A7F3D0; color: #064E3B; }

/* ─── REQUESTS CARDS ─── */
.msg-request-card {
  padding: 16px;
  border-bottom: 1px solid var(--light-gray);
  animation: msgFadeIn 0.2s ease;
}

.msg-request-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.msg-request-preview {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}

.msg-request-actions {
  display: flex;
  gap: 8px;
}

.msg-request-accept {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: var(--green);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.msg-request-accept:hover { background: var(--green-dark); }

.msg-request-decline,
.msg-request-block {
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.msg-request-decline {
  background: none;
  border: 1px solid var(--light-gray);
  color: var(--text-secondary);
}
.msg-request-decline:hover { background: var(--light-gray); }
.msg-request-block {
  background: none;
  border: 1px solid var(--msg-red);
  color: var(--msg-red);
}
.msg-request-block:hover { background: var(--msg-red-light); }

/* ─── NICKNAME SETUP MODAL ─── */
.msg-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.msg-modal-overlay.open { opacity: 1; pointer-events: auto; }

.msg-modal {
  background: var(--white);
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: msgModalSlideUp 0.3s ease-out;
}

.msg-modal-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.msg-modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.msg-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-modal-close:hover { background: var(--light-gray); }

.msg-modal-body { padding: 20px 24px; }
.msg-modal-footer {
  padding: 0 24px 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Nickname input */
.msg-nickname-input-group {
  margin-bottom: 16px;
}
.msg-nickname-input-group label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.msg-nickname-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-nickname-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
}
.msg-nickname-input:focus { border-color: var(--green); }
.msg-nickname-input.error { border-color: var(--msg-red); }
.msg-nickname-input.success { border-color: var(--msg-green-trust); }

.msg-nickname-status {
  font-size: 0.78rem;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-nickname-status.available { color: var(--msg-green-trust); }
.msg-nickname-status.taken { color: var(--msg-red); }
.msg-nickname-status.checking { color: var(--text-light); }

.msg-nickname-info {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
  background: var(--warm-white);
  padding: 12px;
  border-radius: var(--border-radius-sm);
}

/* ─── PRIVACY SETTINGS ─── */
.msg-settings {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.msg-setting-group {
  margin-bottom: 24px;
}
.msg-setting-group h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px;
  font-family: var(--font-display);
}

.msg-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  gap: 16px;
}

.msg-setting-label {
  flex: 1;
}
.msg-setting-label strong {
  display: block;
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: 600;
}
.msg-setting-label span {
  font-size: 0.78rem;
  color: var(--text-light);
  display: block;
  margin-top: 2px;
}

/* Toggle switch */
.msg-toggle {
  width: 44px;
  height: 24px;
  background: #CBD5E1;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
  border: none;
  padding: 0;
  flex-shrink: 0;
}
.msg-toggle.on { background: var(--green); }
.msg-toggle::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 20px;
  height: 20px;
  background: var(--white);
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.msg-toggle.on::after { transform: translateX(20px); }

.msg-setting-select {
  padding: 6px 10px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 0.84rem;
  color: var(--text-primary);
  background: var(--white);
  cursor: pointer;
}

/* Toast */
.msg-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--deep-blue);
  color: var(--white);
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 10000;
  opacity: 0;
  transition: all 0.3s var(--msg-anim-ease);
  pointer-events: none;
}
.msg-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── REPORT MODAL ─── */
.msg-report-step { display: none; }
.msg-report-step.active { display: block; }

.msg-report-categories {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-report-cat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--white);
}
.msg-report-cat:hover { border-color: var(--green); background: var(--green-light); }
.msg-report-cat.selected { border-color: var(--green); background: var(--green-light); }
.msg-report-cat input[type="radio"] { accent-color: var(--green); flex-shrink: 0; }
.msg-report-cat-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.msg-report-evidence {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  margin-top: 12px;
}
.msg-report-evidence-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  font-size: 0.82rem;
  cursor: pointer;
}
.msg-report-evidence-item:hover { background: var(--warm-white); }
.msg-report-evidence-item input[type="checkbox"] { accent-color: var(--green); margin-top: 2px; flex-shrink: 0; }

.msg-report-confirm {
  text-align: center;
  padding: 20px;
}
.msg-report-confirm svg {
  width: 48px;
  height: 48px;
  color: var(--green);
  margin-bottom: 12px;
}

/* ─── ADMIN BROADCAST BUILDER ─── */
.msg-broadcast {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-broadcast-field label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.msg-broadcast-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.msg-broadcast-textarea:focus { border-color: var(--green); }

.msg-broadcast-urgency {
  display: flex;
  gap: 8px;
}
.msg-broadcast-urgency-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  background: var(--white);
  cursor: pointer;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all 0.15s ease;
}
.msg-broadcast-urgency-btn.passive { color: var(--text-secondary); }
.msg-broadcast-urgency-btn.guiding { color: var(--msg-amber); }
.msg-broadcast-urgency-btn.critical { color: var(--msg-red); }
.msg-broadcast-urgency-btn.selected {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green-dark);
}

.msg-broadcast-preview {
  padding: 12px;
  background: var(--warm-white);
  border-radius: var(--border-radius-sm);
  font-size: 0.84rem;
  color: var(--text-secondary);
}

/* ─── FRIENDS PANEL (Phase 3) ─── */
.msg-friends-list { list-style: none; margin: 0; padding: 0; }
.msg-friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.msg-friend-actions { margin-left: auto; display: flex; gap: 8px; }
.msg-friend-btn {
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--light-gray);
  background: var(--white);
  color: var(--text-secondary);
  transition: all 0.15s ease;
}
.msg-friend-btn:hover { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.msg-friend-btn.danger { border-color: var(--msg-red); color: var(--msg-red); }
.msg-friend-btn.danger:hover { background: var(--msg-red-light); }

/* ─── GROUP MANAGEMENT (Phase 3) ─── */
.msg-group-members {
  max-height: 300px;
  overflow-y: auto;
}
.msg-group-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.msg-group-member-role {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-light);
}

/* ─── MENU OVERFLOW ─── */
.msg-overflow-menu {
  position: absolute;
  right: 12px;
  top: 100%;
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 180px;
  z-index: 100;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: all 0.15s ease;
}
.msg-overflow-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.msg-overflow-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.84rem;
  color: var(--text-primary);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
}
.msg-overflow-item:hover { background: var(--warm-white); }
.msg-overflow-item.danger { color: var(--msg-red); }
.msg-overflow-item svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ─── SKELETON LOADING ─── */
.msg-skeleton {
  animation: msgShimmer 1.5s infinite linear;
  background: linear-gradient(90deg, var(--light-gray) 25%, #e8e8e4 50%, var(--light-gray) 75%);
  background-size: 200% 100%;
  border-radius: 6px;
}

.msg-skeleton-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.msg-skeleton-avatar { width: 44px; height: 44px; border-radius: 50%; }
.msg-skeleton-lines { flex: 1; }
.msg-skeleton-line {
  height: 12px;
  margin-bottom: 6px;
  border-radius: 4px;
}
.msg-skeleton-line.w80 { width: 80%; }
.msg-skeleton-line.w50 { width: 50%; }

/* ─── ANIMATIONS ─── */
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

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

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

@keyframes msgTypingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@keyframes msgShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes msgPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes msgBadgePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ─── REDUCED MOTION ─── */
@media (prefers-reduced-motion: reduce) {
  .msg-bubble-wrap,
  .msg-safety-banner,
  .msg-nlp-warning,
  .msg-composer-reply,
  .msg-request-card,
  .msg-modal {
    animation: none !important;
  }
  .msg-typing-dots span { animation: none !important; }
  .msg-skeleton { animation: none !important; background: var(--light-gray) !important; }
  * { transition-duration: 0s !important; }
}

/* ─── DARK MODE ─── */
[data-theme="dark"] .msg-container { background: #1a1a2e; }
[data-theme="dark"] .msg-list-panel { background: #16213e; border-right-color: #2a2a4a; }
[data-theme="dark"] .msg-list-header { border-bottom-color: #2a2a4a; }
[data-theme="dark"] .msg-list-header h2 { color: #e2e8f0; }
[data-theme="dark"] .msg-tabs { background: #1a1a2e; }
[data-theme="dark"] .msg-tab { color: #94a3b8; }
[data-theme="dark"] .msg-tab.active { background: #16213e; color: #e2e8f0; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
[data-theme="dark"] .msg-search input { background: #1a1a2e; border-color: #2a2a4a; color: #e2e8f0; }
[data-theme="dark"] .msg-filter-chip { border-color: #2a2a4a; color: #94a3b8; background: #16213e; }
[data-theme="dark"] .msg-filter-chip.active { background: #0a3d2a; border-color: var(--green); color: #6ee7b7; }
[data-theme="dark"] .msg-conv-row { border-bottom-color: #2a2a4a; }
[data-theme="dark"] .msg-conv-row:hover { background: #1a1a2e; }
[data-theme="dark"] .msg-conv-row.active { background: #0a3d2a; }
[data-theme="dark"] .msg-conv-name { color: #e2e8f0; }
[data-theme="dark"] .msg-conv-preview { color: #94a3b8; }
[data-theme="dark"] .msg-conv-row.unread .msg-conv-preview { color: #e2e8f0; }
[data-theme="dark"] .msg-conv-avatar { background: #2a2a4a; color: #94a3b8; }
[data-theme="dark"] .msg-view-panel { background: #1a1a2e; }
[data-theme="dark"] .msg-view-header { background: #16213e; border-bottom-color: #2a2a4a; }
[data-theme="dark"] .msg-view-header-name { color: #e2e8f0; }
[data-theme="dark"] .msg-context-card { background: #16213e; border-color: #2a2a4a; }
[data-theme="dark"] .msg-context-title { color: #e2e8f0; }
[data-theme="dark"] .msg-bubble-wrap.received .msg-bubble { background: #16213e; border-color: #2a2a4a; color: #e2e8f0; }
[data-theme="dark"] .msg-date-divider span { background: #1a1a2e; color: #64748b; }
[data-theme="dark"] .msg-date-divider::before { background: #2a2a4a; }
[data-theme="dark"] .msg-composer { background: #16213e; border-top-color: #2a2a4a; }
[data-theme="dark"] .msg-composer-input-wrap { background: #1a1a2e; border-color: #2a2a4a; }
[data-theme="dark"] .msg-composer-input { color: #e2e8f0; }
[data-theme="dark"] .msg-modal { background: #16213e; }
[data-theme="dark"] .msg-modal-header h3 { color: #e2e8f0; }
[data-theme="dark"] .msg-nickname-input { background: #1a1a2e; border-color: #2a2a4a; color: #e2e8f0; }
[data-theme="dark"] .msg-nickname-info { background: #1a1a2e; color: #94a3b8; }
[data-theme="dark"] .msg-setting-label strong { color: #e2e8f0; }
[data-theme="dark"] .msg-setting-row { border-bottom-color: #2a2a4a; }
[data-theme="dark"] .msg-setting-select { background: #1a1a2e; border-color: #2a2a4a; color: #e2e8f0; }
[data-theme="dark"] .msg-overflow-menu { background: #16213e; border-color: #2a2a4a; }
[data-theme="dark"] .msg-overflow-item { color: #e2e8f0; }
[data-theme="dark"] .msg-overflow-item:hover { background: #1a1a2e; }
[data-theme="dark"] .msg-scroll-bottom { background: #16213e; border-color: #2a2a4a; }
[data-theme="dark"] .msg-report-cat { border-color: #2a2a4a; background: #16213e; }
[data-theme="dark"] .msg-report-cat:hover,
[data-theme="dark"] .msg-report-cat.selected { background: #0a3d2a; border-color: var(--green); }
[data-theme="dark"] .msg-report-evidence { border-color: #2a2a4a; }
[data-theme="dark"] .msg-broadcast-textarea { background: #1a1a2e; border-color: #2a2a4a; color: #e2e8f0; }
[data-theme="dark"] .msg-broadcast-urgency-btn { border-color: #2a2a4a; background: #16213e; }
[data-theme="dark"] .msg-broadcast-preview { background: #1a1a2e; color: #94a3b8; }
[data-theme="dark"] .msg-empty-icon { background: #0a3d2a; }
[data-theme="dark"] .msg-request-card { border-bottom-color: #2a2a4a; }
[data-theme="dark"] .msg-request-decline { border-color: #2a2a4a; color: #94a3b8; }
[data-theme="dark"] .msg-skeleton { background: linear-gradient(90deg, #2a2a4a 25%, #3a3a5a 50%, #2a2a4a 75%); background-size: 200% 100%; }
[data-theme="dark"] .msg-skeleton-avatar,
[data-theme="dark"] .msg-skeleton-line { background: inherit; }

/* ─── RESPONSIVE: MOBILE ─── */
@media (max-width: 768px) {
  .msg-container {
    flex-direction: column;
    height: calc(100vh - 180px);
    max-height: none;
  }

  .msg-list-panel {
    width: 100%;
    min-width: 100%;
    border-right: none;
    flex: 1;
  }

  .msg-list-panel.hidden-mobile { display: none; }
  .msg-view-panel.hidden-mobile { display: none; }

  .msg-back-btn { display: flex; }

  .msg-bubble-wrap { max-width: 85%; }

  .msg-view-header { padding: 0 12px; }
  .msg-messages { padding: 12px; }
  .msg-composer { padding: 10px 12px; }

  .msg-context-card { margin: 8px 12px 0; }

  .msg-safety-banner { margin: 6px 12px; }
}

/* ─── RESPONSIVE: LARGE SCREENS ─── */
@media (min-width: 1200px) {
  .msg-list-panel {
    width: 400px;
    min-width: 400px;
  }
}
