/* Chat styles */

.root {
  --bg-color: #f5f5f5;
  --surface-color: #ffffff;
  --border-color: #000000;
  --text-color: #333333;
  --muted-color: #888888;
  --primary-color: #ff5722;
}

.messenger-layout {
  max-height: 500px;
  display: flex;
  height: calc(100vh - 140px);
  /* Strictly constrain height so chat history scrolls */
  min-height: 400px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.messenger-sidebar {
  border-radius: 8px;
  border: 1px solid black;
  background-color: #ffffffef;
  flex: 3;
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.messenger-sidebar-header {
  padding: 16px;
  font-weight: 900;
  font-size: 18px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-color);
}

.messenger-main {
  max-height: 500px;
  flex: 7;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  min-height: 0;
  min-width: 0;
}

.chat-conversations {
  margin: 4px;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-conversation-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.2s;
}

.chat-conversation-item.active {
  background: var(--bg-color);
  border-left: 4px solid var(--brand);
}

.chat-conversation-item:hover {
  border-color: var(--brand);
  background: var(--bg-color);
}

.chat-conversation-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-conversation-user {
  font-weight: 800;
  font-size: 16px;
}

.chat-conversation-msg {
  color: var(--muted-color);
  font-size: 14px;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-window {
  border-radius: 8px;
  border: 1px solid black;
  background-color: white;
  max-height: 500px;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
  min-height: 0;
}

.chat-history {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-color);
  min-height: 0;
}

.chat-msg {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-msg--mine {
  align-self: flex-end;
  background: var(--brand, #ff5722);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-msg--theirs {
  align-self: flex-start;
  background: var(--surface-color, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  color: var(--text-color, #333);
  border-bottom-left-radius: 2px;
}

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
}

.chat-input-bar .input {
  flex: 1;
}

.messenger-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.messenger-back-btn {
  display: none;
}

@media (max-width: 700px) {
  .messenger-layout {
    height: calc(100vh - 210px);
    min-height: 420px;
    max-height: none;
  }

  .messenger-layout.has-active-chat .messenger-sidebar {
    display: none;
  }

  .messenger-layout.has-active-chat .messenger-main {
    display: flex;
    flex: 1;
  }

  .messenger-layout:not(.has-active-chat) .messenger-main {
    display: none;
  }

  .messenger-layout:not(.has-active-chat) .messenger-sidebar {
    display: flex;
    flex: 1;
    border-right: 0;
  }

  .messenger-back-btn {
    display: inline-flex;
    border: 1px solid var(--border-color);
    background: #fff;
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: 800;
  }
}

/* Avatars: Gravatar / custom in sidebar & bubbles; initials when no custom (mine) or image error */
.chat-peer-avatar,
.chat-bubble-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #eef2ff;
}

.chat-bubble-avatar {
  width: 28px;
  height: 28px;
}

.chat-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, var(--brand, #5b6cf0), #8b5cf6);
  user-select: none;
}

.chat-avatar-fallback--lg {
  width: 44px;
  height: 44px;
  font-size: 14px;
}

.chat-avatar-fallback--sm {
  width: 28px;
  height: 28px;
  font-size: 10px;
}