/* ─────────────────────────────────────────────────────────────
 * Component Stage — the hero's app window
 *
 * A self-themed app window running live Dievas components. The
 * window has its own scoped data-theme, so its content proves the
 * token model without disturbing the page sheet.
 * ───────────────────────────────────────────────────────────── */

.stage-window {
	position: relative;
	border-radius: var(--radius-2xl);
	background: var(--dv-bg-subtle);
	border: 1px solid var(--dv-border);
	overflow: hidden;
	transition:
		background 260ms var(--ease),
		border-color 260ms var(--ease);
}

/* ── Title bar ─────────────────────────────────────────────── */

.stage-titlebar {
	display: flex;
	align-items: center;
	gap: 12px;
	height: 46px;
	padding-inline: 18px;
	border-bottom: 2px solid var(--dv-text-hi);
	background: color-mix(in srgb, var(--dv-bg-base) 55%, transparent);
	transition: border-color 260ms var(--ease);
}

.stage-dots {
	display: flex;
	gap: 8px;
}

.stage-dot {
	width: 12px;
	height: 12px;
	border-radius: 999px;
}
.stage-dot.d-r {
	background: #ff5f57;
}
.stage-dot.d-y {
	background: #febc2e;
}
.stage-dot.d-g {
	background: #28c840;
}

.stage-title {
	flex: 1;
	font-family: var(--font-mono);
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--dv-text-mid);
	text-align: center;
	user-select: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Scoped theme toggle (minor, inside the window chrome) */
.stage-theme {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px 5px 8px;
	border-radius: 999px;
	border: 1px solid var(--dv-border);
	font-family: var(--font-mono);
	font-size: 10px;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--dv-text-mid);
	background: color-mix(in srgb, var(--dv-bg-base) 60%, transparent);
	transition:
		border-color 200ms var(--ease),
		color 200ms var(--ease);
}
.stage-theme:hover {
	border-color: var(--dv-border-hi);
	color: var(--dv-text-hi);
}

/* ── Tab bar (segmented) ───────────────────────────────────── */

.stage-tabs {
	position: relative;
	display: flex;
	gap: 4px;
	padding: 10px 14px 0;
	background: color-mix(in srgb, var(--dv-bg-base) 30%, transparent);
}

.stage-tab {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 8px 16px;
	border-radius: var(--radius-lg) var(--radius-lg) 0 0;
	font-family: var(--font-mono);
	font-size: 11px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--dv-text-mid);
	transition:
		color 200ms var(--ease),
		background 200ms var(--ease);
}
.stage-tab:hover {
	color: var(--dv-text-hi);
}
.stage-tab[aria-selected="true"] {
	color: var(--dv-text-hi);
}

/* Sliding indicator — one shared bar under the row, sized and moved to
 * the selected tab by the stage module in app.dart. The bar carries the
 * transition, so a tab change is a slide rather than an underline
 * vanishing and reappearing. No transition until .is-ready, so the
 * first placement (and the font-swap correction) land instantly. */
.stage-tab-indicator {
	position: absolute;
	bottom: 0;
	left: 0;
	height: 2px;
	width: 0;
	border-radius: 2px;
	background: var(--dv-brand);
}
.stage-tabs.is-ready .stage-tab-indicator {
	transition:
		transform 260ms var(--ease),
		width 260ms var(--ease);
}

/* ── Body ──────────────────────────────────────────────────── */

.stage-body {
	position: relative;
	min-height: 400px;
	display: grid;
	align-content: center;
	/* minmax(0,1fr) — never let a panel's max-content size the track,
	 * which is what used to push content past the right edge. */
	grid-template-columns: minmax(0, 1fr);
	overflow: hidden;
}

/* Panels ride a flex track; the stage module slides the whole track to
 * the selected tab's index, so a tab change is a page turn rather than
 * a crossfade. The tallest panel sets the row height on its own. */
.stage-track {
	display: flex;
	align-items: stretch;
	width: 100%;
	transition: transform 340ms var(--ease);
}

.stage-panel {
	flex: 0 0 100%;
	min-width: 0;
	padding: clamp(24px, 3vw, 40px);
	display: flex;
	flex-direction: column;
	/* Desktop centres one content column; the column is capped by its
	 * own max-width, so on a narrow sheet it fills the width and its
	 * rows read left-aligned. */
	align-items: center;
	justify-content: center;
	/* Long rows scroll inside the panel instead of being clipped. */
	overflow-x: auto;
	overscroll-behavior-x: contain;
}

/* ── Panels: Primitives & Semantics ───────────────────────── */

.token-rows {
	display: flex;
	flex-direction: column;
	gap: 18px;
	width: 100%;
	max-width: 640px;
}

.token-family {
	display: grid;
	grid-template-columns: 84px 1fr;
	align-items: center;
	gap: clamp(12px, 3vw, 24px);
}

.token-family-name {
	font-family: var(--font-mono);
	font-size: 10px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--dv-text-lo);
}

.token-family-items {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
}

/* Colour primitive */
.swatch-card {
	width: 132px;
	padding: 12px;
	border-radius: var(--radius-xl);
	border: 1px solid var(--dv-border);
	background: var(--dv-bg-base);
	display: flex;
	flex-direction: column;
	gap: 10px;
	transition: border-color 260ms var(--ease);
}

