/* PharmaOS app styles. Token aliases only; no primitive colours here. The
   workbench (rail | canvas over settings | agent) follows design/workbench-mock.html. */

* {
	box-sizing: border-box;
}
html,
body {
	margin: 0;
	height: 100%;
}
body {
	font-family: var(--font-sans);
	font-size: var(--fs-body-sm);
	color: var(--text);
	background: var(--wash-soft);
	overflow: hidden;
}
button {
	font: inherit;
	color: inherit;
}
a {
	color: var(--accent-600);
	text-decoration: none;
}
a:hover {
	text-decoration: underline;
}
b {
	font-weight: 600;
}
.mono {
	font-family: var(--font-mono);
}
.muted {
	color: var(--text-muted);
}
.subtle {
	color: var(--text-subtle);
}
.spacer {
	flex: 1;
}
[hidden] {
	display: none !important;
}

#app {
	display: grid;
	height: 100vh;
	grid-template-columns: 240px 1fr;
	transition: grid-template-columns var(--dur-base) var(--ease-out);
}
#app.with-agent {
	grid-template-columns: 240px 1fr 400px;
}
#app.rail-collapsed {
	grid-template-columns: 56px 1fr;
}
#app.rail-collapsed.with-agent {
	grid-template-columns: 56px 1fr 400px;
}
#app.with-agent.agent-collapsed {
	grid-template-columns: 240px 1fr 44px;
}
#app.rail-collapsed.with-agent.agent-collapsed {
	grid-template-columns: 56px 1fr 44px;
}

/* Rail */
#rail {
	display: flex;
	flex-direction: column;
	border-right: 1px solid var(--border-subtle);
	background: var(--surface-sunken);
	min-width: 0;
	overflow: hidden;
}
#rail .head {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	height: 56px;
	padding: 0 var(--space-3);
}
#rail .head img.word {
	height: 26px;
}
#rail .head img.mark {
	height: 26px;
	display: none;
}
.rail-collapsed #rail .head img.word {
	display: none;
}
.rail-collapsed #rail .head img.mark {
	display: block;
}
.iconbtn {
	width: 28px;
	height: 28px;
	border: 0;
	border-radius: var(--radius-xs);
	background: transparent;
	cursor: pointer;
	display: grid;
	place-items: center;
	color: var(--text-muted);
}
.iconbtn:hover {
	background: var(--surface-hover);
	color: var(--text);
}
.iconbtn svg {
	width: 16px;
	height: 16px;
}
#rail .project {
	margin: 4px 8px 2px;
}
#rail .project select {
	width: 100%;
	font: inherit;
	padding: 6px 8px;
	border: 1px solid var(--border-input);
	border-radius: var(--radius-sm);
	background: var(--white);
	color: var(--text);
}
.rail-collapsed #rail .project {
	display: none;
}
#rail .group {
	padding: var(--space-3) var(--space-2) var(--space-1);
	font-size: var(--fs-overline);
	letter-spacing: var(--ls-overline);
	text-transform: uppercase;
	color: var(--text-subtle);
	white-space: nowrap;
}
.rail-collapsed #rail .group {
	visibility: hidden;
	height: 12px;
	padding: 0;
}
.shelf {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	width: calc(100% - 16px);
	margin: 1px 8px;
	padding: 7px 8px;
	border: 0;
	border-radius: var(--radius-sm);
	background: transparent;
	text-align: left;
	cursor: pointer;
	white-space: nowrap;
	overflow: hidden;
	color: inherit;
}
.shelf:hover {
	background: var(--surface-hover);
	text-decoration: none;
}
.shelf.active {
	background: var(--surface-pressed);
}
.shelf svg {
	width: 18px;
	height: 18px;
	flex: none;
	color: var(--text-muted);
}
.shelf .n {
	margin-left: auto;
	font-size: var(--fs-caption);
	color: var(--text-subtle);
	font-family: var(--font-mono);
}
.rail-collapsed .shelf {
	width: 40px;
	margin: 1px 8px;
	padding: 9px 11px;
}
.rail-collapsed .shelf span {
	display: none;
}
#rail .foot {
	margin-top: auto;
	padding: var(--space-3);
	border-top: 1px solid var(--border-subtle);
	display: flex;
	align-items: center;
	gap: var(--space-2);
	white-space: nowrap;
	overflow: hidden;
}
#rail .foot .avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--avatar-0);
	color: var(--blue-850);
	display: grid;
	place-items: center;
	font-weight: 600;
	font-size: var(--fs-caption);
	flex: none;
}
.rail-collapsed #rail .foot span {
	display: none;
}

