/**
 * CZAR Fragrance Predictor — Frontend Styles
 *
 * Styles the [czar_ai_predictor] shortcode interface:
 * - Selection grid matching the theme's breakpoint system
 * - Card selection states (outline, checkmark overlay)
 * - Search input
 * - Recommendations section
 * - Loading / empty / error states
 * - Full RTL support via logical properties + [dir="rtl"] overrides
 * - Responsive breakpoints matching the CZAR theme grid
 *
 * CSS VARIABLE DEPENDENCIES (from CZAR theme):
 * - --czar-grid-gap     (default: 0)
 * - --czar-space-xs     (0.5rem)
 * - --czar-space-sm     (1rem)
 * - --czar-space-md     (1.5rem)
 * - --czar-space-lg     (2rem)
 * - --czar-space-xl     (3rem)
 * - --czar-space-2xl    (4rem)
 * - --czar-accent       (gold accent color, default #c9a96e)
 * - --czar-text-primary (default #000)
 * - --czar-text-secondary (default #666)
 * - --czar-border       (default #e0e0e0)
 *
 * @package Czar_Fragrance_Predictor
 * @since   1.0.0
 */


/* ═══════════════════════════════════════════════════════════════════════
   CONTAINER
   ═══════════════════════════════════════════════════════════════════════ */

/*
 * The predictor lives inside page.php, which wraps content in
 * .czar-page { max-width: 720px }. That collapses our grid columns
 * to ~160px — far smaller than the 360px home grid columns.
 * Override the page wrapper's constraint so the predictor grid
 * gets the same available width as the home grid (1440px).
 * padding-inline: 0 removes the page wrapper's side padding;
 * the predictor handles its own horizontal padding below.
 */
.czar-page:has(.czar-predictor) {
	max-width: var(--czar-max-width, 1440px);
	padding-inline: 0;
}

.czar-predictor {
	max-width: 1440px;
	margin-inline: auto;
	padding: var(--czar-space-md, 1.5rem);
}


/* ═══════════════════════════════════════════════════════════════════════
   HEADER (heading + count + clear button)
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__header {
	display: flex;
	align-items: center;
	gap: var(--czar-space-sm, 1rem);
	margin-block-end: var(--czar-space-lg, 2rem);
	flex-wrap: wrap;
}

.czar-predictor__heading {
	margin: 0;
	font-size: 1.25rem;
	text-transform: uppercase;
	letter-spacing: 0.1em;
}

.czar-predictor__count {
	font-size: 0.875rem;
	color: var(--czar-text-secondary, #666);
	display: none; /* Shown via JS when count > 0 */
}

.czar-predictor__clear {
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	background: none;
	border: 1px solid currentColor;
	padding: 0.375rem 0.75rem;
	cursor: pointer;
	color: var(--czar-text-secondary, #666);
	display: none; /* Shown via JS when count > 0 */
	transition: color 0.2s ease, border-color 0.2s ease;
}

.czar-predictor__clear:hover,
.czar-predictor__clear:focus-visible {
	color: var(--czar-text-primary, #000);
}


/* ═══════════════════════════════════════════════════════════════════════
   SEARCH FILTER
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__search-wrap {
	margin-block-end: var(--czar-space-md, 1.5rem);
	max-width: 400px;
}

.czar-predictor__search {
	width: 100%;
	padding: 0.625rem 1rem;
	font-size: 0.875rem;
	border: 1px solid var(--czar-border, #e0e0e0);
	background: transparent;
	color: var(--czar-text-primary, #000);
	outline: none;
	transition: border-color 0.2s ease;
	font-family: inherit;
	letter-spacing: 0.02em;
}

.czar-predictor__search:focus {
	border-color: #000;
}

.czar-predictor__search::placeholder {
	color: var(--czar-text-secondary, #666);
	opacity: 0.7;
}


/* ═══════════════════════════════════════════════════════════════════════
   PREDICTIVE SEARCH DROPDOWN
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__dropdown {
	display: none;
	position: absolute;
	inset-inline-start: 0;
	inset-inline-end: 0;
	inset-block-start: 100%;
	z-index: 100;
	background: #fff;
	border: 1px solid var(--czar-border, #e0e0e0);
	border-block-start: none;
	max-height: 360px;
	overflow-y: auto;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.czar-predictor__dropdown-item {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.5rem 0.75rem;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.czar-predictor__dropdown-item:hover,
.czar-predictor__dropdown-item.is-highlighted {
	background-color: #f5f5f5;
}

.czar-predictor__dropdown-img {
	width: 40px;
	height: 53px;
	object-fit: contain;
	flex-shrink: 0;
}

.czar-predictor__dropdown-text {
	display: flex;
	flex-direction: column;
	gap: 0.125rem;
	min-width: 0;
}

.czar-predictor__dropdown-title {
	font-size: 0.8125rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--czar-text-primary, #000);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.czar-predictor__dropdown-subtitle {
	font-size: 0.75rem;
	color: var(--czar-text-secondary, #666);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	direction: rtl;
}

.czar-predictor__dropdown-title mark,
.czar-predictor__dropdown-subtitle mark {
	background: transparent;
	color: inherit;
	font-weight: 700;
}

.czar-predictor__dropdown-empty {
	padding: 1rem 0.75rem;
	font-size: 0.8125rem;
	color: var(--czar-text-secondary, #666);
	text-align: center;
}

/* Flash animation when a dropdown item selects a card */
@keyframes czar-flash {
	0%   { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.3); }
	50%  { box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.1); }
	100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

.czar-predictor__card.is-flash {
	animation: czar-flash 0.6s ease;
}


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

.czar-predictor__grid {
	/*
	 * Flexbox (not grid) so partial rows can center via justify-content.
	 * Card widths below (and in the responsive breakpoints) control column count.
	 */
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--czar-grid-gap, 0);
}


