/**
 * Amazon Comparison Table, Bestseller Grid/List, and Product Card Styles
 *
 * BEM with afh- prefix. Responsive, accessible, print-friendly.
 * CSS-only star rating (same --rating technique as product-box.css).
 *
 * @package AffiliateHub
 * @subpackage Modules\AmazonProducts
 */

/* ==========================================================================
   Shared: Box-sizing Reset
   ========================================================================== */

.afh-comparison,
.afh-comparison *,
.afh-comparison *::before,
.afh-comparison *::after,
.afh-bestsellers,
.afh-bestsellers *,
.afh-bestsellers *::before,
.afh-bestsellers *::after,
.afh-product-card,
.afh-product-card *,
.afh-product-card *::before,
.afh-product-card *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   Comparison Table
   ========================================================================== */

.afh-comparison {
	margin: 1.5em 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: #1a1a1a;
}

.afh-comparison__title {
	margin: 0 0 1rem;
	font-size: 1.25rem;
	font-weight: 700;
	color: #0f1111;
}

.afh-comparison__wrapper {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
}

.afh-comparison__table {
	width: 100%;
	min-width: 500px;
	border-collapse: collapse;
	background: #fff;
}

.afh-comparison__table th,
.afh-comparison__table td {
	padding: 0.75rem 1rem;
	text-align: center;
	vertical-align: middle;
	border-bottom: 1px solid #f0f0f0;
}

/* Corner cell (top-left empty) */
.afh-comparison__corner {
	width: 140px;
	min-width: 120px;
	background: #fafafa;
}

/* Product header cells */
.afh-comparison__product-header {
	padding: 1rem;
	background: #fafafa;
	border-left: 1px solid #f0f0f0;
	vertical-align: top;
}

.afh-comparison__product-header--highlight {
	background: #fff8e1;
	border-left: 2px solid #ff9900;
	border-right: 2px solid #ff9900;
	border-top: 2px solid #ff9900;
}

.afh-comparison__badge {
	display: inline-block;
	padding: 0.15em 0.6em;
	margin-bottom: 0.5rem;
	border-radius: 3px;
	background: #ff9900;
	color: #0f1111;
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.afh-comparison__product-image {
	display: block;
	width: 120px;
	height: 120px;
	margin: 0.5rem auto;
	object-fit: contain;
	border-radius: 4px;
	background: #fff;
}

.afh-comparison__product-name {
	display: block;
	margin-top: 0.5rem;
	font-size: 0.85rem;
	font-weight: 600;
	color: #0f1111;
	line-height: 1.3;
	overflow-wrap: break-word;
	word-break: break-word;
}

/* Image placeholder (when no image available) */
.afh-comparison__image-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 120px;
	height: 120px;
	margin: 0.5rem auto;
	background: #f5f5f5;
	border-radius: 4px;
}

/* CSS-only box icon for image placeholder */
.afh-comparison__placeholder-icon {
	display: inline-block;
	width: 32px;
	height: 28px;
	border: 2px solid #ccc;
	border-radius: 3px;
	position: relative;
	background: transparent;
}

.afh-comparison__placeholder-icon::before {
	content: "";
	position: absolute;
	bottom: 3px;
	left: 3px;
	width: 0;
	height: 0;
	border-left: 6px solid transparent;
	border-right: 6px solid transparent;
	border-bottom: 8px solid #ccc;
}

.afh-comparison__placeholder-icon::after {
	content: "";
	position: absolute;
	top: 4px;
	right: 4px;
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: #ccc;
}

/* Stub product name: italic grey */
.afh-comparison__product-name--stub {
	font-style: italic;
	color: #888;
	font-weight: 400;
}

/* Row labels */
.afh-comparison__label {
	text-align: left;
	font-weight: 600;
	background: #fafafa;
	color: #555;
	font-size: 0.85rem;
	white-space: nowrap;
}

/* Data cells */
.afh-comparison__cell {
	border-left: 1px solid #f0f0f0;
}

.afh-comparison__cell--highlight {
	background: #fffdf5;
	border-left: 2px solid #ff9900;
	border-right: 2px solid #ff9900;
}

