/* ============================================================
   CHIRP — Chat Area
   ============================================================ */

/* ── Message List ── */
.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0 0;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}
.message-list-inner { min-height: 0; }

/* Load more */
.load-more-btn {
  background: none;
  border: none;
  color: var(--text-link);
  cursor: pointer;
  font-size: 13px;
  padding: 8px 16px;
  display: block;
  margin: 0 auto 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.load-more-btn:hover { background: var(--bg-modifier-hover); }

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}
.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--divider);
}

/* Message groups */
.msg-group { padding: 2px 16px; position: relative; }
.msg-group:hover { background: var(--bg-message-hover); }
.msg-group:hover .msg-timestamp { visibility: visible; }
.msg-group:hover .msg-actions { display: flex; }

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.msg-group-start { padding-top: 16px; }

/* Compact (subsequent messages) */
.msg-compact .msg-avatar-space { width: 40px; flex-shrink: 0; display: flex; align-items: flex-start; justify-content: center; }
.msg-compact .msg-timestamp-left {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  visibility: hidden;
  line-height: 22px;
}
.msg-group:hover .msg-timestamp-left { visibility: visible; }

.msg-layout { display: flex; gap: 16px; align-items: flex-start; }
.msg-layout .msg-avatar-col { flex-shrink: 0; }
.msg-layout .msg-body-col { flex: 1; min-width: 0; }

/* Author info */
.msg-author { font-weight: 600; font-size: 15px; color: var(--text-normal); cursor: pointer; }
.msg-author:hover { text-decoration: underline; }
.msg-timestamp {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  visibility: hidden;
}

/* Message content */
.msg-content {
  font-size: 15px;
  color: var(--text-normal);
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-content a { color: var(--text-link); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }

/* Edited tag */
.msg-edited { font-size: 10px; color: var(--text-muted); margin-left: 4px; }

/* Reply bar */
.msg-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding-left: 40px;
  position: relative;
}
.msg-reply-bar::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 50%;
  width: 20px;
  height: 12px;
  border-top: 2px solid var(--text-muted);
  border-left: 2px solid var(--text-muted);
  border-radius: 4px 0 0 0;
}
.reply-author { font-weight: 600; color: var(--text-normal); cursor: pointer; }
.reply-author:hover { text-decoration: underline; }
.reply-content { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; cursor: pointer; }

/* Reactions */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-modifier-hover);
  border: 1px solid var(--divider);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  user-select: none;
}
.reaction-pill:hover { background: var(--bg-modifier-active); }
.reaction-pill.reacted { background: rgba(88,101,242,0.25); border-color: var(--brand); }
.reaction-count { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.reaction-pill.reacted .reaction-count { color: var(--brand); }

/* Message actions toolbar */
.msg-actions {
  position: absolute;
  top: -16px;
  right: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--divider);
  border-radius: 8px;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 4px;
  box-shadow: var(--shadow-high);
  z-index: 50;
}
.msg-action-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.msg-action-btn:hover { background: var(--bg-modifier-hover); color: var(--text-normal); }
.msg-action-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* Attachments */
.msg-attachments { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.attachment-image {
  max-width: 400px;
  max-height: 300px;
  border-radius: var(--radius-md);
  cursor: zoom-in;
  object-fit: contain;
  background: var(--bg-floating);
}
.attachment-video {
  max-width: 400px;
  border-radius: var(--radius-md);
  outline: none;
}
.attachment-audio {
  width: 300px;
  border-radius: var(--radius-sm);
}
.attachment-file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  max-width: 400px;
}
.attachment-file svg { width: 32px; height: 32px; fill: var(--text-muted); flex-shrink: 0; }
.attachment-file-info { min-width: 0; }
.attachment-filename { font-size: 14px; font-weight: 600; color: var(--text-link); cursor: pointer; }
.attachment-filename:hover { text-decoration: underline; }
.attachment-filesize { font-size: 12px; color: var(--text-muted); }

/* Pin message */
.pinned-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
}
.pinned-banner:hover { background: var(--bg-modifier-hover); }
.pinned-banner svg { width: 16px; height: 16px; fill: var(--text-muted); }

/* Welcome message */
.channel-welcome {
  padding: 24px 16px;
}
.channel-welcome-icon {
  width: 64px;
  height: 64px;
  background: var(--bg-modifier-hover);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.channel-welcome-icon svg { width: 36px; height: 36px; fill: var(--text-muted); }
.channel-welcome h2 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.channel-welcome p { font-size: 15px; color: var(--text-muted); }

/* ── Message Input ── */
.message-input-area {
  flex-shrink: 0;
  padding: 0 16px 24px;
}
.message-box {
  background: var(--bg-modifier-hover);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: border-color 0.15s;
  overflow: hidden;
}
.message-box:focus-within { border-color: var(--brand); }

/* Attachment preview strip */
.attachment-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px 0;
}
.att-preview {
  position: relative;
  display: inline-block;
}
.att-preview img,
.att-preview video {
  max-width: 120px;
  max-height: 90px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--divider);
}
.att-preview-file {
  background: var(--bg-secondary);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--text-danger);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
}

/* Reply bar above input */
.reply-context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.reply-context .reply-to-name { font-weight: 600; color: var(--text-normal); }
.reply-context .cancel-reply {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.reply-context .cancel-reply:hover { color: var(--text-normal); }

/* Input row */
.input-row {
  display: flex;
  align-items: flex-end;
  padding: 0 4px 0 8px;
}
.message-input {
  flex: 1;
  min-height: 44px;
  max-height: 50vh;
  background: transparent;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text-normal);
  resize: none;
  padding: 11px 4px;
  font-family: inherit;
  line-height: 1.45;
  overflow-y: auto;
}
.message-input::placeholder { color: var(--text-muted); }
.input-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-bottom: 10px;
}

/* Drag-over overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(88,101,242,0.15);
  border: 3px dashed var(--brand);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--brand);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.drop-overlay.active { opacity: 1; }

/* Typing indicator */
.typing-indicator {
  padding: 4px 16px 0;
  font-size: 12px;
  color: var(--text-muted);
  height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}
.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(1); }
  40% { transform: scale(1.4); }
}

/* Search bar */
.search-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  gap: 8px;
  height: 32px;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.search-input-wrapper:focus-within { border-color: var(--brand); }
.search-input-wrapper svg { width: 16px; height: 16px; fill: var(--text-muted); flex-shrink: 0; }
.search-input-wrapper input {
  background: none;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--text-normal);
  flex: 1;
  min-width: 0;
}
.search-input-wrapper input::placeholder { color: var(--text-muted); }

/* Emoji picker trigger */
.emoji-btn svg, .gif-btn svg { width: 22px; height: 22px; }

/* Message system */
.msg-system {
  padding: 4px 16px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-system svg { width: 16px; height: 16px; fill: var(--text-muted); }

/* Unread divider */
.unread-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  margin: 8px 0;
}
.unread-divider::before { content: ''; flex: 1; height: 1px; background: var(--text-danger); }
.unread-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-danger);
  white-space: nowrap;
}
.unread-divider::after { content: ''; flex: 1; height: 1px; background: var(--text-danger); }
