:root {
  color-scheme: light;
  --page: #f3f4f6;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --text: #17202a;
  --muted: #64748b;
  --border: #d8dee8;
  --accent: #5c2d91;
  --accent-soft: #eee5f8;
  --activity: #86cbd1;
  --activity-stroke: #4f9ca3;
  --business: #7338a7;
  --process: #abc9e8;
  --decision: #f1f3f5;
  --edge: #59636f;
  --selected: #e56f35;
  --shadow: 0 16px 35px rgb(15 23 42 / 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px minmax(480px, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 22px;
  font-weight: 600;
}

h2 {
  margin-bottom: 8px;
  font-size: 18px;
  font-weight: 600;
}

.eyebrow,
#model-kicker {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.header-meta {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.catalog-panel,
.detail-panel {
  min-height: 0;
  padding: 18px;
  background: var(--surface);
}

.catalog-panel {
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.detail-panel {
  border-left: 1px solid var(--border);
  overflow: auto;
}

.search-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
}

#model-search {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

#model-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.catalog-status {
  min-height: 30px;
  padding: 9px 0 6px;
  color: var(--muted);
  font-size: 11px;
}

.model-tree {
  overflow: auto;
  padding-bottom: 24px;
}

.tree-branch {
  margin: 0;
}

.tree-branch > summary {
  padding: 5px 3px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tree-branch > summary:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.tree-children {
  margin-left: 10px;
  padding-left: 9px;
  border-left: 1px solid var(--border);
}

.tree-model,
.search-result {
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.tree-model:hover,
.search-result:hover {
  background: var(--surface-subtle);
}

.tree-model.is-active,
.search-result.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tree-model-id {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
}

.tree-model-title {
  display: block;
  font-size: 12px;
  line-height: 1.25;
}

.diagram-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-subtle);
}

.diagram-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 13px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.workspace-tabs {
  display: flex;
  align-self: center;
  margin-left: auto;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-subtle);
}