/* Centre */
#centre {
	display: grid;
	grid-template-rows: 48px 1fr;
	min-width: 0;
	min-height: 0;
	overflow: hidden;
}
#centre.workbench {
	grid-template-rows: 48px 1fr 6px auto;
}
#topbar {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: 0 var(--space-4);
	border-bottom: 1px solid var(--border-subtle);
	background: rgb(var(--glass-rgb) / 0.6);
	backdrop-filter: var(--acrylic-blur);
	min-width: 0;
}
#topbar h1 {
	margin: 0;
	font: 600 var(--fs-h3) / 1.2 var(--font-display);
	letter-spacing: var(--ls-tight);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
#topbar h1 input {
	font: inherit;
	border: 0;
	background: transparent;
	color: inherit;
	width: 100%;
	min-width: 120px;
	padding: 0;
	outline: none;
	border-bottom: 1px dashed transparent;
}
#topbar h1 input:hover,
#topbar h1 input:focus {
	border-bottom-color: var(--border-default);
}
#topbar .lead {
	color: var(--text-emphasis);
	font-style: italic;
	font-family: var(--font-serif);
	white-space: nowrap;
}
.lozenge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 2px 9px;
	border-radius: var(--radius-pill);
	font-size: var(--fs-caption);
	font-weight: 500;
	border: 1px solid;
	white-space: nowrap;
}
.lozenge.draft {
	background: var(--surface-sunken);
	border-color: var(--border-subtle);
	color: var(--text-muted);
}
.lozenge.ok {
	background: var(--success-100);
	border-color: var(--success-500);
	color: var(--success-600);
}
.lozenge.warn {
	background: var(--warning-100);
	border-color: var(--warning-500);
	color: var(--warning-600);
}
.lozenge.danger {
	background: var(--danger-100);
	border-color: var(--danger-500);
	color: var(--danger-600);
}
.lozenge.info {
	background: var(--accent-50);
	border-color: var(--accent-200);
	color: var(--accent-700);
}
.btn {
	height: 32px;
	padding: 0 12px;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border-subtle);
	background: var(--surface-card);
	cursor: pointer;
	font-weight: 500;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	white-space: nowrap;
	color: inherit;
}
.btn:hover {
	background: var(--surface-hover);
	text-decoration: none;
}
.btn:disabled {
	opacity: 0.5;
	cursor: default;
}
.btn.primary {
	background: var(--accent-600);
	border-color: var(--accent-600);
	color: var(--on-bold);
}
.btn.primary:hover {
	background: var(--accent-700);
}
.btn.danger {
	color: var(--danger-600);
}
.btn.sm {
	height: 26px;
	padding: 0 9px;
	font-size: var(--fs-caption);
}
.btn:focus-visible,
.iconbtn:focus-visible,
.shelf:focus-visible {
	outline: none;
	box-shadow: var(--ring-focus);
}

/* Shelf pages */
#page {
	overflow: auto;
	min-height: 0;
	padding: var(--space-5) var(--space-6);
}
.page-head {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	margin-bottom: var(--space-4);
}
.page-head h2 {
	margin: 0;
	font: 600 var(--fs-h2) / 1.2 var(--font-display);
	letter-spacing: var(--ls-tight);
}
.tabs {
	display: inline-flex;
	gap: 2px;
	padding: 2px;
	border-radius: var(--radius-sm);
	background: var(--surface-sunken);
	margin-bottom: var(--space-4);
}
.tabs button {
	border: 0;
	background: transparent;
	padding: 5px 12px;
	border-radius: var(--radius-xs);
	cursor: pointer;
	color: var(--text-muted);
}
.tabs button.on {
	background: var(--white);
	color: var(--text);
	box-shadow: var(--shadow-xs);
	font-weight: 500;
}
.cards {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
	gap: var(--space-3);
}
.card {
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md);
	padding: var(--space-3) var(--space-4);
	box-shadow: var(--shadow-xs);
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}
.card.click {
	cursor: pointer;
}
.card.click:hover {
	border-color: var(--accent-400);
}
.card .title {
	font-weight: 600;
	display: flex;
	align-items: center;
	gap: 8px;
}
.card .title .code {
	font-family: var(--font-mono);
	font-size: var(--fs-caption);
	color: var(--text-subtle);
	font-weight: 400;
}
.card .meta {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 12px;
	font-size: var(--fs-caption);
	color: var(--text-muted);
}
.card .desc {
	color: var(--text-body);
	line-height: var(--lh-normal);
}
.card .actions {
	display: flex;
	gap: 6px;
	margin-top: 4px;
}
.empty {
	padding: var(--space-6);
	text-align: center;
	color: var(--text-muted);
	border: 1px dashed var(--border-default);
	border-radius: var(--radius-md);
}
table.grid {
	width: 100%;
	border-collapse: collapse;
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md);
	overflow: hidden;
}
table.grid th,
table.grid td {
	text-align: left;
	padding: 7px 10px;
	border-bottom: 1px solid var(--border-subtle);
	font-size: var(--fs-body-sm);
	vertical-align: top;
}
table.grid th {
	font-size: var(--fs-overline);
	letter-spacing: var(--ls-overline);
	text-transform: uppercase;
	color: var(--text-subtle);
	font-weight: 500;
	background: var(--surface-sunken);
}
table.grid tr:last-child td {
	border-bottom: 0;
}
table.grid tr.click {
	cursor: pointer;
}
table.grid tr.click:hover td {
	background: var(--surface-hover);
}
.panel {
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md);
	padding: var(--space-4);
	margin-bottom: var(--space-4);
}
.panel h3 {
	margin: 0 0 var(--space-3);
	font: 600 var(--fs-body) / 1.2 var(--font-display);
}
.two {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--space-4);
	align-items: start;
}
.stats {
	display: flex;
	gap: var(--space-4);
	flex-wrap: wrap;
}
.stat {
	min-width: 110px;
}
.stat .v {
	font: 600 var(--fs-h3) / 1.1 var(--font-display);
}
.stat .k {
	font-size: var(--fs-caption);
	color: var(--text-muted);
}
pre.text {
	background: var(--surface-sunken);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-sm);
	padding: var(--space-3);
	font-family: var(--font-mono);
	font-size: 12px;
	line-height: 1.5;
	overflow: auto;
	max-height: 60vh;
	white-space: pre-wrap;
}
.md {
	line-height: var(--lh-relaxed);
	color: var(--text-body);
}
.md h1,
.md h2,
.md h3 {
	font-family: var(--font-display);
	letter-spacing: var(--ls-tight);
	margin: 1.2em 0 0.4em;
}
.md h1 {
	font-size: var(--fs-h2);
}
.md h2 {
	font-size: var(--fs-h3);
}
.md h3 {
	font-size: var(--fs-body);
}
.md table {
	border-collapse: collapse;
	margin: 0.6em 0;
}
.md td,
.md th {
	border: 1px solid var(--border-subtle);
	padding: 4px 8px;
	font-size: var(--fs-body-sm);
}
.md code {
	font-family: var(--font-mono);
	font-size: 12px;
	background: var(--surface-sunken);
	padding: 1px 4px;
	border-radius: 3px;
}
.md pre {
	background: var(--surface-sunken);
	padding: var(--space-3);
	border-radius: var(--radius-sm);
	overflow: auto;
}
.md pre code {
	background: none;
	padding: 0;
}

