/**
 * chat.css — 私信系统样式（整合去重版）
 * ---------------------------------------------------------------------------
 * 从 style.css 提取并去重：对话列表、聊天气泡、输入框、图片、暗色模式。
 * ---------------------------------------------------------------------------
 */

/* ---- CSS 自定义属性 ---- */
:root {
  --chat-bubble-max-width: 75%;
  --chat-bubble-max-width-page: 60%;
  --chat-bubble-max-width-mobile: 80%;
  --chat-bubble-img-max: 200px;
  --chat-bubble-img-max-page: 280px;
  --chat-font-size: 13px;
  --chat-page-font-size: 14px;
}

/* ================================================================
   对话列表
   ================================================================ */
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
}
.chat-conv-item:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}
.chat-conv-item.is-active {
  border-left: 3px solid var(--color-primary);
}

.chat-conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chat-conv-avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chat-conv-info {
  flex: 1;
  min-width: 0;
}
.chat-conv-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-conv-preview {
  font-size: 13px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.chat-conv-time {
  font-size: 12px;
  color: var(--color-text-muted);
}
.chat-conv-badge {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}
.chat-conv-list { list-style: none; margin: 0; padding: 0; }

/* ================================================================
   聊天气泡（基础样式）
   ================================================================ */
.chat-messages-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  min-height: 200px;
}

