/* ============ 消息通信 ============ */
.message-page {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  height: calc(100vh - 120px);
}

/* 会话列表 */
.conversation-list {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.conversation-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.conversation-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.conversation-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
}

.conversation-items {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid #f5f5f5;
}

.conversation-item:hover {
  background: #f5f7fa;
}

.conversation-item.active {
  background: #ecf5ff;
}

.conversation-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}

.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.conversation-name {
  font-weight: 500;
  font-size: 14px;
}

.conversation-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.conversation-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conversation-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.conversation-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 聊天区域 */
.chat-area {
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

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

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
}

.chat-avatar.chat-avatar-peer {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-size: 17px;
}

.chat-name {
  font-weight: 500;
}

.chat-status {
  font-size: 12px;
  color: var(--success);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f5f7fa;
}

.message-item {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  width: 100%;
  align-items: flex-start;
}

/* —— 微信式左右分侧 —— */
.message-item.other {
  flex-direction: row;          /* 对方：头像在左，靠左 */
  justify-content: flex-start;
}

.message-item.self {
  flex-direction: row-reverse;  /* 自己：头像在右，靠右 */
  justify-content: flex-start;
}

/* —— 头像：双方不同底色，一眼区分 —— */
.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 6px;          /* 微信式方圆头像 */
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.message-avatar.avatar-peer {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); /* 对方：紫色 */
}

.message-avatar.avatar-self {
  background: linear-gradient(135deg, #12b76a 0%, #039855 100%);  /* 自己：绿色 */
}

/* —— 气泡主体 —— */
.message-content {
  max-width: 62%;
  display: flex;
  flex-direction: column;
}

.message-item.other .message-content {
  align-items: flex-start;
}

.message-item.self .message-content {
  align-items: flex-end;
}

/* 发送者名字：始终知道对方是谁 */
.message-sender {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  padding: 0 4px;
  font-weight: 500;
}

.message-item.self .message-sender {
  text-align: right;
}

.message-item.other .message-sender {
  text-align: left;
}

.message-bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  word-break: break-word;
  white-space: pre-wrap;
}

/* 对方气泡：白底 + 左侧小三角指向头像 */
.message-item.other .message-bubble {
  background: #fff;
  color: #262626;
  border-top-left-radius: 2px;
}

.message-item.other .message-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid #fff;
}

/* 自己气泡：微信绿 + 右侧小三角指向头像 */
.message-item.self .message-bubble {
  background: #95ec69;           /* 微信经典绿 */
  color: #0e2b13;
  border-top-right-radius: 2px;
}

.message-item.self .message-bubble::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid #95ec69;
}

/* 自己气泡里的文件卡片配浅色底，避免绿底看不清 */
.message-item.self .message-bubble .chat-message-file {
  background: #ffffff !important;
  border-color: #d9f0c5 !important;
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
}

/* 消息输入区 */
.chat-input {
  border-top: 1px solid var(--border-color);
  padding: 16px 20px;
  background: #fff;
}

.chat-textarea {
  width: 100%;
  min-height: 60px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  resize: none;
  font-size: 14px;
  font-family: inherit;
}

.chat-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.chat-tools {
  display: flex;
  gap: 12px;
}

.chat-tool-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
}

.chat-tool-btn:hover {
  color: var(--primary);
}

.send-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.send-btn:hover {
  background: var(--primary-dark);
}

/* 消息气泡内的图片/文件 */
.chat-message-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 6px;
  display: block;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.08);
}

.chat-message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.chat-file-icon {
  font-size: 28px;
}

.chat-file-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
  max-width: 220px;
}

.chat-file-meta {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

/* 表情选择面板 */
.chat-emoji-panel {
  display: none;
  position: fixed;
  z-index: 1200;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  padding: 8px;
  width: 324px;
  grid-template-columns: repeat(9, 1fr);
  gap: 2px;
}

.chat-emoji-panel.open {
  display: grid;
}

.chat-emoji-item {
  font-size: 20px;
  line-height: 32px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}

.chat-emoji-item:hover {
  background: #f0f0f0;
}

/* 系统公告 */
.announcement-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.announcement-item {
  background: #fff;
  padding: 16px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.announcement-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.announcement-title {
  font-weight: 600;
  font-size: 15px;
}

.announcement-time {
  font-size: 12px;
  color: var(--text-secondary);
}

.announcement-content {
  color: var(--text-regular);
  font-size: 14px;
  line-height: 1.6;
}

/* 响应式 */
@media (max-width: 768px) {
  .message-page {
    grid-template-columns: 1fr;
    height: auto;
  }
  
  .conversation-list {
    height: 300px;
  }

  .message-content {
    max-width: 78%;
  }
}
