/* Tailwind CSS CDN */

/* ============================================
   CSS Variables - 微信风格 WeChat Style
   ============================================ */
:root {
  /* 微信绿 */
  --primary: #0f62fe;
  --primary-hover: #0353e9;
  --primary-active: #002d9c;
  --primary-light: rgba(15,98,254,0.1);

  /* 背景色 */
  --bg-primary: #f4f4f4;
  --bg-surface: #ffffff;
  --bg-hover: #e8e8e8;

  /* 气泡色 */
  --user-bubble: #0f62fe;
  --ai-bubble: #ffffff;

  /* 文字色 */
  --text-primary: #161616;
  --text-secondary: #525252;
  --text-muted: #6f6f6f;

  /* 边框 */
  --border-color: #e0e0e0;
  --border-subtle: #c6c6c6;

  /* 字体 - IBM Plex Sans */
  --font-family: 'IBM Plex Sans', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Geist Mono', 'JetBrains Mono', monospace;

  /* 圆角 - IBM Carbon 直角 */
  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;

  /* 头像尺寸 */
  --avatar-size: 40px;
}

/* ============================================
   全局重置与基础
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   滚动条样式 - 微信风格
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ============================================
   标题栏
   ============================================ */
#titleBar {
  -webkit-app-region: drag;
  user-select: none;
}

#titleBar .titlebar-btn {
  -webkit-app-region: no-drag;
}

/* ============================================
   侧边栏会话列表 - 微信风格
   ============================================ */
.session-item {
  position: relative;
  border-radius: var(--radius-md);
}

.session-item:hover {
  background: var(--bg-hover);
}

.session-item.active {
  background: #c6c6c6;
  border-left: none;
}

.session-item.active .text-sm {
  color: var(--text-primary);
  font-weight: 600;
}

.session-item.active .text-xs {
  color: var(--text-secondary);
}

/* ============================================
   聊天消息区
   ============================================ */
#chatArea {
  scroll-behavior: smooth;
}

/* 欢迎区动画 */
#welcomeArea {
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 快捷提示词 */
.prompt-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
}

.prompt-chip:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ============================================
   消息气泡 - 微信风格
   ============================================ */
.message {
  animation: messageSlideIn 0.25s ease-out;
  padding: 6px 0;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 头像样式 */
.message-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: cover;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  object-fit: cover;
}

/* 消息内容 */
.message-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
  padding: 7px 11px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 100%;
}

.message-text {
  user-select: text;
  word-break: break-word;
}

/* 用户消息 - 右侧绿色气泡 */
.user-message {
  justify-content: flex-end;
}

.user-message .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.user-message .message-content {
  background: var(--user-bubble) !important;
  border-radius: 4px;
  color: #ffffff !important;
  position: relative;
}

/* 用户气泡右侧小三角 */
.user-message .message-content::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 14px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 5px solid var(--user-bubble);
}

/* AI消息 - 左侧白色气泡 */
.ai-message {
  justify-content: flex-start;
}

.ai-message .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.ai-message .message-content {
  background: var(--ai-bubble) !important;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  color: var(--text-primary) !important;
  position: relative;
}

/* AI气泡左侧小三角 */
.ai-message .message-content::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 14px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 5px solid #e0e0e0;
}

.ai-message .message-content::after {
  content: '';
  position: absolute;
  left: -4px;
  top: 14px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 5px solid var(--ai-bubble);
}

/* 消息时间戳 - 微信风格 */
.message-time { display: none; }  /* 兼容旧 DOM，实际由 .feedback-time 渲染 */

/* 时间戳（与反馈按钮同行） */
.feedback-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 2px;
  line-height: 1;
}

/* 时间 + 👍 + 👎 同行容器 */
.feedback-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  padding-left: 2px;
  font-size: 12px;
  color: var(--text-muted);
}
.user-message .feedback-bar { justify-content: flex-end; }
.ai-message .feedback-bar { justify-content: flex-start; }

.feedback-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  font-size: 13px;
  line-height: 1;
}
.feedback-btn:hover { background: var(--bg-hover); }
.feedback-up:hover { color: var(--primary); }
.feedback-down:hover { color: #f87171; }
.feedback-hint { font-size: 11px; opacity: 0.7; }

/* 时间分割线 - 微信风格 */
.time-divider {
  text-align: center;
  margin: 10px 0;
  position: relative;
}

.time-divider span {
  display: inline-block;
  padding: 2px 8px;
  background: #c6c6c6;
  color: #ffffff;
  font-size: 11px;
  border-radius: 2px;
}

/* 复制按钮 */
.copy-btn {
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}

.message:hover .copy-btn {
  opacity: 1;
}

/* ============================================
   输入区 - 微信风格
   ============================================ */
.chat-input-area {
  background: #f5f5f5;
  border-top: 1px solid #e5e5e5;
  padding: 6px 12px env(safe-area-inset-bottom, 4px);
  /* iOS 键盘弹起时由 JS 动态调整 position: fixed + bottom */
}

.input-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.toolbar-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  color: #999;
  transition: all 0.15s;
}

