:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1c2029;
  --line: #262c37;
  --fg: #e6e9ef;
  --dim: #8b93a3;
  --dim-2: #5d6575;
  --accent: #4c8dff;
  --red: #ff5f56;
  --yellow: #ffbd2e;
  --green: #27c93f;
  --blue: #4c8dff;
  --grey: #6b7280;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #e2e5ea;
    --fg: #16181d;
    --dim: #5f6673;
    --dim-2: #939aa6;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ————— 布局 ————— */
#app { display: flex; flex-direction: column; height: 100dvh; }

header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
header h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .2px; }
header .spacer { flex: 1; }

.counts { display: flex; gap: 10px; flex-wrap: wrap; }
.count { font-size: 12px; color: var(--dim); white-space: nowrap; }
.count b { color: var(--fg); font-weight: 600; }

main { flex: 1; display: grid; grid-template-columns: 290px 1fr 320px; min-height: 0; }

.col { min-height: 0; overflow-y: auto; }
.col--list  { background: var(--panel); border-right: 1px solid var(--line); }
.col--main  { background: var(--bg); display: flex; flex-direction: column; }
.col--right { background: var(--panel); border-left: 1px solid var(--line); padding: 12px 14px; }

/* ————— 左栏 cc 列表 ————— */
.agent {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex; gap: 9px; align-items: flex-start;
}
.agent:hover { background: var(--panel-2); }
.agent.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.agent .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: 0 0 auto; }
.agent .body { min-width: 0; flex: 1; }
.agent .name {
  font-weight: 600; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent .meta { font-size: 11.5px; color: var(--dim); margin-top: 1px; }
.agent .step {
  font-size: 11.5px; color: var(--dim-2); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent .busy { font-size: 11px; color: var(--green); }

.dot.blocked { background: var(--red); }
.dot.stalled { background: var(--yellow); }
.dot.ok { background: var(--green); }
.dot.waiting_ci { background: var(--blue); }
.dot.done { background: var(--grey); }

.section-title {
  padding: 9px 12px 6px; font-size: 11px; color: var(--dim-2);
  text-transform: uppercase; letter-spacing: .6px;
}

/* ————— 中栏 ————— */
.detail-head {
  padding: 13px 18px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex: 0 0 auto;
}
.detail-head .title { font-size: 16px; font-weight: 600; }
.detail-head .sub { font-size: 12px; color: var(--dim); margin-top: 3px; font-family: var(--mono); }

.stream { flex: 1; overflow-y: auto; padding: 16px 18px; }

.msg { max-width: 76%; margin-bottom: 12px; }
.msg .bubble {
  padding: 9px 12px; border-radius: 10px; white-space: pre-wrap;
  word-break: break-word; font-size: 13.5px;
}
.msg .when { font-size: 11px; color: var(--dim-2); margin-top: 3px; }
.msg.up   .bubble { background: var(--panel); border: 1px solid var(--line); }
.msg.down { margin-left: auto; }
.msg.down .bubble { background: #2b4a86; border: 1px solid #35589b; }
.msg.system { max-width: 100%; text-align: center; }
.msg.system .bubble {
  background: transparent; color: var(--dim-2); font-size: 12px;
  border: 0; border-top: 1px dashed var(--line); border-radius: 0; padding-top: 8px;
}

.placeholder { color: var(--dim-2); padding: 40px 18px; text-align: center; font-size: 13px; }

/* 投递状态：绝不把五种失败折叠成同一个黄色 */
.msg .st { font-size: 11px; margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msg .st.warn { color: var(--yellow); }
.msg .st.bad  { color: var(--red); }
.msg .st.ok   { color: var(--accent); }
.msg .st button { padding: 2px 7px; font-size: 11px; border-radius: 5px; }
.msg.warn .bubble { border-color: var(--yellow); }
.msg.bad  .bubble { border-color: var(--red); }
.msg.cc .bubble {
  background: transparent; border: 1px dashed var(--line);
  color: var(--dim); font-size: 12.5px;
}
.msg.ask .bubble { border-color: var(--yellow); border-width: 2px; }

/* 输入区 */
.composer { flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--panel); padding: 10px 14px; }
.composer textarea {
  width: 100%; resize: vertical; font: inherit; font-size: 13.5px; padding: 8px 10px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
}
.composer-row { display: flex; align-items: center; gap: 12px; margin-top: 7px; }
.composer-row .chk { font-size: 12.5px; color: var(--dim); display: flex; align-items: center; gap: 5px; }
.composer-row .hint { font-size: 11.5px; color: var(--dim-2); }
.composer-row .hint.warn { color: var(--yellow); }
.composer #send { background: var(--accent); border-color: var(--accent); color: #fff; }
.composer #send:disabled { opacity: .5; cursor: default; }
.quick { display: flex; gap: 6px; margin-bottom: 7px; flex-wrap: wrap; }
.quick button { font-size: 11.5px; padding: 3px 9px; }

/* ————— 右栏时间线 ————— */
.tl-head { font-size: 12px; color: var(--dim-2); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; }
.tl-item { display: flex; gap: 9px; padding-bottom: 12px; position: relative; }
.tl-item:not(:last-child)::before {
  content: ""; position: absolute; left: 3.5px; top: 12px; bottom: 0;
  width: 1px; background: var(--line);
}
.tl-item .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--dim-2); margin-top: 5px; flex: 0 0 auto; z-index: 1; }
.tl-item.longest .pip { background: var(--yellow); }
.tl-item .tl-body { min-width: 0; }
.tl-item .tl-ts { font-size: 11px; color: var(--dim-2); font-family: var(--mono); }
.tl-item .tl-step { font-size: 12.5px; word-break: break-word; }
.tl-item .tl-dur { font-size: 11px; color: var(--dim); }
.tl-item.longest .tl-dur { color: var(--yellow); }

.now-box {
  margin: 6px 0 14px; padding: 8px 10px; border-radius: 8px;
  background: var(--panel-2); font-size: 12px; color: var(--dim);
}
.now-box b { color: var(--fg); }

button {
  font: inherit; cursor: pointer; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--fg);
  padding: 6px 11px; font-size: 12.5px;
}
button:hover { border-color: var(--dim-2); }

