:root {
  --bg: #0a0e17;
  --bg-2: #0f1626;
  --panel: #131b2e;
  --panel-2: #182238;
  --border: #22304d;
  --text: #e6ecff;
  --text-dim: #8b98b8;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --cyan: #22d3ee;
  --purple: #a78bfa;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- 认证 ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2a4d 0%, transparent 55%),
              radial-gradient(900px 500px at 90% 110%, #2a1a4d 0%, transparent 50%),
              var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.logo-orb {
  width: 52px; height: 52px; margin: 0 auto 12px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
  animation: spin 6s linear infinite;
  box-shadow: 0 0 30px rgba(91,140,255,0.5);
}
.logo-orb.small { width: 28px; height: 28px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-logo h1 { font-size: 26px; letter-spacing: 6px; }
.tagline { color: var(--text-dim); margin-top: 4px; font-size: 12px; }

.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; background: var(--bg-2); border-radius: 10px; padding: 4px; }
.auth-tab {
  flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.auth-tab.active { background: var(--accent); color: #fff; }

.auth-form .field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 14px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%; padding: 12px; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--text); font-size: 13px;
}
.btn-ghost:hover { background: var(--panel-2); }

.auth-error { color: var(--red); font-size: 12px; min-height: 18px; margin-bottom: 10px; }
.auth-hint { color: var(--text-dim); font-size: 11px; margin-top: 16px; text-align: center; line-height: 1.6; }

/* ---------- 主应用三栏布局 NAV | WORKSPACE | INTELLIGENCE ---------- */
.app-screen { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 220px; flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; letter-spacing: 2px; }
.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-section-label {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;
  padding: 14px 12px 6px; opacity: 0.7;
}
.nav-item {
  text-align: left; padding: 11px 12px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 10px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 10px;
}
.nav-item .icon { width: 18px; text-align: center; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 13px;
}
.user-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* 右栏智能面板 */
.intelligence {
  width: 300px; flex-shrink: 0; background: var(--bg-2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 12px; overflow-y: auto;
}
.intel-title { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: var(--text-dim); padding: 0 4px; }
.intel-events { display: flex; flex-direction: column; gap: 6px; }

/* ---------- 命令面（常驻顶部） ---------- */
.command-surface {
  display: flex; align-items: center; gap: 10px; padding: 10px 24px;
  border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.cmd-icon { font-size: 18px; color: var(--accent); flex-shrink: 0; }
.command-surface input {
  flex: 1; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}
.command-surface input:focus { border-color: var(--accent); }
.command-surface .btn-primary { width: auto; padding: 11px 22px; }

.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 20px 24px; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.view-head h2 { font-size: 20px; }
.view-head .btn-primary { width: auto; margin-left: auto; padding: 9px 18px; }
.view-sub { color: var(--text-dim); font-size: 12px; }

/* ---------- 面板 / 统计 / 徽标 ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.panel-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.panel-title .view-sub { font-weight: 400; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center;
}
.stat .val { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .lbl { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap;
}
.badge.type { color: var(--cyan); border-color: var(--cyan); }
/* 状态机徽标（完整状态集） */
.badge.status-CREATED { color: #94a3b8; border-color: #94a3b8; }
.badge.status-PLANNING { color: var(--accent); border-color: var(--accent); }
.badge.status-WAITING_APPROVAL { color: var(--amber); border-color: var(--amber); }
.badge.status-RUNNING { color: var(--cyan); border-color: var(--cyan); }
.badge.status-VERIFYING { color: var(--purple); border-color: var(--purple); }
.badge.status-COMPLETED { color: var(--green); border-color: var(--green); }
.badge.status-PAUSED { color: var(--text-dim); border-color: var(--text-dim); }
.badge.status-BLOCKED { color: var(--red); border-color: var(--red); }
.badge.status-CANCELLED { color: #64748b; border-color: #64748b; }
.badge.status-FAILED { color: var(--red); border-color: var(--red); }
/* 兼容旧命名 */
.badge.status-pending { color: var(--amber); border-color: var(--amber); }
.badge.status-running { color: var(--accent); border-color: var(--accent); }
.badge.status-completed { color: var(--green); border-color: var(--green); }
.badge.status-failed { color: var(--red); border-color: var(--red); }

.pill-warn { color: var(--amber); border: 1px solid var(--amber); font-size: 10px; padding: 1px 6px; border-radius: 20px; }
.perm-chip { font-size: 10px; color: var(--purple); border: 1px solid var(--purple); padding: 1px 6px; border-radius: 20px; }
.tag { font-size: 11px; color: var(--accent); background: rgba(91,140,255,0.12); padding: 2px 7px; border-radius: 20px; }
.empty { color: var(--text-dim); text-align: center; padding: 24px 0; font-size: 13px; }
.progress { height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; }

/* ---------- 首页：认知内核循环 ---------- */
.kernel-loop {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
}
.loop-node {
  padding: 8px 14px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text);
}
.loop-node:nth-child(4n+1) { border-color: var(--accent); }
.loop-arrow { color: var(--text-dim); font-size: 14px; }

/* ---------- 记忆：七层架构 + 评分面板 ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input, .toolbar select {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 13px; outline: none;
}
.toolbar input { flex: 1; }
.toolbar select { width: 140px; }

.mem-layers { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.mem-layer-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
.mem-layer-num {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.mem-layer-info { width: 180px; flex-shrink: 0; }
.mem-layer-name { font-size: 13px; font-weight: 600; }
.mem-layer-q { font-size: 11px; color: var(--text-dim); }
.mem-layer-bar { flex: 1; height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.mem-layer-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.mem-layer-count { font-size: 12px; color: var(--text-dim); width: 30px; text-align: right; flex-shrink: 0; }

.mem-score-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 16px;
}
.mem-score-formula { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; font-family: monospace; }
.mem-score-empty { font-size: 13px; color: var(--text-dim); text-align: center; padding: 8px 0; }
.mem-score-item { padding: 10px 0; border-top: 1px solid var(--border); }
.mem-score-item:first-of-type { border-top: none; }
.mem-score-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.mem-score-title { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mem-score-total { font-size: 16px; font-weight: 700; color: var(--accent); }
.mem-score-bar { height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.mem-score-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); border-radius: 3px; }
.mem-score-breakdown { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); padding: 2px 8px; border-radius: 20px; }

/* ---------- 卡片列表（记忆/任务/目标/证据/事件） ---------- */
.card-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.card-content { color: var(--text); line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.card-content a { color: var(--accent); }
.card-content ul, .card-content ol { padding-left: 20px; margin: 6px 0; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions button { padding: 5px 12px; font-size: 12px; }
.card-actions .btn-primary { width: auto; }
.mem-meta { font-size: 11px; color: var(--text-dim); margin-top: 6px; }
.stars { color: var(--amber); font-size: 12px; }
.score { color: var(--accent); font-weight: 700; }

/* ---------- 知识图谱：三层 + 18 种关系 ---------- */
.graph-toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.graph-toolbar textarea {
  flex: 1; resize: vertical; min-height: 52px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font-size: 13px; outline: none; font-family: inherit;
}
.graph-toolbar .btn-primary { width: auto; padding: 0 20px; }

.layer-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.layer-tab {
  padding: 7px 16px; border-radius: 20px; border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); cursor: pointer; font-size: 13px;
}
.layer-tab:hover { color: var(--text); }
.layer-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.graph-layout { display: flex; gap: 14px; flex: 1; min-height: 0; }
#graph-canvas { flex: 1; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); height: 100%; }
.graph-side { width: 280px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.entity-list, .relation-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.entity-item, .relation-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; padding: 7px 9px; background: var(--bg-2); border-radius: 8px;
}
.entity-item .dot, .relation-item .dot, .legend-item .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.entity-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-item .etype, .rtype { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }
.rtype { color: var(--accent); }
.delete-x { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; }
.delete-x:hover { color: var(--red); }

.relation-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend-item {
  display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text);
  background: var(--bg-2); padding: 4px 8px; border-radius: 6px;
}
.legend-item em { color: var(--text-dim); font-style: normal; }

.graph-add { display: flex; gap: 10px; margin-top: 12px; }
.graph-add input { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font-size: 13px; outline: none; }
.graph-add select { padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font-size: 13px; outline: none; }

#world-canvas { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; }

/* ---------- Agent OS ---------- */
.agentos-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }

.fabric-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
.fabric-item:last-child { border-bottom: none; }
.fabric-icon {
  width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #fff; flex-shrink: 0;
}
.fabric-info { flex: 1; }
.fabric-name { font-size: 13px; font-weight: 600; }
.fabric-status { font-size: 11px; color: var(--text-dim); }
.fabric-status.status-running { color: var(--cyan); }
.fabric-status.status-waiting { color: var(--amber); }
.fabric-status.status-completed { color: var(--green); }
.fabric-status.status-failed { color: var(--red); }

.stage-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.stage-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.stage-dot.active { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.stage-name { font-size: 12px; flex: 1; }
.stage-count { font-size: 11px; color: var(--text-dim); }
.state-hint { font-size: 11px; color: var(--text-dim); margin-top: 8px; font-family: monospace; }

.perm-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.perm-item:last-child { border-bottom: none; }
.perm-level {
  width: 34px; height: 24px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.perm-info { flex: 1; font-size: 12px; }
.perm-approval { font-size: 11px; color: var(--text-dim); }

.verify-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12px; }
.verify-icon {
  width: 22px; height: 22px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0; background: var(--panel-2);
}
.verify-icon.state-pass { background: rgba(52,211,153,0.15); color: var(--green); }
.verify-icon.state-fail { background: rgba(248,113,113,0.15); color: var(--red); }
.verify-icon.state-idle { color: var(--text-dim); }
.verify-info { flex: 1; }

.approval-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12px;
}
.approval-item:last-child { border-bottom: none; }
.approval-actions { display: flex; gap: 6px; }
.approval-actions button { padding: 4px 10px; font-size: 12px; }

/* ---------- 我 / 决策 ---------- */
.decision-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.decision-item:last-child { border-bottom: none; }
.decision-item .time { color: var(--text-dim); font-size: 11px; margin-left: 8px; }

/* ---------- 事件总线 ---------- */
.event-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; font-size: 12px;
}
.event-type { color: var(--accent); font-family: monospace; flex-shrink: 0; }
.event-payload { flex: 1; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: monospace; }
.event-time { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }

/* ---------- 命令面结果 ---------- */
.cmd-intent { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cmd-intent strong { color: var(--accent); }
.cmd-query { margin-bottom: 8px; font-size: 13px; }
.command-help { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.command-help code { background: var(--bg-2); padding: 2px 6px; border-radius: 4px; color: var(--cyan); font-family: monospace; }

/* ---------- 设置 ---------- */
.settings-card { max-width: 520px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.settings-status { color: var(--green); font-size: 12px; min-height: 18px; margin-bottom: 10px; }
.settings-status.error { color: var(--red); }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-body .field { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions button { width: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 20px; border-radius: 10px; font-size: 13px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--red); color: var(--red); }

/* 响应式 */
@media (max-width: 1100px) {
  .intelligence { display: none; }
  .agentos-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { width: 64px; padding: 14px 6px; }
  .sidebar-logo span, .nav-item span, .nav-section-label { display: none; }
  .nav-item { justify-content: center; }
  .user-name { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .graph-layout { flex-direction: column; }
  #graph-canvas { height: 320px; }
  .graph-side { width: 100%; flex-direction: row; }
  .graph-side .panel { flex: 1; }
  .mem-layer-info { width: 120px; }
}