.toolbar-btn:hover {
  color: #666;
  background: rgba(0,0,0,0.05);
}

#messageInput {
  width: 100%;
  min-height: 20px;
  max-height: 120px;
  padding: 2px 4px;
  background: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  resize: none;
  outline: none;
  font-family: var(--font-family);
}

#messageInput::placeholder {
  color: #bbb;
}

.input-wrapper {
  position: relative;
  background: #fff;
  border-radius: 6px;
}

/* 发送按钮 - flex 自然布局（不 absolute 避免遮挡） */
#sendBtn {
  flex-shrink: 0;
  align-self: flex-end;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
}

#sendBtn:hover:not(:disabled) {
  background: var(--primary-hover);
}

#sendBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}


/* ============================================
   正在输入动画
   ============================================ */
@keyframes bounce {
  0%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-6px);
  }
}

.animate-bounce {
  animation: bounce 1.4s ease-in-out infinite;
}

/* ============================================
   代码块样式 - 微信风格
   ============================================ */
pre {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px 16px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  line-height: 1.6;
}

:not(pre) > code {
  background: #f0f0f0;
  padding: 0.2em 0.4em;
  border-radius: 4px;
  color: #e83e8c;
  font-family: var(--font-mono);
}

/* ============================================
   思考过程 - 微信风格
   ============================================ */
.think-block {
  margin: 8px 0;
  background: #f7f7f7;
  border-radius: 4px;
  overflow: hidden;
}

.think-block summary {
  padding: 8px 12px;
  font-size: 12px;
  color: #999;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.think-block summary::marker {
  display: none;
}

.think-block summary::before {
  content: '▶';
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}

.think-block[open] summary::before {
  transform: rotate(90deg);
}

.think-block .think-content {
  padding: 0 12px 12px;
  font-size: 13px;
  color: #888;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* think-summary div 样式（chat.js 使用 div 而非 summary 元素） */
.think-block .think-summary {
  padding: 8px 12px;
  font-size: 12px;
  color: #999;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.think-block .think-arrow {
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}

.think-block.collapsed .think-arrow {
  transform: rotate(0deg);
}

.think-block:not(.collapsed) .think-arrow {
  transform: rotate(90deg);
}

/* 思考过程收起状态（默认） */
.think-block.collapsed .think-content {
  display: none;
}

.think-block.collapsed summary::before {
  transform: rotate(0deg);
}

/* 流式过程中正文区域（think 标签之后的内容） */
.answer-stream {
  margin-top: 8px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ============================================
   卡片与表面
   ============================================ */
.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

/* ============================================
   响应式 - 移动端适配（与 index.html 内联 style 互补）
   ============================================ */

/* PC 端：汉堡按钮和遮罩默认隐藏 */
.mobile-only {
  display: none;
}

.sidebar-overlay {
  display: none;
}

/* 注：关键移动端覆盖已移至 index.html 内联 <style>，避免与 Tailwind CDN 冲突 */
/* 此处仅保留 index.html 未覆盖的辅助样式 */

@media (pointer: coarse) {
  .mobile-only {
    display: flex;
  }


  /* 头像缩小 */
  .message-avatar {
    --avatar-size: 36px;
    width: 36px;
    height: 36px;
  }

  /* 消息区内边距 */
  #chatArea {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* 发送按钮加大 */
  #sendBtn {
    width: 44px;
    height: 44px;
    right: 6px;
    bottom: 6px;
  }

  /* 输入区 */
  .chat-input-area {
    padding: 8px 12px 0;
  }

  #messageInput {
    min-height: 48px;
    padding: 10px 52px 10px 12px;
  }

  /* 快捷提示词垂直堆叠 */
  #welcomeArea .flex-wrap {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  #welcomeArea .prompt-chip {
    width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 欢迎区缩小 */
  #welcomeArea .w-16 {
    width: 3.5rem;
    height: 3.5rem;
  }
  #welcomeArea h1 {
    font-size: 1.25rem;
  }

  /* 复制按钮始终显示 */
  .copy-btn {
    opacity: 1;
    width: 28px;
    height: 28px;
  }
  .copy-btn svg {
    width: 14px;
    height: 14px;
  }

  /* 允许文本选择 */
  body {
    user-select: text;
  }

  /* 代码块横向滚动 */
  pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 表格横向滚动 */
  .ai-message table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* ============================================
   Markdown 渲染样式
   ============================================ */

