/* ===== 基础重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2E7D32;
  --primary-light: #4CAF50;
  --primary-dark: #1B5E20;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-hint: #999;
  --bubble-bot: #ffffff;
  --bubble-user: #2E7D32;
  --border: #e0e0e0;
  --divider: #f0f0f0;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 12px rgba(0,0,0,0.08);
  --candidate-bg: #E8F5E9;
  --candidate-border: #4CAF50;
  --suggestion-bg: #FFF3E0;
  --suggestion-border: #FFE0B2;
  --suggestion-text: #E65100;
}

/* ===== 暗色模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --text: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-hint: #788;
    --bubble-bot: #1f2f3f;
    --border: #2a3a4a;
    --divider: #253;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 12px rgba(0,0,0,0.35);
    --candidate-bg: #1a3a1a;
    --candidate-border: #2E7D32;
    --suggestion-bg: #3e2723;
    --suggestion-border: #bf360c;
    --suggestion-text: #ffab91;
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== 容器布局 ===== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  padding-top: env(safe-area-inset-top);
}

/* ===== 绿色顶栏 ===== */
.header {
  background: var(--primary);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.3;
}

.header-subtitle {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}

/* 新对话按钮 */
.new-chat-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #ffffff;
  font-size: 13px;
  font-family: inherit;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.new-chat-btn:active {
  background: rgba(255,255,255,0.28);
}

/* 恢复历史提示条 */
.restore-banner {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  padding: 6px 12px;
  margin: 4px 8px 8px;
  background: var(--divider);
  border-radius: 8px;
}

/* ===== Logo 图片 ===== */
.logo-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

/* ===== 聊天区域 ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

/* ===== 消息 ===== */
.message {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: fadeInUp 0.3s ease;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

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

/* ===== 头像 ===== */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.bot-avatar { background: #e8f5e9; }
.user-avatar { background: #e3f2fd; }

/* ===== 消息内容容器 ===== */
.message-content {
  display: flex;
  flex-direction: column;
}

/* ===== 气泡 ===== */
.bubble {
  background: var(--bubble-bot);
  padding: 12px 14px;
  border-radius: 16px;
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  line-height: 1.6;
  color: var(--text);
  font-size: 14px;
  word-break: break-word;
  min-width: 0;
}
.message.bot .message-content {
  min-width: 0;
  overflow: hidden;
}

.message.user .bubble {
  background: var(--primary);
  color: #ffffff;
  border-radius: 16px;
  border-top-right-radius: 4px;
}

.bubble-text { user-select: text; }
.bubble-text { overflow-x: auto; }

.bubble p { margin-bottom: 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { padding-left: 18px; margin: 6px 0; }
.bubble li { margin-bottom: 4px; }
.bubble em { color: var(--primary-light); font-style: normal; }
.message.user .bubble em { color: #c8e6c9; }
.bubble strong { color: var(--primary); }
.message.user .bubble strong { color: #ffffff; }

/* ===== Markdown 元素 ===== */
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.35;
}
.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1.05em; color: var(--primary); }
.bubble h4 { font-size: 1em; }

.bubble table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  cursor: pointer;
}
/* 表格滚动包装 */
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 6px;
  margin: 8px 0;
}
.table-scroll.scrollable {
  max-height: 65vh;
  overflow-y: auto;
}
.table-scroll.scrollable::after {
  content: '← 左右滑动查看 · 点击放大';
  display: block;
  font-size: 10px;
  color: var(--text-hint);
  text-align: center;
  padding: 2px 0;
  pointer-events: none;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.bubble th {
  background: #e8f5e9;
  font-weight: 600;
  white-space: nowrap;
  color: var(--primary-dark);
}
.bubble tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.02);
}

.bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.88em;
  word-break: break-all;
}

.bubble pre {
  background: #f3f3f3;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
}
.bubble pre code { background: none; padding: 0; border-radius: 0; font-size: inherit; }

