/* ========================================
   CHAT SELECTION MODE & THREADING
   ======================================== */

/* Selection mode overlay */
.selection-mode-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.selection-mode-overlay.visible {
  opacity: 1;
}

/* Dark backdrop behind everything */
.selection-mode-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: -1;
}

/* Selection controls */
.selection-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  gap: 20px;
  flex-wrap: wrap;
  position: relative;
  z-index: 100;
}

.selection-controls-left,
.selection-controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.selection-counter {
  font-size: 16px;
  font-weight: 600;
  color: white;
  padding: 8px 16px;
  background: rgba(145, 70, 255, 0.3);
  border-radius: var(--radius);
}

.selection-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.selection-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
}

.selection-btn span {
  font-size: 16px;
}

/* Selected message container */
.selected-message-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  overflow-y: auto;
  position: relative;
  z-index: 100;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.selected-message-container .chat-message,
.selected-message-container .chat-line {
  max-width: 800px;
  width: 100%;
  background: #18181b !important;
  border: 2px solid var(--accent, #9146ff);
  border-radius: var(--radius-lg, 12px);
  padding: 24px 32px;
  box-shadow: 0 10px 50px rgba(145, 70, 255, 0.3);
  line-height: 1.6;
  color: #efeff1 !important;
  opacity: 1 !important;
}

/* Force all text to be white with text shadow for visibility */
.selected-message-container .chat-message *:not(img),
.selected-message-container .chat-line *:not(img),
.selected-message-container .chat-message:not(img),
.selected-message-container .chat-line:not(img) {
  color: #efeff1 !important;
  opacity: 1 !important;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.5) !important;
}

.selected-message-container .chat-user,
.selected-message-container .chat-user-link,
.selected-message-container .username,
.selected-message-container .chat-msg,
.selected-message-container .message-text,
.selected-message-container span:not(.chat-emote),
.selected-message-container div,
.selected-message-container p,
.selected-message-container a {
  color: #ffffff !important;
  opacity: 1 !important;
  background: transparent !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8) !important;
}

/* Ensure emotes and images are visible */
.selected-message-container img {
  opacity: 1 !important;
}

/* Ensure badges are visible */
.selected-message-container .chat-badge,
.selected-message-container .badge {
  opacity: 1 !important;
}

.selected-enlarged {
  animation: slideIn 0.3s ease;
}

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

.selected-message-container .username {
  font-size: 1.2em;
  font-weight: 700;
  margin-bottom: 8px;
}

.selected-message-container .message-text {
  font-size: inherit;
  line-height: 1.8;
}

/* Reply button */
.reply-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
}

.reply-btn:hover {
  opacity: 1;
  background: var(--panel2);
  border-color: var(--accent);
}

/* Reply indicator */
.reply-indicator {
  display: none;
  padding: 12px 16px;
  background: var(--panel2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  animation: slideDown 0.3s ease;
}

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

.reply-indicator-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.reply-icon {
  font-size: 20px;
  flex-shrink: 0;
}

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

.reply-to {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

.reply-to strong {
  color: var(--accent);
}

.reply-preview {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel {
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.reply-cancel:hover {
  color: var(--text);
}

/* Thread indicator */
.thread-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(145, 70, 255, 0.1);
  border: 1px solid rgba(145, 70, 255, 0.3);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-left: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.thread-indicator:hover {
  background: rgba(145, 70, 255, 0.2);
  border-color: rgba(145, 70, 255, 0.5);
}

/* Thread modal */
.thread-modal-content {
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
}

.thread-messages {
  max-height: 60vh;
  overflow-y: auto;
  padding: 0;
}

.thread-message {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.thread-message:last-child {
  border-bottom: none;
}

.thread-message.thread-root {
  background: rgba(145, 70, 255, 0.05);
  border-left: 3px solid var(--accent);
}

.thread-message:not(.thread-root) {
  padding-left: 40px;
}

.thread-indent {
  position: absolute;
  left: 20px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

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

.thread-username {
  font-weight: 700;
  font-size: 14px;
}

.thread-timestamp {
  font-size: 11px;
  color: var(--muted);
}

.thread-message-text {
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .selection-controls {
    padding: 12px 16px;
  }
  
  .selection-controls-left,
  .selection-controls-right {
    gap: 8px;
  }
  
  .selection-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
  
  .selection-btn span {
    font-size: 14px;
  }
  
  .selected-message-container {
    padding: 20px 16px;
  }
  
  .selected-message-container .chat-message {
    padding: 16px 20px;
  }
  
  .thread-message:not(.thread-root) {
    padding-left: 30px;
  }
  
  .thread-indent {
    left: 15px;
  }
}

/* Smooth scrolling for navigation */
.selected-message-container {
  scroll-behavior: smooth;
}

/* Highlight effect when navigating */
.selected-enlarged {
  position: relative;
}

.selected-enlarged::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  background: linear-gradient(45deg, transparent, rgba(145, 70, 255, 0.2), transparent);
  border-radius: var(--radius-lg);
  z-index: -1;
  animation: pulse 2s ease infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

/* Chat message hover effect to show reply button */
.chat-message {
  position: relative;
  transition: background 0.2s ease;
}

.chat-message:hover {
  background: rgba(255, 255, 255, 0.02);
}

.chat-message:hover .reply-btn {
  opacity: 0.8;
}

/* Selection mode active cursor */
.selection-mode-overlay .selected-message-container {
  cursor: default;
}
/* Reply Box in Focused Mode */
.selection-reply-box {
  width: 100%;
  max-width: 800px;
  margin-top: 20px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selection-reply-box-label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.selection-reply-box-input {
  width: 100%;
  min-height: 80px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  transition: all 0.2s ease;
}

.selection-reply-box-input:focus {
  outline: none;
  border-color: var(--accent, #9146ff);
  box-shadow: 0 0 0 3px rgba(145, 70, 255, 0.2);
}

.selection-reply-box-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.selection-reply-box-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.selection-reply-box-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.selection-reply-box-btn-cancel {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.selection-reply-box-btn-cancel:hover {
  background: rgba(255, 255, 255, 0.15);
}

.selection-reply-box-btn-send {
  background: var(--accent, #9146ff);
  color: white;
}

.selection-reply-box-btn-send:hover {
  background: rgba(145, 70, 255, 0.9);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(145, 70, 255, 0.4);
}

.selection-reply-box-btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}