/* AI消息中的Markdown内容 */
.ai-message .message-text {
  user-select: text;
  color: var(--text-primary);
}

.ai-message .message-text p {
  margin-bottom: 0.75rem;
}

.ai-message .message-text p:last-child {
  margin-bottom: 0;
}

/* 内联代码 */
.inline-code {
  background: #f0f0f0;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: #e83e8c;
  word-break: break-all;
}

/* 代码块 */
.code-block-wrapper {
  border-radius: 6px;
  overflow: hidden;
  margin: 0.75rem 0;
}

.code-block-wrapper pre {
  margin: 0;
  border-radius: 6px;
  border-top: none;
  background: #1e1e1e;
}

.code-block-wrapper code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

/* 复制按钮 */
.copy-btn {
  transition: all 0.2s ease;
}

/* 引用块 */
.ai-message blockquote {
  margin: 0.75rem 0;
  font-style: italic;
  border-left: 3px solid var(--primary);
  padding-left: 1rem;
}

.ai-message blockquote p {
  margin-bottom: 0;
}

/* 表格 */
.ai-message table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.ai-message th,
.ai-message td {
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.ai-message th {
  background: #f7f7f7;
  font-weight: 600;
}

.ai-message tr:nth-child(even) {
  background: #fafafa;
}

/* 列表 */
.ai-message ul,
.ai-message ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.ai-message li {
  margin: 0.25rem 0;
}

.ai-message li::marker {
  color: var(--primary);
}

/* 链接 */
.ai-message a {
  color: #576b95;
  text-decoration: none;
}

.ai-message a:hover {
  text-decoration: underline;
}

/* 标题 */
.ai-message h1,
.ai-message h2,
.ai-message h3,
.ai-message h4 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* 分隔线 */
.ai-message hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1rem 0;
}

/* ============================================
   动画
   ============================================ */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.animate-pulse {
  animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ============================================
   选中文字颜色
   ============================================ */
::selection {
  background: #0f62fe;
  color: #ffffff;
}


/* Tailwind 覆盖 - 强制微信绿 */
#newSessionBtn {
  background-color: var(--primary) !important;
}
#newSessionBtn:hover {
  background-color: var(--primary-hover) !important;
}

/* ============================================
   网络状态提示条
   ============================================ */
.network-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff3cd;
  border-bottom: 1px solid #ffc107;
  color: #856404;
  font-size: 13px;
}

.network-banner-icon {
  font-size: 14px;
}

.network-banner-text {
  flex: 1;
  text-align: center;
}

.network-banner-close {
  background: none;
  border: none;
  color: #856404;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  opacity: 0.7;
}

.network-banner-close:hover {
  opacity: 1;
}

/* ============================================
   日志导出对话框
   ============================================ */
.log-export-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.log-export-dialog {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

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

.log-export-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.log-export-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.log-export-close:hover {
  color: var(--text-primary);
}

.log-export-body {
  padding: 16px 20px;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.log-export-tip {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.log-export-textarea {
  flex: 1;
  min-height: 280px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-primary);
  background: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  resize: none;
  outline: none;
  overflow: auto;
}

.log-export-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border-color);
}

.log-export-btn-copy {
  padding: 8px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.log-export-btn-copy:hover {
  background: var(--primary-hover);
}

.log-export-btn-close {
  padding: 8px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.log-export-btn-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* 空数据回复样式 */
.empty-data-reply .message-content {
    opacity: 0.65;
    font-style: italic;
    background: #f8f8f8;
    border-left: 3px solid #d0d0d0;
    padding-left: 12px;
}

/* ============================================
   iOS Safe Area（顶栏）
   ============================================ */
#headerBar {
  padding-top: max(8px, env(safe-area-inset-top)) !important;
  height: calc(2.5rem + max(8px, env(safe-area-inset-top))) !important;
}

/* ============================================
   iOS 键盘弹起 - input-area 跟键盘上移
   ============================================ */
.chat-input-area {
  /* 桌面端：保持正常文档流 */
  position: relative;
  z-index: 5;
}
@media (max-width: 768px) {
  /* 移动端：用 position: sticky 让 input 跟键盘上移 */
  .chat-input-area {
    position: -webkit-sticky;
    position: sticky;
    bottom: 0;
    background: #f5f5f5;
  }
}
