/**
 * Maya Popular Posts Widget Styles
 *
 * Desktop/Tablet: Two-column layout with featured post on left (RTL) and 2x2 grid on right.
 * Featured post has solid beige background with text content.
 * Small cards: Image on top, title below, button at bottom (vertically stacked, centered).
 * Mobile: Swiper carousel with peek effect.
 *
 * @package MayaPlugin
 */

/* ==========================================================================
	CSS Variables
	========================================================================== */

.mw-pp-wrapper {
	--mw-pp-gap: 24px;
	--mw-pp-peek: 40px;
	--mw-pp-featured-bg: #F5EEE7;
	--mw-pp-text-color: #5E4E40;
	--mw-pp-button-color: #CD9C71;
}

/* ==========================================================================
	Wrapper
	========================================================================== */

.mw-pp-wrapper {
	width: 100%;
	position: relative;
	overflow: visible;
}

/* ==========================================================================
	Desktop Grid Layout - Two Columns
	========================================================================== */

.mw-pp-grid {
	display: grid;
	grid-template-columns: 1fr 1.8fr;
	gap: var(--mw-pp-gap);
	width: 100%;
	align-items: stretch;
}

/* RTL: Featured on left visually (DOM order first), small-grid on right */
[dir="rtl"] .mw-pp-grid,
.rtl .mw-pp-grid {
	grid-template-columns: 1.8fr 1fr;
}

/* ==========================================================================
	Featured Card (Main Post) - With Background Image
	========================================================================== */

.mw-pp-featured {
	position: relative;
	background-color: var(--mw-pp-featured-bg);
	border-radius: 30px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding: 40px 30px;
	min-height: 450px;
	text-align: center;
	overflow: visible;
}

/* Featured Background Image Wrapper - clips image to border-radius */
.mw-pp-featured__image-wrapper {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border-radius: 30px;
	overflow: hidden;
	z-index: 1;
}

/* Featured Background Image */
.mw-pp-featured__image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0.15;
}

.mw-pp-featured__content {
	position: relative;
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 20px;
	max-width: 100%;
}

.mw-pp-featured__subtitle {
	font-size: 18px;
	font-weight: 400;
	line-height: 1.6;
	color: var(--mw-pp-text-color);
}

.mw-pp-featured__title {
	font-size: 32px;
	font-weight: 500;
	line-height: 1.3;
	color: var(--mw-pp-text-color);
	margin: 0;
	padding: 0;
}

/* ==========================================================================
	Circular Badge - Positioned on Featured Card (top-right corner)
	========================================================================== */

.mw-pp-badge {
	position: absolute;
	top: -20px;
	width: 100px;
	height: 100px;
	background-color: var(--mw-pp-button-color);
	border-radius: 50%;
	border: 4px solid #FEFBF6;
	display: flex;
	align-items: center;
	justify-content: center;
	transform: rotate(-25deg);
	z-index: 10;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	/* Always on right side of featured card */
	right: -20px;
	left: auto;
}

.mw-pp-badge__text {
	font-size: 20px;
	font-weight: 500;
	color: #FFFFFF;
	text-align: center;
	line-height: 1.2;
}

/* ==========================================================================
	Small Cards Grid (2x2)
	========================================================================== */

.mw-pp-small-grid {
	--mw-pp-button-align: 0; /* Default: no alignment, set to 1 to enable */
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-rows: 1fr 1fr;
	gap: var(--mw-pp-gap);
}

/* ==========================================================================
	Small Cards
	========================================================================== */

.mw-pp-small {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	text-align: center;
}

.mw-pp-small__link {
	display: block;
	text-decoration: none;
	width: 100%;
}

.mw-pp-small__image-wrapper {
	width: 100%;
	aspect-ratio: 297 / 228;
	border-radius: 20px;
	overflow: hidden;
	background-color: #f5f5f5;
}

.mw-pp-small__image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.3s ease;
}

.mw-pp-small__link:hover .mw-pp-small__image {
	transform: scale(1.05);
}

