* { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #8b949e;
  --guide: #e7e9ec;
  --hover: #f2f4f7;
  --accent: #0b7bd8;
  --danger: #d1483b;
  --shadow: 0 8px 24px rgba(0, 0, 0, .12);
  --tag: #868c90;
  --tag-hover: #4a4f53;
}

html[data-theme="dark"] {
  --bg: #16181c;
  --fg: #e6e8eb;
  --muted: #8b949e;
  --guide: #2b3037;
  --hover: #1f2329;
  --accent: #4aa3ff;
  --danger: #ff6b5e;
  --shadow: 0 8px 24px rgba(0, 0, 0, .5);
  --tag: #9aa0a6;
  --tag-hover: #d0d4d8;
}

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--guide);
  background: var(--bg);
}

.crumbs {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  white-space: nowrap;
}

.crumb {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb:hover { background: var(--hover); color: var(--fg); }
.crumb.current { color: var(--fg); font-weight: 600; }
.sep { color: var(--muted); font-size: 12px; opacity: .7; }

.tools { display: flex; align-items: center; gap: 6px; }

.search {
  width: 200px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--hover);
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
}
.search:focus { border-color: var(--accent); background: var(--bg); }

.icon {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon:hover { background: var(--hover); color: var(--fg); }

/* ---------------- 菜单 ---------------- */
.menu {
  position: fixed;
  top: 50px;
  right: 16px;
  z-index: 40;
  min-width: 190px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--guide);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { margin: 5px 6px; border: 0; border-top: 1px solid var(--guide); }

/* ---------------- 主体 ---------------- */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 22px 16px 45vh;
}

.outline { max-width: 820px; margin: 0 auto; }

.item { position: relative; }

/* 「还有更多，点一下继续显示」——子项特别多时避免一次渲染几万行 */
.more-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 4px 8px 4px 34px;
  margin: 2px 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted, #888);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  opacity: .85;
}
.more-row:hover { background: var(--hover); opacity: 1; }

.row {
  display: flex;
  align-items: flex-start;
  border-radius: 6px;
}
.ver { font-size: 11px; color: var(--muted); user-select: none; }

/* 鼠标移过去不再给整行上底色（读长文时跟着鼠标跳来跳去很干扰）；
   只有光标所在的那一条有一层很淡的灰底，方便知道自己读到哪 */
.row:focus-within { background: var(--hover); }

.toggle {
  flex: 0 0 18px;
  width: 18px;
  height: 26px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 9px;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .1s;
}
.toggle.has { opacity: .5; }
.row:hover .toggle.has { opacity: 1; }
.toggle.leaf { pointer-events: none; }
.toggle .count {
  display: inline-block;
  margin-left: 1px;
  font-size: 9px;
  vertical-align: 1px;
}

.bullet {
  flex: 0 0 22px;
  width: 22px;
  height: 26px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  position: relative;
}
.bullet .dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .65;
  transition: transform .1s, background .1s;
}
.bullet:hover .dot { background: var(--accent); opacity: 1; transform: scale(1.35); }
.item.collapsed > .row > .bullet .dot {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--fg);
  opacity: .8;
}
.item.done > .row > .bullet .dot { background: var(--accent); opacity: .9; }

.content {
  flex: 1;
  min-width: 0;
  min-height: 26px;
  padding: 2px 6px 2px 0;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
}

.item.done > .row > .content {
  color: var(--muted);
  text-decoration: line-through;
  opacity: .75;
}

/* 备注 */
.note {
  margin-left: 40px;
  border-left: 2px solid transparent;
}
.note.hidden { display: none; }

.note-content {
  min-height: 20px;
  padding: 1px 6px 5px 0;
  outline: none;
  font-size: .93em;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
}
.note-content:empty::before {
  content: '备注…';
  color: var(--muted);
  opacity: .55;
}
.item.done > .note > .note-content { opacity: .6; }

/* 行内富文本 */
.content a,
.note-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.content a:hover,
.note-content a:hover { border-bottom-color: var(--accent); }

.content code,
.note-content code {
  padding: 0 4px;
  border: 1px solid var(--guide);
  border-radius: 4px;
  background: var(--hover);
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: .9em;
}

.content strong { font-weight: 650; }

/* #标签 / @提到：跟 Workflowy 一样，灰色字 + 同色细下划线（颜色取自 Workflowy 截图：#868C90）。
   点一下就是按这个标签过滤 */
