:root {
  --bg: #0f0c0b;
  --panel: #191411;
  --panel-2: #211a16;
  --text: #f7f2ed;
  --muted: #b8aaa1;
  --line: rgba(255, 255, 255, 0.13);
  --accent: #df6841;
  --accent-soft: rgba(223, 104, 65, 0.16);
  --green: #91aa65;
  --blue: #5e8fa3;
  --amber: #eda34f;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--text);
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 5% 0, rgba(223, 104, 65, 0.18), transparent 30%),
    radial-gradient(circle at 95% 10%, rgba(94, 143, 163, 0.12), transparent 28%),
    var(--bg);
}
button { font: inherit; }
.app-shell { min-height: 100vh; padding: 14px; }
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  min-height: 76px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(25, 20, 17, 0.9);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; font-weight: 800; }
.brand img { width: 154px; border: 1px solid var(--line); border-radius: 7px; }
.brand span { color: var(--muted); white-space: nowrap; }
.header-copy { display: grid; gap: 3px; text-align: center; }
.header-copy span { color: var(--muted); font-size: 13px; }
.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  cursor: pointer;
}
.secondary-button:hover { background: rgba(255,255,255,0.11); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.version-label { color: var(--muted); font-size: 11px; }
.primary-button, .small-button, .danger-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}
.small-button { min-height: 34px; padding: 0 10px; border-color: var(--line); background: rgba(255,255,255,.07); }
.danger-button { min-height: 34px; color: #ffd9d2; border-color: rgba(223,104,65,.35); background: rgba(223,104,65,.12); }
.primary-button:hover { filter: brightness(1.08); }
.primary-button:disabled, .small-button:disabled, .danger-button:disabled { opacity: .45; cursor: not-allowed; }
.journey { padding: 24px 12px 18px; }
.stage-flow { display: grid; grid-template-columns: repeat(7, minmax(92px, 1fr)); gap: 24px; }
.stage-item { position: relative; display: grid; justify-items: center; gap: 8px; min-width: 0; }
.stage-item:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 31px;
  left: calc(50% + 37px);
  width: calc(100% - 50px);
  border-top: 2px solid var(--line);
}
.stage-item:not(:last-child)::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 27px;
  right: -15px;
  border-left: 7px solid rgba(255,255,255,0.3);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
