/**
 * components.css
 * Generic, reusable UI primitives shared across the whole theme (buttons,
 * cards, badges, forms, icon buttons, ratings, pagination, empty states).
 * Header/footer/nav-specific chrome (sticky behaviour, offcanvas menu,
 * mini-cart) is styled in header.css / footer.css during Phase 3.
 */

/* ---------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------- */
.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	padding: 14px 28px;
	font-size: var(--font-size-small);
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	border-radius: var(--radius-sm);
	border: 1px solid transparent;
	cursor: pointer;
	transition:
		background-color var(--duration-base) var(--ease-standard),
		border-color var(--duration-base) var(--ease-standard),
		color var(--duration-base) var(--ease-standard),
		opacity var(--duration-base) var(--ease-standard),
		transform var(--duration-base) var(--ease-standard);
}

.button:active {
	transform: scale(0.98);
}

.button--primary {
	background-color: var(--color-accent);
	color: var(--color-accent-text);
}

.button--primary:hover {
	background-color: var(--color-accent-hover);
}

.button--secondary {
	background-color: transparent;
	color: var(--color-text);
	border-color: var(--color-border);
}

.button--secondary:hover {
	border-color: var(--color-text-secondary);
}

.button--ghost {
	background-color: transparent;
	color: var(--color-text-secondary);
	padding: 8px 12px;
}

.button--ghost:hover {
	color: var(--color-text);
}

.button--full {
	width: 100%;
}

.button--sm {
	padding: 10px 18px;
}

.button:disabled,
.button[aria-disabled="true"] {
	opacity: 0.45;
	cursor: not-allowed;
	pointer-events: none;
}

/* Loading state: dims label, shows a small inline spinner via ::after. */
.button.is-loading {
	position: relative;
	color: transparent !important;
	pointer-events: none;
}

.button.is-loading::after {
	content: "";
	position: absolute;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	border: 2px solid currentColor;
	border-top-color: transparent;
	color: var(--color-accent-text);
	animation: darkcommerce-spin 0.6s linear infinite;
}

.button--secondary.is-loading::after,
.button--ghost.is-loading::after {
	color: var(--color-text);
}

@keyframes darkcommerce-spin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.button.is-loading::after {
		animation-duration: 1.5s;
	}
}

.button.is-success {
	background-color: var(--color-success);
	border-color: var(--color-success);
	/* White text on this green was only 2.28:1 — fails AA even for large
	   text. Dark text reaches 8.63:1 (§22). */
	color: var(--color-accent-text);
}

/* ---------------------------------------------------------------
 * Icon button — header actions, quantity stepper, mini-cart controls.
 * ------------------------------------------------------------- */
.icon-button {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: var(--radius-sm);
	color: var(--color-text);
	transition: background-color var(--duration-base) var(--ease-standard);
}

.icon-button:hover {
	background-color: var(--color-surface-2);
}

.icon-button svg {
	width: 20px;
	height: 20px;
}

.cart-count {
	position: absolute;
	top: 2px;
	right: 2px;
	min-width: 16px;
	height: 16px;
	padding-inline: 3px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 10px;
	font-weight: 700;
	line-height: 1;
	background-color: var(--color-accent);
	color: var(--color-accent-text);
	border-radius: var(--radius-full);
}

.cart-count:empty,
.cart-count[data-count="0"] {
	display: none;
}

/* ---------------------------------------------------------------
 * Cards — generic surface card used as the base for product cards,
 * category tiles, and blog post cards (each extends this).
 * ------------------------------------------------------------- */
.card {
	background-color: var(--color-surface);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-md);
	overflow: hidden;
	transition:
		border-color var(--duration-base) var(--ease-standard),
		transform var(--duration-base) var(--ease-standard);
}

.card:hover {
	border-color: var(--color-text-muted);
}

/* ---------------------------------------------------------------
 * Badges — sale / new / out-of-stock / discount percentage (§10).
 * ------------------------------------------------------------- */
.badge {
	display: inline-flex;
	align-items: center;
	padding: 4px 10px;
	font-size: var(--font-size-xs);
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	border-radius: var(--radius-sm);
	background-color: var(--color-surface-2);
	color: var(--color-text);
}

.badge--sale {
	/* A solid red fill only reaches 3.76:1 with white text — below AA for
	   text this small (§22). A tinted background with --color-danger as
	   the text color keeps the same "sale" association at ~5:1 contrast,
	   and reads as calmer / more premium than a loud solid block (§4). */
	background-color: rgba(239, 68, 68, 0.14);
	color: var(--color-danger);
}

