/* ==========================================
   DIRECT MESSAGES VIEW - PREMIUM GLASSMORPHISM
   ========================================== */

.chat-container {
  display: flex;
  height: calc(100vh - 60px); /* Adjust based on navbar height */
  margin-top: 0;
  background: radial-gradient(circle at top left, #1c1c2e, #0c0c14);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
}

/* Sidebar Inbox */
.inbox-panel {
  width: 350px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
}

.chat-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff, #8b9bb4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.conv-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.conv-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.conv-item.active {
  background: rgba(255, 255, 255, 0.08);
  border-left: 3px solid var(--primary-color, #ff2c55);
}

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.1);
}

.conv-details {
  flex: 1;
  min-width: 0;
}

.conv-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.conv-display-name {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.conv-msg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conv-last-message {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.unread-badge {
  background: var(--primary-color, #ff2c55);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(255, 44, 85, 0.4);
}

/* Chat Area */
.chat-area-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.2);
}

.chat-area-panel.empty {
  justify-content: center;
  align-items: center;
}

.chat-area-placeholder {
  text-align: center;
  max-width: 320px;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.chat-area-placeholder h3 {
  font-size: 20px;
  margin: 0 0 8px 0;
  color: #fff;
}

.chat-area-placeholder p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

/* Active Chat Thread */
.chat-thread-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-thread-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.01);
  backdrop-filter: blur(10px);
}

.back-to-inbox-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  margin-right: 14px;
  padding: 4px;
}

.chat-partner-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-partner-name {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}

.chat-partner-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-messages-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-bubble-wrapper {
  display: flex;
  width: 100%;
}

.message-bubble {
  max-width: 65%;
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.message-bubble-wrapper.bubble-me {
  justify-content: flex-end;
}

.message-bubble-wrapper.bubble-me .message-bubble {
  background: linear-gradient(135deg, #ff2c55, #d2143a);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(255, 44, 85, 0.2);
}

.message-bubble-wrapper.bubble-partner {
  justify-content: flex-start;
}

.message-bubble-wrapper.bubble-partner .message-bubble {
  background: linear-gradient(135deg, #007aff, #0056b3); /* Premium blue gradient */
  color: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
}

/* Chat Input */
.chat-input-bar {
  padding: 16px 20px;
  display: flex;
  gap: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.01);
  align-items: center;
}

.chat-input-bar input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 10px 16px;
  color: #fff;
  font-size: 16px; /* Prevents auto-zoom on iOS focused inputs */
  outline: none;
  transition: all 0.2s ease;
}

.chat-input-bar input:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.chat-input-bar button {
  background: var(--primary-color, #ff2c55);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-input-bar button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* General Layout helpers */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
  width: 100%;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary-color, #ff2c55);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.no-chats, .chat-error-msg {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 14px;
}

/* Responsive Mobile Layout overrides */
@media (max-width: 768px) {
  /* Hide main top bar and bottom nav when in active message thread */
  body.chat-thread-open .mobile-top-bar {
    display: none !important;
  }
  
  body.chat-thread-open .bottom-nav {
    display: none !important;
  }
  
  body.chat-thread-open .main-content {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }

  .chat-container {
    height: calc(100dvh - 56px - 60px - env(safe-area-inset-bottom));
    width: 100%;
    position: relative;
    overflow: hidden;
  }

  body.chat-thread-open .chat-container {
    height: 100dvh !important;
  }

  .inbox-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .chat-area-panel {
    display: none;
    position: absolute; /* relative to .chat-container stacking context */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: #0c0c14;
    flex-direction: column;
  }

  .chat-thread-view {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .chat-thread-header {
    padding-top: calc(12px + env(safe-area-inset-top, 16px));
    flex-shrink: 0;
  }

  .chat-messages-container {
    flex: 1;
    overflow-y: auto;
  }

  .chat-input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 16px));
    flex-shrink: 0;
  }

  /* Active Chat Switch on Mobile */
  .chat-container.active-chat .inbox-panel {
    display: none;
  }

  .chat-container.active-chat .chat-area-panel {
    display: flex;
  }

  .back-to-inbox-btn {
    display: block;
  }
}
 
/* Lock body scroll when chat is open to prevent page bounce */
body.chat-open {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}