/* Bottom row - title and button container */
.mw-pp-small__bottom-row {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	width: 100%;
	/* When button alignment is enabled, expand to fill remaining card space */
	flex: var(--mw-pp-button-align, 0) 1 auto;
}

.mw-pp-small__title {
	font-size: 18px;
	font-weight: 400;
	line-height: 1.4;
	color: #000000;
	margin: 0;
	padding: 0 10px;
	order: -1; /* Title above button on desktop */
	/* When button alignment is enabled, title grows to push button down */
	flex-grow: var(--mw-pp-button-align, 0);
}

/* ==========================================================================
	Button Styles
	========================================================================== */

.mw-pp-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 10px 40px;
	background-color: var(--mw-pp-button-color);
	color: #FFFFFF;
	font-size: 14px;
	font-weight: 500;
	text-decoration: none;
	border-radius: 38px;
	transition: background-color 0.2s ease, transform 0.2s ease;
	white-space: nowrap;
	box-shadow: 0 8px 20px rgba(48, 38, 34, 0.15);
}

.mw-pp-button:hover {
	background-color: #B8885C;
}

.mw-pp-button:focus {
	outline: none;
}

.mw-pp-button:focus-visible {
	outline: 2px solid var(--mw-pp-button-color);
	outline-offset: 2px;
}

.mw-pp-button:active {
	transform: scale(0.98);
}

/* Featured Card Button */
.mw-pp-button--featured {
	padding: 12px 60px;
	margin-top: 10px;
}

/* Small Card Button */
.mw-pp-button--small {
	padding: 8px 30px;
	font-size: 13px;
}

/* ==========================================================================
	Mobile Carousel (Hidden on Desktop)
	========================================================================== */

.mw-pp-carousel {
	display: none;
}

/* ==========================================================================
	Empty Notice (Editor Only)
	========================================================================== */

.mw-pp-empty-notice {
	padding: 40px 20px;
	text-align: center;
	background: #f5f5f5;
	border: 2px dashed #ddd;
	border-radius: 8px;
	color: #666;
}

.mw-pp-empty-notice p {
	margin: 0;
	font-size: 14px;
}

/* ==========================================================================
	Tablet Adjustments (768px - 1024px)
	========================================================================== */

@media screen and (min-width: 768px) and (max-width: 1024px) {
	/* Single column layout: featured on top, small-grid below */
	.mw-pp-grid {
		display: flex;
		flex-direction: column;
		gap: 24px;
	}

	[dir="rtl"] .mw-pp-grid,
	.rtl .mw-pp-grid {
		grid-template-columns: unset;
	}

	/* Featured post: full width with visible background image */
	.mw-pp-featured {
		width: 100%;
		height: 330px;
		min-height: unset;
		padding: 30px 20px;
		border-radius: 20px;
	}

	.mw-pp-featured__image {
		opacity: 1;
	}

	.mw-pp-featured__image-wrapper::after {
		content: "";
		position: absolute;
		inset: 0;
		background: rgba(0, 0, 0, 0.25);
		border-radius: 20px;
	}

	.mw-pp-featured__content {
		color: #FFFFFF;
	}

	.mw-pp-featured__subtitle {
		font-size: 16px;
		color: #FFFFFF;
	}

	.mw-pp-featured__title {
		font-size: 24px;
		color: #FFFFFF;
	}

	/* Hide badge on tablet */
	.mw-pp-badge {
		display: none;
	}

	/* Small cards grid - 2x2 */
	.mw-pp-small-grid {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 20px;
	}

	/* Small card layout: image then [button | title] row */
	.mw-pp-small {
		flex-direction: column;
		align-items: stretch;
		gap: 10px;
	}

	.mw-pp-small__image-wrapper {
		width: 100%;
		height: 180px;
		aspect-ratio: unset;
		border-radius: 20px;
	}

	/* Button and title in a row - reset alignment styles */
	.mw-pp-small__bottom-row {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		gap: 10px;
		flex: 0 1 auto; /* Reset - don't grow on tablet */
	}

	.mw-pp-small__title {
		font-size: 16px;
		text-align: right;
		flex: 1;
		padding: 0;
		flex-grow: 1; /* Reset - grow to fill row space */
	}

	.mw-pp-button--small {
		padding: 8px 24px;
		font-size: 13px;
		flex-shrink: 0;
	}
}

