/**
 * Magazine Homepage Builder – Frontend Styles
 *
 * Mobile-first responsive CSS.
 *
 * @package MagazineHomepageBuilder
 * @since   1.0.0
 */

/* ─── Size-adjusted font fallbacks (CLS prevention) ── */

@font-face {
	font-family: 'Nunito Sans Fallback';
	src: local('Arial');
	size-adjust: 101%;
	ascent-override: 103%;
	descent-override: 35%;
	line-gap-override: 0%;
	font-display: swap;
}

@font-face {
	font-family: 'Open Sans Fallback';
	src: local('Arial');
	size-adjust: 105.3%;
	ascent-override: 99%;
	descent-override: 27%;
	line-gap-override: 0%;
	font-display: swap;
}

/* ─── CSS Custom Properties (overridden by inline vars) ── */

:root {
	--mhb-primary: #1e40af;
	--mhb-secondary: #f59e0b;
	--mhb-text: #1f2937;
	--mhb-bg: #ffffff;
	--mhb-spacing: 40px;
	--mhb-radius: 8px;
	--mhb-font-headings: 'Nunito Sans', 'Nunito Sans Fallback', Arial, sans-serif;
	--mhb-font-body: 'Open Sans', 'Open Sans Fallback', Arial, sans-serif;
	--mhb-spacing-top: 30px;
	--mhb-spacing-bottom: 30px;
	--mhb-grid-gap: 24px;
	--mhb-fs-hero-title: 28px;
	--mhb-fs-sidebar-title: 15px;
	--mhb-fs-grid-title: 17px;
	--mhb-fs-section-title: 24px;
	--mhb-fs-excerpt: 14px;
	--mhb-fs-meta: 13px;
	--mhb-hero-width: 55%;
	--mhb-sidebar-width: 45%;
	--mhb-hero-ratio: 16/9;
	--mhb-sidebar-image-width: 110px;
	--mhb-sidebar-image-height: 80px;
}

/* ─── Base ────────────────────────────────────── */

.mhb-homepage {
	max-width: 1120px;
	margin: 0 auto;
	padding: var(--mhb-spacing-top) 16px var(--mhb-spacing-bottom);
	font-family: var(--mhb-font-body);
	color: var(--mhb-text);
	background: var(--mhb-bg);
}

.mhb-homepage *,
.mhb-homepage *::before,
.mhb-homepage *::after {
	box-sizing: border-box;
}

.mhb-homepage a {
	color: inherit;
	text-decoration: none;
	transition: color 0.2s ease, opacity 0.2s ease;
}

.mhb-homepage a:hover {
	color: var(--mhb-primary);
}

.mhb-homepage img {
	max-width: 100%;
	height: auto;
	display: block;
}

/* ─── Section Spacing ─────────────────────────── */

.mhb-section {
	margin-bottom: var(--mhb-spacing);
	/* Contain layout to prevent cross-section CLS. */
	contain: layout style;
}

.mhb-section-title {
	font-family: var(--mhb-font-headings);
	font-size: var(--mhb-fs-section-title);
	font-weight: 700;
	margin: 0 0 20px;
	padding-bottom: 12px;
	border-bottom: 3px solid var(--mhb-primary);
	color: var(--mhb-text);
}

/* ═══════════════════════════════════════════════════
   HERO + SIDEBAR  (top area)
   ═══════════════════════════════════════════════════ */

.mhb-top-area {
	display: flex;
	flex-direction: column;
	gap: 24px;
}

/* ─── Hero Card (forced overlay) ─────────────── */

.mhb-hero {
	position: relative;
	border-radius: var(--mhb-radius);
	overflow: hidden;
}

.mhb-hero > a {
	display: block !important;
	position: relative !important;
	border-radius: inherit;
	overflow: hidden;
	color: #fff;
	isolation: isolate;
}

.mhb-hero-image {
	width: 100%;
	aspect-ratio: var(--mhb-hero-ratio);
	position: relative !important;
	overflow: hidden !important;
	background: transparent;
}

