#wfV2Editor {
  position: fixed;
  inset: 0;
  z-index: 91;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5, 10, 18, .72);
}

#wfV2Editor.show { display: flex; }

.wfv2-shell {
  width: min(1500px, 98vw);
  height: min(920px, 96vh);
  min-height: 620px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 190px;
  overflow: hidden;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .4);
}

.wfv2-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 74px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.wfv2-title-block {
  min-width: 260px;
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(180px, 360px) minmax(160px, 1fr);
  align-items: center;
  gap: 9px;
}

.wfv2-badge {
  padding: 4px 8px;
  color: #fff;
  background: #3157a4;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
}

.wfv2-title-block input,
.wfv2-toolbox input,
.wfv2-properties input,
.wfv2-properties select,
.wfv2-properties textarea,
.wfv2-test-row select,
.wfv2-test-row textarea {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

#wfv2Name { font-size: 15px; font-weight: 700; }
#wfv2Description { font-size: 13px; }

.wfv2-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.wfv2-actions button,
.wfv2-canvas-head button,
.wfv2-test-row button {
  padding: 8px 11px;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.wfv2-actions button:disabled,
.wfv2-test-row button:disabled { opacity: .5; cursor: not-allowed; }

.wfv2-close {
  padding: 6px 9px !important;
  color: var(--muted) !important;
  background: transparent !important;
  border-color: var(--border) !important;
}

.wfv2-save-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.wfv2-save-state.dirty { color: #9a6700; }
.wfv2-save-state.saved { color: #1a7f37; }

.wfv2-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 230px minmax(360px, 1fr) 330px;
}

.wfv2-toolbox,
.wfv2-properties {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: var(--panel);
}

.wfv2-toolbox { border-right: 1px solid var(--border); }
.wfv2-properties { border-left: 1px solid var(--border); }
.wfv2-toolbox > label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; }
#wfv2Search { margin-bottom: 12px; font-size: 13px; }

.wfv2-tool-group { margin-bottom: 15px; }
.wfv2-tool-group h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.wfv2-tool {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  padding: 7px 8px;
  color: var(--text);
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.wfv2-tool:hover { border-color: #3157a4; transform: translateY(-1px); }
.wfv2-tool span:first-child { width: 21px; text-align: center; }
.wfv2-tool small { display: block; color: var(--muted); font-size: 9px; }

.wfv2-canvas-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--muted) 20%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}

.wfv2-canvas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--border);
}

.wfv2-canvas-head b { font-size: 13px; }
.wfv2-canvas-head span { margin-left: 8px; color: var(--muted); font-size: 11px; }

.wfv2-canvas {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 24px max(24px, calc((100% - 620px) / 2));
}

.wfv2-node {
  position: relative;
  width: min(620px, 100%);
  margin: 0 auto 25px;
  padding: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid #6e7781;
  border-radius: 11px;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .06);
  cursor: pointer;
}

.wfv2-node::after {
  content: "↓";
  position: absolute;
  left: 50%;
  bottom: -24px;
  color: var(--muted);
  font-size: 16px;
}