/* Forms */
.field label {
	display: block;
	font-size: var(--fs-overline);
	letter-spacing: var(--ls-overline);
	text-transform: uppercase;
	color: var(--text-subtle);
	margin-bottom: 4px;
}
.field .ctl {
	display: flex;
	gap: 4px;
	flex-wrap: wrap;
}
.field input,
.field select,
.field textarea {
	width: 100%;
	font: inherit;
	padding: 6px 8px;
	border: 1px solid var(--border-input);
	border-radius: var(--radius-xs);
	background: var(--white);
	color: var(--text);
}
.field textarea {
	min-height: 56px;
	resize: vertical;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
	outline: none;
	box-shadow: var(--ring-focus);
}
.field .note {
	font-size: var(--fs-caption);
	color: var(--text-muted);
	margin-top: 4px;
}
.field.wide {
	grid-column: 1 / -1;
}
.form {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: var(--space-3) var(--space-4);
}
.seg {
	display: inline-flex;
	border: 1px solid var(--border-input);
	border-radius: var(--radius-xs);
	overflow: hidden;
}
.seg button {
	border: 0;
	background: var(--white);
	padding: 5px 10px;
	cursor: pointer;
	font-size: var(--fs-caption);
}
.seg button + button {
	border-left: 1px solid var(--border-input);
}
.seg button.on {
	background: var(--accent-50);
	color: var(--accent-700);
	font-weight: 600;
}
.chk {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 8px;
	border: 1px solid var(--border-input);
	border-radius: var(--radius-pill);
	font-size: var(--fs-caption);
	cursor: pointer;
	background: var(--white);
}
.chk.on {
	background: var(--accent-50);
	border-color: var(--accent-400);
	color: var(--accent-700);
}
.rules {
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.rule {
	display: grid;
	grid-template-columns: 1.3fr 0.8fr 1.3fr auto;
	gap: 6px;
	align-items: center;
}
.rule select,
.rule input {
	font: inherit;
	padding: 5px 8px;
	border: 1px solid var(--border-input);
	border-radius: var(--radius-xs);
	background: var(--white);
}
.funnel {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: var(--fs-caption);
}
.funnel .row {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 8px;
}
.funnel .bar {
	display: flex;
	height: 8px;
	border-radius: 4px;
	overflow: hidden;
	background: var(--ink-150);
}
.funnel .bar i {
	display: block;
	height: 100%;
}
.funnel .bar .m {
	background: var(--success-500);
}
.funnel .bar .n {
	background: var(--danger-500);
}
.funnel .bar .u {
	background: var(--ink-300);
}

/* Workbench: stage, canvas, history */
#stage {
	position: relative;
	min-height: 0;
	overflow: hidden;
	background: var(--cream-board);
	background-image: radial-gradient(
		var(--cream-board-dot) 1px,
		transparent 1px
	);
	background-size: 18px 18px;
}
#scroll {
	height: 100%;
	overflow-x: auto;
	overflow-y: hidden;
}
#graph {
	display: block;
}
#history {
	position: absolute;
	left: var(--space-4);
	right: var(--space-4);
	bottom: 14px;
	height: 40px;
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: 0 var(--space-3);
	border-radius: var(--radius-md);
	background: var(--acrylic-light-strong);
	backdrop-filter: var(--acrylic-blur);
	box-shadow: var(--acrylic-shadow), var(--acrylic-edge);
}
#history .lbl {
	font-size: var(--fs-caption);
	color: var(--text-muted);
	white-space: nowrap;
}
#range {
	flex: 1;
	margin: 0;
	appearance: none;
	height: 3px;
	background: var(--ink-200);
	border-radius: 2px;
	outline: none;
}
#range::-webkit-slider-thumb {
	appearance: none;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--accent-600);
	border: 2px solid var(--white);
	box-shadow: 0 0 0 1px var(--accent-600);
	cursor: pointer;
}
#legend {
	position: absolute;
	left: var(--space-4);
	top: var(--space-3);
	display: flex;
	gap: var(--space-3);
	font-size: var(--fs-caption);
	color: var(--text-muted);
	padding: 4px 10px;
	border-radius: var(--radius-pill);
	background: rgb(var(--glass-rgb) / 0.7);
}
#legend span::before {
	content: "";
	display: inline-block;
	width: 9px;
	height: 9px;
	border-radius: 3px;
	margin-right: 5px;
	vertical-align: -1px;
	border: 1px solid;
}
#legend .in::before {
	background: var(--surface-sunken);
	border-color: var(--border-default);
}
#legend .agent::before {
	background: var(--accent-50);
	border-color: var(--accent-600);
}
#legend .op::before {
	background: var(--white);
	border-color: var(--ink-400);
	border-style: dashed;
}
#legend .out::before {
	background: var(--success-100);
	border-color: var(--success-500);
}
#legend .ghost::before {
	background: var(--warning-100);
	border-color: var(--warning-500);
	border-width: 2px;
}
#palette {
	position: absolute;
	right: var(--space-4);
	top: var(--space-3);
	display: flex;
	gap: 4px;
}
#palette .menu {
	position: absolute;
	right: 0;
	top: 34px;
	width: 300px;
	max-height: 60vh;
	overflow: auto;
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-lg);
	padding: 6px;
	z-index: 5;
}
#palette .menu .grp {
	padding: 8px 8px 2px;
	font-size: var(--fs-overline);
	letter-spacing: var(--ls-overline);
	text-transform: uppercase;
	color: var(--text-subtle);
}
#palette .menu button {
	display: block;
	width: 100%;
	text-align: left;
	border: 0;
	background: transparent;
	padding: 6px 8px;
	border-radius: var(--radius-xs);
	cursor: pointer;
}
#palette .menu button:hover {
	background: var(--surface-hover);
}
#palette .menu button small {
	display: block;
	color: var(--text-muted);
	font-size: var(--fs-caption);
}
#problems {
	position: absolute;
	left: var(--space-4);
	top: 44px;
	max-width: 420px;
	background: var(--warning-100);
	border: 1px solid var(--warning-500);
	color: var(--warning-600);
	border-radius: var(--radius-sm);
	padding: 6px 10px;
	font-size: var(--fs-caption);
}
#problems ul {
	margin: 2px 0 0 14px;
	padding: 0;
}

