/*
 * NLW Variation Swatches v2.1.0 — Frontend
 */

/* ─── Graceful fallback: select hidden via CSS class ───────── */
select.nlw-vs-raw-select {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	border: 0 !important;
	clip: rect(0, 0, 0, 0) !important;
	overflow: hidden !important;
	white-space: nowrap !important;
}

/* ─── Swatch list ──────────────────────────────────────────── */
.nlw-vs-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	list-style: none;
	margin: 4px 0 12px;
	padding: 0;
}

/* ─── Swatch item ──────────────────────────────────────────── */
.nlw-vs-item {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--nlw-vs-size, 36px);
	height: var(--nlw-vs-size, 36px);
	cursor: pointer;
	border: 2px solid #d4d4d4;
	background: #fff;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
	user-select: none;
	outline: none;
	box-sizing: border-box;
	overflow: hidden;
}

.nlw-vs-item-inner {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	position: relative;
	z-index: 1;
}

/* ─── Shapes ───────────────────────────────────────────────── */
.nlw-vs-shape-rounded .nlw-vs-item,
.nlw-vs-shape-rounded .nlw-vs-archive-item { border-radius: 6px; }
.nlw-vs-shape-squared .nlw-vs-item,
.nlw-vs-shape-squared .nlw-vs-archive-item { border-radius: 0; }
.nlw-vs-shape-circle .nlw-vs-item,
.nlw-vs-shape-circle .nlw-vs-archive-item  { border-radius: 50%; }

/* ─── Color / Image / Button ───────────────────────────────── */
.nlw-vs-color-swatch {
	display: block; width: 100%; height: 100%; border-radius: inherit;
}

.nlw-vs-image-swatch {
	display: block; width: 100%; height: 100%; object-fit: cover; border-radius: inherit;
}

.nlw-vs-type-button .nlw-vs-item {
	width: auto; min-width: var(--nlw-vs-size, 36px); padding: 0 12px;
}

.nlw-vs-button-swatch {
	font-size: var(--nlw-vs-font-size, 14px);
	font-weight: 500; line-height: 1; white-space: nowrap; color: #333;
}

/* ─── Hover / Selected ─────────────────────────────────────── */
.nlw-vs-item:hover:not(.disabled):not(.no-stock) {
	border-color: #666;
	box-shadow: 0 0 0 1px #666;
}

.nlw-vs-item.selected {
	border-color: #222;
	box-shadow: 0 0 0 1px #222;
}

.nlw-vs-item.selected .nlw-vs-button-swatch {
	color: #111; font-weight: 600;
}

/* Checkmark on selected color/image */
.nlw-vs-type-color .nlw-vs-item.selected .nlw-vs-item-inner::after,
.nlw-vs-type-image .nlw-vs-item.selected .nlw-vs-item-inner::after {
	content: '';
	position: absolute; top: 50%; left: 50%;
	transform: translate(-50%, -50%);
	width: 14px; height: 14px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 13l4 4L19 7'/%3E%3C/svg%3E");
	background-size: contain; background-repeat: no-repeat;
	filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.7));
	pointer-events: none; z-index: 3;
}

/* ─── Disabled / Unavailable ───────────────────────────────── */
.nlw-vs-item.disabled { opacity: 0.35; cursor: not-allowed; }

