/* ---------- 设计变量 ---------- */
:root {
  --sidebar-w: 286px;
  --ink: #1c2430;
  --ink-2: #4a5568;
  --ink-3: #8792a2;
  --line: #e4e8ee;
  --line-soft: #eef1f5;
  --bg: #fbfbfc;
  --paper: #ffffff;
  --navy: #1f3a5f;
  --navy-2: #16294a;
  --navy-hi: #2c5183;
  --gold: #c79a4a;
  --gold-soft: #f2e3c6;
  --danger: #c0392b;
  --ok: #2f7d5d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC",
          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* 作者样式里的 display 会覆盖 UA 的 [hidden]，这里强制生效 */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- 布局 ---------- */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

#sidebar {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #dbe4f0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid rgba(255, 255, 255, .06);
}

#main {
  min-width: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
}

/* ---------- 侧栏 ---------- */
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  font-size: 16px; font-weight: 600; letter-spacing: .5px;
  color: #fff;
  flex: 0 0 auto;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold), #a87c33);
  color: #23180a; font-size: 13px; font-weight: 700;
}
.brand-text { flex: 1; }
.only-mobile { display: none; }

.side-search { padding: 0 14px 10px; flex: 0 0 auto; }
.side-search input {
  width: 100%; padding: 9px 12px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .07);
  color: #eaf0f8; outline: none;
  transition: border-color .15s, background .15s;
}
.side-search input::placeholder { color: #9fb0c8; }
.side-search input:focus { border-color: var(--gold); background: rgba(255, 255, 255, .11); }

.side-tools {
  display: flex; gap: 8px; padding: 0 14px 8px; flex: 0 0 auto;
}
.tool-btn {
  flex: 1; padding: 7px 8px; border-radius: 7px; cursor: pointer;
  border: 1px dashed rgba(255, 255, 255, .22);
  background: transparent; color: #c9d6e8; font-size: 13px;
  transition: .15s;
}
.tool-btn:hover { border-color: var(--gold); color: #fff; background: rgba(255, 255, 255, .06); }

.tree { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 16px; min-height: 0; }
.tree::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 8px; }

.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: 7px; cursor: pointer;
  color: #c3d0e2; font-size: 14px; line-height: 1.3;
  user-select: none; position: relative;
  transition: background .12s, color .12s;
}
.tree-row:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.tree-row.active { background: rgba(199, 154, 74, .18); color: #fff; box-shadow: inset 2px 0 0 var(--gold); }
.tree-row .caret {
  width: 14px; text-align: center; font-size: 10px; color: #8ea2bd; flex: 0 0 auto;
  transition: transform .15s;
}
.tree-row .caret.open { transform: rotate(90deg); }
.tree-row .ico { flex: 0 0 auto; font-size: 13px; opacity: .85; }
.tree-row .label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-row .more {
  opacity: 0; border: 0; background: transparent; color: #a9b8cd;
  cursor: pointer; padding: 0 3px; border-radius: 4px; font-size: 14px; line-height: 1;
}
.tree-row:hover .more { opacity: 1; }
.tree-row .more:hover { color: #fff; background: rgba(255, 255, 255, .12); }

.tree-children { margin-left: 12px; border-left: 1px solid rgba(255, 255, 255, .09); padding-left: 4px; }
.tree-children[hidden] { display: none; }
.tree-empty { color: #8ea2bd; font-size: 13px; padding: 12px 10px; }

.user-box {
  flex: 0 0 auto; padding: 12px 18px; border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px; line-height: 1.5;
}
.user-mail { color: #c9d6e8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--gold); margin-top: 2px; }

/* ---------- 状态页 ---------- */
.state-pane {
  height: 100%; display: grid; place-content: center; justify-items: center;
  gap: 10px; padding: 40px; text-align: center; color: var(--ink-2);
}
.state-pane h2 { margin: 0; font-size: 20px; color: var(--ink); }
.state-pane .muted { color: var(--ink-3); font-size: 13px; max-width: 420px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--navy);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 阅读区 ---------- */
#reader { max-width: 860px; margin: 0 auto; padding: 44px 48px 120px; }
.reader-head { margin-bottom: 8px; }
.crumbs { font-size: 12px; color: var(--ink-3); margin-bottom: 10px; letter-spacing: .3px; }
.crumbs span + span::before { content: " / "; color: #c9d0da; }
#docTitle {
  margin: 0 0 10px; font-size: 30px; line-height: 1.35; letter-spacing: -.2px;
  font-weight: 700; color: #14202e;
}
.doc-meta { font-size: 12px; color: var(--ink-3); display: flex; gap: 14px; flex-wrap: wrap; }
.reader-actions { display: flex; gap: 8px; margin-top: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--line-soft); }

.empty-pane { text-align: center; color: var(--ink-3); padding: 90px 40px; }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .6; }

/* ---------- 正文排版 ---------- */
.doc-body {
  font-size: 16px; line-height: 1.9; color: #26303d;
  word-break: break-word;
}
.doc-body > :first-child { margin-top: 1.2em; }
.doc-body h1, .doc-body h2, .doc-body h3, .doc-body h4 {
  color: #14202e; line-height: 1.4; font-weight: 700;
  margin: 1.9em 0 .65em;
}
.doc-body h1 { font-size: 25px; }
.doc-body h2 {
  font-size: 21px; padding-left: 11px; border-left: 3px solid var(--gold);
}
.doc-body h3 { font-size: 18px; }
.doc-body h4 { font-size: 16px; color: var(--ink-2); }
.doc-body p { margin: 0 0 1.05em; }
.doc-body a { color: #1b5fae; text-decoration: underline; text-underline-offset: 2px; }
.doc-body a:hover { color: #0d447f; }
.doc-body strong { color: #101822; }
.doc-body ul, .doc-body ol { padding-left: 1.5em; margin: 0 0 1.1em; }
.doc-body li { margin: .3em 0; }
.doc-body li::marker { color: var(--gold); }
.doc-body blockquote {
  margin: 1.3em 0; padding: 12px 18px;
  background: #f7f5f0; border-left: 3px solid var(--gold);
  color: #55504a; border-radius: 0 8px 8px 0;
}
.doc-body blockquote p:last-child { margin-bottom: 0; }
.doc-body code {
  font-family: var(--mono); font-size: .88em;
  background: #f1f3f7; padding: 2px 6px; border-radius: 5px; color: #a1401f;
}
.doc-body pre {
  background: #1d2430; color: #e6edf6; padding: 16px 18px; border-radius: 10px;
  overflow-x: auto; margin: 1.3em 0; line-height: 1.65; font-size: 13.5px;
}
.doc-body pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.doc-body img { max-width: 100%; height: auto; border-radius: 8px; margin: 1em 0; display: block; }
.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.doc-body table { border-collapse: collapse; width: 100%; margin: 1.3em 0; font-size: 14.5px; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.doc-body th { background: #f5f7fa; font-weight: 600; }
.doc-body mark { background: #fdf0c8; padding: 0 2px; }

/* ---------- 编辑器 ---------- */
#editor { max-width: 900px; margin: 0 auto; padding: 32px 40px 140px; }
.editor-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.editor-title {
  flex: 1; min-width: 0; border: 0; border-bottom: 2px solid transparent;
  font-size: 26px; font-weight: 700; padding: 6px 2px; background: transparent; outline: none;
  color: #14202e;
}
.editor-title:focus { border-bottom-color: var(--gold-soft); }
.editor-head-actions { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }
.dirty-dot { font-size: 12px; color: #b7791f; background: #fdf5e4; padding: 3px 8px; border-radius: 20px; }

.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 2px; align-items: center;
  padding: 7px 8px; margin-bottom: 14px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .04);
}
.toolbar .tb {
  border: 0; background: transparent; cursor: pointer;
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: 6px;
  font-size: 13.5px; color: var(--ink-2); line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.toolbar .tb:hover { background: #eef2f8; color: var(--ink); }
.toolbar .tb.active { background: #e3ecf9; color: #1b4f8a; }
.toolbar .tb b, .toolbar .tb i, .toolbar .tb u, .toolbar .tb s { pointer-events: none; }
.toolbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 5px; }
.toolbar select.tb { padding: 0 4px; }

.editor-area {
  min-height: 60vh; outline: none; padding: 8px 2px;
  border-top: 1px solid var(--line-soft); padding-top: 22px;
}
.editor-area:empty::before {
  content: "从这里开始写…"; color: #b6bfcc;
}
.editor-area:focus:empty::before { content: ""; }
.preview-area { border-top: 1px solid var(--line-soft); padding-top: 22px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #c8d1de; background: #f8fafc; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-hi); border-color: var(--navy-hi); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #efd4d0; }
.btn.danger:hover { background: #fdf3f2; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 18px;
  color: #dbe4f0; padding: 2px 6px; border-radius: 6px;
}

/* ---------- 弹窗 ---------- */
.dialog-mask {
  position: fixed; inset: 0; background: rgba(14, 22, 34, .45);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  animation: fade .14s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  background: #fff; border-radius: 14px; box-shadow: 0 24px 60px rgba(10, 18, 30, .28);
  width: min(440px, 100%); padding: 22px 22px 18px;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.dialog h3 { margin: 0 0 14px; font-size: 17px; }
.dialog .field { margin-bottom: 12px; }
.dialog label { display: block; font-size: 12.5px; color: var(--ink-3); margin-bottom: 6px; }
.dialog input[type=text] {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.dialog input[type=text]:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31, 58, 95, .08); }
.dialog p.hint { font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* 右键/更多 菜单 */
.menu {
  position: fixed; z-index: 120; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 148px;
  animation: pop .1s ease-out;
}
.menu button {
  display: flex; width: 100%; gap: 8px; align-items: center;
  border: 0; background: transparent; padding: 8px 10px; border-radius: 6px;
  cursor: pointer; font-size: 13.5px; color: var(--ink); text-align: left;
}
.menu button:hover { background: #f2f5fa; }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: #fdf3f2; }
.menu .divider { height: 1px; background: var(--line-soft); margin: 4px 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #22303f; color: #fff; padding: 10px 20px; border-radius: 22px;
  font-size: 13.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .22); z-index: 200;
  animation: toastIn .2s ease-out;
  max-width: 80vw;
}
.toast.error { background: #a4342a; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* 搜索结果 */
.tree .search-hit .label { white-space: normal; }
.tree .search-hit .snip { display: block; font-size: 12px; color: #8ea2bd; margin-top: 3px; }
.tree-sec { font-size: 11px; letter-spacing: 1px; color: #7d90ab; padding: 12px 10px 6px; text-transform: uppercase; }

/* ---------- 移动端 ---------- */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; width: 84vw; max-width: 320px;
    z-index: 90; transform: translateX(-102%); transition: transform .22s ease;
  }
  body.nav-open #sidebar { transform: none; }
  .sidebar-mask {
    position: fixed; inset: 0; background: rgba(10, 18, 30, .45);
    border: 0; z-index: 80;
  }
  .only-mobile { display: inline-block; }
  #reader { padding: 26px 20px 100px; }
  #docTitle { font-size: 24px; }
  #editor { padding: 20px 18px 120px; }
  .editor-head { flex-wrap: wrap; }
  .editor-title { font-size: 21px; }
  .toolbar { position: sticky; top: 0; overflow-x: auto; flex-wrap: nowrap; }
}

/* ---------- 密码登录 ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 300;
  display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 18% 8%, rgba(199, 154, 74, .18), transparent 60%),
    radial-gradient(1000px 600px at 85% 90%, rgba(44, 81, 131, .35), transparent 60%),
    linear-gradient(160deg, #16283f 0%, #0d1723 100%);
}
.login-card {
  width: min(360px, 88vw);
  background: #fff; border-radius: 16px;
  padding: 34px 30px 26px; text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
  animation: pop .2s ease-out;
}
.login-mark {
  width: 46px; height: 46px; margin: 0 auto 16px; border-radius: 13px;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
  background: linear-gradient(135deg, var(--gold), #a87c33); color: #23180a;
}
.login-card h1 { margin: 0 0 6px; font-size: 21px; letter-spacing: .5px; }
.login-sub { margin: 0 0 20px; color: var(--ink-3); font-size: 13px; }
.login-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 9px; outline: none;
  font-size: 15px; letter-spacing: 1px;
}
.login-card input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31, 58, 95, .1); }
.login-btn { width: 100%; padding: 12px; font-size: 15px; }
.login-error {
  margin: 14px 0 0; color: var(--danger); font-size: 12.5px; line-height: 1.5;
}
.login-tip { margin: 18px 0 0; color: #a9b3c1; font-size: 11.5px; }

.logout-btn {
  margin-top: 8px; border: 0; background: transparent; padding: 0;
  color: #7d90ab; font-size: 11.5px; cursor: pointer; text-decoration: underline;
}
.logout-btn:hover { color: #c9d6e8; }
