.chat-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* Left Sidebar */
.chat-sidebar-left {
  width: 280px;
  background: white;
  border-right: 1px solid #eee;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eee;
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s ease;
  position: relative;
}

.conv-item:hover {
  background: var(--bg-body);
}

.conv-item.active {
  background: var(--menu-bg);
  border-left: 3px solid var(--primary-purple);
}

.conv-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.conv-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-company {
  font-size: 0.75rem;
  color: var(--text-grey);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-unread {
  width: 8px;
  height: 8px;
  background: var(--primary-purple);
  border-radius: 50%;
  flex-shrink: 0;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: white;
  border-bottom: 1px solid #eee;
}

.back-btn-mobile {
  display: none;
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-grey);
}

.chat-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
}

.chat-contact-info {
  flex: 1;
}

.chat-contact-info h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.chat-contact-info span {
  font-size: 0.75rem;
  color: var(--text-grey);
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
}

.chat-action-btn {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text-grey);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.chat-action-btn:hover {
  background: var(--bg-body);
  color: var(--primary-purple);
}

/* Messages */
.chat-messages {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  display: flex;
  max-width: 70%;
}

.message.me {
  align-self: flex-end;
}

.message.them {
  align-self: flex-start;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  position: relative;
}

.message.me .message-bubble {
  background: var(--primary-purple);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.message.them .message-bubble {
  background: white;
  color: var(--text-dark);
  border-bottom-left-radius: 0.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message-bubble p {
  font-size: 0.875rem;
  line-height: 1.4;
  margin-bottom: 0.25rem;
}

.message-time {
  font-size: 0.65rem;
  opacity: 0.7;
  display: block;
  text-align: right;
}

/* Chat Input */
.chat-input-container {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: white;
  border-top: 1px solid #eee;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #eee;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  outline: none;
  border-color: var(--primary-purple);
}

.send-btn {
  background: var(--primary-purple);
  color: white;
  border: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.send-btn:hover {
  background: var(--primary-purple-dark);
}

/* Right Sidebar */
.chat-sidebar-right {
  width: 280px;
  background: white;
  border-left: 1px solid #eee;
  padding: 1.5rem;
  display: none;
  flex-direction: column;
  gap: 1.5rem;
  flex-shrink: 0;
  overflow-y: auto;
  padding-bottom: 6rem;
  transition: transform 0.3s ease;
}

.chat-sidebar-right.show {
  display: flex;
}

.contact-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
}

.profile-avatar {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  object-fit: cover;
}

.contact-profile h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.contact-details {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.detail-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  color: var(--text-grey);
}

.detail-item svg {
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.detail-item>div {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.125rem;
}

.detail-value {
  font-size: 0.875rem;
  color: var(--text-dark);
  font-weight: 500;
}

.contact-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.contact-action-btn {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.contact-action-btn.primary {
  background: var(--primary-purple);
  color: white;
  border: none;
}

.contact-action-btn.primary:hover {
  background: var(--primary-purple-dark);
}

.contact-action-btn.outline {
  background: transparent;
  color: var(--text-grey);
  border: 1px solid #ddd;
}

.contact-action-btn.outline:hover {
  border-color: #ccc;
  color: var(--text-dark);
}

/* Mobile Responsive */
@media (max-width: 1024px) {
  .chat-sidebar-right {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  }

  .chat-sidebar-right.show {
    transform: translateX(0);
  }
}

@media (max-width: 768px) {
  .chat-sidebar-left {
    display: none;
  }

  .back-btn-mobile {
    display: flex;
  }

  .chat-layout {
    height: calc(100vh - 120px);
  }

  .message {
    max-width: 85%;
  }
}

/* ─── Avatar initials fallback ─── */
.avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-purple, #7c3aed), #a855f7);
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

.conv-avatar.avatar-initials {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.8rem;
}

.chat-avatar.avatar-initials {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.8rem;
}

.profile-avatar.avatar-initials {
  width: 5rem;
  height: 5rem;
  font-size: 1.25rem;
}

/* ─── Loading / empty state ─── */
.conv-loading,
.chat-loading {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-grey);
  font-size: 0.875rem;
}

/* ─── Message read status ─── */
.message-status {
  opacity: 0.75;
}

/* ─── Send button disabled ─── */
.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ─── Right sidebar always-flex on desktop ─── */
@media (min-width: 1025px) {
  .chat-sidebar-right {
    display: flex;
  }
}