.tag {
  padding: 0;
  border-radius: 0;
  color: var(--tag);
  background: none;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--tag);
  text-underline-offset: 3px;
  cursor: pointer;
}
.tag:hover { color: var(--tag-hover); text-decoration-color: var(--tag-hover); }

/* 过滤时的上下文条目（只是为了显示层级，本身没命中） */
.item.ctx > .row > .content { color: var(--muted); }
.item.ctx > .row > .bullet .dot { opacity: .22; }
.item.ctx > .row > .toggle { opacity: .3; }

.empty-state {
  padding: 26px 4px;
  color: var(--muted);
  font-size: 14px;
}

.children {
  margin-left: 12px;
  padding-left: 15px;
  border-left: 1px solid var(--guide);
}

/* 拖拽 */
.item[data-drop="before"] > .row { box-shadow: inset 0 2px 0 var(--accent); }
.item[data-drop="after"] > .row { box-shadow: inset 0 -2px 0 var(--accent); }
.item[data-drop="inside"] > .row { outline: 1.5px solid var(--accent); outline-offset: -1px; }
.item.dragging { opacity: .4; }

/* ---------------- 多选：拖圆点框选 / Shift+点行 ---------------- */
body.selecting { user-select: none; cursor: grabbing; }
.item.selected > .row {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 5px;
}
.item.selected > .row > .bullet .dot {
  background: var(--accent);
  opacity: 1;
  transform: scale(1.15);
}
.item.in-sel > .row { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* 搜索结果 */
.search-head {
  margin: 4px 0 14px;
  font-size: 13px;
  color: var(--muted);
}
.search-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.search-item:hover { background: var(--hover); }
.search-path { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.search-text { white-space: pre-wrap; overflow-wrap: anywhere; }
/* 搜索命中的关键词：蓝色高亮（这是程序里唯一的蓝色底纹） */
mark,
mark.hit {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------------- 状态栏 ---------------- */
.status {
  position: sticky;
  bottom: 0;
  padding: 5px 16px;
  border-top: 1px solid var(--guide);
  background: var(--bg);
  color: var(--muted);
  font-size: 11.5px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.status-left { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status.warn { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--bg)); font-weight: 600; }
.status.warn .pill { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

.status .pill {
  font: inherit;
  font-size: 11px;
  line-height: 1.6;
  padding: 1px 9px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.status .pill:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  padding: 20px;
}
.modal-box {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  overflow: auto;
  padding: 22px 24px;
  background: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.modal-box h2 { margin: 0 0 14px; font-size: 17px; }
.modal-box table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.modal-box th {
  width: 42%;
  padding: 6px 10px 6px 0;
  text-align: left;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  vertical-align: top;
}
.modal-box td { padding: 6px 0; border-top: 1px solid var(--guide); }
.modal-box .tip { margin: 14px 0 18px; font-size: 12.5px; color: var(--muted); }
.primary {
  padding: 8px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

/* ---------------- 导入时锁住页面 ---------------- */
.busy {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .25);
  cursor: progress;
}
.busy-box {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  padding: 16px 22px;
  background: var(--bg);
  color: var(--fg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--guide);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 退出过滤后停在的那一条：闪一下底色 */
.item.landed > .row { animation: landed 1.6s ease-out; border-radius: 6px; }
@keyframes landed {
  0%, 30% { background: color-mix(in srgb, var(--accent) 22%, transparent); }
  100% { background: transparent; }
}

/* ---------------- 云端版：登录 ---------------- */
.login {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h2 { margin: 0; font-size: 18px; }
.login-box .tip { margin: 0; font-size: 13px; color: var(--muted); }
.login-pw {
  padding: 10px 12px;
  font: inherit;
  color: var(--fg);
  background: var(--hover);
  border: 1px solid var(--guide);
  border-radius: 8px;
  outline: none;
}
.login-pw:focus { border-color: var(--accent); background: var(--bg); }
.login-err { min-height: 1.4em; margin: 0; color: var(--danger); font-size: 13px; }

/* 退出过滤按钮（手机上没有 Esc）；浏览器自带的小 × 藏掉，免得两个 */
.search-clear { color: var(--accent); font-size: 15px; }
.search::-webkit-search-cancel-button { display: none; }

.diag-text { width: 100%; height: 260px; font: 12px/1.5 ui-monospace, Consolas, monospace; color: var(--fg); background: var(--hover); border: 1px solid var(--guide); border-radius: 8px; padding: 8px; }

.ver.ver-bad { color: var(--danger); font-weight: 700; cursor: help; }

.hidden { display: none !important; }
