@import url("./panels/context-panel.css");

/* =============================================================================
   Studio + gallery — loaded after page-primitives.css
   A.1 extraction from studio.js injectStyles()

   Token snaps (OKLCH → nearest scale): see research/flywheel/notes/studio-a1-token-snaps.md
   ============================================================================= */

:root {
	/* Studio-only semantics (not promoted to admin-tokens unless reused) */
	--sg-editor-sidebar-width: 380px;
	--sg-things-sidebar-width: 280px;
	--sg-gallery-card-min: 280px;
	--sg-button-sm-size: 28px;
	--sg-backdrop: oklch(0 0 0 / 0.6);
	--sg-backdrop-dark: oklch(0.08 0.02 180 / 0.85);
	--sg-grid-columns: repeat(auto-fill, minmax(var(--sg-gallery-card-min), 1fr));
	--sg-card-aspect: 4 / 3;
	--sg-card-action-bg: oklch(0.30 0.02 180 / 0.85);
	--sg-card-action-hover-bg: oklch(0.22 0.03 180 / 0.95);
	--sg-card-action-bg-dark: oklch(0.14 0.03 180 / 0.9);
	--sg-card-action-hover-bg-dark: oklch(0.20 0.03 180 / 0.95);
	--sg-backend-border: rgba(255, 255, 255, 0.2);
	--sg-backend-bg: rgba(0, 0, 0, 0.5);
	--sg-backend-fg: rgba(255, 255, 255, 0.7);
	--sg-backend-hover-bg: rgba(255, 255, 255, 0.15);
	--sg-backend-active-bg: rgba(255, 255, 255, 0.9);
	--sg-backend-active-fg: rgba(0, 0, 0, 0.85);
	--sg-backend-active-border: rgba(255, 255, 255, 0.9);
	--sg-save-dirty-dark-hover: oklch(0.22 0.02 160);
	--sg-about-sidebar-width: 320px;
}

/* Gallery + DS Components catalog — pg-inset wrapper from primitives */
.pg-inset:has(#sgGrid),
.pg-inset:has(#dscGrid) {
	padding: var(--s-space-3);
	height: 100%;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* Compact toolbar: filter chips + count */
.sg-toolbar {
	display: flex;
	align-items: center;
	gap: var(--s-space-3);
	padding-bottom: var(--s-space-3);
	flex-shrink: 0;
}

.sg-filters {
	display: flex;
	gap: var(--s-space-1);
	flex-wrap: wrap;
	flex: 1;
}

.sg-toolbar-controls {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	margin-left: auto;
}

.sg-toolbar-btn {
	width: var(--sg-button-sm-size);
	height: var(--sg-button-sm-size);
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--s-radius-1);
	background: transparent;
	color: var(--s-color-fg-muted);
	cursor: pointer;
	border: 1px solid transparent;
	transition: var(--s-transition-colors);
}

.sg-toolbar-btn:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
}

.sg-toolbar-btn-active {
	background: var(--s-color-prominent-bg);
	color: var(--s-color-prominent-fg);
}

/* Gallery zoom — segmented variant (see components/zoom-control.js) */
.sg-gallery-zoom-host .sg-zoom {
	display: inline-flex;
	align-items: center;
}

.sg-zoom--segmented {
	gap: 2px;
	padding: 2px;
	background: var(--s-color-bg-subtle);
	border-radius: var(--s-radius-2);
}

.sg-zoom-step {
	min-width: 26px;
	height: 24px;
	padding: 0 var(--s-space-1);
	border: none;
	border-radius: var(--s-radius-1);
	background: transparent;
	color: var(--s-color-fg-muted);
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	font-variant-numeric: tabular-nums;
	cursor: pointer;
	transition:
		background 0.14s,
		color 0.14s;
}

.sg-zoom-step:hover {
	color: var(--s-color-fg-primary);
}

.sg-zoom-step--active {
	background: var(--s-color-bg-card);
	color: var(--s-color-fg-primary);
	box-shadow: 0 1px 2px oklch(0 0 0 / 0.06);
}

/* Stepper variant (optional reuse) */
.sg-zoom--stepper {
	gap: var(--s-space-1);
	align-items: center;
	color: var(--s-color-fg-soft);
}

.sg-zoom-stepper-btn {
	width: 24px;
	height: 24px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: none;
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-muted);
	font-size: var(--s-font-size-1);
	line-height: 1;
	cursor: pointer;
}

.sg-zoom-stepper-btn:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
}

.sg-zoom-stepper-label {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	min-width: 2.5rem;
	text-align: center;
}

.sg-count {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	color: var(--s-color-fg-soft);
	flex-shrink: 0;
	margin-inline-start: var(--s-space-2);
	padding-inline-start: var(--s-space-2);
	border-inline-start: 1px solid var(--s-color-border-subtle);
}

/* About sidebar open — hide gallery toolbar right cluster (cog, zoom, count) so it isn’t covered */
.sg-gallery-layout--about-open .sg-toolbar-controls {
	display: none;
}

.sg-filter-btn {
	font-size: var(--s-font-size-min);
	padding: var(--s-space-1) var(--s-space-2);
	border-radius: var(--s-radius-1);
	background: transparent;
	color: var(--s-color-fg-muted);
	cursor: pointer;
	transition: var(--s-transition-colors);
	border: 1px solid transparent;
}

.sg-filter-btn:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
}

.sg-filter-active {
	background: var(--s-color-prominent-bg);
	color: var(--s-color-prominent-fg);
}

.sg-filter-active:hover {
	background: var(--s-color-prominent-bg-hover);
	color: var(--s-color-prominent-fg);
}

/* Gallery + optional About sidebar */
.sg-gallery-layout {
	display: grid;
	grid-template-columns: 1fr;
	flex: 1;
	min-height: 0;
	transition: grid-template-columns var(--s-duration-fast) var(--s-ease-out);
}

.sg-gallery-layout--about-open {
	grid-template-columns: 1fr var(--sg-about-sidebar-width);
}

/* ── Responsive (see admin-tokens §14c: 1024 = tablet-lg, 900 = tablet-m, 600 = mobile-lg) ── */
@media (max-width: 1024px) {
	.sg-toolbar {
		flex-wrap: wrap;
		align-items: flex-start;
		row-gap: var(--s-space-2);
	}

	.sg-filters {
		flex: 1 1 100%;
		min-width: 0;
	}

	.sg-toolbar-controls {
		margin-left: 0;
		width: 100%;
		justify-content: flex-end;
		flex-wrap: wrap;
		gap: var(--s-space-1);
	}

	.sg-gallery-layout--about-open {
		grid-template-columns: 1fr;
		grid-template-rows: minmax(0, 1fr) minmax(140px, 42vh);
	}

	.sg-about-panel {
		border-left: none;
		border-top: 1px solid var(--s-color-border-subtle);
		min-height: 0;
	}
}