.wfv2-node:last-child::after { display: none; }
.wfv2-node.selected { outline: 3px solid color-mix(in srgb, #3157a4 35%, transparent); border-color: #3157a4; }
.wfv2-node[data-category="input"] { border-left-color: #8250df; }
.wfv2-node[data-category="file_processing"] { border-left-color: #0969da; }
.wfv2-node[data-category="ai"] { border-left-color: #bf8700; }
.wfv2-node[data-category="control"] { border-left-color: #cf222e; }
.wfv2-node[data-category="assessment"] { border-left-color: #8250df; }
.wfv2-node[data-category="output"] { border-left-color: #1a7f37; }

.wfv2-node-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 10px 12px 8px;
}

.wfv2-node-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border-radius: 8px;
}

.wfv2-node-name { min-width: 0; }
.wfv2-node-name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.wfv2-node-name small { color: var(--muted); font: 10px ui-monospace, monospace; }
.wfv2-node-start { padding: 2px 7px; color: #8250df; background: color-mix(in srgb, #8250df 12%, transparent); border-radius: 999px; font-size: 10px; font-weight: 700; }

.wfv2-node-ports {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 7px 12px 10px;
  color: var(--muted);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border-top: 1px solid var(--border);
  font-size: 10px;
}

.wfv2-port {
  padding: 2px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.wfv2-port strong { color: var(--text); }
.wfv2-port.unconnected { color: #cf222e; border-color: color-mix(in srgb, #cf222e 45%, var(--border)); }
.wfv2-canvas-empty { padding: 48px 16px; color: var(--muted); text-align: center; }

.wfv2-empty-panel { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.wfv2-properties h3 { margin: 0 0 3px; font-size: 15px; }
.wfv2-properties .wfv2-type { margin-bottom: 13px; color: var(--muted); font: 10px ui-monospace, monospace; }
.wfv2-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.wfv2-field > label { font-size: 11px; font-weight: 700; }
.wfv2-field small { color: var(--muted); font-size: 10px; line-height: 1.45; }
.wfv2-field textarea { resize: vertical; line-height: 1.45; }
.wfv2-prop-section { margin: 15px 0 8px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; font-weight: 700; }
.wfv2-route-row { display: grid; grid-template-columns: 70px minmax(0, 1fr); align-items: center; gap: 7px; margin-bottom: 7px; }
.wfv2-route-row label { overflow: hidden; color: var(--muted); font: 10px ui-monospace, monospace; text-overflow: ellipsis; }
.wfv2-danger {
  width: 100%;
  margin-top: 12px;
  padding: 7px;
  color: #cf222e;
  background: transparent;
  border: 1px solid color-mix(in srgb, #cf222e 50%, var(--border));
  border-radius: 8px;
  cursor: pointer;
}

.wfv2-bottom {
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.wfv2-tabs { height: 38px; display: flex; align-items: end; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.wfv2-tabs button { padding: 10px 12px 8px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; font: inherit; font-size: 12px; cursor: pointer; }
.wfv2-tabs button.active { color: var(--text); border-bottom-color: #3157a4; font-weight: 700; }
.wfv2-tab-panel { height: 151px; overflow: auto; padding: 10px 14px; font-size: 12px; }
.wfv2-issue { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 8px; padding: 6px 7px; border-bottom: 1px solid var(--border); }
.wfv2-issue.error .severity { color: #cf222e; }
.wfv2-issue.warning .severity { color: #9a6700; }
.wfv2-issue code { color: var(--muted); font-size: 10px; }
.wfv2-ok { color: #1a7f37; padding: 8px; }
.wfv2-test-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; align-items: start; gap: 8px; }
.wfv2-test-row textarea { min-height: 90px; resize: vertical; }
.wfv2-result-summary { display: flex; gap: 10px; align-items: center; margin-bottom: 7px; }
.wfv2-result-node { display: grid; grid-template-columns: minmax(120px, 1fr) 100px minmax(180px, 2fr); gap: 8px; padding: 5px 7px; border-bottom: 1px solid var(--border); }
.wfv2-status-succeeded { color: #1a7f37; }
.wfv2-status-failed { color: #cf222e; }
.wfv2-status-skipped { color: var(--muted); }
.wfv2-status-waiting,
.wfv2-status-waiting_for_human,
.wfv2-waiting { color: #9a6700; }
.wfv2-download { display: inline-block; margin: 6px 8px 0 0; color: #0969da; }

#v2Ops {
  position: fixed;
  inset: 0;
  z-index: 94;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5, 10, 18, .72);
}
#v2Ops.show { display: flex; }
.v2ops-shell {
  width: min(1240px, 98vw);
  height: min(880px, 96vh);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .4);
}
.v2ops-guide { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; color: #173a72; background: #edf5ff; border-top: 1px solid #c7dcf7; border-bottom: 1px solid #c7dcf7; font-size: 13px; }
.v2ops-guide button { padding: 8px 12px; color: white; background: #3157a4; border: 0; border-radius: 8px; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.v2ops-tabs { display: flex; gap: 3px; padding: 0 18px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.v2ops-tabs button { padding: 11px 13px 9px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; font: inherit; cursor: pointer; white-space: nowrap; }
.v2ops-tabs button.active { color: var(--text); border-bottom-color: #3157a4; font-weight: 700; }
.v2ops-content { min-height: 0; overflow: auto; padding: 18px; background: var(--bg); }
.v2ops-page-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.v2ops-page-head h3 { margin: 0 0 4px; }
.v2ops-page-head p { margin: 0; color: var(--muted); font-size: 12px; }
.v2ops-form { display: flex; align-items: end; gap: 9px; margin-bottom: 16px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.v2ops-form-wide { align-items: stretch; flex-wrap: wrap; }
.v2ops-field { min-width: 150px; flex: 1; display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.v2ops-field input, .v2ops-field select, .v2ops-field textarea { width: 100%; min-width: 0; padding: 8px 9px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 7px; font: inherit; font-weight: 400; }
.v2ops-form button, .v2ops-action { padding: 7px 10px; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 7px; font: inherit; font-size: 12px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.v2ops-primary, .v2ops-action.primary { color: var(--accent-text) !important; background: var(--accent) !important; border-color: transparent !important; }
.v2ops-action.danger { color: #cf222e; }
.v2ops-action:disabled, .v2ops-form button:disabled { opacity: .5; cursor: wait; }
.v2ops-list { display: flex; flex-direction: column; gap: 8px; }
.v2ops-card { display: flex; align-items: center; gap: 14px; padding: 11px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; }
.v2ops-card-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.v2ops-card-main code, .v2ops-card-main small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.v2ops-card-actions { display: flex; justify-content: flex-end; gap: 5px; flex-wrap: wrap; }
.v2ops-inline { display: flex; align-items: center; gap: 8px; }
.v2ops-status { padding: 2px 7px; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: 999px; font-size: 10px; }
.v2ops-status.is-succeeded, .v2ops-status.is-published, .v2ops-status.is-approved, .v2ops-status.is-completed { color: #1a7f37; }
.v2ops-status.is-failed, .v2ops-status.is-rejected, .v2ops-status.is-cancelled { color: #cf222e; }
.v2ops-status.is-running, .v2ops-status.is-waiting-for-human, .v2ops-status.is-awaiting-approval { color: #9a6700; }
.v2ops-hint { color: var(--muted); font-size: 11px; }
.v2ops-check { display: flex; align-items: center; gap: 7px; padding: 7px 0; color: var(--text); font-size: 12px; }
.v2ops-check input { width: auto; }
.v2ops-checks { max-height: 110px; overflow: auto; padding: 7px; border: 1px solid var(--border); border-radius: 7px; }
.v2ops-checks label { display: block; margin: 3px 0; color: var(--text); font-size: 12px; font-weight: 400; }
.v2ops-checks input { width: auto; margin-right: 6px; }

@media (max-width: 760px) {
  #v2Ops { padding: 0; }
  .v2ops-shell { width: 100vw; height: 100%; border-radius: 0; }
  .v2ops-guide { align-items: flex-start; flex-direction: column; }
  .v2ops-form, .v2ops-card { align-items: stretch; flex-direction: column; }
  .v2ops-card-actions { justify-content: flex-start; }
}

@media (max-width: 1000px) {
  #wfV2Editor { padding: 0; }
  .wfv2-shell { width: 100vw; height: 100%; min-height: 0; border-radius: 0; grid-template-rows: auto minmax(0, 1fr) 180px; }
  .wfv2-header { align-items: flex-start; flex-direction: column; }
  .wfv2-title-block { width: 100%; grid-template-columns: auto 1fr; }
  #wfv2Description { grid-column: 1 / -1; }
  .wfv2-actions { width: 100%; justify-content: flex-start; }
  .wfv2-save-state { margin-left: auto; }
  .wfv2-workspace { grid-template-columns: 180px minmax(300px, 1fr); }
  .wfv2-properties { display: none; }
}

@media (max-width: 700px) {
  .wfv2-shell { grid-template-rows: auto minmax(0, 1fr) 170px; }
  .wfv2-title-block { display: flex; flex-wrap: wrap; }
  .wfv2-badge { display: none; }
  #wfv2Name, #wfv2Description { flex: 1 1 100%; }
  .wfv2-actions .wfv2-save-state, #wfv2Export, #wfv2AutoLayout { display: none; }
  .wfv2-workspace { grid-template-columns: 1fr; }
  .wfv2-toolbox { display: none; }
  .wfv2-canvas { padding: 14px; }
  .wfv2-canvas-head span { display: none; }
  .wfv2-test-row { grid-template-columns: 1fr; }
  .wfv2-tab-panel { height: 131px; }
}

#templateLibrary {
  position: fixed;
  inset: 0;
  z-index: 92;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text);
  background: rgba(5, 10, 18, .72);
}

#templateLibrary.show { display: flex; }

.tpl-shell {
  width: min(1120px, 96vw);
  max-height: min(850px, 94vh);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .4);
}

.tpl-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}

.tpl-header > div { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 7px 10px; }
.tpl-header h2 { margin: 0; font-size: 19px; }
.tpl-header p { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 12px; }
.tpl-header code { color: var(--text); }

.tpl-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); max-height: calc(94vh - 90px); }
.tpl-create, .tpl-list-wrap { min-height: 0; overflow-y: auto; padding: 18px; }
.tpl-create { display: flex; flex-direction: column; gap: 10px; border-right: 1px solid var(--border); }
.tpl-create h3, .tpl-list-head h3 { margin: 0; font-size: 14px; }
.tpl-help { margin: 0; padding: 10px; background: color-mix(in srgb, var(--accent) 10%, var(--bg)); border-radius: 8px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.tpl-help code { color: var(--text); font-weight: 700; }
.tpl-create label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 700; }
.tpl-create input, .tpl-create select, .tpl-create textarea {
  width: 100%;
  padding: 8px 9px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
}
.tpl-create textarea { resize: vertical; line-height: 1.45; }
.tpl-advanced { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.tpl-advanced > summary { padding: 9px 10px; cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 700; }
.tpl-advanced > div { display: flex; flex-direction: column; gap: 9px; padding: 0 10px 10px; }
.tpl-create > button, .tpl-card button {
  padding: 8px 10px;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.tpl-create > button:disabled { opacity: .55; cursor: wait; }
.tpl-status { min-height: 18px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.tpl-status.error { color: #cf222e; }
.tpl-status.ok { color: #1a7f37; }
.tpl-status.busy { color: var(--text); font-weight: 600; }
.tpl-status.busy::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: tpl-spin .8s linear infinite;
}
@keyframes tpl-spin { to { transform: rotate(360deg); } }
.tpl-list-wrap { display: flex; flex-direction: column; }
.tpl-list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.tpl-list-head > div { display: flex; align-items: baseline; gap: 7px; }
.tpl-list-head span { color: var(--muted); font-size: 11px; }
.tpl-list { display: flex; flex-direction: column; gap: 9px; }
.tpl-card { padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.tpl-card-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 8px; }
.tpl-card h4 { margin: 0 0 2px; font-size: 13px; }
.tpl-card-id { color: var(--muted); font: 10px ui-monospace, monospace; }
.tpl-card-status { padding: 3px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.tpl-card-status.draft { color: #9a6700; background: color-mix(in srgb, #d4a72c 18%, transparent); }
.tpl-card-status.published { color: #1a7f37; background: color-mix(in srgb, #2da44e 16%, transparent); }
.tpl-card-status.archived { color: var(--muted); background: var(--panel); }
.tpl-card-meta { margin-top: 8px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.tpl-field-title { margin-top: 9px; color: var(--text); font-size: 10px; font-weight: 700; }
.tpl-fields { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.tpl-field-chip { padding: 2px 6px; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 999px; font: 10px ui-monospace, monospace; }
.tpl-tech-details { margin-top: 8px; color: var(--muted); font-size: 10px; }
.tpl-tech-details > summary { cursor: pointer; font-weight: 700; }
.tpl-tech-details > div { margin: 6px 0; overflow-wrap: anywhere; font-family: ui-monospace, monospace; }
.tpl-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tpl-card .btn-2nd { padding: 6px 8px; }
.tpl-version-input { display: none; }
.tpl-update-guide { margin-top: 12px; padding: 12px; border: 2px solid color-mix(in srgb, var(--accent) 65%, var(--border)); border-radius: 10px; background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.tpl-update-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tpl-update-guide ol { display: grid; gap: 9px; margin: 10px 0 8px; padding: 0; list-style: none; }
.tpl-update-guide li { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.tpl-update-guide li span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.tpl-update-guide p { margin: 0; color: var(--muted); font-size: 10px; }

@media (max-width: 760px) {
  #templateLibrary { padding: 0; }
  .tpl-shell { width: 100vw; max-height: 100%; height: 100%; border-radius: 0; }
  .tpl-layout { grid-template-columns: 1fr; max-height: calc(100% - 90px); overflow-y: auto; }
  .tpl-create, .tpl-list-wrap { overflow: visible; }
  .tpl-create { border-right: 0; border-bottom: 1px solid var(--border); }
}

#skillLibrary {
  position: fixed;
  inset: 0;
  z-index: 92;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text);
  background: rgba(5, 10, 18, .72);
}

#skillLibrary.show { display: flex; }
/* 依內容決定高度、超出才封頂：避免短內容也把視窗撐到上下邊 */
#skillLibrary .tpl-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: min(850px, 92vh); }
#skillLibrary .tpl-layout { grid-template-columns: 460px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); max-height: none; min-height: 0; }
#skillLibrary .tpl-create, #skillLibrary .tpl-list-wrap { min-height: 0; max-height: 100%; overflow-y: auto; }
#skillLibrary .tpl-create textarea { font-family: ui-monospace, monospace; }
.skl-test-result {
  margin: 0;
  padding: 10px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}
.skl-refs { display: flex; flex-wrap: wrap; gap: 4px; }

@media (max-width: 760px) {
  #skillLibrary { padding: 0; }
  #skillLibrary .tpl-shell { width: 100vw; height: 100%; max-height: 100%; border-radius: 0; }
}

#botManager {
  position: fixed;
  inset: 0;
  z-index: 92;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text);
  background: rgba(5, 10, 18, .72);
}
#botManager.show { display: flex; }
#botManager .tpl-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: min(850px, 92vh); }
#botManager .tpl-layout { grid-template-columns: 420px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); max-height: none; min-height: 0; }
#botManager .tpl-create, #botManager .tpl-list-wrap { min-height: 0; max-height: 100%; overflow-y: auto; }
.bot-docs-label { font-size: 11px; font-weight: 700; color: var(--muted); }
/* 表單比面板高時，flex 子元素預設會被等比壓縮，帶 overflow 的檔案清單會被壓成半行高。
   讓所有欄位維持自然高度，由表單本身捲動。 */
#botManager .tpl-create > * { flex-shrink: 0; }
.bot-docs { display: flex; flex-direction: column; gap: 4px; min-height: 92px; max-height: 160px; overflow-y: auto; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
/* 覆蓋 .tpl-create label 的直排與 input 滿寬設定：勾選項要橫排、方塊不撐大 */
.bot-docs label { display: flex; flex-direction: row; align-items: center; gap: 7px; min-width: 0; padding: 2px 3px; font-size: 12px; font-weight: 400; cursor: pointer; border-radius: 6px; }
.bot-docs label:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
/* 已勾選的整列淡底＋加粗，一眼看得出哪些檔案會綁進機器人 */
.bot-docs label:has(> input:checked) { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
/* 不再依賴原生方塊外觀（會被 .tpl-create input 的樣式干擾、各瀏覽器處理也不一致）：
   直接關掉原生繪製自己畫，並用 #botDocs 提高優先序確保不被覆蓋。 */
#botDocs label > input[type="checkbox"],
.bot-docs label > input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; min-width: 24px; flex: 0 0 auto;
  margin: 0; padding: 0; cursor: pointer;
  display: grid; place-content: center;
  background: var(--panel);
  border: 2px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  border-radius: 6px;
  transition: background .12s, border-color .12s;
}
#botDocs label > input[type="checkbox"]::before,
.bot-docs label > input[type="checkbox"]::before {
  content: "✓"; font-size: 16px; font-weight: 800; line-height: 1;
  color: var(--accent-text); opacity: 0;
}
#botDocs label > input[type="checkbox"]:checked,
.bot-docs label > input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
#botDocs label > input[type="checkbox"]:checked::before,
.bot-docs label > input[type="checkbox"]:checked::before { opacity: 1; }
#botDocs label > input[type="checkbox"]:focus-visible,
.bot-docs label > input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.bot-docs label > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-docs .empty { color: var(--muted); font-size: 12px; padding: 4px; }
#botResult { margin-top: 10px; padding: 12px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border)); border-radius: 10px; background: var(--bg); font-size: 12px; }
#botResult .bot-url { font-family: ui-monospace, monospace; word-break: break-all; color: var(--text); background: var(--panel); padding: 6px 8px; border-radius: 6px; margin: 6px 0; }
#botResult button { margin: 4px 4px 0 0; }
#botResult textarea { width: 100%; margin-top: 6px; font-family: ui-monospace, monospace; font-size: 11px; }
.bot-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

@media (max-width: 760px) {
  #botManager { padding: 0; }
  #botManager .tpl-shell { width: 100vw; height: 100%; max-height: 100%; border-radius: 0; }
}

#botLogs {
  position: fixed;
  inset: 0;
  z-index: 93;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text);
  background: rgba(5, 10, 18, .78);
}
#botLogs.show { display: flex; }
#botLogs .tpl-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); width: min(1000px, 96vw); max-height: min(820px, 92vh); }
.bot-logs-body { min-height: 0; overflow-y: auto; padding: 16px 20px 22px; }
.bot-logs-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.bot-logs-toolbar label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.bot-logs-toolbar select { padding: 6px 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px; font-size: 12px; }
.bot-logs-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.bot-logs-stat { flex: 1 1 130px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.bot-logs-stat b { display: block; font-size: 21px; line-height: 1.3; }
.bot-logs-stat span { color: var(--muted); font-size: 11px; }
.bot-logs-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bot-logs-cols h4, .bot-logs-body > h4 { margin: 0 0 6px; font-size: 13px; }
.bot-logs-list { display: flex; flex-direction: column; gap: 4px; }
.bot-logs-row { display: flex; gap: 8px; align-items: baseline; padding: 6px 9px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }
.bot-logs-row span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.bot-logs-row b { color: var(--muted); font-size: 11px; white-space: nowrap; }
.bot-logs-detail { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 9px; }
.bot-logs-detail table { width: 100%; border-collapse: collapse; font-size: 12px; }
.bot-logs-detail th, .bot-logs-detail td { padding: 6px 9px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.bot-logs-detail th { position: sticky; top: 0; background: var(--panel); font-size: 11px; }
.bot-logs-detail td:nth-child(2) { overflow-wrap: anywhere; }
.bot-logs-miss { color: #cf222e; font-weight: 700; }

@media (max-width: 760px) {
  #botLogs { padding: 0; }
  #botLogs .tpl-shell { width: 100vw; height: 100%; border-radius: 0; }
  .bot-logs-cols { grid-template-columns: 1fr; }
}
