/**
 * Front end styles for the Boktugg blocks.
 *
 * Deliberately thin. Colour, spacing, typography and borders come from the
 * block editor and theme.json, so this file only does the structural work the
 * editor cannot express: how a control is put together, how a list collapses on
 * a phone, and sensible defaults before anyone touches a setting.
 */

/* ---------------------------------------------------------------- tokens */

/*
 * A theme sets these under settings.custom.input in theme.json. The fallbacks
 * are the values WordPress core uses for a core/search field, so that on a site
 * whose theme defines none of them the Boktugg controls still look like the
 * search block sitting next to them rather than like a plugin.
 *
 * Defined on :root so every control in the plugin sees them, not only the ones
 * inside a search form.
 */
:root {
	--boktugg-control-radius: var( --wp--custom--input--border--radius, 0 );
	--boktugg-control-border: var( --wp--custom--input--border--color, #949494 );
	--boktugg-control-border-width: var( --wp--custom--input--border--width, 1px );
	--boktugg-control-padding: var( --wp--custom--input--spacing--padding, 8px );
	--boktugg-control-gap: var( --wp--custom--input--spacing--gap, 10px );
}

/* ---------------------------------------------------------------- search */

.boktugg-search.is-loading .boktugg-results {
	opacity: 0.55;
	transition: opacity 120ms ease-out;
}

/* ------------------------------------------------------------ search field */

.boktugg-search-input {
	display: flex;
	flex-direction: column;
	gap: 0.35em;
	max-width: 100%;
}

.boktugg-search-input--button-outside {
	flex-direction: row;
	align-items: stretch;
	gap: var( --boktugg-control-gap );
	flex-wrap: wrap;
}

.boktugg-search-input__label {
	font-size: 0.85em;
}

.boktugg-search-input__field {
	position: relative;
	display: flex;
	align-items: stretch;
	flex: 1 1 auto;
	min-width: 0;
	border: var( --boktugg-control-border-width ) solid var( --boktugg-control-border );
	border-radius: var( --boktugg-control-radius );
	background: var( --wp--custom--input--color--background, #fff );
	overflow: hidden;
}

.boktugg-search-input__control {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
	padding: var( --boktugg-control-padding );
	border: 0;
	background: transparent;
	color: var( --wp--custom--input--color--text, inherit );
	font: inherit;
	line-height: inherit;
	appearance: none;
}

.boktugg-search-input__control:focus {
	outline: 2px solid currentColor;
	outline-offset: -2px;
}

/* The browser's own clear control would sit on top of ours. */
.boktugg-search-input__control::-webkit-search-cancel-button {
	display: none;
}

.boktugg-search-input__clear {
	flex: 0 0 auto;
	padding: 0 0.6em;
	border: 0;
	background: transparent;
	color: inherit;
	font-size: 1.25em;
	line-height: 1;
	cursor: pointer;
	opacity: 0.6;
}

.boktugg-search-input__clear:hover,
.boktugg-search-input__clear:focus-visible {
	opacity: 1;
}

.boktugg-search-input__clear[hidden] {
	display: none;
}

/* Layout only. The button carries the wp-element-button class, so its colour,
   padding and type come from the theme's button styles and it matches every
   other button on the site. The fallback below sits in :where() so it has no
   specificity and any theme rule wins without needing !important. */
.boktugg-search-input__button {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4em;
	border: 0;
	cursor: pointer;
}

:where( .boktugg-search-input__button ) {
	padding: 0.75em 1.25em;
	background: #1e1e1e;
	color: #fff;
	font: inherit;
}

:where( .boktugg-search-input__button:hover, .boktugg-search-input__button:focus-visible ) {
	opacity: 0.85;
}

/* ----------------------------------------------------------- search filter */

.boktugg-search-filter {
	display: flex;
	flex-direction: column;
	gap: 0.35em;
	min-width: 0;
}

.boktugg-search-filter__label {
	font-size: 0.8em;
	opacity: 0.8;
}

.boktugg-search-filter__select {
	max-width: 100%;
	padding: 0.6em 0.8em;
	border: 1px solid var( --boktugg-control-border );
	border-radius: var( --boktugg-control-radius );
	background: var( --wp--custom--input--color--background, #fff );
	color: inherit;
	font: inherit;
}

.boktugg-search-filter__fieldset {
	margin: 0;
	padding: 0;
	border: 0;
}

.boktugg-search-filter__pills {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4em;
}

.boktugg-search-filter__pill {
	display: inline-block;
	padding: 0.4em 0.9em;
	border: 1px solid var( --boktugg-control-border );
	border-radius: 999px;
	font-size: 0.9em;
	line-height: 1.3;
	cursor: pointer;
}

.boktugg-search-filter__radio:checked + .boktugg-search-filter__pill {
	background: var( --wp--preset--color--theme-6, #1e1e1e );
	border-color: var( --wp--preset--color--theme-6, #1e1e1e );
	color: var( --wp--preset--color--theme-1, #fff );
}

.boktugg-search-filter__radio:focus-visible + .boktugg-search-filter__pill {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* ---------------------------------------------------------------- results */

.boktugg-results,
.boktugg-book-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.boktugg-results > li,
.boktugg-book-list > li {
	list-style: none;
}

.boktugg-results[aria-busy='true'] {
	cursor: progress;
}

.boktugg-no-results[hidden] {
	display: none;
}

/* ------------------------------------------------------------------ fields */

.boktugg-book-cover {
	margin: 0;
}

.boktugg-book-cover img {
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
}

.boktugg-book-title {
	margin: 0;
}

.boktugg-book-byline {
	margin: 0;
}

.boktugg-book-byline__separator {
	opacity: 0.6;
}

.boktugg-book-byline__role {
	opacity: 0.75;
	font-size: 0.9em;
}

.boktugg-book-meta {
	margin: 0;
	padding: 0;
	list-style: none;
}

.boktugg-book-meta--chips {
	display: flex;
	flex-wrap: wrap;
	gap: var( --wp--style--block-gap, 0.5em );
	align-items: baseline;
}

/* Inline metadata flows as text rather than as flex items, so that when it
   wraps the separator stays with the value before it instead of starting the
   next line. */
.boktugg-book-meta--inline .boktugg-book-meta__item {
	display: inline;
}

.boktugg-book-meta--chips .boktugg-book-meta__item {
	padding: 0.15em 0.6em;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-size: 0.85em;
	line-height: 1.5;
	opacity: 0.85;
}

.boktugg-book-meta--inline .boktugg-book-meta__separator {
	margin-right: 0.4em;
	opacity: 0.5;
}

.boktugg-book-meta--list .boktugg-book-meta__item + .boktugg-book-meta__item {
	margin-top: 0.15em;
}

.boktugg-book-meta__label {
	opacity: 0.7;
}

.boktugg-book-meta--table {
	width: 100%;
	border-collapse: collapse;
	table-layout: fixed;
}

.boktugg-book-meta--table th,
.boktugg-book-meta--table td {
	padding: 0.5em 0.75em 0.5em 0;
	text-align: left;
	vertical-align: top;
	border-bottom: 1px solid currentColor;
	border-color: color-mix( in srgb, currentColor 15%, transparent );
}

.boktugg-book-meta--table th {
	width: 30%;
	font-weight: 400;
	opacity: 0.7;
}

.boktugg-book-description > :first-child {
	margin-top: 0;
}

.boktugg-book-description > :last-child {
	margin-bottom: 0;
}

/* ------------------------------------------------------------ buy buttons */

.boktugg-buy-buttons {
	display: flex;
	flex-wrap: wrap;
	gap: var( --wp--style--block-gap, 0.5em );
}

.boktugg-buy-buttons.is-vertical {
	flex-direction: column;
	align-items: stretch;
}

.boktugg-buy-buttons.is-content-justification-center {
	justify-content: center;
}

.boktugg-buy-buttons.is-content-justification-right {
	justify-content: flex-end;
}

.boktugg-buy-buttons.is-content-justification-space-between {
	justify-content: space-between;
}

.boktugg-buy-buttons__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.6em 1.2em;
	border: 1px solid currentColor;
	border-radius: var( --boktugg-control-radius );
	text-decoration: none;
	line-height: 1.3;
}

.boktugg-buy-buttons.is-full-width .boktugg-buy-buttons__button {
	flex: 1 1 100%;
}

.boktugg-buy-buttons__button:hover,
.boktugg-buy-buttons__button:focus-visible {
	opacity: 0.85;
}

/* -------------------------------------------------------------- load more */

.boktugg-load-more[hidden] {
	display: none;
}

.boktugg-load-more__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.75em 1.5em;
	border: 1px solid currentColor;
	border-radius: var( --boktugg-control-radius );
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.boktugg-load-more__button[disabled] {
	cursor: progress;
	opacity: 0.6;
}

.boktugg-load-more__button [hidden] {
	display: none;
}

/* -------------------------------------------------------------- book list */

.boktugg-book-list__more {
	margin-top: var( --wp--style--block-gap, 1.5rem );
}

.boktugg-book-list__more-toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	padding: 0.6em 1.2em;
	border: 1px solid currentColor;
	border-radius: var( --boktugg-control-radius );
	cursor: pointer;
	list-style: none;
}

.boktugg-book-list__more-toggle::-webkit-details-marker {
	display: none;
}

.boktugg-book-list__more[open] .boktugg-book-list__more-toggle {
	margin-bottom: var( --wp--style--block-gap, 1.5rem );
}

/* ------------------------------------------------------------------ small */

@media ( max-width: 600px ) {
	.boktugg-search-input--button-outside {
		flex-direction: column;
	}

	.boktugg-book-meta--table th {
		width: 40%;
	}
}

/* --------------------------------------------------------- list pagination */

.boktugg-book-list__pagination {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var( --wp--style--block-gap, 1rem );
	margin-top: var( --wp--style--block-gap, 1.5rem );
}

.boktugg-book-list__page-link {
	display: inline-flex;
	align-items: center;
	padding: 0.5em 1em;
	border: 1px solid currentColor;
	border-radius: var( --boktugg-control-radius );
	text-decoration: none;
}

.boktugg-book-list__page-link.is-next {
	margin-left: auto;
}

.boktugg-book-list__page-count {
	opacity: 0.7;
	font-size: 0.9em;
}

/* --------------------------------------------------------- admin edit link */

.boktugg-entity-edit-link.has-text-align-center {
	text-align: center;
}

.boktugg-entity-edit-link.has-text-align-right {
	text-align: right;
}

.boktugg-entity-edit-link__button {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	text-decoration: none;
}

/* Layout only: wp-element-button gives it the theme's button appearance. */
:where( .boktugg-entity-edit-link__button ) {
	padding: 0.6em 1.2em;
	background: #1e1e1e;
	color: #fff;
}

.boktugg-entity-edit-link__icon {
	flex: 0 0 auto;
}