/* ==========================================================================
	Mobile Styles (< 768px)
	========================================================================== */

@media screen and (max-width: 767px) {
	/* Hide grid, show carousel */
	.mw-pp-grid {
		display: none !important;
	}

	.mw-pp-carousel {
		display: block !important;
	}

	/* Swiper Container - ensure horizontal slider */
	.mw-pp-swiper {
		overflow: hidden;
		position: relative;
		width: 100%;
		margin: 0 auto;
	}

	.mw-pp-swiper .swiper-wrapper {
		display: flex !important;
		flex-wrap: nowrap !important;
		flex-direction: row !important;
		align-items: stretch;
	}

	.mw-pp-swiper .swiper-slide {
		flex-shrink: 0 !important;
		height: auto;
	}

	/* Mobile Card - image on top, content below */
	.mw-pp-mobile-card {
		display: flex;
		flex-direction: column;
		background-color: transparent;
		border-radius: 20px;
		overflow: visible;
	}

	/* Image wrapper - rounded corners */
	.mw-pp-mobile-card__image-wrapper {
		width: 100%;
		height: 300px;
		overflow: hidden;
		border-radius: 20px;
		flex-shrink: 0;
	}

	.mw-pp-mobile-card__image {
		width: 100%;
		height: 100%;
		object-fit: cover;
		display: block;
	}

	/* Hide the overlay - not needed in new design */
	.mw-pp-mobile-card__overlay {
		display: none;
	}

	/* Content area - title above, button below (vertical stack) */
	.mw-pp-mobile-card__content {
		padding: 16px 10px;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 12px;
		background-color: transparent;
	}

	.mw-pp-mobile-card__title {
		font-size: 18px;
		font-weight: 500;
		line-height: 1.4;
		color: #302622;
		margin: 0;
		text-align: right;
		width: 100%;
		/* Min height for ~2 lines to prevent pagination overlap on long titles */
		min-height: calc(2 * 1.4em); /* 2 lines × line-height */
	}

	/* Mobile Button */
	.mw-pp-carousel .mw-pp-button {
		padding: 7px 50px;
		font-size: 16px;
		background-color: var(--mw-pp-button-color);
		color: #FFFFFF;
		border-radius: 50px;
		box-shadow: 0 15px 30px 0 rgba(48, 38, 34, 0.15);
	}

	/* Pagination Dots */
	.mw-pp-pagination {
		display: flex !important;
		justify-content: center;
		align-items: center;
		margin-top: 20px;
		gap: 8px;
		position: relative;
		z-index: 10;
		width: 100%;
		min-height: 20px;
	}

	.mw-pp-pagination .swiper-pagination-bullet,
	.mw-pp-pagination span {
		width: 10px;
		height: 10px;
		border-radius: 50%;
		background-color: rgba(0, 0, 0, 0.2);
		opacity: 1;
		transition: background-color 0.2s ease, transform 0.2s ease;
		display: inline-block;
		cursor: pointer;
	}

	.mw-pp-pagination .swiper-pagination-bullet-active {
		background-color: var(--mw-pp-button-color);
		transform: scale(1.2);
	}
}

/* ==========================================================================
	Accessibility - Reduced Motion
	========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.mw-pp-small__image,
	.mw-pp-button,
	.mw-pp-pagination .swiper-pagination-bullet {
		transition: none;
	}

	.mw-pp-small__link:hover .mw-pp-small__image {
		transform: none;
	}

	.mw-pp-button:active {
		transform: none;
	}

	.mw-pp-pagination .swiper-pagination-bullet-active {
		transform: none;
	}
}

/* ==========================================================================
	Print Styles
	========================================================================== */

@media print {
	.mw-pp-carousel {
		display: none !important;
	}

	.mw-pp-grid {
		display: grid !important;
	}

	.mw-pp-button {
		display: none;
	}

	.mw-pp-badge {
		display: none;
	}
}
