:root {
  --bg: #f7f6f3;
  --panel: #fffefb;
  --line: #e4e0d8;
  --ink: #24211d;
  --dim: #8b8478;
  --accent: #a4573a;
  --accent-soft: #f3e5de;
  --hit: #fff3cd;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", "Menlo", "Sarasa Mono SC", monospace;
  --sans: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a; --panel: #1e1e21; --line: #302f33; --ink: #e6e3dd;
    --dim: #948f86; --accent: #d08a6a; --accent-soft: #35271f; --hit: #4a4326;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  font-size: 15px; -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; font-size: 13px; cursor: pointer; }
input, select { font-family: inherit; font-size: 14px; }

/* ---------- 启动 / 登录 / 初始化 ---------- */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  color: var(--dim); font-size: 14px; background: var(--bg); z-index: 50;
}
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); padding: 20px; z-index: 40;
}
.gate-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,.06);
}
.gate-card h1 { margin: 0 0 6px; font-size: 20px; font-weight: 650; letter-spacing: .5px; }
.gate-card .sub { margin: 0 0 18px; color: var(--dim); font-size: 13px; line-height: 1.6; }
.gate-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--dim); }
.gate-card input, .gate-card select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; outline: none;
}
.gate-card input:focus, .gate-card select:focus { border-color: var(--accent); }
.gate-card .primary {
  width: 100%; padding: 11px; border: none; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}
