:root {
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-200: #fde68a;
  --amber-500: #d97706;
  --amber-600: #b45309;
  --amber-700: #92400e;
  --amber-800: #78350f;
  --green-50: #f0fdf4;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --gray-50: #fafafa;
  --gray-100: #f5f5f4;
  --gray-200: #e7e5e4;
  --gray-400: #a8a29e;
  --gray-600: #78716c;
  --gray-800: #292524;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(217, 119, 6, 0.08);
  --shadow-lg: 0 4px 16px rgba(217, 119, 6, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--amber-50);
  color: var(--gray-800);
  min-height: 100vh;
}

#app { max-width: 900px; margin: 0 auto; padding: 0 16px 40px; }

/* Navbar */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--amber-200);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.nav-brand { font-size: 20px; font-weight: 700; color: var(--amber-700); }

.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }

.nav-links a {
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--amber-700);
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active { background: var(--amber-500); color: #fff; }

/* Cards */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  font-size: 16px;
  font-weight: 600;
  color: var(--amber-700);
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--amber-500); color: #fff; }
.btn-primary:hover { background: var(--amber-600); }

.btn-secondary { background: var(--amber-100); color: var(--amber-700); }
.btn-secondary:hover { background: var(--amber-200); }

.btn-danger { background: var(--red-500); color: #fff; }
.btn-danger:hover { background: var(--red-600); }

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

/* Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.tag-amber { background: var(--amber-100); color: var(--amber-700); }
.tag-green { background: var(--green-50); color: var(--green-600); }
.tag-red { background: #fef2f2; color: var(--red-600); }
.tag-gray { background: var(--gray-100); color: var(--gray-600); }

/* Progress bar */
.progress-bar {
  height: 10px;
  background: var(--amber-200);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--amber-500);
  border-radius: 5px;
  transition: width 0.5s ease;
}

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

@media (max-width: 600px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr 1fr; }
  #navbar { flex-direction: column; align-items: flex-start; }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--amber-200);
  border-top-color: var(--amber-500);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* Input */
.input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--amber-200);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--gray-800);
  outline: none;
  transition: border-color 0.2s;
}

.input:focus { border-color: var(--amber-500); }

select.input { cursor: pointer; }

/* KaTeX display fix */
.katex-display { overflow-x: auto; overflow-y: hidden; }
.math-content .katex { font-size: 1.05em; }
.math-block { display: block; margin: 8px 0; text-align: center; }

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--amber-700);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } }

/* ===== AI 对话框样式 ===== */

/* 浮动气泡 */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--amber-500);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(217, 119, 6, 0.3);
  z-index: 999;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-fab:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(217, 119, 6, 0.4); }

/* 聊天面板 */
.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 360px;
  height: 480px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  z-index: 998;
  overflow: hidden;
}
.chat-panel--open { display: flex; }

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--amber-500);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

.chat-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--amber-50);
}

.chat-panel-footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--amber-200);
  background: #fff;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--amber-200);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
}
.chat-input:focus { border-color: var(--amber-500); }

.chat-empty {
  text-align: center;
  color: var(--gray-400);
  padding: 40px 20px;
  font-size: 14px;
}

/* 聊天消息 */
.chat-msg {
  margin-bottom: 10px;
  display: flex;
}
.chat-msg--user { justify-content: flex-end; }
.chat-msg--assistant { justify-content: flex-start; }

.chat-msg-content {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.7;
  word-break: break-word;
}
.chat-msg--user .chat-msg-content {
  background: var(--amber-500);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant .chat-msg-content {
  background: #fff;
  color: var(--gray-800);
  border: 1px solid var(--amber-200);
  border-bottom-left-radius: 4px;
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--gray-400);
  padding: 4px 0;
}

.btn-icon {
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-icon:hover { background: rgba(255,255,255,0.2); }

/* 内联 AI 面板 */
.ai-help-panel {
  margin-top: 12px;
  border: 1px solid var(--amber-200);
  border-radius: 12px;
  overflow: hidden;
  background: var(--amber-50);
}
.ai-help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--amber-100);
  font-size: 13px;
  font-weight: 600;
  color: var(--amber-700);
}
.ai-help-body {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--gray-800);
  line-height: 1.8;
  max-height: 300px;
  overflow-y: auto;
}

/* 设置面板 */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}
.settings-panel {
  background: #fff;
  border-radius: 16px;
  width: 400px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--amber-200);
}
.settings-header h3 { color: var(--amber-700); font-size: 16px; margin: 0; }
.settings-body { padding: 20px; }
.settings-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 4px;
}
