/* =================================================================
   Related Content Block
   ================================================================= */

/* Section — padding scale mirrors content-cards / locations for consistency */
.related {
	position: relative;
	overflow: hidden;

	&.related--py-sm { padding-block: 2rem; }
	&.related--py-md { padding-block: 3rem; }
	&.related--py-lg { padding-block: 4rem; }
}

/* Section background */
.related.related--bg-default { background-color: var(--wp--preset--color--bg); }
.related.related--bg-light   { background-color: var(--wp--preset--color--bg-secondary); }

/* Grid (mobile-first: single column, stacks vertically) */
.related__grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: 1.5rem;
}

/* Narrow list: constrains the cards container width. Header keeps the
   section's container width. Useful with few items. */
.related--list-narrow .related__grid {
	max-width: 56rem;
	margin-inline: auto;
}

/* Single item: center the lone card with a sensible max-width so it
   doesn't stretch full-width on desktop or sit orphaned in a multi-col grid.
   Skipped when list-narrow is set, which already provides its own width. */
.related:not(.related--list-narrow).related--count-1 .related__grid {
	grid-template-columns: 1fr;
	max-width: 32rem;
	margin-inline: auto;
}

/* =================================================================
   Card border-radius modifier
   ================================================================= */
.related--radius-rounded .card {
	border-radius: 0.75rem;
}
.related--radius-rounded .card-media:first-child {
	border-radius: 0.75rem 0.75rem 0 0;
}

/* =================================================================
   Card base (all styles)
   ================================================================= */
.related .card {
	overflow: hidden;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.related .card-link {
	display: block;
	color: inherit;
	text-decoration: none;
}
.related .card-link:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}
.related .card-media {
	position: relative;
	overflow: hidden;
}

/* Aspect-ratio modifiers — mirror assets/css/components/card.css, which
   is not enqueued on the frontend. These give card-media a defined
   height so images with different intrinsic sizes stay uniform. */
.related .card-media.aspect-ratio--1-1 {
	aspect-ratio: 1 / 1;
}
.related .card-media.aspect-ratio--4-3 {
	aspect-ratio: 4 / 3;
}
.related .card-media.aspect-ratio--16-9 {
	aspect-ratio: 16 / 9;
}

.related .card-image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.3s ease;
}

.related .card:hover .card-image {
	transform: scale(1.05);
}
.related .card-image--placeholder {
	display: grid;
	place-items: center;
	background: var(--wp--preset--color--bg-secondary);
	color: var(--wp--preset--color--text-muted);
}
.related .card-content {
	display: flex;
	flex-direction: column;
	padding: 1rem;
}
.related .card-title {
	font-size: 1.1rem;
	font-weight: 600;
	margin: 0 0 0.5rem;
	line-height: 1.3;
}
.related .card-excerpt {
	font-size: 0.875rem;
	line-height: 1.5;
	color: var(--wp--preset--color--text);
	margin: 0 0 1rem;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.related .card-actions {
	margin-top: auto;
}
.related .card-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.9375rem;
}
.related .card-btn svg {
	transition: transform 0.2s ease;
}
.related .card-btn:hover svg {
	transform: translateX(2px);
}

/* =================================================================
   Card background token — consumed by every style variant below.
   Modifier classes set --card-bg; variants never hardcode a color.
   ================================================================= */
.related {
	--card-bg: var(--wp--preset--color--white);
}
.related--card-bg-white { --card-bg: var(--wp--preset--color--white); }
.related--card-bg-light { --card-bg: var(--wp--preset--color--bg-secondary); }

/* =================================================================
   Style: Default — border, white bg
   ================================================================= */
.related--style-default .card {
	background: var(--card-bg);
	border: 1px solid var(--wp--preset--color--border);
}
.related--style-default .card:hover {
	transform: translateY(-2px);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* =================================================================
   Style: Cards — elevated, rounded, shadow
   ================================================================= */
.related--style-cards .card {
	background: var(--card-bg);
	border: 0;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.related--style-cards .card:hover {
	transform: translateY(-4px);
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}
.related--style-cards .card-content {
	padding: 1.25rem;
}

/* =================================================================
   Style: Minimal — editorial, centered, clean
   ================================================================= */
.related--style-minimal .card {
	background: var(--card-bg);
	border: 0;
	box-shadow: none;
}
.related--style-minimal .card:hover {
	transform: none;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.related--style-minimal .card:hover .card-image {
	transform: scale(1.03);
}
.related--style-minimal .card-content {
	padding: 1.25rem;
	text-align: center;
}
.related--style-minimal .card-title {
	font-weight: 500;
}
.related--style-minimal .card-excerpt {
	display: none;
}
.related--style-minimal .card-actions {
	display: none;
}

/* =================================================================
   CTA "Ver todos"
   ================================================================= */
.related__cta {
	display: flex;
	justify-content: center;
	margin-top: 2rem;
}

/* =================================================================
   Empty state (editor)
   ================================================================= */
.related__empty {
	border: 2px dashed var(--wp--preset--color--border, #dee2e6);
	border-radius: 0.75rem;
	padding: 2.5rem;
	text-align: center;
	color: var(--wp--preset--color--text-muted, #6c757d);
}

/* =================================================================
   Carrusel (modo "Carrusel" del bloque)
   Scroll-snap horizontal — se desliza con el dedo en táctil, y en
   escritorio (>=64rem) aparecen flechas prev/next alineadas al
   contenedor. Mismo patrón que "Listado de Catálogo".
   ================================================================= */
.related__viewport {
	position: relative;
}

.related--carousel .related__grid {
	display: flex;
	flex-wrap: nowrap;
	grid-template-columns: none;
	max-width: none;
	margin-inline: 0;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x proximity;
	scroll-padding-inline: 0;
	scrollbar-width: none;
}
.related--carousel .related__grid::-webkit-scrollbar {
	display: none;
}

.related--carousel .related__grid > .card {
	flex: 0 0 88%;
	scroll-snap-align: start;
}

@media (min-width: 36rem) {
	.related--carousel .related__grid > .card {
		flex-basis: calc((100% - 1.5rem) / 2 - 0.75rem);
	}
}

@media (min-width: 64rem) {
	.related--carousel.related--cols-2 .related__grid > .card {
		flex-basis: calc((100% - 1.5rem) / 2 - 0.75rem);
	}
	.related--carousel.related--cols-3 .related__grid > .card {
		flex-basis: calc((100% - 3rem) / 3 - 0.75rem);
	}
	.related--carousel.related--cols-4 .related__grid > .card {
		flex-basis: calc((100% - 4.5rem) / 4 - 0.75rem);
	}
}

/* Flechas — solo escritorio */
.related__nav {
	display: none;
	position: absolute;
	top: 50%;
	z-index: 3;
	width: 2.75rem;
	height: 2.75rem;
	margin-top: -1.375rem;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: none;
	border-radius: 999px;
	background: var(--wp--preset--color--white, #fff);
	color: var(--wp--preset--color--text, #331f19);
	box-shadow: var(--wp--custom--shadows--200, 0 2px 8px rgb(0 0 0 / 0.15));
	cursor: pointer;
	transition: opacity 0.2s ease, background-color 0.2s ease;
}
.related__nav--prev { left: 0.5rem; }
.related__nav--next { right: 0.5rem; }
.related__nav:hover {
	background: var(--wp--preset--color--bg-secondary, #eff0f0);
}
.related__nav:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}
.related__nav[disabled] {
	opacity: 0.35;
	cursor: default;
}

@media (min-width: 64rem) {
	.related--carousel.related--with-controls .related__nav {
		display: flex;
	}
}

@media (prefers-reduced-motion: reduce) {
	.related__nav {
		transition: none;
	}
}

/* =================================================================
   Responsive
   ================================================================= */

/* SM (576px) */
@media (min-width: 576px) {
	.related__grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.related .card-content {
		padding: 1.25rem;
	}
}

/* MD (768px) */
@media (min-width: 768px) {
	.related.related--py-sm { padding-block: 3rem; }
	.related.related--py-md { padding-block: 4.5rem; }
	.related.related--py-lg { padding-block: 6rem; }

	/* Grid columns (count-1 keeps its own single-column layout above;
	   la fila flex del carrusel gana por especificidad más abajo) */
	.related:not(.related--count-1) .related__grid {
		grid-template-columns: repeat(3, 1fr);
	}
	.related.related--cols-2:not(.related--count-1) .related__grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.related.related--cols-4:not(.related--count-1) .related__grid {
		grid-template-columns: repeat(4, 1fr);
	}
}

/* =================================================================
   Align-center — centers the last incomplete row.
   Swaps grid → flex so the last card isn't stuck on the left when
   the item count doesn't fill the final row. Mobile-first: starts
   single-col, breakpoints match the non-align-center grid above. */
.related--align-center .related__grid {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
}

.related--align-center .related__grid > * {
	flex: 0 1 100%;
}

@media (min-width: 576px) {
	.related--align-center .related__grid > * {
		flex: 0 1 calc((100% - 1.5rem) / 2);
	}
}

@media (min-width: 768px) {
	.related--align-center.related--cols-2 .related__grid > * {
		flex: 0 1 calc((100% - 1.5rem) / 2);
	}
	.related--align-center.related--cols-3 .related__grid > * {
		flex: 0 1 calc((100% - 3rem) / 3);
	}
	.related--align-center.related--cols-4 .related__grid > * {
		flex: 0 1 calc((100% - 4.5rem) / 4);
	}
}

/* LG (992px) */
@media (min-width: 992px) {
	.related .card-content {
		padding: 1.5rem;
	}
}
