/**
 * Галерея «до и после»: фильтры и карточки.
 * Макеты: десктоп 259:15224, мобильный 259:15652.
 *
 * Подключается только на странице с шаблоном page-gallery.php
 * (inc/gallery.php → wimpole_us_gallery_enqueue). Разметка — там же
 * и в partials/gallery/card.php, поведение — assets/js/gallery.js.
 *
 * Раскладка фильтров:
 *   ≥1024 — кнопки в ряд по шести колонкам, варианты открытого фильтра
 *           строкой под ними (обёртка фильтра — display: contents);
 *   <1024 — кнопки столбцом, варианты раскрываются под своей кнопкой.
 */

.wcg {
	--wcg-ink: #004054;
	--wcg-line: #093449;
	--wcg-accent: #56afcb;
	--wcg-soft: #d6edf2;
	--wcg-text: #595857;

	padding-block: 99px 100px;
	font-family: var(--wc-font-ui);
}

.wcg__inner {
	max-width: calc(1286px + 2 * 5 * var(--vw, 1vw));
	margin-inline: auto;
	padding-inline: calc(5 * var(--vw, 1vw));
}

.wcg button {
	font-family: inherit;
	text-transform: none;
	letter-spacing: normal;
}

/* ------------------------------------------------------------------
   Фильтры
   ------------------------------------------------------------------ */

.wcg-filters__head {
	display: none;
}

.wcg-filters__bar {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	column-gap: 11px;
	max-width: 1272px;
	margin-inline: auto;
}

.wcg-filter {
	display: contents;
}

.wcg .wcg-filter__btn.wcg-filter__btn,
.wcg .wcg-clear--bar.wcg-clear--bar {
	grid-row: 1;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	min-height: 63px;
	margin: 0;
	padding: 0 34px;
	border: 2px solid var(--wcg-line);
	border-radius: 150px;
	background: #fff;
	color: var(--wcg-ink);
	font-weight: 500;
	font-size: clamp(15px, calc(1.125 * var(--vw, 1vw)), 18px);
	line-height: 1.6;
	white-space: nowrap;
	cursor: pointer;
	transition: border-color 0.3s, color 0.3s, background-color 0.3s;
}

.wcg .wcg-filter__btn.wcg-filter__btn:focus-visible,
.wcg-clear:focus-visible,
.wcg .wcg-opt.wcg-opt:focus-visible,
.wcg .wcg-card__more.wcg-card__more:focus-visible {
	outline: 2px solid var(--wcg-accent);
	outline-offset: 2px;
}

@media (hover: hover) {
	.wcg .wcg-filter__btn.wcg-filter__btn:hover {
		border-color: var(--wcg-accent);
		color: var(--wcg-accent);
	}
}

.wcg .wcg-filter.is-open .wcg-filter__btn.wcg-filter__btn,
.wcg .wcg-filter.is-selected .wcg-filter__btn.wcg-filter__btn {
	border-color: var(--wcg-line);
	background: var(--wcg-soft);
	color: var(--wcg-ink);
}

.wcg-filter__label-m,
.wcg-filter__chev {
	display: none;
}

/* Крестик выбранного фильтра — справа внутри кнопки, как в макете. */
.wcg-filter__x {
	position: absolute;
	top: 50%;
	right: 9px;
	display: none;
	width: 26px;
	height: 26px;
	transform: translateY(-50%);
}

.wcg-filter__x svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wcg-filter.is-selected .wcg-filter__x {
	display: block;
}

/* Clear All: гаснет, пока ничего не выбрано. */
.wcg-clear {
	opacity: 0.5;
	cursor: default;
}