@media (max-width: 900px) {
	.pg-inset:has(#sgGrid),
	.pg-inset:has(#dscGrid) {
		padding: var(--s-space-2);
	}

	:root {
		--sg-gallery-card-min: 240px;
	}
}

@media (max-width: 600px) {
	:root {
		--sg-gallery-card-min: 200px;
	}

	.sg-count {
		border-inline-start: none;
		padding-inline-start: 0;
		margin-inline-start: 0;
		width: 100%;
	}
}

.sg-gallery-main {
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
}

/* Grid — fills remaining space, scrollable */
.sg-grid {
	display: grid;
	grid-template-columns: var(--sg-grid-columns, repeat(auto-fill, minmax(var(--sg-gallery-card-min), 1fr)));
	gap: var(--s-space-3);
	flex: 1;
	overflow-y: auto;
	align-content: start;
	/* start — don’t stretch cards to row height; else preview flex-grows past aspect-ratio and leaves empty iframe space */
	align-items: start;
}

/* Design System component catalog — tighter card width band than experiment gallery */
.sg-grid--catalog-ds {
	grid-template-columns: repeat(auto-fill, minmax(220px, 280px));
	gap: var(--s-space-4);
}

/* Dark mode grid — brandscale dark surfaces, creamscale text */
.sg-grid-dark .sg-card {
	background: color-mix(in oklch, var(--s-brand-950) 95%, transparent);
}

/* dark gradient fade removed */

.sg-grid-dark .sg-card-number,
.sg-grid-dark .sg-card-name {
	color: var(--s-cream-400);
}

.sg-grid-dark .sg-card-badge {
	background: var(--s-brand-925);
	color: var(--s-cream-600);
}

.sg-grid-dark .sg-card-preview {
	background: var(--s-brand-975);
}

.sg-grid-dark .sg-card-iframe {
	background: var(--s-brand-975);
}
.sg-grid-dark .sg-card:hover {
	background: var(--s-brand-925);
}

/* ── About sidebar ─────────────────── */
.sg-about-panel {
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 0;
	border-left: 1px solid var(--s-color-border-subtle);
	background: var(--s-surface-elevation-1-bg);
	overflow: hidden;
}

.sg-about-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--s-space-3) var(--s-space-4);
	border-bottom: 1px solid var(--s-color-border-subtle);
	flex-shrink: 0;
}

.sg-about-header h3 {
	font-size: var(--s-font-size-1);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	margin: 0;
}

.sg-about-body {
	flex: 1;
	overflow-y: auto;
	padding: var(--s-space-4);
	font-size: var(--s-font-size-0);
	line-height: 1.7;
	color: var(--s-color-fg-primary);
}

.sg-about-body h1 {
	font-size: var(--s-font-size-2);
	font-weight: var(--s-font-weight-semibold);
	margin: 0 0 var(--s-space-3) 0;
	color: var(--s-color-fg-primary);
}

.sg-about-body h2 {
	font-size: var(--s-font-size-1);
	font-weight: var(--s-font-weight-semibold);
	margin: var(--s-space-5) 0 var(--s-space-2) 0;
	color: var(--s-color-fg-primary);
}

.sg-about-body h3 {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-semibold);
	margin: var(--s-space-4) 0 var(--s-space-2) 0;
	color: var(--s-color-fg-primary);
}

.sg-about-body p {
	margin: 0 0 var(--s-space-3) 0;
	color: var(--s-color-fg-primary);
}

.sg-about-body strong {
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
}

.sg-about-body em {
	font-style: italic;
}

.sg-about-body hr {
	border: none;
	border-top: 1px solid var(--s-color-border-subtle);
	margin: var(--s-space-5) 0;
}

.sg-about-body ul {
	margin: 0 0 var(--s-space-3) 0;
	padding-left: var(--s-space-4);
}

.sg-about-body li {
	margin-bottom: var(--s-space-2);
}

.sg-about-link {
	color: var(--s-color-accent-fg);
	text-decoration: none;
	cursor: pointer;
}

.sg-about-link:hover {
	text-decoration: underline;
}

.sg-about-footer {
	padding: var(--s-space-3) var(--s-space-4);
	border-top: 1px solid var(--s-color-border-subtle);
	flex-shrink: 0;
}

.sg-about-footer a {
	font-size: var(--s-font-size-0);
	color: var(--s-color-accent-fg);
	text-decoration: none;
}

.sg-about-footer a:hover {
	text-decoration: underline;
}

/* Floating about (editor / entity views — no gallery grid layout) */
.sg-about-backdrop {
	position: fixed;
	inset: 0;
	z-index: 45;
	background: oklch(0 0 0 / 0.14);
}

.sg-about-panel--floating {
	position: fixed;
	top: 37px;
	right: 0;
	z-index: 46;
	width: min(28rem, 92vw);
	height: calc(100vh - 37px);
	max-height: calc(100vh - 37px);
	box-shadow: -8px 0 28px oklch(0 0 0 / 0.08);
	border-left: 1px solid var(--s-color-border-subtle);
}

[data-theme="dark"] .sg-about-panel {
	background: var(--s-brand-950);
	border-color: var(--s-brand-925);
}

[data-theme="dark"] .sg-about-panel--floating {
	border-color: var(--s-brand-925);
	box-shadow: -8px 0 28px oklch(0 0 0 / 0.35);
}

[data-theme="dark"] .sg-about-body {
	color: var(--s-cream-400);
}

[data-theme="dark"] .sg-about-body h1,
[data-theme="dark"] .sg-about-body h2,
[data-theme="dark"] .sg-about-body h3,
[data-theme="dark"] .sg-about-body strong {
	color: var(--s-cream-200);
}

[data-theme="dark"] .sg-about-body p {
	color: var(--s-cream-400);
}

[data-theme="dark"] .sg-about-body hr {
	border-color: var(--s-brand-925);
}

/*
 * Catalog card family: .s-catalog-card marks grid tiles shared between Studio
 * gallery (createGalleryCard — .sg-card) and DS Components (createCatalogCard — .dsc-card).
 */

/* Card height follows preview aspect-ratio; footer is overlaid, not a flex sibling */
.sg-card {
	border-radius: var(--s-radius-3);
	background: var(--s-color-bg-card);
	overflow: clip;
	transition: background 0.3s ease;
	position: relative;
	display: block;
	width: 100%;
	height: auto;
	min-height: 0;
}

/* Preview box height = width ÷ aspect-ratio only (no flex-grow past that) */
.sg-card-preview {
	position: relative;
	width: 100%;
	aspect-ratio: var(--sg-card-aspect, 4 / 3);
	overflow: hidden;
	cursor: pointer;
	background: var(--s-color-bg-subtle);
	transition: background 0.3s ease;
}

/* Loading skeleton — pulse until iframe has fired load (see data-preview-ready on iframe) */
.sg-card-preview::before {
	content: "";
	position: absolute;
	inset: 0;
	background: var(--s-color-bg-subtle);
	animation: sg-skeleton-pulse 1.8s ease-in-out infinite;
	z-index: 0;
	transition: opacity var(--s-duration-fast) var(--s-ease-out);
	pointer-events: none;
}

.sg-card-preview:has(iframe[data-preview-ready])::before {
	opacity: 0;
}

.sg-grid-dark .sg-card-preview::before {
	background: var(--s-brand-950);
}

@keyframes sg-skeleton-pulse {
	0%,
	100% {
		opacity: 0.6;
	}
	50% {
		opacity: 0.3;
	}
}

.sg-card-iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: none;
	pointer-events: none;
	background: var(--s-cream-50);
	transition: filter var(--s-duration-fast) var(--s-ease-out);
	z-index: 1;
	box-sizing: border-box;
}

.sg-card:hover .sg-card-iframe {
	filter: brightness(1.06);
}

/* Hover overlay with action buttons — no color overlay, just buttons */
.sg-card-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2;
}

.sg-card-actions {
	display: flex;
	gap: var(--s-space-2);
	opacity: 0;
	transform: translateY(var(--s-space-1));
	transition: opacity var(--s-duration-fast) var(--s-ease-out),
	            transform var(--s-duration-fast) var(--s-ease-out);
}

.sg-card:hover .sg-card-actions {
	opacity: 1;
	transform: translateY(0);
}

/* Gallery overlay actions — createIconButton ghost + studio semantics */
.sg-card-overlay .s-icon-btn--ghost {
	background: var(--sg-card-action-bg);
	color: var(--s-cream-25);
}
.sg-card-overlay .s-icon-btn--ghost:hover {
	background: var(--sg-card-action-hover-bg);
	color: var(--s-cream-25);
}
.sg-grid-dark .sg-card-overlay .s-icon-btn--ghost {
	background: var(--sg-card-action-bg-dark);
}
.sg-grid-dark .sg-card-overlay .s-icon-btn--ghost:hover {
	background: var(--sg-card-action-hover-bg-dark);
}

/*
 * Footer — name + version (badges in title row). Cog → minimal: footer until hover/focus.
 * Tag chips live in .sg-card-tags (top-left on preview), not in the footer.
 */
