/*
 * RahkarTheme — product-reviews.css
 *
 * Loaded ONLY on is_product() pages where the reviews section will render
 * (see enqueue.php feature registry: 'product-reviews'). Zero bytes
 * elsewhere.
 *
 * Layout strategy:
 *   desktop  →  two-column body: cards list on the right, summary card on
 *               the left (RTL flips this: visually summary is top-right of
 *               the page, list is on the left/below). Vertical card list.
 *   mobile   →  stacked: summary card on top, then a horizontal scroll
 *               rail of cards with a final "view all" tile.
 *
 * All styling driven by theme.json tokens (--wp--preset--color--*) so the
 * primary color follows the theme without hardcoding.
 */

/* ===== Root ============================================================ */

.rh-reviews {
	margin-block-start: var(--wp--preset--spacing--30, 1rem);
}

/* ===== Body grid (desktop two-column) ================================== */

.rh-reviews__body {
	display: grid;
	grid-template-columns: 1fr;
	gap: 1rem;
}

@media (min-width: 900px) {
	.rh-reviews__body {
		/*
		 * Summary on the visual RIGHT (RTL reading start), comment list on
		 * the visual LEFT. With direction:rtl the first grid track lays out
		 * at the right edge, so 280px goes first to anchor the summary to
		 * the right; minmax(0, 1fr) takes the remaining width on the left
		 * for the cards (and the empty-state copy).
		 */
		grid-template-columns: 280px minmax(0, 1fr);
		align-items: start;
		gap: 1.5rem;
	}
}

/* ===== Summary card =================================================== */

.rh-reviews__summary {
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 0.75rem;
	padding: 1rem 1rem 1.125rem;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.5rem;
	/* On desktop the summary is the second grid column (i.e. visually
	   right of the list in RTL). On mobile it's just the first item. */
}

@media (min-width: 900px) {
	.rh-reviews__summary {
		grid-column: 1;
		position: sticky;
		top: calc(var(--rh-header-height, 64px) + 1rem);
	}
}

