/* ================================
   QUEST4YOU - Chat Page Styles
   ================================ */

/* Chat Container - Full height layout */
.chat-container {
  display: flex;
  height: calc(100vh - 70px);
  margin-top: 70px;
  background: var(--bg-light);
}

/* ================================
   CONVERSATIONS SIDEBAR
   ================================ */
.conversations-sidebar {
  width: 320px;
  background: white;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
  background: linear-gradient(135deg, var(--cardinal-red) 0%, var(--deep-purple) 100%);
  color: white;
}

.sidebar-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.unread-badge {
  background: white;
  color: var(--cardinal-red);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

.conversations-search {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.conversations-search .search-input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border-light);
  border-radius: 25px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.conversations-search .search-input:focus {
  border-color: var(--cardinal-red);
}

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

/* Conversation Item */
.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid var(--border-lighter);
  position: relative;
}

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

.conversation-item.active {
  background: linear-gradient(90deg, rgba(200, 55, 92, 0.1) 0%, rgba(92, 75, 107, 0.1) 100%);
  border-left: 3px solid var(--cardinal-red);
}

.conversation-item.unread {
  background: rgba(200, 55, 92, 0.05);
}

.conversation-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
}

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

.conversation-online {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #4caf50;
  border: 2px solid white;
}

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

.conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.conversation-name {
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-time {
  font-size: 0.75rem;
  color: var(--text-lighter);
  flex-shrink: 0;
}

.conversation-preview {
  font-size: 0.85rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item.unread .conversation-preview {
  font-weight: 600;
  color: var(--text-dark);
}

.conversation-unread-count {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: var(--cardinal-red);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Empty state */
.empty-conversations {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.empty-conversations .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-conversations .empty-hint {
  font-size: 0.85rem;
  margin: 8px 0 16px;
}

/* ================================
   FRIENDS LIST IN CHAT SIDEBAR
   ================================ */
.friend-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid var(--border-lighter);
  position: relative;
}

.friend-list-item:hover {
  background: var(--bg-light);
}

.friend-list-item:hover .friend-chat-action {
  opacity: 1;
}

.friend-preview {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.friend-nick-tag {
  font-size: 0.8rem;
  color: var(--text-lighter);
  display: inline-block;
}

.friend-has-conv {
  font-size: 0.78rem;
  color: var(--cardinal-red);
  opacity: 0.8;
}

.friend-new-conv {
  font-size: 0.78rem;
  color: var(--deep-purple);
  opacity: 0.8;
}

.friend-chat-action {
  font-size: 1.3rem;
  opacity: 0.3;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.friends-loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.friends-loading .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* ================================
   CHAT AREA
   ================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-light);
  min-width: 0;
}

/* No conversation selected */
.no-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  text-align: center;
  padding: 40px;
}

.no-conversation-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.5;
}

.no-conversation h3 {
  font-size: 1.4rem;
  margin-bottom: 8px;
  color: var(--text-dark);
}

/* Active Chat */
.active-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: white;
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn-back-mobile {
  display: none;
  background: none;
  border: none;
  color: var(--cardinal-red);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px;
}

.chat-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-user-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
}

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

.chat-user-details {
  display: flex;
  flex-direction: column;
}

.chat-user-name {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 1rem;
}

.chat-user-status {
  font-size: 0.8rem;
  color: #4caf50;
}

.chat-user-status.offline {
  color: var(--text-lighter);
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: var(--bg-light);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--border-light);
  transform: scale(1.1);
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(180deg, #f8f9fa 0%, #fff 100%);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.message.sent {
  align-self: flex-end;
}

.message.received {
  align-self: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.message.sent .message-bubble {
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
  background: white;
  color: var(--text-dark);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-lighter);
  margin-top: 4px;
  padding: 0 4px;
}

.message.sent .message-time {
  text-align: right;
}

/* ================================
   SYSTEM MESSAGE STYLES
   ================================ */
.message.system-message {
  align-self: center;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px 0;
}

.system-message-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 12px;
  box-shadow: 0 4px 15px rgba(229, 57, 53, 0.3);
}

.system-bubble {
  background: linear-gradient(135deg, rgba(229, 57, 53, 0.08) 0%, rgba(140, 35, 143, 0.08) 100%) !important;
  border: 1px solid rgba(229, 57, 53, 0.2) !important;
  color: var(--text-dark) !important;
  border-radius: 16px !important;
  padding: 20px 24px !important;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.6;
}

.system-bubble strong {
  color: var(--cardinal-red);
  font-weight: 600;
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
}

.date-separator span {
  background: var(--bg-light);
  color: var(--text-lighter);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.75rem;
}

