/**
 * Teco 相关产品：类名对齐 Woo loops，便于沿用主题 / .woocommerce 样式。
 * 列数：优先用容器查询（随小工具实际宽度），避免 Elementor 画布视口较窄时仍要 4 列却落到 tablet 的 3 列导致提前换行。
 */
.elementor-widget-teco-related-products .teco-related-products {
	width: 100%;
	max-width: 100%;
}

.elementor-widget-teco-related-products .teco-related-products-grid {
	container-type: inline-size;
	container-name: teco-rel;
	width: 100%;
	max-width: 100%;
	min-width: 0;
}

.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list {
	list-style: none;
	margin: 0; /* 可由 Elementor「产品列表外边距」覆盖 */
	padding: 0;
	/* width:100% 会与左右 margin 叠加导致溢出/看似无效；auto 让 margin 参与占位，网格仍撑满剩余宽度 */
	width: auto;
	max-width: 100%;
	box-sizing: border-box;
	clear: both;
	display: grid !important;
	grid-auto-flow: row;
	align-items: stretch;
	justify-items: center;
	gap: var(--teco-rel-row, 2.5rem) var(--teco-rel-col, 1.5rem);
	grid-template-columns: repeat(var(--teco-rcols-m, 2), minmax(0, 1fr));
	grid-auto-rows: minmax(0, auto);
}

/*
 * WooCommerce 为 ul.products 生成 ::before / ::after（table 清除浮动）。
 * 在 display:grid 下二者也算网格子项，会多占一格 → 第一列空、产品整体右移。
 */
.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list::before,
.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list::after {
	content: none !important;
	display: none !important;
}

/*
 * 抵消 Woo / 主题对 ul.products li.product 的 width、float、flex。
 * 勿用 width:100%：在网格格里会占满整条轨道，左右 margin 无法留出可见空隙（与「卡片外边距」冲突）。
 * 卡片宽度封顶见 --teco-rel-card-max（Elementor「卡片宽度」）；整体缩放见 --teco-rel-card-scale（「卡片整体缩放」）。
 */
.elementor-widget-teco-related-products .teco-related-products-grid ul.products li.product.teco-related-product-card {
	width: auto !important;
	max-width: min(100%, var(--teco-rel-card-max, 100%)) !important;
	min-width: 0;
	float: none !important;
	clear: none !important;
	flex: none !important;
	flex-grow: 0 !important;
	flex-shrink: 1 !important;
	flex-basis: auto !important;
	grid-column: auto;
	justify-self: center;
	/* 不强制 margin，便于「卡片外边距」与主题/Woo 覆盖 */
}

.elementor-widget-teco-related-products .teco-related-products-grid li.teco-related-product-card {
	box-sizing: border-box;
	min-width: 0;
	min-height: 0;
	margin: 0;
	height: auto;
	overflow-x: hidden;
	overflow-y: visible;
	isolation: isolate;
	transform: scale(var(--teco-rel-card-scale, 1));
	transform-origin: top center;
	transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
	/* 等高网格行内：配图区 flex 拉长，标题+按钮整体贴在卡片内容区底部 */
	display: flex;
	flex-direction: column;
	min-height: 0;
}

/* 支持容器查询：列数按「小工具内容区宽度」算，避免编辑区视口偏窄却一排只给 3 列 */
@container teco-rel (min-width: 768px) {
	.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list {
		grid-template-columns: repeat(var(--teco-rcols-t, 3), minmax(0, 1fr));
	}
}

@container teco-rel (min-width: 1024px) {
	.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list {
		grid-template-columns: repeat(var(--teco-rcols-d, 4), minmax(0, 1fr));
	}
}

/* 旧浏览器：退回视口断点（桌面用 1024，避免 1025 与常见 1024px 画布差 1px） */
@supports not (container-type: inline-size) {
	@media (min-width: 768px) {
		.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list {
			grid-template-columns: repeat(var(--teco-rcols-t, 3), minmax(0, 1fr));
		}
	}

	@media (min-width: 1024px) {
		.elementor-widget-teco-related-products .teco-related-products-grid ul.products.teco-related-products__list {
			grid-template-columns: repeat(var(--teco-rcols-d, 4), minmax(0, 1fr));
		}
	}
}