.node {
	cursor: pointer;
}
.node rect.body {
	stroke-width: 1.2;
	rx: 10;
	fill: var(--white);
	stroke: var(--border-default);
}
.node.in rect.body {
	fill: var(--surface-sunken);
}
.node.agent rect.body {
	fill: var(--accent-50);
	stroke: var(--accent-600);
}
.node.op rect.body {
	stroke: var(--ink-400);
	stroke-dasharray: 4 3;
}
.node.out rect.body {
	fill: var(--success-100);
	stroke: var(--success-500);
}
.node.ghost rect.body {
	stroke: var(--warning-500);
	stroke-width: 2;
	stroke-dasharray: none;
}
.node.ghost-removed {
	opacity: 0.35;
}
.node.ghost-removed rect.body {
	stroke: var(--danger-500);
	stroke-dasharray: 3 3;
}
.node.selected rect.body {
	stroke: var(--accent-600);
	stroke-width: 2.4;
	stroke-dasharray: none;
}
.node rect.ring {
	fill: none;
	stroke: var(--accent-300);
	stroke-width: 6;
	opacity: 0;
}
.node.selected rect.ring {
	opacity: 1;
}
.node.running rect.body {
	stroke: var(--accent-600);
	stroke-width: 2;
	animation: pulse 1.4s infinite;
}
.node.done rect.body {
	stroke: var(--success-500);
}
.node.failed rect.body {
	stroke: var(--danger-500);
}
.node.waiting rect.body {
	stroke: var(--warning-500);
	stroke-width: 2;
}
@keyframes pulse {
	50% {
		stroke-opacity: 0.35;
	}
}
.node text {
	font-size: 12.5px;
	fill: var(--text);
	font-family: var(--font-sans);
}
.node text.kind {
	font-size: 10.5px;
	fill: var(--text-muted);
	font-family: var(--font-mono);
}
.node .state {
	font-size: 10px;
	fill: var(--text-subtle);
	font-family: var(--font-mono);
	text-anchor: end;
}
.node .port {
	fill: var(--white);
	stroke: var(--ink-300);
	stroke-width: 1.2;
	cursor: crosshair;
}
.node .port:hover {
	stroke: var(--accent-600);
	fill: var(--accent-50);
}
.edge {
	fill: none;
	stroke: var(--ink-300);
	stroke-width: 1.4;
}
.edge.ghost {
	stroke: var(--warning-500);
	stroke-width: 2;
}
.edge.hot {
	stroke: var(--accent-600);
	stroke-width: 2;
}
.edge.drawing {
	stroke: var(--accent-400);
	stroke-dasharray: 4 3;
}

