/* ==========================================================================
   Каталог: сетка, фильтры, полоса выдачи
   --------------------------------------------------------------------------
   Пропорции взяты с каталога Ozon (замер браузером, 1440 px):
     фильтры 256 px | сетка 1104 px | 4 колонки | карточка 261x359 | зазор 18
   У нас контейнер шире (1380 px), поэтому колонка фильтров 280 px, а сетка
   сама набирает 4 колонки по 240+ и не больше пяти на широких экранах:
   больше пяти карточек в ряд читаются хуже (Baymard).
   ========================================================================== */

.ms-cat {
	display: grid;
	grid-template-columns: 280px minmax(0, 1fr);
	gap: 24px;
	align-items: start;
	padding-block: 4px 48px;
}

/* --- Полоса выдачи -------------------------------------------------------- */

.ms-cat__toolbar {
	display: flex;
	align-items: center;
	gap: 16px;
	flex-wrap: wrap;
	position: sticky;
	top: var(--ms-cat-top, 64px);
	z-index: 6;
	margin-bottom: 16px;
	padding: 10px 0;
	background: var(--ms-bg);
	border-bottom: 1px solid var(--ms-line);
}

.ms-cat__count {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	color: var(--ms-ink);
	flex: 1 1 auto;
}

.ms-cat__tools {
	display: flex;
	align-items: center;
	gap: 10px;
}

.ms-cat__select {
	height: 40px;
	padding: 0 34px 0 14px;
	border: 1px solid var(--ms-line);
	border-radius: 10px;
	background: var(--ms-surface);
	color: var(--ms-ink);
	font-size: 14px;
	font-family: inherit;
	appearance: none;
	background-image: linear-gradient(45deg, transparent 50%, var(--ms-muted) 50%), linear-gradient(135deg, var(--ms-muted) 50%, transparent 50%);
	background-position: calc(100% - 18px) 17px, calc(100% - 13px) 17px;
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
	cursor: pointer;
}

.ms-cat__view {
	display: inline-flex;
	border: 1px solid var(--ms-line);
	border-radius: 10px;
	overflow: hidden;
}

.ms-cat__view-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	color: var(--ms-muted);
	background: var(--ms-surface);
}

.ms-cat__view-btn + .ms-cat__view-btn {
	border-left: 1px solid var(--ms-line);
}

.ms-cat__view-btn:hover,
.ms-cat__view-btn.is-on {
	color: var(--ms-accent-text, #12787a);
	background: var(--ms-accent-soft, #e8f6f6);
}

.ms-cat__filterbtn {
	display: none; /* только на телефоне, см. медиазапросы */
}

/* --- Панель фильтров ------------------------------------------------------ */

.ms-cat__side {
	position: sticky;
	top: var(--ms-cat-top, 64px);
	max-height: calc(100vh - var(--ms-cat-top, 64px) - 24px);
	overflow: auto;
	overscroll-behavior: contain;
	background: var(--ms-surface);
	border: 1px solid var(--ms-line);
	border-radius: 16px;
	padding: 4px 0 12px;
	scrollbar-width: thin;
}

.ms-cat__side-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 14px 16px 10px;
	border-bottom: 1px solid var(--ms-line);
}

.ms-cat__side-title {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 17px;
	font-weight: 700;
}

.ms-cat__side-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 11px;
	background: var(--ms-accent);
	color: #fff;
	font-size: 12px;
	font-weight: 700;
}

.ms-cat__side-close {
	display: none;
	width: 36px;
	height: 36px;
	border: 0;
	background: none;
	font-size: 26px;
	line-height: 1;
	color: var(--ms-muted);
	cursor: pointer;
}

/* Активные фильтры */

.ms-cat__active {
	padding: 12px 16px;
	border-bottom: 1px solid var(--ms-line);
}

.ms-cat__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0 0 8px;
	padding: 0;
	list-style: none;
}

