:root {
  --bg: #f4f6f9; --panel: #fff; --border: #e4e8ef; --border-soft: #eef1f6;
  --text: #1a2233; --muted: #5a6370; --faint: #697282;
  --primary: #2563eb; --primary-soft: #eaf1fe; --primary-dark: #1d4ed8;
  --success: #0f9d58; --success-soft: #e6f5ed;
  --warn: #b45309; --warn-soft: #fdf3e3;
  --danger: #dc2626; --danger-soft: #fdecec;
  --purple: #6d4aff; --purple-soft: #f0ecff;
  --teal: #0d9488; --teal-soft: #e3f5f3;
  --r: 10px; --r-sm: 6px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; 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.6;
}
a { color: var(--primary); text-decoration: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d9e2; border-radius: 4px; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.logo { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border-soft); }
.logo-mark {
  width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #2563eb, #6d4aff);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px;
}
.logo-text { font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.logo-sub { font-size: 11px; color: var(--faint); line-height: 1.2; }
.nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.sidebar-foot { padding: 10px 14px; border-top: 1px solid var(--border-soft); font-size: 11px; color: var(--faint); line-height: 1.4; }
.nav-group { font-size: 11px; color: var(--faint); padding: 12px 10px 6px; letter-spacing: .5px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--text); cursor: pointer; font-size: 13.5px; margin-bottom: 1px;
}
.nav-item:hover { background: var(--border-soft); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 500; }
.nav-item .ic { width: 16px; text-align: center; opacity: .75; font-size: 13px; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 9px; line-height: 17px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 16px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; }
.topbar .crumb { color: var(--faint); font-size: 12.5px; }
.spacer { flex: 1; }
.search {
  width: 260px; height: 34px; border: 1px solid var(--border); border-radius: 18px; padding: 0 14px;
  background: #fafbfc; font-size: 13px; outline: none;
}
.search:focus { border-color: var(--primary); background: #fff; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 12.5px; font-weight: 500;
}
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 18px; }
.user-chip:hover { background: var(--border-soft); }
.content { padding: 20px; flex: 1; }

