/* Messages Page Styles */

.messages-main {
  min-height: calc(100vh - 80px);
  padding-top: 80px;
  background: var(--background-primary);
}

.messages-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
  height: calc(100vh - 80px);
}

.messages-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  height: 100%;
  background: var(--card-background);
  border-radius: 0;
  overflow: hidden;
}

/* Conversations Sidebar */
.conversations-sidebar {
  background: var(--background-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-background);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text-primary);
}

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

/* Conversation Item */
.conversation-item {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

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

.conversation-item.active {
  background: var(--card-background);
  border-left: 3px solid var(--accent-purple);
}

.conversation-item.unread {
  background: var(--background-tertiary);
}

.conversation-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conversation-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.conversation-username {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.conversation-last-message {
  color: var(--text-secondary);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.conversation-item.unread .conversation-last-message {
  font-weight: 600;
  color: var(--text-primary);
}

.unread-badge {
  background: var(--accent-purple);
  color: white;
  border-radius: 12px;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
  margin-left: 0.5rem;
}

/* Message Thread */
.message-thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
}

.empty-state svg {
  opacity: 0.5;
}

.empty-state h3 {
  margin: 0;
  color: var(--text-secondary);
}

.empty-state p {
  margin: 0;
  font-size: 0.875rem;
}

/* Conversation Container */
.conversation-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.conversation-container.hidden {
  display: none;
}

.conversation-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card-background);
}

.btn-back {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: none;
  border-radius: 0.5rem;
  transition: all 0.2s;
}

.btn-back:hover {
  background: var(--background-tertiary);
  color: var(--text-primary);
}

.conversation-user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

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

.conversation-user-info h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
}

.user-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.user-status.online {
  color: var(--success-color);
}

/* Messages List */
.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--background-primary);
}

/* Individual Message */
.message {
  display: flex;
  gap: 0.75rem;
  max-width: 70%;
  animation: messageSlideIn 0.3s ease-out;
}

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

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

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.received .message-bubble {
  background: var(--card-background);
  color: var(--text-primary);
  border-bottom-left-radius: 0.25rem;
}

.message.sent .message-bubble {
  background: var(--accent-purple);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.message-text {
  margin: 0;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message-timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

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

/* Message Input */
.message-input-container {
  padding: 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--card-background);
}

.message-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}

#messageInput {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  background: var(--background-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.2s;
}

#messageInput:focus {
  outline: none;
  border-color: var(--accent-purple);
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent-purple);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-send:hover {
  background: var(--accent-purple-hover);
  transform: scale(1.05);
}

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

.btn-send:disabled {
  background: var(--background-tertiary);
  cursor: not-allowed;
  transform: none;
}

/* Button Icon */
.btn-icon {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 0.5rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--background-tertiary);
  color: var(--text-primary);
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  gap: 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Date Divider */
.date-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.date-divider::before,
.date-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 0.75rem;
  max-width: 70%;
  align-self: flex-start;
}

.typing-indicator .message-avatar {
  width: 32px;
  height: 32px;
}

.typing-bubble {
  background: var(--card-background);
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  display: flex;
  gap: 0.25rem;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  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);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .messages-layout {
    grid-template-columns: 1fr;
  }

  .conversations-sidebar {
    border-right: none;
  }

  .conversations-sidebar.hide-mobile {
    display: none;
  }

  .message-thread.show-mobile {
    display: flex;
  }

  .btn-back {
    display: flex;
  }

  .message {
    max-width: 85%;
  }

  .conversation-header {
    padding: 1rem;
  }

  .sidebar-header {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .message {
    max-width: 95%;
  }

  .message-input-container {
    padding: 1rem;
  }

  .messages-list {
    padding: 1rem;
  }
}
