:root {
  --bg: #f3f4f7; --panel: #fff; --text: #1d2330; --muted: #6b7385; --faint: #9aa1b0; --line: #e3e6eb;
  --accent: #2f6fde; --accent-soft: #eaf1fd; --accent-text: #fff; --ok: #1f8a4c; --warn: #a86400; --bad: #c4372f;
  --warn-bg: #fff4e0; --bad-bg: #fdecea; --ok-bg: #e7f6ed; --chip: #eef1f5; --code: #f1f3f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418; --panel: #1b1f26; --text: #e6e8eb; --muted: #98a2b3; --faint: #6c7586; --line: #2c323c;
    --accent: #5b8ff0; --accent-soft: #1d2a42; --accent-text: #0e1116; --ok: #4cc27f; --warn: #f0a83a; --bad: #f2706a;
    --warn-bg: #3a2c12; --bad-bg: #3d1d1b; --ok-bg: #16301f; --chip: #262b33; --code: #262b33;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* 否则 .tasks 的 display:grid 会盖过 hidden */
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }
input, textarea, button, select { font: inherit; color: inherit; }
input, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
label { display: block; margin: 12px 0; color: var(--muted); font-size: 13px; }
label input, label textarea { margin-top: 4px; color: var(--text); font-size: 14px; }
button, .button { padding: 7px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; text-decoration: none; color: var(--text); display: inline-block; }
button:disabled { opacity: .55; cursor: progress; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.link { border: none; background: none; color: var(--accent); padding: 4px 0; }
.block { width: 100%; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; box-shadow: var(--shadow); }
.msg { color: var(--bad); min-height: 0; margin: 8px 0 0; }
.msg:empty { display: none; }
.muted { color: var(--muted); }
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.warn-text { color: var(--warn); font-size: 13px; margin-top: 2px; }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 18px; margin-bottom: 8px; }
.login-card button { width: 100%; margin-top: 8px; }

