/*
 * HCFB styling for the Ruhler Facebook Feed plugin: the homepage "from
 * our community" section (patterns/home-social-updates.php) and the
 * /social-updates/ page (patterns/social-updates-feed.php). Enqueued only
 * on those two views (functions.php).
 *
 * The plugin prints its own feed.css in the footer, after this file, so
 * every override here is scoped under the theme's .hcfb-social-feed
 * wrapper to win on specificity rather than load order. HCFB values reach
 * the plugin through its documented --rff-* custom properties wherever
 * one exists; the plugin source itself stays brand-neutral.
 */

/* ------------------------------------------------------------------ */
/* Shared feed treatment                                                */
/* ------------------------------------------------------------------ */

.hcfb-social-feed .rff-feed {
	--rff-ink: var(--wp--preset--color--hcfb-navy);
	--rff-muted: var(--wp--preset--color--hcfb-text-muted);
	/* Navy, not orange: orange text fails contrast on the white card. */
	--rff-accent: var(--wp--preset--color--hcfb-navy);
	--rff-line: var(--wp--preset--color--hcfb-border);
	font-family: var(--wp--preset--font-family--hcfb-body);
	margin: 0;
	max-width: none;
}

.hcfb-social-feed .rff-feed__items {
	gap: var(--wp--preset--spacing--hcfb-md);
}

.hcfb-social-feed .rff-feed__card {
	background: var(--wp--preset--color--hcfb-surface);
	border-radius: 6px;
	box-shadow: none;
	transition: border-color 0.2s;
}

.hcfb-social-feed .rff-feed__card:hover {
	border-color: var(--wp--preset--color--hcfb-navy);
	box-shadow: none;
	transform: none;
}

/* Text-only posts (no image from Meta, or one that failed to load) keep their
 * natural height instead of stretching to a photo card's height in the same row,
 * which left a large blank gap above the link. Photo cards are unaffected. */
.hcfb-social-feed .rff-feed__card--no-media {
	align-self: start;
}

/* Ratio on the image, not the wrapper: the plugin's wrapper aspect-ratio
 * lets a portrait photo grow its card's media taller than its neighbors'. */
.hcfb-social-feed .rff-feed__media {
	aspect-ratio: auto;
	background: var(--wp--preset--color--hcfb-cream);
}

.hcfb-social-feed .rff-feed__media img {
	aspect-ratio: 16 / 10;
	height: auto;
}

.hcfb-social-feed .rff-feed__video {
	background: var(--wp--preset--color--hcfb-navy);
}

.hcfb-social-feed .rff-feed__fbmark {
	background: var(--wp--preset--color--hcfb-navy);
}

.hcfb-social-feed .rff-feed__meta strong {
	font-weight: 700;
}

/* The shortcode's excerpt="" word limit already bounds length, so show the
 * whole excerpt instead of the plugin's five-line clamp. */
.hcfb-social-feed .rff-feed__message {
	display: block;
	-webkit-line-clamp: unset;
	color: var(--wp--preset--color--hcfb-text);
}

.hcfb-social-feed .rff-feed__read {
	font-weight: 700;
}

.hcfb-social-feed .rff-feed a:focus-visible {
	outline: 3px solid var(--wp--preset--color--hcfb-focus);
	outline-offset: 3px;
}

.hcfb-social-feed .rff-feed__empty {
	background: var(--wp--preset--color--hcfb-surface);
	border: 1px solid var(--wp--preset--color--hcfb-border);
	border-radius: 6px;
}

/* Same pill as the homepage "view all" link (home.css). */
.hcfb-home-social__view-all,
.hcfb-social-updates__follow-link {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	background: var(--wp--preset--color--hcfb-orange);
	color: var(--wp--preset--color--hcfb-navy);
	font-weight: 700;
	padding: 0.6rem 1.5rem;
	border-radius: 999px;
	text-decoration: none;
}

.hcfb-home-social__view-all:focus-visible,
.hcfb-social-updates__follow-link:focus-visible {
	outline: 3px solid var(--wp--preset--color--hcfb-focus);
	outline-offset: 3px;
}

/* ------------------------------------------------------------------ */
/* Homepage section                                                     */
/* ------------------------------------------------------------------ */

body.home .hcfb-home-social,
body.home .hcfb-home-social * {
	box-sizing: border-box;
}

/* Cream band: separates it from white What's Happening above; Get in
 * Touch's own green top border separates it from the cream band below. */
body.home .hcfb-home-social {
	max-width: none;
	width: 100%;
	background: var(--wp--preset--color--hcfb-cream);
	padding: var(--wp--preset--spacing--hcfb-xl) 0;
}

body.home .hcfb-home-social__inner {
	max-width: var(--hcfb-home-wide);
	margin-inline: auto;
	padding-inline: var(--wp--preset--spacing--hcfb-md);
}

