/**
 * Frontend styles for SW Reviews.
 *
 * Theme-adaptive via CSS custom properties fallback chain.
 * No fixed pixel values except hairlines. No !important. No font-face.
 * No box-shadow. No background in default state. BEM naming.
 *
 * @package SW_Reviews
 */

/* === Root variables with theme fallback chain === */

.swr-review-list,
.swr-summary,
.swr-authenticity-notice,
.swr-form-wrap {
	/*
	 * Colours are derived from the inherited text colour, not guessed from
	 * preset names: contrast, contrast-2, base and primary are Twenty-Twenty-
	 * Four/Five conventions and are absent in most other themes, where the whole
	 * chain used to collapse onto currentColor and lose every distinction.
	 * The accent still tries the common preset names and can be set explicitly
	 * through the swr_accent_color filter, which feeds --swr-accent-override.
	 */
	--swr-accent: var(
		--swr-accent-override,
		var(--wp--preset--color--primary,
		var(--wp--preset--color--accent,
		var(--wp--preset--color--theme-1, currentColor)))
	);
	--swr-muted: color-mix(in srgb, currentColor 62%, transparent);
	--swr-border: color-mix(in srgb, currentColor 28%, transparent);
	--swr-gap: var(--wp--preset--spacing--40, 1rem);
	--swr-radius: var(--wp--custom--radius--md, 0.375rem);
	font-family: inherit;
}

/* === Review list === */

.swr-review-list {
	display: flex;
	flex-direction: column;
	gap: var(--swr-gap);
}

.swr-review-list--grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
}

/* === Single review === */

.swr-review {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0 var(--swr-gap);
	border-bottom: 1px solid var(--swr-border);
	padding-bottom: var(--swr-gap);
}

.swr-review--no-avatar {
	display: block;
}

.swr-review__header {
	display: contents;
}

.swr-review--no-avatar .swr-review__header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5em;
	margin-bottom: 0.5em;
}

/* === Avatar and monogram === */

.swr-review__avatar {
	grid-row: 1 / 3;
	width: 3rem;
	height: 3rem;
	border-radius: 50%;
	overflow: hidden;
	flex-shrink: 0;
}

.swr-review__photo {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.swr-review__monogram {
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
}

.swr-review__monogram-text {
	font-size: 1.125rem;
	font-weight: 600;
	line-height: 1;
}

/* === Meta === */

.swr-review__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.25em 0.75em;
}

.swr-review__author {
	font-weight: 600;
}

.swr-review__stars {
	color: var(--swr-accent);
	letter-spacing: 0.05em;
}

.swr-review__verified {
	font-size: 0.8125em;
	color: var(--swr-muted);
}

.swr-review__date {
	font-size: 0.8125em;
	color: var(--swr-muted);
}

/* === Review text === */

.swr-review__text {
	grid-column: 1 / -1;
	margin-top: 0.5em;
}

.swr-review--no-avatar .swr-review__text {
	grid-column: unset;
}

.swr-review__text p:last-child {
	margin-bottom: 0;
}

/* === Incentive notice === */

.swr-review__incentive {
	grid-column: 1 / -1;
	font-size: 0.8125em;
	color: var(--swr-muted);
	margin-top: 0.25em;
}

/* === Owner reply === */

.swr-review__reply {
	grid-column: 1 / -1;
	margin-top: 0.75em;
	padding-left: var(--swr-gap);
	border-left: 2px solid var(--swr-accent);
}

.swr-review__reply-label {
	font-size: 0.8125em;
	font-weight: 600;
	color: var(--swr-muted);
	margin-bottom: 0.25em;
}

.swr-review__reply-text p:last-child {
	margin-bottom: 0;
}

.swr-review__reply-date {
	display: block;
	font-size: 0.75em;
	color: var(--swr-muted);
	margin-top: 0.25em;
}

/* === Summary === */

.swr-summary {
	display: flex;
	flex-wrap: wrap;
	gap: var(--swr-gap);
	align-items: flex-start;
	margin-bottom: var(--swr-gap);
}

.swr-summary__average {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.25em 0.5em;
}

