/**
 * Archive list view — layout only.
 *
 * Colour, type and button styling stay the theme's; this file only turns the
 * product grid into aligned rows. Scoped to body.kohper-products-view-list so
 * nothing leaks into the normal grid.
 *
 * @package Kohper\WooProducts
 */

.kohper-products-view-list {
	--kh-list-border: rgba( 0, 0, 0, 0.12 );
	--kh-list-muted: 0.7;
}

@media ( prefers-color-scheme: dark ) {
	.kohper-products-view-list {
		--kh-list-border: rgba( 255, 255, 255, 0.2 );
	}
}

/* ─────────────────────────────────────────────────────────────────────────
   The toggle. Shown in both views, so it is not scoped to the list body class.
   ───────────────────────────────────────────────────────────────────────── */

/* Sits between the result count and the sorting form, both of which themes
   commonly float — hence the left margin so it doesn't butt against the count. */
.kohper-products-viewtoggle {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0 0 1em 1.5em;
	vertical-align: middle;
}

@media ( max-width: 600px ) {
	.kohper-products-viewtoggle {
		display: flex;
		clear: both;
		margin-left: 0;
	}
}

.kohper-products-viewtoggle__label {
	font-size: 0.85em;
	opacity: 0.7;
}

.kohper-products-viewtoggle__btn {
	padding: 0.35em 0.8em;
	border: 1px solid var( --kh-list-border, rgba( 0, 0, 0, 0.12 ) );
	font-size: 0.9em;
	line-height: 1.4;
	text-decoration: none;
}

.kohper-products-viewtoggle__btn.is-current {
	font-weight: 600;
	border-color: currentColor;
}

/* ─────────────────────────────────────────────────────────────────────────
   Rows.

   The heading strip and every row share one track definition so the columns
   line up. minmax(0,…) rather than a bare 1fr: 1fr floors at min-content, so a
   single long product title would widen the whole row past the viewport.
   ───────────────────────────────────────────────────────────────────────── */

.kohper-products-view-list .kohper-products-list__head,
.kohper-products-view-list ul.products li.product {
	display: grid;
	grid-template-columns:
		minmax( 0, 1fr )      /* product */
		minmax( 0, 9rem )     /* sku */
		minmax( 0, 8rem )     /* price */
		minmax( 0, 9rem )     /* stock */
		minmax( 0, 13rem );   /* qty + add */
	gap: 1rem;
	align-items: center;
}

.kohper-products-view-list .kohper-products-list__head {
	list-style: none;
	margin: 0;
	padding: 0.5rem 0.75rem;
	border-bottom: 1px solid var( --kh-list-border );
	font-size: 0.78em;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	opacity: var( --kh-list-muted );
}

/* Undo the theme's grid/float card layout for the loop itself. */
.kohper-products-view-list ul.products {
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
}

.kohper-products-view-list ul.products li.product {
	float: none;
	clear: both;
	width: auto;
	max-width: none;
	margin: 0;
	padding: 0.85rem 0.75rem;
	border-bottom: 1px solid var( --kh-list-border );
	text-align: left;
}

/* The theme's card rules routinely centre things and hide overflow. */
.kohper-products-view-list ul.products li.product::before,
.kohper-products-view-list ul.products li.product::after {
	content: none;
}

.kohper-products-list__product {
	display: flex;
	align-items: center;
	gap: 0.85rem;
	min-width: 0;
}

.kohper-products-list__thumb {
	flex: 0 0 auto;
	width: 56px;
	line-height: 0;
}

.kohper-products-list__thumb img {
	width: 56px;
	height: auto;
	margin: 0;
	display: block;
}

.kohper-products-list__detail {
	min-width: 0;
}

.kohper-products-list__title {
	display: block;
	font-weight: 600;
	text-decoration: none;
}

.kohper-products-list__excerpt {
	margin: 0.15em 0 0;
	font-size: 0.88em;
	line-height: 1.4;
	opacity: var( --kh-list-muted );
}

.kohper-products-list__sku {
	font-size: 0.9em;
	opacity: var( --kh-list-muted );
	overflow-wrap: anywhere;
}

.kohper-products-list__price {
	font-weight: 600;
}

/* Woo prints the price as a <p> inside the loop; drop its card spacing. */
.kohper-products-view-list .kohper-products-list__price .price,
.kohper-products-view-list .kohper-products-list__price p {
	margin: 0;
	font-size: inherit;
}

.kohper-products-list__stock {
	font-size: 0.9em;
}

.kohper-products-list__stock.is-out {
	opacity: var( --kh-list-muted );
}

.kohper-products-list__buy {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	justify-content: flex-end;
}

.kohper-products-view-list .kohper-products-list__buy .quantity {
	margin: 0;
	float: none;
}

.kohper-products-view-list .kohper-products-list__buy input.qty {
	width: 4.5rem;
	min-width: 0;
	/* 16px keeps the value readable and stops iOS zooming the page on focus. */
	font-size: 16px;
	text-align: center;
}

.kohper-products-view-list .kohper-products-list__buy .button {
	margin: 0;
}

.kohper-products-list__packnote {
	flex-basis: 100%;
	margin: 0;
	font-size: 0.8em;
	text-align: right;
	opacity: var( --kh-list-muted );
}

/* ─────────────────────────────────────────────────────────────────────────
   Narrow screens: a row of five columns becomes a card. Each value is labelled
   by its data-label, since the heading strip is gone.
   ───────────────────────────────────────────────────────────────────────── */
@media ( max-width: 600px ) {
	.kohper-products-view-list .kohper-products-list__head {
		display: none;
	}

	.kohper-products-view-list ul.products li.product {
		grid-template-columns: minmax( 0, 1fr );
		gap: 0.4rem;
	}

	.kohper-products-view-list ul.products li.product > div:not( .kohper-products-list__product ) {
		display: flex;
		align-items: baseline;
		justify-content: space-between;
		gap: 1rem;
		/* Theme rules often set nowrap on price/meta; in a card it has to wrap. */
		white-space: normal;
	}

	.kohper-products-view-list ul.products li.product > div[data-label]::before {
		content: attr( data-label );
		flex: 0 0 auto;
		font-size: 0.75em;
		font-weight: 600;
		letter-spacing: 0.04em;
		text-transform: uppercase;
		opacity: var( --kh-list-muted );
	}

	.kohper-products-list__buy {
		justify-content: flex-start;
		padding-top: 0.35rem;
	}

	.kohper-products-list__packnote {
		text-align: left;
	}
}