.ms-cat__chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px;
	border-radius: 999px;
	background: var(--ms-accent-soft, #e8f6f6);
	color: var(--ms-accent-text, #12787a);
	font-size: 13px;
	line-height: 1.3;
	text-decoration: none;
}

.ms-cat__chip-x {
	font-size: 15px;
	opacity: 0.75;
}

.ms-cat__chip:hover .ms-cat__chip-x {
	opacity: 1;
}

.ms-cat__reset {
	font-size: 13px;
	color: var(--ms-muted);
	text-decoration: underline;
}

/* Разделы фильтра */

.ms-cat__facet {
	border-bottom: 1px solid var(--ms-line);
}

.ms-cat__facet:last-child {
	border-bottom: 0;
}

.ms-cat__facet-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 13px 16px;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
	list-style: none;
}

.ms-cat__facet-head::-webkit-details-marker {
	display: none;
}

.ms-cat__facet-mark {
	position: relative;
	width: 12px;
	height: 12px;
	flex: none;
}

.ms-cat__facet-mark::before,
.ms-cat__facet-mark::after {
	content: "";
	position: absolute;
	inset: 5px 0 auto;
	height: 2px;
	border-radius: 2px;
	background: var(--ms-muted);
	transition: transform 0.2s ease;
}

.ms-cat__facet-mark::after {
	transform: rotate(90deg);
}

.ms-cat__facet[open] .ms-cat__facet-mark::after {
	transform: rotate(0deg);
}

.ms-cat__facet-body {
	padding: 0 16px 14px;
}

/* Значения */

.ms-cat__opts {
	margin: 0;
	padding: 0;
	list-style: none;
	display: grid;
	gap: 2px;
}

.ms-cat__opt {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 6px 6px 2px;
	border-radius: 8px;
	color: var(--ms-ink);
	text-decoration: none;
	font-size: 14px;
	line-height: 1.35;
}

.ms-cat__opt:hover {
	background: var(--ms-bg);
}

/* Значение без товаров: подпись остаётся читаемой (полупрозрачность её
   уводила ниже нормы контраста, это ловил axe), «выключенность» показывает
   пунктирная рамка и приглушённый счётчик. */