.afh-comparison__cell-na {
	color: #999;
}

/* Pricing in comparison */
.afh-comparison__price {
	font-size: 1.1rem;
	font-weight: 700;
	color: #0f1111;
}

.afh-comparison__price--stale {
	color: #6b6b6b;
}

.afh-comparison__original-price {
	display: block;
	font-size: 0.8rem;
	color: #888;
	text-decoration: line-through;
}

.afh-comparison__price-notice {
	display: block;
	font-size: 0.7rem;
	color: #888;
	font-style: italic;
	margin-top: 0.15rem;
}

.afh-comparison__price-na {
	font-size: 0.85rem;
	color: #007185;
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}

.afh-comparison__price-na:hover {
	color: #c7511f;
	text-decoration: underline;
}

/* Stub rating: italic grey "No data" */
.afh-comparison__rating-na {
	font-size: 0.8rem;
	font-style: italic;
	color: #999;
}

/* Star rating in comparison (reuses --rating technique) */
.afh-comparison__rating {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
}

.afh-comparison__stars {
	position: relative;
	display: inline-block;
	width: 5.4em;
	height: 1.1em;
	font-size: 0.8rem;
	line-height: 1;
	letter-spacing: 0.15em;
	overflow: hidden;
}

.afh-comparison__stars::before {
	content: "\2605\2605\2605\2605\2605";
	color: #ddd;
}

.afh-comparison__stars::after {
	content: "\2605\2605\2605\2605\2605";
	position: absolute;
	top: 0;
	left: 0;
	overflow: hidden;
	white-space: nowrap;
	color: #ffa41c;
	width: calc(var(--rating, 0) / 5 * 100%);
}

.afh-comparison__rating-count {
	font-size: 0.75rem;
	color: #007185;
}

/* Prime badge in comparison */
.afh-comparison__prime {
	display: inline-flex;
	align-items: center;
	gap: 0.2rem;
	font-size: 0.75rem;
	font-weight: 700;
	color: #00a8e1;
}

.afh-comparison__prime-icon {
	display: inline-block;
	width: 0.7em;
	height: 0.7em;
	border-radius: 50%;
	background: #00a8e1;
	position: relative;
}

.afh-comparison__prime-icon::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -55%) rotate(-45deg);
	width: 0.35em;
	height: 0.2em;
	border-left: 1.5px solid #fff;
	border-bottom: 1.5px solid #fff;
}

/* Features text */
.afh-comparison__features {
	display: block;
	font-size: 0.8rem;
	color: #555;
	line-height: 1.4;
	text-align: left;
	max-height: 4.2em;
	overflow: hidden;
}

/* CTA row */
.afh-comparison__row--cta td {
	padding: 1rem;
	border-bottom: none;
}

.afh-comparison__row--cta .afh-comparison__cell--highlight {
	border-bottom: 2px solid #ff9900;
}

.afh-comparison__cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	max-width: 220px;
	min-height: 42px;
	padding: 10px 20px;
	border: none;
	border-radius: 8px;
	background: #ff9900;
	color: #0f1111;
	font-size: 0.9rem;
	font-weight: 700;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition: filter 0.15s ease, transform 0.1s ease;
	line-height: 1.3;
}

.afh-comparison__cta:hover {
	filter: brightness(0.9);
	color: #0f1111;
	text-decoration: none;
}

.afh-comparison__cta:active {
	transform: scale(0.98);
}

.afh-comparison__cta:focus-visible {
	outline: 2px solid #ff9900;
	outline-offset: 2px;
}

/* Disclosure */
.afh-comparison__disclosure {
	margin-top: 0.75rem;
	font-size: 0.7rem;
	color: #999;
	line-height: 1.4;
}

/* ==========================================================================
   Bestseller List / Grid
   ========================================================================== */

.afh-bestsellers {
	margin: 1.5em 0;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: #1a1a1a;
}

.afh-bestsellers__title {
	margin: 0 0 1rem;
	font-size: 1.25rem;
	font-weight: 700;
	color: #0f1111;
}

/* Grid layout */
.afh-bestsellers__grid {
	display: grid;
	gap: 1.25rem;
}