.badge--new {
	background-color: var(--color-text);
	color: var(--color-bg);
}

.badge--out-of-stock {
	background-color: transparent;
	border: 1px solid var(--color-border);
	color: var(--color-text-muted);
}

.badge-group {
	position: absolute;
	top: var(--space-2);
	left: var(--space-2);
	display: flex;
	flex-direction: column;
	gap: 4px;
	z-index: 1;
}

/* ---------------------------------------------------------------
 * Rating stars (§10, §12) — accessible: visually renders SVG stars,
 * screen readers get the text label instead.
 * ------------------------------------------------------------- */
.rating {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.rating__stars {
	display: inline-flex;
	gap: 2px;
	color: var(--color-text-muted);
}

.rating__stars svg {
	width: 14px;
	height: 14px;
}

.rating__stars .is-filled {
	color: var(--color-text);
}

.rating__count {
	font-size: var(--font-size-xs);
	color: var(--color-text-muted);
}

/* ---------------------------------------------------------------
 * Forms — inputs, selects, textareas, checkboxes, quantity stepper.
 * ------------------------------------------------------------- */
label {
	display: block;
	font-size: var(--font-size-small);
	font-weight: 500;
	color: var(--color-text);
	margin-bottom: var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
	width: 100%;
	padding: 12px 14px;
	background-color: var(--color-surface);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	color: var(--color-text);
	transition: border-color var(--duration-base) var(--ease-standard);
}

input::placeholder,
textarea::placeholder {
	color: var(--color-text-muted);
}

input:hover,
select:hover,
textarea:hover {
	border-color: var(--color-text-muted);
}

input:focus,
select:focus,
textarea:focus {
	border-color: var(--color-text);
	outline: none;
}

textarea {
	min-height: 120px;
	resize: vertical;
}

.form-row {
	margin-bottom: var(--space-3);
}

.form-row--split {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--space-3);
}

@media (max-width: 480px) {
	.form-row--split {
		grid-template-columns: 1fr;
	}
}

/* Checkbox / radio: keep native control but recolor via accent-color,
   which every evergreen browser now supports without a JS/CSS hack. */
input[type="checkbox"],
input[type="radio"] {
	width: 18px;
	height: 18px;
	accent-color: var(--color-accent);
}

/* Native <input type="submit"> — WordPress core forms (get_search_form(),
   some widgets) render a submit button this way instead of a <button>
   with a class we can already target via .button. Without this, it
   falls back to unstyled browser-default button chrome (light gray,
   clashing hard with the dark theme). */
input[type="submit"] {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 12px 20px;
	background-color: var(--color-accent);
	color: var(--color-accent-text);
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	font-size: var(--font-size-small);
	font-weight: 600;
	cursor: pointer;
	transition: background-color var(--duration-base) var(--ease-standard);
}

input[type="submit"]:hover {
	background-color: var(--color-accent-hover);
}

.search-form {
	display: flex;
	gap: var(--space-2);
}

.search-form .search-field {
	flex: 1;
}

/* Quantity stepper used on product page / cart / mini-cart. */
.quantity-stepper {
	display: inline-flex;
	align-items: center;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.quantity-stepper button {
	width: 36px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--color-text-secondary);
	transition: background-color var(--duration-base) var(--ease-standard);
}

.quantity-stepper button:hover {
	background-color: var(--color-surface-2);
	color: var(--color-text);
}

.quantity-stepper button svg {
	width: 14px;
	height: 14px;
}

.quantity-stepper input {
	width: 44px;
	height: 40px;
	padding: 0;
	text-align: center;
	border: none;
	border-left: 1px solid var(--color-border);
	border-right: 1px solid var(--color-border);
	border-radius: 0;
	-moz-appearance: textfield;
}

.quantity-stepper input::-webkit-outer-spin-button,
.quantity-stepper input::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

/* ---------------------------------------------------------------
 * Pagination (used by darkcommerce_pagination() in
 * inc/template-functions.php).
 * ------------------------------------------------------------- */
.pagination {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
	margin-top: var(--space-5);
}

.pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 40px;
	height: 40px;
	padding-inline: 8px;
	border-radius: var(--radius-sm);
	color: var(--color-text-secondary);
	font-size: var(--font-size-small);
	transition: background-color var(--duration-base) var(--ease-standard), color var(--duration-base) var(--ease-standard);
}

.pagination .page-numbers:hover {
	background-color: var(--color-surface-2);
	color: var(--color-text);
}

