/* =================================================================
   Wapu Variation Swatches – Frontend CSS
   Three swatch types: color · image · label (text button)
   Three shapes:       round · rounded · square
   Five states:        default · hover · selected · disabled · hidden
   ================================================================= */

/* ── Hide native WooCommerce <select> ───────────────────────────── */
/* PHP injects data-wapu-hidden="1" so the select is hidden before JS runs */
select[data-wapu-hidden],
.wapu-vs-hidden-select {
	display: none !important;
}

/* ── Swatch Wrapper ─────────────────────────────────────────────── */
.wapu-swatches-wrapper {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 6px 0 14px;
	--wapu-swatch-size: 40px; /* overridden inline from PHP settings */
}

/* ── Base Swatch (all types inherit this) ───────────────────────── */
.wapu-swatch {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 2px solid transparent;
	cursor: pointer;
	background: transparent;
	font-family: inherit;
	font-size: 13px;
	line-height: 1;
	outline: none;
	transition:
		border-color 0.18s ease,
		box-shadow 0.18s ease,
		opacity 0.18s ease,
		transform 0.12s ease;
}

.wapu-swatch:focus-visible {
	outline: 2px solid #2563EB;
	outline-offset: 3px;
}

/* ── Shape modifiers ────────────────────────────────────────────── */
.wapu-swatch--round   { border-radius: 50%; }
.wapu-swatch--rounded { border-radius: 6px; }
.wapu-swatch--square  { border-radius: 2px; }

/* ================================================================
   COLOR SWATCH
   ================================================================ */
.wapu-swatch--color {
	width:  var(--wapu-swatch-size);
	height: var(--wapu-swatch-size);
	border-color: #e5e7eb;
	background: transparent;
}

/* Inner colour disc – slightly smaller than the button so the border shows */
.wapu-swatch__color {
	display: block;
	width:  calc(var(--wapu-swatch-size) - 8px);
	height: calc(var(--wapu-swatch-size) - 8px);
	border-radius: inherit;
	/* For very light / white colours, add a subtle inner shadow */
	box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}

/* Shape adjustments for the inner disc */
.wapu-swatch--rounded .wapu-swatch__color { border-radius: 4px; }
.wapu-swatch--square  .wapu-swatch__color { border-radius: 1px; }

/* ================================================================
   IMAGE SWATCH
   ================================================================ */
.wapu-swatch--image {
	width:  var(--wapu-swatch-size);
	height: var(--wapu-swatch-size);
	overflow: hidden;
	border-color: #e5e7eb;
	padding: 0;
}

.wapu-swatch__img {
	display: block;
	width:  100%;
	height: 100%;
	object-fit: cover;
	border-radius: inherit;
	pointer-events: none;
}

/* ================================================================
   LABEL (TEXT BUTTON) SWATCH
   ================================================================ */
.wapu-swatch--label {
	height:     var(--wapu-swatch-size);
	min-width:  var(--wapu-swatch-size);
	padding:    0 12px;
	border-color: #d1d5db;
	background: #ffffff;
	color:      #374151;
	font-weight: 500;
	/* Shape overrides */
	border-radius: 4px;
}

.wapu-swatch--label.wapu-swatch--round   { border-radius: calc( var(--wapu-swatch-size) / 2 ); }
.wapu-swatch--label.wapu-swatch--rounded { border-radius: 6px; }
.wapu-swatch--label.wapu-swatch--square  { border-radius: 2px; }

.wapu-swatch__label {
	white-space:    nowrap;
	pointer-events: none;
}

/* ================================================================
   STATES
   ================================================================ */

/* ── Hover (available swatches only) ── */
.wapu-swatch:not( .wapu-swatch--disabled ):hover {
	border-color: #6b7280;
	transform: scale(1.08);
}

.wapu-swatch--label:not( .wapu-swatch--disabled ):hover {
	border-color: #4b5563;
	background:   #f9fafb;
	color:        #111827;
}

/* ── Selected ── */
.wapu-swatch--selected {
	border-color: #1d4ed8;
	box-shadow:   0 0 0 1px #1d4ed8;
	transform: scale(1.06);
}

.wapu-swatch--label.wapu-swatch--selected {
	background:   #1d4ed8;
	border-color: #1d4ed8;
	color:        #ffffff;
}

