/**
 * Google Reviews Block - Carousel Styles CSS
 *
 * CSS-only carousel using native scroll-button and scroll-marker-group
 * Compatible with Block Editor and frontend
 *
 * @package GoogleReviewsBlock
 * @version 1.0.0
 */

/* ==========================================================================
   VARIABLES CSS
   ========================================================================== */

:root {
	--google-reviews-carousel-button-size: 2.8rem;
	--google-reviews-carousel-button-offset: 0px;
	--google-reviews-carousel-marker-size: 0.66rem;
	--google-reviews-carousel-marker-gap: 0.5rem;
	--google-reviews-carousel-marker-bottom-offset: -2rem;
	--google-reviews-carousel-z-index: 5;
	--google-reviews-carousel-transition-duration: 0.3s;
	--google-reviews-carousel-transition-easing: cubic-bezier(0.4, 0, 0.2, 1);

	/* Colors */
	--google-reviews-carousel-button-bg: #007cba;
	--google-reviews-carousel-button-color: #fff;
	--google-reviews-carousel-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

	/* Carousel padding */
	--google-reviews-carousel-padding-left: 0px;
	--google-reviews-carousel-padding-right: 0px;
	--google-reviews-carousel-padding-top: 0px;
	--google-reviews-carousel-padding-bottom: 0px;
}

/* ==========================================================================
   CAROUSEL PRINCIPAL
   ========================================================================== */

/* Force every parent containing a carousel to use position: relative */
:has(.google-reviews-carousel) {
	position: relative !important;
}

.google-reviews-carousel {
	position: relative !important;
}

/* Ensure the direct parent is also positioned relative */
*:has(> .google-reviews-carousel) {
	position: relative !important;
	overflow: visible;
	max-width: 100%;
	box-sizing: border-box;
}

/* Main carousel styles */
.google-reviews-carousel,
.block-editor-block-list__layout .google-reviews-carousel,
.editor-styles-wrapper .google-reviews-carousel {
	position: relative !important;
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
	display: flex;
	flex-flow: row nowrap;
	align-items: stretch;
	justify-content: flex-start;
	gap: var(--wp--style--block-gap, 1.5rem);
	padding: 1rem 0px;

	overflow-x: scroll;
	overflow-y: visible;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;

	scroll-padding-left: var(--google-reviews-carousel-scroll-padding-left, 0);
	scroll-padding-right: var(--google-reviews-carousel-scroll-padding-right, 0);

	-ms-overflow-style: none;
	scrollbar-width: none;
	-webkit-scrollbar: none;

	scroll-marker-group: after;

	isolation: isolate;
	contain: layout !important;
	transform: translateZ(0);
}

.google-reviews-carousel::-webkit-scrollbar {
	display: none;
}

/* ==========================================================================
   CAROUSEL ITEMS (SLIDES)
   ========================================================================== */

/* All direct children of .google-reviews-carousel are slides */
.google-reviews-carousel>.google-reviews-rating,
.google-reviews-carousel>.google-review-item {
	flex: 0 0 auto;
	min-width: 320px;
	max-width: 320px;
	width: 100%;
	scroll-snap-align: start;
	scroll-snap-stop: always;
}

/* ==========================================================================
   REVIEW ITEMS STYLES
   ========================================================================== */

.google-reviews-block {
	width: 100%;
}

.google-reviews-rating {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 1.125rem;
}

/* In grid layout, rating is not a slide */
.google-reviews-grid .google-reviews-rating {
	margin-bottom: 1.5rem;
}

/* In carousel, rating is a slide like others */
.google-reviews-carousel .google-reviews-rating {
	padding: 1.5rem;
	justify-content: center;
}

.google-reviews-rating .rating-value {
	font-weight: 700;
	font-size: 1.5rem;
}

.google-reviews-rating .rating-stars {
	color: #ffa500;
	font-size: 1.25rem;
	line-height: 1;
}

.google-reviews-rating .rating-count {
	font-size: 0.875rem;
}