.wcg .wcg-clear--bar.wcg-clear--bar {
	border-color: var(--wcg-accent);
	color: var(--wcg-accent);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.wcg .wcg-filters.has-filters .wcg-clear {
	opacity: 1;
	cursor: pointer;
}

/* Варианты открытого фильтра — строкой под кнопками. */
.wcg-filter__panel {
	grid-row: 2;
	grid-column: 1 / -1;
	margin-top: 46px;
}

.wcg-filter__panel[hidden] {
	display: none;
}

.wcg-opts {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 15px 25px;
}

.wcg .wcg-opt.wcg-opt {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 56px;
	margin: 0;
	padding: 14px 20px;
	border: 1px solid var(--wcg-text);
	border-radius: 8px;
	background: #fff;
	color: var(--wcg-text);
	font-weight: 400;
	font-size: 16px;
	line-height: 1.6;
	text-align: center;
	cursor: pointer;
	transition: background-color 0.2s, opacity 0.2s;
}

@media (hover: hover) {
	.wcg .wcg-opt.wcg-opt:not(:disabled):hover {
		background: var(--wcg-soft);
	}
}

.wcg .wcg-opt.wcg-opt.is-active {
	background: var(--wcg-soft);
}

.wcg .wcg-opt.wcg-opt:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.wcg-sep {
	height: 2px;
	margin: 50px auto 60px;
	max-width: 1282px;
	border: 0;
	background: var(--wcg-ink);
}

/* ------------------------------------------------------------------
   Сетка и карточки
   ------------------------------------------------------------------ */

.wcg-grid {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 100px 22px;
	transition: opacity 0.3s;
}

.wcg-grid.is-loading {
	opacity: 0.52;
}

.wcg-grid[data-empty] {
	display: block;
}

.wcg-grid > h3 {
	margin: 0;
	color: var(--wcg-ink);
	font-size: 24px;
	line-height: 1.3;
}

.wcg-card {
	display: flex;
	flex-direction: column;
	min-width: 0;
	margin: 0;
}

/* Шторка: «после» лежит целиком, «до» поверх обрезано по позиции. */
.wcg-card__photo {
	--position: 50%;

	position: relative;
	overflow: hidden;
	aspect-ratio: 297 / 299;
	border-radius: 24px;
	background: #eef3f5;
	isolation: isolate;
}

.wcg-card__photo .slider-image {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
}

.wcg-card__photo .image-before {
	clip-path: inset(0 calc(100% - var(--position)) 0 0);
}

.wcg-card__photo .sliderin {
	position: absolute;
	inset: 0;
	z-index: 3;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	background: none;
	opacity: 0;
	cursor: ew-resize;
	-webkit-appearance: none;
	appearance: none;
}

.wcg-card__photo .slider-line {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--position);
	z-index: 1;
	width: 3px;
	background: #fff;
	transform: translateX(-50%);
	pointer-events: none;
}

.wcg-card__photo .slider-button {
	position: absolute;
	top: 50%;
	left: var(--position);
	z-index: 2;
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	color: #fff;
	filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
	transform: translate(-50%, -50%);
	pointer-events: none;
}

.wcg-card__photo .slider-button svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wcg-card__photo .sliderin:focus-visible ~ .slider-button {
	outline: 2px solid #fff;
	outline-offset: 3px;
	border-radius: 50%;
}

.wcg-card__title {
	margin: 24px 0 19px;
	color: #16435a;
	font-family: var(--wc-font-ui);
	font-weight: 700;
	font-size: 20px;
	line-height: 1.6;
	letter-spacing: normal;
	text-transform: none;
}

.wcg-card__rows {
	margin: 0;
	padding: 0;
	list-style: none;
}

.wcg-card__row {
	position: relative;
	display: grid;
	grid-template-columns: 27px minmax(0, 1fr);
	align-items: center;
	margin: 0;
	padding: 10px 0 8px;
	color: var(--wcg-text);
	font-size: 16px;
	line-height: 1.6;
}

.wcg-card__row:first-child {
	padding-top: 0;
}

/* Линия под строкой — короче карточки, как в макете (247 из 297). */
.wcg-card__row:not(:last-child)::after {
	content: "";
	position: absolute;
	bottom: 0;
	left: 0;
	width: min(100%, 247px);
	height: 1px;
	background: rgba(45, 93, 112, 0.35);
}

.wcg-card__row b {
	font-weight: 700;
}

.wcg-card__icon {
	display: flex;
	align-items: center;
	height: 21px;
}

.wcg-card__icon img {
	display: block;
	width: auto;
	max-width: 15px;
	height: auto;
	max-height: 21px;
}

/* Загрузка: кружок под сеткой, пока догружается следующая страница,
   и поверх сетки, пока перестраивается выдача по фильтру. Класс
   is-loading ставит assets/js/gallery.js. */
.wcg .cards_container {
	position: relative;
}

/* Кружок прижат к верху блока: ниже, у края экрана, его может закрыть
   липкая плашка консультации (147px). */
.wcg .gallery_more {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	height: 0;
	padding-top: 0;
	box-sizing: content-box;
	transition: height 0.2s, padding-top 0.2s;
}

.wcg .gallery_more.is-loading {
	height: 160px;
	padding-top: 48px;
}

.wcg .gallery_more.is-loading::before,
.wcg .cards_container.is-loading::before {
	content: "";
	display: block;
	width: 44px;
	height: 44px;
	border: 3px solid var(--wcg-soft);
	border-top-color: var(--wcg-accent);
	border-radius: 50%;
	animation: wcg-spin 0.8s linear infinite;
}

.wcg .cards_container.is-loading::before {
	position: absolute;
	top: 80px;
	left: 50%;
	z-index: 5;
	margin-left: -22px;
}

@keyframes wcg-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.wcg .gallery_more.is-loading::before,
	.wcg .cards_container.is-loading::before {
		animation-duration: 2.4s;
	}
}