.wapu-swatch--label.wapu-swatch--selected:hover {
	background: #1e40af;
	color:      #ffffff;
}

/* ── Disabled / Out-of-Stock ── */
.wapu-swatch--disabled {
	opacity:        0.5;
	cursor:         not-allowed;
	pointer-events: auto; /* keep pointer so oosClickable can still fire */
	transform:      none !important;
}

/* Cross line for color & image swatches (oos_behavior = 'cross') */
.wapu-swatch--disabled.wapu-swatch--color::after,
.wapu-swatch--disabled.wapu-swatch--image::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: inherit;
	/* Diagonal line using a linear-gradient */
	background: linear-gradient(
		to top right,
		transparent       calc( 50% - 1px ),
		rgba(0,0,0,0.45)  50%,
		transparent       calc( 50% + 1px )
	);
	pointer-events: none;
}

/* Strikethrough for label swatches */
.wapu-swatch--disabled.wapu-swatch--label .wapu-swatch__label {
	text-decoration: line-through;
	color: #9ca3af;
}

/* Blur (oos_behavior = 'blur') */
.wapu-swatch--blur {
	filter: grayscale(0.6) opacity(0.45);
}

/* Hidden (oos_behavior = 'hide') */
.wapu-swatch--hidden {
	display: none !important;
}

/* ================================================================
   TOOLTIP
   ================================================================ */
.wapu-swatch__tooltip {
	position:        absolute;
	bottom:          calc( 100% + 9px );
	left:            50%;
	transform:       translateX(-50%);
	z-index:         999;
	background:      #111827;
	color:           #ffffff;
	font-size:       11px;
	line-height:     1.3;
	white-space:     nowrap;
	padding:         5px 9px;
	border-radius:   5px;
	pointer-events:  none;
	opacity:         0;
	transition:      opacity 0.15s ease;
}

/* Arrow */
.wapu-swatch__tooltip::after {
	content:      '';
	position:     absolute;
	top:          100%;
	left:         50%;
	transform:    translateX(-50%);
	border:       5px solid transparent;
	border-top-color: #111827;
}

.wapu-swatch:hover .wapu-swatch__tooltip {
	opacity: 1;
}

/* ================================================================
   ARCHIVE / SHOP LOOP – small swatch indicator dots
   ================================================================ */
.wapu-archive-swatches {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px;
	margin: 6px 0 4px;
}

.wapu-archive-swatch {
	display: inline-block;
	width: 16px;
	height: 16px;
	border: 1.5px solid rgba(0,0,0,.12);
	vertical-align: middle;
	flex-shrink: 0;
}

.wapu-archive-swatch--round   { border-radius: 50%; }
.wapu-archive-swatch--rounded { border-radius: 3px; }
.wapu-archive-swatch--square  { border-radius: 1px; }

.wapu-archive-swatch--img {
	object-fit: cover;
	vertical-align: middle;
}

.wapu-archive-swatch--label {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: auto;
	height: 18px;
	padding: 0 5px;
	font-size: 9px;
	font-weight: 600;
	color: #374151;
	background: #f3f4f6;
	border: 1px solid #e5e7eb;
	border-radius: 3px;
	line-height: 1;
	letter-spacing: 0.2px;
}

/* ================================================================
   RESPONSIVE ADJUSTMENTS
   ================================================================ */
@media ( max-width: 480px ) {
	.wapu-swatches-wrapper {
		gap: 6px;
	}

	.wapu-swatch--label {
		padding: 0 9px;
		font-size: 12px;
	}
}

/* ================================================================
   DISPLAY LABEL – shown only in grid mode, hidden elsewhere
   ================================================================ */
.wapu-swatch__display-label {
	display:        none;
	font-size:      11px;
	font-weight:    500;
	color:          #374151;
	text-align:     center;
	line-height:    1.2;
	white-space:    nowrap;
	overflow:       hidden;
	text-overflow:  ellipsis;
	pointer-events: none;
}

/* ================================================================
   SLICK MODE – ddslick-style dropdown
   data-display="slick" on .wapu-swatches-wrapper
   ================================================================ */

/* Wrapper becomes a block positioning context */
.wapu-swatches-wrapper[data-display="slick"] {
	display:  block;
	position: relative;
	margin:   6px 0 14px;
}

