/**
 * Chat System Styles
 * Facebook Messenger-style floating chat windows
 */

/* ============================================
   Chat Container - Bottom Right Positioning
   ============================================ */
.chat-container {
  position: fixed;
  bottom: 0;
  right: 20px;
  display: flex;
  flex-direction: row-reverse;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
}

.chat-container > * {
  pointer-events: all;
}

/* ============================================
   Chat Widget - Individual Conversation Window
   ============================================ */
.chat-widget {
  width: 328px;
  max-height: 400px;
  background: var(--color-canvas-default, #0d1117);
  border: 1px solid var(--color-border-default, #30363d);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.chat-widget.minimized {
  max-height: 48px;
}

/* Widget Header */
.chat-widget-header {
  background: var(--color-canvas-subtle, #161b22);
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.chat-widget-header:hover {
  background: var(--color-canvas-inset, #21262d);
}

.chat-widget-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
}

.chat-widget-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent-fg);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-widget-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success-emphasis);
  border: 2px solid var(--color-canvas-default);
  position: relative;
  margin-left: -10px;
  margin-top: 18px;
}

.chat-widget-status.offline {
  background: var(--color-neutral-muted);
}

.chat-widget-actions {
  display: flex;
  gap: 4px;
}

.chat-widget-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--color-fg-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget-btn:hover {
  background: var(--color-neutral-muted);
  color: var(--color-fg-default);
}

/* Widget Body - Messages Area */
.chat-widget-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 280px;
}

/* Message Bubble */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.chat-message.outgoing {
  align-self: flex-end;
}

.chat-message.incoming {
  align-self: flex-start;
}

.chat-message-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  word-wrap: break-word;
  position: relative;
}