#sash {
	background: var(--border-subtle);
	cursor: row-resize;
}
#settings {
	background: var(--surface-card);
	border-top: 1px solid var(--border-subtle);
	height: 250px;
	display: grid;
	grid-template-rows: 40px 1fr;
	min-height: 0;
}
#settings.collapsed {
	height: 40px;
}
#settings .head {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: 0 var(--space-4);
	border-bottom: 1px solid var(--border-subtle);
}
#settings .head .title {
	font-weight: 600;
}
#settings .head .path {
	font-family: var(--font-mono);
	font-size: var(--fs-caption);
	color: var(--text-subtle);
}
#settings .body {
	overflow: auto;
	padding: var(--space-3) var(--space-4);
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: var(--space-3) var(--space-5);
	align-content: start;
}
#settings.collapsed .body {
	display: none;
}

/* Agent pane */
#agent {
	display: grid;
	grid-template-rows: 48px 1fr auto;
	border-left: 1px solid var(--border-subtle);
	background: var(--wash-stage);
	min-width: 0;
	min-height: 0;
}
#agent .head {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: 0 var(--space-3) 0 var(--space-4);
	border-bottom: 1px solid var(--border-subtle);
}
#agent .head .title {
	font-weight: 600;
	white-space: nowrap;
}
.agent-collapsed #agent .head .title,
.agent-collapsed #agent .head .status,
.agent-collapsed #agent .head select {
	display: none;
}
.agent-collapsed #agent .head {
	padding: 0 8px;
	justify-content: center;
}
.agent-collapsed #cells,
.agent-collapsed #composer {
	display: none;
}
.status {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font-size: var(--fs-caption);
	color: var(--text-muted);
}
.status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--success-500);
}
.status.busy::before {
	background: var(--warning-500);
	animation: pulse 1s infinite;
}
.status.off::before {
	background: var(--ink-300);
}
#agent .head select {
	font: inherit;
	font-size: var(--fs-caption);
	border: 1px solid var(--border-input);
	border-radius: var(--radius-xs);
	background: var(--white);
	padding: 3px 6px;
	max-width: 150px;
}
#cells {
	overflow: auto;
	padding: var(--space-3) 0;
	min-height: 0;
}
.cell {
	padding: var(--space-2) var(--space-4);
	border-left: 3px solid transparent;
}
.cell.current {
	border-left-color: var(--accent-600);
}
.cell .ask {
	margin-left: auto;
	max-width: 92%;
	background: var(--surface-sunken);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md) var(--radius-md) var(--radius-xs)
		var(--radius-md);
	padding: 8px 12px;
	line-height: var(--lh-normal);
}
.cell .ask .idx {
	font-family: var(--font-mono);
	font-size: var(--fs-caption);
	color: var(--text-subtle);
	margin-right: 6px;
}
.cell .reply {
	margin-top: 6px;
	max-width: 92%;
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius-md) var(--radius-md) var(--radius-md)
		var(--radius-xs);
	padding: 8px 12px;
	box-shadow: var(--shadow-xs);
	color: var(--text-body);
	line-height: var(--lh-normal);
	white-space: pre-wrap;
	word-break: break-word;
}
.cell .reply .who {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: var(--fs-caption);
	color: var(--text-emphasis);
	font-weight: 600;
	margin-bottom: 4px;
}
.cell .reply .who img {
	width: 14px;
	height: 14px;
}
.cell .reply .who .mode {
	margin-left: auto;
	font-family: var(--font-mono);
	font-weight: 400;
	color: var(--text-subtle);
}
.cell .reply.error {
	border-color: var(--danger-500);
}
.cell .tools {
	margin-top: 4px;
	display: flex;
	flex-direction: column;
	gap: 2px;
}
.cell .tools div {
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--text-subtle);
}
.patch {
	margin-top: 8px;
	border-top: 1px dashed var(--border-subtle);
	padding-top: 6px;
}
.patch .ops {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-bottom: 6px;
}
.patch .op {
	font-family: var(--font-mono);
	font-size: 11px;
	padding: 2px 7px;
	border-radius: var(--radius-pill);
	border: 1px solid;
}
.patch .op.add_node,
.patch .op.add_edge {
	background: var(--warning-100);
	border-color: var(--warning-500);
	color: var(--warning-600);
}
.patch .op.set,
.patch .op.settings {
	background: var(--accent-50);
	border-color: var(--accent-200);
	color: var(--accent-700);
}
.patch .op.remove_node,
.patch .op.remove_edge {
	background: var(--danger-100);
	border-color: var(--danger-500);
	color: var(--danger-600);
}
.patch .decide {
	display: flex;
	gap: 6px;
	align-items: center;
}
.patch .decided {
	font-size: var(--fs-caption);
	color: var(--text-muted);
}
.files {
	margin-top: 6px;
	font-size: var(--fs-caption);
}
.files a {
	display: inline-block;
	margin-right: 8px;
	font-family: var(--font-mono);
}
#composer {
	padding: var(--space-3) var(--space-3) var(--space-4);
}
#composer .scope {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin-bottom: 6px;
	padding: 2px 8px 2px 10px;
	border-radius: var(--radius-pill);
	background: var(--accent-50);
	color: var(--accent-700);
	font-size: var(--fs-caption);
	font-family: var(--font-mono);
}
#composer .scope button {
	border: 0;
	background: transparent;
	cursor: pointer;
	color: inherit;
	padding: 0 2px;
	font-size: 13px;
	line-height: 1;
}
#composer .box {
	border: 1px solid var(--border-input);
	border-radius: var(--radius-md);
	background: var(--white);
	padding: 8px 10px 8px;
	box-shadow: var(--shadow-sm);
}
#composer .box:focus-within {
	box-shadow: var(--ring-focus);
	border-color: var(--accent-600);
}
#composer textarea {
	width: 100%;
	border: 0;
	outline: 0;
	resize: none;
	font: inherit;
	line-height: var(--lh-normal);
	min-height: 24px;
	max-height: 140px;
	background: transparent;
	color: var(--text);
}
#composer .row {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 6px;
}
#composer .hint {
	font-size: var(--fs-caption);
	color: var(--text-subtle);
	margin-top: 6px;
}

