/* ════════════════════════════════════════════════════════════════
   Print Hut — UI Components (production layer)
   Extends phpr.css primitives with loading, empty, async states.
   Load after phpr-styles; does not override module-specific skins.
   ════════════════════════════════════════════════════════════════ */

/* ── Layout primitives ───────────────────────────────────────── */
.phpr-stack {
	display: flex;
	flex-direction: column;
	gap: var(--phpr-c-stack-gap, 12px);
}

.phpr-stack--sm { --phpr-c-stack-gap: 8px; }
.phpr-stack--lg { --phpr-c-stack-gap: 20px; }

.phpr-inline {
	display: inline-flex;
	align-items: center;
	gap: var(--phpr-c-inline-gap, 8px);
	flex-wrap: wrap;
}

.phpr-cluster {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--phpr-c-cluster-gap, 10px);
}

/* ── Spinner ─────────────────────────────────────────────────── */
.phpr-spinner {
	--phpr-c-spinner-size: 20px;
	width: var(--phpr-c-spinner-size);
	height: var(--phpr-c-spinner-size);
	border: 2px solid rgba(15, 23, 42, 0.12);
	border-top-color: var(--phpr-brand, #059669);
	border-radius: 50%;
	animation: phpr-spin 0.7s linear infinite;
	flex-shrink: 0;
}

.phpr-spinner--sm { --phpr-c-spinner-size: 16px; }
.phpr-spinner--lg { --phpr-c-spinner-size: 28px; }

.phpr-spinner--on-dark {
	border-color: rgba(255, 255, 255, 0.25);
	border-top-color: #fff;
}

@keyframes phpr-spin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.phpr-spinner { animation: none; border-top-color: var(--phpr-brand, #059669); opacity: 0.85; }
}

/* ── Loading panel ───────────────────────────────────────────── */
.phpr-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 48px 24px;
	text-align: center;
	color: var(--phpr-gray-500, #64748b);
}

.phpr-loading__label {
	font-size: 14px;
	font-weight: 600;
	margin: 0;
}

.phpr-loading--inline {
	flex-direction: row;
	padding: 16px;
	justify-content: flex-start;
}

/* ── Async view states ───────────────────────────────────────── */
.phpr-async {
	position: relative;
	min-height: 120px;
}

.phpr-async__panel {
	display: none;
}

.phpr-async__panel.is-active {
	display: block;
}

.phpr-async__panel--loading.is-active,
.phpr-async__panel--empty.is-active,
.phpr-async__panel--error.is-active {
	display: flex;
}

/* ── Enhanced empty state ────────────────────────────────────── */
.phpr-empty-state--compact {
	padding: 32px 16px;
}

.phpr-empty-state__action {
	margin-top: 16px;
}

/* ── Button loading state ────────────────────────────────────── */
.phpr-btn.is-loading,
.phpr-btn[aria-busy="true"] {
	position: relative;
	color: transparent !important;
	pointer-events: none;
}

.phpr-btn.is-loading::after,
.phpr-btn[aria-busy="true"]::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 18px;
	height: 18px;
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	animation: phpr-spin 0.7s linear infinite;
}

.phpr-btn--ghost.is-loading::after,
.phpr-btn--outline.is-loading::after {
	border-color: rgba(15, 23, 42, 0.15);
	border-top-color: var(--phpr-gray-700, #334155);
}

/* ── Stat ribbon (component) ───────────────────────────────────── */
.phpr-stat-ribbon {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 12px;
}

.phpr-stat-ribbon__item {
	background: var(--phpr-bg, #fff);
	border: 1px solid var(--phpr-border, #e2e8f0);
	border-radius: 16px;
	padding: 18px 20px;
	box-shadow: var(--phpr-shadow-sm, 0 1px 3px rgba(15, 23, 42, 0.06));
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.phpr-stat-ribbon__item:hover {
	transform: translateY(-1px);
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.phpr-stat-ribbon__item--accent {
	border-color: rgba(5, 150, 105, 0.25);
	background: linear-gradient(180deg, #f0fdf4 0%, #fff 100%);
}

.phpr-stat-ribbon__value {
	display: block;
	font-size: clamp(1.5rem, 3vw, 1.85rem);
	font-weight: 800;
	letter-spacing: -0.03em;
	color: var(--phpr-gray-900, #0f172a);
	line-height: 1.1;
}

.phpr-stat-ribbon__label {
	display: block;
	margin-top: 6px;
	font-size: 13px;
	font-weight: 600;
	color: var(--phpr-gray-500, #64748b);
}

.phpr-stat-ribbon__value.is-loading {
	color: transparent;
	background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
	background-size: 200% 100%;
	animation: phpr-shimmer 1.2s ease-in-out infinite;
	border-radius: 8px;
	min-height: 1.2em;
	min-width: 2ch;
}

@keyframes phpr-shimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
	.phpr-stat-ribbon__value.is-loading { animation: none; background: #e2e8f0; color: transparent; }
}

/* ── Toast stack (JS-managed) ──────────────────────────────────── */
.phpr-toast-stack {
	position: fixed;
	right: 16px;
	bottom: 16px;
	z-index: 100000;
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-width: min(420px, calc(100vw - 32px));
	pointer-events: none;
}

.phpr-toast-stack .phpr-toast {
	position: relative;
	bottom: auto;
	right: auto;
	pointer-events: auto;
	margin: 0;
	animation: phpr-toast-in 0.22s ease;
}

@keyframes phpr-toast-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ── Visually hidden (a11y) ────────────────────────────────────── */
.phpr-sr-only {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
	.phpr-stat-ribbon {
		grid-template-columns: repeat(2, 1fr);
	}

	.phpr-toast-stack {
		left: 16px;
		right: 16px;
		max-width: none;
	}
}

@media (max-width: 380px) {
	.phpr-stat-ribbon {
		grid-template-columns: 1fr;
	}
}