.chat-message.outgoing .chat-message-bubble {
  background: var(--color-accent-emphasis, #1f6feb);
  color: var(--color-fg-on-emphasis, #0b0f17);
  border-bottom-right-radius: 4px;
}

.chat-message.incoming .chat-message-bubble {
  background: var(--color-canvas-subtle, #161b22);
  color: var(--color-fg-default, #e6edf3);
  border-bottom-left-radius: 4px;
}

.chat-message-text {
  font-size: 14px;
  line-height: 1.4;
  margin: 0;
}

.chat-message-text a {
  color: inherit;
  text-decoration: underline;
}

.chat-message.outgoing .chat-message-text a {
  color: inherit;
}

.chat-message-timestamp {
  font-size: 11px;
  color: var(--color-fg-muted);
  margin-top: 4px;
}

.chat-message.outgoing .chat-message-timestamp {
  text-align: right;
}

/* Typing Indicator */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--color-canvas-subtle);
  border-radius: 16px;
  width: fit-content;
  border-bottom-left-radius: 4px;
}

.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-fg-muted);
  animation: typing-bounce 1.4s infinite;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* Widget Footer - Input Area */
.chat-widget-footer {
  border-top: 1px solid var(--color-border-default, #30363d);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-widget-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  font-family: inherit;
  background: transparent;
  color: var(--color-fg-default, #e6edf3);
}

.chat-widget-input::placeholder {
  color: var(--color-fg-muted, #8b949e);
}

.chat-widget-send {
  background: var(--color-accent-emphasis);
  color: var(--color-fg-on-emphasis, #0b0f17);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-widget-send:hover {
  background: var(--color-accent-muted);
}

.chat-widget-send:disabled {
  background: var(--color-neutral-muted);
  cursor: not-allowed;
}

/* ============================================
   Chat Sidebar - Conversations List
   ============================================ */
.chat-sidebar {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100vh;
  background: var(--color-canvas-default, #0d1117);
  border-left: 1px solid var(--color-border-default, #30363d);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.5);
  z-index: 999;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.chat-sidebar.open {
  right: 0;
}

/* Sidebar Header */
.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-sidebar-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.chat-sidebar-close {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--color-fg-muted);
  border-radius: 6px;
}

.chat-sidebar-close:hover {
  background: var(--color-neutral-muted);
  color: var(--color-fg-default);
}

/* Search Bar */
.chat-sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
}

.chat-sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border-default, #30363d);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  background: var(--color-canvas-default, #0d1117);
  color: var(--color-fg-default, #e6edf3);
}

.chat-sidebar-search input:focus {
  border-color: var(--color-accent-emphasis, #1f6feb);
}

/* Conversations List */
.chat-sidebar-body {
  flex: 1;
  overflow-y: auto;
}

.chat-conversation-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s;
}

.chat-conversation-item:hover {
  background: var(--color-canvas-subtle, #161b22);
}

.chat-conversation-item.active {
  background: var(--color-accent-subtle, rgba(31, 111, 235, 0.15));
}

.chat-conversation-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-accent-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-accent-fg);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.chat-conversation-status {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-success-emphasis);
  border: 2px solid var(--color-canvas-default);
  position: absolute;
  bottom: 0;
  right: 0;
}

.chat-conversation-status.offline {
  background: var(--color-neutral-muted);
}

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

.chat-conversation-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

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

.chat-conversation-time {
  font-size: 12px;
  color: var(--color-fg-muted);
}

.chat-conversation-unread {
  background: var(--color-accent-emphasis);
  color: var(--color-fg-on-emphasis, #0b0f17);
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

/* Chat toggle button uses btn-icon class from header */

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
  .chat-widget {
    width: 100vw;
    max-width: none;
    right: 0;
    border-radius: 0;
  }

  .chat-container {
    right: 0;
    left: 0;
  }

  .chat-sidebar {
    width: 100vw;
    right: -100vw;
  }

  .chat-sidebar.open {
    right: 0;
  }
}

/* ============================================
   Empty State
   ============================================ */
.chat-empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--color-fg-muted);
}

.chat-empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.chat-empty-state p {
  margin: 0;
  font-size: 14px;
}

/* ============================================
   User Search Modal
   ============================================ */
.chat-user-search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-user-search-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.chat-user-search-content {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  background: var(--color-canvas-default, #0d1117);
  border: 1px solid var(--color-border-default, #30363d);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-user-search-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-user-search-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.chat-user-search-close {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--color-fg-default, #e6edf3);
  border-radius: 4px;
}

.chat-user-search-close:hover {
  background: var(--color-neutral-muted, rgba(110, 118, 129, 0.4));
}

.chat-user-search-input-wrapper {
  padding: 16px;
  border-bottom: 1px solid var(--color-border-default, #30363d);
}

.chat-user-search-input-wrapper input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border-default, #30363d);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  background: var(--color-canvas-subtle, #161b22);
  color: var(--color-fg-default, #e6edf3);
}

.chat-user-search-input-wrapper input:focus {
  border-color: var(--color-accent-emphasis, #1f6feb);
}

.chat-user-search-results {
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
}

.chat-user-search-hint {
  padding: 32px 16px;
  text-align: center;
  color: var(--color-fg-muted, #8b949e);
  font-size: 14px;
}

.chat-user-search-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.chat-user-search-item:hover {
  background: var(--color-canvas-subtle, #161b22);
}

.chat-user-search-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-user-search-info {
  flex: 1;
  min-width: 0;
}

.chat-user-search-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-fg-default, #e6edf3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-search-username {
  font-size: 12px;
  color: var(--color-fg-muted, #8b949e);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-search-online {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-success-emphasis, #2da44e);
  border: 2px solid var(--color-canvas-default, #0d1117);
  flex-shrink: 0;
}

.chat-user-search-section {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-fg-muted, #8b949e);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--color-canvas-subtle, #161b22);
  border-top: 1px solid var(--color-border-default, #30363d);
  border-bottom: 1px solid var(--color-border-default, #30363d);
  margin-top: 8px;
}

.chat-user-search-section:first-child {
  margin-top: 0;
}
