:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #1f252d;
  --muted: #66717f;
  --line: #d8dee6;
  --blue: #1264a3;
  --green: #1f7a56;
  --red: #b33b32;
  --amber: #9b5b06;
  --violet: #6d5bd0;
  --teal: #147d86;
  --shadow: 0 16px 42px rgba(22, 31, 43, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 1180px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 14px;
}

.subhead {
  max-width: 760px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-actions a {
  min-height: 36px;
  padding: 8px 12px;
  color: var(--blue);
  background: #fff;
  border: 1px solid #bfd0df;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.map-shell {
  display: grid;
  grid-template-columns: 270px minmax(620px, 1fr) 360px;
  gap: 18px;
  padding: 18px;
}

.panel,
.workspace,
.inspector {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.left-rail,
.inspector {
  position: sticky;
  top: 96px;
  height: calc(100vh - 114px);
  overflow: auto;
}

.panel {
  padding: 16px;
}

.panel + .panel {
  margin-top: 14px;
}

.compact h2,
.panel h2 {
  margin-bottom: 12px;
}

.perspective-list,
.stage-list {
  display: grid;
  gap: 8px;
}

.perspective-button,
.tree-button {
  position: relative;
  display: grid;
  width: 100%;
  gap: 3px;
  min-height: 72px;
  padding: 11px 42px 11px 12px;
  color: var(--text);
  text-align: left;
  background: #fff;
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  cursor: pointer;
}

.perspective-button {
  min-height: 60px;
  padding-right: 12px;
}

.perspective-button:hover,
.perspective-button.active,
.tree-button:hover,
.tree-button.active {
  border-color: var(--teal);
  box-shadow: inset 3px 0 0 var(--teal);
}

.perspective-button span,
.tree-button span,
.tree-leaf span {
  font-weight: 800;
}

.perspective-button small,
.tree-button small,
.tree-leaf small,
.source-item span,
.source-item code {
  color: var(--muted);
  font-size: 12px;
}

.tree-button b {
  position: absolute;
  top: 11px;
  right: 12px;
  color: var(--teal);
}

.tree-group {
  display: grid;
  gap: 7px;
}

.tree-children {
  display: grid;
  gap: 6px;
  margin: -2px 0 4px 12px;
  padding-left: 12px;
  border-left: 1px solid #dfe6ee;
}

.tree-children.slim {
  margin-left: 8px;
}

.tree-leaf {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  color: var(--text);
  text-align: left;
  background: var(--panel-soft);
  border: 1px solid #e1e7ef;
  border-radius: 7px;
  cursor: pointer;
}

.tree-leaf:hover,
.tree-leaf.active {
  border-color: var(--blue);
  background: #f3f8fb;
}

.source-list {
  display: grid;
  gap: 10px;
}

.source-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--panel-soft);
  border: 1px solid #e0e6ee;
  border-radius: 8px;
}

