/**
 * Component: archive layout, filter rail, toolbar
 *
 * Two columns on desktop: a permanently visible filter rail and the results.
 * The rail stays visible rather than hiding behind a button, because on a
 * catalogue where most items are unavailable, filtering is the main act of
 * browsing rather than a refinement.
 */

/* ---------------------------------------------------------------------- */
/* Archive shell                                                           */
/* ---------------------------------------------------------------------- */

.tcs-archive-header {
	padding-block-end: var(--tcs-space-md);
	margin-block-end: var(--tcs-space-lg);
	border-block-end: var(--tcs-border);
}

.tcs-archive-header__title {
	font-size: var(--tcs-text-2xl);
	margin: 0;
}

.tcs-archive-header .term-description {
	margin-block-start: var(--tcs-space-sm);
	max-width: var(--tcs-measure);
	color: var(--tcs-ink-muted);
	font-size: var(--tcs-text-sm);
}

.tcs-archive {
	display: grid;
	grid-template-columns: 15rem minmax(0, 1fr);
	gap: var(--tcs-space-2xl);
	align-items: start;
}

.tcs-archive__rail {
	position: sticky;
	top: var(--tcs-space-md);
	max-height: calc(100vh - var(--tcs-space-xl));
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
}

/* Bullion trades rail width for grid density. */
.tcs-context-bullion .tcs-archive {
	grid-template-columns: 13rem minmax(0, 1fr);
	gap: var(--tcs-space-xl);
}

/* ---------------------------------------------------------------------- */
/* Filter rail                                                             */
/* ---------------------------------------------------------------------- */

.tcs-filters__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--tcs-space-sm);
	padding-block-end: var(--tcs-space-xs);
	margin-block-end: var(--tcs-space-xs);
	border-block-end: var(--tcs-border-strong);
}

.tcs-filters__title {
	font-family: var(--tcs-font-sans);
	font-size: var(--tcs-text-2xs);
	font-weight: var(--tcs-weight-semibold);
	letter-spacing: var(--tcs-tracking-label);
	text-transform: uppercase;
	color: var(--tcs-ink-faint);
	margin: 0;
}

.tcs-filters__clear {
	font-size: var(--tcs-text-2xs);
	font-weight: var(--tcs-weight-medium);
}

/* ---------------------------------------------------------------------- */
/* Facet                                                                   */
/* ---------------------------------------------------------------------- */

.tcs-facet {
	border-block-end: var(--tcs-border-faint);
}

.tcs-facet__head {
	margin: 0;
}

.tcs-facet__toggle {
	display: flex;
	align-items: center;
	gap: var(--tcs-space-xs);
	width: 100%;
	padding-block: var(--tcs-space-sm);
	min-height: 44px;
	text-align: start;
	color: var(--tcs-ink);
}

.tcs-facet__label {
	font-family: var(--tcs-font-sans);
	font-size: var(--tcs-text-sm);
	font-weight: var(--tcs-weight-semibold);
	flex: 1;
}

.tcs-facet__count {
	font-size: var(--tcs-text-3xs);
	font-weight: var(--tcs-weight-semibold);
	font-variant-numeric: tabular-nums;
	background: var(--tcs-accent);
	color: var(--tcs-ink-inverse);
	border-radius: var(--tcs-radius-pill);
	padding: 0.15em 0.45em;
	min-width: 1.5em;
	text-align: center;
}

.tcs-facet__chevron {
	color: var(--tcs-ink-faint);
	transition: transform var(--tcs-duration) var(--tcs-ease);
	flex-shrink: 0;
}

.tcs-facet__toggle[aria-expanded="true"] .tcs-facet__chevron {
	transform: rotate(180deg);
}

