/**
 * Sayan Variation Swatches – Frontend Styles
 *
 * CSS custom properties are injected via wp_add_inline_style based
 * on the saved plugin settings.
 *
 * @package Sayan_Variation_Swatches
 */

/* ============================================================
   CSS Custom Property Defaults
   (overridden by inline style from PHP settings)
   ============================================================ */
:root {
	--svsw-width: 36px;
	--svsw-height: 36px;
	--svsw-archive-width: 28px;
	--svsw-archive-height: 28px;
	--svsw-border-color: #dddddd;
	--svsw-selected-border-color: #333333;
	--svsw-checkmark-color: #ffffff;
	--svsw-tooltip-bg: #333333;
	--svsw-tooltip-color: #ffffff;
	--svsw-tooltip-font-size: 13px;
	--svsw-gap: 6px;
	--svsw-transition: 0.15s ease;
}

/* ============================================================
   Swatch Wrapper
   ============================================================ */
.svsw-swatches-wrap {
	margin-top: 6px;
	margin-bottom: 4px;
}

.svsw-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: var( --svsw-gap );
	align-items: center;
	margin: 4px 0 6px;
}

/* ============================================================
   Individual Swatch
   ============================================================ */
.svsw-swatch {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var( --svsw-width );
	height: var( --svsw-height );
	box-sizing: border-box;
	border: 2px solid var( --svsw-border-color );
	cursor: pointer;
	transition:
		border-color var( --svsw-transition ),
		transform var( --svsw-transition ),
		box-shadow var( --svsw-transition );
	overflow: hidden;
	outline: none;
}

/* Hover */
.svsw-swatch:hover {
	border-color: var( --svsw-selected-border-color );
	transform: scale( 1.08 );
	box-shadow: 0 2px 8px rgba( 0, 0, 0, 0.12 );
}

/* Focus (keyboard navigation) */
.svsw-swatch:focus-visible {
	outline: 2px solid var( --svsw-selected-border-color );
	outline-offset: 2px;
}

/* Selected */
.svsw-swatch.selected,
.svsw-swatch[aria-checked="true"] {
	border-color: var( --svsw-selected-border-color );
	box-shadow: 0 0 0 2px var( --svsw-selected-border-color );
}

/* ============================================================
   Shape Modifiers
   ============================================================ */
.svsw-shape-square  .svsw-swatch { border-radius: 0; }
.svsw-shape-rounded .svsw-swatch { border-radius: 6px; }
.svsw-shape-circle  .svsw-swatch { border-radius: 50%; }

/* Individual overrides (per-term) */
.svsw-swatch.svsw-shape-square  { border-radius: 0; }
.svsw-swatch.svsw-shape-rounded { border-radius: 6px; }
.svsw-swatch.svsw-shape-circle  { border-radius: 50%; }

/* ============================================================
   Swatch Inner (color / image)
   ============================================================ */
.svsw-swatch-inner {
	display: block;
	width: 100%;
	height: 100%;
}

.svsw-swatch img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* Label swatch text */
.svsw-label-text {
	font-size: 12px;
	font-weight: 500;
	line-height: 1;
	white-space: nowrap;
	padding: 0 4px;
	color: inherit;
}

/* ============================================================
   Radio Swatch
   ============================================================ */
.svsw-radio-wrap {
	width: auto;
	min-width: var( --svsw-width );
	padding: 0 8px;
	background: #f9f9f9;
	gap: 6px;
}

.svsw-radio-dot {
	display: inline-block;
	width: 12px;
	height: 12px;
	border: 2px solid var( --svsw-border-color );
	border-radius: 50%;
	transition: background var( --svsw-transition ), border-color var( --svsw-transition );
}

.svsw-radio-wrap.selected .svsw-radio-dot,
.svsw-radio-wrap[aria-checked="true"] .svsw-radio-dot {
	background: var( --svsw-selected-border-color );
	border-color: var( --svsw-selected-border-color );
}

/* ============================================================
   Checkmark on Selected Swatch
   ============================================================ */
.svsw-swatch.selected::after,
.svsw-swatch[aria-checked="true"]::after {
	content: '';
	position: absolute;
	bottom: 3px;
	right: 3px;
	width: 8px;
	height: 8px;
	background: var( --svsw-checkmark-color );
	clip-path: polygon( 14% 44%, 0 65%, 50% 100%, 100% 15%, 80% 0%, 43% 62% );
}

/* ============================================================
   Out-of-Stock Styles
   ============================================================ */
.svsw-swatch.svsw-unavailable {
	opacity: 0.45;
	cursor: not-allowed;
	pointer-events: none;
}

/* blur-cross: diagonal line */
.svsw-swatch.svsw-unavailable.svsw-cross::before {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 130%;
	height: 2px;
	background: rgba( 0, 0, 0, 0.35 );
	transform: translate( -50%, -50% ) rotate( -45deg );
	z-index: 2;
}

/* ============================================================
   Tooltip
   ============================================================ */
.svsw-swatch {
	/* needed for absolute child */
}

.svsw-tooltip {
	position: absolute;
	bottom: calc( 100% + 8px );
	left: 50%;
	transform: translateX( -50% );
	background: var( --svsw-tooltip-bg );
	color: var( --svsw-tooltip-color );
	font-size: var( --svsw-tooltip-font-size );
	padding: 4px 8px;
	border-radius: 4px;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s;
	z-index: 999;
	line-height: 1.4;
}

.svsw-tooltip::after {
	content: '';
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX( -50% );
	border: 5px solid transparent;
	border-top-color: var( --svsw-tooltip-bg );
}

.svsw-swatch:hover .svsw-tooltip,
.svsw-swatch:focus-visible .svsw-tooltip {
	opacity: 1;
	visibility: visible;
}

/* ============================================================
   Selected Attribute Name
   ============================================================ */
.svsw-selected-name {
	display: inline-block;
	font-size: 13px;
	color: #555;
	margin-left: 6px;
}

/* ============================================================
   Archive / Shop Page Swatches
   ============================================================ */
.svsw-archive-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin: 6px 0 4px;
	padding: 0;
}

.svsw-archive-attribute {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

.svsw-archive-swatch {
	width: var( --svsw-archive-width );
	height: var( --svsw-archive-height );
	box-sizing: border-box;
	border: 2px solid var( --svsw-border-color );
	cursor: default;
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	transition: border-color var( --svsw-transition );
}

.svsw-archive-swatch .svsw-label-text {
	font-size: 10px;
}

.svsw-archive-swatch:hover {
	border-color: var( --svsw-selected-border-color );
}

/* ============================================================
   Utility
   ============================================================ */
.svsw-hidden-select {
	display: none !important;
}

/* ============================================================
   Loading / Skeleton State
   ============================================================ */
.svsw-loading .svsw-swatch {
	background: #f0f0f0;
	animation: svsw-pulse 1.2s ease-in-out infinite;
}

@keyframes svsw-pulse {
	0%, 100% { opacity: 1; }
	50%       { opacity: 0.5; }
}
