/* ===== AI 助手聊天页面 ===== */
:root {
  --primary: #0b5fff;
  --primary-dark: #0747cc;
  --accent: #00c2a8;
  --text: #1f2733;
  --text-light: #5b6675;
  --bg: #ffffff;
  --bg-soft: #f5f8ff;
  --border: #e3e8f0;
  --shadow: 0 2px 12px rgba(15, 35, 80, 0.06);
  --radius: 10px;
  --free-color: #00c2a8;
  --free-bg: #e6fbf6;
}

/* ===== 布局 ===== */
.chat-page {
  display: flex;
  justify-content: center;
  min-height: calc(100vh - 64px - 80px);
  padding: 24px 0;
}

.chat-container {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin: 0 24px;
}

/* ===== 工具栏 ===== */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #f5f8ff 0%, #e6fbf6 100%);
  flex-wrap: wrap;
  gap: 12px;
}

.chat-toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Agent 徽章 */
.chat-agent-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-agent-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 800;
  flex-shrink: 0;
}

.chat-agent-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-agent-info h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.chat-agent-tag {
  font-size: 12px;
  color: var(--primary);
  font-weight: 500;
}

.chat-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 免费徽章 */
.chat-free-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--free-bg);
  color: var(--free-color);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--free-color);
  white-space: nowrap;
  animation: free-pulse 2s ease-in-out infinite;
}

@keyframes free-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 194, 168, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(0, 194, 168, 0); }
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-light);
}

.chat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.chat-dot.on { background: #46c46a; }
.chat-dot.off { background: #ccc; }

.chat-btn {
  padding: 6px 14px;
  font-size: 14px;
}

/* ===== 历史会话面板 ===== */
.chat-history-panel {
  border-bottom: 1px solid var(--border);
  background: #fff;
  max-height: 280px;
  overflow-y: auto;
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.chat-history-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-light);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.chat-history-close:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.chat-history-list {
  padding: 8px 12px;
}

.chat-history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-history-item:hover {
  background: var(--bg-soft);
}

.chat-history-item.active {
  background: #eaf1ff;
}

.chat-history-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #eaf1ff, #e6fbf6);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-history-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-history-item-title {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-item-meta {
  font-size: 12px;
  color: var(--text-light);
}

.chat-history-item-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  font-size: 16px;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-history-item:hover .chat-history-item-delete {
  opacity: 1;
}

.chat-history-item-delete:hover {
  color: #e74c3c;
  background: #fff5f5;
}

.chat-history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-light);
  font-size: 14px;
}

/* ===== 消息区域 ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 400px;
  max-height: calc(100vh - 64px - 80px - 140px);
}

/* ===== 欢迎页 ===== */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 32px 20px;
}

.chat-welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 4px 20px rgba(11, 95, 255, 0.25);
}

/* 免费药丸标签 */
.chat-free-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--free-color), #00d4b8);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 2px 12px rgba(0, 194, 168, 0.3);
}

.chat-welcome h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 10px;
}

.chat-welcome-desc {
  color: var(--text-light);
  font-size: 15px;
  max-width: 480px;
  margin-bottom: 28px;
  line-height: 1.7;
}

.chat-welcome-desc strong {
  color: var(--primary);
}

/* 支持的模型标签 */
.chat-models {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 520px;
  margin-bottom: 24px;
}

.chat-model-tag {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #eaf1ff, #f5f8ff);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

/* Agent 能力亮点 */
.chat-features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 520px;
  width: 100%;
  margin-bottom: 28px;
}

.chat-feature {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
  transition: all 0.15s;
}

.chat-feature:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.chat-feature-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.chat-feature div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-feature strong {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

.chat-feature span {
  font-size: 12px;
  color: var(--text-light);
}

/* 建议标题 */
.chat-suggestions-title {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 10px;
  font-weight: 500;
}

.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
}

.chat-suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.chat-suggestion:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chat-suggestion-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* ===== 消息气泡 ===== */
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-msg-role .role-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
}

.chat-msg.user .role-avatar {
  background: var(--text);
}

.chat-msg.assistant .role-avatar {
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

.chat-msg.assistant .chat-msg-role {
  color: var(--primary);
}

.chat-msg-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user .chat-msg-bubble {
  background: #eaf1ff;
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant .chat-msg-bubble {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg-bubble.cursor::after {
  content: '▋';
  animation: chat-blink 1s steps(2) infinite;
  color: var(--primary);
}

@keyframes chat-blink {
  50% { opacity: 0; }
}

/* 工具调用 */
.chat-msg-tool {
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 6px;
  color: var(--text-light);
}

.chat-msg-tool summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
}

.chat-msg-tool pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  font-family: "SF Mono", Monaco, Consolas, monospace;
}

/* 错误 */
.chat-msg-error {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 4px;
  padding: 8px 12px;
  background: #fff5f5;
  border-radius: 8px;
}

/* ===== 输入区域 ===== */
.chat-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.chat-upload-zone {
  flex-shrink: 0;
}

.chat-upload-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text-light);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s;
}

.chat-upload-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #eaf1ff;
}

.chat-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.chat-composer textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-soft);
  color: var(--text);
  resize: none;
  min-height: 42px;
  max-height: 160px;
  line-height: 1.5;
}

.chat-composer textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 95, 255, 0.12);
  background: #fff;
}

/* 文件列表 */
.chat-file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eaf1ff;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  max-width: 200px;
}

.chat-file-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-chip .chip-size {
  color: var(--text-light);
  flex-shrink: 0;
}

.chat-file-chip .chip-remove {
  cursor: pointer;
  color: var(--text-light);
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.chat-file-chip .chip-remove:hover {
  color: #e74c3c;
}

.chat-file-chip.uploading {
  background: #fff5e6;
  border-color: #f0a020;
}

.chat-file-chip.done {
  background: #e6fbf6;
  border-color: var(--accent);
}

.chat-file-chip.error {
  background: #fff5f5;
  border-color: #e74c3c;
}

.chat-composer .btn {
  padding: 10px 20px;
  font-size: 15px;
  white-space: nowrap;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .chat-container {
    margin: 0 12px;
    border-radius: 10px;
  }

  .chat-toolbar {
    padding: 12px 16px;
  }

  .chat-agent-info h1 {
    font-size: 16px;
  }

  .chat-agent-tag {
    font-size: 11px;
  }

  .chat-toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-features {
    grid-template-columns: 1fr;
  }

  .chat-suggestions {
    grid-template-columns: 1fr;
  }

  .chat-welcome h2 {
    font-size: 20px;
  }

  .chat-composer {
    padding: 12px 16px;
  }

  .chat-composer .btn {
    padding: 8px 14px;
    font-size: 14px;
  }
}
