/*
 * AI Bib Designer — customer-facing styles.
 *
 * This plugin is designed to run on several different WordPress sites, so the
 * styling deliberately inherits the host theme's typography and exposes every
 * colour and radius as a custom property. A site brands the designer by
 * overriding --aibd-* in its own stylesheet; nothing here is hard-coded to one
 * brand. Restraint is the design decision, not an absence of one.
 */

.aibd-designer {
	--aibd-accent: #1b6ef3;
	--aibd-accent-ink: #ffffff;
	--aibd-accent-soft: rgba(27, 110, 243, 0.08);
	--aibd-ink: #16181d;
	--aibd-muted: #5c636e;
	--aibd-line: #d9dde4;
	--aibd-surface: #ffffff;
	--aibd-surface-alt: #f6f7f9;
	--aibd-danger: #c0362c;
	--aibd-success: #1c7c4a;
	--aibd-radius: 10px;
	--aibd-gap: 1.25rem;

	max-width: 56rem;
	margin-inline: auto;
	color: var(--aibd-ink);
	font-size: 1rem;
	line-height: 1.6;
}

.aibd-designer *,
.aibd-designer *::before,
.aibd-designer *::after {
	box-sizing: border-box;
}

.aibd-heading {
	margin: 0 0 var(--aibd-gap);
}

/* ---------- Progress ---------- */

.aibd-progress {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.25rem;
	list-style: none;
	margin: 0 0 1.75rem;
	padding: 0;
}

.aibd-progress__step {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	color: var(--aibd-muted);
	font-size: 0.875rem;
}

.aibd-progress__marker {
	display: grid;
	place-items: center;
	width: 1.75rem;
	height: 1.75rem;
	border: 1px solid var(--aibd-line);
	border-radius: 50%;
	font-size: 0.8125rem;
	font-variant-numeric: tabular-nums;
	flex-shrink: 0;
}

.aibd-progress__step.is-current {
	color: var(--aibd-ink);
	font-weight: 600;
}

.aibd-progress__step.is-current .aibd-progress__marker {
	background: var(--aibd-accent);
	border-color: var(--aibd-accent);
	color: var(--aibd-accent-ink);
}

.aibd-progress__step.is-done .aibd-progress__marker {
	background: var(--aibd-surface-alt);
	border-color: var(--aibd-line);
	color: var(--aibd-success);
}

/* ---------- Panels ---------- */

.aibd-panel {
	background: var(--aibd-surface);
	border: 1px solid var(--aibd-line);
	border-radius: var(--aibd-radius);
	padding: 1.5rem;
}

.aibd-panel[hidden] {
	display: none;
}

.aibd-panel__title {
	margin: 0 0 1rem;
	font-size: 1.25rem;
	line-height: 1.3;
}

/* ---------- Fields ---------- */

.aibd-field {
	margin-bottom: 1.25rem;
}

.aibd-field label {
	display: block;
	margin-bottom: 0.375rem;
	font-weight: 600;
	font-size: 0.9375rem;
}

.aibd-field input[type="text"],
.aibd-field input[type="number"],
.aibd-field input[type="date"],
.aibd-field select,
.aibd-field textarea {
	width: 100%;
	padding: 0.625rem 0.75rem;
	border: 1px solid var(--aibd-line);
	border-radius: calc(var(--aibd-radius) - 4px);
	background: var(--aibd-surface);
	color: inherit;
	font: inherit;
	line-height: 1.5;
}

.aibd-field textarea {
	resize: vertical;
	min-height: 6rem;
}

.aibd-field :is(input, select, textarea):focus-visible {
	outline: 2px solid var(--aibd-accent);
	outline-offset: 1px;
	border-color: var(--aibd-accent);
}

.aibd-field :is(input, textarea).is-invalid {
	border-color: var(--aibd-danger);
}

.aibd-row {
	display: grid;
	gap: 0 var(--aibd-gap);
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.aibd-help {
	margin: 0.375rem 0 0;
	color: var(--aibd-muted);
	font-size: 0.8125rem;
	line-height: 1.5;
}

.aibd-counter {
	margin: 0.25rem 0 0;
	color: var(--aibd-muted);
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.aibd-error {
	margin: 0.375rem 0 0;
	color: var(--aibd-danger);
	font-size: 0.8125rem;
}

.aibd-error[hidden] {
	display: none;
}

/* ---------- Notices ---------- */

.aibd-notice {
	margin: 0 0 1.25rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--aibd-line);
	border-radius: calc(var(--aibd-radius) - 4px);
	background: var(--aibd-surface-alt);
	font-size: 0.9375rem;
}

.aibd-notice--error {
	border-color: var(--aibd-danger);
	background: rgba(192, 54, 44, 0.06);
	color: var(--aibd-danger);
}

.aibd-notice[hidden] {
	display: none;
}

/* ---------- Buttons ---------- */

.aibd-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin-top: 1.5rem;
}

.aibd-button {
	padding: 0.6875rem 1.25rem;
	border: 1px solid var(--aibd-line);
	border-radius: calc(var(--aibd-radius) - 4px);
	background: var(--aibd-surface);
	color: inherit;
	font: inherit;
	font-weight: 600;
	font-size: 0.9375rem;
	cursor: pointer;
}

.aibd-button:hover:not(:disabled) {
	border-color: var(--aibd-muted);
}

.aibd-button:focus-visible {
	outline: 2px solid var(--aibd-accent);
	outline-offset: 2px;
}

