:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e0ea;
  --line-strong: #b9c4d4;
  --text: #172033;
  --muted: #667085;
  --subtle: #8a95a8;
  --primary: #1957d2;
  --primary-soft: #e8efff;
  --green: #0f7b49;
  --green-soft: #e8f6ef;
  --red: #ba2c2c;
  --red-soft: #fff0f0;
  --amber: #9a6100;
  --amber-soft: #fff7df;
  --shadow: 0 14px 34px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 88px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.25;
}

.topStats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.statPill,
.tag,
.versionBadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.statPill strong {
  color: var(--text);
}

.appShell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 18px;
  width: min(1480px, calc(100vw - 32px));
  margin: 18px auto 34px;
}

.sidebar,
.workspace,
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 106px;
  align-self: start;
  max-height: calc(100vh - 124px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebarTools {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.fieldLabel {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.textInput,
.textArea,
.selectInput {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.textInput,
.selectInput {
  padding: 0 12px;
}

.textArea {
  min-height: 86px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.55;
}

.textInput:focus,
.textArea:focus,
.selectInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.sidebarTools .textInput + .fieldLabel {
  margin-top: 14px;
}

.sceneList {
  overflow: auto;
  padding: 10px;
}

.sceneCard {
  width: 100%;
  margin: 0 0 8px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.sceneCard:hover {
  background: var(--panel-soft);
  border-color: var(--line);
}

.sceneCard.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.sceneMeta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.sceneTitle {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
}

.workspace {
  min-height: calc(100vh - 124px);
  padding: 20px;
}

.emptyState {
  display: grid;
  min-height: 360px;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.workspaceHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.workspaceHeader h2 {
  margin-bottom: 8px;
  font-size: 26px;
  line-height: 1.25;
}

.summaryText {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.actionBar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button,
.ghostButton,
.dangerButton,
.smallButton {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.button {
  background: var(--primary);
  color: #fff;
}

.ghostButton,
.smallButton {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
}

.dangerButton {
  border-color: #f4b4b4;
  background: var(--red-soft);
  color: var(--red);
}

.smallButton {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.button:disabled,
.ghostButton:disabled,
.dangerButton:disabled,
.smallButton:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.branchSection {
  margin-bottom: 12px;
}

.branchLabel {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.routeTabs {
  display: flex;
  gap: 8px;
  overflow: auto;
  padding-bottom: 8px;
}

.routeTab {
  flex: 0 0 auto;
  max-width: 320px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.routeTab.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.routeInfoGrid {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr 0.7fr;
  gap: 10px;
  margin-bottom: 16px;
}

.infoBox {
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.infoBox span {
  display: block;
  margin-bottom: 6px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 800;
}

.infoBox strong {
  display: block;
  font-size: 14px;
  line-height: 1.45;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 16px;
}

.panel h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.versionList {
  display: grid;
  gap: 8px;
}

.versionItem {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.versionItem.active {
  border-color: var(--green);
  background: var(--green-soft);
}

.versionItem.viewingOld {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.versionItem strong,
.versionItem span {
  display: block;
}

.versionItem span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.historyBanner {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #e8c268;
  border-radius: 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 800;
}

.nodeFlow {
  display: grid;
  gap: 12px;
}

.nodeCard,
.nodeEditor {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.nodeCard {
  padding: 16px;
}

.nodeHeader {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.nodeHeaderActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nodeNo {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 900;
}

.nodeHeader h4 {
  margin-bottom: 4px;
  font-size: 17px;
}

.nodeHeader p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.nodeGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.nodeField {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.nodeField span {
  display: block;
  margin-bottom: 7px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 900;
}

.nodeField p {
  margin-bottom: 0;
  color: var(--text);
  line-height: 1.6;
}

.nodeField.full {
  grid-column: 1 / -1;
}

.selectionLine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag.primary {
  border-color: #b6c9ff;
  background: var(--primary-soft);
  color: var(--primary);
}

.tag.green {
  border-color: #b7dfc9;
  background: var(--green-soft);
  color: var(--green);
}

.tag.warning {
  border-color: #f0d99a;
  background: var(--amber-soft);
  color: var(--amber);
}

.editorToolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.nodeEditor {
  padding: 14px;
}

.nodeEditor + .nodeEditor {
  margin-top: 12px;
}

.editorHead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 12px;
  align-items: start;
}

.nodeActions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.formGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.formGrid .wide {
  grid-column: 1 / -1;
}

.choicePanel {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.permissionSection {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.permissionSection summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 12px;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.permissionSection summary::-webkit-details-marker {
  display: none;
}

.permissionSection summary::after {
  content: "展开";
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.permissionSection[open] summary::after {
  content: "收起";
}

.permissionSection summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.permissionBody {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.roleEmptyHint {
  margin: 0;
  padding: 8px;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.choiceGroup {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.choiceGroup strong {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
}

.checkLine {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin: 0 8px 6px 0;
  color: var(--text);
  font-size: 13px;
}

.checkLine input {
  width: 16px;
  height: 16px;
}

.auditList {
  display: grid;
  gap: 8px;
}

.auditItem {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.auditItem strong {
  display: block;
  font-size: 13px;
  line-height: 1.45;
}

.auditItem span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.38);
}

.modalPanel {
  width: min(1360px, calc(100vw - 48px));
  max-height: calc(100vh - 64px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.modalHeader {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modalHeader h3 {
  margin-bottom: 0;
}

.flowchartCanvas {
  min-height: 520px;
  max-height: calc(100vh - 190px);
  padding: 18px;
  overflow: auto;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.flowchartCanvas svg {
  display: block;
  width: max(1360px, 100%);
  min-width: 1360px;
  height: auto;
  margin: 0;
}

.flowchartCanvas svg .nodeLabel,
.flowchartCanvas svg .edgeLabel,
.flowchartCanvas svg .label {
  font-size: 13px !important;
  line-height: 1.35 !important;
}

.flowchartLoading,
.flowchartError {
  display: grid;
  min-height: 320px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  font-weight: 800;
}

.flowchartError {
  color: var(--red);
  background: var(--red-soft);
}

.mermaidSource {
  border-top: 1px solid var(--line);
}

.mermaidSource summary {
  min-height: 44px;
  padding: 12px 16px;
  color: var(--primary);
  font-weight: 900;
  cursor: pointer;
}

.mermaidCode {
  max-height: calc(100vh - 180px);
  margin: 0;
  overflow: auto;
  padding: 16px;
  background: #0f172a;
  color: #e5e7eb;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
}

@media (max-width: 1100px) {
  .appShell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: 420px;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .routeInfoGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .topStats {
    justify-content: flex-start;
  }

  .appShell {
    width: calc(100vw - 20px);
    margin-top: 10px;
  }

  .workspace {
    padding: 14px;
  }

  .workspaceHeader,
  .editorToolbar,
  .formGrid,
  .nodeGrid,
  .routeInfoGrid {
    grid-template-columns: 1fr;
  }

  .actionBar,
  .nodeActions {
    justify-content: flex-start;
  }

  .nodeHeader {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .nodeHeaderActions {
    grid-column: 1 / -1;
    justify-self: start;
    justify-content: flex-start;
  }
}