.elementor-widget-teco-related-products .teco-related-products__title {
	margin: 0 0 1em;
}

/* 标题 + Woo 风格排序（右上角） */
.elementor-widget-teco-related-products .teco-related-products__toolbar {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.75rem 1.25rem;
	width: 100%;
	margin: 0 0 1em;
	box-sizing: border-box;
	position: relative;
}

.elementor-widget-teco-related-products .teco-related-products__toolbar-start:empty {
	display: none;
}

.elementor-widget-teco-related-products .teco-related-products__toolbar-start {
	width: 100%;
}

.elementor-widget-teco-related-products .teco-related-products__toolbar-end {
	margin-inline-start: auto;
	flex: 0 0 auto;
}

/* 开启排序时：标题保持整行居中，排序固定在右侧。 */
.elementor-widget-teco-related-products .teco-related-products--has-ordering .teco-related-products__toolbar-start {
	padding-inline-end: calc(12rem + 0.75rem);
}

.elementor-widget-teco-related-products .teco-related-products--has-ordering .teco-related-products__toolbar-end {
	position: absolute;
	inset-inline-end: 0;
	top: 50%;
	transform: translateY(-50%);
	margin-inline-start: 0;
}

/* 窄屏下回到流式布局，避免标题与排序控件重叠。 */
@media (max-width: 767px) {
	.elementor-widget-teco-related-products .teco-related-products--has-ordering .teco-related-products__toolbar {
		display: flex;
	}

	.elementor-widget-teco-related-products .teco-related-products--has-ordering .teco-related-products__toolbar-start {
		padding-inline-end: 0;
	}

	.elementor-widget-teco-related-products .teco-related-products--has-ordering .teco-related-products__toolbar-end {
		position: static;
		top: auto;
		inset-inline-end: auto;
		transform: none;
		margin-inline-start: auto;
	}
}

.elementor-widget-teco-related-products .teco-related-products__toolbar .teco-related-products__title,
.elementor-widget-teco-related-products .teco-related-products__toolbar .woocommerce-result-count {
	margin-bottom: 0;
}

/* 相关产品分页（与 .woocommerce-pagination 类名并存，便于接主题） */
.elementor-widget-teco-related-products .teco-related-products__pagination {
	margin: 1.25em 0 0;
	padding: 0;
	text-align: center;
	box-sizing: border-box;
	width: 100%;
}

.elementor-widget-teco-related-products .teco-related-products__pagination ul.page-numbers {
	margin: 0;
	padding: 0;
	list-style: none;
	display: inline-flex;
	flex-wrap: wrap;
	gap: 0.35rem 0.6rem;
	justify-content: center;
	align-items: center;
}

.elementor-widget-teco-related-products .teco-related-products__pagination .page-numbers {
	display: inline-block;
	padding: 0.35em 0.65em;
	text-decoration: none;
	border: 1px solid rgba(142, 100, 180, 0.35);
	border-radius: 4px;
	line-height: 1.25;
	box-sizing: border-box;
}

.elementor-widget-teco-related-products .teco-related-products__pagination .page-numbers.current {
	font-weight: 600;
	background: rgba(142, 100, 180, 0.12);
}

.elementor-widget-teco-related-products .teco-related-products.teco-related-products--ajax-loading {
	opacity: 0.55;
	pointer-events: none;
	transition: opacity 0.15s ease;
}

.elementor-widget-teco-related-products .teco-related-ordering__form {
	margin: 0;
}

.elementor-widget-teco-related-products .teco-related-ordering__select.orderby {
	max-width: 100%;
	min-width: 12rem;
	cursor: pointer;
	font: inherit;
	line-height: inherit;
}

/* 与商店「显示所有 n 结果」一致：沿用 woocommerce-result-count，并在无主题样式时补浅色框线 */
.elementor-widget-teco-related-products p.teco-related-products__title--result-count.woocommerce-result-count {
	display: block;
	padding: 0.5rem 0.75rem;
	border: 1px solid rgba(142, 100, 180, 0.35);
	border-radius: 2px;
	background: rgba(255, 255, 255, 0.92);
	font-size: inherit;
	line-height: 1.45;
}