.afh-bestsellers__grid--cols-1 { grid-template-columns: 1fr; }
.afh-bestsellers__grid--cols-2 { grid-template-columns: repeat(2, 1fr); }
.afh-bestsellers__grid--cols-3 { grid-template-columns: repeat(3, 1fr); }
.afh-bestsellers__grid--cols-4 { grid-template-columns: repeat(4, 1fr); }
.afh-bestsellers__grid--cols-5 { grid-template-columns: repeat(5, 1fr); }
.afh-bestsellers__grid--cols-6 { grid-template-columns: repeat(6, 1fr); }

/* List layout (vertical stack) */
.afh-bestsellers__list {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.afh-bestsellers__list .afh-product-card {
	flex-direction: row;
	max-width: 100%;
}

.afh-bestsellers__list .afh-product-card__image {
	flex: 0 0 100px;
	max-width: 100px;
}

.afh-bestsellers__list .afh-product-card__body {
	flex: 1 1 0%;
	min-width: 0;
}

.afh-bestsellers__list .afh-product-card__cta {
	flex: 0 0 auto;
	align-self: center;
}

/* Bestseller item wrapper */
.afh-bestsellers__item {
	position: relative;
}

/* Rank badge */
.afh-bestsellers__rank {
	position: absolute;
	top: -6px;
	left: -6px;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: #232f3e;
	color: #fff;
	font-size: 0.75rem;
	font-weight: 700;
	line-height: 1;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Disclosure */
.afh-bestsellers__disclosure {
	margin-top: 0.75rem;
	font-size: 0.7rem;
	color: #999;
	line-height: 1.4;
}

/* ==========================================================================
   Product Card (compact card for grids and lists)
   ========================================================================== */

.afh-product-card {
	position: relative;
	display: flex;
	flex-direction: column;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	overflow: hidden;
	transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.afh-product-card:hover {
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
	transform: translateY(-2px);
}

/* Image area */
.afh-product-card__image {
	position: relative;
	overflow: hidden;
	background: #fafafa;
}

.afh-product-card__image a {
	display: block;
}

.afh-product-card__image img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 1 / 1;
	object-fit: contain;
	padding: 0.75rem;
}

.afh-product-card__image-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 1 / 1;
	background: #f5f5f5;
	color: #999;
	font-size: 0.8rem;
	text-align: center;
}

/* CSS-only box icon for card image placeholder */
.afh-product-card__placeholder-icon {
	display: inline-block;
	width: 32px;
	height: 28px;
	border: 2px solid #ccc;
	border-radius: 3px;
	position: relative;
	background: transparent;
}

.afh-product-card__placeholder-icon::before {
	content: "";
	position: absolute;
	bottom: 3px;
	left: 3px;
	width: 0;
	height: 0;
	border-left: 6px solid transparent;
	border-right: 6px solid transparent;
	border-bottom: 8px solid #ccc;
}

.afh-product-card__placeholder-icon::after {
	content: "";
	position: absolute;
	top: 4px;
	right: 4px;
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: #ccc;
}

/* Discount badge (overlays image) */
.afh-product-card__badge {
	position: absolute;
	top: 8px;
	right: 8px;
	display: inline-block;
	padding: 0.15em 0.5em;
	border-radius: 3px;
	background: #cc0c39;
	color: #fff;
	font-size: 0.75rem;
	font-weight: 700;
	line-height: 1.3;
	z-index: 1;
}

/* Body */
.afh-product-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	padding: 0.75rem;
	flex: 1 1 auto;
}

.afh-product-card__title {
	margin: 0;
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.3;
	color: #0f1111;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	overflow-wrap: break-word;
	word-break: break-word;
}

.afh-product-card__title a {
	color: inherit;
	text-decoration: none;
}

.afh-product-card__title a:hover {
	color: #c7511f;
	text-decoration: underline;
}

/* Pricing */
.afh-product-card__price {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.35rem;
}

.afh-product-card__current-price {
	font-size: 1.1rem;
	font-weight: 700;
	color: #0f1111;
}

.afh-product-card__current-price--stale {
	color: #6b6b6b;
}

