/* ============================================
   全局重置与变量
   ============================================ */
:root {
  --bg: #EDEDED;
  --card-bg: #F5F5F5;
  --card-border: #DDDDDD;
  --text: #333333;
  --text-dim: #666666;
  --red: #e74c3c;
  --red-bg: #ffeaea;
  --blue: #3498db;
  --blue-bg: #eaf4ff;
  --accent: #f39c12;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --brown: #8b5e3c;
  --black: #333;
  --header-h: 42px;
  --bottom-h: 50px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  height: 100%;
}
a { color: inherit; text-decoration: none; }

/* ============================================
   通用布局
   ============================================ */
.app {
  max-width: 480px;
  margin: 0 auto;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 15px;
  background: #7D0000;
  border-bottom: 1px solid #5a0000;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.header-title { font-size: 18px; font-weight: 600; text-align: center; flex: 1; color: #FFFFFF; }
.header-back { font-size: 16px; padding: 5px 8px 5px 0; color: var(--accent); cursor: pointer; flex-shrink: 0; }
.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: auto;
  overscroll-behavior: contain;
  padding: 10px;
}

/* ============================================
   底部栏
   ============================================ */
.bottom-bar {
  height: var(--bottom-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #7D0000;
  border-top: 1px solid #5a0000;
  flex-shrink: 0;
}
.bottom-link {
  color: #FFD700;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(255, 215, 0, 0.1);
}

.bottom-nav {
  height: var(--bottom-h);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #7D0000;
  border-top: 1px solid #5a0000;
  flex-shrink: 0;
}
.bottom-nav-item {
  color: #FFD700;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  cursor: pointer;
}

/* ============================================
   AI 聊天页面
   ============================================ */
.chat-config {
  flex-shrink: 0;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
}
.config-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.config-body {
  padding: 0 12px 10px;
  display: none;
}
.config-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.config-label {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  line-height: 30px;
  min-width: 48px;
}
.config-select {
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  height: 30px;
}
.config-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}
.config-checks label {
  font-size: 11px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.config-checks input[type="checkbox"] {
  accent-color: var(--accent);
}
.config-btn {
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  line-height: 22px;
  flex-shrink: 0;
}
.config-textarea {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

/* 警告提示 */
.chat-warn {
  padding: 6px 12px;
  font-size: 11px;
  background: rgba(231,76,60,0.1);
  flex-shrink: 0;
}

/* 聊天消息区域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 12px;
  -webkit-overflow-scrolling: touch;
}
.chat-msg {
  margin-bottom: 10px;
  max-width: 90%;
}
.chat-msg-user {
  margin-left: auto;
}
.chat-msg-assistant {
  margin-right: auto;
}
.chat-msg-header {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.chat-msg-user .chat-msg-header {
  text-align: right;
}
.chat-msg-body {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg-user .chat-msg-body {
  background: var(--accent);
  color: #fff;
}
.chat-msg-assistant .chat-msg-body {
  background: #4a4a5a;
  color: #FFFFFF;
}
.chat-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 12px;
}
.chat-thinking {
  margin-right: auto;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* 输入区 */
.chat-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--card-border);
  background: var(--card-bg);
  padding: 8px 12px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.chat-input:focus {
  border-color: var(--accent);
}
.chat-send {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-tips {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  min-height: 14px;
}

/* ============================================
   加载状态
   ============================================ */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--card-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================
   PC 端自适应
   ============================================ */
@media (min-width: 1024px) {
  .app { max-width: 100%; }
  .chat-msg-body { font-size: 14px; padding: 10px 14px; }
  .chat-input { font-size: 14px; padding: 10px 12px; }
}
