/* ==================== DIRECT MESSAGES / CHAT STYLES ==================== */

.chat-container {
  display: grid;
  grid-template-columns: 350px 1fr;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-md);
  height: calc(100vh - 120px);
  width: 100%;
  overflow: hidden;
  transition: var(--transition-normal);
}

/* Chat Sidebar (User List) */
.chat-sidebar-list {
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-primary);
}

.chat-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-secondary);
}

.chat-sidebar-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.chat-sidebar-header button {
  color: var(--text-primary);
  font-size: 1.25rem;
}

.conversations-list {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.empty-conversations-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-conversations-state i {
  width: 48px;
  height: 48px;
  stroke-width: 1;
}

/* Chat user item card */
.chat-user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  position: relative;
}

.chat-user-item:hover {
  background-color: var(--bg-secondary-hover);
}

.chat-user-item.active {
  background-color: var(--bg-secondary-hover);
}

.chat-user-avatar-wrap {
  position: relative;
  width: 56px;
  height: 56px;
}

.chat-user-avatar-wrap img {
  width: 56px;
  height: 56px;
  border-radius: var(--border-radius-pill);
}

/* Online Indicator status dot */
.online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #4cd964;
  border-radius: var(--border-radius-pill);
  border: 3px solid var(--bg-primary);
}

.chat-user-item-meta {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0; /* allows text-overflow */
}

.chat-user-item-meta .name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.chat-user-item-meta .username {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-item-meta .time {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.chat-user-item-meta .last-message {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

/* Unread dot layout */
.chat-user-item.unread .last-message {
  font-weight: 700;
  color: var(--text-primary);
}

.unread-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-blue);
  border-radius: var(--border-radius-pill);
  margin-left: 8px;
  flex-shrink: 0;
}

/* ==================== ACTIVE WINDOW PANEL ==================== */
.chat-main-window {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-primary);
  position: relative;
}

/* Unselected placeholder view */
.chat-unselected-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  text-align: center;
  padding: 40px;
}

.chat-unselected-state .icon-circle {
  width: 96px;
  height: 96px;
  border-radius: var(--border-radius-pill);
  border: 2px solid var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-unselected-state .icon-circle i {
  width: 44px;
  height: 44px;
  stroke-width: 1.5;
}

.chat-unselected-state h3 {
  font-size: 1.3rem;
  font-weight: 600;
}

.chat-unselected-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 280px;
}

.chat-unselected-state button {
  background-color: var(--accent-blue);
  color: white;
  padding: 10px 20px;
  border-radius: var(--border-radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  margin-top: 10px;
}

/* Chat Active State Area */
.chat-active-state {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-primary);
}

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

.chat-header-user img {
  width: 44px;
  height: 44px;
  border-radius: var(--border-radius-pill);
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-info .username {
  font-size: 0.95rem;
  font-weight: 600;
}

.chat-header-info .status {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.chat-header button {
  color: var(--text-primary);
  font-size: 1.25rem;
}

/* Chats History Scroll Window */
.chat-messages-scroll {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Messages Bubbles Layout */
.message-row {
  display: flex;
  width: 100%;
}

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

.message-row.received {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 60%;
  padding: 12px 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}

.message-row.sent .message-bubble {
  background-color: var(--bubble-sent);
  color: var(--bubble-sent-text);
  border-radius: 18px 18px 4px 18px;
}

.message-row.received .message-bubble {
  background-color: var(--bubble-received);
  color: var(--bubble-received-text);
  border-radius: 18px 18px 18px 4px;
}

/* Bubble image formatting */
.message-bubble.has-image {
  padding: 4px;
  border-radius: var(--border-radius-md);
  background-color: transparent !important;
  border: 1px solid var(--border-primary);
}

.message-bubble.has-image img {
  border-radius: var(--border-radius-md);
  max-height: 250px;
  width: 100%;
  object-fit: cover;
}

.message-bubble .img-caption {
  padding: 8px 12px;
  font-size: 0.88rem;
  background-color: var(--bubble-sent);
  color: var(--bubble-sent-text);
  border-radius: 0 0 var(--border-radius-md) var(--border-radius-md);
}

.message-row.received .message-bubble .img-caption {
  background-color: var(--bubble-received);
  color: var(--bubble-received-text);
}

/* Chat Input Toolbar */
.chat-input-bar {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-top: 1px solid var(--border-primary);
  gap: 16px;
  background-color: var(--bg-primary);
}

.chat-input-bar button {
  color: var(--text-primary);
}

.chat-input-bar button i {
  width: 24px;
  height: 24px;
}

.chat-input-bar input[type="text"] {
  flex-grow: 1;
  padding: 10px 16px;
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-pill);
  font-size: 0.88rem;
  background-color: var(--bg-secondary);
}

.chat-input-bar input[type="text"]:focus {
  background-color: var(--bg-primary);
}

.chat-input-bar #chat-send-btn {
  color: var(--accent-blue);
}

.chat-input-bar #chat-send-btn:disabled {
  opacity: 0.3;
}

/* Media preview window above input bar */
.chat-media-preview {
  position: absolute;
  bottom: 72px;
  left: 20px;
  right: 20px;
  background-color: var(--bg-modal);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-md);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-modal);
  z-index: 5;
  animation: slide-up-chat-preview 0.25s ease-out;
}

@keyframes slide-up-chat-preview {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.chat-media-preview img {
  max-height: 80px;
  border-radius: var(--border-radius-sm);
}

.chat-media-preview button {
  background-color: rgba(0, 0, 0, 0.5);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: var(--border-radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== RESPONSIVE CHAT VIEWS ==================== */
@media (max-width: 767px) {
  .chat-container {
    height: calc(100vh - 110px);
    grid-template-columns: 1fr; /* Stack sidebar and active box */
  }

  /* Single-panel toggles in JS */
  .chat-sidebar-list.mobile-hidden {
    display: none;
  }
  
  .chat-main-window.mobile-hidden {
    display: none;
  }
}
