/**
 * KOLOR Look Preview - frontend styles.
 *
 * Everything is driven by custom properties. The block writes only the ones the
 * user has actually set, so these defaults stay in charge otherwise.
 */

.kolor-look-preview {
	/* Layout */
	--klp-ratio: 3/2;
	--klp-gap: 20px;
	--klp-thumb-width: 96px;
	--klp-radius: 4px;
	--klp-radius-stage: var(--klp-radius);
	--klp-radius-thumb: var(--klp-radius);
	--klp-radius-button: var(--klp-radius);
	--klp-thumb-outline-width: 2px;
	--klp-thumb-outline-color: var(--klp-btn-active-border);
	--klp-fade: 260ms;
	--klp-stage-bg: rgba(0, 0, 0, 0.04);
	--klp-border-width: 1px;

	/* Button colours - resolved from the per-style defaults below */
	--klp-btn-bg: var(--klp-btn-bg-default, transparent);
	--klp-btn-border: var(--klp-btn-border-default, currentColor);
	--klp-btn-text: inherit;
	--klp-btn-hover-bg: var(--klp-btn-hover-bg-default, rgba(0, 0, 0, 0.08));
	--klp-btn-hover-border: var(--klp-btn-hover-border-default, currentColor);
	--klp-btn-hover-text: var(--klp-btn-text);
	--klp-btn-active-bg: #111111;
	--klp-btn-active-border: #111111;
	--klp-btn-active-text: #ffffff;

	--klp-thumb-ratio: var(--klp-ratio);

	display: flex;
	flex-direction: column;
	gap: var(--klp-gap);
	margin-left: auto;
	margin-right: auto;
	max-width: 100%;
}

/* Square thumbnails are opt-in; the stage always follows the first image. */
.kolor-look-preview--thumbs-square {
	--klp-thumb-ratio: 1/1;
}

/* ---------- Layout slots ---------- */

.kolor-look-preview__row {
	display: flex;
	flex-direction: column;
	gap: var(--klp-gap);
}

.kolor-look-preview__main {
	align-items: stretch;
	display: flex;
	flex-direction: row;
	gap: var(--klp-gap);
}

.kolor-look-preview__frame {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	justify-content: center;
	min-width: 0;
}

.kolor-look-preview__side {
	align-items: center;
	display: flex;
	flex: 0 0 auto;
	flex-direction: column;
	gap: var(--klp-gap);
	max-width: 40%;
}

/* Inside a side column both groups stack vertically. No overflow handling
   here: a scroll container clips child outlines on both axes. */
.kolor-look-preview__side .kolor-look-preview__looks,
.kolor-look-preview__side .kolor-look-preview__thumbs {
	flex-direction: column;
	flex-wrap: nowrap;
}

.kolor-look-preview__side .kolor-look-preview__look {
	width: 100%;
}

/* Button style presets. These only set the *defaults*; any colour the user
   picks is written inline and wins over them. */

.kolor-look-preview--solid {
	--klp-btn-bg-default: rgba(0, 0, 0, 0.08);
	--klp-btn-border-default: transparent;
	--klp-btn-hover-bg-default: rgba(0, 0, 0, 0.16);
	--klp-btn-hover-border-default: transparent;
}

.kolor-look-preview--outline {
	--klp-btn-bg-default: transparent;
	--klp-btn-border-default: currentColor;
	--klp-btn-hover-bg-default: rgba(0, 0, 0, 0.06);
	--klp-btn-hover-border-default: currentColor;
}

/* Alignment. In a row this is horizontal (left / centre / right); in a side
   column it is vertical (top / centre / bottom), done with auto margins so two
   groups sharing a column can still align independently. */

.kolor-look-preview__row .is-align-start {
	justify-content: flex-start;
}

.kolor-look-preview__row .is-align-center {
	justify-content: center;
}

.kolor-look-preview__row .is-align-end {
	justify-content: flex-end;
}

.kolor-look-preview__side .is-align-start {
	margin-bottom: auto;
}

.kolor-look-preview__side .is-align-center {
	margin-bottom: auto;
	margin-top: auto;
}

.kolor-look-preview__side .is-align-end {
	margin-top: auto;
}

/* ---------- Stage ---------- */

.kolor-look-preview__stage {
	position: relative;
	overflow: hidden;
	aspect-ratio: var(--klp-ratio);
	background: var(--klp-stage-bg);
	border-radius: var(--klp-radius-stage);
}

