:root {
  --bg: #ffffff;
  --bg-chrome: #f2f2f4;
  --bg-pane: #fbfbfc;
  --bg-hover: #ececf0;
  --bg-sel: #2f6fd0;
  --bg-sel-soft: #dce8fa;
  --fg: #1c1c1e;
  --fg-dim: #6b6b73;
  --fg-faint: #9a9aa2;
  --border: #d8d8de;
  --accent: #2f6fd0;
  --star: #e8a020;
  --radius: 5px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --row-h: 26px;
}

html[data-theme="dark"] {
  --bg: #1e1e21;
  --bg-chrome: #2a2a2e;
  --bg-pane: #232326;
  --bg-hover: #34343a;
  --bg-sel: #3c72c4;
  --bg-sel-soft: #2c3d55;
  --fg: #e8e8ea;
  --fg-dim: #a0a0a8;
  --fg-faint: #75757e;
  --border: #3a3a40;
  --accent: #5a94e0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 10px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.tb-left, .tb-right { display: flex; gap: 4px; }
.tb-search { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; }

.icon-btn {
  width: 28px; height: 26px;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius); cursor: pointer;
  color: var(--fg-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

.seg {
  display: flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.seg button {
  padding: 4px 11px; background: transparent; border: 0; cursor: pointer;
  color: var(--fg-dim); white-space: nowrap;
}
.seg button.active { background: var(--accent); color: #fff; }

.search-wrap { position: relative; flex: 0 1 420px; min-width: 160px; }
.search-icon {
  position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; color: var(--fg-faint); pointer-events: none;
}
#search {
  width: 100%; padding: 5px 8px 5px 25px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 13px; outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--bg-sel-soft); }

.mini-select {
  padding: 4px 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; color: var(--fg-dim);
}

/* ---------- 三栏 ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--w-left, 210px) 1px 1fr 1px var(--w-right, 380px);
  min-height: 0;
}

.pane { min-width: 0; min-height: 0; overflow: auto; }
.pane-left { background: var(--bg-pane); padding: 8px 0 24px; }
.pane-mid { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.pane-right { background: var(--bg-pane); display: flex; flex-direction: column; overflow: hidden; }

.splitter { background: var(--border); cursor: col-resize; }
.splitter:hover { background: var(--accent); }

/* ---------- 左栏 ---------- */
.sec-title {
  padding: 10px 12px 4px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--fg-faint);
}
.sec-title.with-action { display: flex; justify-content: space-between; align-items: center; }
.tiny-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--fg-faint);
  font-size: 15px; line-height: 1; padding: 0 4px; border-radius: 3px;
}
.tiny-btn:hover { background: var(--bg-hover); color: var(--fg); }