.workspace-tabs button {
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.workspace-tabs button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.model-heading h2,
.model-heading p {
  margin-bottom: 0;
}

.zoom-controls {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.zoom-controls button,
.child-model-button {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.zoom-controls button:hover,
.child-model-button:hover {
  border-color: var(--accent);
}

.diagram-stage {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: auto;
  background-color: var(--surface-subtle);
  background-image: radial-gradient(circle, #cbd5e1 0.7px, transparent 0.8px);
  background-size: 14px 14px;
}

.process-guide-stage {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 28px;
  background: var(--page);
}

.diagram-stage[hidden],
.process-guide-stage[hidden] {
  display: none;
}

.process-guide-container {
  width: min(920px, 100%);
  margin: 0 auto;
}

.process-guide-header {
  margin-bottom: 22px;
}

.process-guide-import {
  width: min(380px, 100%);
  margin-top: 14px;
}

.process-guide-import .guide-import-button {
  width: auto;
  min-width: 220px;
  margin-bottom: 6px;
  padding: 9px 14px;
}

.process-guide-empty .process-guide-import {
  margin-right: auto;
  margin-left: auto;
}

.process-guide-header h3 {
  margin: 0 0 7px;
  font-size: 24px;
}

.process-guide-header > p:last-child,
.process-guide-flow > header p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.process-guide-flow {
  margin-bottom: 28px;
}

.process-guide-flow > header {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.process-guide-flow > header h4 {
  margin: 0 0 4px;
  font-size: 16px;
}

.process-guide-steps {
  position: relative;
}

.process-guide-steps::before {
  position: absolute;
  top: 28px;
  bottom: 28px;
  left: 18px;
  width: 2px;
  background: var(--border);
  content: "";
}

.process-guide-step {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.process-step-number {
  z-index: 1;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 3px solid var(--page);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.process-step-content {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.process-step-content h4 {
  margin: 0 0 8px;
  font-size: 17px;
}

.process-step-content > p {
  margin-bottom: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.process-step-content img {
  display: block;
  width: 100%;
  max-height: 720px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-subtle);
  object-fit: contain;
}

.process-step-details {
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.process-step-details > summary {
  padding: 10px 2px 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.process-step-details[open] > summary {
  margin-bottom: 8px;
}

.process-step-content .detail-list {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 5px 12px;
  margin: 0;
  padding: 4px 2px 2px;
}

.process-step-content .detail-list dt {
  margin-top: 0;
}

.process-step-content .detail-list dd {
  margin-top: 0;
}

.process-guide-empty {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  min-height: 360px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.process-guide-empty h3 {
  margin-bottom: 8px;
  color: var(--text);
}

.process-guide-empty p {
  max-width: 520px;
  margin-bottom: 16px;
}

.process-guide-empty button {
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
}

#diagram {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 7px;
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden],
#diagram[hidden] {
  display: none;
}

.empty-state strong {
  color: var(--text);
}

.edge-line {
  fill: none;
  stroke: var(--edge);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.edge-label {
  fill: var(--text);
  font-size: 11px;
  paint-order: stroke;
  stroke: var(--surface-subtle);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.diagram-node {
  cursor: pointer;
}

.diagram-node .shape {
  vector-effect: non-scaling-stroke;
  transition: stroke-width 120ms ease, filter 120ms ease;
}

.diagram-node:hover .shape {
  filter: brightness(0.98);
  stroke-width: 2;
}

.diagram-node.is-selected .shape {
  stroke: var(--selected) !important;
  stroke-width: 3;
}

.guide-badge {
  pointer-events: none;
}

.guide-badge circle {
  fill: var(--selected);
  stroke: var(--surface);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.guide-badge text {
  fill: #fff;
  font-size: 9px;
  font-weight: 700;
}

.node-activity {
  fill: var(--activity);
  stroke: var(--activity-stroke);
}

.node-business_object {
  fill: var(--business);
  stroke: var(--business);
}

.node-process {
  fill: var(--process);
  stroke: #658bae;
}

.node-decision {
  fill: var(--decision);
  stroke: #5f6670;
}

.node-possibility {
  fill: #e7edf4;
  stroke: #8492a3;
}

.node-role,
.node-organisation,
.node-location {
  fill: #f5dfaa;
  stroke: #a77d21;
}

.node-generic {
  fill: var(--surface);
  stroke: #8b96a4;
}

.node-text {
  fill: transparent;
  stroke: transparent;
}

.node-text.has-border {
  fill: rgb(255 255 255 / 0.46);
  stroke: #8b96a4;
}

.node-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 3px;
  overflow: hidden;
  color: var(--text);
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.node-label.light {
  color: #fff;
}

.detail-type {
  display: inline-block;
  margin-bottom: 10px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
}

.detail-list {
  margin: 0 0 18px;
}

.detail-list dt {
  margin-top: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 3px 0 0;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.detail-section {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-section h3 {
  margin: 0 0 9px;
  font-size: 12px;
}

.document-link,
.document-route {
  display: block;
  margin-bottom: 9px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.document-link {
  color: var(--accent);
}

.document-route code {
  display: block;
  margin-top: 3px;
  padding: 7px;
  border-radius: 5px;
  background: var(--surface-subtle);
  color: var(--text);
}

.child-model-button,
.guide-import-button {
  width: 100%;
  margin-bottom: 7px;
  text-align: left;
  font-size: 12px;
}

.guide-import-button {
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-align: center;
}

.guide-import-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.guide-import-status,
.guide-empty {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.guide-card {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-subtle);
}

.guide-card > summary {
  padding: 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
}

.guide-body {
  padding: 0 9px 9px;
  color: var(--muted);
  font-size: 11px;
}

.guide-step {
  padding: 10px 0;
  border-top: 1px solid var(--border);
  color: var(--text);
}

.guide-step h4 {
  margin: 0 0 8px;
  font-size: 12px;
}

.guide-step p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
}

.guide-step img {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}

.guide-step .detail-list {
  margin-bottom: 0;
}

.error-message {
  color: #a12626;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 250px minmax(420px, 1fr);
    grid-template-rows: auto minmax(300px, 1fr) minmax(230px, 40vh);
  }

  .catalog-panel {
    grid-column: 1;
    grid-row: 2 / 4;
  }

  .diagram-panel {
    grid-column: 2;
    grid-row: 2;
  }

  .detail-panel {
    display: block;
    grid-column: 2;
    grid-row: 3;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .diagram-toolbar {
    flex-wrap: wrap;
  }

  .workspace-tabs {
    order: 3;
    width: 100%;
  }

  .workspace-tabs button {
    flex: 1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    height: auto;
    overflow: visible;
  }

  .app-header {
    align-items: start;
    padding: 14px 16px;
  }

  .catalog-panel {
    max-height: 300px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .diagram-panel {
    min-height: 620px;
  }

  .process-guide-stage {
    padding: 18px 12px;
  }

  .process-guide-step {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 9px;
  }

  .process-step-number {
    width: 32px;
    height: 32px;
  }

  .process-guide-steps::before {
    left: 15px;
  }

  .process-step-content {
    padding: 12px;
  }

  .detail-panel {
    display: block;
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light;
    --page: #f2f1ef;
    --surface: #ffffff;
    --surface-subtle: #f8f7f5;
    --text: #202124;
    --muted: #676767;
    --border: #d8d5d0;
    --accent: #6d3c95;
    --accent-soft: #eee5f6;
    --activity: #9ad5d8;
    --activity-stroke: #4f9ca3;
    --business: #8550ae;
    --process: #c8d5df;
    --decision: #eceae7;
    --edge: #646464;
    --selected: #e9783f;
    --shadow: 0 12px 30px rgb(30 30 30 / 10%);
  }

  .diagram-stage {
    background-image: radial-gradient(circle, #d0ccc6 0.8px, transparent 0.9px);
  }
}