/* ═══════════════════════════════════════════════════════════════════════
   SELECTION CARD
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__card {
	position: relative;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	align-items: center;
	/* Match the home grid card padding exactly (grid.css:84) */
	padding: var(--czar-space-xl, 3rem) var(--czar-space-md, 1.5rem) var(--czar-space-2xl, 4rem);
	transition: opacity 0.2s ease;
	-webkit-user-select: none;
	user-select: none;
	outline-offset: -2px;
	/* 4-column default; overridden in breakpoints below. */
	width: 25%;
	box-sizing: border-box;
}

.czar-predictor__card:hover {
	opacity: 0.75;
}

.czar-predictor__card:focus-visible {
	outline: 2px solid var(--czar-accent, #c9a96e);
}

/* Card image container — matches theme's 3:4 aspect ratio */
.czar-predictor__card-image {
	position: relative;
	width: 100%;
	max-width: 240px;
	aspect-ratio: 3 / 4;
	overflow: hidden;
}

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

.czar-predictor__card:hover .czar-predictor__card-image img {
	transform: scale(1.03);
}

/* Card title — matches theme's .czar-card__title styling */
.czar-predictor__card-title {
	text-align: center;
	font-size: var(--czar-card-title-size, 11px);
	text-transform: uppercase;
	letter-spacing: 0.1em;
	margin-block-start: var(--czar-space-xs, 0.5rem);
	margin-block-end: 0;
}


/* ═══════════════════════════════════════════════════════════════════════
   SELECTION STATE (checkmark + outline)
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__check {
	position: absolute;
	inset-block-start: 0.5rem;
	inset-inline-end: 0.5rem;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: #000;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 14px;
	line-height: 1;
	opacity: 0;
	transform: scale(0.5);
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
}

.czar-predictor__card.is-selected .czar-predictor__check {
	opacity: 1;
	transform: scale(1);
}

.czar-predictor__card.is-selected {
	outline: 2px solid #000;
}

.czar-predictor__card.is-selected:hover {
	opacity: 0.85;
}


/* ═══════════════════════════════════════════════════════════════════════
   RESULTS SECTION
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__results {
	margin-block-start: var(--czar-space-2xl, 4rem);
	padding-block-start: var(--czar-space-lg, 2rem);
	border-block-start: 1px solid var(--czar-border, #e0e0e0);
}

.czar-predictor__results-heading {
	text-transform: uppercase;
	letter-spacing: 0.1em;
	font-size: 1.25rem;
	margin-block-end: var(--czar-space-lg, 2rem);
	text-align: center;
}

.czar-predictor__results-grid {
	/*
	 * Flexbox (not grid) so partial rows of recommendations center nicely.
	 * Result widths below (and in the responsive breakpoints) control column count.
	 */
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--czar-grid-gap, 0);
}

