:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --line: #e2e8f1;
  --text: #1a2433;
  --muted: #6b7889;
  --primary: #1d4ed8;
  --primary-dark: #1740b4;
  --danger: #c23131;
  --green: #128a55;
  --shadow: 0 8px 30px rgba(24, 45, 85, .08);
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cfd8e6;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}
textarea { resize: vertical; line-height: 1.7; }
label { display: block; font-weight: 600; font-size: 12.5px; margin: 14px 0 5px; color: #3c4a5c; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
h2 { margin: 0 0 10px; font-size: 19px; }
h3 { margin: 0 0 8px; font-size: 15px; }
p { margin: 8px 0; }
a { color: var(--primary); }

.muted { color: var(--muted); font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border: 1px solid transparent; border-radius: 8px;
  background: #eef2f8; color: #33415a; font-weight: 600; font-size: 13px;
  cursor: pointer; white-space: nowrap; transition: background .15s, transform .05s;
}
.btn:hover { background: #e3eaf5; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: var(--line); color: #45536a; }
.btn.ghost:hover { background: #f0f4fa; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { background: #fff; border-color: #f0c9c9; color: var(--danger); }
.btn.wide { width: 100%; margin-top: 20px; padding: 11px; font-size: 14px; }
.btn.tiny { padding: 4px 9px; font-size: 11.5px; font-weight: 500; }

.alert { padding: 11px 14px; border-radius: 8px; font-size: 12.5px; margin: 12px 0; line-height: 1.6; }
.alert.danger { background: #fff1f1; border: 1px solid #f6cccc; color: #9b2626; }
.alert.info { background: #eef5ff; border: 1px solid #cfe0ff; color: #1c4ba8; }

.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 3px solid #d9e3f4; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 启动 / 未安装 ---------- */
.screen { min-height: 100vh; }
#boot { display: flex; align-items: center; justify-content: center; }
.boot-card { text-align: center; color: var(--muted); }
.setup-msg { max-width: 640px; margin: 80px auto; padding: 28px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); }
.noscript { padding: 14px; background: #fff1f1; color: #9b2626; text-align: center; font-weight: 600; }

/* ---------- 认证 ---------- */
#auth { display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; }
.auth-wrap { width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 30px 32px 26px; box-shadow: var(--shadow); }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { margin: 10px 0 2px; font-size: 25px; letter-spacing: .5px; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.logo {
  width: 48px; height: 48px; margin: 0 auto; border-radius: 13px;
  background: linear-gradient(140deg, #2563eb, #1e3a8a); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 23px; font-weight: 700; letter-spacing: -1px;
  box-shadow: 0 6px 16px rgba(29, 78, 216, .28);
}
.logo.small { width: 28px; height: 28px; border-radius: 8px; font-size: 15px; margin: 0; box-shadow: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.tab { flex: 1; padding: 9px 4px; border: 0; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.pane { padding-top: 4px; }
.strength { margin-top: 8px; font-size: 12px; color: var(--muted); }
.strength[data-level="4"], .strength[data-level="5"] { color: var(--green); font-weight: 600; }
.strength[data-level="0"], .strength[data-level="1"] { color: var(--danger); }
.auth-foot { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; text-align: center; }

/* ---------- 恢复码 ---------- */
#recovery, .modal { position: fixed; inset: 0; background: rgba(16, 28, 48, .5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
#recovery { position: fixed; background: var(--bg); z-index: 60; }
.modal-card { width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; background: #fff; border-radius: 14px; padding: 26px 28px; box-shadow: 0 20px 60px rgba(10, 25, 50, .22); }
.modal-card.narrow { max-width: 400px; }
.modal-card p { color: #4a5668; font-size: 13px; }
.recovery-code { display: block; margin: 16px 0; padding: 16px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 10px; color: #8a3410; font: 600 16px/1.9 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 1px; word-break: break-all; user-select: all; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 18px 0; }
.check input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- 主界面 ---------- */
.topbar { height: 58px; display: flex; align-items: center; gap: 18px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand-mini { display: flex; align-items: center; gap: 9px; font-size: 16px; }
.search-box { flex: 1; max-width: 420px; }
.search-box input { background: #f6f8fc; border-color: transparent; }
.search-box input:focus { background: #fff; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.workspace { display: grid; grid-template-columns: 210px 320px minmax(0, 1fr); height: calc(100vh - 58px); }
.sidebar, .list-pane, .editor { overflow-y: auto; }
.sidebar { padding: 18px 14px; background: #fafbfe; border-right: 1px solid var(--line); }
.side-label { margin: 24px 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .6px; color: #8a97a8; text-transform: uppercase; }
.category-list { display: flex; flex-direction: column; gap: 3px; }
.cat { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; color: #3d4b5e; text-align: left; cursor: pointer; font-size: 13px; }
.cat:hover { background: #eef2f8; }
.cat.active { background: #e5edff; color: var(--primary); font-weight: 600; }
.cat span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 22px; text-align: center; font-size: 11px; color: #7b8798; background: #e9eef6; border-radius: 10px; padding: 1px 6px; }
.cat.active .badge { background: #fff; color: var(--primary); }
.security-note { font-size: 11.5px; color: #55637a; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; }
.security-note p { margin: 4px 0; display: flex; align-items: center; gap: 7px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.green { background: var(--green); }
.dot.red { background: var(--danger); }
.security-note .tiny { display: block; margin-top: 8px; color: var(--muted); line-height: 1.6; }

.list-pane { background: #fff; border-right: 1px solid var(--line); }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 15px 16px 11px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--line); }
.item-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.item-card { width: 100%; text-align: left; padding: 12px 13px; border: 1px solid var(--line); border-radius: 9px; background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.item-card:hover { border-color: #b9cbf2; box-shadow: 0 3px 12px rgba(30, 60, 120, .07); }
.item-card.selected { border-color: var(--primary); background: #f7faff; }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-date { font-size: 11px; color: #94a0b0; flex: none; }
.item-meta { display: flex; gap: 6px; margin: 7px 0 0; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #e9effc; color: #2a55a8; }
.chip.soft { background: #f0f2f6; color: #6c7889; }
.item-preview { margin-top: 7px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.editor { padding: 18px 24px 40px; background: #fff; }
.editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fields-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 8px; font-weight: 600; font-size: 12.5px; color: #3c4a5c; }
.field-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; margin-bottom: 7px; }
.field-row input { padding: 7px 10px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f0f3f8; font-size: 12.5px; }
.file-row .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-actions { display: flex; align-items: center; gap: 10px; margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.audit-list { max-height: 320px; overflow: auto; }
.audit-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-bottom: 1px solid #f0f3f8; font-size: 12.5px; }

/* ---------- 浮层 ---------- */
.busy { position: fixed; inset: 0; background: rgba(244, 246, 250, .82); display: flex; align-items: center; justify-content: center; z-index: 90; }
.busy-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 22px 30px; box-shadow: var(--shadow); text-align: center; font-size: 13px; color: #42506a; }
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #1d2b45; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(10, 22, 44, .25); }
.toast.bad { background: #a12b2b; }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 190px minmax(0, 1fr); }
  .editor { grid-column: 2; border-top: 1px solid var(--line); }
  .sidebar { grid-row: 1 / span 2; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 8px; }
  .search-box { order: 3; max-width: none; width: 100%; flex: 1 0 100%; }
  .top-actions { gap: 5px; }
  .top-actions .muted { display: none; }
  .workspace { display: block; height: auto; }
  .sidebar, .list-pane, .editor { border: 0; border-bottom: 1px solid var(--line); }
  .category-list { flex-direction: row; flex-wrap: wrap; }
  .cat { width: auto; }
  .editor { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr 1fr auto; }
}