.chat-bubble {
  max-width: var(--chat-bubble-max-width);
  padding: 8px 12px;
  border-radius: 14px;
  font-size: var(--chat-font-size);
  line-height: 1.5;
  word-break: break-word;
}
.chat-bubble-mine {
  align-self: flex-end;
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble-theirs {
  align-self: flex-start;
  background: var(--color-card, #fff);
  color: var(--color-text, #1f2937);
  border: 1px solid var(--color-border, #e5e7eb);
  border-bottom-left-radius: 4px;
}
.chat-bubble-time {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 2px;
}
.chat-bubble-mine .chat-bubble-time { color: rgba(255,255,255,0.7); text-align: right; }
.chat-bubble-date {
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  padding: 6px 0;
  align-self: center;
}
.chat-bubble-content { word-break: break-word; }
.chat-bubble-img {
  display: block;
  max-width: var(--chat-bubble-img-max);
  max-height: var(--chat-bubble-img-max);
  border-radius: 8px;
  cursor: pointer;
  object-fit: cover;
}

/* ---- 纯图片气泡：无背景无边框 ---- */
.chat-bubble-img-only {
  background: none !important;
  border: none !important;
  padding: 0 !important;
  box-shadow: none !important;
}
.chat-bubble-img-only .chat-bubble-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
}
.chat-page-messages .chat-bubble-img-only .chat-bubble-img {
  max-width: 300px;
  max-height: 300px;
}
.chat-bubble-img-only .chat-bubble-time {
  padding: 0 2px;
}

/* ---- 加载更早消息 ---- */
.chat-load-more { text-align: center; padding: 6px 0; }
.chat-load-more-btn {
  background: none;
  border: none;
  color: var(--color-primary, #3b82f6);
  cursor: pointer;
  font-size: 12px;
}
.chat-load-more-btn:hover { text-decoration: underline; }

/* ---- 图片上传/失败状态 ---- */
.msg-img-uploading,
.msg-img-error {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  padding: 8px 0;
}
.chat-bubble-theirs .msg-img-uploading,
.chat-bubble-theirs .msg-img-error { color: var(--color-text-muted); }

/* ================================================================
   聊天输入框（基础样式 — widget 版本）
   ================================================================ */
.msg-chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-card, #fff);
  align-items: flex-end;
  flex-shrink: 0;
}
.msg-chat-textarea {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: var(--chat-font-size);
  font-family: inherit;
  resize: none;
  max-height: 72px;
  line-height: 1.4;
  background: var(--color-surface, #f9fafb);
  color: var(--color-text, #1f2937);
}
.msg-chat-textarea:focus { outline: none; border-color: var(--color-primary); }
.msg-chat-send {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  transition: background 0.15s, opacity 0.15s;
}
.msg-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.msg-chat-send:hover:not(:disabled) { background: var(--color-primary-dark, #2563eb); }

/* ---- 图片发送按钮 ---- */
.msg-chat-img-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.msg-chat-img-btn:hover { opacity: 1; }

/* ================================================================
   悬浮窗跳转按钮
   ================================================================ */
.msg-goto-page {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
  line-height: 1;
}
.msg-goto-page:hover { background: rgba(0,0,0,0.06); color: var(--color-primary); }

/* ================================================================
   独立聊天页面布局
   ================================================================ */
.chat-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.chat-page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}
.chat-page-header .chat-back {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
}
.chat-page-header .chat-back:hover { color: var(--color-primary); }

.chat-page {
  display: flex;
  height: calc(100vh - 64px - 80px);
  background: var(--color-surface, #f9fafb);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border, #e5e7eb);
}
.chat-page-sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border, #e5e7eb);
  display: flex;
  flex-direction: column;
  background: var(--color-card, #fff);
  overflow: hidden;
}
.chat-page-sidebar-head {
  padding: 16px 18px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  flex-shrink: 0;
}
.chat-page-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.chat-page-sidebar-list .chat-conv-item { margin-bottom: 6px; }
.chat-page-sidebar-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
  font-size: 14px;
}

.chat-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--color-surface, #f9fafb);
}
.chat-page-main-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card, #fff);
  flex-shrink: 0;
}
.chat-page-main-head .chat-page-back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
}
.chat-page-main-head img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.chat-page-main-head .chat-page-peer-name {
  font-weight: 600;
  font-size: 15px;
}
.chat-page-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: none;
}
.chat-page-messages::-webkit-scrollbar { display: none; }

/* ---- 页面版气泡覆盖 ---- */
.chat-page-messages .chat-bubble {
  max-width: var(--chat-bubble-max-width-page);
}
.chat-page-messages .chat-bubble-img {
  max-width: var(--chat-bubble-img-max-page);
  max-height: var(--chat-bubble-img-max-page);
}

/* ---- 页面版输入框覆盖 ---- */
.chat-page-input {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-card, #fff);
  align-items: flex-end;
  flex-shrink: 0;
}
.chat-page-input .msg-chat-textarea {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 8px 16px;
  font-size: var(--chat-page-font-size);
  max-height: 80px;
  resize: none;
  background: var(--color-surface, #f9fafb);
  color: var(--color-text, #1f2937);
}
.chat-page-input .msg-chat-textarea:focus { outline: none; border-color: var(--color-primary); }
.chat-page-input .msg-chat-send {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 16px;
  transition: background 0.15s, opacity 0.15s;
}
.chat-page-input .msg-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-page-input .msg-chat-send:hover:not(:disabled) { background: var(--color-primary-dark, #2563eb); }
.chat-page-input .msg-chat-img-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.chat-page-input .msg-chat-img-btn:hover { opacity: 1; }

.chat-page-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 15px;
}

/* ================================================================
   UI/UX 增强样式
   ================================================================ */

/* ---- 新消息进入动画 ---- */
.chat-bubble-enter {
  animation: bubble-in 0.2s ease-out;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- 输入状态指示器 ---- */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing-bounce 1.4s infinite ease-in-out both;
}
.chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- 网络连接状态 ---- */
.chat-network-status {
  text-align: center;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--color-text-muted);
  background: var(--color-surface, #f9fafb);
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  display: none;
}
.chat-network-status.is-offline { display: block; }

/* ---- 消息送达状态 ---- */
.chat-msg-status {
  font-size: 10px;
  margin-top: 1px;
}
.chat-msg-status::before {
  margin-right: 2px;
}
.chat-msg-status[data-status="sent"]::before { content: "✓"; color: rgba(255,255,255,0.6); }
.chat-msg-status[data-status="delivered"]::before { content: "✓✓"; color: rgba(255,255,255,0.6); }
.chat-msg-status[data-status="read"]::before { content: "✓✓"; color: #93c5fd; }
.chat-bubble-mine .chat-msg-status[data-status="sent"]::before { color: rgba(255,255,255,0.6); }
.chat-bubble-mine .chat-msg-status[data-status="delivered"]::before { color: rgba(255,255,255,0.6); }
.chat-bubble-mine .chat-msg-status[data-status="read"]::before { color: #93c5fd; }

/* ---- 图片预览浮层 ---- */
.chat-img-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.chat-img-preview-card {
  background: var(--color-card, #fff);
  border-radius: 16px;
  padding: 16px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.chat-img-preview-card img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  display: block;
  margin-bottom: 12px;
}
.chat-img-preview-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.chat-img-preview-actions button {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  border: none;
}
.chat-img-preview-cancel {
  background: var(--color-surface, #f3f4f6);
  color: var(--color-text, #374151);
}
.chat-img-preview-send {
  background: var(--color-primary, #3b82f6);
  color: #fff;
}

/* ================================================================
   暗色模式
   ================================================================ */
[data-theme="dark"] .chat-bubble-theirs { background: #2a3442; border-color: #3a4553; color: var(--color-text); }
[data-theme="dark"] .chat-page { background: #141b24; border-color: var(--color-border); }
[data-theme="dark"] .chat-page-sidebar { background: rgba(26,34,51,0.92); border-color: var(--color-border); }
[data-theme="dark"] .chat-page-main { background: #141b24; }
[data-theme="dark"] .chat-page-main-head { background: rgba(26,34,51,0.92); border-color: var(--color-border); }
[data-theme="dark"] .chat-page-input { background: rgba(26,34,51,0.92); border-color: var(--color-border); }
[data-theme="dark"] .chat-page-input .msg-chat-textarea { background: #2a3442; border-color: #3a4553; color: var(--color-text); }
[data-theme="dark"] .msg-chat-input { background: #1e2730; border-color: var(--color-border); }
[data-theme="dark"] .msg-chat-textarea { background: #2a3442; border-color: #3a4553; color: var(--color-text); }
[data-theme="dark"] .chat-img-preview-card { background: #1e2730; }
[data-theme="dark"] .chat-img-preview-cancel { background: #2a3442; color: var(--color-text); }

/* ================================================================
   移动端响应式
   ================================================================ */
@media (max-width: 600px) {
  .chat-page { height: calc(100vh - 56px - 60px); }
  .chat-page-sidebar { width: 100%; }
  .chat-page-main { display: none; }
  .chat-page.view-chat .chat-page-sidebar { display: none; }
  .chat-page.view-chat .chat-page-main { display: flex; }
  .chat-page-main-head .chat-page-back-btn { display: inline-flex; }
  .chat-page-messages .chat-bubble { max-width: var(--chat-bubble-max-width-mobile); }
}
