:root {
  --flow-grid: #e9e8e2;
  --flow-board: #fbfbf8;
  --flow-ink: #23231f;
  --flow-arrow: #73736c;
  --flow-yes: #16845a;
  --flow-no: #d14f61;
}

.user-flow-page { background: #f3f2ed; }
.user-flow-page main { width: min(1660px, calc(100% - 40px)); }

.dashboard-nav a:focus-visible,
.domain-tabs button:focus-visible {
  outline: 3px solid var(--system-border);
  outline-offset: 3px;
}

.user-flow-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 410px);
  gap: clamp(30px, 5vw, 80px);
  align-items: end;
}
.user-flow-header > div > p:last-child { margin: 0; color: var(--muted); font-size: 17px; }
.header-note {
  display: grid;
  gap: 7px;
  padding: 18px 20px;
  background: #fff7c7;
  border: 1px solid #d2b74e;
  transform: rotate(.5deg);
}
.header-note span { color: #705d13; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.header-note strong { font-size: 14px; line-height: 1.5; }

.flow-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  padding: 42px 0 24px;
}
.flow-toolbar h2 { margin: 4px 0 0; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.03em; }
.domain-tabs { display: flex; gap: 8px; }
.domain-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 10px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  font-weight: 750;
  transition: color .18s ease, border-color .18s ease, background-color .18s ease;
}
.domain-tabs button:hover { color: var(--ink); border-color: var(--ink); }
.domain-tabs button[aria-selected="true"] {
  color: var(--ink);
  background: #fff;
  border-color: var(--ink);
  box-shadow: inset 0 -3px 0 var(--active-domain, var(--hr-border));
}
.domain-tabs button[data-domain="candidate"][aria-selected="true"] { --active-domain: var(--candidate-border); }
.domain-dot { width: 11px; height: 11px; border: 1px solid; border-radius: 50%; }
.domain-dot-hr { background: var(--hr-bg); border-color: var(--hr-border); }
.domain-dot-candidate { background: var(--candidate-bg); border-color: var(--candidate-border); }

.diagram-shell { overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.diagram-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  padding: 14px 20px;
  background: #f3f3ef;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
}
.diagram-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-shape { display: inline-block; width: 24px; height: 15px; border: 1px solid var(--ink); }
.legend-hr { background: var(--hr-bg); border-radius: 5px; }
.legend-user { background: var(--candidate-bg); border-radius: 5px; }
.legend-system { background: var(--system-bg); border-radius: 5px; }
.legend-decision { width: 17px; height: 17px; background: #fdcfff; transform: rotate(45deg); }
.legend-document { background: #efeae4; border-color: #7a6d5f; clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%); }
.legend-line { position: relative; width: 29px; height: 1.5px; background: #222; }
.legend-line::after {
  content: "";
  position: absolute;
  top: -4px;
  right: 0;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid #222;
  border-bottom: 1.5px solid #222;
  transform: rotate(-45deg);
  transform-origin: center;
}
.legend-line-primary { color: #222; }

.domain-panel { padding: clamp(24px, 4vw, 54px); }
.domain-panel[hidden] { display: none; }
.domain-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 30px;
}
.domain-label {
  display: inline-block;
  padding: 5px 9px;
  border: 1px solid;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .05em;
}
.domain-label-hr { background: var(--hr-bg); border-color: var(--hr-border); }
.domain-label-candidate { background: var(--candidate-bg); border-color: var(--candidate-border); }
.domain-heading h2 { margin: 11px 0 4px; font-size: clamp(27px, 3vw, 40px); letter-spacing: -.04em; }
.domain-heading > div > p { margin: 0; color: var(--muted); }
.scope-note {
  flex: 0 0 auto;
  max-width: 310px;
  margin: 0;
  padding: 11px 13px;
  color: #53534c;
  background: #f6f6f1;
  border-left: 3px solid var(--ink);
  font-size: 13px;
}
.scope-note strong { display: block; color: var(--ink); }

.flow-canvas {
  min-height: 720px;
  padding: 26px;
  overflow: auto;
  background-color: var(--flow-board);
  background-image: linear-gradient(var(--flow-grid) 1px, transparent 1px), linear-gradient(90deg, var(--flow-grid) 1px, transparent 1px);
  background-size: 24px 24px;
  border: 1px solid var(--line);
}
.flow-canvas svg {
  display: block;
  width: 100% !important;
  min-width: 760px;
  max-width: 1120px !important;
  height: auto;
  margin: 0 auto;
}
.flow-canvas .nodeLabel,
.flow-canvas .edgeLabel { font-weight: 700; }
.flow-canvas .nodeLabel p { line-height: 1.35; }
.flow-canvas .node-kind {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .1em;
}
.flow-canvas .node.hr .node-kind { color: var(--hr-border) !important; }
.flow-canvas .node.user .node-kind { color: var(--candidate-border) !important; }
.flow-canvas .node.system .node-kind { color: var(--system-border) !important; }
.flow-canvas .node.condition .node-kind { color: #9a3f83 !important; }
.flow-canvas .node.document .node-kind { color: #7a6d5f !important; }
.flow-canvas .edgeLabel p {
  color: #222;
  background: #fff;
  font-size: 11px;
  line-height: 1.35;
}
.flow-canvas path.flowchart-link {
  stroke: #222 !important;
  stroke-width: 1.5px !important;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.flow-canvas .cluster rect {
  fill: rgba(255, 255, 255, .88) !important;
  stroke: #222 !important;
  stroke-width: 1.5px !important;
}
.flow-canvas .cluster-label {
  color: #222 !important;
  font-size: 13px;
  font-weight: 800 !important;
}
.diagram-loading { margin: 0; color: var(--muted); }
.diagram-error { color: var(--flow-no); font-weight: 700; }

.flow-boundary {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 28px;
  margin-top: 34px;
  padding: 26px 0;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
.flow-boundary > span { font-size: 13px; font-weight: 800; }
.flow-boundary h2 { margin: 0; font-size: clamp(21px, 2.5vw, 30px); line-height: 1.35; }
.flow-boundary p { margin: 7px 0 0; color: var(--muted); }

@media (max-width: 720px) {
  .user-flow-page main { width: min(100% - 28px, 1660px); }
  .user-flow-header { grid-template-columns: 1fr; }
  .header-note { transform: none; }
  .flow-toolbar { display: block; }
  .domain-tabs { margin-top: 18px; }
  .domain-tabs button { flex: 1; justify-content: center; }
  .domain-heading { display: block; }
  .scope-note { margin-top: 18px; }
  .diagram-legend { min-width: 720px; }
  .domain-panel { padding: 24px 14px; }
  .flow-canvas { min-height: 560px; padding: 16px; }
  .flow-canvas svg { min-width: 720px; }
  .flow-boundary { grid-template-columns: 1fr; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .domain-tabs button { transition: none; }
}