/* ── Trigger button (the always-visible "selected option" box) ── */
.wapu-slick__trigger {
	display:         flex;
	align-items:     center;
	gap:             10px;
	width:           100%;
	padding:         10px 14px;
	background:      #ffffff;
	border:          2px solid #d1d5db;
	border-radius:   8px;
	cursor:          pointer;
	font-family:     inherit;
	font-size:       14px;
	font-weight:     500;
	color:           #374151;
	text-align:      left;
	transition:      border-color 0.15s ease;
}

.wapu-slick__trigger:hover {
	border-color: #6b7280;
}

/* Open state: merge trigger bottom with dropdown top */
.wapu-swatches-wrapper[data-display="slick"].wapu-slick--open .wapu-slick__trigger {
	border-color:        #1d4ed8;
	border-bottom-color: transparent;
	border-radius:       8px 8px 0 0;
}

/* Thumbnail area inside trigger */
.wapu-slick__thumb {
	flex-shrink:     0;
	width:           36px;
	height:          36px;
	border-radius:   6px;
	overflow:        hidden;
	background:      #f3f4f6;
	display:         flex;
	align-items:     center;
	justify-content: center;
	flex-shrink:     0;
}

.wapu-slick__thumb img {
	width:      100%;
	height:     100%;
	object-fit: cover;
}

/* Colour dot inside trigger thumb */
.wapu-slick__thumb .wapu-slick__item-color {
	width:  22px;
	height: 22px;
}