.kolor-look-preview__img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: contain;
	opacity: 0;
	transition: opacity var(--klp-fade) ease;
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

.kolor-look-preview__img.is-active {
	opacity: 1;
}

.kolor-look-preview--instant .kolor-look-preview__img {
	transition: none;
}

/* Without JS the first image still shows, so the block degrades to a picture. */
.kolor-look-preview--no-js .kolor-look-preview__looks,
.kolor-look-preview--no-js .kolor-look-preview__thumbs {
	opacity: 0.5;
	pointer-events: none;
}

/* ---------- Look buttons ---------- */

.kolor-look-preview__looks {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: center;
}

.kolor-look-preview__look {
	appearance: none;
	background-color: var(--klp-btn-bg);
	border: var(--klp-border-width) solid var(--klp-btn-border);
	border-radius: var(--klp-radius-button);
	color: var(--klp-btn-text);
	cursor: pointer;
	font-family: var(--klp-btn-font, inherit);
	font-size: 0.875em;
	font-weight: inherit;
	line-height: 1.2;
	margin: 0;
	padding: 0.55em 1.1em;
	transition:
		background-color 150ms ease,
		border-color 150ms ease,
		color 150ms ease;
}

.kolor-look-preview__look:hover,
.kolor-look-preview__look:focus-visible {
	background-color: var(--klp-btn-hover-bg);
	border-color: var(--klp-btn-hover-border);
	color: var(--klp-btn-hover-text);
}

.kolor-look-preview__look.is-active,
.kolor-look-preview__look.is-active:hover,
.kolor-look-preview__look.is-active:focus-visible {
	background-color: var(--klp-btn-active-bg);
	border-color: var(--klp-btn-active-border);
	color: var(--klp-btn-active-text);
}

/* ---------- Thumbnails ---------- */

.kolor-look-preview__thumbs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: center;
}

.kolor-look-preview__thumb {
	appearance: none;
	background: none;
	border: 0;
	border-radius: var(--klp-radius-thumb);
	cursor: pointer;
	line-height: 0;
	opacity: 0.65;
	overflow: hidden;
	padding: 0;
	transition:
		opacity 150ms ease,
		outline-color 150ms ease;

	/* One ring, always present but transparent until it is needed. Using an
	   outline rather than a border keeps selection from shifting the layout,
	   and means selection and focus can never stack into two rings. */
	outline: var(--klp-thumb-outline-width) solid transparent;
	outline-offset: 0;
}

.kolor-look-preview__thumb:hover,
.kolor-look-preview__thumb:focus-visible,
.kolor-look-preview__thumb.is-active {
	opacity: 1;
}

.kolor-look-preview__thumb.is-active,
.kolor-look-preview__thumb:focus-visible {
	outline-color: var(--klp-thumb-outline-color);
}

/* Focus on a thumbnail that is not the selected one reads as dashed, so the
   two states stay distinguishable without adding a second ring. */
.kolor-look-preview__thumb:focus-visible {
	outline-style: dashed;
}

.kolor-look-preview__thumb.is-active:focus-visible {
	outline-style: solid;
}

/* Thumbnails follow the same aspect ratio as the stage. */
.kolor-look-preview__thumb img {
	aspect-ratio: var(--klp-thumb-ratio);
	display: block;
	height: auto;
	margin: 0;
	object-fit: cover;
	width: var(--klp-thumb-width);
}

/* ---------- Focus and accessibility ---------- */

.kolor-look-preview__look:focus-visible {
	outline: 2px solid var(--klp-btn-active-bg);
	outline-offset: 2px;
}

.kolor-look-preview__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.kolor-look-preview__data {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.kolor-look-preview__img {
		transition: none;
	}
}

@media (max-width: 782px) {
	.kolor-look-preview__main {
		flex-direction: column;
	}

	.kolor-look-preview__side {
		max-width: 100%;
		width: 100%;
	}

	.kolor-look-preview__side .kolor-look-preview__looks,
	.kolor-look-preview__side .kolor-look-preview__thumbs {
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
	}

	.kolor-look-preview__side .kolor-look-preview__look {
		width: auto;
	}

	.kolor-look-preview__side .is-align-start,
	.kolor-look-preview__side .is-align-center,
	.kolor-look-preview__side .is-align-end {
		margin-bottom: 0;
		margin-top: 0;
	}
}

@media (max-width: 600px) {
	.kolor-look-preview {
		--klp-thumb-width: 72px;
	}
}
