/* AgentTrace — 观测台样式。暖纸底色 + 墨色文字，与 ActPilot 朱墨风格一致。 */

:root {
  --paper: #faf9f5;
  --paper-raised: #ffffff;
  --ink: #1f1e1b;
  --ink-soft: #5a574f;
  --ink-faint: #918d84;
  --rule: #e3e0d8;
  --rule-strong: #cfcbc0;
  --accent: #c04a2b;
  --accent-soft: #f4e3dd;
  --ok: #3f7d4e;
  --ok-soft: #e2efe6;
  --bad: #b3382a;
  --bad-soft: #f7e3e0;
  --warn: #9a6b12;
  --warn-soft: #f8eed6;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.muted { color: var(--ink-faint); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sep { color: var(--ink-faint); margin: 0 4px; }

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 17px;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--ink-soft);
  font-size: 14px;
}
.nav a:hover { background: var(--paper); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { margin: 0; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }

.page-title { margin: 0 0 6px; font-size: 22px; font-weight: 650; }
.section-title { margin: 30px 0 6px; font-size: 16px; font-weight: 620; }

/* ---------- 指标卡 ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 18px 0 8px;
}
.card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-label { font-size: 12px; color: var(--ink-faint); margin-bottom: 6px; }
.card-value { font-size: 26px; font-weight: 680; line-height: 1.2; }
.card-value small { font-size: 13px; font-weight: 500; color: var(--ink-faint); margin-left: 3px; }
.small-value { font-size: 15px; font-weight: 600; line-height: 1.45; }
.normal { font-weight: 400; }
.card-sub { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }

/* ---------- 表格 ---------- */

.table-wrap {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.table th {
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-faint);
  background: #f6f4ef;
  position: sticky;
  top: 0;
}
.table th.num { text-align: right; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fbfaf7; }
.empty { text-align: center; color: var(--ink-faint); padding: 26px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 占比条 ---------- */

.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar {
  flex: 1;
  min-width: 60px;
  height: 7px;
  background: #eeebe4;
  border-radius: 4px;
  overflow: hidden;
}
.bar span { display: block; height: 100%; background: var(--accent); opacity: 0.75; }
.bar-label { font-size: 12px; color: var(--ink-faint); min-width: 38px; text-align: right; }

/* ---------- 标签 ---------- */

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  background: #eeebe4;
  color: var(--ink-soft);
  font-size: 11.5px;
  white-space: nowrap;
}
.tag-phase { background: #e6e2d8; }
.tag-tool { background: #dfe8f0; color: #2f5570; }
.tag-wait { background: var(--warn-soft); color: var(--warn); }
.tag-metric { background: var(--ok-soft); color: var(--ok); }
.tag-block { background: #eae6f0; color: #5a4a70; }
.tag-error { background: var(--bad-soft); color: var(--bad); }

.kv {
  display: inline-block;
  margin-right: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* ---------- 瀑布图 ---------- */

.waterfall {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 12px;
}
.wf-row {
  display: grid;
  grid-template-columns: 190px 1fr 130px;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}
.wf-label {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wf-track {
  position: relative;
  height: 20px;
  background:
    repeating-linear-gradient(90deg, transparent 0 24.9%, #e8e4dc 24.9% 25%);
  border-radius: 4px;
}
.wf-bar {
  position: absolute;
  top: 3px;
  height: 14px;
  border-radius: 3px;
  background: #9a958a;
  min-width: 2px;
}
.wf-bar.kind-phase { background: #8a857a; }
.wf-bar.kind-tool { background: #5a87ad; }
.wf-bar.kind-wait { background: #d59a2c; }
.wf-bar.kind-metric { background: #5a9c6b; }
.wf-bar.kind-block { background: #8b7aa8; }
.wf-bar.kind-error { background: var(--bad); }
.wf-bar.hot { background: var(--accent); }
.wf-value {
  font-size: 12.5px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 760px) {
  .wf-row { grid-template-columns: 120px 1fr 100px; }
}

/* ---------- 事件流 ---------- */

.events {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 6px 14px;
  margin-top: 12px;
  max-height: 520px;
  overflow: auto;
}
.event { border-bottom: 1px solid var(--rule); }
.event:last-child { border-bottom: none; }
.event summary {
  cursor: pointer;
  padding: 6px 0;
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.event summary:hover { color: var(--accent); }
.event pre {
  background: #f6f4ef;
  border-radius: 6px;
  padding: 10px 12px;
  overflow: auto;
  font-size: 11.5px;
  line-height: 1.5;
  margin: 0 0 10px;
  max-height: 340px;
}

/* ---------- 表单 / 按钮 ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
  align-items: center;
}
.filters input, .filters select {
  padding: 7px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 13.5px;
  font-family: inherit;
}
.filters input[type="text"] { min-width: 240px; }
.filters input[type="number"] { width: 130px; }

.btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { background: #f1eee7; text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #a93f24; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 6px; }

.q { max-width: 340px; }
.back { margin-top: 26px; }

/* ---------- 智能体列表 ---------- */

.instance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.instance-card {
  display: block;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--ink);
}
.instance-card:hover { text-decoration: none; background: #fbfaf7; }
.instance-name { font-size: 16px; font-weight: 650; }
.instance-id { color: var(--ink-faint); font-size: 12px; margin-top: 4px; }
.instance-meta { margin-top: 10px; }
.instance-dir { margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instance-card.is-empty { opacity: 0.75; }

/* ---------- 登录页 ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 30px 28px;
  width: 320px;
  box-shadow: 0 8px 30px rgba(31, 30, 27, 0.07);
}
.login-card h1 { margin: 0; font-size: 21px; }
.login-card form { margin-top: 20px; }
.login-card label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.login-card input {
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
.alert {
  background: var(--bad-soft);
  color: var(--bad);
  padding: 8px 11px;
  border-radius: 7px;
  font-size: 13px;
  margin-top: 14px;
}
.warn-box {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #ecd9a8;
  margin: 16px 0 4px;
  padding: 11px 14px;
  line-height: 1.6;
}
.warn-box strong { color: #7d5608; }

.gaps {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.gap-row {
  display: grid;
  grid-template-columns: 72px 1fr 120px 52px;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.gap-row:last-child { border-bottom: none; }
.gap-size {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--warn);
  font-weight: 600;
}
.gap-where { font-size: 12px; }
.gap-arrow { margin: 0 6px; color: var(--ink-3); }
.gap-bar-track {
  height: 6px;
  background: var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
}
.gap-bar {
  height: 100%;
  background: repeating-linear-gradient(
    45deg,
    #e0b96a,
    #e0b96a 4px,
    #d3a954 4px,
    #d3a954 8px
  );
}
.gap-pct {
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  color: var(--ink-3);
}