.tree { list-style: none; margin: 0; padding: 0; }
.tree li {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 12px; cursor: pointer; user-select: none;
  border-radius: 0; white-space: nowrap;
}
.tree li:hover { background: var(--bg-hover); }
.tree li.active { background: var(--bg-sel); color: #fff; }
.tree li.active .count, .tree li.active .ico { color: rgba(255,255,255,.8); }
.tree .ico { width: 14px; height: 14px; flex: 0 0 14px; color: var(--fg-dim); fill: currentColor; }
.tree .label { overflow: hidden; text-overflow: ellipsis; }
.tree .count { margin-left: auto; color: var(--fg-faint); font-size: 11px; }
.tree li .del {
  margin-left: auto; opacity: 0; color: inherit; border: 0; background: transparent;
  cursor: pointer; font-size: 13px; padding: 0 2px;
}
.tree li:hover .del { opacity: .6; }
.tree li .del:hover { opacity: 1; }

/* arXiv 分类树 */
.cat-filter {
  width: 88px; padding: 1px 6px; font-size: 11px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 9px; outline: none; text-transform: none;
  font-weight: 400; letter-spacing: 0; color: var(--fg);
}
.cat-filter:focus { border-color: var(--accent); width: 110px; }

.tree-cats { max-height: 44vh; overflow: auto; }
.tree-cats li { padding-top: 3px; padding-bottom: 3px; }
.tree-cats li.depth-0 { font-weight: 600; }
.tree-cats li.group { color: var(--fg-dim); }
.twisty {
  flex: 0 0 12px; width: 12px; text-align: center; color: var(--fg-faint);
  font-size: 9px; line-height: 1; user-select: none;
  transition: transform .12s ease;
}
.twisty.open { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }
.tree-cats li.active .twisty { color: rgba(255,255,255,.8); }
.cat-id { font-family: var(--mono); font-size: 11px; }
.tree-cats .label { font-size: 12px; }
.tree-cats li.hit .label { color: var(--accent); }
.tree-cats li.active.hit .label { color: #fff; }

.tagcloud { padding: 4px 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.tagcloud .tag {
  padding: 2px 7px; border-radius: 10px; background: var(--bg-hover);
  color: var(--fg-dim); font-size: 11px; cursor: pointer; border: 1px solid transparent;
}
.tagcloud .tag.active { background: var(--accent); color: #fff; }
.tagcloud:empty::after { content: "还没有标签"; color: var(--fg-faint); font-size: 11px; }

/* ---------- 中栏列表 ---------- */
.list-head {
  display: flex; align-items: center;
  height: 24px; flex: 0 0 auto;
  background: var(--bg-chrome); border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--fg-dim); user-select: none;
}
.list-head .col { padding: 0 8px; cursor: pointer; border-right: 1px solid var(--border); height: 100%; display: flex; align-items: center; }
.list-head .col:hover { background: var(--bg-hover); }
.col-star { flex: 0 0 26px; padding: 0 !important; justify-content: center; }
.col-title { flex: 1 1 auto; min-width: 0; }
.col-authors { flex: 0 0 26%; min-width: 0; }
.col-date { flex: 0 0 92px; border-right: 0 !important; }

.list-body { flex: 1 1 auto; overflow: auto; }
.row {
  display: flex; align-items: center;
  height: var(--row-h); cursor: default; user-select: none;
  border-bottom: 1px solid transparent;
}
.row:nth-child(even) { background: color-mix(in srgb, var(--bg-hover) 40%, transparent); }
.row:hover { background: var(--bg-hover); }
.row.sel { background: var(--bg-sel); color: #fff; }
.row.sel .cell-authors, .row.sel .cell-date, .row.sel .pill { color: rgba(255,255,255,.85); }
.row.sel .pill { background: rgba(255,255,255,.18); }
.row .cell { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-star { flex: 0 0 26px; padding: 0 !important; text-align: center; cursor: pointer; color: var(--fg-faint); }
.cell-star.on { color: var(--star); }
.cell-title { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 0; }
.cell-title .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-title .pill { flex: 0 0 auto; }
.cell-authors { flex: 0 0 26%; min-width: 0; color: var(--fg-dim); }
.cell-date { flex: 0 0 92px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.pill {
  display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 8px;
  background: var(--bg-sel-soft); color: var(--accent); font-size: 10px; vertical-align: 1px;
}
.row .in-lib { color: var(--star); margin-right: 4px; }

.list-foot {
  flex: 0 0 auto; padding: 5px 10px; border-top: 1px solid var(--border);
  color: var(--fg-faint); font-size: 11px; background: var(--bg-chrome);
  display: flex; align-items: center; gap: 10px;
}
.list-foot button {
  border: 1px solid var(--border); background: var(--bg); border-radius: var(--radius);
  padding: 2px 8px; cursor: pointer; color: var(--fg-dim);
}
.list-foot button:hover { background: var(--bg-hover); color: var(--fg); }

.empty {
  padding: 40px 20px; text-align: center; color: var(--fg-faint); line-height: 1.7;
}

/* ---------- 右栏详情 ---------- */
.detail-tabs {
  display: flex; flex: 0 0 auto;
  background: var(--bg-chrome); border-bottom: 1px solid var(--border);
}
.detail-tabs button {
  padding: 6px 14px; background: transparent; border: 0; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--fg-dim);
}
.detail-tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }

.detail-body { flex: 1 1 auto; overflow: auto; display: flex; flex-direction: column; }
.detail-pad { padding: 14px 16px 30px; }

.d-title { font-size: 15px; font-weight: 600; line-height: 1.4; margin: 0 0 8px; }
.d-authors { color: var(--fg-dim); line-height: 1.6; margin-bottom: 10px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.btn {
  padding: 4px 10px; border: 1px solid var(--border); background: var(--bg);
  border-radius: var(--radius); cursor: pointer; color: var(--fg);
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #c0392b; }

.meta { display: grid; grid-template-columns: 74px 1fr; gap: 5px 10px; margin-bottom: 14px; }
.meta dt { color: var(--fg-faint); font-size: 11px; padding-top: 1px; }
.meta dd { margin: 0; word-break: break-word; }
.meta a { color: var(--accent); }
.meta code { font-family: var(--mono); font-size: 11.5px; }

.d-sec-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--fg-faint); margin: 16px 0 6px;
}
.abstract { line-height: 1.65; text-align: justify; white-space: pre-wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 8px; border-radius: 10px;
  background: var(--bg-hover); font-size: 11px;
}
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--fg-faint); line-height: 1; padding: 0 2px; }
.chip button:hover { color: #c0392b; }
.chip-input {
  border: 1px dashed var(--border); background: transparent; border-radius: 10px;
  padding: 2px 8px; width: 90px; outline: none; font-size: 11px;
}
.chip-input:focus { border-color: var(--accent); border-style: solid; }

#note {
  flex: 1 1 auto; width: 100%; border: 0; outline: none; resize: none;
  padding: 14px 16px; background: var(--bg); color: var(--fg);
  line-height: 1.7; font-family: var(--font);
}
.note-foot { flex: 0 0 auto; padding: 5px 12px; border-top: 1px solid var(--border); color: var(--fg-faint); font-size: 11px; background: var(--bg-chrome); }

.pdf-frame { flex: 1 1 auto; width: 100%; border: 0; background: #525659; }

.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 弹窗 / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: grid; place-items: center; z-index: 50;
}
.modal {
  background: var(--bg); border-radius: 8px; padding: 18px 20px; width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3); border: 1px solid var(--border);
}
.modal h3 { margin: 0 0 12px; font-size: 14px; }
.modal input {
  width: 100%; padding: 6px 9px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-hint { color: var(--fg-faint); font-size: 11px; margin: 6px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #262629; color: #fff; padding: 8px 16px; border-radius: 16px;
  font-size: 12px; z-index: 60; box-shadow: 0 4px 20px rgba(0,0,0,.3);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); background-clip: padding-box; }