/* Grid layout: wrap rating and items in a container */
.google-reviews-grid {
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

.google-reviews-grid>.google-review-item {
	display: block;
}

/* Grid layout: items are already styled, no additional rules needed */

.google-review-item {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	padding: 1.5rem;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
	transition: box-shadow 0.3s ease;
}

.google-review-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 0.75rem;
	gap: 1rem;
}

.google-review-avatar {
	width: 48px;
	height: 48px;
	border-radius: 50%;
	overflow: hidden;
	margin-bottom: 0.75rem;
	flex-shrink: 0;
}

.google-review-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.google-review-content {
	flex: 1;
}

.google-review-author {
	margin: 0 0 0.25rem 0;
	font-size: 1rem;
	font-weight: 600;
}

.google-review-stars {
	color: #ffa500;
	font-size: 1rem;
	line-height: 1;
	white-space: nowrap;
}

.google-review-stars .star {
	display: inline-block;
}

.google-review-stars .star-full {
	color: #ffa500;
}

.google-review-stars .star-half {
	color: #ffa500;
	opacity: 0.5;
}

.google-review-stars .star-empty {
	color: #ddd;
}

.google-review-date {
	font-size: 0.875rem;
	margin-bottom: 0.75rem;
}

.google-review-text {
	font-size: 0.9375rem;
	line-height: 1.6;
	margin-top: 0.5rem;
	margin-bottom: 0.5rem;
	word-break: break-word;
	overflow-wrap: anywhere;
	display: -webkit-box;
	-webkit-line-clamp: 10;
	-webkit-box-orient: vertical;
	overflow: hidden;
	max-height: calc(1.6em * 10);
}

.google-reviews-block-error {
	padding: 1rem;
	background: #fff3cd;
	border: 1px solid #ffc107;
	border-radius: 4px;
	color: #856404;
}

/* ==========================================================================
   BOUTONS DE NAVIGATION (CSS natif)
   ========================================================================== */

