/**
 * Catalogue: toolbar, product grid and the card tile.
 *
 * Tiles are portrait because cards are. A 3:4 media box keeps a row of mixed
 * listings aligned whatever the seller uploaded.
 */

.tcgsf-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var( --tcgsf-gap-sm );
	padding: 12px 0;
	margin-bottom: var( --tcgsf-gap-sm );
	border-bottom: 1px solid var( --tcgsf-border );
}

.tcgsf-toolbar__count {
	margin: 0;
	margin-right: auto;
	font-size: 14px;
	color: var( --tcgsf-muted );
}

.tcgsf-toolbar__filters {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 9px 16px;
	border: 1px solid var( --tcgsf-border );
	border-radius: var( --tcgsf-radius-sm );
	background: var( --tcgsf-surface );
	color: var( --tcgsf-ink );
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}

@media ( min-width: 1025px ) {
	.tcgsf-toolbar__filters { display: none; }
}

.tcgsf-toolbar__view {
	display: none;
	gap: 4px;
}

@media ( min-width: 700px ) {
	.tcgsf-toolbar__view { display: flex; }
}

.tcgsf-toolbar__view-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 1px solid var( --tcgsf-border );
	border-radius: var( --tcgsf-radius-sm );
	background: var( --tcgsf-surface );
	color: var( --tcgsf-muted );
	cursor: pointer;
}

.tcgsf-toolbar__view-btn.is-active {
	border-color: var( --tcgsf-primary );
	background: var( --tcgsf-primary-soft );
	color: var( --tcgsf-primary );
}

.tcgsf-toolbar__sort select {
	width: auto;
	min-width: 190px;
	padding-block: 9px;
}

/* --------------------------------------------------------------------------
 * Grid
 * ----------------------------------------------------------------------- */

.woocommerce ul.products.tcgsf-grid,
ul.products.tcgsf-grid {
	display: grid;
	grid-template-columns: repeat( var( --tcgsf-shop-columns, 4 ), minmax( 0, 1fr ) );
	gap: var( --tcgsf-gap-sm );
	margin: 0;
	padding: 0;
	list-style: none;
}

/* WooCommerce's clearfix pseudo-elements become phantom grid cells. */
.woocommerce ul.products.tcgsf-grid::before,
.woocommerce ul.products.tcgsf-grid::after,
ul.products.tcgsf-grid::before,
ul.products.tcgsf-grid::after {
	content: none;
	display: none;
}

@media ( max-width: 1200px ) {
	ul.products.tcgsf-grid { grid-template-columns: repeat( min( var( --tcgsf-shop-columns, 4 ), 3 ), minmax( 0, 1fr ) ); }
}

@media ( max-width: 860px ) {
	ul.products.tcgsf-grid { grid-template-columns: repeat( 2, minmax( 0, 1fr ) ); }
}

@media ( max-width: 420px ) {
	ul.products.tcgsf-grid { grid-template-columns: minmax( 0, 1fr ); }
}

.woocommerce ul.products.tcgsf-grid li.product,
ul.products.tcgsf-grid li.product {
	width: auto;
	margin: 0;
	padding: 0;
	float: none;
	clear: none;
}

/* --------------------------------------------------------------------------
 * Card tile
 * ----------------------------------------------------------------------- */

.tcgsf-card {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	border: 1px solid var( --tcgsf-border );
	border-radius: var( --tcgsf-radius );
	background: var( --tcgsf-surface );
	overflow: hidden;
	transition: transform 0.2s var( --tcgsf-ease ), box-shadow 0.2s var( --tcgsf-ease ), border-color 0.2s var( --tcgsf-ease );
}

.tcgsf-card:hover {
	transform: translateY( -3px );
	border-color: var( --tcgsf-primary );
	box-shadow: var( --tcgsf-shadow-lg );
}

.tcgsf-card__media {
	position: relative;
	overflow: hidden;
	background: var( --tcgsf-surface-alt );
}

.tcgsf-card__image-link { display: block; position: relative; }

.tcgsf-card__media img {
	display: block;
	width: 100%;
	aspect-ratio: 3 / 4;
	object-fit: cover;
	transition: opacity 0.3s var( --tcgsf-ease ), transform 0.4s var( --tcgsf-ease );
}

/* Second gallery image as a hover state — buyers want to see the card back. */
.tcgsf-card__image-alt {
	position: absolute;
	inset: 0;
	opacity: 0;
}

