:root {
  --bg: #0f1420;
  --bg-soft: #161d2e;
  --card: #1a2233;
  --card-border: #263149;
  --text: #e6ecf7;
  --text-dim: #8a96b3;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --green: #34c98e;
  --orange: #ff9f43;
  --purple: #a78bfa;
  --red: #f26d6d;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

/* ---------- 布局：左侧分组导航 ---------- */
.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}
.sidebar {
  width: 172px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side-brand { font-size: 16px; padding: 4px 8px 16px; white-space: nowrap; }
.side-brand span { color: var(--text-dim); font-size: 12px; margin-left: 4px; }
.side-nav { display: flex; flex-direction: column; gap: 6px; }
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.15s;
  text-align: left;
}
.side-item:hover { color: var(--text); background: var(--bg-soft); }
.side-item.active { color: var(--text); background: var(--accent-soft); border-color: var(--accent); }
.side-item .badge {
  margin-left: auto;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 8px;
  color: var(--text-dim);
}
.side-item.active .badge { color: var(--accent); border-color: var(--accent); }
.side-foot { margin-top: 18px; color: var(--text-dim); font-size: 11px; line-height: 1.8; padding: 0 8px; }
.content { flex: 1; min-width: 0; }

@media (max-width: 760px) {
  .layout { flex-direction: column; gap: 12px; }
  .sidebar { position: static; width: 100%; flex-direction: row; align-items: center; gap: 8px; }
  .side-brand { padding: 0 4px 0 0; }
  .side-nav { flex-direction: row; flex: 1; }
  .side-item { width: auto; flex: 1; justify-content: center; }
  .side-foot { display: none; }
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.brand h1 { font-size: 22px; }
.brand .sub { color: var(--text-dim); font-size: 13px; margin-left: 8px; }
.top-actions { display: flex; gap: 10px; }

.btn {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 统计卡 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .num { font-size: 26px; font-weight: 700; }
.stat .label { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.stat.warn .num { color: var(--orange); }
.stat.ok .num { color: var(--green); }
.stat.run .num { color: var(--accent); }

/* ---------- 新建任务面板 ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.panel h2 { font-size: 14px; color: var(--text-dim); margin-bottom: 12px; font-weight: 500; }
.panel.hidden { display: none; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.form-row.end { justify-content: flex-end; margin-bottom: 0; }
input[type="text"], input[type="number"], textarea, select {
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--accent); }
#nt-title { flex: 1; min-width: 260px; }
textarea { width: 100%; resize: vertical; margin-bottom: 10px; }

/* ---------- 过滤器 ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filter {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.filter.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.filter .n { opacity: 0.8; margin-left: 3px; }

/* ---------- 任务卡 ---------- */
.task {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--text-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.task[data-status="pending"] { border-left-color: #64748b; }
.task[data-status="assigned"] { border-left-color: var(--purple); }
.task[data-status="running"] { border-left-color: var(--accent); }
.task[data-status="waiting_feedback"] { border-left-color: var(--orange); box-shadow: 0 0 18px rgba(255, 159, 67, 0.12); }
.task[data-status="done"] { border-left-color: var(--green); }
.task[data-status="cancelled"] { border-left-color: #3a4358; opacity: 0.6; }

.task-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.task-title { font-size: 15px; font-weight: 600; }
.task[data-status="done"] .task-title,
.task[data-status="cancelled"] .task-title { text-decoration: line-through; }
.task-id { color: var(--text-dim); font-size: 12px; }

.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip.status-pending { color: #94a3b8; }
.chip.status-assigned { color: var(--purple); border-color: var(--purple); }
.chip.status-running { color: var(--accent); border-color: var(--accent); }
.chip.status-waiting_feedback { color: var(--orange); border-color: var(--orange); }
.chip.status-done { color: var(--green); border-color: var(--green); }
.chip.status-cancelled { color: #64748b; }
.chip.prio-high { color: var(--red); border-color: var(--red); }
.chip.cat { color: #7dd3fc; }

.task-desc { color: var(--text-dim); font-size: 13px; margin: 8px 0 0; }

.progress-wrap { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.progress {
  flex: 1;
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 999px;
  transition: width 0.6s ease;
}
.progress-pct { font-size: 12px; color: var(--text-dim); min-width: 36px; text-align: right; }

.assignee { font-size: 12px; color: var(--purple); margin-top: 8px; }

.feedback-box {
  margin-top: 10px;
  background: rgba(255, 159, 67, 0.1);
  border: 1px dashed var(--orange);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: #ffd9a8;
}

.result-box {
  margin-top: 10px;
  background: rgba(52, 201, 142, 0.07);
  border: 1px solid rgba(52, 201, 142, 0.35);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
  color: #c4ecdb;
}

.logs { margin-top: 10px; border-top: 1px dashed var(--card-border); padding-top: 8px; }
.log-line { font-size: 12px; color: var(--text-dim); line-height: 1.7; }
.log-line .who { color: #7dd3fc; }

.task-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.task-actions select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}
.fb-input-row { display: flex; gap: 8px; width: 100%; margin-top: 8px; }
.fb-input-row input { flex: 1; }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 0;
  font-size: 14px;
}

.foot {
  margin-top: 30px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}

/* ---------- 视图切换（任务看板 / AI 集群） ---------- */
.view.hidden { display: none; }
.side-sep {
  font-size: 11px;
  color: var(--text-dim);
  padding: 12px 8px 2px;
  letter-spacing: 1px;
}
.side-nav .side-sep:first-child { padding-top: 0; }

/* ---------- AI 集群 ---------- */
#agent-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }

.agent-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.agent-card.off { border-top-color: #3a4358; opacity: 0.65; }

.agent-head { display: flex; align-items: center; gap: 10px; }
.agent-avatar { font-size: 26px; line-height: 1; }
.agent-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-title b { font-size: 15px; }
.agent-model { font-size: 12px; color: var(--text-dim); }
.agent-head-actions { display: flex; gap: 6px; flex-shrink: 0; }

.agent-desc { color: var(--text-dim); font-size: 12px; }

.agent-meta { display: flex; gap: 6px; flex-wrap: wrap; }

.agent-load { display: flex; align-items: center; gap: 10px; }
.agent-load-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.agent-load .progress { flex: 1; height: 6px; }

.agent-tasks {
  border-top: 1px dashed var(--card-border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 30px;
}
.agent-task { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.agent-task-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.agent-task-pct { color: var(--text-dim); }
.agent-task.none { color: var(--text-dim); }

#ag-prompt { margin-bottom: 0; }

/* ---------- 轻提示 toast（替代 alert，不阻塞轮询） ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%) translateY(16px);
  background: var(--red);
  color: #fff;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  white-space: nowrap;
  z-index: 99;
}
.toast.ok { background: var(--green); color: #06281c; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 总览视图 ---------- */
.ov-section { margin-bottom: 22px; }
.ov-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.ov-empty-inline { color: var(--text-dim); font-weight: 400; font-size: 12px; }
.ov-section .task { margin-bottom: 10px; }

.ov-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 6px;
  font-size: 13px;
}
.ov-row-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ov-row-group { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.ov-row-ai { color: var(--purple); font-size: 12px; white-space: nowrap; }
.ov-row-time { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.ov-row-bar { display: flex; align-items: center; gap: 8px; width: 180px; flex-shrink: 0; }
.ov-row-bar .progress { flex: 1; height: 5px; }

.ov-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 13px;
}
.ov-agent.off { opacity: 0.55; }
.ov-agent-avatar { font-size: 18px; }
.ov-agent-name { min-width: 90px; }
.ov-agent .ov-row-bar { flex: 1; width: auto; }
.ov-agent-load { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.ov-more { margin-top: 4px; }

/* ---------- 四象限矩阵视图 ---------- */
.matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mx-cell {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 180px;
}
.mx-cell.mx-q1 { border-top: 3px solid var(--red); }
.mx-cell.mx-q2 { border-top: 3px solid var(--accent); }
.mx-cell.mx-q3 { border-top: 3px solid var(--orange); }
.mx-cell.mx-q4 { border-top: 3px solid #3a4358; }
.mx-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.mx-head b { font-size: 14px; }
.mx-hint { font-size: 11px; color: var(--text-dim); }
.mx-count {
  margin-left: auto;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 11px;
  padding: 0 8px;
  color: var(--text-dim);
}
.mx-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 6px;
  font-size: 12px;
}
.mx-row-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-row .ov-row-ai { font-size: 11px; white-space: nowrap; }
.mx-move { font-size: 11px; padding: 2px 6px; border-radius: 6px; flex-shrink: 0; }
.mx-empty { color: var(--text-dim); font-size: 12px; padding: 8px 2px; }
.chip.mx-q { color: #c4b5fd; border-color: #4c3f78; }

@media (max-width: 760px) {
  .matrix-grid { grid-template-columns: 1fr; }
}

/* ---------- 手机端工作台适配（飞书通知点进来的场景） ---------- */
@media (max-width: 600px) {
  body { padding: 12px 10px 40px; }
  .layout { gap: 10px; }
  .topbar { margin-bottom: 12px; }
  .brand h1 { font-size: 18px; }
  .brand .sub { display: none; }
  .btn { padding: 7px 10px; font-size: 13px; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .num { font-size: 20px; }
  .task { padding: 12px; }
  .task-title { font-size: 14px; }
  .task-actions { gap: 6px; }
  .btn.small { padding: 5px 9px; font-size: 12px; }
  .progress-pct { min-width: 30px; }
  .ov-row { flex-wrap: wrap; }
  .ov-row-bar { width: 130px; }
  .ov-agent .ov-row-bar { width: auto; }
}
