/**
 * Attribute chips — [bb_attribute_chips], see includes/attribute-chips.php.
 *
 * A grid of "icon tile + term name" chips, built for the mega menu but not tied
 * to it. Self-contained: the plugin's `.bb-attr-icon` rules are sized for the
 * product grid and the filter widget, so the chip tile carries its own.
 *
 * Column order is top-to-bottom, then left-to-right (like the design): the
 * shortcode prints the row count as `--bb-chips-rows` and the grid fills by
 * column. Whole `repeat()` values live in the custom properties rather than
 * `repeat(var(--n), …)`, so the media queries below can simply re-declare
 * grid-template-* and win on source order.
 */

.bb-attr-chips {
	display: grid;
	grid-auto-flow: column;
	grid-template-columns: var(--bb-chips-cols, repeat(3, minmax(0, 1fr)));
	grid-template-rows: var(--bb-chips-rows, auto);
	gap: 10px;
}

/* --------------------------------------------------------------------------
 * Chip
 * ----------------------------------------------------------------------- */

/*
 * Anchor colours are set explicitly: inside a dropdown the chip would otherwise
 * inherit --fs-experimental-link-color, and Flatsome's `.dark` dropdown variant
 * would flip it to near-white on hover.
 */
.bb-attr-chip {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	min-height: 48px;
	padding: 6px 14px 6px 6px;
	border-radius: 12px;
	background-color: rgba(36, 71, 87, 0.06);
	color: var(--fs-color-secondary, #244757);
	font-size: 14px;
	font-weight: 700;
	line-height: 1.25;
	text-decoration: none;
	transition: background-color 0.25s ease, color 0.25s ease;
}

/*
 * Hover picks up the term's own colour (the icon background, published by the
 * shortcode as --bb-chip-color). Terms without a colour fall back to the brand
 * primary. The flat rgba() above it is the fallback for browsers without
 * color-mix().
 */
.bb-attr-chip:hover,
.bb-attr-chip:focus-visible {
	background-color: rgba(36, 71, 87, 0.12);
	background-color: color-mix(in srgb, var(--bb-chip-color, var(--fs-color-primary, #b01e22)) 20%, transparent);
	color: var(--fs-color-secondary, #244757);
}

.bb-attr-chip:focus-visible {
	outline: 2px solid var(--fs-color-primary, #b01e22);
	outline-offset: 2px;
}

/* A term without a link (link="none") is a <span> — no pointer, no hover. */
span.bb-attr-chip:hover {
	background-color: rgba(36, 71, 87, 0.06);
}

/* No icon tile to pad around — keep the label off the chip's edge. */
.bb-attr-chip--no-icon {
	padding-left: 14px;
}

.bb-attr-chip__label {
	min-width: 0;
}

.bb-attr-chip__count {
	margin-left: auto;
	padding-left: 6px;
	font-weight: 500;
	opacity: 0.5;
}

/* --------------------------------------------------------------------------
 * Icon tile
 * ----------------------------------------------------------------------- */

/*
 * Two modes, matching BB_Attribute_Icons: no colour set → the uploaded image
 * fills the tile (art that brings its own background); colour set (.has-bg) →
 * the tile is that colour with the glyph inset on top.
 */
.bb-attr-chip__icon {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	overflow: hidden;
	border-radius: 9px;
	background-color: var(--bb-chip-color, transparent);
}

.bb-attr-chip__icon img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	margin: 0;
	object-fit: contain;
}

.bb-attr-chip__icon.has-bg img {
	width: 64%;
	height: 64%;
}

/* --------------------------------------------------------------------------
 * Product chips — [bb_product_chips]
 * ----------------------------------------------------------------------- */

/*
 * The product-summary variant: chips sized to their own content and wrapping,
 * in the display font, like the badges in the design. Every rule here is scoped
 * to the wrapper so the mega-menu chips keep the quieter treatment above.
 */
.bb-product-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.bb-product-chips .bb-attr-chip {
	gap: 12px;
	min-height: 30px;
	padding: 6px 10px;
	border-radius: 6px;
	font-family: "Peace Sans", sans-serif;
	font-size: 15px;
	letter-spacing: 0.03em;
	text-transform: uppercase;
}

.bb-product-chips .bb-attr-chip__icon {
	width: 22px;
	height: 22px;
	border-radius: 0;
}

/* Informational by default (link="none" renders a <span>) — no hover shift. */
.bb-product-chips span.bb-attr-chip:hover {
	background-color: rgba(36, 71, 87, 0.06);
}

/* --------------------------------------------------------------------------
 * Style chips — [bb_product_stijl_chips]
 * ----------------------------------------------------------------------- */

/*
 * Stijl links into the filtered shop, so with display="chip" its chips keep the
 * mega-menu look (base .bb-attr-chip above, hover tint and all) rather than the
 * compact uppercase badge the other product chips wear — only the layout
 * differs, a wrapping row instead of a column grid.
 */
.bb-stijl-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: -60px 0 15px 0;
}

/*
 * display="icon" (the default) renders the plugin's own `.bb-attr-icon` tiles,
 * so size, radius, border, colour and the hover tooltip all come from
 * bb-woocommerce-addons/assets/css/attribute-icons.css and the product page
 * matches the product card by construction.
 *
 * The one thing that file does NOT give us is the image inside the tile: its
 * img rules are all scoped to `.box-image`, because there they exist to fight
 * Flatsome's product-image CSS. Outside a product box the image would render at
 * its natural size, so the two modes are restated here — plain `.bb-attr-icon`
 * means art that brings its own background and fills the tile, `.has-bg` means
 * a transparent glyph inset on a coloured tile.
 */
.bb-stijl-chips--icons .bb-attr-icon{
	width: 58px;
	height: 58px;
}

.bb-stijl-chips--icons .bb-attr-icon img,
.bb-stijl-chips--icons .bb-attr-icon svg {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	margin: 0;
	object-fit: contain;
	/* The tile can't clip (the tooltip needs overflow), so the image that fills
	   it carries the rounding: 12px tile radius minus the 2px border. */
	border-radius: 10px;
}

.bb-stijl-chips--icons .bb-attr-icon.has-bg img,
.bb-stijl-chips--icons .bb-attr-icon.has-bg svg {
	width: 60%;
	height: 60%;
	border-radius: 0;
}

/*
 * The link (.bb-stijl-tile) wraps the tile and a label. The label is
 * screen-reader-only on desktop, where the hover tooltip shows the name, and a
 * compact badge on touch screens (see Responsive below).
 */
.bb-stijl-tile {
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	color: var(--fs-color-secondary, #244757);
	text-decoration: none;
}

.bb-stijl-tile__label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.bb-stijl-tile:focus-visible {
	outline: 0;
}

.bb-stijl-tile:focus-visible .bb-attr-icon {
	outline: 2px solid var(--fs-color-primary, #b01e22);
	outline-offset: 2px;
}

/* The tooltip keys off the tile's own :focus-visible; the link has the focus. */
@media (hover: hover) {
	.bb-stijl-tile:focus-visible .bb-attr-icon[data-bb-tip]::before,
	.bb-stijl-tile:focus-visible .bb-attr-icon[data-bb-tip]::after {
		opacity: 1;
		visibility: visible;
	}
}

/*
 * The built-in people glyph. `currentColor` keeps it on the chip's text colour
 * instead of needing its own; an uploaded icon overrides the whole tile.
 */
.bb-attr-chip__glyph {
	display: block;
	width: 20px;
	height: 20px;
	fill: currentColor;
}

/* --------------------------------------------------------------------------
 * Optional heading row
 * ----------------------------------------------------------------------- */

/*
 * Shared with [bb_category_tiles], which prints this same row above its tiles.
 * Title and link are in the display font; Peace Sans is single-weight, so
 * they stay at 400 rather than invite faux bold.
 */
.bb-attr-chips-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 16px;
	margin-bottom: 14px;
}

.bb-attr-chips-head__title {
	color: var(--fs-color-primary, #b01e22);
	font-family: "Peace Sans", sans-serif;
	font-size: 15px;
	font-weight: 400;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.bb-attr-chips-head__all {
	color: var(--fs-color-secondary, #244757);
	font-family: "Peace Sans", sans-serif;
	font-size: 13px;
	font-weight: 400;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	text-decoration: none;
	white-space: nowrap;
}

.bb-attr-chips-head__all:hover {
	color: var(--fs-color-primary, #b01e22);
}

.bb-attr-chips-head__arrow {
	margin-left: 6px;
}

/* --------------------------------------------------------------------------
 * Responsive
 * ----------------------------------------------------------------------- */

/*
 * Flatsome's tier edges. Below the large tier the column count is CSS-driven,
 * so the row count published by the shortcode no longer applies and the grid
 * flows by row instead.
 */
@media (max-width: 849px) {
	.bb-attr-chips {
		grid-auto-flow: row;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-template-rows: auto;
	}
}

@media (max-width: 549px) {
	.bb-attr-chips {
		grid-template-columns: minmax(0, 1fr);
	}
}

/*
 * Stijl on touch screens: there is no hover, so instead of icon tiles with a
 * tooltip the links become the same compact badges as [bb_product_chips] —
 * small icon plus the name — keeping the term colour as the tap tint.
 * Phones and tablets by width (Flatsome's medium edge), plus any device that
 * cannot hover at all, e.g. a tablet in landscape.
 */
@media (max-width: 849px), (hover: none) {
	.bb-stijl-chips {
		margin-top: 0;
	}

	.bb-stijl-tile {
		flex-direction: row;
		gap: 12px;
		min-height: 30px;
		padding: 6px 10px;
		border-radius: 6px;
		background-color: rgba(36, 71, 87, 0.06);
		font-family: "Peace Sans", sans-serif;
		font-size: 15px;
		line-height: 1.25;
		letter-spacing: 0.03em;
		text-transform: uppercase;
		transition: background-color 0.25s ease;
	}

	a.bb-stijl-tile:hover,
	a.bb-stijl-tile:focus-visible {
		background-color: rgba(36, 71, 87, 0.12);
		background-color: color-mix(in srgb, var(--bb-stijl-color, var(--fs-color-primary, #b01e22)) 20%, transparent);
		color: var(--fs-color-secondary, #244757);
	}

	.bb-stijl-chips--icons .bb-attr-icon {
		flex: 0 0 auto;
		width: 22px;
		height: 22px;
		border: 0;
		border-radius: 0;
	}

	.bb-stijl-chips--icons .bb-attr-icon img,
	.bb-stijl-chips--icons .bb-attr-icon svg {
		border-radius: 0;
	}

	.bb-stijl-chips--icons .bb-attr-icon.has-bg img,
	.bb-stijl-chips--icons .bb-attr-icon.has-bg svg {
		width: 64%;
		height: 64%;
	}

	.bb-stijl-tile__label {
		position: static;
		width: auto;
		height: auto;
		overflow: visible;
		clip: auto;
	}
}

@media (prefers-reduced-motion: reduce) {
	.bb-attr-chip {
		transition: none;
	}
}