.tcgsf-card:hover .tcgsf-card__image-alt { opacity: 1; }
.tcgsf-card:hover .tcgsf-card__media img:first-child { transform: scale( 1.03 ); }

.tcgsf-card__badges {
	position: absolute;
	top: 10px;
	left: 10px;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 6px;
	align-items: flex-start;
}

.tcgsf-card__hover {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 6px;
	opacity: 0;
	transform: translateX( 8px );
	transition: opacity 0.2s var( --tcgsf-ease ), transform 0.2s var( --tcgsf-ease );
}

.tcgsf-card:hover .tcgsf-card__hover,
.tcgsf-card:focus-within .tcgsf-card__hover {
	opacity: 1;
	transform: translateX( 0 );
}

/* Touch devices have no hover, so the actions stay visible. */
@media ( hover: none ) {
	.tcgsf-card__hover { opacity: 1; transform: none; }
}

.tcgsf-card__action {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 1px solid var( --tcgsf-border );
	border-radius: 50%;
	background: var( --tcgsf-surface );
	color: var( --tcgsf-ink-soft );
	cursor: pointer;
	transition: background-color 0.16s var( --tcgsf-ease ), color 0.16s var( --tcgsf-ease );
}

.tcgsf-card__action:hover,
.tcgsf-card__action.is-active {
	background: var( --tcgsf-primary );
	border-color: var( --tcgsf-primary );
	color: #fff;
}

.tcgsf-card__action .tcgsf-icon { width: 17px; height: 17px; }

.tcgsf-card__title {
	margin: 0;
	padding: var( --tcgsf-gap-sm ) var( --tcgsf-gap-sm ) 0;
	font-family: var( --tcgsf-font );
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
}

.tcgsf-card__title a { color: var( --tcgsf-ink ); }

/* Two lines, then ellipsis — keeps every tile in a row the same height. */
.tcgsf-card__title a {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.tcgsf-card__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 6px var( --tcgsf-gap-sm ) 0;
	font-size: 12px;
	color: var( --tcgsf-muted );
}

.tcgsf-card__vendor { color: var( --tcgsf-muted ); }
.tcgsf-card__vendor:hover { color: var( --tcgsf-primary ); }

.tcgsf-card__price {
	padding: 8px var( --tcgsf-gap-sm ) 0;
	font-size: 17px;
	font-weight: 700;
	color: var( --tcgsf-ink );
}

.tcgsf-card__price del { margin-right: 6px; font-size: 14px; font-weight: 400; color: var( --tcgsf-muted ); }
.tcgsf-card__price ins { text-decoration: none; color: var( --tcgsf-danger ); }

.tcgsf-card__actions {
	margin-top: auto;
	padding: var( --tcgsf-gap-sm );
}

.woocommerce .tcgsf-card__actions a.button,
.tcgsf-card__actions a.button {
	display: flex;
	width: 100%;
	justify-content: center;
	padding: 10px 14px;
	border: 1px solid var( --tcgsf-primary );
	border-radius: var( --tcgsf-radius-sm );
	background: var( --tcgsf-primary );
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	text-align: center;
}

.woocommerce .tcgsf-card__actions a.button:hover,
.tcgsf-card__actions a.button:hover {
	background: var( --tcgsf-primary-dark );
	border-color: var( --tcgsf-primary-dark );
	color: #fff;
	text-decoration: none;
}

.woocommerce .tcgsf-card__actions a.button.added::after {
	content: '';
}

/* --------------------------------------------------------------------------
 * List view
 * ----------------------------------------------------------------------- */

.tcgsf-view-list ul.products.tcgsf-grid {
	grid-template-columns: minmax( 0, 1fr );
}

.tcgsf-view-list .tcgsf-card {
	flex-direction: row;
	align-items: stretch;
}

.tcgsf-view-list .tcgsf-card__media { flex: 0 0 170px; }
.tcgsf-view-list .tcgsf-card__media img { height: 100%; aspect-ratio: auto; }

.tcgsf-view-list .tcgsf-card__title { font-size: 17px; }
.tcgsf-view-list .tcgsf-card__title a { -webkit-line-clamp: 3; }
.tcgsf-view-list .tcgsf-card__actions { max-width: 260px; }

/* --------------------------------------------------------------------------
 * Loading state during AJAX filtering
 * ----------------------------------------------------------------------- */

.tcgsf-products-wrap { position: relative; }

.tcgsf-products-wrap.is-loading { min-height: 240px; }