/* ================================
   MESSAGE META (time + read status)
   ================================ */
.message-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}

.message.sent .message-meta {
  justify-content: flex-end;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-lighter);
}

.message-status {
  font-size: 0.7rem;
  font-weight: 600;
}

.message-status.sent {
  color: var(--text-lighter);
}

.message-status.read {
  color: #10b981;
}

/* Admin Delete Message Button */
.btn-delete-msg {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 4px;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  border-radius: 4px;
}

.message:hover .btn-delete-msg {
  opacity: 0.6;
}

.btn-delete-msg:hover {
  opacity: 1 !important;
  transform: scale(1.1);
  background: rgba(239, 68, 68, 0.1);
}

/* ================================
   TYPING INDICATOR - Enhanced
   ================================ */
.typing-indicator-wrapper {
  padding: 8px 16px;
  animation: fadeIn 0.3s ease;
}

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

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: white;
  border: 1px solid var(--border-light);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.typing-text {
  font-size: 0.8rem;
  color: var(--text-light);
}

.typing-text strong {
  color: var(--text-dark);
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--cardinal-red);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% { 
    transform: translateY(0); 
    opacity: 0.4;
  }
  30% { 
    transform: translateY(-4px); 
    opacity: 1;
  }
}

/* Message Input Area */
.message-input-area {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 20px;
  background: white;
  border-top: 1px solid var(--border-light);
}

.message-input-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 25px;
  padding: 8px 16px;
  transition: border-color 0.2s;
}

.message-input-wrapper:focus-within {
  border-color: var(--cardinal-red);
}

.message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  resize: none;
  max-height: 120px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}

.btn-emoji {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.btn-emoji:hover {
  opacity: 1;
}

.btn-send {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(200, 55, 92, 0.4);
}

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

.send-icon {
  font-size: 1.3rem;
}

/* Emoji Picker */
.emoji-picker {
  position: absolute;
  bottom: 80px;
  right: 80px;
  background: white;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

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

.emoji-grid span {
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  text-align: center;
  font-size: 1.3rem;
  transition: background 0.2s;
}

.emoji-grid span:hover {
  background: var(--bg-light);
}

/* ================================
   COMPARE RESULTS MODAL
   ================================ */
.modal-xl {
  max-width: 800px;
}

.compare-header {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 20px;
  background: var(--bg-light);
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.compare-user {
  text-align: center;
}

.compare-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
  font-weight: 600;
  margin: 0 auto 12px;
}

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

.compare-name {
  font-weight: 600;
  color: var(--text-dark);
}

.compare-vs {
  font-size: 1.5rem;
  color: var(--text-lighter);
  font-weight: 700;
}

.compare-body {
  max-height: 400px;
  overflow-y: auto;
}

.compare-quiz {
  background: white;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.compare-quiz-title {
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.compare-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compare-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.compare-bar-label {
  width: 100px;
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: right;
}

.compare-bar-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.compare-bar {
  flex: 1;
  height: 24px;
  background: var(--bg-light);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.compare-bar-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.5s ease;
}

.compare-bar-fill.user1 {
  background: linear-gradient(90deg, var(--cardinal-red), #e57373);
}

.compare-bar-fill.user2 {
  background: linear-gradient(90deg, var(--deep-purple), #9575cd);
}

.compare-bar-value {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 45px;
  text-align: center;
}

.compare-compatibility {
  text-align: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(200, 55, 92, 0.1) 0%, rgba(92, 75, 107, 0.1) 100%);
  border-radius: var(--radius-md);
  margin-top: 20px;
}

.compatibility-score {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cardinal-red), var(--deep-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.compatibility-label {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 4px;
}

.no-common-quizzes {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

.no-common-quizzes .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

/* ================================
   CHAT FOOTER
   ================================ */
.chat-footer {
  display: none;
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 768px) {
  .chat-container {
    flex-direction: column;
  }

  .conversations-sidebar {
    width: 100%;
    height: auto;
    max-height: 100%;
    position: absolute;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    transition: transform 0.3s ease;
  }

  .conversations-sidebar.hidden {
    transform: translateX(-100%);
  }

  .chat-area {
    position: absolute;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .btn-back-mobile {
    display: block;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .messages-container {
    padding: 12px;
  }

  .message {
    max-width: 85%;
  }

  .message-input-area {
    padding: 12px;
  }

  .emoji-picker {
    right: 16px;
    bottom: 70px;
  }

  .compare-header {
    flex-direction: column;
    gap: 16px;
  }

  .compare-vs {
    margin: 0;
  }

  .compare-bar-label {
    width: 80px;
    font-size: 0.75rem;
  }
}