/* Run page */
.run-grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 360px;
	gap: var(--space-4);
	align-items: start;
}
.run-grid > div {
	min-width: 0;
	overflow-wrap: anywhere;
}
.steps {
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.step {
	display: grid;
	grid-template-columns: 18px 1fr auto;
	gap: 8px;
	align-items: center;
	padding: 6px 8px;
	border-radius: var(--radius-sm);
	background: var(--surface-card);
	border: 1px solid var(--border-subtle);
}
.step .dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--ink-200);
	justify-self: center;
}
.step.running .dot {
	background: var(--accent-600);
	animation: pulse 1.2s infinite;
}
.step.done .dot {
	background: var(--success-500);
}
.step.failed .dot {
	background: var(--danger-500);
}
.step.waiting .dot {
	background: var(--warning-500);
}
.step .id {
	font-family: var(--font-mono);
	font-size: var(--fs-caption);
	color: var(--text-subtle);
}
.artifacts a {
	display: block;
	padding: 5px 0;
	border-bottom: 1px solid var(--border-subtle);
	font-size: var(--fs-body-sm);
}
.artifacts a:last-child {
	border-bottom: 0;
}
.artifacts .k {
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--text-subtle);
	margin-left: 6px;
}
.bands {
	display: flex;
	gap: 2px;
	height: 10px;
	border-radius: 5px;
	overflow: hidden;
}
.bands i {
	display: block;
}
.bands .likely_suitable {
	background: var(--success-500);
}
.bands .uncertain {
	background: var(--warning-500);
}
.bands .unlikely_suitable {
	background: var(--danger-500);
}
.bands .not_evaluable {
	background: var(--ink-300);
}

#toasts {
	position: fixed;
	right: 16px;
	bottom: 16px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	z-index: 50;
}
.toast {
	padding: 8px 12px;
	border-radius: var(--radius-sm);
	background: var(--ink-800);
	color: var(--white);
	font-size: var(--fs-body-sm);
	box-shadow: var(--shadow-lg);
}
.toast.warn {
	background: var(--warning-600);
}
.toast.danger {
	background: var(--danger-600);
}

