@use "../tokens" as *;

// Live preview column (appendix B §4.3, D §9). Only the chrome around the swatches lives here: the
// swatches, tooltips and variation table are drawn by the storefront stylesheets loaded on the page
// (Admin\SettingsPage), with the draft's custom properties set on the frame. Rules that could meet
// storefront rules use :where() so the storefront always wins.

// The 1.x storefront class names are not BEM.
/* stylelint-disable selector-class-pattern */

// Stuck under the Save button (.ssw-settings__save: 92px + 20px + 36px + 12px). The max height
// also leaves the 80px under the columns, so the preview stays whole when the options run out.
.ssw-preview {
	position: sticky;
	top: 160px;
	max-height: calc(100vh - 240px);
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.ssw-preview-card {
	background: $surface;
	border: 1px solid $line-card;
	border-radius: $radius-card;
	overflow: hidden;
	flex: 0 1 auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.ssw-preview-card__head {
	flex: 0 0 auto;
	position: relative;
	z-index: 5;
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
	min-height: 51px;
	padding: 10px 14px;
	border-bottom: 1px solid $line-card;
	box-sizing: border-box;
}

.ssw-preview-card__label {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 11px;
	font-weight: 600;
	color: $muted-2;
	text-transform: uppercase;
	letter-spacing: 0.05em;

	&::before {
		content: "";
		width: 7px;
		height: 7px;
		border-radius: 50%;
		background: $success-ink;
		box-shadow: 0 0 0 3px #daf1e2;
	}
}

.ssw-preview-card__body {
	padding: 24px 22px;
	background: $surface;
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	display: flex;
	justify-content: center;
	align-items: flex-start;
}

// Prototype #74757a on the canvas is 4.2:1; $muted meets WCAG AA.
.ssw-preview__note {
	flex: 0 0 auto;
	font-size: 11.5px;
	color: $muted;
	margin: 10px 0 0;
	text-align: center;
}

// Device switch in the header.
.ssw-pv-seg {
	margin-left: auto;
	display: inline-flex;
	gap: 2px;
	padding: 3px;
	border-radius: $radius-menu;
	box-shadow: inset 0 0 0 1px $line-card;
	background: $surface-2;
}

.ssw-pv-seg__btn {
	border: 0;
	font-family: inherit;
	width: 32px;
	height: 26px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	border-radius: $radius-control;
	background: transparent;
	color: $text;
	transition: background 140ms $ease-std, box-shadow 140ms ease, color 140ms ease;

	&.is-on {
		background: #fff;
		color: $blue;
		box-shadow: $shadow-seg-on;
	}

	&:focus-visible {
		outline: 2px solid $blue;
		outline-offset: 1px;
	}
}

// The frame stands in for the storefront <body>: it carries the body classes and custom properties.
.ssw-pv-frame {
	position: relative;
	max-width: 100%;
	font-size: 13px;
	color: $text;
	transition: width 220ms $ease;
}

// Product page ---------------------------------------------------------------------------------

.ssw-pv-product {
	display: grid;
	grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
	gap: 26px;
	align-items: start;

	&.is-narrow {
		grid-template-columns: minmax(0, 1fr);
	}
}

.ssw-pv-gallery {
	position: relative;
	min-width: 0;
	aspect-ratio: 4 / 5;
	border-radius: $radius-pop;
	background: #eef1f2;
	overflow: hidden;
}

.ssw-pv-gallery__track {
	display: flex;
	height: 100%;
	transition: transform 420ms $ease;
}

.ssw-pv-gallery__shot {
	flex: 0 0 100%;
	width: 100%;
	height: 100%;
	display: block;
	background: #eef1f2 center / cover no-repeat;
}

.ssw-pv-gallery__arrow {
	position: absolute;
	top: 50%;
	margin-top: -15px;
	width: 30px;
	height: 30px;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.92);
	color: $ink;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(16, 17, 20, 0.12);
	opacity: 0;
	pointer-events: none;
	transition: opacity 180ms ease, transform 180ms ease;

	&.is-prev {
		left: 8px;
		transform: translateX(-6px);
	}

	&.is-next {
		right: 8px;
		transform: translateX(6px);
	}

	&.is-shown,
	&:focus-visible {
		opacity: 1;
		pointer-events: auto;
		transform: none;
	}
}

.ssw-pv-gallery__zoom {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: #fff;
	color: $ink;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 1px 2px rgba(16, 17, 20, 0.1);
}

.ssw-pv-details {
	min-width: 0;
	display: flex;
	flex-direction: column;
}

.ssw-pv-title {
	font-size: 21px;
	font-weight: 600;
	color: $ink;
	line-height: 1.25;
	letter-spacing: -0.01em;
}

.ssw-pv-rating {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	margin: 6px 0 12px;
	font-size: 12px;
}

.ssw-pv-rating__stars {
	color: #e0a72e;
	font-size: 13px;
	letter-spacing: 1px;
}

.ssw-pv-rating__score {
	color: $ink;
	font-weight: 600;
}

.ssw-pv-rating__dot {
	color: $line-ring-strong;
}

.ssw-pv-rating__link {
	color: $blue;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.ssw-pv-price {
	display: flex;
	align-items: baseline;
	flex-wrap: wrap;
	gap: 4px 9px;
	margin-bottom: 12px;
	font-variant-numeric: tabular-nums;
}

.ssw-pv-price__now {
	font-size: 20px;
	color: $ink;
	font-weight: 700;
}

.ssw-pv-price__was {
	font-size: 14px;
	color: $muted; // prototype #9a9ba0 is 2.7:1 on white
	text-decoration: line-through;
}

.ssw-pv-description {
	margin: 0 0 18px;
	font-size: 13px;
	line-height: 1.6;
	color: $text-2;
	text-wrap: pretty;
}

// The variation table as an unstyled theme would print it; the label-position classes on the frame
// (features.css) lay it out above / beside / hidden.
:where(.ssw-pv-frame) .ssw-pv-form {
	margin: 0;
}

:where(.ssw-pv-frame) table.variations {
	width: 100%;
	border: 0;
	border-collapse: collapse;
	margin: 0;
	background: none;
}

:where(.ssw-pv-frame) table.variations th.label,
:where(.ssw-pv-frame) table.variations td.value {
	padding: 0 0 14px;
	border: 0;
	background: none;
	text-align: left;
	vertical-align: middle;
}

:where(.ssw-pv-frame) table.variations th.label {
	padding-right: 12px;
	white-space: nowrap;
	width: 1%;
}

:where(.ssw-pv-frame) table.variations label {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin: 0;
	font-size: 13px;
	font-weight: 500;
	color: $text-2;
	vertical-align: baseline;
	cursor: default;
}

// The attribute name is text, as a theme prints it: name, separator and selected value run on one
// line ("Colour: Burgundy"). Accordion rows use the storefront's markup and rules (features.scss).
:where(.ssw-pv-frame) table.variations th.label label {
	display: inline;
}

// The value is bold in the 2.0 look only (frontend/look-v2.scss), as on the storefront.
:where(.ssw-pv-frame) .sp-smart-swatches-selected-label {
	color: $ink;
}

// Full width: the 1.x stylesheet makes shop cells flex containers, which would shrink the row.
// Its contents never widen the variations table (large attribute sizes in a slider would push the
// table past the column): the swatch box shrinks and clips instead.
.ssw-pv-row {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	min-width: 0;
	contain: inline-size;

	> .sp-smart-swatches-container {
		flex: 0 1 auto;
		min-width: 0;
	}
}

// Clear (styled by features.css): 14 px after the swatches, on the next line when they fill theirs,
// as on the storefront. Rows with slider buttons or Wrap's "Show less" link stay on one line.
.ssw-pv-row:has(> .reset_variations):not(:has(> .ssw-pv-step, > .ssw-pv-link)) {
	flex-wrap: wrap;
	gap: 8px 14px;
}

.ssw-pv-row:has(> .ssw-pv-step, > .ssw-pv-link) > .reset_variations {
	margin-left: 6px;
}

// Cards: scroll boxes sized by Swatches Per View follow the shop's Swatch Alignment, as on the store.
.ssw-pv-archive .ssw-pv-row {
	justify-content: var(--ssw-s-justify);
}

// Radio-button attributes as a theme prints them: native radios (wp-admin's own radio style has no
// border once the swatch styles apply, so it would draw nothing).
:where(.ssw-pv-frame) label.sp-smart-swatches-item-radio-input-wrapper.sp-smart-swatches-label {
	gap: 6px;
	margin: 0 14px 6px 0;
	font-size: 14px;
	font-weight: 400;
	color: $text;
	cursor: pointer;
}

:where(.ssw-pv-frame) input[type="radio"].sp-smart-swatches-item-radio-input {
	appearance: auto;
	width: auto;
	height: auto;
	min-width: 0;
	margin: 0;
	padding: 0;
	box-shadow: none;
}

// Attributes that stay a dropdown: WooCommerce's select.
:where(.ssw-pv-frame) .ssw-pv-select {
	min-width: 140px;
	max-width: 100%;
}

.ssw-pv-step {
	flex: 0 0 26px;
	width: 26px;
	height: 26px;
	border: 0;
	border-radius: 50%;
	background: #fff;
	color: $text;
	box-shadow: inset 0 0 0 1px $line-ring;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	cursor: pointer;
	transition: opacity 140ms ease, box-shadow 140ms ease, background 140ms ease;

	&:hover {
		box-shadow: inset 0 0 0 1px $faint;
	}

	// Card slider arrows.
	&.is-small {
		flex: 0 0 22px;
		width: 22px;
		height: auto;
		align-self: stretch;
		border-radius: $radius-control;
		background: $surface-2;
		box-shadow: none;

		&:hover {
			background: #eef0f2;
		}
	}
}

.ssw-pv-link {
	flex: 0 0 auto;
	border: 0;
	background: none;
	padding: 0 4px;
	font-family: inherit;
	font-size: 12px;
	color: $blue;
	white-space: nowrap;
	cursor: pointer;
}

.ssw-pv-cart {
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
	margin-top: 4px;
}

.ssw-pv-qty {
	display: inline-flex;
	align-items: stretch;
	flex: 0 0 auto;
	height: 40px;
	border: 1px solid $line-ring;
	border-radius: $radius-control;
	overflow: hidden;
	box-sizing: border-box;

	> span {
		width: 28px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
		color: $text-2;
	}

	> span:nth-child(2) {
		width: 24px;
		font-size: 13px;
		color: $ink;
		font-variant-numeric: tabular-nums;
	}
}

.ssw-pv-add {
	flex: 1 1 110px;
	min-width: 110px;
	height: 40px;
	padding: 0 16px;
	white-space: nowrap;
	border: 0;
	border-radius: $radius-control;
	background: $ink-2;
	color: #fff;
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	transition: opacity 160ms ease;
}

.ssw-pv-meta {
	margin-top: 20px;
	padding-top: 14px;
	border-top: 1px solid #eef0f2;
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 6px 14px;
	font-size: 12px;
	line-height: 1.5;
	color: $muted-2;
}

.ssw-pv-meta__value {
	color: $blue;
}

// Shop / Archive cards ---------------------------------------------------------------------------

.ssw-pv-archive {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 16px;
	align-items: stretch;

	&.is-narrow {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

.ssw-pv-card {
	position: relative;
	z-index: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	background: #fff;
	border: 1px solid #eef0f2;
	border-radius: $radius-pop;
	overflow: hidden;
	transition: margin-bottom 320ms $ease-std, box-shadow 240ms ease;

	&.is-raised {
		z-index: 3;
		box-shadow: 0 14px 30px rgba(16, 17, 20, 0.14);
	}
}

.ssw-pv-card__media {
	position: relative;
	aspect-ratio: 1;
	background: #eef1f2 center / cover no-repeat;
	overflow: hidden;
	transition: background 200ms ease;
}

.ssw-pv-card__body {
	padding: 12px 12px 14px;
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

.ssw-pv-card__title {
	order: 2;
	font-size: 14px;
	font-weight: 600;
	color: $ink;
	line-height: 1.3;
}

.ssw-pv-card__price {
	order: 4;
	margin-top: 3px;
	font-size: 13px;
	font-weight: 600;
	color: $text-2;
	font-variant-numeric: tabular-nums;
}

.ssw-pv-card__button {
	order: 6;
	margin-top: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 34px;
	border-radius: $radius-control;
	background: $ink;
	color: #fff;
	font-size: 13px;
	font-weight: 500;
}

.ssw-pv-card__swatches {
	min-width: 0;

	// Over the image: a strip along the bottom edge that slides in on hover.
	&.is-over {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 2;
		background: rgba(255, 255, 255, 0.9);
		transition: transform 320ms $ease-std, opacity 260ms ease;
	}

	&.is-over.is-hidden {
		transform: translateY(100%);
		opacity: 0;
	}

	// Below the image on hover: the block opens and the card overlaps the next row.
	&.is-below-hover {
		overflow: hidden;
		transition: height 320ms $ease-std, opacity 260ms ease;
	}

	&.is-below-hover.is-hidden {
		opacity: 0;
	}
}

:where(.ssw-pv-frame) table.spswp-shop-variations {
	// Cards are narrower than a nowrap row (slider, scrollbar): the cell must not grow past the card.
	table-layout: fixed;
	width: 100%;
	border: 0;
	border-collapse: collapse;
	margin: 0;
	background: none;

	td {
		border: 0;
		background: none;
	}

	td.label label {
		font-size: 12px;
		font-weight: 500;
		color: $text-2;
		margin: 0;
	}
}

// "+N" / accordion chip on cards (prototype).
.ssw-pv-more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	box-sizing: border-box;
	padding: 0 4px;
	border: 1px dashed $line-ring-strong;
	border-radius: var(--ssw-s-radius, #{$radius-control});
	background: $surface-2;
	color: $text-2;
	font-family: inherit;
	font-size: 12px;
	font-weight: 500;
	line-height: 1.2;
	cursor: pointer;
	transition: background 140ms ease;

	&.is-colour {
		padding: 0 5px;
	}

	&:hover {
		background: #eef0f2;
	}
}

// Like the store's display-style buttons (features.scss): no focus outline or ring, no tap flash.
.ssw-pv-step,
.ssw-pv-link,
.ssw-pv-more {
	-webkit-tap-highlight-color: transparent;

	&:focus,
	&:focus-visible {
		outline: none;
	}
}

// Tooltip: the storefront's own (`.ssw-tip`, frontend/features.scss), under the admin bar and menus.
.ssw-admin .ssw-tip {
	z-index: 60;
}

@media (prefers-reduced-motion: reduce) {

	.ssw-pv-frame,
	.ssw-pv-gallery__track,
	.ssw-pv-card,
	.ssw-pv-card__swatches {
		transition: none;
	}
}