/*
 * Recommendation cards use the theme's .czar-card class
 * (from grid.css) so they inherit the existing card styling.
 * No additional styling needed here — the theme handles it.
 */


/* ═══════════════════════════════════════════════════════════════════════
   LOADING / EMPTY / ERROR STATES
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__loading,
.czar-predictor__empty,
.czar-predictor__error {
	width: 100%;
	text-align: center;
	padding: var(--czar-space-xl, 3rem) var(--czar-space-sm, 1rem);
	color: var(--czar-text-secondary, #666);
	font-size: 0.875rem;
	letter-spacing: 0.02em;
}

.czar-predictor__error {
	color: #a94442;
}


/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   Matches the CZAR theme grid breakpoints exactly.
   ═══════════════════════════════════════════════════════════════════════ */

/* Ultrawide: 5 columns */
@media ( min-width: 1800px ) {
	.czar-predictor__card,
	.czar-predictor__result {
		width: 20%;
	}
}

/* Tablet: 3 columns */
@media ( max-width: 1024px ) {
	.czar-predictor__card,
	.czar-predictor__result {
		width: 33.3333%;
	}
}

/* Large mobile: 2 columns */
@media ( max-width: 768px ) {
	.czar-predictor__card,
	.czar-predictor__result {
		width: 50%;
	}

	/* Match home grid's responsive image cap (grid.css:169) */
	.czar-predictor__card-image {
		max-width: 180px;
	}

	.czar-predictor__search-wrap {
		max-width: 100%;
	}
}

/* Small mobile: 1 column */
@media ( max-width: 480px ) {
	.czar-predictor__card,
	.czar-predictor__result {
		width: 100%;
	}

	/* Match home grid's small-mobile image cap (grid.css:185) */
	.czar-predictor__card-image {
		max-width: 220px;
	}

	.czar-predictor__header {
		flex-direction: column;
		align-items: flex-start;
	}
}


/* ═══════════════════════════════════════════════════════════════════════
   RTL SUPPORT
   CSS logical properties handle most RTL cases automatically.
   These overrides cover remaining edge cases.
   ═══════════════════════════════════════════════════════════════════════ */

[dir="rtl"] .czar-predictor__search {
	font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

[dir="rtl"] .czar-predictor__heading,
[dir="rtl"] .czar-predictor__results-heading {
	font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

[dir="rtl"] .czar-predictor__card-title {
	font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

[dir="rtl"] .czar-predictor__clear {
	font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

[dir="rtl"] .czar-predictor__dropdown-title,
[dir="rtl"] .czar-predictor__dropdown-empty {
	font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

/* In small mobile RTL, align header items to the end (right in RTL) */
@media ( max-width: 480px ) {
	[dir="rtl"] .czar-predictor__header {
		align-items: flex-end;
	}
}


/* ═══════════════════════════════════════════════════════════════════════
   SIMILARITY MATCH BADGE
   Rendered under each recommendation card's title. Swiss/monochrome:
   thin 1px border, micro-caps, tight tracking. The strict tier is
   emphasized in solid black; lenient/family/global tiers are muted.
   ═══════════════════════════════════════════════════════════════════════ */

.czar-predictor__match {
	display: inline-block;
	margin-block-start: var(--czar-space-xs, 0.5rem);
	padding: 0.25rem 0.5rem;
	font-size: 0.6875rem;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	border: 1px solid var(--czar-border, #e0e0e0);
	color: var(--czar-text-secondary, #666);
	line-height: 1;
	align-self: center;
}

.czar-predictor__match[data-tier="strict"] {
	border-color: #000;
	color: #000;
}

.czar-predictor__match[data-tier="lenient"] {
	border-color: #bfbfbf;
	color: #333;
}

/* Center the badge under the card title regardless of card layout. */
.czar-predictor__result {
	text-align: center;
	/* 4-column default for the results grid; overridden in breakpoints above. */
	width: 25%;
	box-sizing: border-box;
}

/*
 * Results use .czar-card__image which already has max-width: 240px globally.
 * No override needed — let results match the home grid exactly.
 * (The previous 300px override has been removed.)
 */

/* Arabic: neutralize Latin tracking + use the Arabic stack. */
[dir="rtl"] .czar-predictor__match,
body.czar-rtl .czar-predictor__match,
body.czar-lang-ar .czar-predictor__match {
	font-family: 'Noto Kufi Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
	letter-spacing: 0;
}
