:root {
  color-scheme: light dark;
  --bg: #f7f8fa;
  --card: #ffffff;
  --text: #1a1d24;
  --subtext: #5b6475;
  --line: #dfe4ec;
  --brand: #2b6ff7;
  --good: #0d8f4f;
  --warn: #c06a00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav .logo {
  font-weight: 700;
}

.nav .links {
  display: flex;
  gap: 16px;
  font-size: 14px;
}

.badge {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  color: var(--subtext);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.card h3 { margin: 0 0 8px; }
.card p { margin: 0; color: var(--subtext); }

.primary-btn, .ghost-btn {
  border-radius: 10px;
  border: none;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
}

.primary-btn {
  background: var(--brand);
  color: #fff;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.assistant-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
}

@media (max-width: 900px) {
  .assistant-layout {
    grid-template-columns: 1fr;
  }
}

.label {
  display: block;
  font-size: 13px;
  color: var(--subtext);
  margin-bottom: 6px;
}

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: #111;
  border-radius: 10px;
  padding: 10px;
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.meta-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--subtext);
}

.chat-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 460px;
  max-height: 65vh;
  overflow: auto;
  padding: 14px;
}

.msg {
  margin-bottom: 14px;
}

.msg .who {
  font-size: 12px;
  color: var(--subtext);
  margin-bottom: 4px;
}

.msg .bubble {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 0 0 10px 20px; }
.msg .bubble pre {
  margin: 8px 0;
  overflow: auto;
  border-radius: 8px;
  padding: 10px;
  background: #0f172a;
  color: #e2e8f0;
}
.msg .bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.msg .bubble :not(pre) > code {
  background: #eef2ff;
  border-radius: 6px;
  padding: 2px 6px;
}
.msg .bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.msg .bubble th, .msg .bubble td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.msg .bubble blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid #93c5fd;
  color: #334155;
  background: #f8fafc;
}
.mermaid-diagram {
  overflow-x: auto;
  padding: 6px 0;
}
.mermaid-error {
  color: var(--warn);
  font-size: 12px;
}

.msg .bubble .katex,
.msg .bubble .katex * {
  overflow-wrap: normal !important;
  word-break: normal !important;
}

.msg .bubble .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

.msg.user .bubble {
  border-color: #bfd0ff;
  background: #eef3ff;
}

.hint {
  font-size: 13px;
  color: var(--subtext);
}

.tools-trace {
  margin-top: 8px;
  font-size: 12px;
  color: var(--subtext);
}

.warning { color: var(--warn); }
.success { color: var(--good); }