/* Кнопка «View Result» — только на мобильном. */
.wcg .wcg-card__more.wcg-card__more {
	display: none;
}

/* ------------------------------------------------------------------
   Окно «View Result»
   ------------------------------------------------------------------ */

.wcg-modal {
	width: min(92vw, 720px);
	max-width: none;
	max-height: 92vh;
	padding: 0;
	border: 0;
	border-radius: 24px;
	background: #fff;
	overflow: auto;
}

.wcg-modal::backdrop {
	background: rgba(9, 52, 73, 0.6);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

.wcg-modal__box {
	position: relative;
	padding: 24px;
}

.wcg .wcg-modal__close.wcg-modal__close {
	position: absolute;
	top: 34px;
	right: 34px;
	z-index: 5;
	width: 36px;
	height: 36px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: #fff;
	cursor: pointer;
}

.wcg .wcg-modal__close.wcg-modal__close svg {
	display: block;
	width: 100%;
	height: 100%;
}

.wcg-modal .wcg-card__photo {
	aspect-ratio: 1 / 1;
	border-radius: 16px;
}

.wcg-modal .wcg-card__row:not(:last-child)::after {
	width: 100%;
}

html.wcg-modal-open {
	overflow: hidden;
}

/* ------------------------------------------------------------------
   Планшет и мобильный
   ------------------------------------------------------------------ */

@media (max-width: 1199px) {
	.wcg-grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 70px 22px;
	}
}

@media (max-width: 1023px) {
	.wcg {
		padding-block: 43px 50px;
	}

	.wcg-filters__head {
		display: flex;
		align-items: baseline;
		justify-content: space-between;
		margin-bottom: 21px;
	}

	.wcg-filters__title {
		color: var(--wcg-ink);
		font-weight: 500;
		font-size: 18px;
		line-height: 1.6;
	}

	.wcg .wcg-clear--head.wcg-clear--head {
		margin: 0;
		padding: 0;
		border: 0;
		background: none;
		color: var(--wcg-accent);
		font-weight: 500;
		font-size: 18px;
		line-height: 1.6;
		text-decoration: underline;
		text-underline-offset: 3px;
	}

	.wcg-filters__bar {
		display: flex;
		flex-direction: column;
		gap: 10px;
		max-width: none;
	}

	.wcg-filter {
		display: block;
	}

	.wcg .wcg-clear--bar.wcg-clear--bar {
		display: none;
	}

	.wcg .wcg-filter__btn.wcg-filter__btn {
		justify-content: space-between;
		width: 100%;
		min-height: 55px;
		padding: 0 29px;
		font-size: 18px;
		text-align: left;
	}

	.wcg-filter__label-d {
		display: none;
	}

	.wcg-filter__label-m {
		display: inline;
	}

	.wcg-filter__chev {
		display: flex;
		width: 17px;
		transition: transform 0.3s;
	}

	.wcg-filter__chev svg {
		display: block;
		width: 100%;
		height: auto;
	}

	.wcg-filter.is-open .wcg-filter__chev {
		transform: rotate(180deg);
	}

	.wcg-filter.is-selected .wcg-filter__chev {
		display: none;
	}

	.wcg-filter__x {
		position: static;
		transform: none;
	}

	.wcg-filter__panel {
		margin-top: 10px;
	}

	.wcg-opts {
		grid-template-columns: 1fr;
		gap: 8px;
	}

	.wcg .wcg-opt.wcg-opt {
		min-height: 50px;
		padding: 11px 20px;
	}

	.wcg-sep {
		margin-block: 50px;
	}

	.wcg-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 60px 20px;
	}
}

@media (max-width: 767px) {
	.wcg__inner {
		padding-inline: 20px;
	}

	.wcg-grid {
		grid-template-columns: 1fr;
		gap: 43px;
		padding-inline: 7px;
	}

	.wcg-card__photo {
		aspect-ratio: 337 / 340;
		border-radius: 12px;
	}

	.wcg-card__title {
		color: var(--wcg-text);
	}

	.wcg-card__row:not(:last-child)::after {
		width: 100%;
	}

	.wcg .wcg-card__more.wcg-card__more {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		min-height: 52px;
		margin: 24px 0 0;
		padding: 0 20px;
		border: 2px solid #2d5d70;
		border-radius: 8px;
		background: #fff;
		color: #2d5d70;
		font-weight: 700;
		font-size: 14px;
		line-height: 1;
		cursor: pointer;
	}

	.wcg-modal {
		width: calc(100vw - 24px);
	}

	.wcg-modal__box {
		padding: 16px;
	}

	.wcg .wcg-modal__close.wcg-modal__close {
		top: 24px;
		right: 24px;
	}
}