.sg-card-info {
	display: flex;
	flex-direction: column;
	gap: var(--s-space-1);
	padding: var(--s-space-2) var(--s-space-3);
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 3;
	background: var(--s-color-bg-card);
	opacity: 1;
	transform: none;
	pointer-events: auto;
	transition: background var(--s-duration-fast) var(--s-ease-out);
}

.sg-grid-dark .sg-card-info {
	background: color-mix(in oklch, var(--s-brand-950) 95%, transparent);
}
.sg-card-info-title {
	display: flex;
	align-items: baseline;
	gap: var(--s-space-2);
	min-width: 0;
}

/* Lab + extraction chips — top-left overlay, translucent (hidden when cog minimal mode is on) */
.sg-card-tags {
	position: absolute;
	top: var(--s-space-2);
	left: var(--s-space-2);
	z-index: 3;
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: flex-start;
	gap: var(--s-space-1);
	max-width: calc(100% - var(--s-space-4));
	pointer-events: none;
}

.sg-card-tags .s-badge {
	background: color-mix(in oklch, var(--s-color-bg-card) 35%, transparent);
	color: var(--s-color-fg-primary);
	border: 1px solid color-mix(in oklch, var(--s-color-border-subtle) 55%, transparent);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	box-shadow: none;
}

.sg-card-tags .s-badge--info {
	background: color-mix(in oklch, var(--s-color-accent-fg) 12%, transparent);
	color: var(--s-color-fg-primary);
	border-color: color-mix(in oklch, var(--s-color-accent-fg) 22%, transparent);
}

.sg-grid-dark .sg-card-tags .s-badge {
	background: color-mix(in oklch, var(--s-brand-950) 45%, transparent);
	color: var(--s-cream-200);
	border-color: color-mix(in oklch, var(--s-cream-400) 25%, transparent);
}

.sg-grid-dark .sg-card-tags .s-badge--info {
	background: color-mix(in oklch, var(--s-brand-850) 55%, transparent);
	color: var(--s-cream-200);
	border-color: color-mix(in oklch, var(--s-brand-700) 50%, transparent);
}

/* Ontology phenomenon chips — green outline, aligned with Context tags */
.sg-card-tags .s-badge--success.s-badge--outline {
	background: color-mix(in oklch, var(--s-color-success-fg, var(--s-brand-500)) 10%, transparent);
	color: var(--s-color-fg-primary);
	border-color: color-mix(in oklch, var(--s-color-success-fg, var(--s-brand-500)) 35%, transparent);
}

.sg-grid-dark .sg-card-tags .s-badge--success.s-badge--outline {
	background: color-mix(in oklch, var(--s-brand-500) 14%, transparent);
	color: var(--s-cream-200);
	border-color: color-mix(in oklch, var(--s-brand-400) 45%, transparent);
}

.sg-grid--hide-info .sg-card-tags {
	display: none !important;
}

/* Minimal mode (toolbar cog): hide footer until hover/focus */
.sg-grid--hide-info .sg-card-info {
	opacity: 0;
	transform: translateY(6px);
	pointer-events: none;
	transition:
		opacity var(--s-duration-fast) var(--s-ease-out),
		transform var(--s-duration-fast) var(--s-ease-out),
		background var(--s-duration-fast) var(--s-ease-out);
}

.sg-grid--hide-info .sg-card:hover .sg-card-info,
.sg-grid--hide-info .sg-card:focus-within .sg-card-info {
	opacity: 1;
	transform: translateY(0);
	pointer-events: auto;
}

@media (hover: none) {
	.sg-grid--hide-info .sg-card-info {
		opacity: 1;
		transform: none;
		pointer-events: auto;
	}
}

.sg-card-number {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	color: var(--s-color-fg-soft);
	flex-shrink: 0;
}

.sg-card-name {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-primary);
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sg-card-badge {
	font-size: var(--s-font-size-min);
	padding: 1px var(--s-space-1);
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-muted);
	white-space: nowrap;
	flex-shrink: 0;
}

.sg-card-version {
	font-family: var(--s-font-mono);
}

.sg-card-lab {
	font-weight: var(--s-font-weight-medium);
}

/* Lab accent on preview bottom edge */
/* Lab color indicators removed — cards rely on badge text instead */

/* ── Lightbox ────────────────────────── */
.sg-lightbox {
	position: fixed;
	inset: 0;
	/* Above shell-header (1000 on mobile drawer) — was --s-z-modal (510), which trapped controls under chrome */
	z-index: var(--s-z-max);
	display: flex;
	flex-direction: column;
	animation: sg-fade-in var(--s-duration-fast) var(--s-ease-out);
}

.sg-lb-backdrop {
	position: absolute;
	inset: 0;
	background: var(--sg-backdrop);
	z-index: 0;
}

.sg-lb-container {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	width: 100%;
}

.sg-lb-header {
	display: flex;
	align-items: center;
	gap: var(--s-space-3);
	min-width: 0;
	width: 100%;
}

.sg-lb-title {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	flex: 1 1 auto;
	min-width: 0;
	flex-wrap: wrap;
}

.sg-lb-title-sep {
	color: var(--s-color-fg-soft);
	opacity: 0.55;
	user-select: none;
}

.sg-lb-number {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
}

.sg-lb-name {
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sg-lb-lab {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-muted);
}

/* Lab + separator — grouped for a clean second line on narrow lightbox headers */
.sg-lb-title-meta {
	display: inline-flex;
	align-items: center;
	gap: var(--s-space-1);
	min-width: 0;
}

.sg-lb-version-bar {
	display: flex;
	gap: var(--s-space-1);
	align-items: center;
	flex-wrap: wrap;
	flex: 0 1 auto;
	min-width: 0;
	justify-content: center;
}

.sg-lb-version-picker {
	display: inline-flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--s-space-2);
	max-width: 100%;
	/* Keep count + select on the same vertical center as toolbar icons */
	line-height: 1;
}

.sg-lb-version-count {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	line-height: var(--s-line-height-snug, 1.35);
	font-variant-numeric: tabular-nums;
	color: var(--s-color-fg-soft);
	white-space: nowrap;
	flex-shrink: 0;
}

.sg-lb-version-only-label {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-muted);
	white-space: nowrap;
}

.sg-lb-version-select-host {
	min-width: 0;
	flex: 0 1 auto;
	max-width: min(10rem, 38vw);
	position: relative;
	z-index: 2;
}

.sg-lb-version-select-host .s-select {
	min-width: 0;
	width: 100%;
}

.sg-lb-toolbar {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 2px;
	flex: 0 0 auto;
	flex-shrink: 0;
	padding-inline-end: var(--s-space-1);
}

.sg-lb-toolbar .s-icon-btn {
	flex-shrink: 0;
	overflow: visible;
}

.sg-lb-toolbar .s-icon-btn svg {
	overflow: visible;
}

.sg-lb-toolbar > span {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 28px;
	overflow: visible;
}

.sg-lb-btn {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	padding: var(--s-space-2) var(--s-space-3);
	border-radius: var(--s-radius-2);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	background: var(--s-color-bg-subtle);
	cursor: pointer;
	transition: var(--s-transition-colors);
}

.sg-lb-btn:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
}

.sg-lb-close:hover {
	color: var(--s-color-error);
}

.sg-lb-body {
	flex: 1;
	display: flex;
	align-items: stretch;
	min-height: 0;
	position: relative;
}

.sg-lb-nav {
	position: relative;
	align-self: stretch;
	width: 44px;
	min-width: 44px;
	display: flex;
	flex-direction: column;
	background: transparent;
	color: var(--s-color-fg-soft);
	flex-shrink: 0;
	z-index: 5;
	pointer-events: auto;
}

/* Full-column hit target — previous small centered icon missed most clicks */
.sg-lb-nav-btn {
	flex: 1;
	width: 100%;
	min-height: 3rem;
	margin: 0;
	padding: 0;
	border: none;
	border-radius: var(--s-radius-2);
	background: transparent;
	color: inherit;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: color var(--s-duration-fast) var(--s-ease-out),
		background var(--s-duration-fast) var(--s-ease-out);
}