body.home .hcfb-home-social__heading {
	color: var(--wp--preset--color--hcfb-navy);
	font-size: clamp(2rem, 1.5rem + 2.2vw, 3.25rem);
	margin: 0 0 0.5rem;
}

body.home .hcfb-home-social__copy {
	color: var(--wp--preset--color--hcfb-text);
	margin: 0 0 var(--wp--preset--spacing--hcfb-lg);
}

body.home .hcfb-home-social__view-all {
	margin-top: var(--wp--preset--spacing--hcfb-lg);
}

/* Three cards: stack rather than leave a 2 + 1 orphan at tablet widths. */
@media (max-width: 900px) {
	.hcfb-social-feed--home .rff-feed:not(.rff-feed--list) .rff-feed__items {
		grid-template-columns: 1fr;
	}
}

/*
 * Homepage layout. Posts always stay in chronological order (visual = DOM = keyboard
 * order 1 -> 2 -> 3); nothing is reordered for images.
 *  - Default (641px and up): a compact chronological list. Text-only posts sit at
 *    natural height with no image area; photo posts are horizontal cards.
 *  - Desktop, when the NEWEST post has a photo: that post is featured on the left and
 *    posts 2 and 3 stack on the right (CSS :has() checks post 1 only, it never moves
 *    posts). Browsers without :has() keep the compact list.
 * Images are always shown whole on cream (object-fit: contain): no face is cropped and
 * no JavaScript is needed.
 */
.hcfb-social-feed--home .rff-feed__media img {
	aspect-ratio: 4 / 3;
	object-fit: contain;
}

@media (min-width: 641px) {
	.hcfb-social-feed--home .rff-feed:not(.rff-feed--list) .rff-feed__items {
		grid-template-columns: 1fr;
	}

	.hcfb-social-feed--home .rff-feed__card:not(.rff-feed__card--no-media) {
		display: grid;
		grid-template-columns: minmax(10rem, 28%) 1fr;
		align-items: start;
	}

	.hcfb-social-feed--home .rff-feed__message {
		max-width: 68ch;
	}
}

@media (min-width: 901px) {
	.hcfb-social-feed--home .rff-feed__items:has(> .rff-feed__card:first-child:not(.rff-feed__card--no-media)) {
		grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
		/* Extra height from the tall featured card goes below post 3, not between 2 and 3. */
		grid-template-rows: auto 1fr;
		align-items: start;
	}

	.hcfb-social-feed--home .rff-feed__items:has(> .rff-feed__card:first-child:not(.rff-feed__card--no-media)) > .rff-feed__card:first-child {
		grid-row: span 2;
		display: flex;
		flex-direction: column;
	}

	.hcfb-social-feed--home .rff-feed__items:has(> .rff-feed__card:first-child:not(.rff-feed__card--no-media)) > .rff-feed__card:first-child .rff-feed__media img {
		aspect-ratio: 16 / 10;
	}

	.hcfb-social-feed--home .rff-feed__items:has(> .rff-feed__card:first-child:not(.rff-feed__card--no-media)) > .rff-feed__card:not(:first-child):not(.rff-feed__card--no-media) {
		grid-template-columns: minmax(8rem, 38%) 1fr;
	}

	/* Newest post is text-only: posts 1 and 2 side by side (equal height), post 3 full
	 * width beneath them. Order stays 1 -> 2 -> 3; a photo post in the top row stays a
	 * compact horizontal card so the row is balanced. */
	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card--no-media:first-child) {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card--no-media:first-child) > .rff-feed__card:nth-child(-n+2) {
		align-self: stretch;
	}

	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card--no-media:first-child) > .rff-feed__card:not(.rff-feed__card--no-media):nth-child(-n+2) {
		grid-template-columns: minmax(8rem, 38%) 1fr;
	}

	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card--no-media:first-child) > .rff-feed__card:nth-child(3) {
		grid-column: 1 / -1;
	}

	/* All three text-only: three equal compact cards in one row. */
	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card:nth-child(3)):not(:has(> .rff-feed__card:not(.rff-feed__card--no-media))) {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.hcfb-social-feed--home .rff-feed .rff-feed__items:has(> .rff-feed__card:nth-child(3)):not(:has(> .rff-feed__card:not(.rff-feed__card--no-media))) > .rff-feed__card {
		grid-column: auto;
		align-self: stretch;
	}

	/* A lone post uses the full width instead of leaving the right column empty. */
	.hcfb-social-feed--home .rff-feed__items > .rff-feed__card:only-child {
		grid-column: 1 / -1;
		grid-row: auto;
	}
}

/* ------------------------------------------------------------------ */
/* /social-updates/ page                                                */
/* ------------------------------------------------------------------ */

main .hcfb-social-updates {
	max-width: 63rem;
	margin: var(--wp--preset--spacing--hcfb-lg) auto var(--wp--preset--spacing--hcfb-xl);
}

/* Heading and introduction, only on a page that contains this section (the page has
 * no slug body class; :has() keeps it explicit, and older browsers keep the default). */
/* Breadcrumbs, heading and introduction share the feed's left edge and width. */
#hcfb-primary-content:has(> .hcfb-social-updates) > :is(.hcfb-breadcrumbs, .wp-block-post-title, .wp-block-post-content) {
	max-width: 63rem;
}

#hcfb-primary-content:has(> .hcfb-social-updates) > .wp-block-post-title {
	color: var(--wp--preset--color--hcfb-navy);
	font-size: clamp(2.25rem, 1.75rem + 2vw, 3.25rem);
	line-height: 1.1;
	margin-bottom: var(--wp--preset--spacing--hcfb-md);
}

/* Short decorative brand rule under the heading (no text, skipped by screen readers). */
#hcfb-primary-content:has(> .hcfb-social-updates) > .wp-block-post-title::after {
	content: "";
	display: block;
	width: 3.5rem;
	height: 4px;
	margin-top: 0.85rem;
	border-radius: 2px;
	background: var(--wp--preset--color--hcfb-orange);
}

#hcfb-primary-content:has(> .hcfb-social-updates) > .wp-block-post-content p {
	color: var(--wp--preset--color--hcfb-navy);
	font-size: clamp(1.1rem, 1rem + 0.4vw, 1.3rem);
	font-weight: 500;
	line-height: 1.6;
	max-width: 46rem;
}

/*
 * One chronological column: visual order = reading order = DOM order, so any mix of
 * photo and text-only posts lays out with no gaps, spans or reordering. A full-width
 * "text strip" inside a 3-column grid was rejected: a text post that follows an
 * unfinished photo row would leave empty cells, and dense packing would reorder posts.
 */
.hcfb-social-feed--page .rff-feed:not(.rff-feed--list) .rff-feed__items {
	grid-template-columns: 1fr;
	gap: var(--wp--preset--spacing--hcfb-md);
}

/* Photo posts: horizontal card, fixed-ratio image left (same size on every card). */
@media (min-width: 641px) {
	.hcfb-social-feed--page .rff-feed__card:not(.rff-feed__card--no-media) {
		display: grid;
		grid-template-columns: minmax(12rem, 33%) 1fr;
		align-items: start;
	}
}

/*
 * Image framing: every photo gets the same 4:3 box. Default is the WHOLE image on
 * cream (no cropping, no distortion). assets/js/social-updates-framing.js adds
 * .hcfb-fit-crop only when filling the box would remove at most 12% of the image;
 * that crop is top-weighted. It uses image dimensions only -- nothing here detects
 * faces -- so portraits, squares and very wide images always stay whole.
 */
.hcfb-social-feed--page .rff-feed__media img {
	aspect-ratio: 4 / 3;
	object-fit: contain;
	object-position: 50% 50%;
}

.hcfb-social-feed--page .rff-feed__media img.hcfb-fit-crop {
	object-fit: cover;
	object-position: 50% 25%;
}

/* Readability: slightly larger text, comfortable line length, clearer link spacing. */
.hcfb-social-feed--page .rff-feed__message {
	font-size: 1rem;
	line-height: 1.65;
	max-width: 68ch;
	margin: 0.75rem 0 1rem;
}

.hcfb-social-feed--page .rff-feed__read {
	padding-block: 0.15rem;
}

/* Post date: full text colour (was the muted grey) and a little larger. */
.hcfb-social-feed--page .rff-feed__meta time {
	color: var(--wp--preset--color--hcfb-text);
	font-size: 0.85rem;
	font-weight: 500;
}

/* Cards: softer corners, quiet border, restrained hover and keyboard-focus highlight
 * (the 3px link focus outline above still applies). */
.hcfb-social-feed--page .rff-feed__card {
	border-radius: 8px;
	border-color: var(--wp--preset--color--hcfb-border);
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.hcfb-social-feed--page .rff-feed__card:hover,
.hcfb-social-feed--page .rff-feed__card:focus-within {
	border-color: var(--wp--preset--color--hcfb-navy);
	box-shadow: 0 2px 10px rgb(38 39 96 / 0.08);
}

@media (min-width: 641px) {
	.hcfb-social-feed--page .rff-feed__body {
		padding: 1.25rem 1.5rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hcfb-social-feed .rff-feed__card {
		transition: none;
	}
}

.hcfb-social-updates__follow {
	margin: var(--wp--preset--spacing--hcfb-xl) 0 0;
}