/* Fallback : indicateur de pagination pour navigateurs non compatibles */
:has(> .google-reviews-carousel)::after {
	content: '';
	position: absolute;
	z-index: calc(var(--google-reviews-carousel-z-index, 999999) - 1);
	left: var(--google-reviews-carousel-padding-left, 0px);
	bottom: calc(var(--google-reviews-carousel-marker-bottom-offset, -2rem) + var(--google-reviews-carousel-padding-bottom, 0px));
	transform: translate(0, 100%);
	display: block;
	width: var(--google-reviews-carousel-marker-size, 0.66rem);
	height: var(--google-reviews-carousel-marker-size, 0.66rem);
	pointer-events: none;
	color: var(--google-reviews-carousel-button-bg, #007cba);
	opacity: 0.55;
	border-radius: 999px;
	background-color: currentColor;
	box-shadow:
		calc(var(--google-reviews-carousel-marker-size, 0.66rem) + var(--google-reviews-carousel-marker-gap, 0.5rem)) 0 0 currentColor,
		calc(2 * (var(--google-reviews-carousel-marker-size, 0.66rem) + var(--google-reviews-carousel-marker-gap, 0.5rem))) 0 0 currentColor;
	filter: drop-shadow(var(--google-reviews-carousel-shadow, 0 2px 8px rgba(0, 0, 0, 0.1)));
	transition: opacity var(--google-reviews-carousel-transition-duration, 0.3s) var(--google-reviews-carousel-transition-easing, cubic-bezier(0.4, 0, 0.2, 1));
}

:has(> .google-reviews-carousel)::hover::after {
	opacity: 0.75;
}

/* Sur les navigateurs compatibles, masquer les fallbacks et afficher les vrais boutons */
@supports selector(::scroll-button(*)) {
	:has(> .google-reviews-carousel)::after {
		display: none;
	}

	.google-reviews-carousel::scroll-button(*) {
		position: absolute;
		z-index: var(--google-reviews-carousel-z-index);
		top: 50%;
		width: var(--google-reviews-carousel-button-size);
		height: var(--google-reviews-carousel-button-size);
		line-height: 1em;
		border-radius: 100rem;
		background-color: var(--google-reviews-carousel-button-bg);
		border: 2px solid var(--google-reviews-carousel-button-bg);
		color: var(--google-reviews-carousel-button-color);
		opacity: 1;
		visibility: visible;
		cursor: pointer;
		text-align: center;
		display: inline-block;
		box-shadow: var(--google-reviews-carousel-shadow);
		transition: all var(--google-reviews-carousel-transition-duration) var(--google-reviews-carousel-transition-easing);
		font-size: 0px;
		overflow: hidden;
		left: auto;
		right: auto;
	}

	.google-reviews-carousel::scroll-button(*):hover {
		box-shadow: var(--google-reviews-carousel-shadow), 0 6px 20px rgba(0, 0, 0, 0.2);
		background-color: var(--google-reviews-carousel-button-bg);
		filter: brightness(1.1);
	}

	.google-reviews-carousel::scroll-button(*):disabled {
		opacity: 0;
		visibility: hidden;
		pointer-events: none;
		cursor: default;
	}

	.google-reviews-carousel::scroll-button(left) {
		left: calc(var(--google-reviews-carousel-padding-left, 0px) + var(--google-reviews-carousel-button-offset, 0px));
		content: '';
		transform: translate(-50%, -50%);
		background-image: var(--google-reviews-carousel-button-arrow-left, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'%3E%3Cpath fill='white' d='M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z'/%3E%3C/svg%3E"));
		background-repeat: no-repeat;
		background-position: center;
		background-size: 50% 50%;
	}

	.google-reviews-carousel::scroll-button(right) {
		right: calc(var(--google-reviews-carousel-padding-right, 0px) + var(--google-reviews-carousel-button-offset, 0px));
		left: auto;
		content: '';
		transform: translate(50%, -50%);
		background-image: var(--google-reviews-carousel-button-arrow-right, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'%3E%3Cpath fill='white' d='M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z'/%3E%3C/svg%3E"));
		background-repeat: no-repeat;
		background-position: center;
		background-size: 50% 50%;
	}
}

/* ==========================================================================
   MARQUEURS DE SCROLL (CSS natif)
   ========================================================================== */

@supports selector(::scroll-marker-group) {
	:has(> .google-reviews-carousel)::after {
		display: none;
	}

	.google-reviews-carousel::scroll-marker-group {
		position: absolute;
		z-index: var(--google-reviews-carousel-z-index);
		bottom: calc(var(--google-reviews-carousel-marker-bottom-offset) + var(--google-reviews-carousel-padding-bottom, 1rem));
		left: var(--google-reviews-carousel-padding-left, 0);
		display: flex;
		justify-content: center;
		gap: var(--google-reviews-carousel-marker-gap);
		transform: translate(0, 100%);
		transition: opacity var(--google-reviews-carousel-transition-duration) var(--google-reviews-carousel-transition-easing);
	}
}

@supports selector(::scroll-marker) {
	.google-reviews-carousel .google-review-item::scroll-marker {
		position: relative;
		content: '';
		width: var(--google-reviews-carousel-marker-size);
		height: var(--google-reviews-carousel-marker-size);
		background: var(--google-reviews-carousel-button-bg);
		border-radius: 50%;
		opacity: 0.5;
		box-shadow: var(--google-reviews-carousel-shadow);
		transition: opacity var(--google-reviews-carousel-transition-duration) var(--google-reviews-carousel-transition-easing);
		cursor: pointer;
	}

	.google-reviews-carousel .google-review-item::scroll-marker:hover {
		opacity: 0.75;
	}

	.google-reviews-carousel .google-review-item::scroll-marker:target-current {
		opacity: 1;
		cursor: default;
	}
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 600px) {

	.google-reviews-carousel>.google-reviews-rating,
	.google-reviews-carousel>.google-review-item {
		min-width: 100%;
		max-width: 100%;
		width: 100%;
	}
}