.ms-cat__opt.is-zero {
	cursor: default;
	color: var(--ms-ink-2, #5d6b6d);
}

.ms-cat__opt.is-zero .ms-cat__opt-box {
	border-style: dashed;
}

.ms-cat__opt.is-zero .ms-cat__opt-count {
	color: var(--ms-ink-2, #5d6b6d);
	opacity: 0.7;
}

.ms-cat__opt-box {
	position: relative;
	width: 18px;
	height: 18px;
	flex: none;
	border: 1.5px solid var(--ms-line);
	border-radius: 5px;
	background: var(--ms-surface);
	transition: background 0.15s ease, border-color 0.15s ease;
}

.ms-cat__opt.is-on .ms-cat__opt-box {
	background: var(--ms-accent);
	border-color: var(--ms-accent);
}

.ms-cat__opt.is-on .ms-cat__opt-box::after {
	content: "";
	position: absolute;
	left: 5px;
	top: 2px;
	width: 5px;
	height: 9px;
	border: solid #fff;
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
}

.ms-cat__opt-name {
	flex: 1 1 auto;
	min-width: 0;
	overflow-wrap: anywhere;
}

.ms-cat__opt-count {
	flex: none;
	color: var(--ms-muted);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
}

.ms-cat__opt.is-on .ms-cat__opt-name {
	font-weight: 600;
}

.ms-cat__more {
	margin-top: 6px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--ms-accent-text, #12787a);
	font: inherit;
	font-size: 13px;
	cursor: pointer;
	text-decoration: underline;
}

.ms-cat__stars {
	color: #f0a500;
	letter-spacing: 1px;
}


/* Цена */

.ms-cat__price-row {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-bottom: 8px;
}

.ms-cat__price input {
	width: 100%;
	min-width: 0;
	height: 40px;
	padding: 0 10px;
	border: 1px solid var(--ms-line);
	border-radius: 10px;
	background: var(--ms-surface);
	font: inherit;
	font-size: 14px;
	color: var(--ms-ink);
}

.ms-cat__price-dash {
	color: var(--ms-muted);
}

.ms-cat__hint,
.ms-cat__facet-body .ms-muted {
	margin: 8px 0 0;
	font-size: 12px;
	line-height: 1.4;
}

.ms-cat__side-foot {
	display: none; /* кнопки нужны только в мобильном листе */
	gap: 8px;
	padding: 12px 16px 0;
}

/* --- Сетка и карточки ----------------------------------------------------- */

.ms-cat__grid {
	display: grid;
	gap: 18px;
	align-items: stretch;
}

.ms-cat--grid .ms-cat__grid {
	grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* Кадр карточки в каталоге — 3:4, как на странице товара. Пропорция одна на всю
   площадку: тот же кадр рисует карточка товара (product.css, «Кадр витрины 3:4»)
   и предпросмотр в кабинете продавца (inc/ms-vendor-gallery.php, ms_vg_ratio),
   поэтому продавец видит в редакторе ровно то, что попадёт в каталог.

   Пропорцию держит само поле под фото, а не обёртка с белыми полями: 12 px
   padding внутри кадра искажают пропорцию содержимого (поле выходило 1,37
   вместо 1,33), и снимок 3:4 оставлял узкую белую полосу снизу — на живой
   карточке это и было видно. Теперь поле под фото ровно 3:4 при любой ширине
   карточки, и фото 3:4 заполняет его целиком, без полос.

   Снимок показывается целиком (object-fit: contain из cards.css), поэтому
   инструмент не обрезается: квадратное фото встаёт по центру с ровными полями
   сверху и снизу — так же, как на странице товара.

   Заглушка вместо фото живёт в том же поле 3:4 — иначе загрузка снимка меняла
   бы высоту карточки и строки сетки переставали совпадать по низам. */
.ms-cat .ms-pcard__media {
	aspect-ratio: auto;
}

.ms-cat .ms-pcard__media .ms-pcard__img,
.ms-cat .ms-pcard__media .ms-ph {
	aspect-ratio: 3 / 4;
	height: auto;
}

/* Каталог: карточка тянется по высоте строки, чтобы низы совпадали */
.ms-cat .ms-pcard {
	height: 100%;
}

/* В списке карточек больше, чем на витрине, поэтому внутри каталога тело
   карточки чуть плотнее — в первом экране помещается больше товаров. */
.ms-cat .ms-pcard__body {
	gap: 5px;
	padding: 10px 12px 12px;
}

.ms-cat .ms-pcard__buy {
	min-height: 40px;
}

.ms-cat .ms-pcard__title {
	min-height: 2.6em;
}

/* Список: слева фото, справа характеристики — так сравнивать удобнее */
.ms-cat--list .ms-cat__grid {
	grid-template-columns: 1fr;
	gap: 12px;
}

.ms-cat--list .ms-pcard {
	display: grid;
	grid-template-columns: 220px minmax(0, 1fr);
	gap: 18px;
	align-items: start;
	padding: 14px;
}

.ms-cat--list .ms-pcard__media {
	border-radius: 12px;
}

.ms-cat--list .ms-pcard__body {
	padding: 0;
}

.ms-cat--list .ms-pcard__title {
	min-height: 0;
	font-size: 17px;
	-webkit-line-clamp: 3;
}

.ms-cat--list .ms-pcard__specs {
	display: block;
	font-size: 14px;
	color: var(--ms-ink);
}

.ms-cat--list .ms-pcard__foot {
	justify-content: flex-start;
}

.ms-cat--list .ms-pcard__buy {
	min-width: 180px;
}

/* --- Пагинация ------------------------------------------------------------ */

.ms-cat__pager {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 16px;
	margin-top: 28px;
}

.ms-cat__more[disabled] {
	opacity: 0.6;
	cursor: default;
}

.ms-cat__pages ul {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ms-cat__pages a,
.ms-cat__pages span {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 40px;
	height: 40px;
	padding: 0 12px;
	border: 1px solid var(--ms-line);
	border-radius: 10px;
	background: var(--ms-surface);
	color: var(--ms-ink);
	text-decoration: none;
	font-size: 14px;
}

.ms-cat__pages .current {
	background: var(--ms-accent);
	border-color: var(--ms-accent);
	color: #fff;
	font-weight: 600;
}

.ms-cat__pages a:hover {
	border-color: var(--ms-accent-text, #12787a);
	color: var(--ms-accent-text, #12787a);
}

/* --- Пустая выдача -------------------------------------------------------- */

.ms-cat__empty {
	padding: 48px 24px;
	border: 1px dashed var(--ms-line);
	border-radius: 16px;
	text-align: center;
}

.ms-cat__empty-title {
	margin: 0 0 8px;
	font-size: 20px;
	font-weight: 700;
}

.ms-cat__empty-cats {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin: 20px 0 0;
	padding: 0;
	list-style: none;
}

.ms-cat__empty-cats a {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	border: 1px solid var(--ms-line);
	border-radius: 999px;
	text-decoration: none;
	font-size: 14px;
}

.ms-cat__empty-cats a:hover {
	border-color: var(--ms-accent-text, #12787a);
	color: var(--ms-accent-text, #12787a);
}

/* --- Обновление выдачи ---------------------------------------------------- */

.ms-cat.is-busy {
	opacity: 0.55;
	pointer-events: none;
	transition: opacity 0.15s ease;
}

.ms-cat__grid.is-appended {
	animation: ms-cat-fade 0.25s ease;
}

@keyframes ms-cat-fade {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

/* --- Узкие экраны: фильтры становятся листом ----------------------------- */

@media (max-width: 1279px) {
	.ms-cat {
		grid-template-columns: minmax(0, 1fr);
	}

	.ms-cat__filterbtn {
		display: inline-flex;
	}

	.ms-cat__side {
		position: fixed;
		inset: 0;
		z-index: 120;
		max-height: none;
		border: 0;
		border-radius: 0;
		padding-bottom: 96px;
		transform: translateY(100%);
		transition: transform 0.25s ease;
		visibility: hidden;
	}

	.ms-cat__side.is-open {
		transform: none;
		visibility: visible;
	}

	.ms-cat__side-head {
		position: sticky;
		top: 0;
		z-index: 2;
		background: var(--ms-surface);
	}

	.ms-cat__side-close {
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	.ms-cat__side-foot {
		display: grid;
	}

	/* Кнопки листа прилипают к низу: подтверждение всегда под рукой */
	.ms-cat__side-foot {
		position: sticky;
		bottom: 0;
		background: var(--ms-surface);
		border-top: 1px solid var(--ms-line);
		padding: 12px 16px;
	}

	.ms-cat .ms-pcard__title {
		min-height: 0;
	}
}

@media (max-width: 767px) {
	.ms-cat--grid .ms-cat__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 12px;
	}

	.ms-cat__toolbar {
		gap: 8px;
	}

	.ms-cat__count {
		flex: 1 1 100%;
		order: 2;
		font-size: 14px;
	}

	.ms-cat__view {
		display: none; /* на телефоне сетка из двух колонок — единственный вид */
	}

	.ms-cat--list .ms-pcard {
		grid-template-columns: 128px minmax(0, 1fr);
		gap: 12px;
		padding: 10px;
	}

	.ms-cat--list .ms-pcard__specs {
		display: none;
	}

	.ms-cat--list .ms-pcard__buy {
		min-width: 0;
	}

	.ms-cat__pages .ms-cat__page-dots {
		display: none;
	}
}

body.ms-cat-locked {
	overflow: hidden;
}

