/**
 * Category tiles — [bb_category_tiles], see includes/category-tiles.php.
 *
 * Photo tiles for product categories, built for the mega menu: the category
 * image filling the tile, its name over a dark fade at the bottom, and a small
 * arrow badge on the right.
 *
 * Desktop (>=850) runs on a six-column grid so both row widths fit one track
 * set: the first two tiles span three columns (two wide tiles on top), every
 * later tile spans two (rows of three). A short last row stretches instead of
 * leaving a hole:
 *
 *   5 tiles   [  1  ][  2  ]      4 tiles   [  1  ][  2  ]
 *             [ 3 ][ 4 ][ 5 ]               [  3  ][  4  ]
 *
 *   3 tiles   [  1  ][  2  ]      6 tiles   [  1  ][  2  ]
 *             [     3      ]                [ 3 ][ 4 ][ 5 ]
 *                                           [     6      ]
 *
 * Tablet gets two columns and phones one — a mega menu never shows there
 * (Flatsome's mobile drawer does not render menu-item blocks), but the
 * shortcode can sit in any UX Block.
 *
 * Tune per placement with custom properties on the wrapper:
 *
 *   .my-menu .bb-cat-tiles { --bb-cat-tiles-h: 180px; --bb-cat-tiles-gap: 16px }
 *
 * Anchor colours are set on the inner spans: inside a dropdown the link would
 * otherwise pick up --fs-experimental-link-color, or near-white from Flatsome's
 * `.dark` dropdown variant.
 */

.bb-cat-tiles {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	grid-auto-rows: var(--bb-cat-tiles-h, 180px);
	gap: var(--bb-cat-tiles-gap, 12px);
}

/* --------------------------------------------------------------------------
 * Tile
 * ----------------------------------------------------------------------- */

/*
 * Petrol underneath the image: what a category without a thumbnail shows, and
 * what fills the tile for the moment the lazy image takes to arrive on the
 * first hover.
 */
.bb-cat-tile {
	position: relative;
	display: block;
	overflow: hidden;
	border-radius: var(--bb-cat-tiles-radius, 8px);
	background-color: var(--fs-color-secondary, #244757);
	text-decoration: none;
}

/* Full-tile image; `height: auto` from flatsome.css would leave a gap. */
.bb-cat-tile__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	object-fit: cover;
	transition: transform 0.35s ease;
}

/* The fade the name sits on — petrol, so it reads as brand rather than black. */
.bb-cat-tile::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(to top, rgba(36, 71, 87, 0.85) 0%, rgba(36, 71, 87, 0.35) 35%, rgba(36, 71, 87, 0) 65%);
	pointer-events: none;
}

.bb-cat-tile__body {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 1;
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 10px;
	padding: 10px;
}

/*
 * One long Dutch compound ("Vriendenweekenden") can be wider than a bottom
 * tile: hyphenate it on the page's `lang="nl-NL"`, and break it outright where
 * the browser has no Dutch dictionary — rather than run under the arrow.
 */
.bb-cat-tile__title {
	min-width: 0;
	overflow-wrap: break-word;
	-webkit-hyphens: auto;
	hyphens: auto;
	color: #fff;
	font-family: "Creato Display", sans-serif;
	font-size: 14px;
	font-weight: 800;
	line-height: 1.2;
	text-shadow: 0 1px 2px rgba(36, 71, 87, 0.5);
}

.bb-cat-tile__arrow {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	border-radius: 4px;
	background-color: #f4d5cd;
	color: var(--fs-color-secondary, #244757);
	transition: background-color 0.25s ease, color 0.25s ease;
}

.bb-cat-tile__arrow svg {
	display: block;
	width: 12px;
	height: 12px;
}

/* Same lift as the product cards and the style images; the badge goes brand red. */
.bb-cat-tile:hover .bb-cat-tile__img,
.bb-cat-tile:focus-visible .bb-cat-tile__img {
	transform: scale(1.04);
}

.bb-cat-tile:hover .bb-cat-tile__arrow,
.bb-cat-tile:focus-visible .bb-cat-tile__arrow {
	background-color: var(--fs-color-primary, #b01e22);
	color: #fff;
}

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

/* --------------------------------------------------------------------------
 * Responsive — Flatsome's tier edges
 * ----------------------------------------------------------------------- */

@media (min-width: 550px) and (max-width: 849px) {
	.bb-cat-tiles {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	/* An odd one out at the end takes the full row. */
	.bb-cat-tile:last-child:nth-child(odd) {
		grid-column: 1 / -1;
	}
}

@media (min-width: 850px) {
	.bb-cat-tiles {
		grid-template-columns: repeat(6, minmax(0, 1fr));
		gap: var(--bb-cat-tiles-gap, 20px);
	}

	.bb-cat-tile {
		grid-column: span 2;
	}

	.bb-cat-tile:nth-child(-n + 2) {
		grid-column: span 3;
	}

	/*
	 * Rows of three start at tile 3, 6, 9…  A last row of one (the last tile
	 * is one of those) runs full width; a last row of two (the last tile is
	 * 4, 7, 10…) is two halves. A single tile is full width too.
	 */
	.bb-cat-tile:nth-child(3n):last-child,
	.bb-cat-tile:only-child {
		grid-column: 1 / -1;
	}

	.bb-cat-tile:nth-child(3n + 3):nth-last-child(2),
	.bb-cat-tile:nth-child(3n + 4):last-child {
		grid-column: span 3;
	}
}

@media (prefers-reduced-motion: reduce) {
	.bb-cat-tile__img,
	.bb-cat-tile__arrow {
		transition: none;
	}
}