.stage-button {
  position: relative;
  z-index: 2;
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 900;
}
.stage-button:hover { border-color: rgba(255,255,255,0.4); }
.stage-button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); }
.stage-label { text-align: center; font-weight: 800; overflow-wrap: anywhere; }
.stage-owner { color: var(--muted); font-size: 11px; text-align: center; }
.workspace {
  display: grid;
  grid-template-columns: minmax(235px, 290px) minmax(0, 1fr);
  min-height: 610px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(25, 20, 17, 0.78);
}
.process-list { padding: 22px; border-right: 1px solid var(--line); background: rgba(255,255,255,0.025); }
.aside-heading { display: flex; gap: 12px; align-items: center; }
.aside-heading > span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text);
  background: var(--accent);
  font-weight: 900;
}
.aside-heading p, .eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; }
h2 { margin-bottom: 8px; font-size: clamp(28px, 3vw, 43px); line-height: 1; }
h3 { margin-bottom: 0; }
.stage-purpose { margin: 18px 0; color: var(--muted); line-height: 1.45; }
.stage-notes { margin-bottom: 18px; }
#processList { display: grid; gap: 7px; }
.process-button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: center;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.process-button:hover { background: rgba(255,255,255,0.06); }
.process-button[aria-pressed="true"] { border-color: rgba(223,104,65,.4); background: var(--accent-soft); }
.process-button span:first-child { color: var(--muted); font-weight: 900; }
.process-detail { min-width: 0; padding: clamp(22px, 3vw, 38px); }
.detail-heading { display: grid; grid-template-columns: 1fr minmax(190px, 260px); gap: 24px; align-items: start; }
.summary { max-width: 780px; margin-bottom: 0; color: var(--muted); font-size: 16px; line-height: 1.5; }
.result-card {
  display: grid;
  gap: 7px;
  padding: 16px;
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: rgba(145,170,101,.11);
}
.result-card span, .handoff-strip span { color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.handoff-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  margin: 26px 0 30px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,.035);
}
.handoff-strip div { display: grid; gap: 4px; }
.handoff-arrow { color: var(--accent) !important; font-size: 24px !important; }
.section-title { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 13px; }
.help-text { color: var(--muted); font-size: 12px; }
.step-list { display: grid; gap: 8px; }
.step-item { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: rgba(255,255,255,.025); }
.step-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.step-toggle:hover { background: rgba(255,255,255,.045); }
.step-index { color: var(--accent); font-weight: 900; }
.step-title { display: grid; gap: 2px; }
.step-title span { color: var(--muted); font-size: 12px; }
.chevron { color: var(--muted); transition: transform 150ms ease; }
.step-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.step-body { display: none; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; padding: 0 15px 15px 69px; }
.step-body.open { display: grid; }
.fact { display: grid; gap: 4px; padding-top: 11px; border-top: 1px solid var(--line); }
.fact span { color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.fact strong { font-size: 13px; line-height: 1.4; }
.process-notes, .stage-notes {
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 3px solid var(--amber);
  color: var(--muted);
  background: rgba(237,163,79,.08);
  white-space: pre-wrap;
}

dialog {
  width: min(1240px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 30px 90px rgba(0,0,0,.65);
}
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
.editor-shell { display: grid; grid-template-rows: auto minmax(0,1fr) auto; height: min(820px, calc(100vh - 28px)); }
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}
.editor-header h2 { margin: 0; font-size: 28px; }
.editor-header-actions, .editor-item-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.editor-body { min-height: 0; display: grid; grid-template-columns: 330px minmax(0,1fr); }
.editor-tree { min-height: 0; padding: 14px; border-right: 1px solid var(--line); overflow-y: auto; background: rgba(255,255,255,.02); }
.tree-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
#editorTree { display: grid; gap: 5px; }
.tree-stage, .tree-process, .tree-step {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.tree-stage { font-weight: 900; }
.tree-process { padding-left: 24px; color: #ded4cd; }
.tree-step { padding-left: 42px; color: var(--muted); font-size: 12px; }
.tree-stage:hover, .tree-process:hover, .tree-step:hover { background: rgba(255,255,255,.055); }
.tree-stage[aria-pressed="true"], .tree-process[aria-pressed="true"], .tree-step[aria-pressed="true"] {
  border-color: rgba(223,104,65,.42);
  background: var(--accent-soft);
}
.editor-form-panel { min-width: 0; min-height: 0; padding: 20px; overflow-y: auto; }
.editor-context { display: flex; justify-content: space-between; gap: 18px; align-items: start; margin-bottom: 20px; }
.editor-context h3 { font-size: 26px; }
.editor-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.editor-fields label, .editor-footer label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 800; }
.editor-fields label.wide { grid-column: 1 / -1; }
.editor-fields input, .editor-fields textarea, .editor-footer input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255,255,255,.045);
  font: inherit;
}
.editor-fields textarea { min-height: 94px; resize: vertical; line-height: 1.45; }
.editor-fields textarea.notes-field { min-height: 130px; }
.editor-footer {
  display: grid;
  grid-template-columns: minmax(260px,1fr) auto auto;
  align-items: end;
  gap: 14px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}
.save-status { align-self: center; color: var(--muted); font-size: 12px; }
.history-dialog { width: min(780px, calc(100vw - 24px)); }
.history-dialog form { max-height: calc(100vh - 28px); display: grid; grid-template-rows: auto minmax(0,1fr); }
.history-list { padding: 14px 20px 20px; overflow-y: auto; }
.history-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.history-row strong, .history-row span { display: block; }
.history-row span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.toast {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-2);
  box-shadow: 0 15px 50px rgba(0,0,0,.5);
}
[hidden] { display: none !important; }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .header-copy { display: none; }
  .stage-flow { grid-template-columns: repeat(4, 1fr); row-gap: 18px; }
  .stage-item::after, .stage-item::before { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .process-list { border-right: 0; border-bottom: 1px solid var(--line); }
  #processList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-body { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .editor-body { grid-template-columns: 280px minmax(0,1fr); }
}
@media (max-width: 620px) {
  .app-shell { padding: 8px; }
  .topbar { grid-template-columns: 1fr; }
  .brand { justify-content: space-between; }
  .brand span { white-space: normal; }
  .secondary-button { width: 100%; }
  .top-actions { width: 100%; }
  .top-actions .version-label { width: 100%; text-align: center; }
  .stage-flow { grid-template-columns: repeat(2, 1fr); }
  .detail-heading { grid-template-columns: 1fr; }
  #processList { grid-template-columns: 1fr; }
  .handoff-strip { grid-template-columns: 1fr; }
  .handoff-arrow { transform: rotate(90deg); }
  .section-title { align-items: start; flex-direction: column; }
  .step-body { grid-template-columns: 1fr; padding-left: 15px; }
  .editor-body { grid-template-columns: 1fr; overflow-y: auto; }
  .editor-tree { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-form-panel { overflow: visible; }
  .editor-context { flex-direction: column; }
  .editor-fields { grid-template-columns: 1fr; }
  .editor-footer { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; }
}