.pagination .page-numbers.current {
	background-color: var(--color-accent);
	color: var(--color-accent-text);
}

.pagination .page-numbers svg {
	width: 16px;
	height: 16px;
}

/* ---------------------------------------------------------------
 * Empty state (404, no search results, empty cart).
 * ------------------------------------------------------------- */
.empty-state {
	text-align: center;
	padding-block: var(--space-6);
	max-width: 480px;
	margin-inline: auto;
}

.empty-state__eyebrow {
	font-size: var(--font-size-h2);
	font-weight: 700;
	color: var(--color-border);
	margin-bottom: var(--space-2);
}

.empty-state__title {
	font-size: var(--font-size-h3);
	margin-bottom: var(--space-2);
}

.empty-state__description {
	margin-bottom: var(--space-4);
}

.empty-state__actions {
	display: flex;
	gap: var(--space-2);
	justify-content: center;
	flex-wrap: wrap;
	margin-bottom: var(--space-4);
}

.empty-state__search {
	max-width: 360px;
	margin-inline: auto;
}

/* ---------------------------------------------------------------
 * Blog post card (template-parts/content/content.php)
 * ------------------------------------------------------------- */
.post-card {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.post-card__thumbnail {
	border-radius: var(--radius-md);
	overflow: hidden;
	aspect-ratio: 16 / 9;
}

.post-card__thumbnail img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.post-card__title a {
	transition: color var(--duration-base) var(--ease-standard);
}

.post-card__title a:hover {
	color: var(--color-text-secondary);
}

.post-card__meta {
	font-size: var(--font-size-small);
	color: var(--color-text-muted);
}

.post-card__excerpt {
	color: var(--color-text-secondary);
}

/* ---------------------------------------------------------------
 * Page content (template-parts/content/content-page.php)
 * ------------------------------------------------------------- */
.page-content__header {
	margin-bottom: var(--space-4);
}

.page-content__thumbnail {
	border-radius: var(--radius-md);
	overflow: hidden;
	margin-bottom: var(--space-4);
}

.page-content__body > * + * {
	margin-top: var(--space-3);
}

.page-content__body img {
	border-radius: var(--radius-md);
}

.archive-header {
	margin-bottom: var(--space-5);
}

.archive-header__title {
	margin-bottom: var(--space-2);
}

/* ---------------------------------------------------------------
 * Comments (comments.php)
 * ------------------------------------------------------------- */
.comments-area {
	margin-top: var(--space-6);
	padding-top: var(--space-5);
	border-top: 1px solid var(--color-border);
}

.comments-area__title {
	margin-bottom: var(--space-4);
}

.comment-list > li {
	padding: var(--space-3) 0;
	border-bottom: 1px solid var(--color-border);
}

.comment-form .form-row {
	margin-bottom: var(--space-3);
}

/* ---------------------------------------------------------------
 * Product card (template-parts/components/product-card.php)
 * Shared by the homepage, shop/category archive (Phase 5), and related
 * products (Phase 6) — styled once here rather than per-context.
 * Client-requested: 3 columns on desktop (was 4).
 * ------------------------------------------------------------- */
.product-grid,
ul.products {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--space-3);
}

@media (max-width: 900px) {
	.product-grid,
	ul.products {
		grid-template-columns: repeat(2, 1fr);
	}
}

@media (max-width: 600px) {
	/* Client-requested change: one product per row on phones instead of
	   two — two columns felt cramped at phone widths in practice. */
	.product-grid,
	ul.products {
		grid-template-columns: 1fr;
	}
}

.product-card {
	display: flex;
	flex-direction: column;
}

.product-card__media {
	position: relative;
	aspect-ratio: 4 / 5;
	overflow: hidden;
	background-color: var(--color-surface-2);
}

/*
 * Loading shimmer (visual reference: 21st.dev "Product Grid Skeleton" by
 * cnippet.dev) — even though this theme renders product cards server-side
 * (no client-side loading state to skeleton), each individual product
 * image still takes real network time to arrive, especially with the
 * native loading="lazy" WordPress already adds. initProductImageSkeletons()
 * in assets/js/woocommerce.js toggles .is-loaded once each image's own
 * `load` event fires; until then this gradient sweep plays instead of an
 * empty gray box.
 */
.product-card__media::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	background: linear-gradient(
		100deg,
		var(--color-surface-2) 30%,
		var(--color-surface) 50%,
		var(--color-surface-2) 70%
	);
	background-size: 200% 100%;
	animation: darkcommerce-shimmer 1.4s ease-in-out infinite;
	opacity: 1;
	transition: opacity var(--duration-slow) var(--ease-standard);
}

