:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --muted: #77736b;
  --line: #e4e1da;
  --accent: #b5532f;
  --accent-soft: #f6e6de;
  --ok: #2f7d4f;
  --ok-soft: #e1f1e6;
  --warn: #a8710c;
  --warn-soft: #fbf0d9;
  --err: #b42a2a;
  --err-soft: #f8e0e0;
  --nav: #1f1d1a;
  --radius: 10px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.shell { display: grid; grid-template-columns: 196px 1fr; min-height: 100vh; }
.nav { background: var(--nav); color: #d9d5cc; padding: 18px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.brand small { display: block; font-weight: 400; color: #9a958a; font-size: 12px; margin-top: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; user-select: none; }
.nav a span { width: 18px; text-align: center; color: #9a958a; }
.nav a:hover { background: #2d2a26; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a.active span { color: #fff; }
.nav-sep { height: 1px; background: #34312c; margin: 10px 6px; }
.nav-foot { margin-top: auto; font-size: 12px; color: #9a958a; padding: 10px; line-height: 1.6; }
.nav-lang { display: flex; gap: 4px; padding: 0 10px 4px; }
#whoami-line { color: #d9d5cc; }
.modal-box.narrow { max-width: 420px; }
/* 账号和模式：signed = 用账号登录的（不是本机直接打开）；member = 普通账号；server = 部署在服务器上
   普通账号只有管理员能做的操作不显示（服务端也会拒绝）；服务器上没有「打开文件夹」和局域网设置 */
body:not(.signed) .signed-only, body:not(.member) .member-only, body.member .admin-only, body.server .local-only { display: none !important; }
body.member #settings-form, body.member [data-act="del"], body.member [data-delbook], body.member [data-delglobal], body.member [data-rm],
body.member #k-save, body.member #k-del, body.member #k-new, body.member #lib-add, body.member #tpl-del, body.member #learn-start, body.member label.btn:has(input[type=file]):not(#book-list label), body.member #bulk-drop,
body.member [data-open], body.member [data-act="open"], body.server [data-open], body.server [data-act="open"] { display: none !important; }
/* 知识库和学习只给管理员看 */
body.member .nav a[data-page="knowledge"], body.member .nav a[data-page="learn"], body.member #page-knowledge, body.member #page-learn { display: none !important; }
.nav-lang button { padding: 2px 8px; font-size: 12px; background: transparent; border-color: #34312c; color: #9a958a; }
.nav-lang button.on { background: #2d2a26; color: #fff; border-color: #4a463f; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; margin-left: auto; }
.nav a.active .badge { background: #fff; color: var(--accent); }

main { padding: 26px 30px 60px; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
header h1 { margin: 0 0 4px; font-size: 22px; }
header p { margin: 0 0 18px; color: var(--muted); max-width: 900px; line-height: 1.6; }

.grid2 { display: grid; grid-template-columns: minmax(360px, 5fr) 6fr; gap: 18px; align-items: start; }
.grid-k { display: grid; grid-template-columns: 300px 1fr; gap: 18px; }
@media (max-width: 1100px) { .grid2, .grid-k { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; min-width: 0; }
.card.narrow { max-width: 720px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 small { font-weight: 400; font-size: 12px; }
.actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

form label, .card > label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 13px; }
label em { font-style: normal; color: var(--accent); font-weight: 400; font-size: 12px; }
input, select, textarea { width: 100%; margin-top: 5px; font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; min-width: 0; }
.check { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; }
.check input { width: auto; margin: 0; }
.check.inline { display: inline-flex !important; font-size: 12px; margin-left: 10px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

button, .btn { font: inherit; border-radius: 7px; padding: 8px 16px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
button:hover, .btn:hover { border-color: #c9c4b8; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.primary:disabled { opacity: .5; cursor: wait; }
.ghost { background: transparent; }
.sm { padding: 4px 10px; font-size: 12px; width: auto; margin: 0; }
select.sm { padding: 4px 6px; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; display: inline !important; font-weight: 400 !important; }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fcfbf9; min-width: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: var(--accent); }
.item.active { border-color: var(--accent); background: var(--accent-soft); }

.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #eee; color: #555; white-space: nowrap; }
.pill.running { background: var(--accent-soft); color: var(--accent); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.error, .pill.interrupted { background: var(--err-soft); color: var(--err); }
.pill.cancelled { background: #eee; color: #777; }
.pill.good { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--err-soft); color: var(--err); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.job { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin-bottom: 6px; background: #fcfbf9; }
.job:hover { border-color: var(--accent); }
.job .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .s { font-size: 12px; color: var(--muted); grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .bar, .progress { grid-column: 1 / -1; height: 4px; background: #eee; border-radius: 2px; overflow: hidden; }
.job .bar i, .progress i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: #fff; }
.chip.ok { border-color: #b7dcc4; background: var(--ok-soft); }
.chip.warn { border-color: #ecd59e; background: var(--warn-soft); }
.chip.err { border-color: #e7b3b3; background: var(--err-soft); }
.chips-select { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-weight: 400; }
.chips-select label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-weight: 400; margin: 0; }
.chips-select input { width: auto; margin: 0; }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid #f0eee9; vertical-align: middle; }
.tbl td input, .tbl td select { margin: 0; padding: 4px 6px; }
.tbl .files { font-size: 12px; color: var(--muted); }
.tbl .files .btn { padding: 2px 7px; font-size: 12px; }
.tbl .files div { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.k-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
#k-editor { height: calc(100vh - 250px); min-height: 420px; font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.k-off { opacity: .5; }

.modal { position: fixed; inset: 0; background: rgba(20, 18, 15, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; max-height: 92vh; display: flex; flex-direction: column; padding: 18px; }
.modal-box.wide { max-width: 1280px; height: 92vh; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.jm-meta { font-size: 12px; color: var(--muted); margin: 8px 0; }
.jm-body { display: grid; grid-template-columns: 1fr 2fr; gap: 14px; flex: 1; min-height: 0; }
.jm-body > div { display: flex; flex-direction: column; min-height: 0; }
.jm-body h3 { font-size: 13px; margin: 0 0 6px; }
pre { margin: 0; flex: 1; overflow: auto; background: #1f1d1a; color: #e9e5dc; padding: 12px; border-radius: 8px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; font-family: Consolas, "Courier New", monospace; }
#tm-text { flex: 1; font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.cm-body { overflow: auto; flex: 1; }
.qa { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
.qa div { background: #f7f6f2; border-radius: 8px; padding: 8px 10px; }
.qa b { display: block; font-size: 16px; }
.qa span { font-size: 11px; color: var(--muted); }
.msgs { margin: 0 0 12px; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.msgs.err li { color: var(--err); }
.msgs.warn li { color: var(--warn); }
.script { font-size: 12px; }
.script td { padding: 3px 6px; border-bottom: 1px solid #f0eee9; vertical-align: top; }
.script tr.prem td { background: #fff8e1; }
.script tr.sub td { background: #eef4fb; }
.script tr.btnrow td { font-weight: 700; }
.script td.c { max-width: 520px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 99; }
#toast.show { opacity: 1; }
#toast.err { background: var(--err); }
.editor-chips .ord:not(:empty) { display: inline-block; min-width: 16px; height: 16px; line-height: 16px; border-radius: 8px; background: var(--accent, #4a6cf7); color: #fff; font-size: 11px; text-align: center; }