.gate-card .primary:disabled { opacity: .6; cursor: default; }
.err { color: #c0392b; font-size: 12.5px; min-height: 18px; margin-top: 10px; line-height: 1.5; }
#setupFields .row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
#setupFields .row span { width: 84px; font-size: 13px; color: var(--dim); }
#setupFields .row input { margin: 0; padding: 8px 10px; }

/* ---------- 顶栏 ---------- */
.app { display: flex; flex-direction: column; height: 100%; }
.top {
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  height: 52px; min-height: 52px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.icon {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  width: 30px; height: 30px; border-radius: 8px; line-height: 1;
}
.icon:hover { color: var(--ink); border-color: var(--dim); }
#btnMenu { display: none; }
.brand { font-weight: 650; font-size: 14px; letter-spacing: .6px; white-space: nowrap; }
.searchwrap { position: relative; flex: 1; max-width: 520px; }
.searchwrap input {
  width: 100%; padding: 7px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none;
}
.searchwrap input:focus { border-color: var(--accent); }
.hits {
  position: absolute; top: 40px; left: 0; right: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  max-height: 60vh; overflow: auto; box-shadow: 0 12px 30px rgba(0,0,0,.12);
}
.hit { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hit:last-child { border-bottom: none; }
.hit:hover { background: var(--accent-soft); }
.hit .t { font-size: 13.5px; font-weight: 600; }
.hit .s { font-size: 12px; color: var(--dim); margin-top: 3px; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hit .z { font-size: 11px; color: var(--accent); }
.usermenu { position: relative; margin-left: auto; }
.who {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  padding: 6px 12px; border-radius: 20px; font-size: 13px;
}
.dropdown {
  position: absolute; right: 0; top: 40px; z-index: 40; width: 250px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 6px; box-shadow: 0 12px 30px rgba(0,0,0,.12);
}
.ditem { padding: 9px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.ditem:hover { background: var(--accent-soft); }
.dnote { font-size: 11.5px; color: var(--dim); line-height: 1.5; margin-top: 4px; }
.switchline { display: flex; align-items: center; gap: 7px; cursor: pointer; }

/* ---------- 主体 ---------- */
.body { display: flex; flex: 1; min-height: 0; }
.side {
  width: 268px; min-width: 268px; border-right: 1px solid var(--line);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.sidehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 8px; font-size: 12px; color: var(--dim); letter-spacing: .8px;
}
.mini {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  border-radius: 7px; padding: 3px 9px; font-size: 12px;
}
.mini:hover { color: var(--ink); border-color: var(--dim); }
.tree { flex: 1; overflow: auto; padding: 0 6px 14px; }
.zone { margin-bottom: 6px; }
.zonename {
  padding: 7px 8px; font-size: 12px; font-weight: 650; color: var(--dim);
  letter-spacing: .5px; display: flex; align-items: center; gap: 6px;
  border-radius: 7px; cursor: pointer; user-select: none;
}
.zonename:hover { background: var(--accent-soft); }
.zonename .lock { font-size: 10px; color: var(--accent); }
.zonename .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 折叠箭头：空文件夹也有，避免「看着像禁用」 */
.tw { width: 10px; flex: none; font-size: 10px; color: var(--dim); opacity: .8; }
.cnt { font-size: 10.5px; color: var(--dim); opacity: .75; flex: none; }
.cnt.zero { opacity: .5; }
.node {
  padding: 5px 8px 5px 14px; border-radius: 7px; font-size: 13.5px;
  color: var(--ink); cursor: pointer; display: flex; gap: 6px; align-items: baseline;
  user-select: none;
}
.node:hover { background: var(--accent-soft); }
.node.active { background: var(--accent-soft); font-weight: 600; }
.node.dir { color: var(--dim); font-size: 12.5px; }
.node.dir .nm { font-weight: 600; }
.node.dir.sel { background: var(--accent-soft); color: var(--ink); }
.node .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .tag { font-size: 10px; color: var(--accent); margin-left: auto; }
/* 行内 ＋：hover 才出现，给「空文件夹」一个明确的落点 */
.rowact {
  opacity: 0; flex: none; border: none; background: transparent; color: var(--dim);
  font-size: 13px; line-height: 1; padding: 1px 4px; border-radius: 5px;
}
.node:hover .rowact, .zonename:hover .rowact { opacity: 1; }
.rowact:hover { background: var(--line); color: var(--ink); }
.emptynode { font-size: 12px; color: var(--dim); opacity: .65; padding: 4px 8px; font-style: italic; }

/* ---------- 拖拽 ---------- */
.node.dragging { opacity: .45; }
/* 落点高亮：区域头与文件夹都套同一条，避免「不知道松手会发生什么」 */
.zonename.dragover, .node.dir.dragover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.zonename.dragover .nm, .node.dir.dragover .nm { color: var(--ink); }

/* ---------- 多选 ---------- */
.node.sel { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.selbar {
  display: flex; align-items: center; gap: 6px; margin: 0 6px 8px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); font-size: 12px; color: var(--dim);
}
.selbar .n { flex: 1; color: var(--ink); font-weight: 600; }
.selbar button {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  border-radius: 6px; padding: 3px 8px; font-size: 11.5px; cursor: pointer;
}
.selbar button:hover { color: var(--ink); border-color: var(--dim); }
.selbar .dl:hover { color: #c0392b; border-color: #c0392b; }

/* ---------- 对话框 / 右键菜单 ---------- */
.dlgbg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .28); z-index: 60;
  display: grid; place-items: center; padding: 18px;
}
.dlg {
  width: 100%; max-width: 420px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 13px; padding: 18px 18px 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
}
.dlgtitle { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
.fld { display: block; margin-bottom: 11px; font-size: 12px; color: var(--dim); }
.fld > span { display: block; margin-bottom: 5px; }
.fld input, .fld select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); outline: none;
}
.fld input:focus, .fld select:focus { border-color: var(--accent); }
.dlgerr { color: #c0392b; font-size: 12px; min-height: 16px; }
.dlgfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.mini.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.mini.primary:disabled { opacity: .6; cursor: default; }
.ctx {
  position: fixed; z-index: 70; min-width: 172px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .16);
}
.citem { padding: 7px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.citem:hover { background: var(--accent-soft); }
.csep { height: 1px; background: var(--line); margin: 4px 2px; }
.sidefoot { border-top: 1px solid var(--line); padding: 8px 12px; font-size: 11px;
  color: var(--dim); line-height: 1.5; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.notehead {
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  height: 40px; min-height: 40px; border-bottom: 1px solid var(--line);
}
.pathline { font-size: 12px; color: var(--dim); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.noteacts { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.save { font-size: 11.5px; color: var(--dim); }
.save.ok { color: #3f8a5a; }
.save.err { color: #c0392b; }
.conflict {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--hit); font-size: 12.5px; border-bottom: 1px solid var(--line);
}
.extchange {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: #e6f0fb; font-size: 12.5px; border-bottom: 1px solid var(--line);
}
@media (prefers-color-scheme: dark) { .extchange { background: #1c2a3a; } }
.editorwrap { position: relative; flex: 1; min-height: 0; display: flex; }
.editor { flex: 1; min-width: 0; overflow: hidden; }
.preview { flex: 1; overflow: auto; padding: 20px 26px 30vh; line-height: 1.75; }

/* ---------- 大纲面板（T19：标题跳转） ---------- */
.outline {
  width: 190px; flex: none; overflow: auto; padding: 10px 8px 24px;
  border-right: 1px solid var(--line); background: var(--panel);
  font-size: 12.5px; line-height: 1.5;
}
.outline .ohead {
  font-size: 10.5px; color: var(--dim); letter-spacing: .5px;
  padding: 0 6px 6px; display: flex; justify-content: space-between; align-items: center;
}
.outline .oitem {
  display: block; width: 100%; text-align: left; border: none; background: none;
  color: var(--ink); cursor: pointer; padding: 3px 6px; border-radius: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.outline .oitem:hover { background: var(--accent-soft); }
.outline .oitem .ol { color: var(--dim); font-size: 10px; margin-right: 5px; }
.outline .emptyo { color: var(--dim); padding: 4px 6px; font-size: 11.5px; }
@media (max-width: 760px) { .outline { display: none !important; } }

/* ---------- 侧栏底部：最近打开 ---------- */
.sidefoot { overflow: auto; max-height: 30vh; }
.rfhead { font-size: 10.5px; color: var(--dim); letter-spacing: .5px; padding: 6px 8px 2px; }
.ritem {
  font-size: 12px; color: var(--ink); cursor: pointer;
  padding: 3px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ritem:hover { background: var(--accent-soft); }
.rempty { font-size: 11.5px; color: var(--dim); padding: 2px 8px; }
.rvault { font-size: 10.5px; color: var(--dim); opacity: .7; padding: 4px 8px 8px; }
.fstar { color: #e8a020; font-size: 10px; margin-right: 4px; flex: none; }
.empty { position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; pointer-events: none; }
.emptytitle { font-size: 15px; color: var(--dim); }
.emptysub { font-size: 12.5px; color: var(--dim); margin-top: 8px; opacity: .8; }

/* ---------- 预览排版 ---------- */
.preview h1, .preview h2, .preview h3 { line-height: 1.35; margin: 1.4em 0 .5em; }
.preview h1 { font-size: 1.55em; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.preview h2 { font-size: 1.28em; }
.preview h3 { font-size: 1.1em; }
.preview p { margin: .8em 0; }
.preview code { font-family: var(--mono); font-size: .9em;
  background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.preview pre { background: var(--accent-soft); padding: 12px 14px; border-radius: 9px;
  overflow: auto; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--accent);
  color: var(--dim); }
.preview ul, .preview ol { padding-left: 1.4em; }
.preview li { margin: .25em 0; }
.preview img { max-width: 100%; border-radius: 8px; }
.preview a { color: var(--accent); }
.preview hr { border: none; border-top: 1px solid var(--line); margin: 1.6em 0; }
.preview table { border-collapse: collapse; margin: 1em 0; font-size: .94em; }
.preview td, .preview th { border: 1px solid var(--line); padding: 5px 9px; }
.fm { font-size: 12px; color: var(--dim); background: var(--bg); border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; font-family: var(--mono); white-space: pre-wrap; }

/* ---------- 手机 ---------- */
@media (max-width: 760px) {
  #btnMenu { display: block; }
  .brand { display: none; }
  .side {
    position: fixed; left: 0; top: 52px; bottom: 0; z-index: 35;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.18); width: 82vw; min-width: 0;
  }
  .side.open { transform: translateX(0); }
  .notehead { height: 36px; min-height: 36px; }
  .preview { padding: 14px 16px 40vh; }
  .dropdown { width: 76vw; }
}

/* 家庭成员口令面板（管理员） */
#members .gate-card { max-width: 440px; }
#memberRows .mrow {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 8px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
#memberRows .mrow:last-child { border-bottom: none; }
#memberRows .mname { font-size: 13.5px; font-weight: 600; }
#memberRows .mname small { display: block; font-weight: 400; color: var(--dim); font-size: 11.5px; margin-top: 2px; }
#memberRows .mstat { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; align-self: center; }
#memberRows .mstat.on { color: #1f7a4d; background: rgba(31,122,77,.12); }
#memberRows .mstat.off { color: #b3541e; background: rgba(179,84,30,.12); }
#memberRows .mrow input { grid-column: 1 / 2; margin: 0; padding: 8px 10px; }
#memberRows .mrow button { grid-column: 2 / 3; align-self: center; }

/* ---------------------------------------------------------- 跨模块联动（M2-B） */
.linklist { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.linkbtn { font-size: 12.5px; padding: 6px 10px; }
.linkbtn:disabled { opacity: .45; cursor: not-allowed; }
.linkhint { font-size: 11.5px; color: var(--dim); margin-bottom: 8px; line-height: 1.5; }
.linkprev {
  width: 100%; min-height: 210px; max-height: 46vh; resize: vertical;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink);
}
.linkprev:focus { outline: none; border-color: var(--accent); }