.swatch {
	height: 46px;
	border-radius: var(--radius-md);
	border: 1px solid rgba(15, 23, 42, 0.06);
}

.swatch-label {
	display: flex;
	flex-direction: column;
	gap: 2px;
}
.swatch-label b {
	font-family: var(--font-mono);
	font-size: 10px;
	font-weight: 500;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--dv-text-hi);
}
.swatch-label span {
	font-family: var(--font-mono);
	font-size: 10px;
	color: var(--dv-text-lo);
}

.rail-code {
	margin-top: 20px;
	text-align: left;
	/* Same column as .token-rows so the code strip keeps the panel's
	 * left edge on both the centred desktop sheet and the narrow one. */
	width: 100%;
	max-width: 640px;
}

/* Shape primitives — elevation, radius, spacing. The value is the
 * sample: the shadow blur, the corner curve, the bar width. */
.shape-card {
	width: 132px;
	padding: 12px;
	border-radius: var(--radius-xl);
	border: 1px solid var(--dv-border);
	background: var(--dv-bg-base);
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.shape-sample {
	height: 46px;
	border-radius: var(--radius-md);
	border: 1px solid var(--dv-border);
	background: var(--dv-bg-subtle);
	display: grid;
	place-items: center;
}

/* The track stays transparent so the tile reads as a distinct raised
 * object. A full-width sample with a downward shadow can only ever look
 * like a band at its bottom edge — the air beneath a smaller, centred
 * tile is what makes the shadow read as a lift. */
.elev-sample {
	background: transparent;
	border-color: transparent;
}
.elev-tile {
	width: 72px;
	height: 30px;
	border-radius: var(--radius-md);
	border: 1px solid var(--dv-border);
	background: var(--dv-bg-elevated);
}

.spacing-bar {
	height: 10px;
	min-width: 4px;
	border-radius: 999px;
	background: var(--dv-brand);
}

/* Semantic alias chips */
.alias-chip {
	flex: 1;
	min-width: 168px;
	padding: 10px 12px;
	border-radius: var(--radius-lg);
	border: 1px solid var(--dv-border);
	background: var(--dv-bg-base);
	display: flex;
	flex-direction: column;
	gap: 3px;
	text-align: left;
	cursor: copy;
	transition: border-color 200ms var(--ease);
}
.alias-chip:hover {
	border-color: var(--dv-border-hi);
}
.alias-chip.is-copied {
	border-color: var(--dv-border-brand);
}

.alias-name {
	font-family: var(--font-mono);
	font-size: 11px;
	font-weight: 500;
	color: var(--dv-text-hi);
}
.alias-accessor {
	font-family: var(--font-mono);
	font-size: 10px;
	color: var(--dv-brand);
	overflow-wrap: anywhere;
}
.alias-value {
	font-family: var(--font-mono);
	font-size: 10px;
	color: var(--dv-text-lo);
}

/* ── Panel: Components ─────────────────────────────────────── */

/* Components panel mirrors the token panels: one left-anchored column,
 * not a centred pile. */
.comp-demo {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 26px;
	width: 100%;
	max-width: 640px;
}

.comp-row {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	justify-content: flex-start;
}

/* Dievas-style buttons (mirror package variants) */
.dbtn {
	padding: 10px 18px;
	border-radius: var(--radius-md);
	font-family: var(--font-mono);
	font-size: 12px;
	letter-spacing: 0.02em;
	transition:
		background 160ms var(--ease),
		border-color 160ms var(--ease),
		color 160ms var(--ease),
		transform 110ms var(--ease),
		box-shadow 160ms var(--ease);
}
.dbtn:active {
	transform: scale(0.97);
}

.dbtn-primary {
	background: var(--dv-action);
	color: var(--dv-on-brand);
	box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--dv-action) 60%, transparent);
}
.dbtn-primary:hover {
	background: var(--dv-action-hover);
}

.dbtn-secondary {
	background: var(--dv-action-sec);
	color: var(--dv-text-hi);
	border: 1px solid var(--dv-border);
}
.dbtn-secondary:hover {
	background: var(--dv-action-sec-hover);
}

.dbtn-text {
	color: var(--dv-brand);
	padding-inline: 10px;
	border-radius: var(--radius-md);
}
.dbtn-text:hover {
	background: var(--dv-brand-subtle);
}

.dbtn-ghost {
	color: var(--dv-text-mid);
	border: 1px solid var(--dv-border);
}
.dbtn-ghost:hover {
	color: var(--dv-text-hi);
	border-color: var(--dv-border-hi);
}

.dbtn-disabled {
	color: var(--dv-text-off);
	background: var(--dv-action-disabled);
	cursor: not-allowed;
	pointer-events: none;
	box-shadow: none;
}

/* Switch + checkbox — custom, token-driven */
.toggle-cluster {
	display: flex;
	gap: 28px;
	align-items: center;
}

