/* ========== 基础重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: #f0f0f3;
  color: #1a1a1a;
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

/* ========== 应用容器 ========== */
#app-container {
  width: 100%;
  max-width: 430px;
  background: #fff;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  box-shadow: 0 0 40px rgba(0,0,0,0.06);
  overflow: hidden;
}

/* ========== 视图切换 ========== */
.view { display: none; flex: 1; flex-direction: column; }
.view.active { display: flex; }

/* ========== 首页 ========== */
.home-header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  padding: 60px 24px 40px;
  color: #fff;
  text-align: center;
}
.home-header h1 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.home-header p { font-size: 14px; opacity: 0.9; line-height: 1.5; }

.feature-list { padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }

.feature-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.feature-card:active { transform: scale(0.97); }
.feature-card:hover { border-color: #c4b5fd; box-shadow: 0 4px 16px rgba(99,102,241,0.12); }

.feature-icon {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; flex-shrink: 0;
}
.feature-info { flex: 1; }
.feature-info h3 { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.feature-info p { font-size: 13px; color: #888; line-height: 1.4; }
.feature-arrow { color: #ccc; font-size: 20px; }

/* ========== 聊天视图 ========== */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  position: sticky; top: 0; z-index: 10;
}
.chat-header .back-btn {
  font-size: 22px; background: none; border: none; cursor: pointer;
  color: #333; padding: 4px 8px; line-height: 1;
}
.chat-header span { font-size: 17px; font-weight: 600; flex: 1; }
.chat-header .clear-btn { font-size: 18px; background: none; border: none; cursor: pointer; opacity: 0.4; }
.chat-header .clear-btn:hover { opacity: 1; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}

.welcome-msg {
  text-align: center; padding: 40px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.welcome-icon { font-size: 48px; }
.welcome-msg p { color: #999; font-size: 14px; max-width: 260px; line-height: 1.6; }

/* ========== 推荐问题 ========== */
.suggested-questions {
  display: flex; flex-direction: column; gap: 8px;
  padding: 0 20px 8px;
}
.suggested-question {
  padding: 12px 16px;
  background: #f3f0ff;
  border: 1px solid #e9e4ff;
  border-radius: 12px;
  font-size: 14px;
  color: #6366f1;
  cursor: pointer;
  transition: all 0.2s;
}
.suggested-question:hover {
  background: #ede9fe;
  border-color: #c4b5fd;
}
.suggested-question:active { transform: scale(0.98); }

.message { display: flex; gap: 10px; max-width: 85%; animation: fadeIn 0.3s ease; }
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.msg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.message.user .msg-avatar { background: #6366f1; color: #fff; }
.message.assistant .msg-avatar { background: #f3f0ff; }

.msg-bubble {
  padding: 12px 16px; border-radius: 18px;
  font-size: 15px; line-height: 1.6; word-break: break-word;
}
.message.user .msg-bubble {
  background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
  color: #fff; border-bottom-right-radius: 4px;
}
.message.assistant .msg-bubble {
  background: #f5f5f5; color: #1a1a1a; border-bottom-left-radius: 4px;
}
.msg-bubble p { margin: 4px 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 4px 20px; }
.msg-bubble pre { background: #2d2d2d; color: #f8f8f2; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; font-size: 13px; }
.msg-bubble code { font-family: 'SF Mono', Consolas, monospace; font-size: 13px; }
.msg-bubble :not(pre) > code { background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 4px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span {
  width: 8px; height: 8px; border-radius: 50%; background: #aaa;
  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); } }

/* ========== 聊天输入栏 ========== */
.chat-input-bar {
  display: flex; gap: 8px; padding: 10px 12px;
  background: #fff; border-top: 1px solid #f0f0f0;
  align-items: flex-end;
  flex-wrap: wrap;
}
.upload-btn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border: none;
  width: 42px; height: 42px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; border-radius: 50%;
  transition: transform 0.1s;
}
.upload-btn:active { transform: scale(0.9); }
.upload-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.upload-icon {
  color: #fff;
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
  margin-top: -2px;
}

.chat-input-bar textarea {
  flex: 1; border: 1px solid #e0e0e0; border-radius: 22px;
  padding: 10px 16px; font-size: 15px; resize: none;
  max-height: 120px; line-height: 1.5; outline: none;
  font-family: inherit;
}
.chat-input-bar textarea:focus { border-color: #8b5cf6; }
#send-btn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #fff; border: none; border-radius: 50%;
  width: 42px; height: 42px; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform 0.1s;
}
#send-btn span { font-size: 18px; transform: rotate(0deg); }
#send-btn:active { transform: scale(0.9); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== 文件预览 ========== */
.file-preview {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
  width: 100%;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f3f0ff;
  border: 1px solid #e9e4ff;
  border-radius: 16px;
  font-size: 13px;
  color: #6366f1;
  max-width: 200px;
}
.file-chip-icon { font-size: 16px; flex-shrink: 0; }
.file-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip-remove {
  cursor: pointer;
  font-size: 14px;
  opacity: 0.5;
  flex-shrink: 0;
  margin-left: 2px;
}
.file-chip-remove:hover { opacity: 1; }

/* ========== 表单视图 ========== */
.form-content { flex: 1; overflow-y: auto; padding: 20px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; color: #333; }
.form-group .required { color: #ef4444; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; border: 1px solid #e0e0e0; border-radius: 12px;
  padding: 12px 16px; font-size: 15px; outline: none;
  font-family: inherit; background: #fff;
}
.form-group textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: #8b5cf6; box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
}

.submit-btn {
  width: 100%; padding: 14px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: transform 0.1s;
}
.submit-btn:active { transform: scale(0.97); }
.submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.form-result {
  margin-top: 24px; padding: 20px;
  background: #f9f8ff; border: 1px solid #e9e4ff;
  border-radius: 14px;
}
.form-result h4 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: #6366f1; }
.form-result .result-content { font-size: 14px; line-height: 1.7; }
.form-result .result-content p { margin: 6px 0; }
.form-result .result-content ul, .form-result .result-content ol { margin: 6px 0 6px 20px; }

.loading-spinner {
  text-align: center; padding: 40px; color: #999;
}
.loading-spinner .spinner {
  width: 36px; height: 36px; border: 3px solid #e0e0e0;
  border-top-color: #8b5cf6; border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  margin-top: 16px; padding: 14px 16px; background: #fef2f2;
  border: 1px solid #fecaca; border-radius: 12px;
  color: #dc2626; font-size: 14px;
}

/* ========== 底部标签栏 ========== */
.tabbar {
  display: flex; background: #fff; border-top: 1px solid #f0f0f0;
  padding-bottom: env(safe-area-inset-bottom);
  position: sticky; bottom: 0;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 0; cursor: pointer;
  transition: color 0.2s; color: #999;
}
.tab.active { color: #6366f1; }
.tab-icon { font-size: 22px; }
.tab-label { font-size: 10px; }

/* ========== 配置警告 ========== */
.config-warning {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.config-warning.hidden { display: none; }
.warning-box {
  background: #fff; border-radius: 16px; padding: 28px;
  max-width: 380px; max-height: 80vh; overflow-y: auto;
}
.warning-box h3 { font-size: 18px; margin-bottom: 16px; color: #dc2626; }
.warning-box p { font-size: 14px; line-height: 1.6; color: #555; margin-bottom: 12px; }
.warning-box code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 13px; color: #6366f1; }
.warning-box ul { margin: 8px 0 16px 20px; }
.warning-box li { font-size: 14px; color: #555; margin-bottom: 4px; }
.warning-box .hint { font-size: 13px; color: #999; margin-top: 8px; }

/* ========== 首页大按钮样式 ========== */
.feature-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px 24px;
}
.feature-btn {
  width: 100%;
  padding: 16px;
  background: #6345ff;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.feature-btn:active {
  transform: scale(0.97);
  background: #5238e0;
}

/* 第二行副标题 */
.app-subtitle2 {
  font-size: 14px;
  opacity: 0.9;
  line-height: 1.5;
  margin-top: 2px;
}

/* ========== 计数器组件 ========== */
.counter-input {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}
.counter-btn {
  width: 44px;
  height: 44px;
  border: 1px solid #e0e0e0;
  background: #f5f5fa;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: background 0.2s;
}
.counter-btn:active {
  background: #e8e8f0;
}
.counter-minus {
  border-radius: 8px 0 0 8px;
  border-right: none;
}
.counter-plus {
  border-radius: 0 8px 8px 0;
  border-left: none;
}
.counter-input input[type="number"] {
  flex: 1;
  text-align: center;
  border: 1px solid #e0e0e0;
  border-left: none;
  border-right: none;
  border-radius: 0;
  height: 44px;
  padding: 0;
  font-size: 16px;
  font-weight: 600;
  background: #f5f5fa;
  -moz-appearance: textfield;
}
.counter-input input[type="number"]::-webkit-outer-spin-button,
.counter-input input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ========== 欢迎消息（分类样式） ========== */
.welcome-full .welcome-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 4px;
}
.welcome-full .welcome-cat {
  margin-top: 12px;
}
.welcome-full .welcome-cat-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: #333;
}
.welcome-full .welcome-cat-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.welcome-full .welcome-cat-list li {
  font-size: 14px;
  line-height: 1.6;
  color: #555;
  padding-left: 16px;
  position: relative;
  margin-bottom: 4px;
}
.welcome-full .welcome-cat-list li::before {
  content: "•";
  position: absolute;
  left: 4px;
  color: #6366f1;
  font-weight: bold;
}
.welcome-full .welcome-footer {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #555;
}

/* ========== 桌面端适配 ========== */
@media (min-width: 768px) {
  #app-container { border-radius: 0; min-height: 100vh; }
}