/* Best Before theme · shared product-card hover/focus interactions (site-wide).
   Loaded everywhere the one card (template-parts/product/card.php) renders:
   category/shop/search grids, home rails, related products, quick-view
   suggestions, the Promotions [products] shortcode grid.

   .bb-card itself already gets a box-shadow + border-color hover transition
   from assets/css/main.css - this file only ADDS to that (lift, image zoom,
   title underline, button darken, Sale badge wiggle), never redefines it.

   Touch devices: :hover rules that would otherwise "stick" after a tap are
   gated behind @media (hover: hover). Keyboard focus gets the same state at
   every width via :focus-within, which is not hover-gated. */

.bb-card {
	position: relative; /* containing block for the wishlist heart below */
}
.bb-card__img {
	overflow: hidden; /* keeps the hover zoom inside the image's own box */
}

/* ---------- Gary: "Save to wishlist" heart on every card ----------
   Same [woosw] button/states/toast as the product page and quick view
   (assets/css/wishlist.css, assets/js/wishlist.js - not edited here, this only
   positions/sizes it for the card). One DOM position (next to the add-to-
   basket button, template-parts/product/card.php); CSS alone floats it into
   the image's top-right corner for grid/compact cards and leaves it inline
   for the list-row card. */
.bb-card:not(.bb-card--row) .bb-card__wish {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 2;
}
.bb-card__wish .woosw-btn {
	width: 40px !important;
	height: 40px !important;
	min-width: 40px !important;
}
/* Reserve room on the right of the sale/saving + best-before badges so the
   heart never overlaps them when a product happens to carry both. */
.bb-card:has(.bb-card__wish) .bb-card__badges {
	right: 56px;
}
.bb-card--row .bb-card__action {
	display: flex;
	align-items: center;
	gap: 8px;
}
.bb-card--row .bb-card__action .bb-btn {
	flex: 1;
}
.bb-card--row .bb-card__wish {
	flex: none;
}
.bb-card__img img {
	transition: transform .25s var(--bb-ease), opacity .25s var(--bb-ease);
}
.bb-card__name a {
	transition: text-decoration-color .15s var(--bb-ease);
}
.bb-card__action .bb-btn--primary {
	transition: background-color .2s var(--bb-ease), color .2s var(--bb-ease), transform .15s var(--bb-ease);
}
.bb-badge--sale {
	transition: background-color .25s var(--bb-ease), color .25s var(--bb-ease);
	transform-origin: center;
}

@media (hover: hover) {
	.bb-card:hover {
		transform: translateY(-2px);
	}
	.bb-card:hover .bb-card__img img {
		transform: scale(1.04);
		opacity: .85;
	}
	.bb-card:hover .bb-card__name a {
		text-decoration: underline;
		text-decoration-thickness: 2px;
	}
	.bb-card:hover .bb-card__action .bb-btn--primary {
		background: var(--bb-ink);
		color: var(--bb-yellow);
	}
	.bb-card:hover .bb-badge--sale {
		background: var(--bb-yellow);
		color: var(--bb-ink);
		animation: bb-card-badge-wiggle .4s var(--bb-ease);
	}
}

/* Keyboard focus (any device, any hover capability) gets the same state. */
.bb-card:focus-within {
	transform: translateY(-2px);
}
.bb-card:focus-within .bb-card__img img {
	transform: scale(1.04);
	opacity: .85;
}
.bb-card:focus-within .bb-card__name a {
	text-decoration: underline;
	text-decoration-thickness: 2px;
}
.bb-card:focus-within .bb-card__action .bb-btn--primary {
	background: var(--bb-ink);
	color: var(--bb-yellow);
}
.bb-card:focus-within .bb-badge--sale {
	background: var(--bb-yellow);
	color: var(--bb-ink);
}

/* ================= Reusable accessible CSS tooltip ================= */
/* Gary: `data-bbt-tip="Label text"` on any icon-only (or icon+text) control -
   grid/list view buttons, the wishlist heart wrapper, the sort button, the
   mobile Filters button. Shown on hover (desktop only - @media (hover: hover),
   never "stuck" on touch) and on keyboard focus (:focus-within covers the
   wishlist wrapper, which isn't itself focusable; :focus-visible covers plain
   buttons). This is a decoration only - every element still carries its own
   real aria-label/accessible name, never relies on the tooltip for that. */
[data-bbt-tip] {
	position: relative;
}
[data-bbt-tip]::after {
	content: attr(data-bbt-tip);
	position: absolute;
	bottom: calc(100% + 9px);
	left: 50%;
	z-index: 40;
	transform: translateX(-50%) translateY(4px);
	padding: 5px 10px;
	border-radius: var(--bb-r-small);
	background: var(--bb-ink);
	color: #fff;
	font-size: .75rem;
	font-weight: 600;
	line-height: 1.3;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transition: opacity .12s var(--bb-ease), transform .12s var(--bb-ease), visibility .12s;
}
@media (hover: hover) {
	[data-bbt-tip]:hover::after,
	[data-bbt-tip]:focus-visible::after,
	[data-bbt-tip]:focus-within::after {
		opacity: 1;
		visibility: visible;
		transform: translateX(-50%) translateY(0);
		transition-delay: .3s;
	}
}
/* Keyboard users on any device still get it (not hover-gated). */
[data-bbt-tip]:focus-visible::after,
[data-bbt-tip]:focus-within::after {
	opacity: 1;
	visibility: visible;
	transform: translateX(-50%) translateY(0);
	transition-delay: .3s;
}
@media (prefers-reduced-motion: reduce) {
	[data-bbt-tip]::after { transition: none; }
}

@keyframes bb-card-badge-wiggle {
	0% { transform: scale(1) rotate(0); }
	35% { transform: scale(1.08) rotate(-4deg); }
	65% { transform: scale(1.05) rotate(3deg); }
	100% { transform: scale(1.04) rotate(0); }
}

@media (prefers-reduced-motion: reduce) {
	.bb-card,
	.bb-card__img img,
	.bb-card__action .bb-btn--primary,
	.bb-badge--sale {
		transition: none;
	}
	.bb-card:hover,
	.bb-card:focus-within {
		transform: none;
	}
	.bb-card:hover .bb-card__img img,
	.bb-card:focus-within .bb-card__img img {
		transform: none;
		opacity: .85;
	}
	.bb-card:hover .bb-badge--sale,
	.bb-card:focus-within .bb-badge--sale {
		animation: none;
		transform: none;
	}
}