.rh-reviews__summary-title {
	margin: 0 0 0.25rem;
	font-size: var(--wp--preset--font-size--md, 1.125rem);
	font-weight: var(--rh-fw-strong);
	color: var(--wp--preset--color--contrast, #0f1115);
}

.rh-reviews__summary-score {
	display: flex;
	align-items: baseline;
	gap: 0.375rem;
	margin-block-start: 0.25rem;
}

.rh-reviews__summary-avg {
	font-size: 2rem;
	font-weight: var(--rh-fw-strong);
	line-height: 1;
	color: var(--wp--preset--color--contrast, #0f1115);
	letter-spacing: -0.01em;
}

.rh-reviews__summary-avg-of {
	font-size: 1rem;
	font-weight: var(--rh-fw-base);
	color: var(--wp--preset--color--text-muted, #5b6271);
	margin-inline-start: 0.125rem;
}

.rh-reviews__summary-count {
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
}

.rh-reviews__summary-stars {
	margin-block-start: 0.125rem;
}

.rh-reviews__summary-cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--wp--custom--button--gap, 8px);
	box-sizing: border-box;
	width: 100%;
	text-align: center;
	margin-block-start: 0.75rem;
	min-height: var(--wp--custom--button--h--md, 44px);
	padding: 0 var(--wp--custom--button--px--md, 20px);
	border: 1px solid var(--wp--preset--color--primary, #0a66c2);
	color: var(--wp--preset--color--primary, #0a66c2);
	background: transparent;
	border-radius: var(--wp--custom--button--radius, 10px);
	font-weight: var(--wp--custom--button--fw, 600);
	font-size: var(--wp--custom--button--fs--md, 0.9375rem);
	text-decoration: none;
	transition: background-color 120ms ease, color 120ms ease;
}

.rh-reviews__summary-cta:hover,
.rh-reviews__summary-cta:focus-visible {
	background: var(--wp--preset--color--primary, #0a66c2);
	color: var(--wp--preset--color--base, #fff);
}

.rh-reviews__summary-cta--inline {
	display: inline-block;
	margin-block-start: 0;
}

/* ===== List (desktop) / rail (mobile) ================================== */

.rh-reviews__list {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

@media (min-width: 900px) {
	.rh-reviews__list {
		grid-column: 2;
	}
}

/* Mobile used to be a horizontal scroll rail here, with a "مشاهده همه نظرات"
 * tile to expand into a vertical list. Reviews are now always the plain
 * vertical list (the base .rh-reviews__list rule above already is one) on
 * every viewport — see the "مشاهده همه" tile rule further down, permanently
 * hidden now that there's no rail to expand out of. */

/* ===== Card =========================================================== */

.rh-reviews__card {
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 0.75rem;
	padding: 0.875rem 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.rh-reviews__card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	min-height: 1.25rem;
}

.rh-reviews__card-stars {
	display: inline-flex;
	align-items: center;
}

.rh-reviews__card-meta {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
}

/* Every reviewer shares the shop's avatar: a pearl with a frangipani on its
   shoulder (assets/img/review-avatar.png, 120px wide for 2x screens). Shown
   uncropped — no circle mask — so the flower can sit past the pearl's edge. */
.rh-reviews__card-avatar {
	flex: 0 0 auto;
	width: 44px;
	height: 40px;
	background: url(../img/review-avatar.png) center / contain no-repeat;
}

.rh-reviews__card-author {
	font-weight: var(--rh-fw-strong);
	color: var(--wp--preset--color--text, #1a1d23);
}

.rh-reviews__card-sep {
	color: var(--wp--preset--color--border, #e2e4e9);
}

.rh-reviews__card-body {
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	line-height: 1.7;
	color: var(--wp--preset--color--text, #1a1d23);
}

.rh-reviews__card-body p {
	margin: 0;
}

.rh-reviews__card-body p + p {
	margin-block-start: 0.5rem;
}

/*
 * Long-review clamp.
 *
 *   - max-height = 5 lines × line-height(1.7) × font-size(--sm). Calc keeps
 *     the math token-driven so a font-size change in theme.json scales the
 *     clamp automatically — no magic pixel number to maintain.
 *   - The fade gradient at the bottom hints there's more to read without
 *     adding an arrow. mask-image rather than ::after so it works over any
 *     background colour (the card might sit on surface, base, or muted).
 *   - is-expanded removes the cap; we cap to a generous 9999px instead of
 *     `none` so the height transition stays animatable if we add one later.
 *
 *  The .has-clamp gate is added by JS only when scrollHeight actually
 *  exceeds clientHeight, so short reviews are never clipped or faded.
 *  Without JS (the .rh-reviews has no .is-clamp-ready class) the clamp is
 *  off — the SSR HTML shows full content, which is the safer no-JS default.
 */
.rh-reviews.is-clamp-ready .rh-reviews__card-body--clamped.has-clamp {
	max-height: calc(5 * 1.7 * var(--wp--preset--font-size--sm, 0.875rem));
	overflow: hidden;
	-webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
	mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
}

.rh-reviews.is-clamp-ready .rh-reviews__card-body--clamped.has-clamp.is-expanded {
	max-height: 9999px;
	-webkit-mask-image: none;
	mask-image: none;
}

.rh-reviews__card-toggle {
	align-self: flex-start;
	background: transparent;
	border: 0;
	padding: 0;
	margin-block-start: 0.125rem;
	color: var(--wp--preset--color--primary, #0a66c2);
	font: inherit;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	font-weight: var(--rh-fw-strong);
	cursor: pointer;
	line-height: 1.6;
}

.rh-reviews__card-toggle:hover,
.rh-reviews__card-toggle:focus-visible {
	text-decoration: none;
}

/* ===== Shop reply ======================================================= */

.rh-reviews__reply {
	margin-block-start: 0.75rem;
	padding: 0.625rem 0.75rem;
	border-inline-start: 2px solid var(--wp--preset--color--primary, #0a66c2);
	background: var(--wp--preset--color--surface, #f7f7f8);
	border-radius: 0.375rem;
}

.rh-reviews__reply-label {
	display: block;
	margin-block-end: 0.25rem;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	font-weight: var(--rh-fw-strong);
	color: var(--wp--preset--color--primary, #0a66c2);
}

.rh-reviews__reply-body {
	margin: 0;
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	line-height: 1.7;
	color: var(--wp--preset--color--text, #1a1d23);
}

/* ===== Badge ("خریدار") ================================================ */

.rh-reviews__badge {
	display: inline-flex;
	align-items: center;
	padding: 0.125rem 0.5rem;
	border-radius: 999px;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	font-weight: var(--rh-fw-strong);
	line-height: 1.6;
}

.rh-reviews__badge--buyer {
	background: color-mix(in srgb, var(--wp--preset--color--success, #198754) 12%, transparent);
	color: var(--wp--preset--color--success, #198754);
}

/* ===== Stars =========================================================== */

.rh-reviews__stars {
	display: inline-flex;
	align-items: center;
	gap: 0.125rem;
}

.rh-reviews__star--solid {
	color: var(--wp--preset--color--warning, #d97706);
}

.rh-reviews__star--outline {
	color: var(--wp--preset--color--border, #e2e4e9);
}

/* ===== "View all" tile (mobile only) =================================== */

.rh-reviews__viewall-tile {
	display: none;
}

@media (max-width: 899px) {
	.rh-reviews__viewall-tile {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 0.5rem;
		background: var(--wp--preset--color--surface, #f7f7f8);
		border: 1px solid var(--wp--preset--color--border, #e2e4e9);
		border-radius: 0.75rem;
		padding: 1rem;
		text-decoration: none;
		color: var(--wp--preset--color--text, #1a1d23);
		text-align: center;
	}
	.rh-reviews__viewall-icon {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 2.5rem;
		height: 2.5rem;
		border-radius: 999px;
		background: var(--wp--preset--color--base, #fff);
		border: 1px solid var(--wp--preset--color--border, #e2e4e9);
		color: var(--wp--preset--color--text, #1a1d23);
	}
	.rh-reviews__viewall-label {
		font-weight: var(--rh-fw-strong);
		font-size: var(--wp--preset--font-size--sm, 0.875rem);
	}
	.rh-reviews__viewall-count {
		font-size: var(--wp--preset--font-size--xs, 0.75rem);
		color: var(--wp--preset--color--text-muted, #5b6271);
	}
}

/* Desktop view-all link (under list) */
.rh-reviews__foot {
	margin-block-start: 1rem;
	text-align: center;
}

/* Load-more ("نمایش نظرات بیشتر"): a clean outlined pill. It's a <button>, so we
   MUST reset the UA chrome (grey fill + border) — otherwise it renders as a grey
   box. Secondary look (subtle border + primary text) so it doesn't compete with
   the primary "ثبت دیدگاه" CTA; hover gives a soft surface fill. */
.rh-reviews__viewall-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	box-sizing: border-box;
	min-height: var(--wp--custom--button--h--md, 44px);
	padding: 0 1.5rem;
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: var(--wp--custom--button--radius, 10px);
	background: transparent;
	color: var(--wp--preset--color--primary, #0a66c2);
	font-weight: var(--wp--custom--button--fw, 600);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	text-decoration: none;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.rh-reviews__viewall-link:hover,
.rh-reviews__viewall-link:focus-visible {
	background: var(--wp--preset--color--surface, #f7f7f8);
	border-color: var(--wp--preset--color--primary, #0a66c2);
	outline: none;
}

/* ===== "مشاهده همه نظرات" tile — retired =================================
 * This used to be the last item of a mobile horizontal rail (mirrors the
 * sliders' .rps-view-all), expanding into a vertical list on tap. Reviews
 * are now always the vertical list on every viewport, so there is no rail
 * left to expand out of — the tile (still built by rh-reviews.js, harmless
 * dead markup) stays permanently hidden, and the load-more foot below is
 * always the one visible way to fetch further pages. */
.rh-reviews__viewall-card { display: none; }

/* ===== Empty state ====================================================== */

/*
 * Inviting two-up: copy block on the right (RTL start), chat-bubble icon
 * on the left. No background card — the message is meant to feel light,
 * not like a placeholder error. The summary card on the right already
 * provides the "افزودن دیدگاه جدید" CTA; we don't repeat it here.
 */
.rh-reviews__empty {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 1.25rem;
	padding: 2rem 1rem;
	color: var(--wp--preset--color--text-muted, #5b6271);
	text-align: center;
}

.rh-reviews__empty-copy {
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
	text-align: center;
}

.rh-reviews__empty-title {
	margin: 0;
	color: var(--wp--preset--color--contrast, #0f1115);
	font-size: var(--wp--preset--font-size--md, 1.125rem);
	font-weight: var(--rh-fw-strong);
}

.rh-reviews__empty-text {
	margin: 0;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	line-height: 1.7;
}

.rh-reviews__empty-icon {
	color: var(--wp--preset--color--text-muted, #5b6271);
	opacity: 0.55;
	flex-shrink: 0;
}

@media (min-width: 900px) {
	.rh-reviews__body--empty {
		/* keep summary right + empty card left even when there are no reviews */
		grid-template-columns: 280px minmax(0, 1fr);
	}
	.rh-reviews__body--empty .rh-reviews__empty {
		grid-column: 2;
	}
}

/* =========================================================================
 *  Archive view  (URL: /product/.../?reviews=1)
 * ========================================================================= */

.rh-reviews-archive {
	/* Override the inline section's compact top spacing — the archive is
	   the page's main content, not a section after the product summary. */
	margin-block-start: 0;
}

/* ---- top crumb (back to product) ---- */

.rh-reviews-archive__crumb {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	background: var(--wp--preset--color--surface, #f7f7f8);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 0.75rem;
	text-decoration: none;
	color: inherit;
	margin-block-end: 1rem;
}

.rh-reviews-archive__crumb-img {
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 0.5rem;
	object-fit: cover;
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	flex-shrink: 0;
}

.rh-reviews-archive__crumb-name {
	font-weight: var(--rh-fw-strong);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	color: var(--wp--preset--color--text, #1a1d23);
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.rh-reviews-archive__crumb-back {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	white-space: nowrap;
}

.rh-reviews-archive__crumb:hover .rh-reviews-archive__crumb-back,
.rh-reviews-archive__crumb:focus-visible .rh-reviews-archive__crumb-back {
	color: var(--wp--preset--color--primary, #0a66c2);
}

/* ---- main column ---- */

.rh-reviews-archive__main {
	display: flex;
	flex-direction: column;
	gap: 0.875rem;
}

@media (min-width: 900px) {
	.rh-reviews-archive__main {
		grid-column: 1;
	}
}

/* ---- toolbar (filter + sort + total) ---- */

.rh-reviews-archive__toolbar {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.75rem;
	padding: 0.875rem 1rem;
	background: var(--wp--preset--color--base, #fff);
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 0.75rem;
}

.rh-reviews-archive__filter {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	padding: 0.375rem 0.75rem;
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 999px;
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	color: var(--wp--preset--color--text, #1a1d23);
	background: var(--wp--preset--color--base, #fff);
	text-decoration: none;
	transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.rh-reviews-archive__filter-dot {
	width: 0.625rem;
	height: 0.625rem;
	border-radius: 999px;
	border: 1.5px solid var(--wp--preset--color--text-muted, #5b6271);
	background: transparent;
	transition: background-color 120ms ease, border-color 120ms ease;
}

.rh-reviews-archive__filter.is-on {
	border-color: var(--wp--preset--color--primary, #0a66c2);
	background: color-mix(in srgb, var(--wp--preset--color--primary, #0a66c2) 8%, transparent);
	color: var(--wp--preset--color--primary, #0a66c2);
}

.rh-reviews-archive__filter.is-on .rh-reviews-archive__filter-dot {
	background: var(--wp--preset--color--primary, #0a66c2);
	border-color: var(--wp--preset--color--primary, #0a66c2);
}

.rh-reviews-archive__filter:hover:not(.is-on),
.rh-reviews-archive__filter:focus-visible:not(.is-on) {
	border-color: var(--wp--preset--color--text-muted, #5b6271);
}

/* sort group */

.rh-reviews-archive__sort {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	flex: 1 1 auto;
	min-width: 0;
}

.rh-reviews-archive__sort-label {
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	white-space: nowrap;
}

.rh-reviews-archive__sort-tabs {
	display: inline-flex;
	list-style: none;
	margin: 0;
	padding: 0;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.rh-reviews-archive__sort-tabs > li { margin: 0; }

.rh-reviews-archive__sort-tab {
	display: inline-block;
	padding: 0.25rem 0.5rem;
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	color: var(--wp--preset--color--text-muted, #5b6271);
	text-decoration: none;
	border-block-end: 2px solid transparent;
	transition: color 120ms ease, border-color 120ms ease;
}

.rh-reviews-archive__sort-tab:hover,
.rh-reviews-archive__sort-tab:focus-visible {
	color: var(--wp--preset--color--text, #1a1d23);
}

.rh-reviews-archive__sort-tab.is-active {
	color: var(--wp--preset--color--primary, #0a66c2);
	border-block-end-color: var(--wp--preset--color--primary, #0a66c2);
	font-weight: var(--rh-fw-strong);
}

.rh-reviews-archive__total {
	margin-inline-start: auto;
	color: var(--wp--preset--color--text-muted, #5b6271);
	font-size: var(--wp--preset--font-size--xs, 0.75rem);
	white-space: nowrap;
}

/* ---- list ---- */

.rh-reviews-archive__list {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

/* ---- pagination ---- */

.rh-reviews-archive__pagination {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 0.375rem;
	margin-block-start: 0.5rem;
	padding-block: 0.5rem;
}

.rh-reviews-archive__page {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 2.25rem;
	height: 2.25rem;
	padding: 0 0.5rem;
	border: 1px solid var(--wp--preset--color--border, #e2e4e9);
	border-radius: 0.5rem;
	background: var(--wp--preset--color--base, #fff);
	color: var(--wp--preset--color--text, #1a1d23);
	text-decoration: none;
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	font-variant-numeric: tabular-nums;
	transition: border-color 120ms ease, color 120ms ease, background-color 120ms ease;
}

.rh-reviews-archive__page:hover,
.rh-reviews-archive__page:focus-visible {
	border-color: var(--wp--preset--color--primary, #0a66c2);
	color: var(--wp--preset--color--primary, #0a66c2);
}

.rh-reviews-archive__page.is-current {
	background: var(--wp--preset--color--primary, #0a66c2);
	border-color: var(--wp--preset--color--primary, #0a66c2);
	color: var(--wp--preset--color--base, #fff);
	pointer-events: none;
}

.rh-reviews-archive__page--gap {
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--text-muted, #5b6271);
}

.rh-reviews-archive__page--prev,
.rh-reviews-archive__page--next {
	color: var(--wp--preset--color--text-muted, #5b6271);
}

/* a11y helper — visually hidden but readable for screen readers */
.rh-reviews-archive .screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

/* ---- mobile: rail-style toolbar layout ---- */

@media (max-width: 899px) {
	.rh-reviews-archive__toolbar {
		flex-direction: column;
		align-items: stretch;
		gap: 0.625rem;
	}
	.rh-reviews-archive__filter { align-self: flex-start; }
	.rh-reviews-archive__sort {
		flex-direction: column;
		align-items: flex-start;
		gap: 0.375rem;
	}
	.rh-reviews-archive__sort-tabs {
		/* horizontal scroll for tabs when the row gets cramped */
		display: flex;
		overflow-x: auto;
		scrollbar-width: none;
		gap: 0.75rem;
		width: 100%;
	}
	.rh-reviews-archive__sort-tabs::-webkit-scrollbar { display: none; }
	.rh-reviews-archive__sort-tab { flex: 0 0 auto; }
	.rh-reviews-archive__total {
		margin-inline-start: 0;
		align-self: flex-end;
	}
}