.source-item code {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.workspace {
  min-width: 0;
  padding: 16px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar-controls {
  display: flex;
  gap: 12px;
  align-items: end;
}

.search-box {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-box input {
  width: 250px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  font: inherit;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 10px;
  background: var(--panel-soft);
  border: 1px solid #dce4ed;
  border-radius: 6px;
  color: #3b4652;
  font-size: 13px;
  font-weight: 700;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px;
  background: #fff;
  border: 1px solid #dce4ed;
  border-radius: 6px;
}

.zoom-controls button {
  min-width: 32px;
  height: 28px;
  padding: 0 8px;
  color: #344253;
  background: var(--panel-soft);
  border: 1px solid #dbe3ec;
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.zoom-controls button:hover {
  border-color: var(--teal);
}

.zoom-controls .icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  padding: 0;
}

.zoom-controls .icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.zoom-controls .icon-button.saved {
  color: var(--green);
  border-color: #9bd4b7;
  background: #edf8f3;
}

.zoom-controls .icon-button.failed {
  color: var(--red);
  border-color: #e7aaa4;
  background: #fff6f5;
}

#zoomLabel {
  min-width: 44px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid #dfe6ee;
  border-radius: 8px;
}

.stat strong {
  display: block;
  font-size: 24px;
  color: var(--teal);
}

.stat.warn strong {
  color: var(--amber);
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.canvas-frame {
  position: relative;
  height: calc(100vh - 274px);
  min-height: 620px;
  overflow: auto;
  background:
    linear-gradient(#edf1f5 1px, transparent 1px),
    linear-gradient(90deg, #edf1f5 1px, transparent 1px),
    #fbfcfe;
  background-size: 28px 28px;
  border: 1px solid #dce4ec;
  border-radius: 8px;
}

.canvas-stage {
  position: relative;
  min-width: 1200px;
  min-height: 620px;
}

.node-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  transform-origin: 0 0;
}

.edge-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 1440px;
  height: 720px;
  pointer-events: none;
  transform-origin: 0 0;
}

.edge-layer marker path {
  fill: #8c98a7;
}

.edge-path {
  fill: none;
  stroke: #9aa6b5;
  stroke-width: 2;
}

.edge-label {
  fill: #5d6977;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #fbfcfe;
  stroke-width: 5px;
}

.edge-label-bg {
  fill: rgba(255, 255, 255, 0.92);
  stroke: #d8dee6;
  stroke-width: 1;
}

.stage-dot {
  background: var(--blue);
}

.page-dot {
  background: var(--teal);
}

.module-dot {
  background: var(--violet);
}

.feature-dot {
  background: var(--green);
}

.automation-dot {
  background: var(--amber);
}

.interaction-dot {
  background: var(--teal);
}

.decision-dot {
  background: var(--red);
}

.graph-node {
  position: absolute;
  display: grid;
  gap: 4px;
  min-height: 88px;
  padding: 12px;
  color: var(--text);
  text-align: left;
  background: #fff;
  border: 1px solid #cfd8e2;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(31, 37, 45, 0.08);
  cursor: grab;
  overflow-wrap: anywhere;
  touch-action: none;
  user-select: none;
}

.graph-node:hover,
.graph-node.selected {
  border-color: var(--violet);
  box-shadow: 0 12px 26px rgba(109, 91, 208, 0.18);
}

.graph-node.dragging {
  z-index: 5;
  cursor: grabbing;
  opacity: 0.96;
}

.graph-node.has-gap {
  box-shadow: 0 8px 20px rgba(155, 91, 6, 0.12);
}

.graph-node.has-gap::after {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  content: "";
  background: var(--amber);
  border-radius: 50%;
}

.node-stage {
  border-color: #bfd0ee;
  background: #f3f7ff;
}

.node-page {
  border-color: #bfe1df;
  background: #f1fbfa;
}

.node-module {
  border-color: #d3ccf5;
  background: #f7f5ff;
}

.node-feature {
  border-color: #c7e5d4;
  background: #f2fbf6;
}

.node-automation,
.node-automationType {
  border-color: #f0d7a5;
  background: #fff9ed;
}

.node-interaction {
  border-color: #bfe1df;
  background: #f1fbfa;
}

.node-decision {
  border-color: #e9c4c0;
  background: #fff6f5;
}

.node-event,
.node-analyticsStatus {
  border-color: #c8dce9;
  background: #f3f8fb;
}

.node-eventGap {
  border-color: #f0c8a5;
  background: #fff7ed;
}

.node-source,
.node-sourceType {
  border-color: #d5dce5;
  background: #f8fafc;
}

.node-kind {
  width: max-content;
  padding: 2px 6px;
  color: var(--teal);
  background: #e9f6f7;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
}

.graph-node strong {
  font-size: 15px;
}

.graph-node small,
.node-meta {
  color: var(--muted);
  font-size: 12px;
}

.node-meta b {
  color: var(--text);
}

.inspector {
  overflow: hidden auto;
}

.inspector-head {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.kind-pill {
  width: max-content;
  padding: 3px 8px;
  color: #fff;
  background: var(--teal);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

#detailPurpose {
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 10px;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 34px;
  color: var(--muted);
  background: #fff;
  border: 1px solid #dbe3ec;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.tab.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.tab-panel {
  display: none;
  padding: 16px;
}

.tab-panel.active {
  display: grid;
  gap: 16px;
}

.detail-section {
  display: grid;
  gap: 10px;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pill-list span {
  padding: 5px 8px;
  color: #3b4652;
  background: #f0f4f8;
  border: 1px solid #dbe3ec;
  border-radius: 999px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.pill-list .ok {
  color: var(--green);
  background: #edf8f3;
  border-color: #c9e7d9;
}

.pill-list .warn {
  color: var(--amber);
  background: #fff7e8;
  border-color: #f2d7a6;
}

.logic-list {
  display: grid;
  gap: 10px;
}

.logic-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid #dfe6ee;
  border-radius: 8px;
}

.logic-card strong {
  color: var(--violet);
  font-size: 13px;
}

.logic-card p,
.note,
.empty {
  color: var(--muted);
  font-size: 13px;
}

.logic-card p b {
  display: inline-block;
  min-width: 42px;
  margin-right: 6px;
  color: var(--text);
}

@media (max-width: 1240px) {
  body {
    min-width: 0;
  }

  .map-shell {
    grid-template-columns: 1fr;
  }

  .left-rail,
  .inspector {
    position: static;
    height: auto;
  }

  .canvas-frame {
    height: 640px;
  }
}