.t-switch {
	display: inline-flex;
	align-items: center;
	gap: 12px;
	cursor: pointer;
	user-select: none;
}
.t-switch .track {
	width: 42px;
	height: 26px;
	border-radius: 999px;
	background: var(--dv-switch-off);
	border: 1px solid var(--dv-switch-border);
	position: relative;
	transition:
		background 220ms var(--ease),
		border-color 220ms var(--ease);
}
.t-switch .track .knob {
	position: absolute;
	top: 2px;
	left: 2px;
	width: 20px;
	height: 20px;
	border-radius: 999px;
	background: var(--dv-switch-thumb);
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
	transition: transform 240ms var(--ease);
}
.t-switch.is-on .track {
	background: var(--dv-switch-on);
	border-color: var(--dv-switch-on);
}
.t-switch.is-on .track .knob {
	transform: translateX(16px);
}
.t-switch .t-label {
	font-family: var(--font-mono);
	font-size: 11px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--dv-text-mid);
}

/* ── Component samples ─────────────────────────────────────── */

.comp-cluster {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 10px;
	width: 100%;
}

.comp-name {
	font-family: var(--font-mono);
	font-size: 10px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--dv-text-lo);
}

.comp-preview {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	min-height: 44px;
	width: 100%;
}

/* Outlined variant — mirrors DievasOutlinedButton */
.dbtn-outlined {
	background: transparent;
	color: var(--dv-brand);
	border: 1px solid var(--dv-border-brand);
}
.dbtn-outlined:hover {
	background: var(--dv-brand-subtle);
}

/* Accordion */
.acc {
	width: 100%;
	max-width: 420px;
	border: 1px solid var(--dv-border);
	border-radius: var(--radius-lg);
	background: var(--dv-bg-base);
	overflow: hidden;
}

.acc-head {
	width: 100%;
	background: transparent;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 16px;
	font-family: var(--font-mono);
	font-size: 11.5px;
	color: var(--dv-text-hi);
	text-align: left;
	transition: background 160ms var(--ease);
}
.acc-head:hover {
	background: var(--dv-bg-subtle);
}

.acc-arrow {
	color: var(--dv-text-lo);
	font-size: 14px;
	line-height: 1;
	transition: transform 220ms var(--ease);
}
.acc-head[aria-expanded="true"] .acc-arrow {
	transform: rotate(180deg);
}

.acc-body {
	padding: 0 16px 14px;
	font-size: 12.5px;
	line-height: 1.6;
	color: var(--dv-text-mid);
}
.acc-head[aria-expanded="false"] + .acc-body {
	display: none;
}

/* Breadcrumb */
.crumbs {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	justify-content: flex-start;
	gap: 6px;
}
.crumb {
	padding: 5px 10px;
	border-radius: var(--radius-md);
	font-family: var(--font-mono);
	font-size: 11px;
	color: var(--dv-text-mid);
	transition:
		color 160ms var(--ease),
		background 160ms var(--ease);
}
.crumb:hover {
	color: var(--dv-text-hi);
	background: var(--dv-bg-subtle);
}
.crumb-sep {
	color: var(--dv-text-lo);
	user-select: none;
}
.crumb.is-current {
	color: var(--dv-brand);
	font-weight: 500;
}

/* Dot indicator */
.dots {
	display: flex;
	align-items: center;
	gap: 10px;
}
.dots .dot {
	width: 9px;
	height: 9px;
	border-radius: 999px;
	background: var(--dv-border-hi);
	transition:
		width 220ms var(--ease),
		background 200ms var(--ease);
}
.dots .dot:hover {
	background: var(--dv-text-lo);
}
.dots .dot.is-active {
	width: 24px;
	background: var(--dv-brand);
}

/* ── Footer readout ────────────────────────────────────────── */

.stage-foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 20px;
	border-top: 2px solid var(--dv-text-hi);
	background: color-mix(in srgb, var(--dv-bg-base) 30%, transparent);
	transition: border-color 260ms var(--ease);
	font-family: var(--font-mono);
	font-size: 10px;
	font-weight: 500;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--dv-text-lo);
}

.stage-foot .readout {
	color: var(--dv-text-mid);
	font-variant-numeric: tabular-nums;
}
.stage-foot .readout b {
	color: var(--dv-brand);
	font-weight: 500;
}

/* Reuses .craft-inline-link (craft.css) for the underline + arrow
 * treatment; scoped overrides keep it on the foot's baseline. */
.stage-foot .stage-foot-link {
	color: var(--dv-text-lo);
	font-weight: 500;
}
.stage-foot .stage-foot-link:hover {
	color: var(--dv-brand);
}

@media (max-width: 640px) {
	.stage-body {
		min-height: 0;
	}
	/* Every panel keeps its left edge, matching the headings above it. */
	.stage-panel {
		padding: 22px 18px;
		justify-content: flex-start;
	}
	.token-family {
		grid-template-columns: 1fr;
		gap: 8px;
	}
	.token-family-items {
		justify-content: flex-start;
	}
	.swatch-card,
	.shape-card {
		width: calc(50% - 6px);
	}
	.toggle-cluster {
		flex-direction: column;
		gap: 16px;
		align-items: flex-start;
	}
	.stage-title {
		text-align: left;
	}
}
