:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e3e8f0;
  --text: #1b2430;
  --muted: #6b7789;
  --brand: #2456d6;
  --brand-soft: #eaf0ff;
  --ok: #0f8a5f;
  --ok-soft: #e6f6ef;
  --warn: #b8730a;
  --warn-soft: #fff4e0;
  --danger: #c23838;
  --danger-soft: #fdeaea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 35, 60, .06), 0 6px 20px rgba(20, 35, 60, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex: 0 0 236px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 20px 18px 18px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 38px;
  background: var(--brand); color: #fff; font-size: 19px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-group { color: var(--muted); font-size: 11px; letter-spacing: .08em; padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 11px; margin: 2px 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer;
  font-size: 13.5px; text-align: left;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item .num { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--panel-2); padding: 1px 7px; border-radius: 10px; }
.nav-item.active .num { background: #fff; color: var(--brand); }
.sidebar-foot { display: flex; gap: 9px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 8px; }
.foot-title { font-size: 12px; font-weight: 600; }
.foot-sub { font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 26px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 19px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.project-pick { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
select, input, textarea {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px;
  background: #fff; color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; max-width: 100%;
}
select:focus, input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 13px; font-family: inherit;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { opacity: .9; color: #fff; }
.btn.ghost { background: var(--panel-2); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #f0c9c9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.alertbar { margin: 16px 26px 0; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alertbar.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f2dcae; }
.alertbar.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3cccc; }
.alertbar.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe8d5; }
.hidden { display: none !important; }

.view { padding: 22px 26px 30px; flex: 1; }
.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 25px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.metric .sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.metric.ok .value { color: var(--ok); }
.metric.warn .value { color: var(--warn); }
.metric.danger .value { color: var(--danger); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; background: #fff; }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafbfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tag.gray { background: #eef1f6; color: #5c6878; }
.tag.blue { background: var(--brand-soft); color: var(--brand); }
.tag.green { background: var(--ok-soft); color: var(--ok); }
.tag.orange { background: var(--warn-soft); color: var(--warn); }
.tag.red { background: var(--danger-soft); color: var(--danger); }

.form-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11.5px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { min-height: 58px; resize: vertical; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.check-item { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; font-size: 13px; }
.check-item.on { background: var(--ok-soft); border-color: #bfe8d5; color: var(--ok); font-weight: 600; }
.check-item input { width: 16px; height: 16px; accent-color: var(--ok); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.list-item .idx { flex: 0 0 26px; height: 26px; border-radius: 7px; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; font-size: 13px; }
.list-item .d { color: var(--muted); font-size: 12px; margin-top: 2px; }

.notice { padding: 11px 14px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.notice strong { color: var(--text); }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; color: #38455a; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
pre { background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-size: 12px; line-height: 1.6; margin: 0; }

.footer { padding: 14px 26px 20px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); }
.modal { position: fixed; inset: 0; background: rgba(18, 28, 45, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px 22px; width: min(720px, 100%); max-height: 86vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-box h3 { margin: 0 0 6px; font-size: 16px; }
.modal-box .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; right: 22px; bottom: 22px; background: #1b2430; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px; z-index: 80; box-shadow: 0 8px 28px rgba(0,0,0,.22); }

@media (max-width: 1000px) {
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.k3, .grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { display: flex; flex-wrap: wrap; padding: 8px; }
  .nav-group, .sidebar-foot { display: none; }
  .nav-item { width: auto; }
  .topbar { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
  .view { padding: 16px; }
  .grid.k4, .grid.k3, .grid.k2 { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
}

/* ---------- 云端共享状态与登录 ---------- */
.cloud-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe8d5;
  white-space: nowrap;
}
.cloud-status.warn { background: var(--warn-soft); color: var(--warn); border-color: #f2dcae; }
.cloud-status.bad { background: var(--danger-soft); color: var(--danger); border-color: #f3cccc; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }

.auth-box { width: min(420px, 100%); }
.auth-box .field { margin: 12px 0 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.auth-box .field input { padding: 9px 11px; font-size: 13px; font-weight: 400; color: var(--text); }
.auth-box .btn { width: 100%; margin-top: 6px; }
.auth-box #authStep2 { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.form-err { min-height: 18px; margin: 10px 0 0; font-size: 12px; color: var(--danger); }
@media (max-width: 720px) {
  .cloud-status { order: -1; }
}

/* ---------- 本地知识库 v0 ---------- */
.notice.danger { background: var(--danger-soft); border-color: #f3cccc; color: var(--danger); }
.notice.danger strong { color: var(--danger); }
.kb-gate {
  margin-top: 12px; padding: 10px 13px; border-radius: 8px; font-size: 12.5px;
  background: var(--ok-soft); border: 1px solid #bfe8d5; color: var(--ok);
}
.kb-gate.bad { background: var(--danger-soft); border-color: #f3cccc; color: var(--danger); }
.kb-gate strong { color: inherit; }
.kb-highlight { background: #fff8dc !important; outline: 2px solid var(--warn); }
.kb-highlight td { background: transparent !important; }

/* ---------- 只读 DAG ---------- */
.dag-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 6px; }
.dag-svg { display: block; width: 100%; min-width: 660px; height: auto; }
.dag-edge { fill: none; stroke: #9aa7b8; stroke-width: 1.6; }
.dag-node { cursor: pointer; }
.dag-node rect { stroke-width: 1.5; transition: opacity .15s; }
.dag-node:hover rect { opacity: .78; stroke-width: 2.4; }
.dag-node.idle rect   { fill: #ffffff; stroke: #c8d2e0; }
.dag-node.busy rect   { fill: #fff4e0; stroke: #e2b260; }
.dag-node.ok rect     { fill: #e6f6ef; stroke: #6cc39d; }
.dag-node.rejected rect { fill: #fdeaea; stroke: #dc8c8c; }
.dag-t1 { font-size: 11.5px; font-weight: 700; fill: #1b2430; }
.dag-t2 { font-size: 11px; fill: #44506a; }
.dag-t3 { font-size: 10px; fill: #6b7789; }
.dag-node.rejected .dag-t1, .dag-node.rejected .dag-t3 { fill: var(--danger); }
.dag-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.dag-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dag-legend .sw { display: inline-block; width: 13px; height: 13px; border-radius: 3px; border: 1.5px solid; }
.dag-legend .sw.idle { background: #fff; border-color: #c8d2e0; }
.dag-legend .sw.busy { background: #fff4e0; border-color: #e2b260; }
.dag-legend .sw.ok { background: #e6f6ef; border-color: #6cc39d; }
.dag-legend .sw.rejected { background: #fdeaea; border-color: #dc8c8c; }