.tcs-facet__list {
	list-style: none;
	margin: 0;
	padding: 0 0 var(--tcs-space-sm);
	display: flex;
	flex-direction: column;
	gap: var(--tcs-space-3xs);
	max-height: 18rem;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.tcs-facet__list[hidden] {
	display: none;
}

.tcs-facet__option {
	display: flex;
	align-items: center;
	gap: var(--tcs-space-xs);
	padding: var(--tcs-space-2xs) var(--tcs-space-2xs);
	min-height: 32px;
	font-size: var(--tcs-text-sm);
	color: var(--tcs-ink-muted);
	text-decoration: none;
	border-radius: var(--tcs-radius-sm);
	transition: background-color var(--tcs-duration) var(--tcs-ease);
}

.tcs-facet__option:hover {
	background: var(--tcs-paper-sunk);
	color: var(--tcs-ink);
	text-decoration: none;
}

.tcs-facet__option.is-selected {
	color: var(--tcs-ink);
	font-weight: var(--tcs-weight-medium);
}

/*
 * A term with no matches is shown rather than hidden, so the shape of the
 * catalogue stays legible - "no platinum in this category" is information.
 * It is not a link, because there is nothing to navigate to.
 */
.tcs-facet__option.is-empty {
	color: var(--tcs-ink-faint);
	cursor: default;
	opacity: 0.65;
}

.tcs-facet__box {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 15px;
	height: 15px;
	flex-shrink: 0;
	border: 1px solid var(--tcs-rule-strong);
	border-radius: var(--tcs-radius-sm);
	background: var(--tcs-surface-raised);
	color: var(--tcs-ink-inverse);
}

.tcs-facet__option.is-selected .tcs-facet__box {
	background: var(--tcs-accent);
	border-color: var(--tcs-accent);
}

.tcs-facet__name {
	flex: 1;
	min-width: 0;
}

.tcs-facet__total {
	font-size: var(--tcs-text-3xs);
	font-variant-numeric: tabular-nums;
	color: var(--tcs-ink-faint);
	flex-shrink: 0;
}

/* ---------------------------------------------------------------------- */
/* Toolbar                                                                 */
/* ---------------------------------------------------------------------- */

.tcs-toolbar {
	margin-block-end: var(--tcs-space-lg);
}

.tcs-toolbar__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--tcs-space-sm) var(--tcs-space-md);
	padding-block-end: var(--tcs-space-sm);
	border-block-end: var(--tcs-border);
}

.tcs-toolbar__count {
	font-size: var(--tcs-text-sm);
	color: var(--tcs-ink-muted);
	margin: 0;
	max-width: none;
	font-variant-numeric: tabular-nums;
}

.tcs-toolbar__count strong {
	color: var(--tcs-ink);
	font-weight: var(--tcs-weight-semibold);
}

.tcs-toolbar__filtered {
	color: var(--tcs-ink-faint);
}

.tcs-toolbar__controls {
	display: flex;
	align-items: center;
	gap: var(--tcs-space-sm);
	margin-inline-start: auto;
}

/* WooCommerce's ordering form. */
.woocommerce-ordering select {
	min-height: 36px;
	padding-block: 0.35rem;
	font-size: var(--tcs-text-sm);
	width: auto;
}

.woocommerce-ordering {
	margin: 0;
}

/* The filters button is a mobile affordance; the rail is always visible above. */
.tcs-filters-button {
	display: none;
}

.tcs-filters-button__count {
	font-size: var(--tcs-text-3xs);
	font-variant-numeric: tabular-nums;
	background: var(--tcs-accent);
	color: var(--tcs-ink-inverse);
	border-radius: var(--tcs-radius-pill);
	padding: 0.1em 0.4em;
	margin-inline-start: var(--tcs-space-2xs);
}

/* ---------------------------------------------------------------------- */
/* View switch                                                             */
/* ---------------------------------------------------------------------- */

.tcs-viewswitch {
	display: inline-flex;
	border: var(--tcs-border);
	border-radius: var(--tcs-radius);
	overflow: hidden;
}

.tcs-viewswitch__option {
	display: inline-flex;
	align-items: center;
	gap: var(--tcs-space-2xs);
	padding: 0.4rem var(--tcs-space-sm);
	min-height: 36px;
	font-size: var(--tcs-text-2xs);
	font-weight: var(--tcs-weight-medium);
	color: var(--tcs-ink-muted);
	background: var(--tcs-surface);
	text-decoration: none;
}

.tcs-viewswitch__option + .tcs-viewswitch__option {
	border-inline-start: var(--tcs-border);
}

.tcs-viewswitch__option:hover {
	background: var(--tcs-paper-sunk);
	color: var(--tcs-ink);
}

.tcs-viewswitch__option.is-current {
	background: var(--tcs-accent);
	color: var(--tcs-ink-inverse);
}

/* ---------------------------------------------------------------------- */
/* Active filter chips                                                     */
/* ---------------------------------------------------------------------- */

.tcs-chips {
	display: flex;
	flex-wrap: wrap;
	gap: var(--tcs-space-2xs);
	list-style: none;
	margin: var(--tcs-space-sm) 0 0;
	padding: 0;
}

.tcs-chip {
	display: inline-flex;
	align-items: center;
	gap: var(--tcs-space-2xs);
	font-size: var(--tcs-text-2xs);
	font-weight: var(--tcs-weight-medium);
	color: var(--tcs-ink);
	background: var(--tcs-surface);
	border: var(--tcs-border);
	border-radius: var(--tcs-radius-sm);
	padding: 0.3em 0.5em;
	min-height: 30px;
	text-decoration: none;
}

