/**
 * Стили страницы каталога (section.php): панель сортировки и сетка товаров.
 * Подключается отдельно из section.php.
 */

/* Панель сортировки/фильтра #catalogLine */
#catalogLine {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	background: #fff;
	border-radius: 8px;
	padding: 12px 16px;
	margin-bottom: 20px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
	gap: 20px;
	height: auto !important;
	line-height: normal !important;
	box-sizing: border-box;
}

#catalogLine .oFilter {
	display: block !important;
	margin: 0 !important;
}

#catalogLine .column {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0 !important;
	float: none !important;
	min-width: 0;
}

#catalogLine .label {
	font-size: 14px;
	color: #6c757d;
	white-space: nowrap;
	margin-right: 8px;
}

#catalogLine .dropDownList {
	position: relative;
	min-width: 160px;
	cursor: pointer;
	user-select: none;
}

#catalogLine .dropDownSelected {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 12px;
	border: 1px solid #dee2e6;
	border-radius: 6px;
	background-color: #fff;
	font-size: 14px;
	color: #212529;
	transition: all 0.2s;
	position: relative;
}

#catalogLine .dropDownSelected:after {
	content: "";
	display: inline-block;
	width: 8px;
	height: 8px;
	border-right: 2px solid #adb5bd;
	border-bottom: 2px solid #adb5bd;
	transform: rotate(45deg);
	margin-left: 8px;
	position: relative;
	top: -2px;
}

#catalogLine .dropDownSelected:hover {
	border-color: #adb5bd;
}

#catalogLine .dropDownItems {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 99;
	margin-top: 0;
	padding-top: 6px;
	background-color: white;
	border: 1px solid #dee2e6;
	border-radius: 6px;
	box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
	max-height: 300px;
	overflow-x: hidden;
	overflow-y: auto;
	display: none;
}

#catalogLine .dropDownItems::before {
	content: "";
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 10px;
}

#catalogLine .dropDownList:hover .dropDownItems {
	display: block;
}

#catalogLine .dropDownItem {
	padding: 8px 12px;
	font-size: 14px;
	color: #495057;
	transition: background-color 0.2s;
}

#catalogLine .dropDownItem:hover {
	background-color: #f8f9fa;
}

#catalogLine .dropDownItem.selected {
	background-color: #e9ecef;
	color: #212529;
	font-weight: 500;
}

#catalogLine .viewList {
	display: flex;
	align-items: center;
	gap: 8px;
}

#catalogLine .viewList .element {
	margin: 0;
}

#catalogLine .viewList .element a {
	width: 36px;
	height: 36px;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #f8f9fa;
	border: 1px solid #dee2e6;
	border-radius: 6px;
	transition: all 0.2s;
}

#catalogLine .viewList .element a:hover {
	background-color: #e9ecef;
	border-color: #ced4da;
}

#catalogLine .viewList .element a.selected {
	background-color: #e9ecef;
	border-color: #adb5bd;
}

#catalogLine .oSmartFilter {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 38px;
	padding: 8px 16px;
	border-radius: 12px;
	font-family: "Montserrat", sans-serif;
	font-size: 13px;
	font-weight: 700;
	line-height: 1.2;
	color: #1a1a1a !important;
	text-decoration: none !important;
	border: 1px solid rgba(255, 204, 51, 0.3);
	background: linear-gradient(135deg, #ffcc33, #ffd700 50%, #ffcc33);
	background-size: 200% 200%;
	box-shadow:
		0 2px 6px rgba(255, 204, 51, 0.25),
		inset 0 1px 2px rgba(255, 255, 255, 0.5);
	transition:
		background 0.25s ease,
		border-color 0.25s ease,
		box-shadow 0.25s ease,
		transform 0.2s ease;
}

#catalogLine .oSmartFilter:hover {
	border-color: rgba(255, 204, 51, 0.45);
	box-shadow:
		0 4px 10px rgba(255, 204, 51, 0.32),
		inset 0 1px 2px rgba(255, 255, 255, 0.55);
}

#catalogLine .oSmartFilter:active {
	transform: translateY(1px);
}

#catalogLine .oSmartFilter .ico {
	width: 14px;
	height: 14px;
	opacity: 1;
	/* Иконка фильтра приходит background-image (png) из template_styles.css.
	   Делаем её чёрной и на ПК, и на мобилке без замены картинки. */
	filter: brightness(0) saturate(100%);
}

#catalogColumn #smartFilter .smart-filter__close {
	display: none;
	border: 0;
	background: transparent;
	color: #6b7280;
	font-size: 22px;
	line-height: 1;
	padding: 0;
	margin-left: auto;
	cursor: pointer;
	transition: color 0.2s ease;
}

#catalogColumn #smartFilter .smart-filter__close:hover {
	color: #1f2937;
}