.sg-lb-nav-btn:hover:not(:disabled) {
	color: var(--s-color-fg-primary);
	background: var(--s-color-bg-subtle);
}

.sg-lb-nav-btn:focus-visible {
	outline: 2px solid var(--s-color-focus);
	outline-offset: 2px;
}

.sg-lb-nav-btn:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

.sg-lb-nav-btn svg {
	display: block;
	flex-shrink: 0;
}

.sg-lb-viewport {
	flex: 1;
	min-width: 0;
	display: flex;
}

.sg-lb-viewport iframe {
	width: 100%;
	height: 100%;
	border: none;
	background: var(--s-color-bg-app);
}

.sg-lb-details-off {
	opacity: 0.5;
}

.sg-lb-footer {
	display: flex;
	align-items: center;
	gap: var(--s-space-4);
	padding: var(--s-space-2) var(--s-space-5);
	background: var(--s-surface-elevation-1-bg);
	border-top: 1px solid var(--s-color-border-subtle);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
}

.sg-lb-counter {
	font-family: var(--s-font-mono);
}

/* Dark lightbox — brandscale surfaces, creamscale text */
.sg-lb-dark .sg-lb-backdrop {
	background: var(--sg-backdrop-dark);
}

.sg-lb-dark .sg-lb-header,
.sg-lb-dark .sg-lb-footer {
	background: var(--s-brand-950);
	border-color: var(--s-brand-925);
}

.sg-lb-dark .sg-lb-number,
.sg-lb-dark .sg-lb-counter {
	color: var(--s-cream-700);
}

.sg-lb-dark .sg-lb-name {
	color: var(--s-cream-200);
}

.sg-lb-dark .sg-lb-lab,
.sg-lb-dark .sg-lb-pipeline,
.sg-lb-dark .sg-lb-subject,
.sg-lb-dark .sg-lb-tags {
	color: var(--s-cream-700);
}

.sg-lb-dark .sg-lb-title-sep {
	color: var(--s-cream-600);
}

.sg-lb-dark .sg-lb-version-count,
.sg-lb-dark .sg-lb-version-only-label {
	color: var(--s-cream-700);
}

.sg-lb-dark .sg-lb-btn {
	background: var(--s-brand-925);
	color: var(--s-cream-600);
}

.sg-lb-dark .sg-lb-btn:hover {
	background: var(--s-brand-900);
	color: var(--s-cream-200);
}

.sg-lb-dark .sg-lb-nav-btn:hover:not(:disabled) {
	background: var(--s-brand-925);
	color: var(--s-cream-200);
}

.sg-lb-dark .sg-lb-nav {
	color: var(--s-cream-800);
}

.sg-lb-dark .sg-lb-viewport iframe {
	background: var(--s-brand-975);
}

/* ── Editor (inline, replaces gallery) ─── */
.sg-editor {
	display: flex;
	flex-direction: column;
	height: 100%;
	width: 100%;
	background: var(--s-color-bg-app);
}

.sg-editor-header {
	display: flex;
	align-items: center;
	gap: var(--s-space-3);
	padding: var(--s-space-1) var(--s-space-2);
	background: var(--s-surface-elevation-1-bg);
	border-bottom: 1px solid var(--s-color-border-subtle);
	flex-shrink: 0;
}

/* ── Mode switcher (Primitive / Thing / Data Visualization / Animation) ── */
.sg-editor-mode-switcher {
	display: flex;
	gap: var(--s-space-1);
	background: var(--s-color-bg-subtle);
	border-radius: var(--s-radius-2);
	padding: var(--s-space-1);
}

/* ── Save button ── */
.sg-editor-save-btn {
	display: flex;
	align-items: center;
	gap: var(--s-space-1);
	padding: var(--s-space-1) var(--s-space-3);
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-mono);
	border-radius: var(--s-radius-1);
	background: transparent;
	color: var(--s-color-fg-muted);
	cursor: pointer;
	border: 1px solid var(--s-color-border-subtle);
	transition: background 0.15s, color 0.15s, border-color 0.15s;
	white-space: nowrap;
}

.sg-editor-save-btn:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
	border-color: var(--s-color-fg-muted);
}

.sg-editor-save-btn--dirty {
	color: var(--s-color-accent-active);
	border-color: var(--s-color-accent-active);
}

.sg-editor-save-btn--dirty:hover {
	background: var(--s-color-success-bg);
	color: var(--s-color-accent-active);
}

[data-theme="dark"] .sg-editor-save-btn--dirty:hover {
	background: var(--sg-save-dirty-dark-hover);
}

.sg-editor-icon-btn,
.sg-editor-close {
	width: var(--sg-button-sm-size);
	height: var(--sg-button-sm-size);
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--s-radius-1);
	background: transparent;
	color: var(--s-color-fg-muted);
	cursor: pointer;
	border: 1px solid transparent;
	transition: var(--s-transition-colors);
	flex-shrink: 0;
}

.sg-editor-icon-btn:hover,
.sg-editor-close:hover {
	background: var(--s-color-hover-bg);
	color: var(--s-color-fg-primary);
}

/* Editor mode switcher — createTabs pill (see .sg-editor-mode-switcher .s-tabs below) */

/* ── Editor footer (experiment info bar) ── */
.sg-editor-footer {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	padding: var(--s-space-1) var(--s-space-3);
	background: var(--s-surface-elevation-1-bg);
	border-top: 1px solid var(--s-color-border-subtle);
	flex-shrink: 0;
	min-height: var(--sg-button-sm-size);
	overflow: hidden;
}

.sg-footer-name {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.sg-footer-version {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	white-space: nowrap;
}

.sg-footer-sep {
	width: var(--s-border-thin);
	height: var(--s-space-4);
	background: var(--s-color-border-subtle);
	flex-shrink: 0;
}

.sg-footer-tag {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
	white-space: nowrap;
}

.sg-footer-pipeline {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
	margin-left: auto;
	white-space: nowrap;
}

/* Legacy breadcrumb classes kept for standalone entity views */
.sg-editor-breadcrumb {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	min-width: 0;
	margin-left: var(--s-space-2);
}

.sg-editor-breadcrumb:empty {
	display: none;
}

.sg-breadcrumb-sep {
	color: var(--s-color-fg-soft);
	font-size: var(--s-font-size-0);
}

.sg-breadcrumb-name {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.sg-breadcrumb-version {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
}

.sg-breadcrumb-tag {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	padding: 0 var(--s-space-1);
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-soft);
}

.sg-editor-header-actions {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	margin-left: auto;
	flex-shrink: 0;
}

.sg-editor-body {
	flex: 1;
	min-height: 0;
	overflow: hidden;
}

/* ── Things mode ─────────────────────── */
.sg-things-layout {
	display: grid;
	grid-template-columns: 1fr var(--sg-things-sidebar-width);
	height: 100%;
	min-height: 0;
}

.sg-things-main {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--s-space-6);
	min-height: 0;
}

.sg-things-dropzone {
	width: 100%;
	max-width: calc(var(--s-space-7) * 9);
	border: 2px dashed var(--s-color-border-subtle);
	border-radius: var(--s-radius-3);
	padding: var(--s-space-6) var(--s-space-6);
	text-align: center;
	transition: border-color 0.15s, background 0.15s;
}

.sg-things-dropzone:hover,
.sg-things-dropzone.sg-things-dropzone--dragover {
	border-color: var(--s-color-fg-muted);
	background: var(--s-color-bg-subtle);
}

.sg-things-dropzone-content h3 {
	font-size: var(--s-font-size-2);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	margin: var(--s-space-3) 0 var(--s-space-2);
}

.sg-things-dropzone-content p {
	font-size: var(--s-font-size-1);
	color: var(--s-color-fg-muted);
	line-height: 1.5;
	margin: 0 0 var(--s-space-4);
}

