/**
 * SIM Swatches — frontend stylesheet.
 *
 * Self-contained by design: the active theme dequeues woocommerce-layout,
 * woocommerce-smallscreen, wc-blocks-style and wc-blocks-vendors-style, so
 * nothing below may rely on WooCommerce default CSS. Theme design tokens are
 * only ever referenced with a hard fallback (e.g. `var(--space-2, 8px)`), never
 * as a required value.
 *
 * All custom properties are also printed on :root inline by
 * SIM_Swatches::print_inline_css() from the saved settings. The fallback block
 * below is deliberately FIRST so the stylesheet still renders correctly if that
 * inline block fails to print (caching plugin, head stripped, etc.).
 *
 * @package SIM_Swatches
 */

/* -------------------------------------------------------------------------
 * 0. Fallback custom properties (overridden by the inline :root block)
 * ---------------------------------------------------------------------- */
:root{--sims-size-single:50px;--sims-size-archive:40px;--sims-font-single:16px;--sims-font-archive:16px;--sims-border-color:#d8d8d8;--sims-border-width:1px;--sims-border-hover-color:#8c8c8c;--sims-border-hover-width:2px;--sims-border-selected-color:#000;--sims-border-selected-width:1px;--sims-unavailable-opacity:.3;--sims-cross-color:#ff0000;--sims-radius:4px}

/* -------------------------------------------------------------------------
 * 1. Screen-reader-only utility
 * ---------------------------------------------------------------------- */
.sims-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* -------------------------------------------------------------------------
 * 2. The original <select> wrapper
 *
 * WHY clip-rect and not `display:none`:
 * WooCommerce's variations.js caches `$form.find('.variations select')` once and
 * keeps writing to that collection. The select must therefore stay in the DOM,
 * in layout, and in the accessibility tree — it is never removed, disabled or
 * re-parented. `pointer-events:none` stops it from swallowing clicks that belong
 * to the swatch sitting on top of it.
 * ---------------------------------------------------------------------- */
.sims-select {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	pointer-events: none;
}

/* Belt and braces: some UAs reserve intrinsic space for a <select> regardless
   of the clipped wrapper. */
.sims-select select {
	width: 1px;
	height: 1px;
}

/* NO-JS ESCAPE HATCH.
   The plugin never adds `no-js` itself; this exists so a theme that toggles
   html.no-js -> html.js gets a working dropdown for free when JS is dead. */
html.no-js .sims-select {
	position: static;
	width: auto;
	height: auto;
	margin: 0;
	overflow: visible;
	clip: auto;
	clip-path: none;
	pointer-events: auto;
}

html.no-js .sims-select select {
	width: auto;
	height: auto;
}

html.no-js .sims-wrap {
	display: none;
}

/* -------------------------------------------------------------------------
 * 3. Field
 * ---------------------------------------------------------------------- */
.sims-field {
	position: relative;
}

/* -------------------------------------------------------------------------
 * 4. Wrap (one per attribute)
 * ---------------------------------------------------------------------- */
.sims-wrap {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2, 8px);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Archive sizing is keyed off BOTH the data-context attribute and structural
   containment in .sims-archive. The markup contract only guarantees
   data-context on the single-product wrap, so a renderer that omits it on the
   archive wrap would otherwise silently paint 50px PDP-sized swatches into the
   product cards. Keep both selectors on every archive rule. */
.sims-wrap[data-context="archive"],
.sims-archive .sims-wrap {
	gap: 6px;
	margin-top: 8px;
}

/* -------------------------------------------------------------------------
 * 5. Archive container
 * ---------------------------------------------------------------------- */
.sims-archive {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 0 8px 10px;
}

.sims-archive--left {
	align-items: flex-start;
}

.sims-archive--center {
	align-items: center;
}

.sims-archive--right {
	align-items: flex-end;
}

.sims-archive--left .sims-wrap {
	justify-content: flex-start;
}

.sims-archive--center .sims-wrap {
	justify-content: center;
}

.sims-archive--right .sims-wrap {
	justify-content: flex-end;
}

/* -------------------------------------------------------------------------
 * 6. Term base (shared by the single-product <div> and the archive <a>)
 *
 * WHY no `overflow:hidden` here (see §12): the CSS tooltip is a ::before on
 * .sims-term positioned ABOVE the box. `overflow:hidden` on this element would
 * clip it away. The image crop that used to need it lives on .sims-term__img
 * instead. Do NOT "fix" this by moving overflow back up — it silently kills
 * every tooltip on the site.
 *
 * WHY box-sizing + the `--sims-bw` indirection: hover and selected states change
 * border-width (1px -> 2px), which would reflow a whole swatch row on every
 * mouse move. The current border width is held in `--sims-bw` on the term
 * itself, so every box that must stay stable can subtract it from its own
 * padding: border-box plus explicit width/height keeps the image and color
 * OUTER box fixed, and the compensating padding keeps their INNER box fixed
 * too. The button type has no fixed width at all, so the same subtraction is
 * the only thing stopping it from growing 2px and pushing the row along.
 * Do NOT hard-code the paddings back to constants.
 * ---------------------------------------------------------------------- */
.sims-term {
	--sims-bw: var(--sims-border-width);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	cursor: pointer;
	background: transparent;
	padding: 0;
	margin: 0;
	text-decoration: none;
	color: inherit;
	border: var(--sims-bw) solid var(--sims-border-color);
	border-radius: var(--sims-radius);
	transition: border-color .15s ease, opacity .15s ease, background-color .15s ease;
	-webkit-tap-highlight-color: transparent;
	position: relative;
}

.sims-term *,
.sims-term *::before,
.sims-term *::after {
	box-sizing: border-box;
}

.sims-term:hover {
	--sims-bw: var(--sims-border-hover-width);
	border-color: var(--sims-border-hover-color);
	border-width: var(--sims-bw);
}

.sims-term:focus-visible {
	outline: 2px solid var(--sims-border-selected-color);
	outline-offset: 2px;
}

/* `.selected` is the legacy alias emitted alongside `.is-selected` (RTWPVS-era
   markup that the theme already styles/queries). Keep both in every rule. */
.sims-term.is-selected,
.sims-term.selected {
	--sims-bw: var(--sims-border-selected-width);
	border-color: var(--sims-border-selected-color);
	border-width: var(--sims-bw);
}

/* Shape body classes. `rounded` is the default already carried by
   --sims-radius; square and circle override it at the root of the swatch. */
.sims-shape-square .sims-term {
	border-radius: 0;
}

.sims-shape-circle .sims-term--image,
.sims-shape-circle .sims-term--color {
	border-radius: 50%;
}

/* A pill is the only sane "circle" for a variable-width text swatch; without
   this the button type would silently ignore the shape setting. */
.sims-shape-circle .sims-term--button {
	border-radius: 999px;
}

/* -------------------------------------------------------------------------
 * 7. Image type — the production-critical swatch
 * ---------------------------------------------------------------------- */
.sims-term--image {
	width: var(--sims-size-single);
	height: var(--sims-size-single);
	/* 3px total inset minus the live border width: the <img> keeps exactly the
	   same box when the border grows on hover/selection. See §6. */
	padding: calc(3px - var(--sims-bw));
	/* Explicitly visible: the crop lives on the <img>, the tooltip needs to
	   escape this box. See the note in §6. */
	overflow: visible;
}

.sims-wrap[data-context="archive"] .sims-term--image,
.sims-archive .sims-wrap .sims-term--image {
	width: var(--sims-size-archive);
	height: var(--sims-size-archive);
}

.sims-term__img {
	display: block;
	width: 100%;
	height: 100%;
	/* Only !important in the file: themes ship a global `img{max-width:100%}`
	   which fights object-fit inside a border-box parent and letterboxes the
	   swatch. Nothing else here needs the escalation. */
	max-width: none !important;
	object-fit: cover;
	border-radius: calc(var(--sims-radius) - 2px);
	overflow: hidden;
}

.sims-shape-square .sims-term__img {
	border-radius: 0;
}

.sims-shape-circle .sims-term__img {
	border-radius: 50%;
}

/* -------------------------------------------------------------------------
 * 8. Color type
 * ---------------------------------------------------------------------- */
.sims-term--color {
	width: var(--sims-size-single);
	height: var(--sims-size-single);
	/* 4px total inset minus the live border width — see §6. */
	padding: calc(4px - var(--sims-bw));
	overflow: visible;
}

.sims-wrap[data-context="archive"] .sims-term--color,
.sims-archive .sims-wrap .sims-term--color {
	width: var(--sims-size-archive);
	height: var(--sims-size-archive);
}

.sims-term__color {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: calc(var(--sims-radius) - 3px);
	background: var(--sims-color, #d8d8d8);
	/* REQUIRED, not decorative: the inset ring is the only thing that keeps a
	   #ffffff swatch visible on a white page. Do not remove it. */
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}

.sims-shape-square .sims-term__color {
	border-radius: 0;
}

.sims-shape-circle .sims-term--color,
.sims-shape-circle .sims-term__color {
	border-radius: 50%;
}

/* -------------------------------------------------------------------------
 * 9. Button / pill type
 *
 * The 40px height / 44px width minimums are deliberate touch targets on the
 * product page. Do not shrink them there; the archive variant is the only
 * place allowed to go smaller.
 * ---------------------------------------------------------------------- */
.sims-term--button {
	min-height: 40px;
	min-width: 44px;
	/* 13px total horizontal inset minus the live border width: a pill has no
	   fixed width, so without this subtraction the 1px -> 2px hover border
	   would widen it by 2px and shove every following swatch sideways. */
	padding: 0 calc(13px - var(--sims-bw));
	font-size: var(--sims-font-single);
	line-height: 1.2;
	font-weight: 500;
	background: #fff;
	color: #111;
}

.sims-wrap[data-context="archive"] .sims-term--button,
.sims-archive .sims-wrap .sims-term--button {
	min-height: 32px;
	min-width: 32px;
	padding: 0 calc(9px - var(--sims-bw));
	font-size: var(--sims-font-archive);
}

.sims-term--button.is-selected,
.sims-term--button.selected {
	background: var(--sims-border-selected-color);
	color: #fff;
}

.sims-term__label {
	display: block;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * 10. Unavailable / out-of-stock states
 *
 * Driven entirely by the body class, so changing the `unavailable_behavior`
 * setting is a class swap with no re-render and no JS involvement.
 *
 * `.is-out-of-stock` looks identical to `.is-disabled` in every mode; only the
 * cursor differs, because an out-of-stock term stays clickable when the
 * `out_of_stock_clickable` setting is on. Hence: visuals target both classes,
 * `cursor:not-allowed` targets `.is-disabled` alone.
 *
 * pointer-events are NEVER set to none on a disabled term — the JS decides
 * whether a click is honoured, and a keyboard/screen-reader user must still be
 * able to reach the element and hear its aria-disabled state.
 * ---------------------------------------------------------------------- */
.sims-term.is-disabled {
	cursor: not-allowed;
}

/* --- blur (default) --- */
body.sims-unavailable-blur .sims-term.is-disabled,
body.sims-unavailable-blur .sims-term.is-out-of-stock {
	opacity: var(--sims-unavailable-opacity);
	filter: blur(.6px);
}

/* Desaturating the media is a blur-mode flourish only, so it is scoped rather
   than living on the bare state class. */
body.sims-unavailable-blur .sims-term.is-disabled .sims-term__img,
body.sims-unavailable-blur .sims-term.is-disabled .sims-term__color,
body.sims-unavailable-blur .sims-term.is-out-of-stock .sims-term__img,
body.sims-unavailable-blur .sims-term.is-out-of-stock .sims-term__color {
	filter: grayscale(1);
}

/* --- cross --- */
body.sims-unavailable-cross .sims-term.is-disabled,
body.sims-unavailable-cross .sims-term.is-out-of-stock {
	opacity: var(--sims-unavailable-opacity);
}

/* A pseudo-element gradient rather than a background image: it scales cleanly
   with any swatch size and never fights the term's own background. */
body.sims-unavailable-cross .sims-term.is-disabled::after,
body.sims-unavailable-cross .sims-term.is-out-of-stock::after {
	content: "";
	position: absolute;
	inset: 0;
	/* Follow the swatch shape, otherwise the square gradient box pokes out of a
	   circle/rounded term (the term itself is overflow:visible for tooltips). */
	border-radius: inherit;
	background: linear-gradient(to top left, transparent calc(50% - 1px), var(--sims-cross-color) calc(50% - 1px), var(--sims-cross-color) calc(50% + 1px), transparent calc(50% + 1px));
	pointer-events: none;
}

body.sims-unavailable-cross .sims-term--button.is-disabled,
body.sims-unavailable-cross .sims-term--button.is-out-of-stock {
	text-decoration: line-through;
	text-decoration-color: var(--sims-cross-color);
}

/* --- hide --- */
body.sims-unavailable-hide .sims-term.is-disabled,
body.sims-unavailable-hide .sims-term.is-out-of-stock {
	display: none;
}

/* --- none: state class stays for JS/QA, no visual change --- */
body.sims-unavailable-none .sims-term.is-disabled,
body.sims-unavailable-none .sims-term.is-out-of-stock {
	opacity: 1;
	filter: none;
}

/* -------------------------------------------------------------------------
 * 11. Overflow indicator ("+3"), archive only
 * ---------------------------------------------------------------------- */
.sims-more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 24px;
	height: var(--sims-size-archive);
	padding: 0 6px;
	font-size: 12px;
	color: #666;
}

/* -------------------------------------------------------------------------
 * 12. Tooltip — pure CSS, no library, from the data-tooltip attribute
 *
 * Only on real hover-capable pointers: on touch, :hover sticks after a tap and
 * would leave the label stranded over the grid.
 *
 * This is why .sims-term must not set `overflow:hidden` (see §6). The image
 * crop is applied on .sims-term__img instead, leaving .sims-term--image with
 * `overflow:visible` so the tooltip can escape the swatch box.
 * ---------------------------------------------------------------------- */
@media (hover: hover) {

	.sims-term[data-tooltip]:hover::before {
		content: attr(data-tooltip);
		position: absolute;
		bottom: calc(100% + 6px);
		left: 50%;
		transform: translateX(-50%);
		background: #111;
		color: #fff;
		font-size: 11px;
		line-height: 1;
		padding: 5px 7px;
		border-radius: 3px;
		white-space: nowrap;
		pointer-events: none;
		z-index: 5;
	}
}

/* -------------------------------------------------------------------------
 * 13. Reduced motion
 * ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {

	.sims-term {
		transition: none;
	}
}

/* -------------------------------------------------------------------------
 * 14. HANDS OFF: .reset_variations
 *
 * WooCommerce shows/hides the "LIMPIAR" reset link with
 * visibility:hidden|visible only. Any rule here that sets `display` on it — or
 * otherwise hides it — permanently breaks the reset flow, because WC will keep
 * flipping a visibility value that no longer has any effect. There is
 * deliberately NO `.reset_variations` rule in this file. Do not add one.
 * ---------------------------------------------------------------------- */
