:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e4e7ee;
  --line-strong: #cfd4de;
  --text: #1c2130;
  --text-2: #4d5566;
  --text-3: #7c8496;
  --accent: #2f5bff;
  --accent-soft: #e8eeff;
  --accent-text: #1f45d6;
  --ok: #1a8f4e;
  --ok-soft: #e4f6ec;
  --bad: #c62828;
  --bad-soft: #fdeceb;
  --warn: #b7791f;
  --warn-soft: #fff4dd;
  --muted-soft: #eef0f4;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(18, 24, 44, 0.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --panel: #1b1e27;
    --panel-2: #20242e;
    --line: #2b3040;
    --line-strong: #3a4054;
    --text: #e8eaf1;
    --text-2: #b4bac8;
    --text-3: #7f8698;
    --accent: #6d8bff;
    --accent-soft: #232b4a;
    --accent-text: #9db0ff;
    --ok: #4cc47f;
    --ok-soft: #173325;
    --bad: #ff6b6b;
    --bad-soft: #3a1d1d;
    --warn: #e2b04c;
    --warn-soft: #3a3016;
    --muted-soft: #262a36;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
code, .mono { font-family: var(--mono); }

/* ---------- 基础组件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line-strong)); }
.btn.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line-strong)); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted-soft); }
.btn.block { width: 100%; justify-content: center; }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--text); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 84px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field .help { font-size: 12px; color: var(--text-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: var(--muted-soft); color: var(--text-2); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent-text); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.mono { font-family: var(--mono); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.dot.open { background: var(--accent); }
.dot.passed { background: var(--ok); }
.dot.failed { background: var(--bad); }
.dot.handoff { background: var(--warn); }
.dot.archived { background: var(--text-3); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.code-label { font-family: var(--mono); font-weight: 700; letter-spacing: .3px; }
.word-label { font-weight: 600; }

/* toast */
#toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 360px; animation: toast-in .18s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border-radius: 16px; width: min(640px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow); padding: 22px 24px; }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.tbl th { color: var(--text-3); font-weight: 500; font-size: 12px; white-space: nowrap; }
table.tbl tr:hover td { background: var(--panel-2); }
.tbl-wrap { overflow-x: auto; }

/* topbar */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .brand .logo { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-2); font-size: 13px; }

.banner { padding: 8px 14px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-bottom: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--accent-soft); color: var(--accent-text); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-all; }

.empty { text-align: center; color: var(--text-3); padding: 40px 16px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* transcript */
.transcript { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.agent { align-self: flex-start; background: var(--muted-soft); border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; background: transparent; color: var(--text-3); font-size: 12px; }
.bubble .meta { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }
