/**
 * Post Cards block - frontend and editor styles.
 *
 * Per-block stylesheet (block.json "style"), enqueued only when the block is on
 * the page. Theme tokens are used where they exist, with the mockup value as the
 * fallback. No background on the grid - the parent section owns it.
 */

.ivy-post-cards {
	position: relative;
}

/* Columns come from the space the track gets: as many 15rem cards as fit,
   up to the column count set in the inspector. Screen breakpoints gave three
   ~230px cards at 1100px, and three cards as two plus one at tablet sizes. */
.ivy-post-cards__track {
	--ivy-card-min: 15rem;
	--ivy-gap: 32px;
	display: grid;
	grid-template-columns: repeat(
		auto-fill,
		minmax(min(100%, max(var(--ivy-card-min), (100% - (var(--ivy-cols, 3) - 1) * var(--ivy-gap)) / var(--ivy-cols, 3))), 1fr)
	);
	gap: var(--ivy-gap);
	align-items: stretch;
}

/* ---------- Card ---------- */

.ivy-post-card {
	display: flex;
	flex-direction: column;
	background-color: #fff;
	border-radius: 15px;
	padding: 12px 12px 30px;
}

.ivy-post-card__media {
	display: block;
	border-radius: 10px;
	overflow: hidden;
}

.ivy-post-card__media img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	border-radius: 10px;
}

/* No image and no default card image set (General Settings > Post Cards): an
   empty 4:3 area in the theme's Off White, so the row still lines up. */
.ivy-post-card__media--placeholder {
	aspect-ratio: 4 / 3;
	background-color: var(--ivy-color-light-gray, #f5f3ee);
}

/* Every card image fills its 4:3 area (object-fit: cover above). Blocks saved
   with the old "Contain" image fit still print ivy-post-cards--media-contain,
   but it no longer changes the image. */

.ivy-post-card__body {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	padding: 20px 18px 0;
}

/* Therapy tags: the shared .ivy-tag-pill (css/tag-pill.css) in the post card
   look from the design: teal text on a pale teal tag with small corners. The
   colours go through the pill's own variables, so the location cards keep
   theirs. Note #12AFA6 on #F1FBFB is ~2.6:1, as designed. */
.ivy-post-card .ivy-post-card__tags.ivy-tag-pills {
	--ivy-tag-pill-bg: #f1fbfb;
	--ivy-tag-pill-text: #12afa6;
	margin: 0 0 12px;
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
}

.ivy-post-card .ivy-post-card__tags.ivy-tag-pills .ivy-tag-pill.ivy-tag-pill {
	border-radius: 4px;
}

/* Blog cards (Default style): title in Urbane, as in the design. The Text
   Only cards over a photo keep theirs. */
.wp-block-ivy-post-cards:not(.is-style-text-only) .ivy-post-card__title {
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
}

.ivy-post-card__title {
	font-family: var(--ivy-font-serif, "Adelle", Georgia, serif);
	font-weight: 700;
	font-size: 20px;
	line-height: 28px;
	color: var(--ivy-color-black, #111827);
	margin: 0 0 8px;
}

.ivy-post-card__title a {
	color: inherit;
	text-decoration: none;
}

.ivy-post-card__title a:hover,
.ivy-post-card__title a:focus-visible {
	text-decoration: underline;
}

/* Hover colour (#2379BC): shared link rules in css/buttons-links.css. */

/* Blog cards (Default style): green title link, blue on hover, as in the
   design. The hover is repeated here because this selector outweighs the
   shared one. The Text Only cards over a photo keep their dark title. */
.wp-block-ivy-post-cards:not(.is-style-text-only) .ivy-post-card__title a {
	color: var(--ivy-btn-arrow-text, #009f4c);
}

.wp-block-ivy-post-cards:not(.is-style-text-only) .ivy-post-card__title a:hover,
.wp-block-ivy-post-cards:not(.is-style-text-only) .ivy-post-card__title a:focus-visible {
	color: var(--ivy-color-blue, #2379bc);
}

.ivy-post-card__excerpt {
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
	font-weight: 300;
	font-size: 14px;
	line-height: 20px;
	color: var(--ivy-color-gray, #6b778d);
	margin: 0 0 20px;
}

/* Default style: long excerpts stop after three lines. Text Only cards keep
   their full copy. */
.wp-block-ivy-post-cards:not(.is-style-text-only) .ivy-post-card__excerpt {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	overflow: hidden;
}

/* CTA: layout and typography here; colours and hover/focus come from the
   shared Text button rules in css/buttons-links.css. */
.ivy-post-card__cta {
	margin-top: auto;
	align-self: flex-start;
	display: inline-flex;
	align-items: center;
	/* Same spacing as the core Arrow button style. */
	gap: 0.75rem;
	min-width: 120px;
	padding: 0;
	border: 0;
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
	font-weight: 600;
	font-size: 14px;
	line-height: 22px;
	letter-spacing: 1.4px;
	text-transform: uppercase;
	text-decoration: none;
}

.ivy-post-card__arrow {
	flex: none;
	width: 1rem;
	height: 1rem;
	transition: transform 150ms ease;
}

.ivy-post-card__cta:hover .ivy-post-card__arrow,
.ivy-post-card__cta:focus-visible .ivy-post-card__arrow {
	transform: translateX(3px);
}

/* ---------- Text Only style ---------- */

/* Keyed off the wrapper's is-style-* class, so switching styles in the editor
   applies instantly and Load More cards appended into the track inherit it.
   The block class is repeated in the selector to outrank the base card rules. */
.wp-block-ivy-post-cards.is-style-text-only .ivy-post-card {
	background-color: rgba(255, 255, 255, 0.5);
}

.wp-block-ivy-post-cards.is-style-text-only .ivy-post-card__media,
.wp-block-ivy-post-cards.is-style-text-only .ivy-post-card__tags {
	display: none;
}

/* With no media above it, the title starts at the top of the card. */
.wp-block-ivy-post-cards.is-style-text-only .ivy-post-card__body {
	padding-top: 0;
}

/* Text Only cards over a cover photo ("See Ivy in Action" and the same module
   on the CPT pages): frosted glass, as in the design. The card's padding is
   left to the block. */
.wp-block-cover .wp-block-ivy-post-cards.is-style-text-only .ivy-post-card {
	background-color: rgba(255, 255, 255, 0.6);
	border: 1px solid rgba(255, 255, 255, 0.7);
	border-radius: 12px;
	-webkit-backdrop-filter: blur(12px);
	backdrop-filter: blur(12px);
}

/* Body copy dark on the glass, as in the design: the default grey drops below
   readable contrast where the glass sits over the darker parts of the photo. */
.wp-block-cover .wp-block-ivy-post-cards.is-style-text-only .ivy-post-card__excerpt {
	color: var(--ivy-color-black, #111827);
}

/* A clear keyboard focus ring on the title link; the browser's thin dotted one
   is hard to see on the glass. */
.wp-block-cover .wp-block-ivy-post-cards.is-style-text-only .ivy-post-card__title a:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
	border-radius: 2px;
}

/* No blur to soften the photo behind: a more solid white keeps the text
   readable. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
	.wp-block-cover .wp-block-ivy-post-cards.is-style-text-only .ivy-post-card {
		background-color: rgba(255, 255, 255, 0.85);
	}
}

/* ---------- Mobile ---------- */

@media (max-width: 781px) {
	/* Slider off: the grid above, with a tighter gap. */
	.ivy-post-cards__track {
		--ivy-gap: 24px;
	}

	/* Slider on: one card per view with scroll snapping.

	   The track must be a real containing box or the off-screen cards widen the
	   whole layout: min-width:0 stops content-based sizing from any flex/grid
	   ancestor, max-width:100% pins it to the column, and overflow-y is declared
	   explicitly because a lone overflow-x makes the other axis compute to auto. */
	.ivy-post-cards[data-mobile-slider="true"] .ivy-post-cards__track {
		display: flex;
		grid-template-columns: none;
		gap: 16px;
		min-width: 0;
		max-width: 100%;
		overflow-x: auto;
		overflow-y: hidden;
		scroll-snap-type: x mandatory;
		scroll-behavior: smooth;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}

	/* The track clips visually, but its scrollable content still propagates into
	   every ancestor's scrollWidth, which widens the document and makes mobile
	   browsers zoom out to fit. overflow-x:clip stops that propagation without
	   creating a scroll container, and unlike `hidden` it leaves overflow-y as
	   `visible` rather than forcing it to `auto`. */
	.ivy-post-cards[data-mobile-slider="true"] {
		min-width: 0;
		max-width: 100%;
		overflow-x: clip;
	}

	.ivy-post-cards[data-mobile-slider="true"] .ivy-post-cards__track::-webkit-scrollbar {
		display: none;
	}

	/* min-width:0 keeps a long word or a wide image from inflating the card past
	   the basis, which is what makes the track wider than one card per view. */
	.ivy-post-cards[data-mobile-slider="true"] .ivy-post-card {
		flex: 0 0 100%;
		min-width: 0;
		max-width: 100%;
		scroll-snap-align: start;
	}
}

/* ---------- Slider nav ---------- */

/* Colours come from --slider-arrow / --slider-active / --slider-muted when the
   block sets them in the inspector; the fallbacks below are the original design
   values, so a block that sets nothing renders exactly as it always has. The
   variables are printed on the block wrapper by render.php, which keeps two
   blocks on one page independent. Arrow icons are inline SVG stroked with
   currentColor, so they follow the arrow colour on their own. */

/* Hidden by default so the nav can never appear on desktop, and so it is
   correct before the view script runs and inside the editor preview. */
.ivy-post-cards__nav {
	display: none;
	align-items: center;
	justify-content: center;
	gap: 16px;
	margin-top: 24px;
}

@media (max-width: 781px) {
	.ivy-post-cards[data-mobile-slider="true"] .ivy-post-cards__nav {
		display: flex;
	}
}

/* Respected if anything still sets the attribute. */
.ivy-post-cards__nav[hidden] {
	display: none;
}

/* The theme styles every bare <button> as a primary button - including
   min-width:120px and min-height:3.25rem, which override plain width/height, and
   :hover/:disabled rules at (0,1,1). These selectors are scoped to the block so
   they carry (0,2,0) / (0,3,0) and can reset all of it. */
.ivy-post-cards .ivy-post-cards__prev,
.ivy-post-cards .ivy-post-cards__next {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 36px;
	height: 36px;
	min-width: 0;
	min-height: 0;
	gap: 0;
	margin: 0;
	padding: 0;
	border: 1px solid var(--slider-arrow, #0fa58c);
	border-radius: 8px;
	background: transparent;
	color: var(--slider-arrow, #0fa58c);
	font-size: 0;
	line-height: 1;
	box-shadow: none;
	cursor: pointer;
	transition: background-color 150ms ease, color 150ms ease;
}

.ivy-post-cards .ivy-post-cards__prev:hover,
.ivy-post-cards .ivy-post-cards__next:hover,
.ivy-post-cards .ivy-post-cards__prev:focus-visible,
.ivy-post-cards .ivy-post-cards__next:focus-visible {
	background: var(--slider-arrow, #0fa58c);
	border-color: var(--slider-arrow, #0fa58c);
	color: #fff;
	opacity: 1;
}

.ivy-post-cards .ivy-post-cards__prev:focus-visible,
.ivy-post-cards .ivy-post-cards__next:focus-visible {
	outline: 2px solid var(--slider-arrow, #0fa58c);
	outline-offset: 2px;
}

.ivy-post-cards .ivy-post-cards__prev:disabled,
.ivy-post-cards .ivy-post-cards__next:disabled {
	background: transparent;
	border-color: var(--slider-arrow, #0fa58c);
	color: var(--slider-arrow, #0fa58c);
	opacity: 0.4;
	cursor: default;
}

.ivy-post-cards__progress {
	width: 60px;
	height: 4px;
	border-radius: 2px;
	background-color: var(--slider-muted, #e5e7eb);
	overflow: hidden;
}

.ivy-post-cards__progress span {
	display: block;
	height: 100%;
	width: 0;
	border-radius: 2px;
	background-color: var(--slider-active, #0fa58c);
	transition: width 150ms ease;
}

.ivy-post-cards__counter {
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
	font-weight: 600;
	font-size: 12px;
	line-height: 1;
	white-space: nowrap;
	color: var(--slider-muted, var(--ivy-color-black, #111827));
}

/* The chevrons are sized by the svg itself; font-size:0 on the button would
   otherwise collapse them in browsers that scale svg from the font size. */
.ivy-post-cards__prev svg,
.ivy-post-cards__next svg {
	width: 9px;
	height: 10px;
	flex: none;
}

/* ---------- Load More ---------- */

.ivy-post-cards__more {
	display: flex;
	justify-content: center;
	margin-top: 40px;
}

.ivy-post-cards__load-more[disabled] {
	opacity: 0.6;
	cursor: default;
}

/* The display:flex above would otherwise beat the hidden attribute. */
.ivy-post-cards__more[hidden],
.ivy-post-cards__no-results[hidden] {
	display: none;
}

/* ---------- Category Filter ---------- */

/* Dimmed while a Category Filter request is in flight. */
.ivy-post-cards[aria-busy="true"] .ivy-post-cards__track {
	opacity: 0.5;
	transition: opacity 150ms ease;
}

.ivy-post-cards__no-results {
	margin: 0;
	padding: 40px 0;
	font-family: var(--ivy-font-sans, "Urbane", sans-serif);
	font-size: 16px;
	line-height: 1.6;
	color: var(--ivy-color-gray, #6b778d);
	text-align: center;
}

@media (prefers-reduced-motion: reduce) {
	.ivy-post-cards[data-mobile-slider="true"] .ivy-post-cards__track {
		scroll-behavior: auto;
	}

	.ivy-post-card__arrow,
	.ivy-post-cards__progress span {
		transition: none;
	}

	.ivy-post-card__cta:hover .ivy-post-card__arrow,
	.ivy-post-card__cta:focus-visible .ivy-post-card__arrow {
		transform: none;
	}
}