@media (max-width: 768px) {
	#catalogLine {
		flex-direction: column;
		align-items: flex-start;
	}
	#catalogLine .column {
		width: 100%;
		margin-bottom: 10px !important;
		display: block;
	}
	#catalogLine .dropDownList {
		width: 100%;
	}

	#catalogLine .oFilter {
		width: 100%;
	}

	#catalogLine .oSmartFilter {
		width: 100%;
	}

	/* Фильтр как full-screen modal на мобилке */
	html.tsk-filter-open,
	body.tsk-filter-open {
		overflow: hidden;
		height: 100%;
	}

	#catalogColumn #smartFilter {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: auto;
		z-index: 10000;
		width: 100vw;
		height: 100vh;
		background: #ffffff;
		margin-top: 0 !important;
		transform: translateY(110vh);
		transition: transform 0.25s ease;
		overflow: hidden;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
	}

	#catalogColumn #smartFilter.opened {
		transform: translateY(0);
	}

	#catalogColumn #smartFilter.opened {
		box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.18);
	}

	/* Прокрутка только внутри формы, чтобы не было "пустого" скролла */
	#catalogColumn #smartFilter.opened {
		overflow: hidden;
	}

	#catalogColumn #smartFilter .smart-filter__form {
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
	}

	/* Убираем лишние нижние паддинги из глобальных/min стилей */
	#catalogColumn #smartFilter #smartFilterForm.smart-filter__form {
		padding-bottom: 0;
		margin-bottom: 0;
	}

	/* Кнопки — с безопасной зоной снизу, но без "пустого" скролла */
	#catalogColumn #smartFilterControls.smart-filter__actions {
		position: sticky;
		bottom: 0;
		background: #fff;
		box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.06);
		padding-top: 12px;
		padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	}

	/* Кнопку закрытия показываем в full-screen режиме */
	#catalogColumn #smartFilter.opened .smart-filter__close {
		display: inline-flex;
	}
}

/* На ПК кнопку фильтра в панели скрываем */
@media (min-width: 1025px) {
	#catalogLine .oFilter {
		display: none !important;
	}
}

@media (max-width: 1024px) {
	#catalogLine {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
		height: auto !important;
		line-height: normal !important;
		padding: 8px 0 !important;
		gap: 10px;
		box-sizing: border-box;
	}

	#catalogLine .oFilter {
		flex: 0 0 100%;
		width: 100%;
		margin-right: 0 !important;
	}

	#catalogLine .column {
		flex: 0 0 100%;
		width: 100%;
		min-width: 0;
		display: block;
		margin: 0 !important;
	}

	#catalogLine .dropDownList {
		min-width: 0;
		width: 100%;
	}

	#catalogColumn #smartFilter.opened .smart-filter__close {
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}
}

/* Сетка товаров каталога — CSS Grid (как у .catalog-categories-grid), без calc() на карточках */
#catalogColumn .rightColumn .items.productList,
#ajaxSection .items.productList {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 20px;
	width: 100%;
	margin: 0;
	max-width: none;
	box-sizing: border-box;
}

/* Карточки в гриде — без принудительного width/flex */
#catalogColumn .rightColumn .items.productList .product-card,
#catalogColumn .rightColumn .items.productList .tsk-product-card,
#ajaxSection .items.productList .product-card,
#ajaxSection .items.productList .tsk-product-card {
	box-sizing: border-box;
	min-width: 0;
}

#ajaxSection .product-card,
#ajaxSection .tsk-product-card,
.product-card {
	min-width: 0;
	background-color: #fff;
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	padding: 10px;
	position: relative;
	transition:
		transform 0.3s ease,
		box-shadow 0.3s ease;
	display: flex;
	flex-direction: column;
	height: 100%;
	box-sizing: border-box;
	overflow: hidden !important;
	justify-content: space-between;
}

@media (max-width: 1400px) {
	#catalogColumn .rightColumn .items.productList,
	#ajaxSection .items.productList {
		grid-template-columns: repeat(4, 1fr);
	}
}

@media (max-width: 1100px) {
	#catalogColumn .rightColumn .items.productList,
	#ajaxSection .items.productList {
		grid-template-columns: repeat(3, 1fr);
		gap: 18px;
	}
}

@media (max-width: 700px) {
	#catalogColumn .rightColumn .items.productList,
	#ajaxSection .items.productList {
		grid-template-columns: repeat(2, 1fr);
		gap: 15px;
	}
}

@media (max-width: 450px) {
	#catalogColumn .rightColumn .items.productList,
	#ajaxSection .items.productList {
		grid-template-columns: 1fr;
		gap: 10px;
	}
}

/* Кнопка «В корзину» в карточках — не растягивать по высоте (перебиваем flex: 0 0 100% из глобальных стилей) */
@media (max-width: 1199.98px) {
	#catalogColumn .rightColumn .items.productList .product-card .cart-button,
	#catalogColumn
		.rightColumn
		.items.productList
		.tsk-product-card
		.cart-button,
	#ajaxSection .items.productList .product-card .cart-button,
	#ajaxSection .items.productList .tsk-product-card .cart-button,
	#catalogColumn .rightColumn .items.productList .product-card .addCart,
	#catalogColumn .rightColumn .items.productList .tsk-product-card .addCart,
	#catalogColumn .rightColumn .items.productList .product-card .tsk-btn--cart,
	#catalogColumn
		.rightColumn
		.items.productList
		.tsk-product-card
		.tsk-btn--cart,
	#ajaxSection .items.productList .product-card .addCart,
	#ajaxSection .items.productList .tsk-product-card .addCart,
	#ajaxSection .items.productList .product-card .tsk-btn--cart,
	#ajaxSection .items.productList .tsk-product-card .tsk-btn--cart {
		flex: none !important;
		height: auto !important;
		min-height: auto;
		width: 100%;
		max-width: 100%;
		display: block;
		text-align: center;
		box-sizing: border-box;
	}
}