/* Placeholder image icon */
.wapu-slick__ph-icon {
	display:      block;
	width:        20px;
	height:       20px;
	background:   #9ca3af;
	flex-shrink:  0;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E") center/contain no-repeat;
	mask:         url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Label span inside trigger */
.wapu-slick__label {
	flex:     1;
	color:    #9ca3af;  /* gray when placeholder */
	overflow: hidden;
	white-space:   nowrap;
	text-overflow: ellipsis;
}

.wapu-slick__label.wapu-slick__label--selected {
	color: #111827;
}

/* Dropdown arrow */
.wapu-slick__arrow {
	flex-shrink:  0;
	width:        0;
	height:       0;
	border-left:  5px solid transparent;
	border-right: 5px solid transparent;
	border-top:   6px solid #9ca3af;
	transition:   transform 0.15s ease;
}

.wapu-swatches-wrapper[data-display="slick"].wapu-slick--open .wapu-slick__arrow {
	transform: rotate( 180deg );
}

/* ── Dropdown list ── */
.wapu-slick__list {
	display:       none;
	position:      absolute;
	top:           100%;
	left:          0;
	right:         0;
	background:    #ffffff;
	border:        2px solid #1d4ed8;
	border-top:    none;
	border-radius: 0 0 8px 8px;
	z-index:       200;
	max-height:    320px;
	overflow-y:    auto;
	box-shadow:    0 6px 16px rgba(0,0,0,.10);
}

.wapu-swatches-wrapper[data-display="slick"].wapu-slick--open .wapu-slick__list {
	display: block;
}

/* ── Individual option ── */
.wapu-slick__option {
	display:       flex;
	align-items:   center;
	gap:           12px;
	width:         100%;
	padding:       10px 14px;
	background:    transparent;
	border:        none;
	border-bottom: 1px solid #f3f4f6;
	cursor:        pointer;
	font-family:   inherit;
	font-size:     14px;
	text-align:    left;
	color:         #374151;
	transition:    background 0.12s ease;
}

.wapu-slick__option:last-child {
	border-bottom: none;
}

.wapu-slick__option:hover {
	background: #f9fafb;
}

.wapu-slick__option.wapu-swatch--selected,
.wapu-slick__option.wapu-swatch--selected:hover {
	background: #EFF6FF;
	color:      #1d4ed8;
}

/* ── Option thumbnail ── */
.wapu-slick__item-thumb {
	flex-shrink:     0;
	width:           40px;
	height:          40px;
	border-radius:   6px;
	overflow:        hidden;
	background:      #f3f4f6;
	border:          1px solid rgba(0,0,0,.06);
	display:         flex;
	align-items:     center;
	justify-content: center;
}

.wapu-slick__item-thumb img {
	width:      100%;
	height:     100%;
	object-fit: cover;
}

.wapu-slick__item-thumb--placeholder {
	background: #f3f4f6;
}

/* Colour dot inside option thumb */
.wapu-slick__item-color {
	display:       block;
	width:         26px;
	height:        26px;
	box-shadow:    inset 0 0 0 1px rgba(0,0,0,.10);
}

.wapu-slick__item-color--round   { border-radius: 50%; }
.wapu-slick__item-color--rounded { border-radius: 4px; }
.wapu-slick__item-color--square  { border-radius: 2px; }

/* Text initials inside option thumb */
.wapu-slick__item-text {
	font-size:   11px;
	font-weight: 700;
	color:       #6b7280;
}

/* Option label */
.wapu-slick__item-label {
	flex: 1;
}

/* Reset / placeholder option */
.wapu-slick__option--reset {
	color:      #9ca3af;
	font-style: italic;
	font-size:  13px;
}

/* Disabled option */
.wapu-slick__option.wapu-swatch--disabled {
	opacity: 0.45;
	cursor:  not-allowed;
}

.wapu-slick__option.wapu-swatch--hidden {
	display: none;
}

/* ================================================================
   GRID MODE – variation cards with large image + checkmark
   data-display="grid" on .wapu-swatches-wrapper
   ================================================================ */
.wapu-swatches-wrapper[data-display="grid"] {
	display:               grid;
	grid-template-columns: repeat( auto-fill, minmax( 110px, 1fr ) );
	gap:                   10px;
	margin:                6px 0 14px;
}

/* Each swatch → card */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch {
	position:        relative;
	flex-direction:  column;
	width:           100%;
	height:          auto;
	padding:         0;
	border:          2px solid #e5e7eb;
	border-radius:   8px;
	overflow:        hidden;
	background:      #f9fafb;
	transition:      border-color 0.18s ease, box-shadow 0.18s ease;
}

.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch:hover:not( .wapu-swatch--disabled ) {
	border-color: #9ca3af;
	transform:    none; /* override default scale */
}

.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--selected {
	border-color: #16a34a;
	box-shadow:   0 0 0 1px #16a34a;
	transform:    none;
}

/* ── Radio circle (top-right corner, always visible) ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch::before {
	content:      '';
	position:     absolute;
	top:          7px;
	right:        7px;
	z-index:      2;
	width:        20px;
	height:       20px;
	border-radius: 50%;
	border:       2px solid #d1d5db;
	background:   #ffffff;
	transition:   border-color 0.15s, background 0.15s;
}

/* ── Checkmark when selected ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--selected::before {
	background:   #16a34a;
	border-color: #16a34a;
}

.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--selected::after {
	content:      '';
	position:     absolute;
	top:          7px;
	right:        7px;
	z-index:      3;
	width:        20px;
	height:       20px;
	background:   #ffffff;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E") center / 14px no-repeat;
	mask:         url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E") center / 14px no-repeat;
}

/* ── Override diagonal cross on disabled (grid uses opacity instead) ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--disabled.wapu-swatch--color::after,
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--disabled.wapu-swatch--image::after {
	background: none;
	-webkit-mask: none;
	mask: none;
}

/* ── Image fills the card ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--image .wapu-swatch__img {
	width:      100%;
	height:     calc( var(--wapu-swatch-size) * 1.8 );
	object-fit: contain;
	padding:    10px;
	box-sizing: border-box;
	background: #f9fafb;
}

/* ── Colour disc fills the card ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--color .wapu-swatch__color {
	width:         calc( 100% - 16px );
	height:        calc( var(--wapu-swatch-size) * 1.4 );
	margin:        8px;
	border-radius: 4px;
}

.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--color.wapu-swatch--round .wapu-swatch__color {
	border-radius: 50%;
}

/* ── Label below every card ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch__display-label {
	display:    block;
	padding:    5px 8px 7px;
	font-size:  12px;
	max-width:  100%;
	background: #ffffff;
	border-top: 1px solid #f3f4f6;
	color:      #374151;
	width:      100%;
	box-sizing: border-box;
	text-align: center;
	white-space: normal;
	word-break:  break-word;
}

.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--selected .wapu-swatch__display-label {
	color:       #16a34a;
	font-weight: 700;
}

/* ── Label-type swatch in grid ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch--label {
	justify-content: center;
	padding:         12px 8px;
	height:          auto;
	min-height:      64px;
}

/* ── No tooltip in grid ── */
.wapu-swatches-wrapper[data-display="grid"] .wapu-swatch__tooltip {
	display: none;
}