.nlw-vs-item.disabled::after {
	content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
	background: linear-gradient(to top right,
		transparent calc(50% - 0.5px), #cc0000 calc(50% - 0.5px),
		#cc0000 calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.nlw-vs-disabled-blur .nlw-vs-item.disabled::after { display: none; }
.nlw-vs-item.nlw-vs-hidden { display: none !important; }

.nlw-vs-item.no-stock { opacity: 0.5; cursor: pointer; }

.nlw-vs-item.no-stock::after {
	content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
	background: linear-gradient(to top right,
		transparent calc(50% - 0.5px), #999 calc(50% - 0.5px),
		#999 calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* ─── Focus ────────────────────────────────────────────────── */
.nlw-vs-item:focus-visible {
	outline: 2px solid #2271b1; outline-offset: 2px;
}

/* ─── Selected name label ──────────────────────────────────── */
.nlw-vs-selected-name {
	font-weight: 400;
	color: #555;
	margin-left: 2px;
	display: inline;
}

/* Keep label + selected name on one line */
.variations .label {
	white-space: nowrap;
}

/* ─── Single product: Blocksy variation layout fixes ──────── */
/* Blocksy sets label to display:block — force inline so "Βάρος: 2 kg" stays on one line */
.variations th.label label,
.variations td.label label {
	display: inline !important;
}

/* ─── Tooltip ──────────────────────────────────────────────── */
.nlw-vs-tooltip [data-nlw-vs-tooltip]::before {
	content: attr(data-nlw-vs-tooltip);
	position: absolute; bottom: calc(100% + 8px); left: 50%;
	transform: translateX(-50%);
	padding: 4px 10px; border-radius: 4px;
	background: #222; color: #fff;
	font-size: 12px; font-weight: 400; line-height: 1.4;
	white-space: nowrap; pointer-events: none;
	opacity: 0; visibility: hidden;
	transition: opacity 0.15s ease, visibility 0.15s ease;
	z-index: 100;
}

.nlw-vs-tooltip [data-nlw-vs-tooltip] > .nlw-vs-item-inner::before {
	content: '';
	position: absolute; bottom: calc(100% + 3px); left: 50%;
	transform: translateX(-50%);
	border: 5px solid transparent; border-top-color: #222;
	pointer-events: none; opacity: 0; visibility: hidden;
	transition: opacity 0.15s ease, visibility 0.15s ease;
	z-index: 100;
}

.nlw-vs-tooltip [data-nlw-vs-tooltip]:hover::before,
.nlw-vs-tooltip [data-nlw-vs-tooltip]:focus::before { opacity: 1; visibility: visible; }

.nlw-vs-tooltip [data-nlw-vs-tooltip]:hover > .nlw-vs-item-inner::before,
.nlw-vs-tooltip [data-nlw-vs-tooltip]:focus > .nlw-vs-item-inner::before { opacity: 1; visibility: visible; }

.nlw-vs-tooltip .nlw-vs-item.disabled::before,
.nlw-vs-tooltip .nlw-vs-item.disabled > .nlw-vs-item-inner::before { display: none; }

/* ─── Mobile ───────────────────────────────────────────────── */
@media (max-width: 768px) {
	.nlw-vs-swatches { gap: 6px; }
	.nlw-vs-tooltip [data-nlw-vs-tooltip]::before,
	.nlw-vs-tooltip [data-nlw-vs-tooltip] > .nlw-vs-item-inner::before {
		display: none !important;
	}
}

.nlw-vs-value-cell { position: relative; }

/* ═══════════════════════════════════════════════════════════
   ARCHIVE / LOOP SWATCHES
   ═══════════════════════════════════════════════════════════ */

.nlw-vs-archive-swatches {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	margin: 6px 0 10px;
}

.nlw-vs-archive-items {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	justify-content: center;
}

/* ─── Archive swatch item (shared base) ────────────────────── */
.nlw-vs-archive-item {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: calc(var(--nlw-vs-size, 36px) * 0.78);
	height: calc(var(--nlw-vs-size, 36px) * 0.78);
	border: 2px solid #d4d4d4;
	background: #fff;
	overflow: hidden;
	box-sizing: border-box;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
	text-decoration: none;
	cursor: pointer;
}

.nlw-vs-archive-item:hover {
	border-color: #999;
}

.nlw-vs-archive-item .nlw-vs-color-swatch,
.nlw-vs-archive-item img {
	width: 100%; height: 100%; display: block;
	object-fit: cover; border-radius: inherit;
}

/* Button type in archive */
.nlw-vs-type-button .nlw-vs-archive-item {
	width: auto;
	min-width: calc(var(--nlw-vs-size, 36px) * 0.78);
	padding: 0 8px;
	height: calc(var(--nlw-vs-size, 36px) * 0.78);
}

.nlw-vs-archive-item .nlw-vs-button-swatch {
	font-size: calc(var(--nlw-vs-font-size, 14px) * 0.85);
	font-weight: 500; line-height: 1;
	white-space: nowrap; color: #333; text-decoration: none;
}

/* ─── Archive: selected state ──────────────────────────────── */
.nlw-vs-archive-selected {
	border-color: #333 !important;
}

.nlw-vs-archive-selected .nlw-vs-button-swatch {
	font-weight: 700;
	color: #111;
}

/* ─── Archive: unavailable (out of stock) ──────────────────── */
.nlw-vs-archive-unavailable {
	opacity: 0.35;
	cursor: not-allowed;
	pointer-events: none;
}

/* ─── Archive: Add to Cart button ──────────────────────────── */
/* Base styling comes from the theme (Blocksy, etc.) via .button + .add_to_cart_button classes.
   We only define states: disabled, loading, success, error. */
.nlw-vs-archive-cart-btn {
	white-space: nowrap;
}

.nlw-vs-archive-cart-btn[disabled] {
	opacity: 0.4;
	cursor: not-allowed;
}

/* Loading state */
.nlw-vs-archive-cart-btn.nlw-vs-loading {
	opacity: 0.7;
	cursor: wait;
	pointer-events: none;
}

/* Success state */
.nlw-vs-archive-cart-btn.nlw-vs-added {
	background: #2e7d32 !important;
	border-color: #2e7d32 !important;
	color: #fff !important;
}

/* Error state */
.nlw-vs-archive-cart-btn.nlw-vs-error {
	background: #c62828 !important;
	border-color: #c62828 !important;
	color: #fff !important;
}

/* ─── Hide WC's native "Select options" on products with our cart btn ── */
/* Excludes our own button via :not(.nlw-vs-archive-cart-btn) */
li.product.nlw-vs-has-archive-cart .button.product_type_variable:not(.nlw-vs-archive-cart-btn),
li.product.nlw-vs-has-archive-cart a.product_type_variable:not(.nlw-vs-archive-cart-btn) {
	display: none !important;
}

/* ─── Shortcode wrapper — fills card height, button at bottom ──── */
.nlw-vs-shortcode-wrap {
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	width: 100%;
}

.nlw-vs-shortcode-btn-wrap {
	margin-top: auto;
	width: 100%;
	text-align: center;
	padding-top: 8px;
}

.nlw-vs-shortcode-btn-wrap .button {
	display: inline-block;
}