.mhb-hero-image--fallback {
	background: linear-gradient(135deg, #111827 0%, #374151 100%);
}

.mhb-hero-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block !important;
	position: absolute !important;
	inset: 0 !important;
	max-width: none !important;
	z-index: 0;
	/* No opacity transition on the hero – it must render instantly. */
	background: transparent !important;
	opacity: 1 !important;
}

.mhb-homepage .mhb-hero .mhb-hero-overlay {
	position: absolute !important;
	inset: 0 !important;
	background: linear-gradient(
		to top,
		rgba(0, 0, 0, var(--mhb-overlay-max, 0.7)) 0%,
		rgba(0, 0, 0, var(--mhb-overlay-mid, 0.4)) 45%,
		rgba(0, 0, 0, 0) 100%
	);
	pointer-events: none;
	z-index: 1;
	/* Overlay visible immediately for eager hero image. */
	opacity: 1;
}

/* For lazy-loaded images (sidebar/grid), keep the delayed overlay. */
.mhb-hero-image img.mhb-lazy + .mhb-hero-overlay {
	opacity: 0;
	transition: opacity 0.25s ease;
}

/* Keep overlay visible in no-thumbnail fallback state */
.mhb-hero-image--fallback .mhb-hero-overlay {
	opacity: 1;
}

.mhb-homepage .mhb-hero .mhb-hero-content {
	position: absolute !important;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 18px 18px 16px;
	z-index: 2;
	color: #fff !important;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 6px;
	transition: transform 0.3s ease;
	/* Prevent content from overflowing above the card. */
	max-height: 100%;
	overflow: hidden;
}

.mhb-hero-category {
	display: inline-block;
	background: rgba(255, 255, 255, 0.18);
	color: #fff;
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	padding: 4px 10px;
	border-radius: 4px;
	margin: 0;
}