/*
 * 图片链接区：flex:1 占满卡片剩余高度，使标题+按钮始终贴在底部。
 * --teco-rel-img-min-h：「图片区域最小高度」，有无缩略图均保证一定视觉空间；默认 120px。
 */
.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__link {
	flex: 1 1 0;
	min-height: var(--teco-rel-img-min-h, 120px);
	width: 100%;
	display: flex;
	align-items: flex-start;
	text-decoration: none;
	overflow: hidden;
	border-radius: inherit;
}

/*
 * 图片填满整个链接区（height:100% 在父级有明确高度时生效，即设了卡片高度时）。
 * object-fit:contain 保持完整产品图不裁切；无固定卡片高度时退回 height:auto 自然尺寸。
 */
.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__link img {
	display: block;
	width: 100%;
	height: auto;
	object-fit: contain;
	vertical-align: middle;
	border-radius: inherit !important;
}

/*
 * 标题：flex:0 0 auto，与按钮一起留在卡片底部（上方由配图链接区 flex 填满）。
 */
.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__title {
	flex: 0 0 auto;
	font-size: inherit;
	font-weight: 400;
	margin: 0.65em 0 0;
	padding: 0 0.25em;
	line-height: 1.35;
}

.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__title a {
	color: inherit;
	text-decoration: none;
}

.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__title a:hover {
	text-decoration: underline;
}

.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__buttons {
	flex-shrink: 0;
	margin-top: 0;
	padding-top: 0.65em;
	margin-bottom: 0.5rem;
	text-align: center;
}

/**
 * 默认「read more」样式对齐设计稿：橙底、深灰字、圆角按钮；可在 Elementor「按钮」样式里覆盖。
 */
.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__buttons .button {
	display: inline-block;
	box-sizing: border-box;
	text-decoration: none;
	transition: background-color 0.2s ease, color 0.2s ease;
	border: none;
	background-color: #f29c11;
	color: #333333;
	border-radius: 5px;
	padding: 0.5em 1.25em;
	font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	font-weight: 500;
	font-size: 0.9375rem;
	line-height: 1.25;
	-webkit-font-smoothing: antialiased;
}

.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__buttons .button:hover,
.elementor-widget-teco-related-products .teco-related-products-grid .woocommerce-loop-product__buttons .button:focus {
	background-color: #d98a0f;
	color: #1a1a1a;
	text-decoration: none;
}

/* -------------------------------------------------------------------------
 * 横向循环滚动（走马灯）：关闭 .marquee_mode 时仍为上方 Grid。
 * 结构为「单 ul、两组 li」：接缝处仍是 li+li，避免双 ul 并排时间距丢失。
 * ------------------------------------------------------------------------- */
/* 内边距为卡片 box-shadow（尤其 blur）留出空间，避免 overflow:hidden 裁掉顶部/两侧阴影 */
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-viewport {
	width: 100%;
	max-width: 100%;
	overflow: hidden;
	min-width: 0;
	padding: 28px 12px 32px;
	box-sizing: border-box;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track {
	display: flex;
	flex-direction: row;
	flex-wrap: nowrap;
	align-items: stretch;
	width: max-content;
	animation: teco-related-marquee-shift var(--teco-marquee-duration, 45s) linear infinite;
	will-change: transform;
}

.elementor-widget-teco-related-products .teco-related-products--marquee[data-teco-marquee-dir="right"] .teco-related-products__marquee-track {
	animation-direction: reverse;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-viewport:hover .teco-related-products__marquee-track {
	animation-play-state: paused;
}

/*@media (prefers-reduced-motion: reduce) {
	.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track {
		animation: none !important;
	}
}*/

@keyframes teco-related-marquee-shift {
	from {
		transform: translateX(0);
	}
	to {
		transform: translateX(-50%);
	}
}

/* 走马灯行内：Flex 横排 + stretch 等高；间距用 li+li 的 margin（比 gap 更扛主题/Woo 的奇怪 margin） */
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip {
	display: flex !important;
	flex-direction: row;
	flex-wrap: nowrap;
	grid-template-columns: none !important;
	align-items: stretch;
	width: max-content;
	max-width: none !important;
	margin: 0 !important;
	padding: 0 !important;
	gap: 0 !important;
	column-gap: 0 !important;
	row-gap: 0 !important;
	list-style: none;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip::before,
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip::after {
	content: none !important;
	display: none !important;
}

/*
 * 走马灯卡宽：与网格共用 --teco-rcols-m/t/d + --teco-rel-col（容器查询，与小工具内容区一致）
 */
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
	float: none !important;
	clear: none !important;
	margin: 0 !important;
	box-sizing: border-box !important;
	min-width: 0 !important;
	height: auto !important;
	flex: none !important;
	align-self: stretch;
	overflow-x: hidden !important;
	overflow-y: auto !important;
	isolation: auto;
	position: relative;
	z-index: 0;
	/* 与「卡片宽度」取 min，未设置时 --teco-rel-card-max 回退极大值，实际由列宽公式决定 */
	width: min(
		var(--teco-rel-card-max, 100000px),
		calc((100cqi - (var(--teco-rcols-m, 2) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-m, 2))
	) !important;
	max-width: min(
		var(--teco-rel-card-max, 100000px),
		calc((100cqi - (var(--teco-rcols-m, 2) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-m, 2))
	) !important;
}

@container teco-rel (min-width: 768px) {
	.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
		width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100cqi - (var(--teco-rcols-t, 3) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-t, 3))
		) !important;
		max-width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100cqi - (var(--teco-rcols-t, 3) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-t, 3))
		) !important;
	}
}

