/*
 * KB Advanced Automatic Compare - front end styles.
 * Works in LTR and RTL (logical properties only).
 *
 * Colours, fonts and radius follow the active theme. WoodMart's CSS variables are used first, with plain
 * fallbacks for other themes. The accent and surface can be overridden in the plugin settings
 * (--kb-aac-accent / --kb-aac-surface).
 */

.kb-aac {
	--kb-aac-accent: var(--btn-accented-bgcolor, var(--wd-primary-color, #c8202f));
	--kb-aac-accent-contrast: var(--btn-accented-color, #fff);
	--kb-aac-surface: var(--bgcolor-white, #fff);
	--kb-aac-text: var(--wd-text-color, inherit);
	--kb-aac-title: var(--wd-title-color, inherit);
	--kb-aac-muted: var(--color-gray-500, rgba(127, 127, 127, 0.9));
	--kb-aac-radius: var(--wd-brd-radius, 12px);
	--kb-aac-btn-radius: var(--btn-default-brd-radius, var(--wd-form-brd-radius, 6px));
	--kb-aac-line: var(--brdcolor-gray-300, rgba(127, 127, 127, 0.22));
	--kb-aac-zebra: rgba(127, 127, 127, 0.1);
	--kb-aac-soft: rgba(127, 127, 127, 0.07);
	--kb-aac-star: #f59e0b;
	--kb-aac-label-w: 8.5em;
	box-sizing: border-box;
	clear: both;
	max-width: 100%;
	margin: 30px 0;
	color: var(--kb-aac-text);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.6;
}

/* White rounded card, like the other blocks of the product page. */
.kb-aac--card {
	padding: 30px;
	border-radius: var(--kb-aac-radius);
	background: var(--kb-aac-surface);
}

.kb-aac *,
.kb-aac *::before,
.kb-aac *::after {
	box-sizing: border-box;
}

/* Placeholder (AJAX mode): a quiet skeleton that keeps the space until the table arrives. */
.kb-aac--pending {
	min-height: 360px;
}

.kb-aac__skel {
	display: block;
	border-radius: 8px;
	background: linear-gradient(90deg, rgba(127, 127, 127, 0.1) 25%, rgba(127, 127, 127, 0.2) 50%, rgba(127, 127, 127, 0.1) 75%);
	background-size: 200% 100%;
	animation: kb-aac-shimmer 1.4s ease-in-out infinite;
}

.kb-aac__skel--title {
	width: 220px;
	max-width: 60%;
	height: 28px;
	margin-bottom: 24px;
}

.kb-aac__skel--body {
	height: 260px;
}

@keyframes kb-aac-shimmer {
	from { background-position: 200% 0; }
	to { background-position: -200% 0; }
}

.kb-aac__head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.75em 1.5em;
	margin-bottom: 1em;
}

.kb-aac .kb-aac__title {
	display: inline-block;
	margin: 0;
	padding-top: 0.55em;
	border-top: 2px solid var(--kb-aac-accent);
	color: var(--kb-aac-title);
	font-family: var(--wd-title-font, inherit);
	font-size: 1.45em;
	font-weight: var(--wd-title-font-weight, 600);
	line-height: 1.3;
}

.kb-aac__toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	margin: 0;
	font-size: 0.95em;
	cursor: pointer;
	user-select: none;
}

.kb-aac__toggle input {
	width: 1.1em;
	height: 1.1em;
	margin: 0;
	accent-color: var(--kb-aac-accent);
}

/* Scroll area: the product columns scroll sideways, the label column stays. */
.kb-aac__scroll {
	overflow-x: auto;
	border-radius: var(--kb-aac-radius);
	background: var(--kb-aac-surface);
	overscroll-behavior-x: contain;
}

.kb-aac__scroll:focus-visible {
	outline: 2px solid var(--kb-aac-accent);
	outline-offset: 2px;
}

.kb-aac .kb-aac__table {
	width: 100%;
	min-width: max-content;
	margin: 0;
	border: 0;
	border-collapse: separate;
	border-spacing: 0;
	table-layout: auto;
	background: transparent;
	color: inherit;
}

.kb-aac .kb-aac__table th,
.kb-aac .kb-aac__table td {
	padding: 0.85em 1.1em;
	border: 0;
	background: transparent;
	color: inherit;
	font-size: 1em;
	font-weight: 400;
	line-height: 1.5;
	text-align: start;
	vertical-align: top;
}

/* Header row: product images and names, separated from the rows by a line. */
.kb-aac .kb-aac__table thead .kb-aac__hrow--action > * {
	border-bottom: 1px solid var(--kb-aac-line);
}

/* Tight spacing between the three header rows (image / name / button). */
.kb-aac .kb-aac__table .kb-aac__hrow--image > * {
	padding-bottom: 0.4em;
	vertical-align: bottom;
}

.kb-aac .kb-aac__table .kb-aac__hrow--name > * {
	padding-block: 0.2em;
}

.kb-aac .kb-aac__table .kb-aac__hrow--action > * {
	padding-top: 0.6em;
	padding-bottom: 1.1em;
}

/* Specification rows: zebra bands with rounded ends, like the product page's attribute table. */
.kb-aac .kb-aac__table .kb-aac__row.is-alt > * {
	background: var(--kb-aac-zebra);
}

.kb-aac .kb-aac__table .kb-aac__row.is-alt > :first-child {
	border-start-start-radius: 8px;
	border-end-start-radius: 8px;
}

.kb-aac .kb-aac__table .kb-aac__row.is-alt > :last-child {
	border-start-end-radius: 8px;
	border-end-end-radius: 8px;
}

.kb-aac .kb-aac__table .kb-aac__row--price > *,
.kb-aac .kb-aac__table .kb-aac__row--rating > * {
	border-bottom: 1px solid var(--kb-aac-line);
}

.kb-aac .kb-aac__table .kb-aac__product,
.kb-aac .kb-aac__table .kb-aac__cell {
	min-width: 12em;
	max-width: 17em;
}

/* Sticky label column. */
.kb-aac .kb-aac__table .kb-aac__label {
	position: sticky;
	inset-inline-start: 0;
	z-index: 1;
	width: var(--kb-aac-label-w);
	min-width: var(--kb-aac-label-w);
	max-width: var(--kb-aac-label-w);
	background: var(--kb-aac-surface);
	color: var(--kb-aac-title);
	font-weight: 600;
}

/* The sticky label keeps the zebra band colour, drawn over the surface. */
.kb-aac .kb-aac__table .kb-aac__row.is-alt > .kb-aac__label {
	background: linear-gradient(var(--kb-aac-zebra), var(--kb-aac-zebra)), var(--kb-aac-surface);
}

/* The product being viewed. */
.kb-aac .kb-aac__table .is-current {
	background-color: var(--kb-aac-soft);
}

.kb-aac .kb-aac__table .kb-aac__row.is-alt > .is-current {
	background: linear-gradient(var(--kb-aac-soft), var(--kb-aac-soft)), var(--kb-aac-zebra);
}

.kb-aac .kb-aac__table .kb-aac__cell:not(.is-current) {
	color: var(--kb-aac-muted);
}

.kb-aac .kb-aac__table .kb-aac__row--price .kb-aac__cell,
.kb-aac .kb-aac__table .kb-aac__row--rating .kb-aac__cell {
	color: inherit;
}

/* Product header cells. */
.kb-aac .kb-aac__table .kb-aac__product {
	font-weight: 400;
}

.kb-aac__badge {
	display: inline-block;
	margin: 0 0 0.6em;
	margin-inline-end: 0.4em;
	padding: 0.1em 0.8em;
	border-radius: var(--kb-aac-btn-radius);
	background: var(--kb-aac-accent);
	color: var(--kb-aac-accent-contrast);
	font-size: 0.8em;
	font-weight: 600;
	line-height: 1.6;
}

.kb-aac__badge--muted {
	background: rgba(127, 127, 127, 0.75);
}

.kb-aac__imglink {
	display: block;
	margin-bottom: 0.7em;
	text-decoration: none;
}

.kb-aac .kb-aac__img {
	display: block;
	width: 100%;
	max-width: 130px;
	height: auto;
	margin: 0 auto;
	border-radius: 6px;
	object-fit: contain;
}

.kb-aac a.kb-aac__name,
.kb-aac span.kb-aac__name {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	margin-bottom: 0;
	color: var(--kb-aac-title);
	font-weight: 600;
	line-height: 1.5;
	text-decoration: none;
}

.kb-aac a.kb-aac__name:hover,
.kb-aac a.kb-aac__name:focus-visible {
	color: var(--kb-aac-accent);
}

.kb-aac a.kb-aac__btn {
	display: inline-block;
	padding: 0.5em 1.3em;
	border: 1px solid var(--kb-aac-accent);
	border-radius: var(--kb-aac-btn-radius);
	background: transparent;
	color: var(--kb-aac-accent);
	font-size: 0.95em;
	font-weight: 600;
	line-height: 1.35;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.kb-aac a.kb-aac__btn:hover,
.kb-aac a.kb-aac__btn:focus-visible {
	background: var(--kb-aac-accent);
	color: var(--kb-aac-accent-contrast);
}

/* Price and its difference tag. */
.kb-aac__price {
	display: block;
	font-weight: 600;
}

.kb-aac__price del {
	opacity: 0.6;
	font-weight: 400;
}

.kb-aac__price ins {
	background: transparent;
	text-decoration: none;
}

.kb-aac__diff {
	display: inline-block;
	margin-top: 0.3em;
	padding: 0.05em 0.7em;
	border-radius: var(--kb-aac-btn-radius);
	font-size: 0.82em;
	font-weight: 600;
	line-height: 1.6;
}

.kb-aac__diff--down {
	background: rgba(22, 163, 74, 0.14);
	color: #15803d;
}

.kb-aac__diff--up {
	background: rgba(234, 88, 12, 0.14);
	color: #c2410c;
}

.kb-aac__diff--same {
	background: rgba(127, 127, 127, 0.16);
}

.kb-aac__empty {
	opacity: 0.5;
}

.kb-aac__count {
	opacity: 0.7;
	font-size: 0.92em;
}

/* Group headings. */
.kb-aac .kb-aac__table .kb-aac__group th {
	padding-top: 1.6em;
	padding-bottom: 0.6em;
	background: transparent;
	color: var(--kb-aac-title);
	font-size: 1.08em;
	font-weight: 700;
}

.kb-aac .kb-aac__table .kb-aac__group th::before {
	content: "";
	display: inline-block;
	width: 4px;
	height: 1em;
	margin-inline-end: 0.6em;
	border-radius: 2px;
	background: var(--kb-aac-accent);
	vertical-align: -0.15em;
}

/* "Show differences only". */
.kb-aac--diff-only tr[data-same="1"] {
	display: none;
}

.kb-aac__note {
	margin: 0.75em 0 0;
	font-size: 0.88em;
	opacity: 0.75;
}

/* Stars (CSS only; the fill is data-r = rating x 10 in half steps). */
.kb-aac__stars {
	position: relative;
	display: inline-block;
	direction: ltr;
	color: rgba(127, 127, 127, 0.4);
	font-size: 15px;
	letter-spacing: 1px;
	line-height: 1;
	vertical-align: middle;
	white-space: nowrap;
}

.kb-aac__stars::before {
	content: "\2605\2605\2605\2605\2605";
}

.kb-aac__stars::after {
	content: "\2605\2605\2605\2605\2605";
	position: absolute;
	top: 0;
	left: 0;
	width: 0;
	overflow: hidden;
	color: var(--kb-aac-star);
}

.kb-aac__stars[data-r="5"]::after { width: 10%; }
.kb-aac__stars[data-r="10"]::after { width: 20%; }
.kb-aac__stars[data-r="15"]::after { width: 30%; }
.kb-aac__stars[data-r="20"]::after { width: 40%; }
.kb-aac__stars[data-r="25"]::after { width: 50%; }
.kb-aac__stars[data-r="30"]::after { width: 60%; }
.kb-aac__stars[data-r="35"]::after { width: 70%; }
.kb-aac__stars[data-r="40"]::after { width: 80%; }
.kb-aac__stars[data-r="45"]::after { width: 90%; }
.kb-aac__stars[data-r="50"]::after { width: 100%; }

@media (max-width: 640px) {
	.kb-aac {
		margin: 20px 0;
		font-size: 13px;
	}

	.kb-aac--card {
		padding: 18px 14px;
	}


	.kb-aac .kb-aac__table th,
	.kb-aac .kb-aac__table td {
		padding: 0.7em 0.75em;
	}

	.kb-aac .kb-aac__table .kb-aac__product,
	.kb-aac .kb-aac__table .kb-aac__cell {
		min-width: 10.5em;
	}
}

@media (prefers-reduced-motion: reduce) {
	.kb-aac a.kb-aac__btn {
		transition: none;
	}

	.kb-aac__skel {
		animation: none;
	}
}

/* Centered data and product headers (the label column keeps the reading direction). */
.kb-aac .kb-aac__table .kb-aac__cell,
.kb-aac .kb-aac__table .kb-aac__product {
	text-align: center;
}

.kb-aac .kb-aac__table .kb-aac__hrow--image > .kb-aac__product {
	text-align: center;
}

.kb-aac .kb-aac__badge {
	margin-inline: 0.2em;
}

/* Vertical dividers: every product column is separated from the next one. */
.kb-aac .kb-aac__table .kb-aac__product,
.kb-aac .kb-aac__table .kb-aac__cell {
	border-inline-start: 1px solid var(--kb-aac-line);
}

/* Group heading rows span all columns: no divider there. */
.kb-aac .kb-aac__table .kb-aac__group th {
	border-inline-start: 0;
}

/*
 * Price: the currency always follows the amount in reading order (Persian: "7,600,000 Toman"), whatever
 * the theme's direction rules or the markup order are. The direction is forced and the symbol is ordered last.
 */
.kb-aac--rtl .kb-aac__price .woocommerce-Price-amount,
.kb-aac--rtl .kb-aac__price .woocommerce-Price-amount bdi {
	display: inline-flex;
	flex-direction: row;
	align-items: baseline;
	gap: 0.3em;
	direction: rtl;
	unicode-bidi: isolate;
	white-space: nowrap;
}

.kb-aac--rtl .kb-aac__price .woocommerce-Price-currencySymbol {
	order: 2;
}

/* Sticky product column: the product being viewed stays in view next to the label column. */
.kb-aac .kb-aac__table .kb-aac__product.is-current,
.kb-aac .kb-aac__table .kb-aac__cell.is-current {
	position: sticky;
	inset-inline-start: var(--kb-aac-label-w);
	z-index: 1;
	background: linear-gradient(var(--kb-aac-soft), var(--kb-aac-soft)), var(--kb-aac-surface);
	border-inline-end: 1px solid var(--kb-aac-line);
}

.kb-aac .kb-aac__table .kb-aac__row.is-alt > .kb-aac__cell.is-current {
	background: linear-gradient(var(--kb-aac-soft), var(--kb-aac-soft)), linear-gradient(var(--kb-aac-zebra), var(--kb-aac-zebra)), var(--kb-aac-surface);
}

/* Phones: label column + the main product + at least one more product fit on screen. */
@media (max-width: 640px) {
	.kb-aac {
		--kb-aac-label-w: 62px;
	}

	.kb-aac .kb-aac__table th,
	.kb-aac .kb-aac__table td {
		padding: 0.6em 0.45em;
	}

	.kb-aac .kb-aac__table .kb-aac__label {
		font-size: 0.85em;
		line-height: 1.4;
		overflow-wrap: anywhere;
	}

	.kb-aac .kb-aac__table .kb-aac__product,
	.kb-aac .kb-aac__table .kb-aac__cell {
		width: 8em;
		min-width: 8em;
		max-width: 8em;
	}

	.kb-aac .kb-aac__table .kb-aac__img {
		max-width: 90px;
	}

	.kb-aac a.kb-aac__btn {
		padding: 0.4em 0.6em;
		font-size: 0.85em;
		white-space: nowrap;
	}

	.kb-aac .kb-aac__badge {
		margin-inline: 0;
	}
}

/* Exact column width from the measured scroll width (set by the script); the 8em above is the fallback. */
@media (max-width: 640px) {
	.kb-aac[style*="--kb-aac-vw"] .kb-aac__table .kb-aac__product,
	.kb-aac[style*="--kb-aac-vw"] .kb-aac__table .kb-aac__cell {
		width: calc((var(--kb-aac-vw) - var(--kb-aac-label-w)) / 2);
		min-width: calc((var(--kb-aac-vw) - var(--kb-aac-label-w)) / 2);
		max-width: calc((var(--kb-aac-vw) - var(--kb-aac-label-w)) / 2);
	}
}

/*
 * Safari / iOS: sticky table cells can stay blank (white) after a scroll until the page is scrolled again.
 * Promoting them to their own compositing layer makes WebKit paint them reliably.
 */
.kb-aac .kb-aac__table .kb-aac__label,
.kb-aac .kb-aac__table .kb-aac__product.is-current,
.kb-aac .kb-aac__table .kb-aac__cell.is-current {
	-webkit-transform: translateZ(0);
	transform: translateZ(0);
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
}