/* ————— 页脚：平台自身状态 ————— */
footer {
  flex: 0 0 auto; padding: 6px 16px; font-size: 11.5px; color: var(--dim-2);
  background: var(--panel); border-top: 1px solid var(--line);
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
footer.bad { color: var(--red); }

.mode { display: inline-flex; align-items: center; gap: 5px; }
.mode .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.mode.polling .pip { background: var(--yellow); }
.mode.offline .pip { background: var(--red); }

/* ————— 终端快照 ————— */
dialog {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  color: var(--fg); max-width: min(1000px, 92vw); width: 100%; padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog .dlg-head {
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
dialog pre {
  margin: 0; padding: 14px; overflow: auto; max-height: 65vh;
  font-family: var(--mono); font-size: 12px; line-height: 1.45;
}

/* ————— 登录页 ————— */
.login-wrap { height: 100dvh; display: grid; place-items: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 24px; width: min(340px, 90vw);
}
.login-card h1 { margin: 0 0 4px; font-size: 17px; }
.login-card p { margin: 0 0 18px; color: var(--dim); font-size: 12.5px; }
.login-card input {
  width: 100%; padding: 9px 11px; margin-bottom: 10px; font: inherit;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 7px;
}
.login-card button { width: 100%; padding: 9px; background: var(--accent); border-color: var(--accent); color: #fff; }
.login-err { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 8px; }

/* ————— 窄屏：S6 会做完整 tab 折叠，这里先保证不横向溢出 ————— */
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .col--list { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .col--right { display: none; }
}