/* 顶栏 */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { margin-right: 8px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { border: none; background: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tab.active { background: var(--chip); color: var(--text); font-weight: 600; }
.exec { font-size: 13px; color: var(--muted); }
.exec::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--faint); }
.exec.on::before { background: var(--ok); }
.exec.off { color: var(--bad); font-weight: 600; }
.exec.off::before { background: var(--bad); }
.me { color: var(--muted); font-size: 13px; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* 任务页：左列表、右详情 */
.tasks { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.list-pane { position: sticky; top: 64px; }
.task-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 140px); overflow: auto; padding-right: 2px; }
.task-item { text-align: left; width: 100%; padding: 8px 10px 8px 12px; border: 1px solid var(--line); border-left: 3px solid transparent; border-radius: 8px; background: var(--panel); }
.task-item:hover { border-color: var(--faint); }
.task-item.todo { border-left-color: var(--warn); }
.task-item.sel { border-color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }
.task-item .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-item .s { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.detail { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

/* 任务头：原话是主标题 */
.task-head { padding: 4px 2px 2px; }
.task-head .meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.task-head .quote { font-size: 20px; line-height: 1.45; font-weight: 600; margin: 8px 0 4px; word-break: break-word; }
.task-head .sub { font-size: 12px; }

/* 区块标题；需要人处理的区块用强调色边框 */
.sec { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card.action { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.action > .sec { color: var(--accent); }
.card.warn { border-left: 4px solid var(--warn); }
.card.warn > .sec { color: var(--warn); }
.card.bad { border-left: 4px solid var(--bad); }
.card.fold { padding: 12px 20px; }
.card.fold > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.card.fold[open] > summary { margin-bottom: 10px; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.chip.DONE { background: var(--ok-bg); color: var(--ok); }
.chip.AWAITING_CONFIRM, .chip.WAITING_REPLY { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.chip.FAILED, .chip.INVALID_PLAN, .chip.CANCELLED { background: var(--bad-bg); color: var(--bad); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px; vertical-align: 1px; }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

/* Agent 答复（Markdown 子集） */
.md p { margin: 0 0 8px; }
.md p:last-child, .md ul:last-child, .md ol:last-child { margin-bottom: 0; }
.md .md-h { font-weight: 600; margin-top: 4px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code, .args code { background: var(--code); padding: 0 5px; border-radius: 4px; font: 12.5px ui-monospace, Consolas, monospace; }
.md strong { font-weight: 600; }

/* 追问对话 */
.thread { display: flex; flex-direction: column; gap: 10px; }
.bubble { padding: 10px 12px; border-radius: 8px; max-width: 90%; }
.bubble .who { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.bubble.agent { background: var(--chip); }
.bubble.human { background: var(--accent-soft); align-self: flex-end; }
.reply-form { margin-top: 12px; }

/* 工具参数 */
.args { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.arg .k { color: var(--muted); font-size: 12px; }

.banner { padding: 9px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
td.num { color: var(--muted); width: 28px; }
td.num + td, td.nowrap { white-space: nowrap; }
.lead { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
tr.flag td { background: var(--bad-bg); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-top: 14px; }
.actions label { margin: 0; flex: 1; min-width: 160px; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar label { margin: 0; }
#ledger > .sec, #cost > .sec { margin: 20px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--muted); font-size: 13px; }
.stat b { display: block; font-size: 20px; color: var(--text); }
.stat.bad { border-color: var(--bad); }
.stat.bad b { color: var(--bad); }
.busy { color: var(--muted); padding: 20px 0; }
.small { font-size: 12px; }
.link.inline { padding: 0; font-size: inherit; }

/* 追加操作 */
.fu-person { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.fu-name { font-weight: 600; margin-right: 4px; }
.sugg { padding: 3px 10px; border-radius: 14px; font-size: 13px; border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.sugg:hover { background: var(--accent); color: var(--accent-text); }
.actions label.narrow { flex: 0 1 220px; min-width: 160px; }
.fu-links { margin-top: 10px; }
.faint { color: var(--faint); }

/* 目录（只读 ADUC 视图）：OU 树 | 对象列表 | 属性 */
.dir { display: grid; grid-template-columns: 250px minmax(0, 1fr) 360px; gap: 12px; align-items: start; }
.dir .card { padding: 12px 14px; }
.dir-tree, .dir-props { position: sticky; top: 64px; max-height: calc(100vh - 84px); overflow: auto; }
.dir-search { margin-bottom: 8px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; }
.tree .node { display: flex; align-items: center; border-radius: 6px; }
.tree .node.sel { background: var(--accent-soft); }
.tree .node.sel .ou { color: var(--accent); font-weight: 600; }
.tree button { border: none; background: none; padding: 3px 4px; text-align: left; }
.tree .twisty { width: 18px; flex: none; color: var(--muted); font-size: 13px; padding: 3px 0; display: inline-block; text-align: center; }
.tree .ou { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs { font-size: 13px; margin-bottom: 4px; display: flex; flex-wrap: wrap; align-items: center; }
.crumbs .link { padding: 0; }
.dir-list table { margin-top: 6px; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--chip); }
tr.row-link.sel td { background: var(--accent-soft); }
tr.row-link.dim td, tr.dim td { color: var(--muted); }
.ico { display: inline-block; min-width: 22px; padding: 0 3px; border-radius: 4px; font: 600 10px/16px ui-monospace, Consolas, monospace; text-align: center; vertical-align: 1px; background: var(--chip); color: var(--muted); }
.ico.user { background: var(--accent-soft); color: var(--accent); }
.ico.group { background: var(--ok-bg); color: var(--ok); }
.ico.organizationalUnit { background: var(--warn-bg); color: var(--warn); }
.props-head { display: flex; gap: 10px; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.props-head .ico { font-size: 12px; line-height: 22px; min-width: 30px; }
.props-head .pname { font-size: 16px; font-weight: 600; word-break: break-all; }
.dir-props h3 { margin: 14px 0 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.dir-props .kv { grid-template-columns: 112px 1fr; font-size: 13px; }
ul.plain { list-style: none; margin: 0; padding: 0; font-size: 13px; }
ul.plain li { padding: 2px 0; }
ul.plain .link { padding: 0; text-align: left; }
@media (max-width: 1100px) {
  .dir { grid-template-columns: 230px minmax(0, 1fr); }
  .dir-props { grid-column: 1 / -1; position: static; max-height: none; }
}

@media (max-width: 760px) {
  main { padding: 12px; }
  .tasks { grid-template-columns: 1fr; }
  .list-pane { position: static; }
  .task-list { max-height: 240px; }
  .tabs { order: 3; width: 100%; }
  .task-head .quote { font-size: 17px; }
  .bubble { max-width: 100%; }
  .dir { grid-template-columns: 1fr; }
  .dir-tree { position: static; max-height: 260px; }
}

/* 测试页 */
.progress { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.progress .track { flex: 1; height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.progress .bar { height: 100%; background: var(--accent); transition: width .4s; }
pre.log { white-space: pre-wrap; word-break: break-word; background: var(--code); border-radius: 6px; padding: 10px 12px; font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 420px; overflow: auto; margin: 8px 0 0; }
.inline-check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.inline-check input { width: auto; }
#test-task:not(:empty) { margin-top: 16px; padding-top: 12px; border-top: 2px dashed var(--line); }
.test-task-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