/* ---------- 组件 ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: 10px; }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .lb { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .vl { font-size: 24px; font-weight: 600; margin-top: 4px; letter-spacing: -.5px; }
.stat .ex { font-size: 12px; color: var(--faint); }
.stat.accent { border-left: 3px solid var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafbfc; font-size: 12.5px; white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }
.tbl-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11.5px; line-height: 18px; white-space: nowrap; }
.b-blue { background: var(--primary-soft); color: var(--primary-dark); }
.b-green { background: var(--success-soft); color: var(--success); }
.b-amber { background: var(--warn-soft); color: var(--warn); }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-gray { background: #f0f2f5; color: var(--muted); }
.b-purple { background: var(--purple-soft); color: var(--purple); }
.b-teal { background: var(--teal-soft); color: var(--teal); }

.btn {
  height: 32px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text); display: inline-flex;
  align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: #c9d2de; background: #fafbfc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12.5px; }
.btn.danger { color: var(--danger); border-color: #f3c8c8; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { padding: 8px 14px; cursor: pointer; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.input, select, textarea {
  width: 100%; height: 34px; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0 10px; font-size: 13px; outline: none; font-family: inherit; background: #fff; color: var(--text);
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }

.modal-mask { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 12px; width: 640px; max-width: 92vw; max-height: 86vh; overflow: auto; box-shadow: 0 20px 50px rgba(16,24,40,.2); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 15px; }
.modal-b { padding: 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 8px; }

.empty { text-align: center; padding: 40px 20px; color: var(--faint); font-size: 13px; }
.list-item { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); display: flex; gap: 10px; align-items: flex-start; }
.list-item:last-child { border-bottom: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.flex { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.sm { font-size: 12.5px; }
.xs { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb8 { margin-bottom: 8px; } .mb16 { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }

/* 条形图 */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 6px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; transition: height .3s; }
.bar-lb { font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bar-vl { font-size: 11px; color: var(--muted); }

/* 进度条 */
.prog { height: 6px; background: #eef1f6; border-radius: 3px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }

/* 时间线 */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 1px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 14px; }
.tl-item::before { content: ''; position: absolute; left: -18px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--border); border: 2px solid #fff; }
.tl-item.done::before { background: var(--success); }
.tl-item.now::before { background: var(--primary); }
.tl-item.reject::before { background: var(--danger); }

/* 智能体对话 */
.chat-wrap { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 14px; height: calc(100vh - 156px); }
.agent-list { overflow-y: auto; }
.agent-card { padding: 12px; border-bottom: 1px solid var(--border-soft); cursor: pointer; }
.agent-card:hover { background: #fafbfc; }
.agent-card.active { background: var(--primary-soft); }
.chat-box { display: flex; flex-direction: column; }
.chat-body { flex: 1; overflow-y: auto; padding: 18px; background: #fafbfc; }
.msg { display: flex; gap: 10px; margin-bottom: 16px; }
.msg .av { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; }
.msg .bd { max-width: 78%; }
.bubble { background: #fff; border: 1px solid var(--border); padding: 10px 13px; border-radius: 10px; font-size: 13.5px; white-space: pre-wrap; }
.msg.me { flex-direction: row-reverse; }
.msg.me .bubble { background: var(--primary); color: #fff; border-color: var(--primary); }
.msg.me .bd { text-align: right; }
.steps { margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.step-h { padding: 7px 11px; font-size: 12.5px; background: #fafbfc; cursor: pointer; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border-soft); }
.step-b { padding: 10px 12px; font-size: 12px; background: #fff; overflow-x: auto; }
.chat-in { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; background: #fff; }
.chat-in textarea { flex: 1; height: 42px; }
.act-btn { margin-top: 8px; }

/* 事件链路 */
.evt { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; background: #fff; }
.evt-h { padding: 10px 12px; background: #fafbfc; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.evt-b { padding: 10px 12px; }
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.chain .node { padding: 3px 9px; border-radius: 14px; background: var(--primary-soft); color: var(--primary-dark); }
.chain .arrow { color: var(--faint); }
.chain .node.ok { background: var(--success-soft); color: var(--success); }
.chain .node.fail { background: var(--danger-soft); color: var(--danger); }

.toast { position: fixed; right: 20px; bottom: 20px; background: #1a2233; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border: 1px solid var(--border); border-radius: 14px; font-size: 12.5px; cursor: pointer; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

/* ---------- 登录视图（M5） ---------- */
.login-card { text-align: center; }
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 14px; font-size: 26px; font-weight: 600;
  background: linear-gradient(135deg, #2563eb, #6d4aff); color: #fff; display: flex; align-items: center; justify-content: center;
}
.login-card .field { text-align: left; margin-bottom: 12px; }
.login-card input { width: 100%; }

/* ---------- P5.5 体验打磨：全局加载指示 / 错误兜底 / 窄屏 ---------- */
body { position: relative; }
/* 顶部请求指示条：body[data-busy] 时出现 */
body::after {
  content: ''; position: fixed; top: 0; left: 0; height: 2px; width: 28%; z-index: 300;
  background: linear-gradient(90deg, transparent, var(--primary), #9f7bff, transparent);
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
body[data-busy]::after { opacity: 1; animation: busySlide 1.1s ease-in-out infinite; }
@keyframes busySlide {
  0% { left: 0; }
  60%, 100% { left: 100%; transform: translateX(-100%); }
}

/* 页面级错误兜底（render catch） */
.err-pane { padding: 60px 20px; }
.err-ic { font-size: 30px; line-height: 1; margin-bottom: 10px; }
.err-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.err-msg { font-size: 12.5px; color: var(--muted); max-width: 520px; margin: 0 auto; word-break: break-all; }
.err-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: center; }
.err-actions .btn { min-width: 96px; }

/* 窄屏：菜单列收窄、隐藏全局搜索、压缩留白 */
@media (max-width: 1024px) {
  .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { width: 176px; }
  .logo-sub { display: none; }
  .topbar .search { display: none; }
  .content { padding: 12px; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: column;
  }
  .app { flex-direction: column; }
  .nav { display: flex; flex-wrap: wrap; padding: 6px; gap: 2px; }
  .nav-group { display: none; }
  .nav-item { font-size: 12.5px; padding: 6px 8px; margin-bottom: 0; }
  .nav-badge { position: static; }
  .sidebar-foot { display: none; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .user-chip > div:last-child { display: none; } /* 极窄屏只保留头像 */
  .content { padding: 8px; }
  table { min-width: 640px; } /* 配合 .tbl-wrap 横向滚动，保持窄屏可读 */
  .stat .vl { font-size: 20px; }
}