.mhb-hero-title {
	font-family: var(--mhb-font-headings);
	font-size: var(--mhb-fs-hero-title);
	font-weight: 800;
	line-height: 1.2;
	margin: 0;
	color: #fff !important;
	text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.mhb-hero-excerpt {
	font-size: var(--mhb-fs-excerpt);
	line-height: 1.5;
	color: rgba(255, 255, 255, 0.9) !important;
	margin: 0;
	max-width: 72ch;
	/* Clamp to 3 lines max; prevents overflow on small screens. */
	display: -webkit-box;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mhb-hero .mhb-meta {
	color: rgba(255, 255, 255, 0.7) !important;
	gap: 10px;
	margin-top: 2px;
}

.mhb-hero a:hover .mhb-hero-title {
	color: #fff !important;
}

.mhb-hero:hover .mhb-hero-image img {
	transform: scale(1.02);
	transition: transform 0.6s ease;
}

.mhb-hero:hover .mhb-hero-content {
	transform: translateY(-2px);
}

.mhb-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	font-size: var(--mhb-fs-meta);
	color: #6b7280;
}

.mhb-meta span {
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

/* ─── Sidebar Posts (admin-controlled layout) ── */

.mhb-sidebar-posts {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.mhb-sidebar-card {
	display: flex;
	gap: 14px;
	align-items: flex-start;
	transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.mhb-sidebar-card-image {
	border-radius: var(--mhb-radius);
	overflow: hidden;
	/* Reserve space for lazy-loaded images to prevent CLS. */
	background: #f3f4f6;
}

.mhb-sidebar-card-image img {
	transition: transform 0.35s ease;
}

.mhb-sidebar-card-body {
	flex: 1;
	min-width: 0;
}

.mhb-sidebar-card-title {
	font-family: var(--mhb-font-headings);
	font-size: var(--mhb-fs-sidebar-title);
	font-weight: 700;
	line-height: 1.3;
	margin: 0 0 6px;
}

.mhb-sidebar-card-title a:hover {
	color: var(--mhb-primary);
}

.mhb-sidebar-card:hover {
	transform: translateY(-2px);
}

.mhb-sidebar-card:hover .mhb-sidebar-card-image img {
	transform: scale(1.03);
}

.mhb-sidebar-card-excerpt {
	font-size: var(--mhb-fs-excerpt);
	color: #6b7280;
	line-height: 1.4;
	margin: 0 0 4px;
	/* Clamp to 2 lines to keep sidebar cards compact. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mhb-sidebar-card .mhb-meta {
	font-size: calc(var(--mhb-fs-meta) - 1px);
}

.mhb-sidebar-layout-horizontal .mhb-sidebar-card {
	display: grid;
	grid-template-columns: var(--mhb-sidebar-image-width) minmax(0, 1fr);
	align-items: start;
}

.mhb-sidebar-layout-horizontal .mhb-sidebar-card-image {
	width: var(--mhb-sidebar-image-width);
}

.mhb-sidebar-layout-horizontal .mhb-sidebar-card-image img {
	width: var(--mhb-sidebar-image-width);
	height: var(--mhb-sidebar-image-height);
	object-fit: cover;
}

.mhb-sidebar-layout-below .mhb-sidebar-card {
	flex-direction: column;
	align-items: stretch;
}

.mhb-sidebar-layout-below .mhb-sidebar-card-image {
	width: 100%;
}

.mhb-sidebar-layout-below .mhb-sidebar-card-image img {
	width: 100%;
	height: var(--mhb-sidebar-image-height);
	object-fit: cover;
}

/* ═══════════════════════════════════════════════════
   GRID
   ═══════════════════════════════════════════════════ */

.mhb-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--mhb-grid-gap);
}

/* ─── Grid Card ───────────────────────────────── */

.mhb-grid-card {
	border-radius: var(--mhb-radius);
	overflow: hidden;
	background: #fff;
	border: 1px solid #e5e7eb;
	transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.mhb-grid-card:hover {
	box-shadow: 0 10px 22px rgba(0, 0, 0, 0.08);
	transform: translateY(-2px);
}

.mhb-grid-card-image {
	aspect-ratio: 16 / 10;
	overflow: hidden;
	/* Reserve space for lazy-loaded images to prevent CLS. */
	min-height: 0;
	background: #f3f4f6;
}

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

.mhb-grid-card:hover .mhb-grid-card-image img {
	transform: scale(1.04);
}

.mhb-grid-card-body {
	padding: 16px;
}

.mhb-grid-card-title {
	font-family: var(--mhb-font-headings);
	font-size: var(--mhb-fs-grid-title);
	font-weight: 700;
	line-height: 1.3;
	margin: 0 0 8px;
}

.mhb-grid-card-title a:hover {
	color: var(--mhb-primary);
}

.mhb-grid-card-title a {
	transition: color 0.2s ease;
}

.mhb-grid-card-excerpt {
	font-size: var(--mhb-fs-excerpt);
	color: #6b7280;
	line-height: 1.5;
	margin: 0 0 10px;
	/* Clamp to 3 lines to keep cards uniform. */
	display: -webkit-box;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mhb-grid-card .mhb-meta {
	font-size: calc(var(--mhb-fs-meta) - 1px);
}

/* ─── Pagination ──────────────────────────────── */

.mhb-pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 6px;
	margin-top: 32px;
	flex-wrap: wrap;
}

.mhb-pagination a,
.mhb-pagination span {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 38px;
	height: 38px;
	padding: 0 10px;
	border-radius: var(--mhb-radius);
	font-size: 0.9rem;
	font-weight: 500;
	border: 1px solid #d1d5db;
	background: #fff;
	color: var(--mhb-text);
	transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mhb-pagination a:hover {
	background: var(--mhb-primary);
	color: #fff;
	border-color: var(--mhb-primary);
	transform: translateY(-1px);
}

.mhb-pagination .current {
	background: var(--mhb-primary);
	color: #fff;
	border-color: var(--mhb-primary);
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE – Small mobile (≤ 479px)
   Aggressively limit excerpts so content stays inside cards.
   ═══════════════════════════════════════════════════ */

@media (max-width: 479px) {

	.mhb-hero-excerpt {
		-webkit-line-clamp: 2;
		line-clamp: 2;
		font-size: 12px;
	}

	.mhb-hero-title {
		font-size: 18px !important;
	}

	.mhb-homepage .mhb-hero .mhb-hero-content {
		padding: 12px 12px 10px;
		gap: 4px;
	}

	.mhb-hero-category {
		font-size: 0.6rem;
		padding: 2px 6px;
	}

	.mhb-sidebar-card-excerpt {
		-webkit-line-clamp: 2;
		line-clamp: 2;
		font-size: 12px;
	}

	.mhb-grid-card-excerpt {
		-webkit-line-clamp: 2;
		line-clamp: 2;
		font-size: 12px;
	}

	.mhb-grid-card-body {
		padding: 12px;
	}
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE – Mobile (≤ 599px)
   Limit hero excerpt and grid excerpts on mobile.
   ═══════════════════════════════════════════════════ */

@media (max-width: 599px) {

	.mhb-hero-excerpt {
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	.mhb-grid-card-excerpt {
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE – Tablet (≥ 600px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 600px) {

	.mhb-homepage {
		padding-left: 24px;
		padding-right: 24px;
	}

	.mhb-grid {
		grid-template-columns: repeat(2, 1fr);
	}
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE – Desktop (≥ 960px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 960px) {

	.mhb-homepage {
		padding-left: 32px;
		padding-right: 32px;
	}

	.mhb-top-area {
		flex-direction: row;
	}

	.mhb-hero {
		flex: 0 0 var(--mhb-hero-width);
		max-width: var(--mhb-hero-width);
	}

	.mhb-sidebar-posts {
		flex: 1 1 var(--mhb-sidebar-width);
		max-width: var(--mhb-sidebar-width);
		display: flex;
		gap: 16px;
	}

	/* Stretch columns to same height */
	.mhb-top-area {
		align-items: stretch;
	}

	/* ─── Height Lock: Common ─────────────────── */
	/* Full height chain: hero → a → hero-image → img (abs) so
	   the hero image always fills whatever height the container has. */
	.mhb-top-area.mhb-height-lock-ratio .mhb-hero > a,
	.mhb-top-area.mhb-height-lock-fixed .mhb-hero > a {
		height: 100%;
	}

	.mhb-top-area.mhb-height-lock-ratio .mhb-hero-image,
	.mhb-top-area.mhb-height-lock-fixed .mhb-hero-image {
		aspect-ratio: unset;
		height: 100%;
	}

	/* ─── Height Lock: Ratio Mode ─────────────── */
	/* Sidebar stretches to hero height; clips if content is taller. */
	.mhb-top-area.mhb-height-lock-ratio .mhb-sidebar-posts {
		overflow: hidden;
	}

	/* ─── Height Lock: Fixed Mode ────────────── */
	/* Both columns share a fixed pixel height set via --mhb-top-height. */
	.mhb-top-area.mhb-height-lock-fixed {
		height: var(--mhb-top-height, auto);
	}

	.mhb-top-area.mhb-height-lock-fixed .mhb-hero {
		height: var(--mhb-top-height);
	}

	.mhb-top-area.mhb-height-lock-fixed .mhb-sidebar-posts {
		height: var(--mhb-top-height);
		overflow: hidden;
	}

	.mhb-sidebar-layout-horizontal .mhb-sidebar-card-image img {
		width: var(--mhb-sidebar-image-width);
		height: var(--mhb-sidebar-image-height);
	}

	.mhb-sidebar-layout-below .mhb-sidebar-card-image img {
		height: var(--mhb-sidebar-image-height);
	}

	.mhb-hero-content {
		padding: 24px 24px 22px;
	}

	/* Grid columns follow admin setting via inline style */
	.mhb-grid.mhb-grid--cols-3 {
		grid-template-columns: repeat(3, 1fr);
	}

	.mhb-grid.mhb-grid--cols-4 {
		grid-template-columns: repeat(4, 1fr);
	}
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE – Large (≥ 1200px)
   ═══════════════════════════════════════════════════ */

@media (min-width: 1200px) {

	.mhb-hero-content {
		padding: 28px 28px 26px;
	}
}

/* ─── DRY Clamp Utilities ────────────────────── */

.mhb-clamp-2 {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mhb-clamp-3 {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* ─── Lazy-load placeholder ──────────────────── */

.mhb-lazy {
	opacity: 0;
	transition: opacity 0.4s ease;
}

.mhb-lazy.loaded {
	opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
	.mhb-homepage *,
	.mhb-homepage *::before,
	.mhb-homepage *::after {
		transition: none !important;
		animation: none !important;
	}
}

/* ─── Ad Slots ────────────────────────────────── */

.mhb-ad-slot {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 100%;
	margin: var(--mhb-spacing) 0;
	padding: 12px 0;
	overflow: hidden;
	/* Prevent ad loading from shifting content below. */
	contain: layout;
	min-height: 0;
}

.mhb-ad-slot--top {
	margin-top: 0;
}

.mhb-ad-slot--after-hero {
	margin-top: calc(var(--mhb-spacing) / 2);
}

.mhb-ad-slot--grid {
	grid-column: 1 / -1;
	margin: 8px 0;
	padding: 16px;
	background: #f9fafb;
	border-radius: var(--mhb-radius);
}

/* ─── Blocksy Theme Compatibility ────────────── */

/* Hide Blocksy's own featured image / hero section on the MHB page.
   The plugin renders its own hero; the theme's version is redundant
   and causes a duplicate LCP element with loading="lazy". */
.mhb-homepage ~ .ct-featured-image,
.ct-featured-image:has(+ .mhb-homepage),
article:has(.mhb-homepage) > .ct-featured-image,
body.page-template-mhb-homepage-template .ct-featured-image,
body.page-template-mhb-homepage-template figure.ct-featured-image {
	display: none !important;
}

.mhb-homepage .entry-content {
	max-width: none;
	padding: 0;
}

/* Override Blocksy's default page content width */
[data-page="page"] .mhb-homepage {
	max-width: 1120px;
}

/* Force top/bottom spacing even when Blocksy's .site-main or
   content-area wrappers reset padding/margin to 0. */
.mhb-homepage#mhb-homepage {
	padding-top: var(--mhb-spacing-top) !important;
	padding-bottom: var(--mhb-spacing-bottom) !important;
}

/* Blocksy wraps page content in .site-main – remove its own
   top padding so only ours applies. */
.site-main > .mhb-homepage,
.site-main > article .mhb-homepage,
.hfeed > .mhb-homepage,
.hfeed > article .mhb-homepage {
	margin-top: 0;
}

/* When Blocksy adds top spacing on the content area container */
.site-main.hfeed:has(.mhb-homepage) {
	padding-top: 0 !important;
	margin-top: 0 !important;
}

/* Blocksy content-area spacing override */
[class*="content-area"]:has(.mhb-homepage) {
	padding-top: 0 !important;
}

/* Direct body-level: if our <main> is a direct child of body
   or of Blocksy's site wrapper */
body.page-template-mhb-homepage-template .site-main,
body.page-template-mhb-homepage-template .hfeed,
body.page-template-mhb-homepage-template [class*="content-area"] {
	padding-top: 0 !important;
	margin-top: 0 !important;
}

/* ─── Screen-reader text ─────────────────────── */

.screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	position: absolute !important;
	height: 1px;
	width: 1px;
	overflow: hidden;
	word-wrap: normal !important;
}
