/* ── Chat Layout ── */
.chat-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  margin: calc(-1 * var(--space-lg));
}

/* ── Conversation List ── */
.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.chat-sidebar-header h3 {
  font-size: var(--font-size-lg);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--accent-bg); }

.conversation-item-info {
  flex: 1;
  min-width: 0;
}

.conversation-item-name {
  font-weight: 500;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-preview {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conversation-item-time {
  font-size: 10px;
  color: var(--text-muted);
}

.conversation-item-unread {
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  padding: 0 4px;
}

/* ── Presence Dot ── */
.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.presence-dot.online { background: var(--success); }
.presence-dot.away { background: var(--warning); }
.presence-dot.offline { background: var(--text-muted); }

/* ── Message Thread ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-header-title {
  font-weight: 600;
  flex: 1;
}

.chat-header-participants {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.chat-load-more {
  text-align: center;
  padding: var(--space-md);
}

/* ── Message Bubble ── */
.message {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
}

.message:hover .message-actions { opacity: 1; }

.message-avatar {
  flex-shrink: 0;
  margin-top: 2px;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: 2px;
}

.message-author {
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.message-role {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--text-muted);
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
}

.message-edited {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}

.message-text {
  font-size: var(--font-size-base);
  line-height: 1.5;
  word-break: break-word;
}

.message-deleted {
  color: var(--text-muted);
  font-style: italic;
  font-size: var(--font-size-sm);
}

/* ── Reply Quote ── */
.message-reply {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-xs);
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  cursor: pointer;
}

.message-reply:hover { background: var(--bg-active); }

.message-reply-author {
  font-weight: 600;
  color: var(--text-primary);
}

.message-reply-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Reactions ── */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  font-size: var(--font-size-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.reaction-pill:hover { border-color: var(--accent); }
.reaction-pill.mine { border-color: var(--accent); background: var(--accent-bg); }

.reaction-pill-count {
  font-size: 10px;
  color: var(--text-secondary);
}

/* ── Message Actions (hover) ── */
.message-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  position: absolute;
  top: -8px;
  right: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}

.message-wrapper {
  position: relative;
}

/* ── Chat Input ── */
.chat-input-area {
  padding: var(--space-md);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-typing {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  padding: 0 var(--space-sm);
  min-height: 18px;
}

.chat-input-wrapper {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.chat-input-wrapper textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: inherit;
  line-height: 1.5;
}

.chat-input-wrapper textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Emoji Picker (lightweight) ── */
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-sm);
  width: 280px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 18px;
  padding: 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: center;
}

.emoji-btn:hover { background: var(--bg-hover); }

/* ── New Message Button ── */
.btn-new-message {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.btn-new-message:hover { background: var(--accent-hover); }

/* ── People Picker ── */
.people-picker-search {
  margin-bottom: var(--space-md);
}

.people-picker-selected {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.people-picker-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
}

.people-picker-pill button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.people-picker-results {
  max-height: 200px;
  overflow-y: auto;
}

.people-picker-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  cursor: pointer;
  border-radius: var(--radius-md);
}

.people-picker-item:hover { background: var(--bg-hover); }