.sg-things-formats {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-space-1);
	justify-content: center;
}

.sg-things-format-tag {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	padding: 2px var(--s-space-2);
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-muted);
}

.sg-things-sidebar {
	border-left: 1px solid var(--s-color-border-subtle);
	padding: var(--s-space-4);
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: var(--s-space-5);
}

.sg-things-chat-hint {
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	margin: 0 0 var(--s-space-2);
}

.sg-things-examples {
	display: flex;
	flex-direction: column;
	gap: var(--s-space-1);
}

.sg-things-example-btn {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	text-align: left;
	padding: var(--s-space-2) var(--s-space-3);
	border: 1px solid var(--s-color-border-subtle);
	border-radius: var(--s-radius-2);
	background: var(--s-color-bg-card);
	color: var(--s-color-fg-primary);
	cursor: pointer;
	transition: border-color 0.15s, background 0.15s;
}

.sg-things-example-btn:hover {
	border-color: var(--s-color-fg-muted);
	background: var(--s-color-bg-subtle);
}

.sg-things-pipeline-info h4 {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-primary);
	margin: 0 0 var(--s-space-2);
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.sg-things-pipeline-steps {
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	line-height: 1.7;
	padding-left: var(--s-space-4);
	margin: 0;
}

.sg-things-pipeline-steps li {
	padding-left: var(--s-space-1);
}

/* Thing preview (editing existing) */
.sg-thing-preview {
	position: relative;
	width: 100%;
	height: 100%;
	min-height: 0;
}

.sg-thing-preview-iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: none;
	display: block;
	background: var(--s-color-bg-app);
}

/* Full-bleed iframe (animation / morph workspace) */
.sg-studio-embed-iframe {
	width: 100%;
	height: 100%;
	border: none;
	display: block;
}

/* Floating backend switcher (bottom-right corner) */
.sg-thing-backend-float {
	position: absolute;
	bottom: var(--s-space-3);
	right: var(--s-space-3);
	display: flex;
	gap: 1px;
	z-index: 1;
}

.sg-thing-backend-btn {
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-mono);
	padding: var(--s-space-1) var(--s-space-3);
	border: 1px solid var(--sg-backend-border);
	background: var(--sg-backend-bg);
	color: var(--sg-backend-fg);
	cursor: pointer;
	transition: background 0.1s, color 0.1s, border-color 0.1s;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
}

.sg-thing-backend-btn:first-child {
	border-radius: var(--s-radius-2) 0 0 var(--s-radius-2);
}

.sg-thing-backend-btn:last-child {
	border-radius: 0 var(--s-radius-2) var(--s-radius-2) 0;
}

.sg-thing-backend-btn:not(:first-child) {
	border-left: none;
}

.sg-thing-backend-btn:hover {
	background: var(--sg-backend-hover-bg);
	color: var(--s-cream-25);
}

.sg-thing-backend-btn--active {
	background: var(--sg-backend-active-bg);
	color: var(--sg-backend-active-fg);
	border-color: var(--sg-backend-active-border);
}

.sg-thing-backend-btn--active:hover {
	background: var(--s-cream-25);
	color: var(--sg-backend-active-fg);
}

/* ── Sidebar tabs ──────────────────────── */
.sg-things-sidebar-tabs {
	border-bottom: 1px solid var(--s-color-border-subtle);
	flex-shrink: 0;
	padding: 0 var(--s-space-2);
}

.sg-things-sidebar-tabs .s-tabs {
	width: 100%;
}

.sg-things-sidebar-tabs .s-tabs__list {
	gap: var(--s-space-1);
}

.sg-things-sidebar-panels {
	flex: 1;
	min-height: 0;
	overflow: hidden;
	position: relative;
}

.sg-things-sidebar-panel {
	display: none;
	flex-direction: column;
	height: 100%;
	overflow-y: auto;
	padding: var(--s-space-4);
}

.sg-things-sidebar-panel--active {
	display: flex;
}

/* Chat panel */
.sg-things-chat-empty {
	flex: 1;
}

.sg-things-chat-input-area {
	flex-shrink: 0;
	padding-top: var(--s-space-3);
	margin-top: auto;
}

.sg-things-chat-field {
	width: 100%;
	padding: var(--s-space-2) var(--s-space-3);
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-sans);
	color: var(--s-color-fg-primary);
	background: var(--s-color-bg-subtle);
	border: 1px solid var(--s-color-border-subtle);
	border-radius: var(--s-radius-2);
	outline: none;
	transition: border-color 0.15s;
}

.sg-things-chat-field:focus {
	border-color: var(--s-color-fg-muted);
}

.sg-things-chat-field::placeholder {
	color: var(--s-color-fg-soft);
}

/* Traits panel */
.sg-traits-list {
	display: flex;
	flex-direction: column;
	gap: var(--s-space-2);
}

.sg-trait-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: var(--s-space-3);
	padding: var(--s-space-1) 0;
	border-bottom: 1px solid var(--s-color-border-subtle);
}

.sg-trait-row:last-child {
	border-bottom: none;
}

.sg-trait-label {
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	white-space: nowrap;
}

.sg-trait-value {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-primary);
	text-align: right;
	word-break: break-word;
}

/* ── Pipeline panel ─────────────────── */
.sg-pipe-header {
	display: flex;
	align-items: baseline;
	gap: var(--s-space-2);
}

.sg-pipe-header h4 {
	margin: 0;
}

.sg-pipe-version {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
}

.sg-pipe-stale-banner {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	padding: var(--s-space-2) var(--s-space-3);
	border-radius: var(--s-radius-2);
	background: color-mix(in srgb, var(--s-color-accent-warm) 12%, transparent);
	color: var(--s-color-accent-warm);
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-medium);
	margin-top: var(--s-space-2);
}

.sg-pipe-stale-banner svg {
	flex-shrink: 0;
}

.sg-pipe-steps {
	display: flex;
	flex-direction: column;
	gap: 1px;
	margin-top: var(--s-space-3);
}

.sg-pipe-step {
	display: flex;
	align-items: flex-start;
	gap: var(--s-space-2);
	padding: var(--s-space-2) 0;
	cursor: pointer;
	border-radius: var(--s-radius-1);
	transition: background 0.1s;
}

.sg-pipe-step:hover {
	background: var(--s-color-bg-subtle);
}

.sg-pipe-step-check {
	margin-top: var(--s-space-1);
	flex-shrink: 0;
	accent-color: var(--s-color-fg-primary);
}

.sg-pipe-step-content {
	min-width: 0;
}

.sg-pipe-step-header {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	flex-wrap: wrap;
}

.sg-pipe-step-name {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-primary);
}

.sg-pipe-type-tag {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	padding: 0 var(--s-space-1);
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-soft);
}

.sg-pipe-override-tag {
	font-size: var(--s-font-size-min);
	padding: 0 var(--s-space-1);
	border-radius: var(--s-radius-1);
	background: color-mix(in srgb, var(--s-color-accent-warm) 15%, transparent);
	color: var(--s-color-accent-warm);
}

.sg-pipe-step-desc {
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
	line-height: 1.4;
	margin-top: 1px;
}

.sg-pipe-add-step {
	display: block;
	width: 100%;
	padding: var(--s-space-2);
	margin-top: var(--s-space-2);
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-mono);
	color: var(--s-color-fg-muted);
	background: none;
	border: 1px dashed var(--s-color-border-subtle);
	border-radius: var(--s-radius-2);
	cursor: pointer;
	transition: border-color 0.15s, color 0.15s;
}

.sg-pipe-add-step:hover {
	border-color: var(--s-color-fg-muted);
	color: var(--s-color-fg-primary);
}

.sg-pipe-run {
	display: block;
	width: 100%;
	padding: var(--s-space-3) var(--s-space-4);
	margin-top: var(--s-space-3);
	font-size: var(--s-font-size-1);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-bg-app);
	background: var(--s-color-fg-primary);
	border: none;
	border-radius: var(--s-radius-2);
	cursor: pointer;
	transition: opacity 0.15s;
}

