:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e3e6ec;
  --text: #22262e;
  --muted: #6b7280;
  --accent: #1d6fb8;
  --accent-soft: #e8f2fc;
  --danger: #b4453f;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 600; letter-spacing: .2px; }
.badge {
  margin-left: 10px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 400;
}
.badge.warn { background: #fff3e0; color: #9a6412; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status { font-size: 12px; color: var(--muted); min-width: 120px; text-align: right; }

button, .file-btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 12px; font-size: 13px;
}
button:hover, .file-btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { color: #fff; opacity: .9; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.file-btn input { display: none; }

.layout {
  display: grid; grid-template-columns: 250px minmax(320px, 1fr) 340px;
  gap: 14px; padding: 14px; height: calc(100vh - 57px);
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; min-height: 0;
  display: flex; flex-direction: column;
}
.section-title { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.libs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.lib {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 11px; border-radius: 8px; border: 1px solid transparent;
  background: #f4f6f9; cursor: pointer; font-size: 13px;
}
.lib:hover { border-color: var(--border); }
.lib.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.lib .count { font-size: 12px; color: var(--muted); }
.lib.active .count { color: var(--accent); }

.list-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--muted); padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.list-head button { padding: 3px 9px; font-size: 12px; }
.note-list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.note-list li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
}
.note-list li:hover { background: #f4f6f9; }
.note-list li.active { background: var(--accent-soft); }
.note-list .t { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list .d { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.note-list .dirty { color: #b07a17; }

.editor-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.editor-bar input { flex: 1; min-width: 150px; }
.editor-bar select, .editor-bar input, .ask-controls select {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface);
}
#note-body, #ask-input {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; resize: none; background: #fcfcfd; line-height: 1.7;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px;
}
#note-body { flex: 1; min-height: 180px; }
#ask-input { height: 88px; }
.preview {
  flex: 1; min-height: 180px; overflow-y: auto; padding: 4px 14px;
  border: 1px solid var(--border); border-radius: 8px; line-height: 1.8;
}
.preview h3, .preview h4 { margin: 14px 0 8px; }
.preview code { background: #f0f2f5; padding: 2px 5px; border-radius: 4px; }
.preview pre { background: #f0f2f5; padding: 10px; border-radius: 8px; overflow-x: auto; }
.preview .wikilink { color: var(--accent); }
.editor-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; font-size: 12px; color: var(--muted);
}

.ask-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.ask-controls select { flex: 1; }
.ask-controls button { background: var(--accent); color: #fff; border-color: var(--accent); }
.sources { margin-top: 12px; overflow-y: auto; flex: 1; min-height: 60px; }
.source {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px;
  margin-bottom: 8px; font-size: 12px; cursor: pointer;
}
.source:hover { border-color: var(--accent); }
.source .s-title { font-weight: 600; margin-bottom: 4px; }
.source .s-text { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.answer {
  border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px;
  font-size: 13px; line-height: 1.8; white-space: pre-wrap; min-height: 48px;
}
.empty { color: var(--muted); font-size: 12px; padding: 8px 0; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { min-height: 260px; }
  .note-list { max-height: 220px; }
}