.modal-back {
	position: fixed;
	inset: 0;
	background: rgb(0 0 0 / 0.3);
	display: grid;
	place-items: center;
	z-index: 40;
}
.modal {
	width: min(720px, 92vw);
	max-height: 86vh;
	overflow: auto;
	background: var(--surface-card);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lg);
	padding: var(--space-5);
}
.modal h3 {
	margin: 0 0 var(--space-3);
	font: 600 var(--fs-h3) / 1.2 var(--font-display);
}
.modal .foot {
	display: flex;
	gap: 8px;
	justify-content: flex-end;
	margin-top: var(--space-4);
}

/* Motion (ui/app/motion.ts, ports of motion-primitives) */
.tabular { font-variant-numeric: tabular-nums; }
.text-shimmer {
  --base-color: var(--text-subtle);
  --base-gradient-color: var(--text);
  --bg: linear-gradient(90deg, #0000 calc(50% - var(--spread)), var(--base-gradient-color), #0000 calc(50% + var(--spread)));
  display: inline-block; position: relative;
  background-image: var(--bg), linear-gradient(var(--base-color), var(--base-color));
  background-size: 250% 100%, auto; background-repeat: no-repeat, padding-box; background-position: 100% center;
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.status.busy .text-shimmer::before { display: none; }
.node .inner { transform-box: fill-box; transform-origin: center; }
#history .play { width: 26px; height: 26px; border: 0; border-radius: 50%; background: var(--accent-600); color: var(--on-bold); cursor: pointer; display: grid; place-items: center; font-size: 11px; flex: none; }
#history .play:disabled { background: var(--ink-200); cursor: default; }
#history .pos { font-family: var(--font-mono); font-size: var(--fs-caption); color: var(--text-muted); min-width: 56px; text-align: right; }
#history .ticks { position: relative; flex: 1; height: 24px; display: flex; align-items: center; }
#history .ticks i { position: absolute; top: 19px; width: 1px; height: 5px; background: var(--ink-200); }
#history .ticks i.done { background: var(--accent-400); }
#stage.replay #palette, #stage.replay #legend { opacity: .35; pointer-events: none; }
#stage.replay::after { content: "replay"; position: absolute; right: var(--space-4); bottom: 64px; font-family: var(--font-mono); font-size: var(--fs-caption); color: var(--accent-700); background: var(--accent-50); border: 1px solid var(--accent-200); border-radius: var(--radius-pill); padding: 2px 9px; }

/* Icons: Fluent (20px grid) and Health Icons (48px grid), coloured by currentColor. */
.fluent { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: -4px; }
.btn .fluent { width: 16px; height: 16px; vertical-align: -3px; margin-left: -2px; }
.btn.sm .fluent { width: 14px; height: 14px; vertical-align: -2px; }
.iconbtn .fluent { width: 16px; height: 16px; vertical-align: 0; }
.shelf .fluent { width: 18px; height: 18px; color: var(--text-muted); }
.shelf.active .fluent { color: var(--accent-700); }
.health { width: 18px; height: 18px; display: inline-block; vertical-align: -4px; color: var(--accent-700); }
.organ { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--brand-gradient-soft); margin-right: 8px; vertical-align: -7px; }
.organ .health { width: 16px; height: 16px; vertical-align: 0; }
.tile { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand-gradient-soft); color: var(--accent-700); flex: none; }
.tile .fluent { width: 16px; height: 16px; vertical-align: 0; }
.card .title .tile { margin-right: 2px; }
.agent-mark { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; background: var(--brand-gradient-soft); color: var(--accent-700); }
.agent-mark .fluent { width: 12px; height: 12px; vertical-align: 0; }

/* The rail: PharmaOS's cream with the CancerOS mesh kept as a faint tint,
   brand blobs drifting slowly over the cream-to-paper fade. Each layer's
   background-size is larger than the element and its position sweeps, so the
   blobs move without the gradients being repainted. Same recipe as
   canceros-chat-runtime's .rail. */