.sg-pipe-run:hover {
	opacity: 0.85;
}

.sg-pipe-run--stale {
	background: var(--s-color-accent-warm);
}

/* Source provenance block */
.sg-pipe-source {
	margin-top: var(--s-space-4);
	padding-top: var(--s-space-4);
	border-top: 1px solid var(--s-color-border-subtle);
}

.sg-pipe-section-label {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-semibold);
	color: var(--s-color-fg-soft);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	margin-bottom: var(--s-space-2);
}

.sg-pipe-source-type {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	margin-bottom: var(--s-space-1);
}

.sg-pipe-source-input {
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-primary);
	font-style: italic;
	margin-bottom: var(--s-space-2);
}

.sg-pipe-citations {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-space-1);
}

.sg-pipe-citation {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	padding: 1px var(--s-space-2);
	border-radius: var(--s-radius-1);
	background: var(--s-color-bg-subtle);
	color: var(--s-color-fg-soft);
}

/* ── Stale Things view ──────────────── */
.sg-things-main-inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	gap: var(--s-space-6);
}

.sg-things-main-inner--has-stale {
	justify-content: flex-start;
	padding-top: var(--s-space-6);
	overflow-y: auto;
}

.sg-stale-section {
	width: 100%;
	max-width: calc(var(--s-space-7) * 10);
	border: 1px solid color-mix(in srgb, var(--s-color-accent-warm) 30%, transparent);
	border-radius: var(--s-radius-3);
	padding: var(--s-space-4);
	background: color-mix(in srgb, var(--s-color-accent-warm) 4%, transparent);
}

.sg-stale-header {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	color: var(--s-color-accent-warm);
	font-size: var(--s-font-size-1);
	font-weight: var(--s-font-weight-semibold);
	margin-bottom: var(--s-space-3);
}

.sg-stale-header svg {
	flex-shrink: 0;
}

.sg-stale-header-sub {
	font-weight: var(--s-font-weight-regular);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-muted);
	margin-left: auto;
}

.sg-stale-list {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.sg-stale-row {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	padding: var(--s-space-2) var(--s-space-2);
	border-radius: var(--s-radius-1);
	cursor: pointer;
	transition: background 0.1s;
}

.sg-stale-row:hover {
	background: color-mix(in srgb, var(--s-color-accent-warm) 8%, transparent);
}

.sg-stale-row-check {
	flex-shrink: 0;
	accent-color: var(--s-color-accent-warm);
}

.sg-stale-row-number {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
	color: var(--s-color-fg-soft);
	min-width: 2.5em;
}

.sg-stale-row-name {
	font-size: var(--s-font-size-0);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-primary);
	flex: 1;
	min-width: 0;
}

.sg-stale-row-version {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-min);
	color: var(--s-color-fg-soft);
	white-space: nowrap;
}

.sg-stale-actions {
	display: flex;
	align-items: center;
	gap: var(--s-space-3);
	margin-top: var(--s-space-3);
	padding-top: var(--s-space-3);
	border-top: 1px solid color-mix(in srgb, var(--s-color-accent-warm) 15%, transparent);
}

.sg-stale-select-all {
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-mono);
	color: var(--s-color-fg-muted);
	background: none;
	border: none;
	cursor: pointer;
	padding: var(--s-space-1) var(--s-space-2);
	border-radius: var(--s-radius-1);
	transition: color 0.15s;
}

.sg-stale-select-all:hover {
	color: var(--s-color-fg-primary);
}

.sg-stale-actions .sg-pipe-run {
	flex: 1;
	margin-top: 0;
}

.sg-stale-actions .sg-pipe-run:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ── Animations ──────────────────────── */
@keyframes sg-fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}

/* ── Extraction badges on experiment cards ── */
.sg-card-badge--extraction {
	font-size: var(--s-font-size-min);
	font-weight: var(--s-font-weight-medium);
	border: 1px solid;
}
.sg-card-badge--primitive {
	border-color: var(--s-color-accent-active);
	color: var(--s-color-accent-active);
	background: transparent;
}
.sg-card-badge--pattern {
	border-color: var(--s-color-accent-secondary);
	color: var(--s-color-accent-secondary-soft);
	background: transparent;
}

/* ── Entity Editor (primitive/pattern inspector) ── */
.sg-editor-body > .sg-ep-body {
	display: grid;
	grid-template-columns: 1fr var(--sg-editor-sidebar-width);
	height: 100%;
	overflow: hidden;
}

.sg-editor--entity .sg-editor-body.sg-ep-body {
	display: grid;
	grid-template-columns: 1fr var(--sg-editor-sidebar-width);
	gap: 0;
	height: 100%;
	overflow: hidden;
}
.sg-ep-preview {
	height: 100%;
	overflow: hidden;
	background: var(--s-color-bg-app);
}
.sg-ep-preview-iframe {
	width: 100%;
	height: 100%;
	border: none;
	display: block;
}
.sg-ep-preview-placeholder {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--s-color-fg-muted);
	font-size: var(--s-font-size-1);
}
.sg-ep-inspector {
	height: 100%;
	overflow-y: auto;
	padding: var(--s-space-4) var(--s-space-5);
	border-left: 1px solid var(--s-color-border-strong);
	background: var(--s-surface-elevation-1-bg);
}
.sg-ep-section {
	margin-bottom: var(--s-space-5);
}
.sg-ep-section:last-child {
	margin-bottom: 0;
}
.sg-ep-heading {
	font-size: var(--s-font-size-min);
	font-weight: var(--s-font-weight-semibold);
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--s-color-fg-muted);
	margin: 0 0 var(--s-space-3);
}
.sg-ep-desc {
	font-size: var(--s-font-size-0);
	line-height: 1.5;
	color: var(--s-color-fg-soft);
	margin: 0;
}
.sg-ep-param-table {
	width: 100%;
	font-size: var(--s-font-size-0);
	border-collapse: collapse;
}
.sg-ep-param-table th {
	text-align: left;
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-muted);
	padding: var(--s-space-1) var(--s-space-3) var(--s-space-1) 0;
	border-bottom: 1px solid var(--s-color-border-strong);
}
.sg-ep-param-table td {
	padding: var(--s-space-2) var(--s-space-3) var(--s-space-2) 0;
	border-bottom: 1px solid var(--s-color-border-subtle);
	color: var(--s-color-fg-primary);
}
.sg-ep-param-name code {
	font-family: var(--s-font-mono, monospace);
	font-size: var(--s-font-size-0);
}
.sg-ep-slider {
	width: calc(var(--s-space-7) + var(--s-space-5));
	accent-color: var(--s-color-accent-active);
}
.sg-ep-motion {
	display: flex;
	gap: var(--s-space-3);
	align-items: baseline;
	padding: var(--s-space-1) 0;
	font-size: var(--s-font-size-0);
}
.sg-ep-motion-type {
	font-family: var(--s-font-mono, monospace);
	font-weight: var(--s-font-weight-medium);
	color: var(--s-color-fg-primary);
	min-width: calc(var(--s-space-7) + var(--s-space-1));
}
.sg-ep-motion-desc {
	color: var(--s-color-fg-muted);
}
.sg-ep-sources {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: var(--s-space-1) var(--s-space-4);
	font-size: var(--s-font-size-0);
}
.sg-ep-source-link {
	color: var(--s-color-accent-active);
	cursor: pointer;
	text-decoration: none;
}
.sg-ep-source-link:hover {
	text-decoration: underline;
}
.sg-ep-source-role {
	color: var(--s-color-fg-muted);
	font-style: italic;
}
.sg-ep-tags {
	display: flex;
	flex-wrap: wrap;
	gap: var(--s-space-1);
}
.sg-ep-vocab-tag {
	display: inline-block;
	padding: var(--s-space-1) var(--s-space-3);
	border-radius: var(--s-radius-1);
	font-size: var(--s-font-size-0);
	font-family: var(--s-font-mono, monospace);
	background: var(--s-surface-elevation-1-bg);
	color: var(--s-color-fg-soft);
	border: 1px solid var(--s-color-border-strong);
}
.sg-ep-vocab-tag--motion {
	border-color: var(--s-color-accent-active);
}

