/* ============================================================
   SMART PRODUCT COMPARISON
   Compare button (cards + single), floating counter bar,
   comparison modal with side-by-side table, and a toast.
   Uses the theme's design tokens from main.css (--bms-*).
   ============================================================ */

/* The [hidden] attribute is only `display:none` in the UA stylesheet, so
   any class rule that sets `display` (e.g. the modal below) would override
   it and leave an invisible full-screen overlay swallowing every click.
   Force these components truly hidden until JS un-hides them. */
.bm-compare-modal[hidden],
.bm-compare-bar[hidden],
.bm-compare-toast[hidden] {
	display: none !important;
}

/* ---------- Compare button ---------- */
.bm-compare-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	border: 1px solid var(--bms-border);
	background: #fff;
	color: var(--bms-text-muted);
	font-family: var(--bms-font-body);
	font-size: 13px;
	font-weight: 600;
	line-height: 1;
	padding: 8px 12px;
	border-radius: var(--bms-radius-md);
	cursor: pointer;
	transition: color .15s ease, border-color .15s ease, background .15s ease;
	-webkit-appearance: none;
	appearance: none;
}
.bm-compare-btn:hover {
	color: var(--bms-red);
	border-color: var(--bms-red);
}
.bm-compare-btn .bm-compare-icon {
	width: 16px;
	height: 16px;
	flex: none;
}
/* The "on" (check) icon is hidden until the product is selected */
.bm-compare-btn .bm-compare-icon--on { display: none; }
.bm-compare-btn.is-active {
	color: var(--bms-red);
	border-color: var(--bms-red);
	background: var(--bms-red-light);
}
.bm-compare-btn.is-active .bm-compare-icon:not(.bm-compare-icon--on) { display: none; }
.bm-compare-btn.is-active .bm-compare-icon--on { display: block; }

/* Compare button as an overlay on the product card image.
   Sits over the top-right of the card (a sibling of the card link,
   so it is never nested inside the card's <a>). */
.bm-product-card,
.bx-pcard { position: relative; }
.bm-compare-btn--card {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 3;
	padding: 7px 10px;
	font-size: 12px;
	background: rgba(255, 255, 255, .92);
	backdrop-filter: blur(4px);
	box-shadow: var(--bms-shadow-sm);
	opacity: 0;
	transform: translateY(-4px);
	transition: opacity .15s ease, transform .15s ease, color .15s ease, border-color .15s ease;
}
/* Reveal on card hover; keep visible once selected or on touch devices */
.bm-product-card:hover .bm-compare-btn--card,
.bx-pcard:hover .bm-compare-btn--card,
.bm-compare-btn--card.is-active,
.bm-compare-btn--card:focus-visible {
	opacity: 1;
	transform: none;
}
.bm-compare-btn--card .bm-compare-btn-label { display: none; }
@media (hover: none) {
	.bm-compare-btn--card { opacity: 1; transform: none; }
}

/* The homepage product grid renders inside `.bx-scope`, whose
   `.bx-scope button` reset (main.css) strips border + background from
   every button — which flattened the compare pill to a bare icon there.
   Re-assert the pill with higher specificity, scoped to .bx-scope so the
   shop/category cards are unaffected. Matches the .bm-compare-btn styles. */
.bx-scope .bm-compare-btn {
	border: 1px solid var(--bms-border);
	background: #fff;
	border-radius: var(--bms-radius-md);
}
.bx-scope .bm-compare-btn--card { background: rgba(255, 255, 255, .92); }
.bx-scope .bm-compare-btn:hover { border-color: var(--bms-red); }
.bx-scope .bm-compare-btn.is-active {
	border-color: var(--bms-red);
	background: var(--bms-red-light);
}

/* Single product page button */
.bm-compare-single { margin-top: 14px; }
.bm-compare-btn--single { padding: 10px 16px; font-size: 14px; }