.product-card__media.is-loaded::before {
	opacity: 0;
	pointer-events: none;
	animation-play-state: paused;
}

@keyframes darkcommerce-shimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
	.product-card__media::before {
		animation: none;
	}
}

.product-card__image-link {
	display: block;
	width: 100%;
	height: 100%;
}

.product-card__image {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: opacity var(--duration-slow) var(--ease-standard), transform var(--duration-slow) var(--ease-standard);
}

.product-card__image--hover {
	opacity: 0;
}

.product-card:hover .product-card__image--primary {
	transform: scale(1.03);
}

.product-card:hover .product-card__image--hover {
	opacity: 1;
}

/* Quick add button: hidden until hover on devices with a real pointer;
   always visible on touch (no hover state to reveal it). */
.product-card__quick-add {
	position: absolute;
	left: var(--space-2);
	right: var(--space-2);
	bottom: var(--space-2);
	opacity: 0;
	transform: translateY(6px);
	transition: opacity var(--duration-base) var(--ease-standard), transform var(--duration-base) var(--ease-standard);
}

@media (hover: hover) {
	.product-card:hover .product-card__quick-add,
	.product-card:focus-within .product-card__quick-add {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (hover: none) {
	.product-card__quick-add {
		opacity: 1;
		transform: none;
		position: static;
		margin-top: var(--space-2);
	}
}

.product-card__body {
	padding-top: var(--space-2);
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.product-card__title {
	font-size: var(--font-size-small);
	font-weight: 500;
	color: var(--color-text);
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.product-card__rating {
	min-height: 14px;
}

.product-card__price {
	font-size: var(--font-size-small);
	font-weight: 600;
	color: var(--color-text);
}

/* ---------------------------------------------------------------
 * WooCommerce native output styling — price, rating stars,
 * add-to-cart button — restyled in place rather than replaced, so the
 * theme keeps using WooCommerce's own escaping/formatting/AJAX wiring.
 * ------------------------------------------------------------- */
.price {
	color: var(--color-text);
}

.price del {
	color: var(--color-text-muted);
	font-weight: 400;
	text-decoration-color: var(--color-text-muted);
	margin-right: 6px;
}

.price ins {
	text-decoration: none;
	color: var(--color-danger);
}

/* WooCommerce renders stars via a background-image sprite by default;
   this swaps it for a lightweight ::before glyph approach that follows
   the theme's dark palette without shipping star-sprite images. */
.star-rating {
	position: relative;
	display: inline-block;
	font-family: Georgia, serif; /* only used for the ★ glyph fallback below */
	font-size: 14px;
	line-height: 1;
	width: 5.4em;
	height: 1em;
	color: var(--color-text-muted);
}

.star-rating::before {
	content: '\2605\2605\2605\2605\2605';
	letter-spacing: 3px;
	color: var(--color-border);
	display: block;
}

.star-rating span {
	position: absolute;
	top: 0;
	left: 0;
	overflow: hidden;
	height: 100%;
}

.star-rating span::before {
	content: '\2605\2605\2605\2605\2605';
	letter-spacing: 3px;
	color: var(--color-text);
	display: block;
}

.woocommerce-review-link,
.woocommerce-product-rating .woocommerce-review-link {
	font-size: var(--font-size-xs);
	color: var(--color-text-muted);
	margin-left: var(--space-1);
}

/* Loop add-to-cart button + its AJAX-added/loading states, all classes
   WooCommerce itself applies (added / loading) — no custom JS needed. */
.add_to_cart_button,
.product_type_simple,
.ajax_add_to_cart {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: 10px 16px;
	background-color: var(--color-accent);
	color: var(--color-accent-text);
	font-size: var(--font-size-xs);
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	border-radius: var(--radius-sm);
	text-align: center;
	transition: background-color var(--duration-base) var(--ease-standard), opacity var(--duration-base) var(--ease-standard);
}

.add_to_cart_button:hover {
	background-color: var(--color-accent-hover);
}

.add_to_cart_button.loading {
	opacity: 0.6;
	pointer-events: none;
}

.added_to_cart {
	display: block;
	margin-top: 6px;
	font-size: var(--font-size-xs);
	text-align: center;
	color: var(--color-success);
}


.divider {
	border: none;
	border-top: 1px solid var(--color-border);
	margin-block: var(--space-4);
}