#rail {
	position: relative; isolation: isolate;
	background-color: var(--cream-50);
	background-image:
		radial-gradient(900px 900px at 50% 50%, rgba(117, 141, 250, 0.10) 0%, rgba(117, 141, 250, 0) 70%),
		radial-gradient(1100px 1100px at 50% 50%, rgba(117, 231, 239, 0.08) 0%, rgba(117, 231, 239, 0) 70%),
		radial-gradient(800px 800px at 50% 50%, rgba(107, 180, 247, 0.07) 0%, rgba(107, 180, 247, 0) 70%),
		radial-gradient(760px 760px at 50% 50%, rgba(168, 121, 250, 0.06) 0%, rgba(168, 121, 250, 0) 70%),
		radial-gradient(1000px 1000px at 50% 50%, rgb(var(--glass-rgb) / 0.40) 0%, rgb(var(--glass-rgb) / 0) 70%),
		linear-gradient(180deg, var(--cream-100) 0%, var(--cream-50) 100%);
	background-size: 400% 400%, 400% 400%, 400% 400%, 400% 400%, 400% 400%, 100% 100%;
	background-repeat: no-repeat;
	animation: railmesh 40s ease-in-out infinite alternate;
	border-right: 1px solid var(--cream-border);
}
@keyframes railmesh {
	0%   { background-position: 100% 0%, 0% 100%, 50% 60%, 0% 0%, 100% 100%, 0 0; }
	33%  { background-position: 40% 40%, 60% 60%, 100% 0%, 80% 100%, 0% 30%, 0 0; }
	66%  { background-position: 0% 100%, 100% 0%, 20% 100%, 100% 30%, 50% 0%, 0 0; }
	100% { background-position: 80% 100%, 100% 20%, 0% 30%, 20% 60%, 90% 80%, 0 0; }
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes runbar { 0% { transform: translateX(-100%); } 100% { transform: translateX(400%); } }
.shelf:hover { background: rgb(var(--glass-rgb) / 0.55); }
.shelf.active { background: var(--acrylic-light); box-shadow: var(--acrylic-edge), var(--shadow-xs); }
#rail .project select { background: rgb(var(--glass-rgb) / 0.7); border-color: var(--cream-border); }

/* Acrylic: a strong blur of what passes underneath, tinted cream. Bars,
   pills, menus and modals wear it; the stage and the page show through. */
#topbar { background: var(--acrylic-light); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); border-bottom: 1px solid rgb(var(--glass-rgb) / 0.6); box-shadow: var(--acrylic-edge), 0 1px 0 var(--cream-border); }
#agent .head { background: var(--acrylic-light); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--acrylic-edge); }
#legend, #palette .btn, #history, #problems { background: var(--acrylic-light); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--acrylic-shadow), var(--acrylic-edge); border-color: transparent; }
#palette .btn:hover { background: var(--acrylic-light-strong); }
#problems { background: var(--warning-100); border: 1px solid var(--warning-500); backdrop-filter: none; -webkit-backdrop-filter: none; box-shadow: var(--shadow-sm); }
#history { background: var(--acrylic-light-strong); }
/* The cascading menu: cream acrylic, the same glass as the callouts and modals. */
#palette .menu { background: var(--acrylic-light-strong); backdrop-filter: blur(40px) saturate(1.8); -webkit-backdrop-filter: blur(40px) saturate(1.8); border: 1px solid rgb(var(--glass-rgb) / 0.75); box-shadow: 0 16px 40px rgba(17, 19, 21, 0.16), inset 0 1px 0 rgb(var(--glass-rgb) / 0.9), var(--acrylic-edge); animation: rise var(--dur-base) var(--ease-out) both; }
#palette .menu button { display: flex; align-items: flex-start; gap: 10px; }
#palette .menu button:hover { background: rgb(var(--glass-rgb) / 0.78); }
#palette .menu button .tile { margin-top: 1px; }
#palette .menu button > span:last-child { min-width: 0; }
#composer .box { background: var(--acrylic-light-strong); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); border-color: rgb(var(--glass-rgb) / 0.75); box-shadow: var(--acrylic-shadow), var(--acrylic-edge); }
#composer .box:focus-within { box-shadow: var(--ring-focus), var(--acrylic-shadow); }
#settings { background: var(--acrylic-light); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); }
.cell .reply { background: rgb(var(--glass-rgb) / 0.7); backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1); border-color: rgb(var(--glass-rgb) / 0.8); box-shadow: var(--shadow-xs), var(--sheen-top); }
.modal-back { background: rgba(17, 19, 21, 0.32); backdrop-filter: var(--scrim-blur); -webkit-backdrop-filter: var(--scrim-blur); animation: fadein var(--dur-base) var(--ease-out) both; }
.modal { background: var(--acrylic-light-strong); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); border: 1px solid rgb(var(--glass-rgb) / 0.75); box-shadow: var(--acrylic-shadow), var(--acrylic-edge); animation: rise var(--dur-base) var(--ease-out) both; }
.toast { background: var(--acrylic-dark); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--acrylic-shadow); }
.toast.warn, .toast.danger { background-image: none; }
.panel:has(.stats) { background: var(--acrylic-light); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); border-color: transparent; box-shadow: var(--acrylic-shadow), var(--acrylic-edge); }
.card { box-shadow: var(--shadow-xs), var(--sheen-top); }
.card.click:hover { box-shadow: var(--shadow-md), var(--sheen-top); transform: translateY(-1px); transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }

/* The brand gradient, decorative only: progress, the deep tier, the running step. */
.step.running { position: relative; overflow: hidden; }
.step.running::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: 30%; border-radius: 2px; background: var(--brand-gradient); animation: runbar 1.4s ease-in-out infinite; }
.lozenge.deep { background: var(--brand-gradient); border-color: transparent; color: var(--on-bold); }
#history .play { background: var(--brand-gradient); }
#history .ticks i.done { background: var(--accent-400); }
