: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; overflow-wrap: anywhere; }
.message .media-item :is(audio, video) { max-width: 100%; }
.conversation-message-type { margin-block: 3px; font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.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; }
#simulationUseOrder { width: auto; }
.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); }
.simulation-capture-settings { margin: 0 0 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.simulation-capture-settings details { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.simulation-capture-settings summary { cursor: pointer; font-weight: 700; }
.simulation-capture-settings label { margin-top: 10px; }
.simulation-capture-settings .simulation-consulted-product { display: grid; gap: 6px; margin-top: 0; font-weight: 600; }
.simulation-capture-settings textarea { min-height: 130px; resize: vertical; font: 12px/1.5 monospace; }
.simulation-capture-settings p { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.simulation-capture-settings .head-actions { flex-wrap: wrap; }
.simulation-message-kind { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12px; }
.simulation-message-kind select { width: auto; padding: 4px 8px; }
.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; width: 72px; min-width: 0; 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-code-picker { display: grid; gap: 5px; min-width: 0; }
.catalog-code-picker small:empty { display: none; }
.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; }

#pendingReception button {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
}
#pendingReception .head-actions { align-items: center; }
#pendingReception #manualAfterSaleFollowUp { align-items: end; }


.notification-template-preview {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
}
#notificationTemplateVariables { flex-wrap: wrap; }
#notificationTemplateVariables button { min-height: 28px; padding: 4px 8px; }

/* Shared workspace and task layouts */
:root {
  --bg: #f2f5fa;
  --line: #dbe3ed;
  --text: #17283d;
  --muted: #506178;
  --blue: #235bc4;
  --blue-dark: #1d49a1;
  --panel-shadow: 0 1px 2px rgb(24 42 68 / 5%);
}

body {
  height: 100dvh;
  min-height: 0;
  grid-template-columns: 215px minmax(0, 1fr);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  overflow: hidden;
}

.sidebar {
  height: 100dvh;
  min-height: 0;
  padding: 21px 13px 15px;
  gap: 19px;
  background: #142139;
  border-right: 1px solid #273956;
}

.brand { padding-inline: 5px; gap: 10px; }
.brand-mark { flex: 0 0 35px; width: 35px; height: 35px; border-radius: 9px; background: #a7c6ff; color: #173260; }
.brand h1 { font-size: 15px; }
.brand p { color: #bbcadf; }
.sidebar-menu-toggle { display: none; }
.sidebar-content { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.admin-nav { display: grid; flex: 1 1 auto; min-height: 0; align-content: start; gap: 10px; overflow: auto; scrollbar-width: thin; }
.nav-group { display: grid; gap: 3px; padding: 0 2px; }
.nav-group > p { margin: 0 0 2px; padding: 2px 10px; color: #aabdd7; font-size: 11px; }
.nav { min-height: 36px; padding: 6px 11px; border-radius: 7px; font-size: 13px; }
.nav.active { background: #294770; border-color: #4a6a95; box-shadow: inset 3px 0 #a5c4ff; font-weight: 650; }
.nav:hover:not(.active) { background: #233650; border-color: #3d546f; }
.health { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; margin-top: 0; padding: 7px 9px; }
.health::before { flex: 0 0 7px; width: 7px; height: 7px; content: ""; background: #a9b8cd; border-radius: 50%; }
.health[data-state="online"]::before { background: #6ed4ad; }
.health[data-state="offline"]::before { background: #ffab96; }
.current-user { flex: 0 0 auto; padding: 9px 4px 0; }
.current-user button { margin-top: 5px; padding: 5px 8px; }

main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  padding: 0 clamp(13px, 2vw, 27px) 16px;
}

.workspace-tabs { flex: 0 0 48px; gap: 5px; scrollbar-width: thin; }
.workspace-tab { min-width: 105px; max-width: 210px; height: 35px; border-radius: 8px 8px 0 0; background: #e7edf7; }
.workspace-tab.active { background: #fff; border-color: #c6d5ef; box-shadow: inset 0 2px #3e72d9; }
.workspace-tab.active .workspace-tab-label { color: var(--blue-dark); font-weight: 650; }
.workspace-tab-close:hover { background: #e5edf9; }
.view.active { flex: 1 1 auto; min-height: 0; max-height: none; padding: 21px 2px 9px; overflow: auto; scrollbar-width: thin; }
.view.active#simulation { height: auto; }
.page-head { align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 17px; }
.page-head h2 { font-size: clamp(21px, 2.2vw, 29px); letter-spacing: -.025em; line-height: 1.25; }
.page-head p { margin-top: 5px; }
.page-head > :first-child { min-width: 0; }
.head-actions { gap: 7px; align-items: center; }
.head-actions button, .filters button, .settings-tab, .workflow-toolbar button { white-space: nowrap; }

button, .action-link, .advanced-actions > summary {
  min-height: 34px;
  font: inherit;
}
button:disabled { cursor: not-allowed; opacity: .58; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #3971db;
  outline-offset: 2px;
}
.action-link, .advanced-actions > summary {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  background: var(--panel);
  color: var(--blue-dark);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.action-link:hover, .advanced-actions > summary:hover { border-color: #9bb4df; }
.button-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.button-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.advanced-actions { position: relative; }
.advanced-actions-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  z-index: 10;
  display: grid;
  gap: 5px;
  padding: 8px;
  min-width: max-content;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  box-shadow: 0 7px 25px rgb(24 42 68 / 15%);
}
.advanced-actions-menu button { text-align: left; }

.panel { border-radius: 11px; box-shadow: var(--panel-shadow); }
.panel-head { gap: 9px; flex-wrap: wrap; }
.panel-head > span { color: var(--muted); font-size: 12px; }
.filters, .search-toolbar { flex-wrap: wrap; align-items: center; gap: 8px; }
.search-toolbar {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  background: var(--panel);
}
.search-toolbar input { flex: 3 1 220px; min-width: 0; }
.search-toolbar select { flex: 1 1 112px; min-width: 0; }
.search-toolbar button { flex: 0 0 auto; }
input, select, textarea { min-width: 0; color: var(--text); }
input[readonly], textarea[readonly] { background: #f5f8fc; }
textarea { line-height: 1.6; }
.editor > label, .editor .grid2 > label, .editor .grid3 > label { font-weight: 550; }

.empty-state { margin: 0; padding: 16px; color: var(--muted); line-height: 1.55; }
.state-error { color: var(--red); }
.metrics { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.metric { min-width: 0; text-align: left; box-shadow: var(--panel-shadow); }
.metric span { color: var(--muted); }
.metric strong { font-variant-numeric: tabular-nums; font-size: 28px; }
button.metric:hover { border-color: #6e97e4; background: #f7fbff; }
.metric-warning strong { color: var(--amber); }
td, th { overflow-wrap: normal; }
.table-wrap { scrollbar-width: thin; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }

.case-table-wrap { max-height: min(62vh, 665px); }
.case-table { min-width: 730px; font-size: 13px; }
.case-table td { max-width: none; white-space: normal; overflow: visible; text-overflow: clip; cursor: auto; vertical-align: middle; }
.case-table td:first-child { min-width: 184px; }
.case-order { font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.case-meta { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
.case-status { display: inline-block; padding: 3px 8px; border-radius: 999px; background: #eaf1fc; color: #254c86; white-space: nowrap; }
.case-status.urgent { background: #ffebe8; color: #a23525; }
.case-status.done { background: #e6f7ed; color: #19603b; }
.case-issue { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 9em; overflow-wrap: anywhere; }
.case-date, .case-action button { white-space: nowrap; }
.case-action button { min-height: 32px; }
.panel-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 9px 12px; border-top: 1px solid var(--line); }

.split { grid-template-columns: minmax(220px, .7fr) minmax(0, 1.4fr); align-items: start; }
.selectable-item { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; text-align: left; gap: 6px; }
.selectable-item.selected { border-color: #739aec; background: #f2f7ff; }
.item-title { color: var(--text); overflow-wrap: anywhere; }
.item-description { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.conversation-order { font-size: 12px; color: #314867; font-variant-numeric: tabular-nums; }
.conversation-list-back { display: none; }
.conversation-split { grid-template-columns: minmax(220px, .65fr) minmax(0, 1.45fr); }
#conversationList, #messageList { min-height: 126px; max-height: calc(100dvh - 252px); align-content: start; }
#messageList { background: #fafcff; }
.message { max-width: min(86%, 660px); }
.reception-insights { border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.reception-insights > summary { padding: 8px 11px; color: var(--blue-dark); cursor: pointer; }
.reception-insight-body { padding: 0 12px 12px; }
.reception-insight-body h3 { margin: 5px 0; font-size: 14px; }
.reception-turn[open] { min-width: 0; }
.reception-turn dd, .reception-turn li { overflow-wrap: anywhere; }

.pending-section { margin-bottom: 12px; }
#pendingReception .table-wrap, #afterSaleResultFollowUpList .table-wrap { max-height: 38vh; }
#pendingReception th { position: sticky; top: 0; z-index: 1; white-space: nowrap; }
#pendingReception .wide-cell { min-width: 13em; }
#manualAfterSaleFollowUp { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); }
#manualAfterSaleFollowUp label { display: grid; gap: 4px; flex: 0 1 260px; }
#manualAfterSaleFollowUp button { white-space: nowrap; }

.semantic-tools, .maintenance-panel { margin-bottom: 12px; padding: 10px 13px; }
.semantic-tools > summary, .maintenance-panel > summary { cursor: pointer; color: var(--blue-dark); font-weight: 600; }
.semantic-tools .search-toolbar { border: 0; padding: 9px 0 0; margin: 0; }
.maintenance-panel { margin-top: 12px; }
.maintenance-panel .actions { margin-top: 10px; }

.workflow-shell { grid-template-columns: minmax(120px, .65fr) minmax(0, 3fr) minmax(181px, 1fr); min-height: 0; }
.workflow-library, .workflow-inspector, .workflow-canvas-wrap { min-width: 0; min-height: 0; }
.workflow-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 9px; }
.workflow-toolbar input { flex: 1 1 150px; }
.workflow-toolbar select { flex: 0 1 92px; width: auto; }
.workflow-toolbar .workflow-zoom { display: flex; flex-wrap: wrap; max-width: 100%; }
.workflow-toolbar button { padding-inline: 7px; }
.workflow-levels { flex-wrap: wrap; padding-inline: 8px; }
.workflow-gesture-hint { margin-left: 0; }
.workflow-canvas { min-height: 370px; }
.workflow-inspector, .workflow-library { max-height: min(700px, 72vh); overflow: auto; }

.simulation-shell { grid-template-columns: minmax(180px, .8fr) minmax(300px, 1.65fr) minmax(190px, .85fr); }
.settings-tabs { flex-wrap: wrap; }
.settings-tab { min-height: 38px; }
.settings-route-layout { grid-template-columns: minmax(245px, .8fr) minmax(0, 1.2fr); }
.integration-grid { grid-template-columns: repeat(auto-fit, minmax(min(310px, 100%), 1fr)); }
.template-workspace { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.template-workspace > div { min-width: 0; }
.template-workspace label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; }
#notificationTemplateBody { min-height: 224px; margin-bottom: 5px; font-weight: 400; }
.template-preview { min-width: 0; }
.template-preview-heading { display: flex; gap: 8px; justify-content: space-between; align-items: center; min-height: 31px; margin-bottom: 5px; }
.template-preview-heading h4 { margin: 0; }
.template-preview-heading button { min-height: 29px; padding-block: 3px; }
.notification-template-preview { min-height: 224px; background: #f7faff; }
.template-editor-actions { margin-top: 14px; }

.workspace-feedback {
  position: fixed;
  right: clamp(10px, 2vw, 24px);
  bottom: 18px;
  z-index: 60;
  display: flex;
  align-items: start;
  gap: 12px;
  max-width: min(520px, calc(100% - 20px));
  padding: 10px 12px;
  border: 1px solid #a7bce4;
  border-radius: 8px;
  box-shadow: 0 6px 22px rgb(24 42 68 / 18%);
  background: #f5f9ff;
  color: #1e3f6b;
}
.workspace-feedback span { max-height: 180px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.workspace-feedback button { min-height: 28px; padding: 3px 8px; white-space: nowrap; }
.workspace-feedback.feedback-error { color: #8f2d24; border-color: #efb5ae; background: #fff7f5; }
.skip-link { position: fixed; top: 5px; left: 5px; z-index: 120; padding: 8px; background: white; transform: translateY(-130%); }
.skip-link:focus { transform: none; }

@media (max-width: 1080px) {
  .workflow-shell { grid-template-columns: minmax(0, 1fr) minmax(180px, 230px); }
  .workflow-library { grid-column: 1 / -1; max-height: 180px; }
  .workflow-library:has(.workflow-versions:empty) { max-height: 130px; }
  .view.active#simulation { display: block; overflow: auto; }
  .simulation-shell { height: auto; grid-template-columns: minmax(210px, .75fr) minmax(0, 1.4fr); overflow: visible; }
  .simulation-chat-panel { height: min(72dvh, 680px); min-height: 410px; }
  .simulation-config-panel { max-height: min(72dvh, 680px); }
  .simulation-context-panel { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0,1fr); }
  .sidebar { height: auto; min-height: 0; display: flex; flex-direction: row; justify-content: space-between; align-items: center; padding: 8px 12px; z-index: 30; }
  .sidebar-menu-toggle { display: inline-flex; align-items: center; min-height: 34px; color: #e3edff; border-color: #4a6388; background: #243b5c; }
  .sidebar-content { display: none; position: absolute; top: 100%; left: 0; width: min(330px, 100vw); max-height: 84dvh; padding: 11px 12px; background: #142139; box-shadow: 0 12px 30px rgb(15 30 55 / 25%); border-radius: 0 0 11px 0; }
  .sidebar { position: relative; }
  .sidebar.menu-open .sidebar-content { display: flex; }
  main { height: auto; min-height: 0; padding-inline: 11px; }
  .view.active { padding-top: 14px; }
  .workspace-tabs { flex-basis: 42px; }
  .split, .conversation-split, .settings-route-layout { grid-template-columns: minmax(0, 1fr); }
  .conversation-list-back { display: inline-flex; }
  #conversationList { max-height: 34vh; }
  #messageList { max-height: min(64vh, 680px); }
  .template-workspace { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 620px) {
  .workspace-tab { min-width: 88px; max-width: 136px; }
  .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .page-head { gap: 8px; }
  .head-actions { justify-content: flex-start; }
  .case-table-wrap { max-height: none; overflow: visible; }
  .case-table { min-width: 0; }
  .case-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .case-table, .case-table tbody { display: block; }
  .case-table tr { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
  .case-table tr:last-child { border-bottom: 0; }
  .case-table td, .case-table td:first-child { display: block; min-width: 0; border-bottom: 0; padding: 1px 0; }
  .case-table td[data-label]:not(:first-child)::before { display: block; margin-bottom: 2px; color: var(--muted); font-size: 11px; content: attr(data-label); }
  .case-table td:first-child, .case-table td[data-label="顾客问题"], .case-table .case-empty td { grid-column: 1 / -1; }
  .case-table .case-action { justify-self: end; align-self: end; }
  .case-issue { min-width: 0; }
  .workflow-shell, .simulation-shell { grid-template-columns: minmax(0,1fr); }
  .workflow-canvas { height: 52vh; min-height: 300px; }
  .workflow-library, .workflow-inspector { max-height: none; }
  .simulation-config-panel { max-height: none; }
  .simulation-chat-panel { height: min(70dvh, 650px); min-height: 390px; }
  .advanced-actions-menu { right: auto; left: 0; max-width: 85vw; }
}
@media (prefers-reduced-motion: reduce) {
  .progress-spinner { animation-duration: 2s; }
}

.conversation-search-actions { display: flex; align-items: center; gap: 8px; }
#conversationBackfillDivider { color: var(--muted); }
#conversationBackfillDialog {
  width: min(450px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  color: var(--text);
  background: var(--panel);
}
#conversationBackfillDialog::backdrop { background: rgb(15 23 42 / 38%); }
#conversationBackfillDialog h3 { margin-top: 0; }
#conversationBackfillLookupStatus { margin: 12px 0 4px; }

.conversation-review-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  color: var(--text);
  background: var(--panel);
}
.conversation-review-dialog::backdrop { background: rgb(15 23 42 / 38%); }
#conversationReviewReports details { margin-top: 16px; }
#conversationReviewReports li { margin-bottom: 8px; }
#conversationReviewReports select { margin-inline: 8px; }

.message-review-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.message-review-actions label { display: inline-flex; align-items: center; gap: 4px; }
.message-review-actions input { width: auto; }

.archive-image-previews { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 6px; }
.archive-image-preview { display: inline-block; max-width: 100%; }
.archive-image-preview img:not([hidden]) { display: block; max-width: min(240px, 100%); max-height: 200px; object-fit: contain; border-radius: 6px; }

@media (min-width: 821px) {
  #conversations .conversation-list-panel {
    position: sticky;
    top: 8px;
    align-self: start;
  }
  #conversations #messageList {
    max-height: none;
    overflow: visible;
  }
}

/* Collapsible desktop navigation. */
.sidebar-group-items { display: grid; gap: 3px; min-width: 0; }
.sidebar-group-items > p { margin: 0 0 2px; padding: 2px 10px; color: #aabdd7; font-size: 11px; }
.sidebar-rail-toggle, .sidebar-group-trigger { display: none; }
@media (min-width: 821px) {
  body.sidebar-rail-layout { grid-template-columns: 60px minmax(0, 1fr); }
  .sidebar:has(.sidebar-rail-toggle) { position: relative; }
  .sidebar:has(.sidebar-rail-toggle) .brand { padding-right: 23px; }
  .sidebar-rail-toggle, .sidebar-group-trigger {
    place-items: center;
    padding: 0;
    color: #c5d5ee;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
  }
  .sidebar-rail-toggle { display: grid; position: absolute; top: 24px; right: 9px; width: 27px; height: 29px; }
  .sidebar-rail-toggle svg { width: 16px; height: 16px; }
  .sidebar-group-trigger svg { width: 20px; height: 20px; }
  .sidebar-rail-toggle:hover, .sidebar-group-trigger:hover, .sidebar-group-trigger[aria-expanded="true"] { background: #233650; }
  .sidebar-rail-toggle:focus-visible, .sidebar-group-trigger:focus-visible { outline: 2px solid #a5c4ff; outline-offset: -2px; }
  .sidebar.is-rail { padding: 16px 7px 13px; gap: 9px; }
  .sidebar.is-rail .brand { justify-content: center; padding: 0; }
  .sidebar.is-rail .brand > :not(.brand-mark) { display: none; }
  .sidebar.is-rail .sidebar-rail-toggle { position: static; align-self: center; width: 38px; height: 32px; }
  .sidebar.is-rail .sidebar-rail-toggle svg { transform: scaleX(-1); }
  .sidebar.is-rail .nav-group { padding: 0 1px; }
  .sidebar.is-rail .sidebar-group-trigger { display: grid; width: 100%; min-height: 42px; }
  .sidebar-group-trigger.is-selected { background: #294770; color: #fff; border-color: #4a6a95; }
  .sidebar.is-rail .sidebar-group-items:not(:popover-open) { display: none; }
  .sidebar-group-items:popover-open {
    position: fixed;
    inset: auto;
    margin: 0;
    width: 192px;
    max-height: calc(100dvh - 16px);
    padding: 8px;
    overflow: auto;
    border: 1px solid #425879;
    border-radius: 9px;
    background: #142139;
    box-shadow: 0 10px 24px rgb(15 30 55 / 25%);
  }
  .sidebar.is-rail .health { justify-content: center; font-size: 0; padding: 8px 0; }
  .sidebar.is-rail .current-user { padding: 6px 0 0; }
  .sidebar.is-rail .current-user strong, .sidebar.is-rail .current-user span { display: none; }
  .sidebar.is-rail #logoutButton { display: grid; place-items: center; width: 100%; height: 36px; padding: 0; }
  .sidebar.is-rail #logoutButton .sidebar-logout-label { display: none; }
  .sidebar.is-rail #logoutButton svg { display: block; width: 18px; height: 18px; }
  .admin-nav:has(.sidebar-selection-marker) { position: relative; }
  .admin-nav:has(.sidebar-selection-marker) .nav.active:not(:popover-open *) { box-shadow: none; }
  .sidebar-selection-marker {
    position: absolute;
    top: 0;
    left: 2px;
    width: 3px;
    height: 20px;
    border-radius: 3px;
    background: #a5c4ff;
    z-index: 1;
    pointer-events: none;
    transform: translateY(var(--marker-top, 0px));
    transition: transform 160ms ease-out;
  }
}
@media (max-width: 820px) { .sidebar-selection-marker { display: none; } }
@media (prefers-reduced-motion: reduce) { .sidebar-selection-marker { transition: none; } }

/* Sidebar disclosures. */
.sidebar-group-items { gap: 0; }
.sidebar-group-heading {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr) 13px;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #c4d3e9;
  background: transparent;
  text-align: left;
  font-size: 12px;
}
.sidebar-group-heading:hover { color: #fff; background: #233650; }
.sidebar-group-heading:focus-visible { outline: 2px solid #a5c4ff; outline-offset: -2px; }
.sidebar-group-heading svg { width: 100%; }
.sidebar-group-heading svg:last-child { transition: transform 160ms ease-out; }
.sidebar-group-heading[aria-expanded="false"] svg:last-child { transform: rotate(-90deg); }
.sidebar-group-list { display: grid; grid-template-rows: 1fr; opacity: 1; transition: grid-template-rows 180ms ease, opacity 150ms ease; }
.sidebar-group-list.is-folded { grid-template-rows: 0fr; opacity: 0; }
.sidebar-group-list > div { display: grid; min-height: 0; overflow: hidden; gap: 3px; }
.sidebar-group-list .nav:focus-visible { outline-offset: -2px; }
.sidebar-group-items > .sidebar-flyout-title { display: none; }
.admin-nav .sidebar-group-heading + p + .sidebar-group-list .nav { padding-inline-start: 18px; }

@media (min-width: 821px) {
  body.sidebar-motion-ready { transition: grid-template-columns 210ms ease; }
  .sidebar.is-rail .sidebar-group-heading { display: none; }
  .sidebar.is-rail .sidebar-flyout-title { display: block; }
  .sidebar.is-rail .sidebar-group-items:popover-open {
    animation: sidebar-flyout-in 160ms ease-out both;
  }
  .sidebar.is-rail .sidebar-group-items .sidebar-group-list .nav { padding-inline-start: 10px; }
  .sidebar .brand { min-width: 0; white-space: nowrap; }
  .sidebar .brand > div:last-child { min-width: 0; overflow: hidden; }
}
@keyframes sidebar-flyout-in {
  from { opacity: 0; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  body.sidebar-motion-ready, .sidebar-group-list, .sidebar-group-heading svg:last-child { transition: none; }
  .sidebar.is-rail .sidebar-group-items:popover-open { animation: none; }
}

#logoutButton svg { display: none; }
#logoutButton .sidebar-logout-label { display: inline; color: inherit; font: inherit; }