.afh-product-card__original-price {
	font-size: 0.8rem;
	color: #888;
	text-decoration: line-through;
}

/* Stub title: italic grey for products awaiting API data */
.afh-product-card__title--stub,
.afh-product-card__title--stub a {
	font-style: italic;
	color: #888;
}

.afh-product-card__title--stub a:hover {
	color: #007185;
}

/* "Check Amazon" clickable link when price is unavailable */
.afh-product-card__price-na {
	font-size: 0.85rem;
	font-weight: 600;
	color: #007185;
	text-decoration: none;
	cursor: pointer;
}

.afh-product-card__price-na:hover {
	color: #c7511f;
	text-decoration: underline;
}

/* "No data" for stub ratings */
.afh-product-card__rating-na {
	font-size: 0.75rem;
	font-style: italic;
	color: #999;
}

/* Star rating (same --rating technique) */
.afh-product-card__rating {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
}

.afh-product-card__stars {
	position: relative;
	display: inline-block;
	width: 5.4em;
	height: 1.1em;
	font-size: 0.75rem;
	line-height: 1;
	letter-spacing: 0.15em;
	overflow: hidden;
}

.afh-product-card__stars::before {
	content: "\2605\2605\2605\2605\2605";
	color: #ddd;
}

.afh-product-card__stars::after {
	content: "\2605\2605\2605\2605\2605";
	position: absolute;
	top: 0;
	left: 0;
	overflow: hidden;
	white-space: nowrap;
	color: #ffa41c;
	width: calc(var(--rating, 0) / 5 * 100%);
}

.afh-product-card__rating-count {
	font-size: 0.7rem;
	color: #007185;
}

/* Prime badge */
.afh-product-card__prime {
	display: inline-flex;
	align-items: center;
	gap: 0.2rem;
	font-size: 0.7rem;
	font-weight: 700;
	color: #00a8e1;
}

.afh-product-card__prime-icon {
	display: inline-block;
	width: 0.65em;
	height: 0.65em;
	border-radius: 50%;
	background: #00a8e1;
	position: relative;
}

.afh-product-card__prime-icon::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -55%) rotate(-45deg);
	width: 0.3em;
	height: 0.18em;
	border-left: 1.5px solid #fff;
	border-bottom: 1.5px solid #fff;
}

/* CTA area */
.afh-product-card__cta {
	padding: 0 0.75rem 0.75rem;
}

.afh-product-card__button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: 40px;
	padding: 8px 16px;
	border: none;
	border-radius: 8px;
	background: #ff9900;
	color: #0f1111;
	font-size: 0.85rem;
	font-weight: 700;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition: filter 0.15s ease, transform 0.1s ease;
	line-height: 1.3;
}

.afh-product-card__button:hover {
	filter: brightness(0.9);
	color: #0f1111;
	text-decoration: none;
}

.afh-product-card__button:active {
	transform: scale(0.98);
}

.afh-product-card__button:focus-visible {
	outline: 2px solid #ff9900;
	outline-offset: 2px;
}

/* ==========================================================================
   Responsive: Tablet (< 768px)
   ========================================================================== */

@media (max-width: 768px) {
	/* Comparison table: horizontal scroll is handled by .afh-comparison__wrapper */

	/* Reduce bestseller grid columns */
	.afh-bestsellers__grid--cols-4,
	.afh-bestsellers__grid--cols-5,
	.afh-bestsellers__grid--cols-6 {
		grid-template-columns: repeat(3, 1fr);
	}
}

/* ==========================================================================
   Responsive: Mobile (< 600px)
   ========================================================================== */

