:root {
  --bg: #F5F4EF; --card: #FFFFFF; --ink: #1F2420; --sub: #6E746F; --line: #E4E2DA; --hover: #F0EEE6;
  --brand: #2F7D5B; --brand-soft: #E2F0E8; --danger: #C8433A; --code: #F3F1EA;
  --shadow: 0 1px 2px rgba(30,40,30,.05), 0 6px 20px rgba(30,40,30,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141815; --card: #1C211D; --ink: #E6EAE6; --sub: #929A94; --line: #2C332E; --hover: #242A25;
          --brand: #5CC596; --brand-soft: #1F3529; --code: #232925; --shadow: none; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--ink); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.primary { border: 0; background: var(--brand); color: #fff; border-radius: 10px; padding: 9px 18px; font-weight: 600; }
.ghost { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ghost:hover { background: var(--hover); }
.ghost svg { width: 17px; height: 17px; }
.danger { color: var(--danger); }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 56px; height: 56px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: -10px 0 4px; color: var(--sub); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--sub); }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--brand); }
.login-err { color: var(--danger); font-size: 13px; min-height: 1em; }

/* 顶栏 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, calc(50% - 484px)); padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand img { width: 32px; height: 32px; }
.search { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; max-width: 420px; margin-left: auto; }
.search svg { width: 16px; height: 16px; color: var(--sub); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; padding: 7px 0; font-size: 15px; }
.me { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; max-width: 30vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me.admin::after { content: " · 管理"; color: var(--brand); }
@media (max-width: 600px) { .brand span { display: none; } .me { max-width: 26vw; } }

main { max-width: 1000px; margin: 0 auto; padding: 16px 16px 90px; }

/* 文件夹视图 */
.bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.crumbs { flex: 1; min-width: 200px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 16px; font-weight: 600; }
.crumbs a { color: var(--sub); font-weight: 500; }
.crumbs a:hover { color: var(--brand); }
.crumbs i { color: var(--sub); font-style: normal; margin: 0 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.list { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--ink); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--hover); }
.ico { width: 36px; height: 36px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); overflow: hidden; }
.ico svg { width: 20px; height: 20px; }
.ico img { width: 100%; height: 100%; object-fit: cover; }
.ico.folder { background: #F6E9C8; color: #A87A12; }
.ico.doc { background: #DDEBF7; color: #2D6DA8; }
@media (prefers-color-scheme: dark) { .ico.folder { background: #3A3220; color: #E1B654; } .ico.doc { background: #1E2E3D; color: #7DB3E6; } }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta mark { background: none; color: var(--brand); }
.pin { color: var(--brand); font-size: 12px; margin-left: 6px; }
.more { border: 0; background: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; color: var(--sub); flex: none; }
.more:hover { background: var(--line); }
.more svg { width: 18px; height: 18px; }
.empty { text-align: center; color: var(--sub); padding: 48px 16px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.foot { text-align: center; color: var(--sub); font-size: 12px; margin-top: 14px; }

/* 菜单 */
.menu { position: fixed; z-index: 30; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.15); padding: 6px; min-width: 150px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: 8px; }
.menu button:hover { background: var(--hover); }

/* 文档 */
.article { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 28px clamp(16px, 5vw, 48px) 40px; }
.doc-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.doc-head h1 { flex: 1; min-width: 200px; margin: 0; font-size: 26px; line-height: 1.3; word-break: break-word; }
.doc-meta { color: var(--sub); font-size: 13px; margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { line-height: 1.35; margin: 1.4em 0 .5em; }
.md h1 { font-size: 1.6em; } .md h2 { font-size: 1.35em; padding-bottom: .2em; border-bottom: 1px solid var(--line); } .md h3 { font-size: 1.15em; }
.md > :first-child { margin-top: 0; }
.md img, .md video { max-width: 100%; border-radius: 8px; }
.md code { background: var(--code); padding: .1em .35em; border-radius: 5px; font-size: .9em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.md pre { background: var(--code); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 1em 0; padding: 2px 14px; border-left: 4px solid var(--brand); color: var(--sub); background: var(--hover); border-radius: 0 8px 8px 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; }
.md th { background: var(--hover); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.md a { text-decoration: underline; text-underline-offset: 2px; }
.md li > input[type=checkbox] { margin-right: 6px; }

/* 编辑器 */
.editor { display: flex; flex-direction: column; gap: 10px; }
.ed-title { font-size: 22px; font-weight: 700; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; outline: none; }
.ed-title:focus { border-color: var(--brand); }
.ed-tabs { display: none; gap: 6px; }
.ed-tabs button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 14px; }
.ed-tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.ed-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; height: calc(100vh - 230px); min-height: 360px; }
.ed-panes textarea { width: 100%; height: 100%; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--card);
  font: 14px/1.7 ui-monospace, Menlo, Consolas, "PingFang SC", monospace; outline: none; }
.ed-panes textarea:focus { border-color: var(--brand); }
.ed-panes .md { overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; }
.ed-tip { font-size: 12px; color: var(--sub); }
@media (max-width: 760px) {
  .ed-tabs { display: flex; }
  .ed-panes { grid-template-columns: 1fr; height: calc(100vh - 250px); }
  .ed-panes.show-edit .md, .ed-panes.show-view textarea { display: none; }
}

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(10,14,11,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--card); border-radius: 16px; width: min(420px, 100%); padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 90vh; }
.dialog h3 { margin: 0; font-size: 17px; }
.dialog input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 16px; background: var(--bg); outline: none; }
.dialog input:focus { border-color: var(--brand); }
.dialog .btns { display: flex; justify-content: flex-end; gap: 8px; }
.folders { overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 50vh; }
.folders button { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 8px 12px; }
.folders button:first-child { border-top: 0; }
.folders button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.folders button:disabled { color: var(--sub); opacity: .5; cursor: not-allowed; }
.versions { overflow-y: auto; max-height: 40vh; border: 1px solid var(--line); border-radius: 10px; }
.versions button { display: flex; justify-content: space-between; width: 100%; border: 0; border-top: 1px solid var(--line); background: none; padding: 8px 12px; }
.versions button:first-child { border-top: 0; }
.versions button.on { background: var(--brand-soft); }

/* 预览 */
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(8,10,9,.92); display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); color: #eee; }
.viewer-top .t { flex: 1; min-width: 0; }
.viewer-top .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-top .t span { font-size: 12px; color: #aaa; }
.viewer-top .ghost { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.15); color: #fff; }
.viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 12px 12px; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 8px; }
.viewer-body pre { width: 100%; height: 100%; overflow: auto; margin: 0; background: var(--card); color: var(--ink); border-radius: 8px; padding: 14px; font: 13px/1.6 ui-monospace, Menlo, monospace; white-space: pre-wrap; }
.viewer-body .nopreview { color: #ccc; text-align: center; }
.viewer-body .nopreview .primary { margin-top: 12px; display: inline-block; }

/* 上传进度 / 拖放 / 提示 */
.uploads { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20; display: flex; flex-direction: column; gap: 8px; width: min(320px, calc(100vw - 32px)); }
.up { background: var(--card); border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.15); padding: 10px 12px; font-size: 13px; }
.up .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up .b { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.up .b i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.up.fail { color: var(--danger); }
.drop-mask { position: fixed; inset: 0; z-index: 35; background: color-mix(in srgb, var(--brand) 18%, transparent); display: grid; place-items: center; pointer-events: none; }
.drop-mask div { background: var(--card); color: var(--brand); font-weight: 700; font-size: 18px; padding: 18px 28px; border-radius: 14px; border: 2px dashed var(--brand); }
.toast { position: fixed; left: 50%; top: 70px; transform: translate(-50%, -20px); z-index: 50; background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 600px) { .doc-head .actions { flex-wrap: nowrap; gap: 6px; } .doc-head .ghost { padding: 7px 10px; } }