/* Pattern mode cards */
.sg-ep-modes {
	display: flex;
	flex-direction: column;
	gap: var(--s-space-3);
}
.sg-ep-mode-card {
	padding: var(--s-space-3) var(--s-space-4);
	border: 1px solid var(--s-color-border-strong);
	border-radius: var(--s-radius-2);
	background: var(--s-color-bg-app);
}
.sg-ep-mode-header {
	display: flex;
	align-items: center;
	gap: var(--s-space-2);
	margin-bottom: var(--s-space-1);
}
.sg-ep-mode-name {
	font-weight: var(--s-font-weight-semibold);
	font-size: var(--s-font-size-0);
	text-transform: capitalize;
	color: var(--s-color-fg-primary);
}
.sg-ep-mode-badge {
	display: inline-block;
	padding: 1px var(--s-space-2);
	border-radius: var(--s-radius-1);
	font-size: var(--s-font-size-min);
	font-weight: var(--s-font-weight-medium);
	background: var(--s-surface-elevation-1-bg);
	color: var(--s-color-fg-soft);
}
.sg-ep-mode-badge--animated {
	background: var(--s-color-accent-active);
	color: var(--s-color-fg-on-strong);
}
.sg-ep-mode-desc {
	font-size: var(--s-font-size-0);
	line-height: 1.4;
	color: var(--s-color-fg-soft);
	margin: 0;
}
.sg-ep-constraint {
	font-size: var(--s-font-size-0);
	font-style: italic;
	color: var(--s-color-fg-muted);
	margin: var(--s-space-1) 0 0;
}
.sg-breadcrumb-tag--entity {
	background: var(--s-color-accent-active);
	color: var(--s-color-fg-on-strong);
}
/* Extraction mode labels on createTabs pill buttons */
.sg-editor-mode-switcher .s-tabs__tab.sg-mode-tab--extraction {
	color: var(--s-color-accent-active);
	font-style: italic;
}

.sg-editor-mode-switcher .s-tabs__tab.sg-mode-tab--extraction:not(.s-tabs__tab--active) {
	opacity: 0.7;
}

/* Studio editor pill tabs — match pre-component success-tint active chip */
.sg-editor-mode-switcher .s-tabs--pill .s-tabs__tab {
	font-family: var(--s-font-mono);
	font-size: var(--s-font-size-0);
}

.sg-editor-mode-switcher .s-tabs--pill .s-tabs__tab--active {
	background: var(--s-color-success-bg);
	color: var(--s-color-fg-primary);
	font-weight: var(--s-font-weight-medium);
}

[data-theme="dark"] .sg-editor-mode-switcher .s-tabs--pill .s-tabs__tab {
	color: var(--s-color-fg-soft);
}

[data-theme="dark"] .sg-editor-mode-switcher .s-tabs--pill .s-tabs__tab--active {
	background: var(--s-brand-850);
	color: var(--s-color-fg-primary);
}

/* ── Lightbox: centered ~75% shell + Studio scrim ─────────────────── */
#sgLightboxHost {
	position: fixed;
	inset: 0;
	z-index: var(--s-z-max);
	pointer-events: none;
}

#sgLightboxHost .s-modal.s-modal--open {
	display: block;
	width: 100%;
	height: 100%;
	position: relative;
	pointer-events: none;
}

#sgLightboxHost .s-modal--open .s-modal__backdrop {
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1;
	padding: var(--s-space-4);
	pointer-events: auto;
	/* Mint scrim (light) — matches Studio gallery feel */
	background: oklch(0.52 0.06 165 / 0.42);
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
}

.sg-lb-dark #sgLightboxHost .s-modal--open .s-modal__backdrop {
	background: var(--sg-backdrop-dark);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}

#sgLightboxHost .s-modal__dialog--lightbox {
	position: fixed;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	z-index: 2;
	pointer-events: auto;
	width: min(75vw, 1200px) !important;
	height: min(75vh, 880px) !important;
	max-width: 75vw !important;
	max-height: 75vh !important;
	border-radius: var(--s-radius-window, 12px) !important;
	box-shadow: var(--s-shadow-xl, 0 24px 64px oklch(0 0 0 / 0.2)) !important;
	overflow: hidden;
	border: 1px solid var(--s-color-border-subtle);
}

.sg-lb-dark #sgLightboxHost .s-modal__dialog--lightbox {
	border-color: var(--s-brand-850);
	box-shadow: 0 24px 64px oklch(0 0 0 / 0.45) !important;
}

/* Toolbar Close only — modal also adds default X when dismissible */
#sgLightboxHost .s-modal__header > button.s-modal__close {
	display: none !important;
}

/* z-index + overflow: body (iframe) is a later flex sibling and would paint over an open dropdown */
#sgLightboxHost .s-modal__header {
	padding: 0;
	border: none;
	flex-shrink: 0;
	position: relative;
	z-index: 20;
	overflow: visible;
	align-items: center;
}

#sgLightboxHost .s-modal__header-inner {
	flex-direction: row;
	align-items: center;
	flex-wrap: wrap;
	width: 100%;
	min-width: 0;
	gap: var(--s-space-3);
	padding: var(--s-space-2) var(--s-space-5) var(--s-space-2) var(--s-space-4);
	background: var(--s-surface-elevation-1-bg);
	border-bottom: 1px solid var(--s-color-border-subtle);
	overflow: visible;
}

/* Narrow / full-bleed lightbox (matches ≤1023 modal): two-row header */
@media (max-width: 1023px) {
	#sgLightboxHost .s-modal__header-inner {
		padding: var(--s-space-3) var(--s-space-3) var(--s-space-2);
		gap: var(--s-space-2);
		align-items: stretch;
	}

	#sgLightboxHost .sg-lb-header {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto;
		grid-template-areas:
			"title tools"
			"ver ver";
		column-gap: var(--s-space-2);
		row-gap: var(--s-space-2);
		align-items: start;
		width: 100%;
	}

	#sgLightboxHost .sg-lb-title {
		grid-area: title;
		flex-wrap: wrap;
		row-gap: 2px;
		column-gap: var(--s-space-2);
		align-items: baseline;
		min-width: 0;
	}

	#sgLightboxHost .sg-lb-title-meta {
		flex: 1 1 100%;
		color: var(--s-color-fg-muted);
	}

	#sgLightboxHost .sg-lb-toolbar {
		grid-area: tools;
		align-self: start;
		padding-inline-end: 0;
	}

	#sgLightboxHost .sg-lb-version-bar {
		grid-area: ver;
		justify-content: flex-start;
		width: 100%;
		min-width: 0;
	}

	#sgLightboxHost .sg-lb-version-picker {
		position: relative;
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: center;
		gap: var(--s-space-2);
		width: 100%;
		max-width: 100%;
	}

	/* Redundant with combobox aria-label — keeps the row to a single visual line */
	#sgLightboxHost .sg-lb-version-count {
		position: absolute;
		width: 1px;
		height: 1px;
		padding: 0;
		margin: -1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		white-space: nowrap;
		border: 0;
	}

	#sgLightboxHost .sg-lb-version-select-host {
		flex: 1 1 auto;
		min-width: 0;
		max-width: 100%;
	}
}

#sgLightboxHost .sg-lb-version-select-host .s-select__listbox {
	z-index: 60;
}

.sg-lb-dark #sgLightboxHost .s-select__listbox {
	background: var(--s-brand-925);
	border-color: var(--s-brand-850);
	box-shadow: 0 16px 48px oklch(0 0 0 / 0.35);
}

.sg-lb-dark #sgLightboxHost .s-select__option {
	color: var(--s-cream-200);
}