@media (max-width: 600px) {
	/* Bestseller grid: 2 columns max */
	.afh-bestsellers__grid--cols-3,
	.afh-bestsellers__grid--cols-4,
	.afh-bestsellers__grid--cols-5,
	.afh-bestsellers__grid--cols-6 {
		grid-template-columns: repeat(2, 1fr);
	}

	/* Comparison: smaller header images */
	.afh-comparison__product-image {
		width: 80px;
		height: 80px;
	}

	.afh-comparison__table th,
	.afh-comparison__table td {
		padding: 0.5rem 0.6rem;
		font-size: 0.8rem;
	}

	.afh-comparison__product-name {
		font-size: 0.75rem;
	}

	.afh-comparison__cta {
		padding: 8px 12px;
		font-size: 0.8rem;
	}

	/* Bestseller list: stack cards */
	.afh-bestsellers__list .afh-product-card {
		flex-direction: column;
	}

	.afh-bestsellers__list .afh-product-card__image {
		flex: none;
		max-width: 100%;
	}

	.afh-bestsellers__list .afh-product-card__cta {
		align-self: stretch;
	}
}

/* ==========================================================================
   Responsive: Small Mobile (< 480px)
   ========================================================================== */

@media (max-width: 480px) {
	/* All grids to 1 column */
	.afh-bestsellers__grid--cols-2,
	.afh-bestsellers__grid--cols-3,
	.afh-bestsellers__grid--cols-4,
	.afh-bestsellers__grid--cols-5,
	.afh-bestsellers__grid--cols-6 {
		grid-template-columns: 1fr;
	}

	/* Rank badge smaller */
	.afh-bestsellers__rank {
		width: 24px;
		height: 24px;
		font-size: 0.65rem;
		top: -4px;
		left: -4px;
	}
}

/* ==========================================================================
   Comparison Cards Layout
   ========================================================================== */

.afh-comparison--cards .afh-comparison-cards__grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
	gap: 1.25rem;
}

.afh-comparison-cards__item {
	position: relative;
}

.afh-comparison-cards__item--highlight {
	border: 2px solid #ff9900;
	border-radius: 8px;
	background: #fffdf5;
}

.afh-comparison-cards__item--highlight .afh-product-card {
	border-color: transparent;
}

.afh-comparison-cards__badge {
	position: absolute;
	top: -10px;
	left: 16px;
	z-index: 2;
	display: inline-block;
	padding: 0.15em 0.6em;
	border-radius: 3px;
	background: #ff9900;
	color: #0f1111;
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	line-height: 1.3;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Cards layout responsive: Tablet */
@media (max-width: 768px) {
	.afh-comparison--cards .afh-comparison-cards__grid {
		grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	}
}

/* Cards layout responsive: Mobile */
@media (max-width: 600px) {
	.afh-comparison--cards .afh-comparison-cards__grid {
		grid-template-columns: repeat(2, 1fr);
		gap: 0.75rem;
	}
}

/* Cards layout responsive: Small Mobile */
@media (max-width: 480px) {
	.afh-comparison--cards .afh-comparison-cards__grid {
		grid-template-columns: 1fr;
	}
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.afh-comparison {
		page-break-inside: avoid;
	}

	.afh-comparison__wrapper {
		overflow: visible;
		border: 1px solid #ccc;
	}

	.afh-comparison__table {
		min-width: 0;
	}

	.afh-comparison__cta,
	.afh-product-card__button {
		display: none;
	}

	.afh-comparison__row--cta {
		display: none;
	}

	.afh-comparison__product-header--highlight {
		background: #f5f5f5;
		border-color: #999;
	}

	.afh-comparison__cell--highlight {
		background: #fafafa;
		border-color: #999;
	}

	.afh-comparison__disclosure,
	.afh-bestsellers__disclosure {
		display: block;
		color: #555;
	}

	.afh-product-card {
		box-shadow: none;
		border: 1px solid #ccc;
		page-break-inside: avoid;
	}

	.afh-product-card:hover {
		box-shadow: none;
		transform: none;
	}

	.afh-product-card__title a::after {
		content: " (" attr(href) ")";
		font-size: 0.7rem;
		font-weight: 400;
		color: #666;
		word-break: break-all;
	}

	.afh-product-card__badge,
	.afh-comparison__badge,
	.afh-comparison-cards__badge {
		border: 1px solid currentColor;
		background: none;
		color: #333;
	}

	.afh-comparison-cards__item--highlight {
		border-color: #999;
		background: #fafafa;
	}

	.afh-bestsellers__rank {
		background: none;
		color: #333;
		border: 1px solid #333;
		box-shadow: none;
	}
}