.tcs-chip:hover {
	border-color: var(--tcs-ink-faint);
	background: var(--tcs-paper-sunk);
	color: var(--tcs-ink);
}

.tcs-chip__group {
	color: var(--tcs-ink-faint);
	font-weight: var(--tcs-weight-regular);
}

.tcs-chip__x {
	font-size: 1.1em;
	line-height: 1;
	color: var(--tcs-ink-faint);
}

/* ---------------------------------------------------------------------- */
/* Empty state                                                             */
/* ---------------------------------------------------------------------- */

.tcs-empty {
	padding-block: var(--tcs-space-2xl);
	max-width: var(--tcs-measure);
}

.tcs-empty__title {
	font-size: var(--tcs-text-xl);
	margin: 0 0 var(--tcs-space-xs);
}

.tcs-empty__body {
	color: var(--tcs-ink-muted);
	margin-block-end: var(--tcs-space-md);
}

/* ---------------------------------------------------------------------- */
/* Mobile filter drawer                                                    */
/* ---------------------------------------------------------------------- */

.tcs-filter-drawer {
	position: fixed;
	inset: 0;
	z-index: var(--tcs-z-modal);
}

.tcs-filter-drawer[hidden] { display: none; }

.tcs-filter-drawer__scrim {
	position: absolute;
	inset: 0;
	background: rgba(var(--tcs-scrim-rgb), 0.45);
	opacity: 0;
	transition: opacity var(--tcs-duration) var(--tcs-ease);
}

.tcs-filter-drawer.is-open .tcs-filter-drawer__scrim { opacity: 1; }

.tcs-filter-drawer__panel {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	width: min(24rem, 92vw);
	display: flex;
	flex-direction: column;
	background: var(--tcs-surface);
	box-shadow: var(--tcs-shadow-overlay);
	transform: translateX(100%);
	transition: transform var(--tcs-duration-slow) var(--tcs-ease);
}

.tcs-filter-drawer.is-open .tcs-filter-drawer__panel { transform: translateX(0); }

.tcs-filter-drawer__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--tcs-space-md);
	border-block-end: var(--tcs-border);
}

.tcs-filter-drawer__title {
	font-family: var(--tcs-font-sans);
	font-size: var(--tcs-text-2xs);
	font-weight: var(--tcs-weight-semibold);
	letter-spacing: var(--tcs-tracking-label);
	text-transform: uppercase;
	color: var(--tcs-ink-faint);
}

.tcs-filter-drawer__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin: -10px;
	color: var(--tcs-ink);
	border-radius: var(--tcs-radius);
}

.tcs-filter-drawer__body {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 0 var(--tcs-space-md);
}

/* The rail heading is redundant inside the drawer, which has its own. */
.tcs-filter-drawer__body .tcs-filters__head {
	display: none;
}

.tcs-filter-drawer__foot {
	display: flex;
	align-items: center;
	gap: var(--tcs-space-xs);
	padding: var(--tcs-space-md);
	border-block-start: var(--tcs-border);
	background: var(--tcs-paper-sunk);
}

/* ---------------------------------------------------------------------- */
/* Breakpoints                                                             */
/* ---------------------------------------------------------------------- */

@media (max-width: 1024px) {
	.tcs-archive,
	.tcs-context-bullion .tcs-archive {
		grid-template-columns: minmax(0, 1fr);
		gap: 0;
	}

	/* The rail moves into the drawer; without JS it stays inline below. */
	.tcs-js .tcs-archive__rail {
		display: none;
	}

	.tcs-js .tcs-filters-button {
		display: inline-flex;
	}

	/* No JS: the rail sits above results rather than disappearing. */
	html:not(.tcs-js) .tcs-archive__rail {
		position: static;
		max-height: none;
		margin-block-end: var(--tcs-space-lg);
		padding-block-end: var(--tcs-space-lg);
		border-block-end: var(--tcs-border);
	}
}

@media (max-width: 640px) {
	.tcs-toolbar__row {
		gap: var(--tcs-space-xs);
	}

	.tcs-toolbar__controls {
		width: 100%;
		margin-inline-start: 0;
		justify-content: space-between;
	}

	.woocommerce-ordering select {
		max-width: 11rem;
	}
}

/* ---------------------------------------------------------------------- */
/* Reduced motion                                                          */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.tcs-filter-drawer__panel,
	.tcs-filter-drawer__scrim {
		transition: none;
	}
}

/* ---------------------------------------------------------------------- */
/* Print                                                                   */
/* ---------------------------------------------------------------------- */

@media print {
	.tcs-archive__rail,
	.tcs-toolbar__controls,
	.tcs-filter-drawer {
		display: none;
	}

	.tcs-archive {
		grid-template-columns: minmax(0, 1fr);
	}
}
