:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #dfe3e8;
  --text: #1f2933;
  --muted: #697586;
  --blue: #1f6feb;
  --blue-dark: #1758bd;
  --red: #b42318;
  --green: #067647;
  --amber: #a15c07;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Microsoft YaHei UI", "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef1f5;
}

.login-panel {
  width: min(400px, 100%);
  padding: 30px;
  border: 1px solid #d6dce4;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(17, 24, 39, 0.12);
}

.login-panel h1 { margin: 16px 0 2px; font-size: 22px; }
.login-panel p { margin: 0 0 22px; color: var(--muted); }
.login-panel label { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; }
.login-panel button { width: 100%; margin-top: 4px; background: var(--blue); color: #fff; border-color: var(--blue); }
.login-mark { width: 48px; height: 48px; }
.form-error { margin-top: 14px; color: var(--red); overflow-wrap: anywhere; }
.login-active > .sidebar,
.login-active > main { visibility: hidden; }

.sidebar {
  background: #111827;
  color: #e5e7eb;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f2c94c;
  color: #111827;
  font-weight: 800;
}

.brand h1, .brand p { margin: 0; }
.brand h1 { font-size: 18px; }
.brand p { color: #9ca3af; font-size: 12px; }

nav { display: grid; gap: 8px; }
.nav {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d1d5db;
  text-align: left;
  cursor: pointer;
}
.nav.active, .nav:hover {
  background: #243042;
  color: #fff;
  border-color: #374151;
}

.health {
  margin-top: auto;
  padding: 10px;
  border: 1px solid #374151;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 12px;
  word-break: break-word;
}

.current-user {
  display: grid;
  gap: 2px;
  padding-top: 14px;
  border-top: 1px solid #374151;
}
.current-user span { color: #9ca3af; font-size: 12px; }
.current-user button { margin-top: 8px; color: #d1d5db; background: #1f2937; border-color: #4b5563; }

main {
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  padding: 0 24px 24px;
  overflow: hidden;
}

.view { display: none; }
.view.active { display: block; padding-top: 20px; max-height: calc(100vh - 49px); overflow: auto; }

.workspace-tabs {
  height: 49px;
  display: flex;
  align-items: end;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.workspace-tab {
  flex: 0 0 auto;
  height: 38px;
  min-width: 120px;
  max-width: 240px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  background: #e9edf2;
}
.workspace-tab.active { background: #fff; border-color: #c8d0da; }
.workspace-tab-label,
.workspace-tab-close {
  height: 100%;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.workspace-tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.workspace-tab-close { padding: 0; color: var(--muted); font-size: 18px; }
.workspace-tab-close:hover { color: var(--red); background: #fee4e2; }
.workspace-empty { margin-top: 20px; padding: 60px; border: 1px dashed #c9d1db; text-align: center; color: var(--muted); }
.tab-context-menu {
  position: fixed;
  z-index: 90;
  min-width: 170px;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
}
.tab-context-menu button { width: 100%; border: 0; text-align: left; }
.tab-context-menu button:hover { background: #eef2f6; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: #b6c2cf; }
button[type="submit"], #initDb {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
button[type="submit"]:hover, #initDb:hover { background: var(--blue-dark); }
#resetWorkflow {
  border-color: #f79009;
  color: #93370d;
  background: #fffaeb;
}
#upgradeDefaultWorkflow {
  border-color: #067647;
  color: #075f34;
  background: #ecfdf3;
}
#restoreWorkflowSnapshot {
  border-color: #7f56d9;
  color: #53389e;
  background: #f4f3ff;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; font-size: 24px; margin-top: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 15px; }

.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }

.split {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
}

.list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: calc(100vh - 230px);
  overflow: auto;
}
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
}
.item:hover { border-color: #b6c2cf; }
.item h4 { margin: 0 0 4px; font-size: 14px; }
.item p { margin: 0; color: var(--muted); font-size: 12px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  padding: 2px 6px;
  border-radius: 6px;
  background: #eef2f6;
  color: #364152;
  font-size: 12px;
}
.badge.high { background: #fee4e2; color: var(--red); }
.badge.medium { background: #fef0c7; color: var(--amber); }
.badge.active { background: #dcfae6; color: var(--green); }

.editor {
  padding: 12px;
}
.editor .panel-head {
  margin: -12px -12px 12px;
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.editor > label,
.editor .grid2 > label,
.editor .grid3 > label,
.attachment-section > label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  color: #455468;
  font-size: 12px;
  font-weight: 600;
}
.editor input, .editor textarea, .editor .grid2 { margin-bottom: 10px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.check input { width: auto; margin: 0; }
.actions { display: flex; gap: 10px; }
.semantic-results {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.semantic-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fafbfc;
}
.semantic-result strong { display: block; margin-bottom: 4px; }
.semantic-result p { margin: 0; color: var(--muted); font-size: 12px; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
th { color: var(--muted); font-weight: 600; background: #fafbfc; }

.messages {
  display: grid;
  gap: 10px;
  padding: 12px;
  max-height: calc(100vh - 230px);
  overflow: auto;
}
.message {
  max-width: 78%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}
.message.agent { margin-left: auto; background: #eff6ff; }
.message.customer { margin-right: auto; background: #f8fafc; }
.message.system { margin-inline: auto; background: #f8fafc; }
.message .message-text { white-space: pre-wrap; }
.reception-turn { margin-top: 8px; font-size: 12px; color: var(--muted); }
.reception-turn summary { width: fit-content; cursor: pointer; color: #245484; font-size: 13px; font-weight: 600; padding: 4px 6px; border: 1px solid #c8d8e8; border-radius: 5px; background: #fff; }
.reception-turn summary:hover { background: #eef5ff; }
.reception-turn-body { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.reception-turn-body h4 { margin: 9px 0 4px; color: #243447; }
.reception-turn-body dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 9px; margin: 0; }
.reception-turn-body dd { margin: 0; white-space: pre-wrap; }
.reception-turn-body ul, .reception-turn-body ol { margin: 0; padding-left: 18px; }
.reception-turn-body dl + dl { margin-top: 8px; }
.message .meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }

.conversation-filters { flex-wrap: wrap; }
.conversation-filters select { flex: 1 1 180px; min-width: 0; }
.conversation-filters input { flex: 2 1 260px; min-width: 0; }
.conversation-filters button { flex: 0 0 auto; white-space: nowrap; }
.conversation-source { padding: 10px 14px; border-bottom: 1px solid var(--line); }
#conversationList .item, #messageList .message, .conversation-source { overflow-wrap: anywhere; }
#conversationList .item.selected { border-color: var(--blue); }

.case-table-panel { margin-bottom: 14px; }
.case-table-wrap { max-height: 44vh; }
.case-table { min-width: 2820px; font-size: 12px; }
.case-table th { position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.case-table td { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.case-table td.wide-cell { min-width: 240px; }
.case-table tr.selected td { background: #eaf2ff; }
.case-editor { margin: 0 auto; max-width: 1500px; }
.case-disposition { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(260px, .7fr) auto; gap: 12px; align-items: end; padding: 14px; border: 1px solid var(--line); border-left: 3px solid var(--blue); background: #f7f9fb; }
.case-disposition p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.case-disposition .muted { grid-column: 1 / -1; }
.edit-case { padding: 5px 10px; color: var(--blue-dark); }
.internal-fields { margin: 12px 0; border-top: 1px solid var(--line); padding-top: 12px; }
.internal-fields summary { margin-bottom: 12px; color: var(--muted); cursor: pointer; }

.attachment-section { margin: 12px 0; border-top: 1px solid var(--line); padding-top: 4px; }
.attachment-section .panel-head { padding-left: 0; padding-right: 0; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 8px; }
.message .media-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 160px)); }
.media-item { position: relative; display: grid; gap: 5px; min-width: 0; }
.media-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; }
.media-item span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.media-item > button { position: absolute; top: 5px; right: 5px; width: 28px; height: 28px; padding: 0; border-color: #fecaca; background: #fff; color: var(--red); font-size: 18px; }
.file-attachment { min-height: 90px; display: grid; place-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; }

.workflow-shell {
  display: grid;
  grid-template-columns: 190px minmax(620px, 1fr) 300px;
  gap: 10px;
  min-height: calc(100vh - 130px);
}

.workflow-library,
.workflow-inspector,
.workflow-canvas-wrap {
  min-height: calc(100vh - 130px);
}

.workflow-library {
  padding-bottom: 12px;
}

.panel-head.compact {
  margin-top: 10px;
  padding-top: 10px;
}

.node-template {
  width: calc(100% - 24px);
  margin: 10px 12px 0;
  text-align: left;
}

.library-note { margin: 12px; color: var(--muted); font-size: 12px; }

.workflow-versions {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: 45vh;
  overflow: auto;
}

.workflow-version {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  cursor: pointer;
}

.workflow-version strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.workflow-version span {
  color: var(--muted);
  font-size: 12px;
}

.workflow-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 110px auto auto auto;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.workflow-levels {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.workflow-level {
  min-height: 32px;
  padding: 5px 11px;
  border-color: transparent;
  background: transparent;
  color: #526170;
}
.workflow-level:hover { background: #eef2f6; }
.workflow-level.active { border-color: #9bb8dc; background: #eaf2fb; color: #174f87; font-weight: 700; }
.workflow-gesture-hint { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

.workflow-zoom {
  display: grid;
  grid-template-columns: 34px 48px 34px auto;
  align-items: center;
  gap: 4px;
}
.workflow-zoom button { height: 38px; padding: 6px 8px; }
.workflow-zoom output { text-align: center; color: var(--muted); font-size: 12px; }

.workflow-canvas {
  position: relative;
  height: calc(100vh - 255px);
  min-height: 520px;
  overflow: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(#eef2f6 1px, transparent 1px),
    linear-gradient(90deg, #eef2f6 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: default;
}
.workflow-canvas.panning { cursor: grabbing; user-select: none; }
.workflow-canvas.panning .wf-node { pointer-events: none; }
.workflow-layer-empty {
  position: sticky;
  left: 50%;
  top: 45%;
  z-index: 4;
  width: max-content;
  padding: 10px 14px;
  border: 1px dashed #b7c1cc;
  border-radius: 7px;
  background: rgba(255,255,255,.9);
  color: var(--muted);
  transform: translate(-50%, -50%);
}

.workflow-edges {
  position: absolute;
  inset: 0;
  width: 2400px;
  height: 2300px;
  z-index: 1;
  pointer-events: none;
}

.workflow-nodes {
  position: relative;
  z-index: 2;
  width: 2400px;
  height: 2300px;
}

.wf-node {
  position: absolute;
  width: 230px;
  height: 104px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  cursor: grab;
  user-select: none;
}

.wf-node.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.16), 0 8px 20px rgba(15, 23, 42, 0.08);
}

.wf-node:active { cursor: grabbing; }

.wf-node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.node-lock-mark {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 5px;
  background: #eef2f6;
  color: #526170;
  font-size: 10px;
  font-weight: 600;
}

.wf-node-body {
  padding: 8px 10px 10px;
  color: var(--muted);
  font-size: 12px;
  max-height: 56px;
  overflow: hidden;
}

.wf-port {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 1px #64748b;
  transform: translateY(-50%);
  z-index: 3;
}
.wf-port.input { left: -8px; }
.wf-port.output { right: -8px; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); cursor: crosshair; }
.workflow-canvas.connecting .wf-port.input { background: var(--green); box-shadow: 0 0 0 3px rgba(6, 118, 71, 0.18); }

.wf-edge-line {
  fill: none;
  stroke: #8795a7;
  stroke-width: 2;
}
.wf-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  pointer-events: stroke;
  cursor: pointer;
}
.wf-edge.selected .wf-edge-line { stroke: var(--blue); stroke-width: 3; }
.wf-edge.backward .wf-edge-line { stroke: #a7b1bf; stroke-dasharray: 6 5; }
.wf-edge:not(.selected) text { display: none; }
.wf-edge text {
  fill: #526170;
  font: 12px "Microsoft YaHei UI", sans-serif;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #f5f6f8;
  stroke-width: 4px;
  stroke-linejoin: round;
}
.wf-edge-line.preview { stroke: var(--blue); stroke-dasharray: 7 5; pointer-events: none; }
.wf-section-label {
  fill: #526170;
  font: 700 13px "Microsoft YaHei UI", sans-serif;
  letter-spacing: 0;
}
.wf-section-divider { stroke: #cfd6df; stroke-width: 1; stroke-dasharray: 5 5; }

.wf-pill {
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
}

.wf-pill.state { background: #e0f2fe; color: #075985; }
.wf-pill.router { background: #ede9fe; color: #5b21b6; }
.wf-pill.pre_sale { background: #dcfae6; color: #067647; }
.wf-pill.after_sale { background: #fee4e2; color: #b42318; }
.wf-pill.outcome { background: #e8f1ee; color: #176448; }
.wf-pill.tool { background: #fef0c7; color: #a15c07; }

.workflow-inspector {
  padding: 12px;
  max-height: calc(100vh - 130px);
  overflow: auto;
}

.workflow-inspector .panel-head {
  margin: -12px -12px 12px;
}

.workflow-inspector input,
.workflow-inspector textarea,
.workflow-inspector select {
  margin-bottom: 10px;
}

.workflow-inspector textarea {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.workflow-inspector form label,
#edgeEditor label,
.users-layout label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  color: #455468;
  font-size: 12px;
  font-weight: 600;
}

.workflow-inspector form textarea { font-family: inherit; font-size: 13px; }
.node-editor-summary { margin-bottom: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #f8fafc; }
.node-editor-summary p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.locked-badge, .editable-badge { margin-left: 6px; font-size: 11px; font-weight: 600; }
.locked-badge { color: var(--amber); }
.editable-badge { color: var(--green); }
.field-hint { display: block; color: var(--muted); font-weight: 400; line-height: 1.4; }
.workflow-validation { display: grid; gap: 7px; padding: 0 0 12px; }
.workflow-validation-summary { padding: 9px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; }
.workflow-validation-summary.valid { background: #e7f7ec; color: #176b35; }
.workflow-validation-summary.invalid { background: #fee4e2; color: #b42318; }
.workflow-validation-summary.warning { background: #fff3cf; color: #875d00; }
.workflow-validation-issue { padding: 8px 9px; border-left: 3px solid #d4a72c; background: #fffaf0; color: #526170; font-size: 12px; line-height: 1.45; }
.workflow-validation-issue.error { border-color: #d92d20; background: #fff1f0; color: #8f1f17; }
.option-field { min-width: 0; margin: 0 0 12px; padding: 9px; border: 1px solid var(--line); border-radius: 7px; }
.option-field legend { padding: 0 5px; color: #455468; font-size: 12px; font-weight: 600; }
.option-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.option-item { display: flex !important; align-items: flex-start; gap: 6px; margin: 0 !important; padding: 5px; border-radius: 5px; font-weight: 400 !important; }
.option-item:hover { background: #eef2f6; }
.option-item input { width: auto; margin: 2px 0 0 !important; }
.option-item span { min-width: 0; overflow-wrap: anywhere; }
.guide-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.guide-section { padding: 16px; }
.guide-section h3 { margin: 0 0 12px; }
.guide-section dt { margin-top: 9px; font-weight: 700; }
.guide-section dd { margin-left: 0; color: var(--muted); }
.guide-section li { margin-bottom: 8px; }
.guide-tools { grid-column: 1 / -1; overflow: auto; }
.empty-state { padding: 12px 0; color: var(--muted); }
.advanced-json { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.advanced-json summary { cursor: pointer; color: var(--muted); }
.advanced-json textarea { margin-top: 10px; }
.item.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.1); }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.62; }

.simulation-notice {
  margin-bottom: 12px;
  padding: 9px 12px;
  border-left: 4px solid var(--amber);
  background: #fff8e7;
  color: #6d4b08;
  font-size: 13px;
}
.simulation-shell {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(420px, 1fr) minmax(240px, 320px);
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.view.active#simulation {
  height: calc(100dvh - 73px);
  max-height: none;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}
#simulation > .page-head { margin-bottom: 12px; }
.simulation-shell > .panel { min-width: 0; min-height: 0; overflow: hidden; }
.simulation-config-panel,
.simulation-context-panel { padding: 12px; overflow-y: auto !important; }
.simulation-config-panel .panel-head,
.simulation-context-panel .panel-head { margin: -12px -12px 12px; }
.simulation-config-panel label,
.simulation-review label,
.simulation-fixture-item { display: grid; gap: 5px; }
.simulation-config-panel label,
.simulation-review label { margin-bottom: 9px; color: #455468; font-size: 12px; font-weight: 600; }
.form-section-title {
  margin: 14px 0 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: #1c2a3a;
  font-size: 12px;
  font-weight: 700;
}
.form-section-title:first-of-type { margin-top: 2px; padding-top: 0; border-top: 0; }
.compact-grid { gap: 8px; }
.compact-grid input,
.compact-grid select { min-width: 0; }
.simulation-chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.simulation-chat-panel > .panel-head { flex: 0 0 auto; margin: 0; }
.simulation-chat-panel .panel-head > div { min-width: 0; }
#simulationVersionText { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.simulation-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: #eff7ff;
  color: #15558d;
  font-size: 12px;
}
.simulation-progress[hidden] { display: none; }
.progress-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #a9cbee;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: simulation-spin .8s linear infinite;
}
@keyframes simulation-spin { to { transform: rotate(360deg); } }
.simulation-message-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background: #f5f7fa;
}
.simulation-messages {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scroll-padding-bottom: 20px;
  padding: 16px;
  background: #f5f7fa;
}
.simulation-message {
  width: min(74%, 720px);
  margin: 0 auto 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 1px 2px rgba(25, 40, 60, .06);
  overflow: hidden;
}
.simulation-message.customer { margin-right: 0; margin-left: auto; border-color: #b9d5f2; background: #eef7ff; }
.simulation-message.status { width: fit-content; max-width: 70%; border-style: dashed; background: #fff9e8; box-shadow: none; }
.simulation-message.status .message-meta { display: none; }
.simulation-message.status .message-body { padding: 9px 12px; color: #6b5314; }
.simulation-jump-latest {
  position: absolute;
  right: 18px;
  bottom: 14px;
  z-index: 3;
  border-color: #b8c9dd;
  background: #fff;
  color: #244a73;
  box-shadow: 0 5px 16px rgba(31, 55, 80, .16);
}
.message-meta { display: flex; justify-content: space-between; gap: 12px; padding: 8px 11px 0; color: var(--muted); font-size: 11px; }
.message-meta strong { color: #243447; }
.message-body { padding: 8px 11px 11px; color: #1f2937; line-height: 1.65; overflow-wrap: anywhere; }
.message-media { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 11px 11px; }
.message-media img { width: 88px; height: 88px; border: 1px solid var(--line); border-radius: 6px; object-fit: cover; }
.message-revision { display: grid; gap: 3px; padding: 9px 11px; border-top: 1px solid var(--line); background: #f1faf4; color: #254b32; font-size: 12px; }
.turn-details { border-top: 1px solid var(--line); background: #fbfcfe; }
.turn-details > summary { display: flex; justify-content: space-between; gap: 12px; padding: 9px 11px; cursor: pointer; color: #34455a; font-size: 12px; font-weight: 700; }
.turn-details > summary span { color: var(--muted); font-weight: 400; text-align: right; }
.turn-details > h5,
.turn-details > .trace-table,
.turn-details > .simulation-review,
.turn-detail-grid { margin-right: 11px; margin-left: 11px; }
.turn-details h5 { margin: 12px 0 7px; font-size: 12px; }
.turn-detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.turn-detail-grid section { min-width: 0; padding-top: 8px; border-top: 2px solid #cfdae7; }
.turn-detail-grid p { margin: 4px 0; color: #526170; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.trace-table { overflow: auto; border: 1px solid var(--line); }
.raw-trace { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.raw-trace summary { cursor: pointer; font-weight: 700; }
.raw-trace pre { margin: 8px 0 0; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.55 Consolas, monospace; color: var(--muted); }
.trace-table table { min-width: 620px; font-size: 11px; }
.trace-table th,
.trace-table td { padding: 6px 8px; vertical-align: top; }
.simulation-review { margin-top: 12px; padding: 10px 0 12px; border-top: 1px solid var(--line); }
.review-checks { display: flex; flex-wrap: wrap; gap: 5px 14px; margin: 8px 0; }
.review-checks label { display: flex; align-items: center; gap: 5px; margin: 0; font-weight: 400; }
.review-checks input { width: auto; }
.simulation-composer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: white;
  box-shadow: 0 -4px 12px rgba(25, 40, 60, .04);
}
.simulation-compose-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.simulation-composer textarea {
  flex: 1 1 auto;
  width: 100%;
  height: 44px;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  overflow-y: hidden;
  line-height: 1.55;
}
.composer-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.composer-actions button { white-space: nowrap; }
.composer-actions .primary-action {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.composer-actions .primary-action:hover { background: var(--blue-dark); }
.simulation-file-preview { display: flex; gap: 8px; max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.simulation-file-preview:empty { display: none; }
.simulation-file-preview > div { position: relative; flex: 0 0 72px; margin-bottom: 8px; }
.simulation-file-preview img { width: 72px; height: 60px; border: 1px solid var(--line); border-radius: 5px; object-fit: cover; }
.simulation-file-preview button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: rgba(25, 35, 45, .78); color: white; }
.simulation-file-preview span { display: block; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.simulation-run-notice { display: grid; gap: 3px; padding: 9px 11px; border-top: 1px solid var(--line); font-size: 12px; }
.simulation-run-notice.failed { background: #fff1f0; color: #8f1d18; }
.simulation-run-notice.blocked { background: #fff8e7; color: #6d4b08; }
.simulation-run-notice span { overflow-wrap: anywhere; }
.runtime-status { display: grid; gap: 8px; margin-bottom: 14px; }
.runtime-status > div { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 8px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-size: 12px; }
.runtime-status span { color: var(--muted); }
.runtime-status strong { overflow-wrap: anywhere; }
.runtime-status .ok { color: var(--green); }
.runtime-status .warn { color: var(--amber); }
.context-facts { margin: 0; }
.context-facts dt { margin-top: 12px; color: var(--muted); font-size: 11px; font-weight: 600; }
.context-facts dd { margin: 3px 0 0; color: #263548; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.risk { display: inline-block; padding: 2px 6px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.risk.low { background: #e7f7ec; color: #176b35; }
.risk.medium { background: #fff3cf; color: #875d00; }
.risk.high { background: #fee4e2; color: #b42318; }
.simulation-fixture-item { width: 100%; margin-bottom: 8px; text-align: left; }
.simulation-fixture-item h4,
.simulation-fixture-item p { margin: 0; }
.fixture-filter { margin: 10px; }

.settings-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.settings-tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; }
.settings-tab.active { border-bottom-color: var(--blue); color: var(--blue-dark); font-weight: 700; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-summary { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; padding: 12px 14px; }
.settings-summary span { color: var(--muted); font-size: 12px; }
.section-actions { display: flex; justify-content: flex-end; margin: 0 0 10px; }
.integration-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.integration-card { padding: 0; overflow: hidden; }
.integration-card form { display: grid; gap: 10px; padding: 14px; }
.integration-card .panel-head { padding: 12px 14px; }
.integration-card textarea { min-height: 112px; font-family: Consolas, monospace; font-size: 12px; }
.integration-config-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.integration-callback { grid-column: 1 / -1; display: grid; gap: 5px; padding: 10px; background: #f4f6f8; border: 1px solid var(--line); }
.integration-callback code { overflow-wrap: anywhere; font-size: 11px; }
.integration-callback small { color: var(--muted); }
.integration-health { padding: 3px 7px; border-radius: 5px; background: #eef2f6; color: var(--muted); font-size: 11px; }
.integration-health.enabled { background: #e7f7ec; color: #176b35; }
.secret-status { color: var(--muted); font-size: 11px; }
.settings-route-layout { display: grid; grid-template-columns: minmax(320px, .8fr) minmax(420px, 1.2fr); gap: 12px; }
.tool-status { display: inline-block; padding: 2px 6px; border-radius: 5px; background: #eef2f6; font-size: 11px; }
.tool-status.succeeded { background: #e7f7ec; color: #176b35; }
.tool-status.plugin_reported_success { background: #e8f5ee; color: #176b35; border: 1px solid #9dd8b0; }
.tool-status.failed, .tool-status.configuration_required, .tool-status.plugin_reported_failure,
.tool-status.expired, .tool-status.rejected { background: #fee4e2; color: #b42318; }
.tool-status.running, .tool-status.leased { background: #e0f2fe; color: #075985; }
.tool-status.awaiting_plugin, .tool-status.reconcile_required { background: #fff3cf; color: #875d00; }
.settings-inbox-panel, .settings-receipt-panel { margin-top: 12px; }
.plugin-device-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: end; gap: 10px; margin-bottom: 14px; }
.plugin-token-reveal { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; padding: 12px; margin-bottom: 14px; border: 1px solid #d4a72c; background: #fff8df; }
.plugin-token-reveal strong { grid-column: 1 / -1; }
.plugin-token-reveal textarea { min-height: 62px; font-family: Consolas, monospace; resize: vertical; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .workflow-shell { grid-template-columns: 1fr; }
  .workflow-library, .workflow-inspector, .workflow-canvas-wrap { min-height: auto; }
  .workflow-inspector { max-height: none; }
  .workflow-toolbar { grid-template-columns: 1fr 110px auto auto; }
  .workflow-zoom { grid-column: 1 / -1; width: max-content; }
  .guide-layout { grid-template-columns: 1fr; }
  .guide-tools { grid-column: auto; }
  .simulation-shell { grid-template-columns: minmax(220px, 260px) minmax(380px, 1fr) minmax(220px, 260px); }
  .turn-detail-grid { grid-template-columns: 1fr; }
  .settings-route-layout { grid-template-columns: 1fr; }
  .integration-config-grid { grid-template-columns: 1fr; }
  .plugin-device-form { grid-template-columns: 1fr 1fr; }
  .case-disposition { grid-template-columns: 1fr; }
  .case-disposition .muted { grid-column: auto; }
}

@media (max-width: 620px) {
  main { padding: 0 14px 14px; }
  .page-head { display: grid; }
  .head-actions { justify-content: flex-start; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .filters { flex-wrap: wrap; }
  .plugin-device-form, .plugin-token-reveal { grid-template-columns: 1fr; }
  .view.active#simulation { height: auto; min-height: calc(100dvh - 73px); display: block; overflow: auto; }
  .simulation-shell { height: auto; grid-template-columns: 1fr; overflow: visible; }
  .simulation-config-panel, .simulation-chat-panel, .simulation-context-panel { min-height: auto; }
  .simulation-chat-panel { height: min(72dvh, 680px); min-height: 480px; }
  .simulation-message { width: 90%; }
  .simulation-compose-row { align-items: stretch; flex-direction: column; }
  .composer-actions { justify-content: flex-end; }
}

.catalog-toolbar { gap: 12px; }
.catalog-toolbar input { width: min(100%, 380px); }
#catalogStatus:empty { display: none; }
#catalogRows td { vertical-align: top; }
#catalogRows td > div + div { margin-top: 5px; }
.catalog-image { width: 48px; height: 48px; object-fit: contain; border-radius: 4px; }
.catalog-current-image { width: 84px; height: 84px; object-fit: contain; }
.catalog-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100dvh - 32px); border: 1px solid #cbd5e1; border-radius: 10px; padding: 22px; }
.catalog-dialog::backdrop { background: rgb(15 23 42 / 46%); }
.catalog-fields, .catalog-child { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 12px; align-items: end; }
.catalog-fields label, .catalog-child label { display: grid; gap: 5px; }
.catalog-child { padding: 12px 0; border-top: 1px solid #e2e8f0; }
.catalog-details { margin-top: 18px; }
.catalog-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#catalogFormError { margin-top: 12px; }
