/* chat_room.css */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px); /* 减去顶部导航和标题高度 */
  margin-top: 20px;
  width: 100%;
  max-width: 800px; /* 限制聊天区域最大宽度 */
  margin: 0 auto;
  padding: 0 16px; /* 小屏留边距 */
}

.notification-bar {
  width: auto; /* 根据需求调整宽度 */
  float: left; /* 或者使用 flexbox 布局 */
  box-sizing: border-box;
  padding: 10px;
}


.chat-box {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
}

/* 消息容器 */
.message {
  margin-bottom: 12px;
  opacity: 0;
  animation: fadeIn 0.3s ease-out forwards;
}

/* 系统消息 */
.message.system {
  text-align: center;
  font-size: 0.875rem;
  color: #666;
  margin: 12px 0;
  animation-name: scaleIn;
}

.message.system .system {
  background-color: #eef2ff;
  padding: 4px 10px;
  border-radius: 12px;
  display: inline-block;
  font-weight: 500;
}

/* 头像容器 */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
  /* 👇 与 .text 顶部对齐 */
  margin-top: 20px; /* 与 .user 高度 + margin-bottom 一致 */
}

/* 头像与内容顺序控制 */
.message.chat .avatar {
  order: 0;
}

.message.chat .content {
  order: 1;
}

.message.chat.me .avatar {
  order: 1;
  margin-left: 8px;
}

.message.chat.me .content {
  order: 0;
}

/* 聊天消息通用样式 */
.message.chat {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* 我的消息：整体靠右 */
.message.chat.me {
  justify-content: flex-end;
  /* animation-name: slideInRight; */
}

/* 他人消息：靠左（默认） */
.message.chat.other {
  justify-content: flex-start;
  /* animation-name: slideInLeft; */
}

/* 内容包裹容器 */
.message.chat .content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 70%;
  min-width: 0;
  /* 关键：让 .content 的“对齐基准”从 .text 开始 */
  margin-top: 20px; /* 临时占位，稍后用负 margin 抵消 */
  position: relative;
}

.message.chat.me .content {
  align-items: flex-end; /* 自己的消息内容右对齐 */
}

/* 用户名 */
.message .user {
  font-size: 0.75rem;
  font-weight: bold;
  color: #555;
  background-color: #e0e0e0;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  margin-bottom: 4px;

  /* 👇 关键：绝对定位，让它脱离文档流 */
  position: absolute;
  top: -20px; /* 提到 .content 上方 */
  left: 0;
}

.message.chat.me .user {
  background-color: #d1e7ff;
  color: #1a73e8;
  left: auto;
  right: 0;
}

/* 消息文本 */
.message .text {
  background-color: white;
  padding: 8px 12px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  word-wrap: break-word;
  line-height: 1.4;
  width: fit-content;
  max-width: 100%;
}

.message.chat.me .text {
  background-color: #e3f2fd; /* 浅蓝色背景表示自己 */
  align-items: flex-end;
}

/* 时间戳 */
.message .time {
  font-size: 0.7rem;
  color: #999;
  margin-top: 4px;
  align-self: flex-end; /* 在 content 内靠右（me）或靠左（other） */
}

/* 输入区域 */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid #eee;
}

#message-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 20px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#message-input:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

#send-button {
  padding: 10px 20px;
  background-color: #1a73e8;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

#send-button:hover {
  background-color: #1557b0;
}

#send-button:active {
  transform: scale(0.98);
}

/* 动画定义 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 滚动条美化（可选） */
.chat-box::-webkit-scrollbar {
  width: 6px;
}
.chat-box::-webkit-scrollbar-track {
  background: #f1f1f1;
}
.chat-box::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}
.chat-box::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}

/* 响应式：小屏调整 */
@media (max-width: 600px) {
  .chat-container {
    height: calc(100vh - 100px);
    padding: 0 12px;
  }

  .message .text {
    max-width: 85%;
  }

  #message-input,
  #send-button {
    font-size: 0.95rem;
  }
}