/* ===== CHAT / MESSAGES ===== */
.chat-layout {
  display: flex !important;
  gap: 0;
  height: calc(100vh - var(--topbar-height) - 4rem);
  padding: 0 !important;
  overflow: hidden;
}

#section-messages:not(.section-active) {
  display: none !important;
}

/* Chat Sidebar */
.chat-sidebar {
  width: 320px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--border-radius) 0 0 var(--border-radius);
  border-right: 1px solid var(--glass-border);
}

.chat-search {
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-search input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  color: white;
  font-size: 0.9rem;
}

.chat-search input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
}

body.light-mode .chat-search input {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
}

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

.chat-item {
  display: flex;
  padding: 14px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  transition: var(--transition);
  align-items: center;
}

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

.chat-item.active {
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid var(--primary);
}

body.light-mode .chat-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

body.light-mode .chat-item.active {
  background: rgba(99, 102, 241, 0.08);
}

.avatar-container {
  position: relative;
  flex-shrink: 0;
}

.avatar-container img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.online-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: #10b981;
  border: 2px solid var(--glass-bg);
  border-radius: 50%;
}

.chat-item-content {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.chat-item-content h4 {
  font-size: 0.95rem;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-content p {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
}

/* Chat Window */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  overflow: hidden;
}

.chat-empty-window {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 2rem;
}

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

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

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

.chat-user-info img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.chat-user-info h3 {
  font-size: 1rem;
  margin-bottom: 2px;
}

.online-status {
  font-size: 0.8rem;
  color: #10b981;
}

.chat-messages {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 0.2s ease;
}

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

.msg-content {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.sent .msg-content {
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  border-bottom-right-radius: 4px;
}

.received .msg-content {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
}

body.light-mode .received .msg-content {
  background: rgba(0, 0, 0, 0.04);
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.sent .msg-time {
  align-self: flex-end;
}
.received .msg-time {
  align-self: flex-start;
}

.chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 24px;
  padding: 12px 20px;
  color: white;
  font-size: 0.92rem;
  transition: var(--transition);
}

.chat-input-area input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(99, 102, 241, 0.3);
}

body.light-mode .chat-input-area input {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
}

body.light-mode .chat-input-area input:focus {
  background: rgba(0, 0, 0, 0.06);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white !important;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.send-btn:hover {
  background: #4f46e5;
  transform: scale(1.05);
}

/* Responsive */
@media (max-width: 768px) {
  .chat-layout {
    flex-direction: column;
  }
  .chat-sidebar {
    width: 100%;
    min-width: 100%;
    height: 240px;
    flex: none;
    border-radius: var(--border-radius);
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
  }
  .chat-window {
    border-radius: var(--border-radius);
  }
}