.bubble blockquote {
  border-left: 3px solid var(--primary-light);
  padding: 4px 0 4px 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.bubble a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble ol li { margin-bottom: 4px; }

.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.bubble del, .bubble s { color: var(--text-hint); }

.bubble img { max-width: 100%; border-radius: 8px; }

/* ===== 暗色模式 Markdown 覆盖 ===== */
@media (prefers-color-scheme: dark) {
  .bubble th { background: #1a3a1a; color: #81c784; }
  .bubble code { background: rgba(255, 255, 255, 0.1); }
  .bubble pre { background: #0d1b2a; }
  .bubble blockquote { border-left-color: var(--primary); color: #aaa; }
  .bubble tr:nth-child(even) td { background: rgba(255, 255, 255, 0.03); }
}

/* ===== 流式光标 ===== */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.7s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ===== 思考中动画 ===== */
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.thinking-dots .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: dotPulse 1.4s ease-in-out infinite;
}
.thinking-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ===== 加载动画 ===== */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ===== 候选按钮 ===== */
.candidate-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.candidate-btn {
  padding: 8px 16px;
  border: 1.5px solid var(--candidate-border);
  border-radius: 20px;
  background: var(--candidate-bg);
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.candidate-btn:active {
  background: var(--primary-light);
  color: #ffffff;
  border-color: var(--primary-light);
}

/* ===== 追问建议 ===== */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.suggestion-label {
  width: 100%;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.suggestion-chip {
  padding: 8px 16px;
  border: 1.5px solid var(--suggestion-border);
  border-radius: 20px;
  background: var(--suggestion-bg);
  color: var(--suggestion-text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.suggestion-chip:active {
  background: #FFE0B2;
  color: #BF360C;
}

/* ===== 反馈按钮 ===== */
.feedback-row {
  margin-top: 8px;
}

.feedback-btns {
  display: flex;
  gap: 8px;
}

.fb-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #f5f5f5;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.fb-btn:active {
  background: #e0e0e0;
  transform: scale(1.1);
}

.feedback-done {
  font-size: 12px;
  color: var(--text-hint);
}

@media (prefers-color-scheme: dark) {
  .fb-btn { background: #2a3a4a; }
  .fb-btn:active { background: #3a4a5a; }
}

/* ===== 快捷问题 ===== */
.quick-questions {
  padding: 8px 16px 4px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.quick-questions::-webkit-scrollbar { display: none; }

.quick-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1.5px solid var(--primary);
  border-radius: 20px;
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.quick-btn:active {
  background: var(--primary);
  color: #ffffff;
}

/* ===== 输入区域 ===== */
.input-area {
  background: var(--surface);
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== 文字输入 ===== */
#messageInput {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border 0.2s;
}

#messageInput:focus {
  border-color: var(--primary);
}

#messageInput:disabled {
  opacity: 0.6;
}

/* ===== 发送按钮 ===== */
.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.send-btn:active {
  background: var(--primary-dark);
  transform: scale(0.95);
}

.send-btn:disabled {
  background: #ccc;
  opacity: 0.5;
  cursor: not-allowed;
}

.send-icon {
  width: 20px;
  height: 20px;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
  opacity: 0.7;
}

/* ===== 欢迎消息 ===== */
.welcome-msg {
  border-bottom: 1px solid var(--divider);
  padding-bottom: 16px;
  margin-bottom: 8px;
}

/* ===== 表格全屏弹窗 ===== */
.table-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.table-fullscreen.active {
  opacity: 1;
  pointer-events: auto;
}

.table-fullscreen-inner {
  max-width: 96vw;
  max-height: 90vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.table-fullscreen-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  pointer-events: none;
}

.table-fullscreen table {
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  color: #1a1a1a;
  transform-origin: 0 0;
}

.table-fullscreen th,
.table-fullscreen td {
  border: 1px solid #ccc;
  padding: 8px 14px;
  text-align: left;
  white-space: nowrap;
}

.table-fullscreen th {
  background: #e8f5e9;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
}

.table-fullscreen tr:nth-child(even) td {
  background: #f9f9f9;
}