@container teco-rel (min-width: 1024px) {
	.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
		width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100cqi - (var(--teco-rcols-d, 4) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-d, 4))
		) !important;
		max-width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100cqi - (var(--teco-rcols-d, 4) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-d, 4))
		) !important;
	}
}

/* 无容器查询环境：退回视口 + 与网格相同的列变量 */
@supports not (container-type: inline-size) {
	.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
		width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100vw - (var(--teco-rcols-m, 2) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-m, 2) - 2rem)
		) !important;
		max-width: min(
			var(--teco-rel-card-max, 100000px),
			calc((100vw - (var(--teco-rcols-m, 2) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-m, 2) - 2rem)
		) !important;
	}

	@media (min-width: 768px) {
		.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
			width: min(
				var(--teco-rel-card-max, 100000px),
				calc((100vw - (var(--teco-rcols-t, 3) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-t, 3) - 2rem)
			) !important;
			max-width: min(
				var(--teco-rel-card-max, 100000px),
				calc((100vw - (var(--teco-rcols-t, 3) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-t, 3) - 2rem)
			) !important;
		}
	}

	@media (min-width: 1024px) {
		.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card {
			width: min(
				var(--teco-rel-card-max, 100000px),
				calc((100vw - (var(--teco-rcols-d, 4) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-d, 4) - 2rem)
			) !important;
			max-width: min(
				var(--teco-rel-card-max, 100000px),
				calc((100vw - (var(--teco-rcols-d, 4) - 1) * var(--teco-rel-col, 1.5rem)) / var(--teco-rcols-d, 4) - 2rem)
			) !important;
		}
	}
}

.woocommerce .elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card + li.product.teco-related-product-card,
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track ul.products.teco-related-products__list--marquee-strip > li.product.teco-related-product-card + li.product.teco-related-product-card {
	margin-inline-start: var(--teco-rel-col, 1.5rem) !important;
}

/* 走马灯：与网格相同，配图区 flex 长高，标题+按钮贴卡片底 */
.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track .teco-related-product-card .woocommerce-loop-product__link {
	flex: 1 1 0 !important;
	min-height: var(--teco-rel-img-min-h, 120px) !important;
	width: 100%;
	display: flex !important;
	align-items: flex-start !important;
	overflow: hidden;
	border-radius: inherit;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track .woocommerce-loop-product__link img {
	width: 100%;
	height: auto;
	object-fit: contain;
	display: block;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track .woocommerce-loop-product__title {
	flex: 0 0 auto;
	min-width: 0;
	margin-top: 0.65em;
	margin-bottom: 0;
	padding: 0 0.25em;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track .woocommerce-loop-product__title a {
	color: inherit;
	text-decoration: none;
}

.elementor-widget-teco-related-products .teco-related-products--marquee .teco-related-products__marquee-track .woocommerce-loop-product__buttons {
	flex-shrink: 0;
	padding-top: 0.65em !important;
	margin-top: 0 !important;
}
