/* ============================================
   MESSAGE ACTIONS - Copy, Reply, Fork, Edit
   ============================================ */

/* Actions container - appears on hover */
.message-actions {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
  background: var(--bg-secondary, rgba(0,0,0,0.6));
  border-radius: var(--radius-sm);
  padding: 2px;
}

.message:hover .message-actions,
.message:focus-within .message-actions,
.message-actions:focus-within {
  opacity: 1;
}

/* Touch devices - always show */
@media (hover: none) {
  .message-actions {
    opacity: 0.7;
  }
}

/* Focus styles for action buttons */
.message-action-btn:focus {
  outline: 2px solid var(--accent, #6366f1);
  outline-offset: 2px;
  background: var(--bg-input, var(--white-10));
  color: var(--text, #fff);
}

.message-action-btn:focus-visible {
  outline: 2px solid var(--accent, #6366f1);
  outline-offset: 2px;
}

/* Action buttons - 44x44px minimum touch target (Apple HIG / WCAG 2.5.5) */
.message-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, rgba(255,255,255,0.5));
  cursor: pointer;
  padding: var(--space-1) 6px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-action-btn:hover {
  background: var(--bg-input, var(--white-10));
  color: var(--text, #fff);
}

.message-action-btn:active {
  transform: scale(0.95);
}

/* Tooltip on buttons */
.message-action-btn[title] {
  position: relative;
}

/* Reply context display */
.reply-context {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  background: var(--bg-secondary, var(--black-30));
  border-left: 3px solid var(--accent, #6366f1);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-sm);
  color: var(--text-muted, rgba(255,255,255,0.7));
}

.reply-context-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: 2.8em;
}

.reply-context-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  opacity: 0.7;
}

.reply-context-close:hover {
  opacity: 1;
  color: var(--text);
}

/* Reply indicator on messages */
.message-reply-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-1) var(--space-2);
  margin-bottom: var(--space-1);
  background: var(--bg-tertiary, var(--black-20));
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
}

.message-reply-indicator:hover {
  background: var(--bg-input, var(--white-10));
}

.message-reply-indicator::before {
  content: '↩';
  opacity: 0.6;
}

/* Message being replied to */
.message.replying-to {
  outline: 2px solid var(--accent, #6366f1);
  outline-offset: 2px;
  border-radius: var(--radius-lg, 12px);
}

/* Copy success animation */
.message-action-btn.copied {
  color: var(--success, #22c55e);
}

.message-action-btn.copied::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path stroke='none' d='M0 0h24v24H0z' fill='none'/><path d='M5 12l5 5l10 -10'/></svg>");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--success, #22c55e);
  padding: 4px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  animation: copyFade 1s ease forwards;
}

@keyframes copyFade {
  0% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* Fork dialog */
.fork-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary, #1a1a2e);
  border: 1px solid var(--border, var(--white-10));
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  min-width: 300px;
  max-width: 400px;
  z-index: var(--z-overlay);
  box-shadow: 0 20px 60px var(--black-50);
}

.fork-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--black-50);
  z-index: calc(var(--z-overlay) - 1);
}

.fork-dialog h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-base);
  color: var(--text);
}

.fork-dialog-preview {
  background: var(--bg-input, var(--black-30));
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-height: 100px;
  overflow: hidden;
}

.fork-dialog input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input, var(--black-30));
  border: 1px solid var(--border, var(--white-10));
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.fork-dialog input:focus {
  outline: none;
  border-color: var(--accent, #6366f1);
}

.fork-dialog-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.fork-dialog-actions button {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.fork-dialog-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.fork-dialog-cancel:hover {
  background: var(--bg-input);
}

.fork-dialog-confirm {
  background: var(--accent, #6366f1);
  border: none;
  color: white;
}

.fork-dialog-confirm:hover {
  opacity: 0.9;
}

/* Fork dialog focus styles */
.fork-dialog input:focus-visible,
.fork-dialog-cancel:focus-visible,
.fork-dialog-confirm:focus-visible {
  outline: 2px solid var(--accent, #6366f1);
  outline-offset: 2px;
}

/* Accessibility: Respect reduced motion preference (M-09) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