.tcgsf-products-wrap.is-loading ul.products {
	opacity: 0.35;
	pointer-events: none;
	transition: opacity 0.2s var( --tcgsf-ease );
}

.tcgsf-products-wrap.is-loading::after {
	content: '';
	position: absolute;
	top: 80px;
	left: 50%;
	width: 34px;
	height: 34px;
	margin-left: -17px;
	border: 3px solid var( --tcgsf-border );
	border-top-color: var( --tcgsf-primary );
	border-radius: 50%;
	animation: tcgsf-spin 0.7s linear infinite;
}

@keyframes tcgsf-spin {
	to { transform: rotate( 360deg ); }
}

/* --------------------------------------------------------------------------
 * Compare dock
 * ----------------------------------------------------------------------- */

.tcgsf-compare-bar {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 150;
	background: var( --tcgsf-surface );
	border-top: 1px solid var( --tcgsf-border );
	box-shadow: 0 -4px 24px rgba( 19, 26, 58, 0.12 );
}

.tcgsf-compare-bar[hidden] { display: none; }

.tcgsf-compare-bar__inner {
	display: flex;
	align-items: center;
	gap: var( --tcgsf-gap-sm );
	padding: 12px 20px;
}

.tcgsf-compare-bar__items {
	display: flex;
	flex: 1 1 auto;
	gap: 8px;
	overflow-x: auto;
}

.tcgsf-compare-bar__item { position: relative; flex: 0 0 auto; }

.tcgsf-compare-bar__item img {
	width: 48px;
	height: 64px;
	border-radius: var( --tcgsf-radius-sm );
	object-fit: cover;
}

.tcgsf-compare-bar__remove {
	position: absolute;
	top: -6px;
	right: -6px;
	width: 20px;
	height: 20px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --tcgsf-danger );
	color: #fff;
	font-size: 13px;
	line-height: 20px;
	cursor: pointer;
}

/* ---- Price filter widget ----------------------------------------------
   WooCommerce renders a jQuery UI slider but ships its styles inside a
   stylesheet this theme does not load. */
.widget_price_filter .price_slider_wrapper { padding-top: 10px; }
.widget_price_filter .price_slider { position: relative; height: 6px; margin: 10px 8px 22px; border-radius: 999px; background: var(--tcgsf-border); }
.widget_price_filter .ui-slider-range { position: absolute; top: 0; height: 100%; border-radius: 999px; background: var(--tcgsf-primary); }
.widget_price_filter .ui-slider-handle { position: absolute; top: -6px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: var(--tcgsf-surface); border: 2px solid var(--tcgsf-primary); cursor: grab; outline: none; }
.widget_price_filter .ui-slider-handle:focus-visible { box-shadow: 0 0 0 3px var(--tcgsf-primary-soft); }
.widget_price_filter .price_slider_amount { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: .92em; }
.widget_price_filter .price_slider_amount .button { order: 2; }
.widget_price_filter .price_label { flex: 1 1 100%; color: var(--tcgsf-muted); }
/* Two cards across on a phone, not four. */
@media (max-width: 640px) { :root { --tcgsf-shop-columns: 2; } }
@media (max-width: 380px) { :root { --tcgsf-shop-columns: 1; } }
/* An empty category invites sellers rather than dead-ending. */
.tcgsf-empty-cat { margin: 18px 0; padding: 22px 24px; border-radius: var(--tcgsf-radius); background: var(--tcgsf-primary-soft); display: flex; flex-wrap: wrap; align-items: center; gap: 14px 22px; }
.tcgsf-empty-cat p { margin: 0; flex: 1 1 320px; }

/* ---- Mobile audit, round 2 (2026-10) ------------------------------------ */

/* The filters button shows how many are applied, since the drawer is shut. */
.tcgsf-toolbar__filters { min-height: 44px; }

.tcgsf-toolbar__filters-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	border-radius: 999px;
	background: var( --tcgsf-primary );
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 1;
}

:root[ data-tcgsf-theme='dark' ] .tcgsf-toolbar__filters-count { color: #0f1a1a; }
.tcgsf-toolbar__filters-count[hidden] { display: none; }

/* Price form inside the drawer should not wrap under its own label. */
.tcgsf-sidebar .tcgc-filters .tcgc-filter__price { flex-wrap: nowrap; }

/* The filter widget prints its own section headings, so the generic widget
   title is redundant when it is left blank; when set, keep it tight. */
.tcgsf-sidebar .widget_tcgc_filters .widget__title { margin-bottom: 4px; }
