:root {
  --paper: #f4f2ec;
  --panel: #fffefa;
  --panel-strong: #ffffff;
  --ink: #18201d;
  --muted: #69736f;
  --line: #d9ded9;
  --line-strong: #bdc8c1;
  --forest: #174b3b;
  --forest-soft: #dcebe3;
  --blue: #3e6f86;
  --blue-soft: #e2edf3;
  --amber: #ac6a17;
  --amber-soft: #f6e8cf;
  --red: #a8493e;
  --red-soft: #f5dedb;
  --gray-soft: #eceeeb;
  --shadow-1: 0 1px 2px rgba(21, 41, 33, 0.05);
  --shadow-2: 0 18px 46px rgba(25, 51, 41, 0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 14% 4%, rgba(23, 75, 59, 0.055), transparent 24rem),
    var(--paper);
  color: var(--ink);
  font-family: "MiSans", "PingFang SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  text-rendering: optimizeLegibility;
}

button, select, input { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 20px 32px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.eyebrow, .section-kicker {
  margin: 0 0 7px;
  color: var(--forest);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
}

.title-line { display: flex; align-items: center; gap: 12px; }
h1, h2, h3, p { text-wrap: pretty; }
h1 { margin: 0; font-size: clamp(24px, 2.2vw, 36px); line-height: 1.1; letter-spacing: -0.035em; }
h2 { margin: 0; font-size: 22px; line-height: 1.25; letter-spacing: -0.025em; }
h3 { margin: 0; font-size: 20px; line-height: 1.3; }

.demo-badge, .event-date {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--forest-soft);
  color: var(--forest);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.header-actions, .workshop-context, .summary-metrics, .legend, .task-meta, .member-line {
  display: flex;
  align-items: center;
}

.header-actions { gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.header-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
  color: var(--forest);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}
.header-link:hover, .header-link:focus-visible { border-color: var(--forest); outline: none; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-strong); }
.segmented button { border: 0; background: transparent; min-height: 38px; padding: 0 16px; border-radius: 8px; color: var(--muted); }
.segmented button:hover, .segmented button:focus-visible { color: var(--ink); background: var(--gray-soft); outline: none; }
.segmented button.is-active { background: var(--forest); color: white; box-shadow: var(--shadow-1); }

.primary-button, .icon-button {
  min-height: 44px;
  padding: 0 17px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  transition: transform 160ms var(--ease), background 160ms var(--ease), border-color 160ms var(--ease);
}
.primary-button { background: var(--forest); border-color: var(--forest); color: white; font-weight: 700; }
.primary-button:hover, .icon-button:hover { transform: translateY(-1px); }
.primary-button.is-editing { background: var(--amber); border-color: var(--amber); }

.context-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.workshop-context { gap: 10px; min-width: 0; }
.workshop-context label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.workshop-context select, .edit-grid select, .edit-grid input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 34px 0 11px;
  background: var(--panel-strong);
}

.summary-metrics { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.summary-chip { display: flex; align-items: baseline; gap: 6px; padding: 7px 10px; border-radius: 9px; background: var(--gray-soft); color: var(--muted); font-size: 12px; }
.summary-chip strong { color: var(--ink); font-size: 17px; }
.summary-chip.danger strong { color: var(--red); }

.workspace {
  width: 100%;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(350px, 420px);
  gap: 16px;
  padding: 16px;
  overflow: hidden;
}

.flow-panel, .detail-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.flow-panel { min-width: 0; display: flex; flex-direction: column; }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 22px 24px 18px; }
.legend { gap: 14px; flex-wrap: wrap; justify-content: flex-end; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.completed { background: var(--forest); }
.dot.active { background: var(--blue); }
.dot.pending { background: var(--amber); }
.dot.overdue { background: var(--red); }

.edit-notice { margin: 0 24px 8px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-size: 13px; }
.edit-notice button { color: inherit; border: 0; border-bottom: 1px solid currentColor; background: transparent; padding: 2px; }

.flow-scroll { flex: 1; min-height: 520px; overflow: auto; position: relative; border-top: 1px solid var(--line); background-image: radial-gradient(var(--line) 0.75px, transparent 0.75px); background-size: 22px 22px; }
.flow-stage { min-width: 1060px; min-height: 570px; position: relative; transition: min-height 240ms var(--ease); }
.edge-layer { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; color: var(--line-strong); pointer-events: none; }
.edge-path { fill: none; stroke: currentColor; stroke-width: 1.8; marker-end: url(#arrow); transition: d 220ms var(--ease); }
.edge-path.is-active { color: var(--forest); stroke-width: 2.4; }

.flow-node {
  width: 140px;
  min-height: 190px;
  position: absolute;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-strong);
  box-shadow: var(--shadow-1);
  text-align: left;
  user-select: none;
  transition: left 260ms var(--ease), top 260ms var(--ease), transform 160ms var(--ease), box-shadow 160ms var(--ease), border-color 160ms var(--ease);
}
.flow-node:hover { transform: translateY(-3px); border-color: var(--line-strong); }
.flow-node:focus-visible { outline: 3px solid color-mix(in srgb, var(--forest) 30%, transparent); outline-offset: 2px; }
.flow-node.is-selected { border-color: var(--forest); box-shadow: 0 0 0 2px var(--forest-soft), var(--shadow-2); }
.flow-node.is-editable { cursor: grab; }
.flow-node.is-dragging { cursor: grabbing; transition: none; z-index: 12; transform: scale(1.02); }

.node-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.step-number { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--forest); color: white; font-weight: 800; }
.node-task-total { color: var(--muted); font-size: 11px; }
.node-title { margin: 14px 0 8px; font-size: 16px; line-height: 1.32; letter-spacing: -0.02em; }
.intervention-tag { align-self: flex-start; padding: 4px 7px; border-radius: 6px; background: var(--blue-soft); color: var(--blue); font-size: 10px; font-weight: 700; }
.node-spacer { flex: 1; min-height: 8px; }
.member-line { gap: 7px; margin: 8px 0; min-width: 0; }
.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: 0 0 auto; background: var(--ink); color: white; font-size: 10px; font-weight: 750; }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }

.status-pill, .status-tag { display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; font-weight: 700; white-space: nowrap; }
.status-pill { width: 100%; min-height: 27px; padding: 4px 8px; font-size: 11px; }
.status-tag { min-height: 25px; padding: 4px 8px; font-size: 11px; }
.status-completed { background: var(--forest-soft); color: var(--forest); }
.status-active { background: var(--blue-soft); color: var(--blue); }
.status-pending { background: var(--amber-soft); color: var(--amber); }
.status-overdue, .status-rejected { background: var(--red-soft); color: var(--red); }
.status-not-started { background: var(--gray-soft); color: var(--muted); }

.swimlane-labels { position: sticky; left: 0; z-index: 4; width: 134px; pointer-events: none; }
.swimlane-labels span { position: absolute; left: 12px; width: 112px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: color-mix(in srgb, var(--panel) 92%, transparent); color: var(--muted); font-size: 11px; font-weight: 700; }
.swimlane-labels span:nth-child(1) { top: 74px; }
.swimlane-labels span:nth-child(2) { top: 284px; }
.swimlane-labels span:nth-child(3) { top: 494px; }

.detail-panel { padding: 22px; min-height: 660px; overflow: auto; }
.detail-head { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.detail-step { margin: 0 0 7px; color: var(--forest); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; }
.detail-description { margin: 10px 0 13px; color: var(--muted); line-height: 1.65; font-size: 13px; }
.detail-members { display: flex; gap: 8px; flex-wrap: wrap; }
.person-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px 6px 6px; border-radius: 999px; background: var(--gray-soft); font-size: 11px; }
.person-chip .avatar { width: 23px; height: 23px; }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 18px 0; }
.stat-card { min-width: 0; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; text-align: center; background: var(--panel-strong); }
.stat-card span { display: block; color: var(--muted); font-size: 10px; }
.stat-card strong { display: block; margin-top: 5px; font-size: 24px; line-height: 1; }
.stat-card.completed strong { color: var(--forest); }
.stat-card.active strong { color: var(--blue); }
.stat-card.pending strong { color: var(--amber); }
.stat-card.overdue strong { color: var(--red); }

.task-section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 18px 0 10px; }
.task-section-head h4 { margin: 0; font-size: 15px; }
.task-filters { display: flex; gap: 4px; overflow-x: auto; }
.filter-button { min-height: 30px; border: 0; border-radius: 7px; padding: 0 9px; background: transparent; color: var(--muted); font-size: 11px; white-space: nowrap; }
.filter-button:hover, .filter-button.is-active { background: var(--gray-soft); color: var(--ink); }

.task-list { display: grid; gap: 7px; }
.task-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px 10px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-strong); transition: border-color 160ms var(--ease), transform 160ms var(--ease); }
.task-row:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.task-name { font-size: 13px; font-weight: 700; }
.task-meta { gap: 9px; color: var(--muted); font-size: 10px; flex-wrap: wrap; }
.task-meta span + span::before { content: "·"; margin-right: 9px; color: var(--line-strong); }

.edit-card { margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--gray-soft); }
.edit-card h4 { margin: 0 0 12px; font-size: 14px; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.edit-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.edit-grid label.full { grid-column: 1 / -1; }
.edit-grid select, .edit-grid input { width: 100%; padding-right: 10px; font-size: 12px; }

.empty-state { min-height: 200px; display: grid; place-items: center; text-align: center; color: var(--muted); }
.app-footer { min-height: 46px; display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 10px 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

body.dark {
  --paper: #121714;
  --panel: #171d19;
  --panel-strong: #1c231f;
  --ink: #edf2ee;
  --muted: #9ca8a1;
  --line: #2d3932;
  --line-strong: #4a5b52;
  --forest: #8cc2a8;
  --forest-soft: #263e32;
  --blue: #91bfd2;
  --blue-soft: #253b45;
  --amber: #e3b46e;
  --amber-soft: #44351e;
  --red: #e59b91;
  --red-soft: #462b28;
  --gray-soft: #252d28;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.18);
  --shadow-2: 0 18px 46px rgba(0, 0, 0, 0.35);
}
body.dark .primary-button, body.dark .segmented button.is-active { color: #10231b; }

body.embed .app-header { position: static; }
body.embed .eyebrow, body.embed .app-footer { display: none; }
body.embed .app-header { min-height: 72px; padding-top: 14px; padding-bottom: 14px; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .detail-panel { min-height: 0; }
  .context-bar { align-items: flex-start; }
  .summary-metrics { max-width: 46%; }
}

@media (max-width: 760px) {
  .app-header, .context-bar, .panel-heading, .app-footer { padding-left: 16px; padding-right: 16px; }
  .app-header, .context-bar, .panel-heading { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; width: 100%; }
  .segmented { flex: 1; }
  .segmented button { flex: 1; padding: 0 10px; }
  .context-bar { gap: 14px; }
  .workshop-context { width: 100%; flex-wrap: wrap; }
  .workshop-context select { max-width: 100%; flex: 1; }
  .summary-metrics { max-width: none; justify-content: flex-start; }
  .workspace { padding: 8px; gap: 8px; }
  .legend { justify-content: flex-start; }
  .flow-scroll { min-height: 470px; }
  .detail-panel { padding: 17px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .edit-grid { grid-template-columns: 1fr; }
  .edit-grid label.full { grid-column: auto; }
  .app-footer { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