/* ---------- Floating counter bar ---------- */
.bm-compare-bar {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 9000;
	background: var(--bms-text);
	color: #fff;
	box-shadow: 0 -6px 24px rgba(0, 0, 0, .18);
	transform: translateY(100%);
	transition: transform .25s ease;
}
.bm-compare-bar.is-visible { transform: none; }
.bm-compare-bar-inner {
	max-width: 1240px;
	margin: 0 auto;
	padding: 12px 24px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
}
.bm-compare-bar-count { font-size: 14px; }
.bm-compare-bar-count .bm-compare-count {
	display: inline-grid;
	place-items: center;
	min-width: 24px;
	height: 24px;
	padding: 0 6px;
	margin-right: 6px;
	border-radius: 12px;
	background: var(--bms-red);
	color: #fff;
	font-size: 13px;
	font-weight: 700;
}
.bm-compare-bar-actions { display: flex; align-items: center; gap: 10px; }
.bm-compare-open {
	border: 0;
	background: var(--bms-red);
	color: #fff;
	font-family: var(--bms-font-body);
	font-weight: 700;
	font-size: 14px;
	padding: 10px 20px;
	border-radius: var(--bms-radius-md);
	cursor: pointer;
	transition: background .15s ease, transform .15s ease;
}
.bm-compare-open:hover { background: var(--bms-red-dark); transform: translateY(-1px); }
.bm-compare-clear {
	border: 0;
	background: transparent;
	color: rgba(255, 255, 255, .75);
	font-family: var(--bms-font-body);
	font-size: 13px;
	font-weight: 600;
	padding: 8px 10px;
	cursor: pointer;
	border-radius: var(--bms-radius-sm);
	transition: color .15s ease, background .15s ease;
}
.bm-compare-clear:hover { color: #fff; background: rgba(255, 255, 255, .1); }

/* ---------- Header badge (counter in the header actions) ---------- */
.bx-hicon .bm-compare-count {
	position: absolute;
	top: -6px;
	right: 2px;
	min-width: 17px;
	height: 17px;
	padding: 0 4px;
	border-radius: 9px;
	background: var(--bms-red, #c8102e);
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	display: grid;
	place-items: center;
	line-height: 1;
}
/* The badge carries the [hidden] attribute when the compare list is
   empty, but the display:grid above would otherwise override the UA
   [hidden] { display:none }, leaving a stray "0" showing. Force it. */
.bx-hicon .bm-compare-count[hidden] { display: none !important; }

/* ---------- Modal ---------- */
.bm-compare-modal {
	position: fixed;
	inset: 0;
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
}
.bm-compare-modal-overlay {
	position: absolute;
	inset: 0;
	background: rgba(15, 18, 22, .55);
	backdrop-filter: blur(2px);
	opacity: 0;
	transition: opacity .2s ease;
}
.bm-compare-modal.is-open .bm-compare-modal-overlay { opacity: 1; }
.bm-compare-modal-panel {
	position: relative;
	width: 100%;
	max-width: 1100px;
	max-height: 90vh;
	background: #fff;
	border-radius: var(--bms-radius-xl);
	box-shadow: var(--bms-shadow-lg);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform: translateY(16px) scale(.98);
	opacity: 0;
	transition: transform .2s ease, opacity .2s ease;
}
.bm-compare-modal.is-open .bm-compare-modal-panel {
	transform: none;
	opacity: 1;
}
.bm-compare-modal-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 18px 24px;
	border-bottom: 1px solid var(--bms-border);
	flex: none;
}
.bm-compare-modal-head h2 {
	margin: 0;
	font-size: 20px;
	font-weight: 800;
}
.bm-compare-modal-head-actions { display: flex; align-items: center; gap: 8px; }
.bm-compare-modal-head .bm-compare-clear {
	color: var(--bms-text-muted);
	border: 1px solid var(--bms-border);
}
.bm-compare-modal-head .bm-compare-clear:hover {
	color: var(--bms-red);
	border-color: var(--bms-red);
	background: #fff;
}
.bm-compare-modal-close {
	border: 0;
	background: var(--bms-bg-alt);
	color: var(--bms-text);
	width: 36px;
	height: 36px;
	border-radius: 50%;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	transition: background .15s ease, color .15s ease;
}
.bm-compare-modal-close:hover { background: var(--bms-red); color: #fff; }
.bm-compare-modal-body {
	overflow: auto;
	padding: 8px 24px 24px;
	-webkit-overflow-scrolling: touch;
}

/* Empty / loading states */
.bm-compare-state {
	text-align: center;
	color: var(--bms-text-muted);
	padding: 48px 16px;
	font-size: 15px;
}

/* ---------- Comparison table ---------- */
.bm-compare-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	table-layout: fixed;
}
.bm-compare-table th,
.bm-compare-table td {
	border-bottom: 1px solid var(--bms-border);
	padding: 12px 14px;
	text-align: left;
	vertical-align: middle;
	font-size: 14px;
}
/* Sticky first column of attribute labels */
.bm-compare-rowhead {
	position: sticky;
	left: 0;
	z-index: 2;
	background: var(--bms-bg-alt);
	font-weight: 700;
	color: var(--bms-text);
	width: 150px;
	min-width: 130px;
}
.bm-compare-corner { background: #fff; border-bottom: 0; }

/* Product column heads */
.bm-compare-col-head {
	position: relative;
	text-align: center;
	vertical-align: top;
	background: #fff;
	min-width: 180px;
}
.bm-compare-thumb {
	display: block;
	width: 120px;
	height: 120px;
	margin: 6px auto 10px;
	border-radius: var(--bms-radius-md);
	overflow: hidden;
	background: var(--bms-bg-alt);
}
.bm-compare-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}
.bm-compare-name {
	display: block;
	font-size: 14px;
	font-weight: 700;
	line-height: 1.35;
	color: var(--bms-text);
	text-decoration: none;
}
.bm-compare-name:hover { color: var(--bms-red); }
.bm-compare-remove {
	position: absolute;
	top: 0;
	right: 6px;
	width: 26px;
	height: 26px;
	border: 0;
	border-radius: 50%;
	background: var(--bms-bg-alt);
	color: var(--bms-text-muted);
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	transition: background .15s ease, color .15s ease;
}
.bm-compare-remove:hover { background: var(--bms-red); color: #fff; }

/* Cells */
.bm-compare-cell { text-align: center; color: var(--bms-text); }
.bm-compare-row--price .bm-compare-cell { font-weight: 700; font-size: 15px; }
.bm-compare-row:nth-child(even) td,
.bm-compare-row:nth-child(even) .bm-compare-rowhead { background: rgba(0, 0, 0, .015); }
.bm-compare-muted { color: var(--bms-text-light); }
.bm-compare-features { font-size: 13px; color: var(--bms-text-muted); line-height: 1.45; }
.bm-compare-rating-num { font-size: 13px; color: var(--bms-text-muted); }
.bm-compare-stars { color: #f5a623; letter-spacing: 1px; }

.bm-compare-stock {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	font-weight: 600;
}
.bm-compare-dot { width: 8px; height: 8px; border-radius: 50%; }
.bm-compare-stock.is-in { color: var(--bms-success); }
.bm-compare-stock.is-in .bm-compare-dot { background: var(--bms-success); }
.bm-compare-stock.is-out { color: var(--bms-error); }
.bm-compare-stock.is-out .bm-compare-dot { background: var(--bms-error); }

/* Buy row buttons — force brand styling. "Add to basket" otherwise
   inherits the global dark WooCommerce button, and "View basket"
   (.added_to_cart) renders as the default blue link-button. */
.bm-compare-cell--action .button,
.bm-compare-cell--action .added_to_cart {
	display: block;
	width: 100%;
	margin: 6px 0 0;
	padding: 10px 12px !important;
	border-radius: var(--bms-radius-md) !important;
	font-size: 13px !important;
	font-weight: 700 !important;
	line-height: 1.2 !important;
	text-align: center;
	text-decoration: none !important;
	border: 1px solid transparent !important;
	transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.bm-compare-cell--action .button:first-child { margin-top: 0; }
/* Primary — Add to basket */
.bm-compare-cell--action .button {
	background: var(--bms-red) !important;
	color: #fff !important;
	border-color: var(--bms-red) !important;
}
.bm-compare-cell--action .button:hover {
	background: var(--bms-red-dark) !important;
	border-color: var(--bms-red-dark) !important;
	color: #fff !important;
}
/* Secondary — View basket (appears after adding) */
.bm-compare-cell--action .added_to_cart {
	background: #fff !important;
	color: var(--bms-text) !important;
	border-color: var(--bms-border) !important;
}
.bm-compare-cell--action .added_to_cart:hover {
	background: var(--bms-red-light) !important;
	color: var(--bms-red) !important;
	border-color: var(--bms-red) !important;
}

/* ---------- Toast ---------- */
.bm-compare-toast {
	position: fixed;
	left: 50%;
	bottom: 88px;
	transform: translateX(-50%) translateY(12px);
	z-index: 10001;
	background: var(--bms-text);
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	padding: 12px 20px;
	border-radius: var(--bms-radius-md);
	box-shadow: var(--bms-shadow-lg);
	opacity: 0;
	pointer-events: none;
	transition: opacity .2s ease, transform .2s ease;
	max-width: calc(100vw - 32px);
	text-align: center;
}
.bm-compare-toast.is-visible {
	opacity: 1;
	transform: translateX(-50%);
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
	.bm-compare-modal { padding: 0; }
	.bm-compare-modal-panel {
		max-width: none;
		max-height: 100vh;
		height: 100vh;
		border-radius: 0;
	}
	/* Let product columns scroll horizontally on small screens while
	   the attribute-label column stays pinned. */
	.bm-compare-rowhead { width: 116px; min-width: 116px; }
	.bm-compare-col-head { min-width: 150px; }
	.bm-compare-thumb { width: 90px; height: 90px; }
	.bm-compare-table th,
	.bm-compare-table td { padding: 10px; font-size: 13px; }
}
@media (max-width: 600px) {
	.bm-compare-bar-inner { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
	.bm-compare-bar-count { flex: 1 1 100%; }
	.bm-compare-bar-actions { flex: 1 1 100%; justify-content: space-between; }
	.bm-compare-open { flex: 1; }
}
