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

:root {
  --primary: #4f7cff;
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e5e8f0;
  --text: #2b3040;
  --muted: #8a91a5;
}

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 18px; }

nav { display: flex; gap: 8px; }
nav button {
  padding: 7px 18px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
nav button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

main { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; padding: 20px 24px; overflow-y: auto; }
.view.active { display: block; }

/* 搜索 */
.search-box { display: flex; gap: 10px; margin-bottom: 18px; }
.search-box input, .chat-box input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
button { padding: 11px 20px; border: none; border-radius: 8px; background: var(--primary); color: #fff; cursor: pointer; font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card .meta { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.card .meta .dist { float: right; font-family: monospace; }
.card .text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }

.hint, .error { color: var(--muted); padding: 12px 4px; }
.error { color: #d14343; }

/* 问答 */
#view-chat { display: none; flex-direction: column; }
#view-chat.active { display: flex; }
#chat-log { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.msg { margin-bottom: 14px; display: flex; }
.msg .content {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { justify-content: flex-end; }
.msg.user .content { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant { justify-content: flex-start; }
.msg.assistant .content { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.sources { margin-top: 8px; font-size: 12px; color: var(--muted); }
.sources-title { font-weight: 600; margin-bottom: 6px; }
.source { border-left: 3px solid var(--border); padding-left: 10px; margin-bottom: 6px; }
.source .src-path { font-family: monospace; }
.source .src-text { margin-top: 3px; white-space: pre-wrap; }
.chat-box { display: flex; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }

/* 图谱 */
#view-graph.active { display: block; padding: 0; }
#graph-container { width: 100%; height: 100%; background: #fbfcfe; }
#graph-container svg { display: block; }

/* 顶部操作按钮 */
.actions { display: flex; gap: 8px; }
button.ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

/* 弹窗 */
.modal {
  position: fixed; inset: 0;
  background: rgba(20, 24, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  width: 520px; max-width: 92vw;
  background: #fff; border-radius: 12px;
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box h2 { font-size: 16px; }
.modal-box input, .modal-box select, .modal-box textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.modal-box textarea { min-height: 180px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #2b3040; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s;
  z-index: 200; max-width: 80vw;
}
#toast.show { opacity: 1; }
