/* ============================================================
   ISKRA CHAT & MESSAGE STYLES
   ============================================================ */

/* ── Message Group ───────────────────────────────────────── */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 100%;
  position: relative;
}

.msg-group.out {
  align-items: flex-end;
}

.msg-group.in {
  align-items: flex-start;
}

/* ── Message Row ─────────────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  max-width: var(--msg-max-w);
  position: relative;
}

.msg-group.out .msg-row {
  flex-direction: row-reverse;
}

/* ── Avatar (small, in-chat) ─────────────────────────────── */
.msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: var(--weight-bold);
  flex-shrink: 0;
  margin-bottom: 2px;
}

.msg-avatar-spacer {
  width: 28px;
  min-width: 28px;
  flex-shrink: 0;
}

/* ── Bubble ──────────────────────────────────────────────── */
.msg-bubble {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xl);
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: var(--leading-relaxed);
  font-size: var(--text-base);
  transition: box-shadow var(--duration-fast);
}

/* Tail shapes */
.msg-group.in  .msg-row:first-child .msg-bubble { border-bottom-left-radius: var(--radius-sm); }
.msg-group.out .msg-row:first-child .msg-bubble { border-bottom-right-radius: var(--radius-sm); }
.msg-group.in  .msg-row:not(:first-child) .msg-bubble { border-top-left-radius: var(--radius-sm); }
.msg-group.out .msg-row:not(:first-child) .msg-bubble { border-top-right-radius: var(--radius-sm); }

.msg-bubble.outgoing {
  background: var(--msg-out-bg);
  color: var(--msg-out-text);
}

.msg-bubble.incoming {
  background: var(--msg-in-bg);
  color: var(--msg-in-text);
  border: 1px solid var(--border-subtle);
}

/* Hover to show actions */
.msg-bubble:hover {
  box-shadow: var(--shadow-sm);
}

/* Deleted message */
.msg-bubble.deleted {
  opacity: 0.5;
  font-style: italic;
  font-size: var(--text-sm);
}

/* ── Message Meta ────────────────────────────────────────── */
.msg-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: 2px;
  white-space: nowrap;
}

.msg-group.out .msg-meta {
  flex-direction: row-reverse;
}

.msg-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1;
}

.msg-bubble.outgoing .msg-time {
  color: rgba(var(--msg-out-text), 0.6);
}

.msg-status {
  display: flex;
  align-items: center;
}

.msg-status svg {
  width: 14px;
  height: 14px;
}

.msg-status.sent     svg { color: rgba(255,255,255,0.5); }
.msg-status.delivered svg { color: rgba(255,255,255,0.7); }
.msg-status.read     svg { color: #60a5fa; }
.msg-status.failed   svg { color: var(--danger); }

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

.msg-bubble.outgoing .msg-edited {
  color: rgba(255,255,255,0.5);
}

/* ── Reply Quote ─────────────────────────────────────────── */
.msg-reply-quote {
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: var(--space-1);
  cursor: pointer;
  transition: background var(--duration-fast);
}

.msg-bubble.outgoing .msg-reply-quote {
  background: rgba(0,0,0,0.12);
  border-left-color: rgba(255,255,255,0.4);
}

.msg-bubble.incoming .msg-reply-quote {
  background: var(--bg-hover);
}

.msg-reply-quote:hover { opacity: 0.8; }

.msg-reply-author {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--accent);
  margin-bottom: 2px;
  display: block;
}

.msg-bubble.outgoing .msg-reply-author {
  color: rgba(255,255,255,0.8);
}

.msg-reply-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
  display: block;
}

.msg-bubble.outgoing .msg-reply-text {
  color: rgba(255,255,255,0.7);
}

/* ── Reactions ───────────────────────────────────────────── */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--space-1);
}

.reaction-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-fast);
  font-size: 13px;
  line-height: 1.4;
  min-height: 26px;
}

.reaction-pill:hover {
  background: var(--accent-muted);
  border-color: rgba(var(--accent-rgb), 0.3);
  transform: scale(1.08);
}

.reaction-pill.mine {
  background: var(--accent-muted);
  border-color: rgba(var(--accent-rgb), 0.35);
}

.reaction-count {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
}

/* ── Message Action Menu ─────────────────────────────────── */
.msg-actions {
  position: absolute;
  top: -44px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  opacity: 0;
  transform: translateY(4px) scale(0.92);
  transition: all var(--duration-base) var(--ease-spring);
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

.msg-group.out .msg-actions { right: 0; }
.msg-group.in  .msg-actions { left: 0; }

.msg-bubble:hover .msg-actions,
.msg-actions:hover {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.msg-action-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  transition: all var(--duration-fast);
}

.msg-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.msg-action-btn.danger:hover {
  background: var(--danger-muted);
  color: var(--danger);
}

.msg-action-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ── Quick Reaction Bar ──────────────────────────────────── */
.reaction-picker {
  position: absolute;
  top: -52px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  gap: 2px;
  padding: 6px;
  z-index: 20;
  animation: popIn var(--duration-base) var(--ease-spring);
}

.msg-group.out .reaction-picker { right: 0; }
.msg-group.in  .reaction-picker { left: 0; }

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.reaction-emoji-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: transform var(--duration-fast) var(--ease-spring);
}

.reaction-emoji-btn:hover {
  transform: scale(1.3);
  background: var(--bg-hover);
}

/* ── Context Menu (right-click) ──────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: calc(var(--z-modal) - 1);
  min-width: 200px;
  animation: popIn var(--duration-fast) var(--ease-spring);
}

.context-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  transition: background var(--duration-fast);
  cursor: pointer;
}

.context-item:hover { background: var(--bg-hover); }
.context-item.danger { color: var(--danger); }
.context-item.danger:hover { background: var(--danger-muted); }

.context-item svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  flex-shrink: 0;
}

.context-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-1) 0;
}

/* ── Chat List Item ──────────────────────────────────────── */
.chat-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--duration-fast);
  position: relative;
  border-bottom: 1px solid var(--border-subtle);
  min-height: 72px;
}

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

.chat-item:hover .chat-item-pin-btn {
  opacity: 1;
}

.chat-item-avatar {
  flex-shrink: 0;
  position: relative;
}

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

.chat-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: 3px;
}

.chat-item-name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-item-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-item-time.unread { color: var(--accent); font-weight: var(--weight-semibold); }

.chat-item-preview {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: space-between;
}

.chat-item-preview-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-item-preview-text.unread {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.chat-item-badges {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #0a0b0f;
  font-size: 10px;
  font-weight: var(--weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.unread-badge.muted {
  background: var(--text-muted);
  color: var(--bg-base);
}

.pin-icon {
  color: var(--text-muted);
  font-size: 13px;
  transform: rotate(45deg);
}

.mute-icon {
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Search Highlight ────────────────────────────────────── */
.highlight {
  background: rgba(var(--accent-rgb), 0.25);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}
