:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #24211c;
  --muted: #8a857c;
  --accent: #d97706;
  --accent-dark: #b45309;
  --border: #e7e2d9;
  --chip: #f1ede4;
  --good: #16a34a;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.brand h1 { font-size: 18px; margin: 0; }
.subtitle { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }

.panel { display: none; }
.panel.active { display: block; }

/* Ask */
.chat { display: flex; flex-direction: column; gap: 14px; min-height: 320px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.sources { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.source {
  background: #fbfaf7;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.source-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.source-title { font-weight: 600; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.tag.pages { background: #eaf4ee; color: var(--good); }
.source-body { display: none; margin-top: 8px; font-size: 13px; color: #555; line-height: 1.6; }
.source.open .source-body { display: block; }
.source-body ul { margin: 6px 0 0; padding-left: 18px; }
.source-body li { margin: 2px 0; }

.askbar { display: flex; gap: 10px; margin-top: 16px; }
.askbar input {
  flex: 1;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
}
.askbar button {
  padding: 13px 22px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
}
.askbar button:disabled { opacity: 0.6; cursor: not-allowed; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Browse */
#panel-browse { display: none; }
#panel-browse.active { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }

.filters { display: flex; flex-direction: column; gap: 16px; }
.filter-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.filter-group select, .filter-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.group-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.group-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.group-btn .cnt { float: right; color: var(--muted); }
.group-btn.active .cnt { color: #fff; }
.meta { font-size: 12px; color: var(--muted); }

.entries { display: flex; flex-direction: column; gap: 12px; }
.entry {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.entry-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.entry-title { font-size: 16px; font-weight: 700; }
.entry-summary { margin-top: 8px; font-size: 14px; line-height: 1.7; color: #333; }
.entry-facts { margin-top: 8px; padding-left: 18px; font-size: 13px; color: #555; }
.entry-facts li { margin: 3px 0; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.loading { color: var(--muted); font-size: 13px; }

/* v2 additions */
.muted { color: #8a8f98; font-size: 0.85em; margin-left: 6px; }
.entry-head { cursor: pointer; }
.entry-body { margin-top: 8px; }
.entry-body[hidden] { display: none; }
.doc-text { white-space: pre-wrap; font-family: inherit; font-size: 0.92em; line-height: 1.55; max-height: 60vh; overflow: auto; background: rgba(0,0,0,0.03); padding: 12px; border-radius: 8px; }
a.tag { text-decoration: none; }