.swr-summary__number {
	font-size: 2em;
	font-weight: 700;
	line-height: 1;
}

.swr-summary__count {
	font-size: 0.875em;
	color: var(--swr-muted);
}

.swr-summary__distribution {
	flex: 1;
	min-width: 12rem;
}

.swr-summary__bar {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin-bottom: 0.25em;
}

.swr-summary__bar-label {
	flex-shrink: 0;
	width: 3em;
	text-align: right;
	font-size: 0.8125em;
}

.swr-summary__bar-track {
	flex: 1;
	height: 0.5em;
	background: color-mix(in srgb, var(--swr-muted) 20%, transparent);
	border-radius: 0.25em;
	overflow: hidden;
}

.swr-summary__bar-fill {
	display: block;
	height: 100%;
	background: var(--swr-accent);
	border-radius: 0.25em;
}

.swr-summary__bar-count {
	flex-shrink: 0;
	width: 2em;
	font-size: 0.8125em;
	color: var(--swr-muted);
}

/* === Authenticity notice === */

.swr-authenticity-notice {
	font-size: 0.8125em;
	color: var(--swr-muted);
	margin-bottom: var(--swr-gap);
	line-height: 1.5;
}

.swr-authenticity-notice p {
	margin: 0;
}

/* === Pagination === */

.swr-pagination {
	margin-top: var(--swr-gap);
}

.swr-pagination ul {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25em;
	list-style: none;
	padding: 0;
	margin: 0;
}

/* === Review form (token page and review-form block) === */

/*
 * Two layers, deliberately separated:
 * structure below (layout the theme cannot know about) at normal specificity,
 * appearance of native controls at the end wrapped in :where() so any theme
 * rule — down to a bare `input {}` — overrides it without a specificity fight.
 */

.swr-form__field {
	display: flex;
	flex-direction: column;
	gap: 0.25em;
	margin-bottom: var(--swr-gap);
}

/* Honeypot — must never be perceivable, functional rather than decorative. */
.swr-form__hp {
	display: none;
}

.swr-form__errors {
	border-left: 2px solid var(--swr-accent);
	padding-left: var(--swr-gap);
	margin-bottom: var(--swr-gap);
}

.swr-form__errors ul {
	margin: 0;
}

/* === Rating stars === */

.swr-form__rating,
.swr-form__consent {
	border: 0;
	padding: 0;
	margin: 0 0 var(--swr-gap);
}

.swr-form__rating legend,
.swr-form__consent legend {
	padding: 0;
	margin-bottom: 0.25em;
}

.swr-form__stars {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25em 0.75em;
}

.swr-form__star {
	display: inline-flex;
	align-items: center;
	gap: 0.25em;
	color: var(--swr-accent);
	cursor: pointer;
}

/*
 * Cumulative reading without JS: every star after the selected one is dimmed,
 * and nothing is highlighted while the group is still untouched.
 * Themes without :has() support simply see all five in the accent colour.
 */
.swr-form__star:has(input:checked) ~ .swr-form__star,
.swr-form__rating:not(:has(input:checked)) .swr-form__star {
	color: var(--swr-muted);
}

/* === Consent === */

.swr-form__checkbox {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0 0.5em;
	align-items: baseline;
	margin-bottom: 0.5em;
	cursor: pointer;
}

.swr-form__incentive-notice {
	font-size: 0.8125em;
	color: var(--swr-muted);
}

/* === Native controls: zero specificity, theme always wins === */

:where(.swr-form-wrap) :where(input[type="text"], input[type="email"], textarea) {
	box-sizing: border-box;
	width: 100%;
	padding: 0.5em 0.75em;
	font: inherit;
	color: inherit;
	background-color: transparent;
	border: 1px solid var(--swr-border);
	border-radius: var(--swr-radius);
}

:where(.swr-form-wrap) :where(textarea) {
	resize: vertical;
}

/*
 * The submit button carries `wp-element-button`, so block themes style it from
 * theme.json. This only covers classic themes without one — no colour, no chrome.
 */
:where(.swr-form-wrap) :where(.swr-form__submit) {
	font: inherit;
	cursor: pointer;
}
