:root {
  --bg: #070a0f;
  --panel: #0b1017;
  --panel2: #0e141c;
  --line: #1b2632;
  --line2: #263646;
  --txt: #dbe7f3;
  --txt2: #9fb3c6;
  --dim: #667a8d;
  --acc: #3f8cff;
  --acc2: #5fa3ff;
  --ok: #2dd4a0;
  --warn: #f5b544;
  --err: #ff6b6b;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--txt);
  font-family: var(--sans); font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

body.app { display: flex; flex-direction: column; overflow: hidden; }

/* ------------------------------ 顶栏 ------------------------------ */
.topbar {
  flex: 0 0 auto; height: 52px;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0a1018, #080d13);
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; letter-spacing: .04em; white-space: nowrap; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 9px var(--ok); }
.brand em { font-style: normal; font-size: 10px; color: var(--dim); border: 1px solid var(--line2); padding: 2px 5px; border-radius: 4px; font-family: var(--mono); }

.topbar select, .topbar input {
  height: 30px; padding: 0 8px; border-radius: 7px;
  background: #0a1118; border: 1px solid var(--line2); color: var(--txt); font-size: 12px;
  outline: none;
}
.topbar select:focus, .topbar input:focus { border-color: var(--acc); }
#source { width: 168px; }
#database { width: 150px; }

.chips { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px;
  border: 1px solid var(--line2); border-radius: 13px; background: #0b121a;
  font-size: 11.5px; color: var(--txt2); white-space: nowrap; text-decoration: none;
}
.chip b { font-family: var(--mono); font-weight: 600; color: var(--txt); }
.chip i { width: 6px; height: 6px; border-radius: 50%; background: #3d4c5c; }
.chip.on i { background: var(--ok); box-shadow: 0 0 7px var(--ok); }
.chip.bad b { color: var(--err); }
.chip.link { cursor: pointer; }
.chip.link:hover { border-color: #33506b; color: #fff; }

/* ------------------------------ 布局 ------------------------------ */
.grid {
  flex: 1 1 0; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) 424px;
  grid-template-rows: minmax(0, 1fr);
}

.left {
  min-width: 0; min-height: 0; padding: 10px;
  display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 10px;
}

.pane {
  min-height: 0; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 11px; background: var(--panel);
  overflow: hidden;
}
.pane-head {
  flex: 0 0 auto; height: 34px; display: flex; align-items: center; gap: 8px;
  padding: 0 11px; border-bottom: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: #c3d5e6; letter-spacing: .02em;
}
.pane-head span { font-weight: 400; font-size: 10.5px; color: var(--dim); font-family: var(--mono); }

/* 对象树 */
.tree-filter {
  flex: 0 0 auto; margin: 8px 9px 4px; height: 28px; padding: 0 9px; border-radius: 7px;
  background: #0a1118; border: 1px solid var(--line2); color: var(--txt); font-size: 11.5px; outline: none;
}
.tree-filter:focus { border-color: var(--acc); }
.tree { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 4px 6px 20px; }

.tgroup { margin: 2px 0; }
.tgroup-head {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px;
  font-size: 11.5px; color: var(--txt2); cursor: pointer; user-select: none;
}
.tgroup-head:hover { background: rgba(63, 140, 255, .07); }
.tgroup-head b { font-weight: 500; color: #cfe0f0; }
.tgroup-head .cnt { margin-left: auto; font-family: var(--mono); font-size: 10px; color: var(--dim); }

.titem {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 17px;
  border-radius: 6px; font-size: 11.5px; color: var(--txt2); cursor: pointer;
  white-space: nowrap; overflow: hidden;
}
.titem:hover { background: rgba(63, 140, 255, .08); color: #fff; }
.titem.active { background: rgba(63, 140, 255, .16); color: #fff; box-shadow: inset 2px 0 0 var(--acc); }
.titem .ico { font-size: 9px; color: #4f6b85; }
.titem .nm { overflow: hidden; text-overflow: ellipsis; }
.titem .rw { margin-left: auto; font-family: var(--mono); font-size: 9.5px; color: #4a6076; }

.tcols { padding: 2px 0 6px 0; }
.tcol {
  display: flex; align-items: center; gap: 6px; padding: 2px 6px 2px 30px;
  font-family: var(--mono); font-size: 10.5px; color: #8ba2b7;
}
.tcol .pk { color: var(--warn); font-size: 9px; }
.tcol .ty { color: #58748c; }
.tcol .nn { margin-left: auto; color: #4c6274; font-size: 9px; }

/* 工作区 */
.work { display: flex; flex-direction: column; min-width: 0; }

.toolbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel2);
}
.toolbar .sep { width: 1px; height: 20px; background: var(--line2); margin: 0 2px; }

button {
  height: 29px; padding: 0 11px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line2); background: #0e1721; color: var(--txt2);
  font-size: 12px; font-family: inherit; white-space: nowrap; transition: .14s;
}
button:hover { border-color: #3a5670; color: #fff; background: #142231; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #2f7fd6, #2569b3); border-color: #3f8fe0; color: #fff; font-weight: 600; }
button.primary:hover { background: linear-gradient(180deg, #3a8fe8, #2b74c4); }
button.ghost { background: transparent; }

.toolbar select {
  height: 29px; padding: 0 6px; border-radius: 7px; font-size: 11.5px;
  background: #0a1118; border: 1px solid var(--line2); color: var(--txt2); outline: none;
}
#intentText {
  flex: 1; min-width: 130px; height: 29px; padding: 0 9px; border-radius: 7px;
  background: #0a1118; border: 1px solid var(--line2); color: var(--txt); font-size: 11.5px; outline: none;
}
#intentText:focus { border-color: var(--acc); }

.editor-wrap { flex: 0 0 auto; position: relative; height: 38%; min-height: 120px; }
#editor {
  width: 100%; height: 100%; resize: none; display: block;
  background: #070c12; color: #cfe2f2; border: 0; outline: none;
  padding: 11px 13px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  tab-size: 2;
}
#editor::placeholder { color: #40566a; }

.resbar {
  flex: 0 0 auto; height: 28px; display: flex; align-items: center; gap: 12px;
  padding: 0 11px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #0a121a; font-size: 11px; color: var(--dim); font-family: var(--mono);
}
.resbar .ok { color: var(--ok); }
.resbar .bad { color: var(--err); }
.resbar .warn { color: var(--warn); }
.resbar .grow { margin-left: auto; }

.result { flex: 1 1 0; min-height: 0; overflow: auto; background: #070c12; }
table.dgrid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-family: var(--mono); font-size: 11.5px; }
table.dgrid thead th {
  position: sticky; top: 0; z-index: 2; text-align: left; white-space: nowrap;
  padding: 6px 10px; background: #0d1620; color: #a9c0d4; font-weight: 600;
  border-bottom: 1px solid var(--line2); border-right: 1px solid rgba(38, 54, 70, .5);
}
table.dgrid thead th .t { color: #55708a; font-weight: 400; font-size: 9.5px; margin-left: 5px; }
table.dgrid tbody td {
  padding: 4px 10px; border-bottom: 1px solid rgba(27, 38, 50, .65);
  color: #c6d8e8; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.dgrid tbody tr:nth-child(even) td { background: rgba(255, 255, 255, .014); }
table.dgrid tbody tr:hover td { background: rgba(63, 140, 255, .07); }
table.dgrid td.null { color: #4a5f72; font-style: italic; }
table.dgrid td.num { color: #7fd4b0; text-align: right; }

.empty {
  display: flex; align-items: center; justify-content: center; height: 100%;
  color: #3d5164; font-size: 12px; flex-direction: column; gap: 6px;
}
.empty b { color: #5b7288; font-weight: 500; }

/* 结构面板（表详情浮层） */
.sheet {
  position: fixed; inset: 0; z-index: 40; display: none;
  background: rgba(3, 6, 10, .62); backdrop-filter: blur(3px);
}
.sheet.on { display: flex; align-items: center; justify-content: center; }
.sheet-box {
  width: min(760px, 92vw); max-height: 78vh; display: flex; flex-direction: column;
  background: #0b1219; border: 1px solid var(--line2); border-radius: 13px; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.sheet-head { display: flex; align-items: center; gap: 9px; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; font-weight: 600; }
.sheet-head .x { margin-left: auto; cursor: pointer; color: var(--dim); padding: 2px 8px; border-radius: 6px; }
.sheet-head .x:hover { background: var(--line); color: #fff; }
.sheet-body { overflow: auto; padding: 10px 14px 16px; }
.sheet-body table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
.sheet-body th { text-align: left; padding: 5px 8px; color: #7f97ac; border-bottom: 1px solid var(--line2); font-weight: 500; }
.sheet-body td { padding: 4px 8px; border-bottom: 1px solid rgba(27, 38, 50, .6); color: #b9cddd; }
.sheet-body .tag { font-size: 9.5px; padding: 1px 5px; border-radius: 4px; background: #16232f; color: #7ea3c3; }

/* ------------------------------ 日志 ------------------------------ */
.right {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  border-left: 1px solid var(--line); background: #080e14;
}
.log-head { flex: 0 0 auto; border-bottom: 1px solid var(--line); padding: 8px 12px 8px; }
.hidden { display: none !important; }

/* 右侧两个 Tab：通信日志 / 执行记录 */
.log-tabs { display: flex; align-items: center; gap: 4px; }
.ltab {
  height: 26px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent;
  color: #7b90a4; font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
}
.ltab:hover { color: #cfe0f0; background: rgba(63, 140, 255, .08); }
.ltab.on { color: #e6f2ff; background: #101c28; box-shadow: inset 0 0 0 1px var(--line2); }
.ltab .tb {
  font: 9.5px/1 var(--mono); color: #6d8798; background: #0d1721; border-radius: 8px; padding: 2px 5px;
}
.ltab.on .tb { color: #8ec8ff; background: #14283a; }
.ltab.fresh .tb { color: #0b1219; background: var(--acc); animation: tabPulse 1.4s ease-out 2; }
@keyframes tabPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.log-tabs .ws { margin-left: auto; font: 10px var(--mono); color: #4e6373; }

.log-tools { display: flex; gap: 6px; margin-top: 8px; }
.log-tools select, .log-tools input {
  height: 27px; border-radius: 7px; background: #0b131b; border: 1px solid var(--line2);
  color: var(--txt2); padding: 0 7px; font-size: 11px; outline: none;
}
.log-tools select { width: 116px; }
.log-tools input { flex: 1; min-width: 0; }
.log-tools input:focus { border-color: var(--acc); }
button.mini { height: 27px; width: 29px; padding: 0; font-size: 12px; }

.log-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 10px; color: var(--dim); font-family: var(--mono); }
.log-stats b { color: var(--txt2); }
.log-stats #sFile { color: #4e6373; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-list { flex: 1 1 0; min-height: 0; overflow-y: auto; padding-bottom: 30px; }
.exec-list { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 6px 8px 30px; }

/* 执行记录卡片 */
.xrow { border: 1px solid var(--line); border-radius: 9px; background: #0a1118; margin-bottom: 7px; padding: 7px 9px 8px; }
.xrow:hover { border-color: #23384c; }
.xrow.bad { border-color: #44201f; background: #120c0c; }
.xhead { display: flex; align-items: center; gap: 6px; font: 10px/1.4 var(--mono); color: #6f879b; }
.xorg { padding: 1px 5px; border-radius: 4px; font-size: 9.5px; letter-spacing: .04em; white-space: nowrap; }
.xorg.ai { color: #8ad4ff; border: 1px solid #2c5c7c; background: #0b1c27; }
.xorg.console { color: #c3b3ff; border: 1px solid #4a3f6b; background: #151129; }
.xorg.verify { color: #8ee6b8; border: 1px solid #285c43; background: #0a1c14; }
.xhead .xdb { color: #8ba0b3; }
.xhead .xwhen { margin-left: auto; color: #55708a; }
.xstat { display: flex; align-items: center; gap: 6px; margin-left: 4px; }
.xpill { font-size: 9.5px; padding: 1px 5px; border-radius: 4px; border: 1px solid transparent; }
.xpill.ok { color: #7ee0b4; border-color: #1e5a42; background: #0a1c15; }
.xpill.bad { color: #ff9d9d; border-color: #5a2424; background: #1a0d0d; }
.xpill.warn { color: #f0c674; border-color: #5a4420; background: #1a1408; }
.xmeta { color: #6d8798; }

.xsql {
  margin: 6px 0 0; padding: 6px 8px; border-radius: 6px;
  background: #060b10; border: 1px solid var(--line);
  font: 10.5px/1.62 var(--mono); color: #a9c4d8;
  white-space: pre-wrap; word-break: break-word;
  max-height: 108px; overflow: auto; cursor: text;
}
.xsql .kw { color: #7ec8ff; font-weight: 600; }
.xsql .str { color: #b7d98a; }
.xsql .cm { color: #55697a; font-style: italic; }
.xacts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; align-items: center; }
.xacts button { height: 23px; padding: 0 8px; font-size: 10.5px; border-radius: 6px; }
.xerr {
  margin-top: 6px; font: 10px/1.45 var(--mono); color: #ff9d9d;
  max-height: 58px; overflow: auto; word-break: break-word;
}

.xcheck { margin-top: 6px; padding: 5px 8px; border-radius: 6px; font: 10.5px/1.5 var(--mono); border: 1px solid; }
.xcheck.good { color: #7ee0b4; border-color: #1a4a36; background: #08150f; }
.xcheck.warn { color: #f0c674; border-color: #4a3a15; background: #171207; }
.xcheck.bad { color: #ff9d9d; border-color: #4d2020; background: #190c0c; }
.xcheck .xgo { margin-left: 6px; height: 21px; padding: 0 7px; font-size: 10px; border-radius: 5px; vertical-align: 1px; }
.xchecks { margin-top: 5px; font: 9.5px/1.5 var(--mono); color: #55708a; }
.xchecks div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 日志行里的 SQL 摘要 */
.lrow .lcode {
  grid-column: 2 / -1; font: 9.5px/1.45 var(--mono); color: #6f93ac;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px;
}
.lrow .lcode::before { content: 'SQL '; color: #4b6e86; }

.lrow {
  display: grid; grid-template-columns: 62px 12px minmax(0, 1fr) auto 10px;
  align-items: center; gap: 5px; padding: 5px 10px 5px 8px;
  border-left: 2px solid transparent; cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.5;
  border-bottom: 1px solid rgba(255, 255, 255, .02);
}
.lrow:hover { background: rgba(63, 140, 255, .05); }
.lrow.lane-mcp { border-left-color: #3b7fc4; }
.lrow.lane-db { border-left-color: #2f9e8f; }
.lrow.lane-hub { border-left-color: #4a5b6b; }
.lrow.lane-sys { border-left-color: #6b5a86; }
.lrow.err { background: rgba(255, 107, 107, .07); border-left-color: var(--err) !important; }
.lrow .lt { color: #5d7285; font-size: 9.5px; }
.lrow .ldir { color: #7d93a6; text-align: center; font-size: 9px; }
.lrow .lkind { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #93a9bd; }
.lrow .lkind .k { color: #cfdfef; }
.lrow .lkind .tool { color: #7ec8ff; }
.lrow .lms { color: #6d8798; font-size: 9.5px; text-align: right; }
.lrow .larr { color: #44586b; font-size: 8px; }
.lrow.open .larr { transform: rotate(90deg); }
.lrow.err .lkind { color: #ffa0a0; }
.lrow .lpay { grid-column: 1 / -1; display: none; margin: 5px 0 2px 4px; background: #060b10; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; max-height: 240px; overflow: auto; }
.lrow.open .lpay { display: block; }
.lrow .lpay pre { margin: 0; font: 10px/1.6 var(--mono); color: #9fb6c9; white-space: pre-wrap; word-break: break-all; }
.lrow .note { grid-column: 2 / -1; font-size: 10px; color: #8ba0b3; margin-top: 1px; }
.lrow .note.bad { color: #ff9d9d; }

/* ------------------------------ 操作人 / 审批人 ------------------------------ */
.topbar input.who { width: 96px; }
.log-tools input.who { flex: 0 0 112px; }

/* 审计链路 */
.lrow.lane-audit { border-left-color: #a97bff; }
.lrow.lane-audit .lkind .k { color: #d6c2ff; }

/* 执行记录里的操作人 / 审批人标记 */
.xhead .xwho { color: #9fb3c6; }
.xhead .xappr {
  color: #c3b3ff; border: 1px solid #4a3f6b; background: #151129;
  border-radius: 4px; padding: 0 4px; font-size: 9px;
}

/* ------------------------------ 审批台 ------------------------------ */
.arow { border-left: 2px solid #4a3a15; }
.arow.st-approved { border-left-color: #2f6fa8; }
.arow.st-executed { border-left-color: #1e5a42; }
.arow.st-rejected, .arow.st-failed { border-left-color: #5a2424; }
.arow.st-expired, .arow.st-cancelled { border-left-color: #2a3742; opacity: .78; }
.arow .xwhen { margin-left: 0; }
.arow .xdb { white-space: nowrap; }
.arow .aid { margin-left: auto; flex: 0 0 auto; color: #4e6373; font-size: 9px; }

/* 审批台：只钉住“刚刚处理的那一张”，避免整档跳走让历史工单一起冒出来 */
.apin {
  flex: 0 0 auto; min-width: 0;
  border-bottom: 1px solid var(--line2);
  background: linear-gradient(180deg, rgba(63, 140, 255, .10), rgba(63, 140, 255, .02));
  max-height: 46%;
  overflow: auto;
}
.apin-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px 5px; font-size: 10.5px; color: var(--txt2); min-width: 0;
}
.apin-tag {
  flex: 0 0 auto; font-size: 9.5px; font-weight: 700; letter-spacing: .02em;
  color: #061019; background: var(--acc); padding: 1.5px 6px; border-radius: 4px;
}
.apin-id { flex: 0 0 auto; font-family: var(--mono); font-size: 9.5px; color: var(--txt2); }
.apin-pill {
  flex: 0 0 auto; font-size: 9.5px; padding: 1px 6px; border-radius: 4px;
  color: var(--ok); border: 1px solid rgba(45, 212, 160, .35); background: rgba(45, 212, 160, .08);
}
.apin-note {
  flex: 1 1 auto; min-width: 0; margin-left: 4px; color: var(--dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.apin .arow { border-left-color: var(--acc); background: rgba(63, 140, 255, .05); }
.apin .arow .xhead { padding-top: 2px; }

.alistnote {
  padding: 6px 12px; font-size: 10.5px; color: var(--dim);
  border-bottom: 1px dashed var(--line);
  background: rgba(255, 255, 255, .015);
}
.alistnote b { color: var(--txt2); }

.apill { font-size: 9.5px; padding: 1px 5px; border-radius: 4px; border: 1px solid transparent; white-space: nowrap; }
.apill.warn { color: #f0c674; border-color: #5a4420; background: #1a1408; }
.apill.go { color: #8ec8ff; border-color: #2c5c7c; background: #0b1c27; }
.apill.ok { color: #7ee0b4; border-color: #1e5a42; background: #0a1c15; }
.apill.bad { color: #ff9d9d; border-color: #5a2424; background: #1a0d0d; }
.apill.dim { color: #6d8798; border-color: #263646; background: #0c141b; }

.arisk {
  margin-top: 5px; padding: 3px 7px; border-radius: 6px;
  background: #1a1408; border: 1px solid #4a3a15; color: #f0c674;
  font: 10px/1.5 var(--mono);
}
.atrail { margin-top: 6px; font: 9.5px/1.6 var(--mono); color: #6d8798; }
.atrail b { color: #b9cddd; font-weight: 600; }
.atrail .asep { color: #3f566b; padding: 0 3px; }
.acomment { margin-top: 4px; font: 10px/1.5 var(--mono); color: #9fb3c6; }

button.okbtn { border-color: #1e5a42; color: #7ee0b4; background: #0a1c15; }
button.okbtn:hover { border-color: #2a7d5c; background: #0f2a1f; color: #a7f0cf; }
button.badbtn { border-color: #5a2424; color: #ff9d9d; background: #1a0d0d; }
button.badbtn:hover { border-color: #7d3232; background: #241111; color: #ffbcbc; }

/* 结果/日志滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1f2c39; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #2c3f52; }

@media (max-width: 1180px) {
  .grid { grid-template-columns: minmax(0, 1fr) 360px; }
  .left { grid-template-columns: 196px minmax(0, 1fr); }
  .topbar input.who { width: 76px; }
  #source { width: 138px; }
  #database { width: 120px; }
}
@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1.4fr) minmax(0, 1fr); }
  .right { border-left: 0; border-top: 1px solid var(--line); }
  #intentText { display: none; }
}
