:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-muted: #ecece8;
  --text: #111111;
  --muted: #656565;
  --line: #d8d8d2;
  --line-strong: #111111;
  --accent: #0057ff;
  --accent-soft: #e7eeff;
  --ok: #147a3b;
  --warn: #a36500;
  --danger: #b3261e;
  --shadow: 0 24px 80px rgba(17, 17, 17, .12);
  --radius: 0;
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(17, 17, 17, .035) 1px, transparent 1px),
    linear-gradient(rgba(17, 17, 17, .035) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

button, a, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: .85rem 1.1rem;
  border-bottom: 2px solid var(--line-strong);
  background: rgba(244, 244, 241, .94);
  position: sticky;
  top: 0;
  z-index: 20;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -.055em;
  line-height: .95;
}

h2 {
  margin-bottom: .75rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

h3 {
  margin-bottom: .4rem;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.eyebrow {
  margin-bottom: .28rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .68rem;
  font-weight: 700;
}

.muted { color: var(--muted); }

.header-actions,
.dialog-actions,
.zoom-controls {
  display: flex;
  gap: .45rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn,
.mini-btn,
.icon-btn {
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  padding: .52rem .72rem;
  text-decoration: none;
  font-size: .82rem;
  font-weight: 700;
  line-height: 1;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.btn:hover,
.mini-btn:hover,
.icon-btn:hover {
  background: var(--text);
  color: var(--surface);
}

.btn.secondary {
  color: var(--muted);
  border-color: var(--line);
}

.btn.secondary:hover {
  color: var(--surface);
  border-color: var(--line-strong);
}

.mini-btn {
  min-width: 2.35rem;
  padding: .48rem .58rem;
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 1.35rem;
}

.process-layout {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: calc(100vh - 72px);
  padding: .75rem;
  gap: .75rem;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .55rem;
}

.process-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  padding: .5rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 10px 30px rgba(17, 17, 17, .05);
}

.control-group {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}

.control-label {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.filter-list {
  display: flex;
  gap: .35rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  white-space: nowrap;
  padding: .46rem .58rem;
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  font-size: .8rem;
  font-weight: 700;
}

.filter-btn small {
  color: inherit;
  font-size: .68rem;
  font-weight: 700;
}

.filter-btn.active {
  border-color: var(--line-strong);
  color: var(--text);
  background: var(--surface);
}

.toggle-row {
  display: inline-flex;
  gap: .45rem;
  align-items: center;
  white-space: nowrap;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
}

.legend {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: .62rem;
  height: .62rem;
  margin-right: .24rem;
  border: 1px solid currentColor;
  vertical-align: -1px;
}

.dot.action { background: #ffffff; color: #1f2937; }
.dot.decision { background: #fff4d8; color: var(--warn); }
.dot.exception { background: #ffe8e6; color: var(--danger); }
.dot.end { background: #e4f4e9; color: var(--ok); }

.canvas-shell {
  height: calc(100vh - 158px);
  min-height: 620px;
  overflow: auto;
  border: 2px solid var(--line-strong);
  background:
    linear-gradient(90deg, rgba(17, 17, 17, .045) 1px, transparent 1px),
    linear-gradient(rgba(17, 17, 17, .045) 1px, transparent 1px),
    #fbfbf8;
  background-size: 24px 24px;
  box-shadow: var(--shadow);
}

#diagram {
  transform-origin: 0 0;
  display: block;
  min-width: 100%;
}

#diagram text {
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
}

.node .node-shape {
  filter: drop-shadow(0 8px 14px rgba(17, 17, 17, .09));
}

.node text { pointer-events: none; }
.node { cursor: pointer; opacity: .98; transition: opacity .15s ease; }
.node:hover { opacity: 1; }
.node.dimmed, .edge.dimmed { opacity: .16; }
.node.hidden, .edge.hidden { display: none; }
.node.selected .node-shape { stroke: var(--accent); stroke-width: 4; }
.node.related .node-shape { stroke: var(--ok); stroke-width: 3; }

.edge path {
  stroke: rgba(17, 17, 17, .42);
  stroke-width: 2.2;
  fill: none;
  marker-end: url(#arrow);
}

.edge text {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fbfbf8;
  stroke-width: 5px;
}

.details {
  position: absolute;
  right: 1.15rem;
  bottom: 5.65rem;
  z-index: 8;
  width: min(420px, calc(100vw - 2.3rem));
  pointer-events: none;
}

.details-card {
  max-height: min(520px, 58vh);
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.details-card.empty {
  color: var(--muted);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: .8rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  padding: .26rem .42rem;
  font-size: .7rem;
  font-weight: 700;
}

.detail-list {
  margin: .4rem 0 1rem;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.42;
}

.next-links {
  display: grid;
  gap: .35rem;
}

.next-link {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  padding: .55rem;
  color: var(--text);
  background: var(--surface);
  font-size: .82rem;
  font-weight: 700;
}

.next-link:hover {
  border-color: var(--line-strong);
}

.support-dock {
  display: grid;
  grid-template-columns: minmax(220px, .6fr) minmax(320px, 1fr) minmax(220px, .55fr);
  gap: .75rem;
}

.support-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .76);
}

.support-panel[open] {
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(17, 17, 17, .08);
}

.support-panel summary {
  cursor: pointer;
  padding: .68rem .8rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.support-panel > div,
.support-panel > ul {
  padding: 0 .8rem .8rem;
}

.definition-list,
#priorities {
  display: grid;
  gap: .5rem;
}

.definition-list .term,
.priority-card {
  border-top: 1px solid var(--line);
  padding-top: .55rem;
}

.definition-list strong,
.priority-card strong {
  display: block;
  margin-bottom: .18rem;
  font-size: .84rem;
}

.definition-list span,
.priority-card span {
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.35;
}

.todo-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.45;
  font-size: .84rem;
}

.todo-list li { margin-bottom: .25rem; }

.dialog {
  width: min(1100px, 92vw);
  border: 2px solid var(--line-strong);
  color: var(--text);
  background: var(--surface);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(17, 17, 17, .36);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

textarea {
  width: 100%;
  min-height: 56vh;
  margin: 1rem 0;
  resize: vertical;
  color: var(--text);
  background: #fbfbf8;
  border: 1px solid var(--line-strong);
  padding: 1rem;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 1180px) {
  .process-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .control-group,
  .legend,
  .zoom-controls {
    width: 100%;
  }

  .zoom-controls {
    justify-content: flex-end;
  }

  .details {
    position: static;
    width: auto;
    order: 3;
  }

  .details-card {
    max-height: none;
  }

  .support-dock {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: space-between;
  }

  .process-layout {
    padding: .5rem;
  }

  .canvas-shell {
    height: 62vh;
    min-height: 440px;
  }

  .role-group {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  body {
    background: white;
    color: #111;
  }

  .app-header,
  .process-controls,
  .details,
  .support-dock {
    display: none !important;
  }

  .process-layout {
    display: block;
    padding: 0;
  }

  .canvas-shell {
    height: auto;
    overflow: visible;
    border: none;
    background: white;
    box-shadow: none;
  }

  #diagram {
    transform: scale(.42);
    transform-origin: top left;
  }
}