.sg-lb-dark #sgLightboxHost .s-select__option:hover:not(.s-select__option--disabled),
.sg-lb-dark #sgLightboxHost .s-select__option--highlighted {
	background: var(--s-brand-900);
	color: var(--s-cream-100);
}

#sgLightboxHost .s-modal__body {
	padding: 0 !important;
	flex: 1;
	min-height: 0;
	overflow: hidden !important;
	display: flex;
	flex-direction: column;
}

#sgLightboxHost .s-modal__footer {
	padding: 0;
	border: none;
	flex-shrink: 0;
	background: transparent;
}

#sgLightboxHost .sg-lb-footer {
	width: 100%;
	box-sizing: border-box;
}

.sg-lb-dark #sgLightboxHost .s-modal__header-inner {
	background: var(--s-brand-950);
	border-color: var(--s-brand-925);
}

.sg-lb-dark #sgLightboxHost .s-icon-btn {
	color: var(--s-cream-600);
}

.sg-lb-dark #sgLightboxHost .s-icon-btn:hover {
	color: var(--s-cream-200);
	background: var(--s-brand-925);
}

.sg-lb-dark .sg-lb-version-bar .s-button-group--segmented .s-seg-item {
	background: var(--s-brand-925);
	color: var(--s-cream-700);
}

.sg-lb-dark .sg-lb-version-bar .s-button-group--segmented .s-seg-item:hover {
	background: var(--s-brand-900);
	color: var(--s-cream-200);
}

.sg-lb-dark .sg-lb-version-bar .s-button-group--segmented .s-seg-item--active {
	background: var(--s-color-prominent-bg);
	color: var(--s-color-prominent-fg);
}

/* ===== Studio surfaces — responsive template (admin-tokens §14c) =====
   Editor: preview-first, params / inspector below from tablet-lg down.
   Lightbox: viewport-first; nav chevrons share one row; modal uses more viewport on small screens.
   Iframe experiment chrome (info/controls) defaults off below 992px — studio.js getLightboxDetailsDefaultVisible. */

@media (max-width: 991px) {
	.sg-lb-body {
		display: grid;
		grid-template-columns: 1fr 1fr;
		grid-template-rows: minmax(0, 1fr) auto;
		min-height: 0;
		align-items: stretch;
	}

	.sg-lb-viewport {
		grid-column: 1 / -1;
		grid-row: 1;
		min-height: min(42vh, 28rem);
	}

	.sg-lb-nav.sg-lb-prev {
		grid-column: 1;
		grid-row: 2;
		width: 100%;
		min-width: 0;
	}

	.sg-lb-nav.sg-lb-next {
		grid-column: 2;
		grid-row: 2;
		width: 100%;
		min-width: 0;
	}

	.sg-lb-nav-btn {
		flex: 0 0 auto;
		min-height: 2.75rem;
		width: 100%;
	}
}

/* Phone: prev/next on the canvas (stacked grid), not a thin strip above the footer */
@media (max-width: 767px) {
	.sg-lb-body {
		display: grid;
		grid-template-columns: 1fr;
		grid-template-rows: minmax(min(48dvh, 26rem), 1fr);
		min-height: 0;
	}

	.sg-lb-viewport,
	.sg-lb-nav.sg-lb-prev,
	.sg-lb-nav.sg-lb-next {
		grid-column: 1;
		grid-row: 1;
	}

	.sg-lb-viewport {
		min-height: 0;
		z-index: 1;
	}

	.sg-lb-nav.sg-lb-prev,
	.sg-lb-nav.sg-lb-next {
		z-index: 2;
		width: auto;
		min-width: 0;
		align-self: center;
		pointer-events: none;
	}

	.sg-lb-nav.sg-lb-prev {
		justify-self: start;
		margin-inline-start: max(var(--s-space-2), env(safe-area-inset-left, 0px));
	}

	.sg-lb-nav.sg-lb-next {
		justify-self: end;
		margin-inline-end: max(var(--s-space-2), env(safe-area-inset-right, 0px));
	}

	.sg-lb-nav-btn {
		pointer-events: auto;
		touch-action: manipulation;
		-webkit-tap-highlight-color: transparent;
		min-width: 3.25rem;
		min-height: 3.25rem;
		width: 3.25rem;
		border-radius: 999px;
		background: color-mix(in oklch, var(--s-surface-elevation-1-bg) 82%, transparent);
		border: 1px solid var(--s-color-border-subtle);
		color: var(--s-color-fg-primary);
		box-shadow: 0 2px 12px oklch(0 0 0 / 0.2);
	}

	.sg-lb-nav-btn svg {
		width: 22px;
		height: 22px;
	}

	.sg-lb-nav-btn:active:not(:disabled) {
		background: color-mix(in oklch, var(--s-color-bg-subtle) 90%, transparent);
		transform: scale(0.96);
	}

	.sg-lb-dark .sg-lb-nav-btn {
		background: color-mix(in oklch, var(--s-brand-900) 78%, transparent);
		border-color: var(--s-brand-850);
		color: var(--s-cream-200);
		box-shadow: 0 4px 20px oklch(0 0 0 / 0.45);
	}

	.sg-lb-dark .sg-lb-nav-btn:active:not(:disabled) {
		background: color-mix(in oklch, var(--s-brand-925) 88%, transparent);
	}
}

@media (max-width: 600px) {
	.sg-lb-footer {
		flex-wrap: wrap;
		align-items: flex-start;
		row-gap: var(--s-space-2);
		column-gap: var(--s-space-3);
	}

	.sg-lb-tags {
		width: 100%;
		white-space: normal;
		line-height: 1.45;
	}
}

/* Tablet + phone: edge-to-edge lightbox (768–1023 was still 96vw×90vh and felt “floating”). */
@media (max-width: 1023px) {
	#sgLightboxHost .s-modal--open .s-modal__backdrop {
		padding: 0;
		align-items: stretch;
		justify-content: stretch;
	}

	#sgLightboxHost .s-modal__dialog--lightbox {
		width: 100vw !important;
		height: 100vh !important;
		max-width: none !important;
		max-height: none !important;
		min-height: 100dvh !important;
		border-radius: 0 !important;
		inset: 0 !important;
		left: 0 !important;
		top: 0 !important;
		transform: none !important;
		margin: 0 !important;
	}
}

/* Handheld landscape: scroll the dialog as one column (must follow max-width:1023 full-bleed rules). */
@media (max-width: 932px) and (orientation: landscape) {
	#sgLightboxHost .s-modal__dialog--lightbox {
		overflow-y: auto !important;
		overflow-x: hidden;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior-y: contain;
		max-height: 100dvh !important;
		height: auto !important;
		min-height: 0;
	}

	#sgLightboxHost .s-modal__body {
		flex: 0 1 auto !important;
		overflow: visible !important;
		min-height: min(52dvh, 16rem);
	}

	#sgLightboxHost .s-modal__footer {
		flex: 0 0 auto;
	}
}

@media (max-width: 1024px) {
	.sg-editor-body > .sg-ep-body,
	.sg-editor--entity .sg-editor-body.sg-ep-body {
		grid-template-columns: 1fr;
		grid-template-rows: minmax(14rem, min(45vh, 24rem)) minmax(0, 1fr);
		overflow: auto;
		align-content: start;
	}

	.sg-ep-preview {
		min-height: 12rem;
		max-height: min(45vh, 24rem);
		border-bottom: 1px solid var(--s-color-border-strong);
	}

	.sg-ep-inspector {
		border-left: none;
		min-height: 0;
	}

	.sg-things-layout {
		grid-template-columns: 1fr;
		grid-template-rows: minmax(12rem, 1fr) auto;
		height: auto;
		min-height: 0;
		max-height: 100%;
	}

	.sg-things-main {
		min-height: min(40vh, 20rem);
	}

	.sg-things-sidebar {
		border-left: none;
		border-top: 1px solid var(--s-color-border-subtle);
		max-height: min(55vh, 28rem);
		overflow-y: auto;
	}
}