.aibd-button--primary {
	background: var(--aibd-accent);
	border-color: var(--aibd-accent);
	color: var(--aibd-accent-ink);
}

.aibd-button:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.aibd-button.is-busy {
	position: relative;
	color: transparent;
}

.aibd-button.is-busy::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 1rem;
	height: 1rem;
	border: 2px solid currentcolor;
	border-top-color: var(--aibd-accent-ink);
	border-radius: 50%;
	animation: aibd-spin 0.7s linear infinite;
}

/* ---------- Working state ---------- */

.aibd-working {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	gap: 0.5rem;
	padding: 1.5rem 0;
}

.aibd-spinner {
	width: 2rem;
	height: 2rem;
	border: 3px solid var(--aibd-line);
	border-top-color: var(--aibd-accent);
	border-radius: 50%;
	animation: aibd-spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
	.aibd-spinner,
	.aibd-button.is-busy::after {
		animation-duration: 3s;
	}

	.aibd-skeleton {
		animation: none;
	}
}

/* ---------- Results ---------- */

.aibd-grid,
.aibd-skeletons {
	display: grid;
	gap: var(--aibd-gap);
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
	margin-top: 1rem;
}

.aibd-option {
	display: block;
	width: 100%;
	padding: 0;
	border: 2px solid var(--aibd-line);
	border-radius: var(--aibd-radius);
	background: var(--aibd-surface-alt);
	cursor: pointer;
	overflow: hidden;
	text-align: left;
}

.aibd-option:focus-visible {
	outline: 2px solid var(--aibd-accent);
	outline-offset: 2px;
}

.aibd-option.is-selected {
	border-color: var(--aibd-accent);
	background: var(--aibd-accent-soft);
}

.aibd-option__image {
	display: block;
	width: 100%;
	aspect-ratio: 540 / 414;
	object-fit: cover;
	background: var(--aibd-surface-alt);
}

.aibd-option__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.625rem 0.75rem;
	font-size: 0.8125rem;
	font-weight: 600;
}

.aibd-option__state {
	color: var(--aibd-muted);
	font-weight: 500;
}

.aibd-option.is-selected .aibd-option__state {
	color: var(--aibd-accent);
}

.aibd-skeleton {
	aspect-ratio: 540 / 414;
	border-radius: var(--aibd-radius);
	background: linear-gradient(90deg, var(--aibd-surface-alt) 25%, #eceef1 37%, var(--aibd-surface-alt) 63%);
	background-size: 400% 100%;
	animation: aibd-shimmer 1.4s ease infinite;
}

@keyframes aibd-shimmer {
	0% { background-position: 100% 50%; }
	100% { background-position: 0 50%; }
}

/* ---------- Summary ---------- */

.aibd-summary {
	display: grid;
	gap: 0.5rem;
	margin-bottom: 1.25rem;
}

.aibd-summary__row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	padding-bottom: 0.5rem;
	border-bottom: 1px solid var(--aibd-line);
	font-size: 0.9375rem;
}

.aibd-summary__label {
	flex: 0 0 11rem;
	color: var(--aibd-muted);
}

.aibd-summary__value {
	font-weight: 600;
	word-break: break-word;
}

.aibd-summary__value code {
	font-size: 0.9375rem;
}

/* ---------- Mobile ---------- */

@media (max-width: 36rem) {
	.aibd-panel {
		padding: 1.125rem;
	}

	.aibd-row {
		grid-template-columns: 1fr;
	}

	.aibd-progress {
		gap: 0.375rem 0.75rem;
	}

	.aibd-progress__label {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.aibd-progress__step.is-current .aibd-progress__label {
		position: static;
		width: auto;
		height: auto;
		clip-path: none;
	}

	.aibd-actions .aibd-button {
		flex: 1 1 100%;
	}

	.aibd-summary__label {
		flex-basis: 100%;
	}
}

/* ---------- Preview ---------- */

.aibd-preview {
	margin-bottom: 1.25rem;
}

.aibd-preview__stage {
	display: block;
	border-radius: var(--aibd-radius);
	overflow: hidden;
	background: var(--aibd-surface-alt);
	min-height: 8rem;
}

.aibd-preview__stage .aibd-bib {
	display: block;
	width: 100%;
	height: auto;
}

.aibd-preview[aria-busy="true"] .aibd-preview__stage {
	position: relative;
	aspect-ratio: 540 / 414;
	background: linear-gradient(90deg, var(--aibd-surface-alt) 25%, #eceef1 37%, var(--aibd-surface-alt) 63%);
	background-size: 400% 100%;
	animation: aibd-shimmer 1.4s ease infinite;
}

.aibd-numbers {
	margin-bottom: 1.25rem;
}

.aibd-numbers[hidden] {
	display: none;
}

.aibd-numbers__label {
	margin: 0 0 0.5rem;
	color: var(--aibd-muted);
	font-size: 0.8125rem;
}

.aibd-numbers__options {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.aibd-number {
	padding: 0.4375rem 0.875rem;
	border: 1px solid var(--aibd-line);
	border-radius: 999px;
	background: var(--aibd-surface);
	color: inherit;
	font: inherit;
	font-size: 0.8125rem;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
}

.aibd-number:focus-visible {
	outline: 2px solid var(--aibd-accent);
	outline-offset: 2px;
}

.aibd-number.is-active {
	border-color: var(--aibd-accent);
	background: var(--aibd-accent-soft);
	color: var(--aibd-accent);
	font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
	.aibd-preview[aria-busy="true"] .aibd-preview__stage {
		animation: none;
	}
}
