/*
 * CQI Shop Assistant search form ([cqi_shop_search]).
 *
 * The form itself is deliberately left unstyled here: it uses the same
 * classes as WordPress's own search form (classic) or Search block
 * (block themes), so the active theme styles it. This file only lays
 * out the parts a theme knows nothing about (the optional microphone
 * and the results), inheriting the theme's font and text color
 * throughout. Override any rule from the theme or Customizer CSS.
 *
 * STANDING-RULE-STYLE-01 extension: no weight below 400.
 */

.cqisa-search {
	--cqisa-search-gap: 16px;
	--cqisa-search-rule: rgba(127, 127, 127, 0.25);
	--cqisa-search-muted: rgba(127, 127, 127, 0.9);
	--cqisa-search-form-max: 600px;
	--cqisa-search-control-min: 40px;
	margin: 0 0 1.5em;
}

/* Fallback only: most themes already define this WordPress class. */
.cqisa-search .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.cqisa-search__form {
	display: flex;
	/* One row at every width: the box shrinks rather than the buttons
	   dropping onto a line of their own, which left them hanging to one
	   side on a phone. */
	flex-wrap: nowrap;
	align-items: stretch;
	gap: 8px;
	/* The whole row (box, microphone, button) stops at this width on a
	   wide screen and takes the full width below it. Limiting the form
	   rather than the input keeps the buttons beside the box. */
	width: 100%;
	max-width: var(--cqisa-search-form-max);
	box-sizing: border-box;
}

/* A comfortable minimum height for typing and tapping, whatever the
   theme sets; a theme that makes them taller still wins. */
.cqisa-search__input,
.cqisa-search__submit,
.cqisa-search__mic {
	min-height: var(--cqisa-search-control-min);
	box-sizing: border-box;
}

.cqisa-search__form > label {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
}

.cqisa-search__form .cqisa-search__mic,
.cqisa-search__form .cqisa-search__submit {
	flex: 0 0 auto;
}

.cqisa-search__form > label .cqisa-search__input {
	width: 100%;
	box-sizing: border-box;
}

.cqisa-search__mic {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 40px;
	padding: 0 10px;
	border: 1px solid var(--cqisa-search-rule);
	border-radius: 4px;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.cqisa-search__mic[hidden] {
	display: none;
}

.cqisa-search__mic.is-listening {
	border-color: currentColor;
	animation: cqisa-search-pulse 1.4s ease-in-out infinite;
}

@keyframes cqisa-search-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.55; }
}

.cqisa-search__results {
	margin-top: var(--cqisa-search-gap);
}

.cqisa-search__results:empty {
	display: none;
}

.cqisa-search__summary {
	margin: 0 0 6px;
	font-weight: 600;
}

.cqisa-search__note,
.cqisa-search__status,
.cqisa-search__sources {
	margin: 0 0 6px;
	font-size: 0.875em;
	font-weight: 400;
	color: var(--cqisa-search-muted);
}

.cqisa-search__grid {
	list-style: none;
	margin: var(--cqisa-search-gap) 0 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
	gap: var(--cqisa-search-gap);
}

.cqisa-search__card {
	margin: 0;
	padding: 0;
}

.cqisa-search__card-link {
	display: flex;
	flex-direction: column;
	gap: 4px;
	height: 100%;
	color: inherit;
	text-decoration: none;
}

.cqisa-search__card-link:hover .cqisa-search__card-title,
.cqisa-search__card-link:focus-visible .cqisa-search__card-title {
	text-decoration: underline;
}

.cqisa-search__card-image {
	display: block;
	width: 100%;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	border-radius: 4px;
	background: var(--cqisa-search-rule);
	margin-bottom: 4px;
}

.cqisa-search__card-title {
	font-weight: 600;
	line-height: 1.3;
}

.cqisa-search__card-price {
	font-weight: 400;
}

.cqisa-search__card-stock {
	font-size: 0.875em;
	font-weight: 400;
	color: var(--cqisa-search-muted);
}

.cqisa-search__answer {
	padding: 12px 16px;
	border-left: 3px solid var(--cqisa-search-rule);
}

.cqisa-search__answer p {
	margin: 0 0 6px;
}

.cqisa-search__more {
	margin: var(--cqisa-search-gap) 0 0;
	text-align: center;
}

/* Block-theme markup: the Search block's own wrapper takes the full row. */
.cqisa-search__form .wp-block-search__inside-wrapper {
	flex: 1 1 100%;
}

/*
 * results="modal": a window over the page, so a form in a header or a
 * theme's own search overlay still shows every result in full. Unlike
 * the form, this window needs a surface of its own; override the two
 * variables below to match the site.
 */
.cqisa-search-modal {
	--cqisa-search-surface: #fff;
	--cqisa-search-text: #1d2327;
	position: fixed;
	inset: 0;
	box-sizing: border-box;
	width: min(1120px, calc(100vw - 32px));
	max-width: none;
	height: auto;
	max-height: calc(100vh - 48px);
	max-height: calc(100dvh - 48px);
	margin: auto;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: var(--cqisa-search-surface);
	color: var(--cqisa-search-text);
	font: inherit;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
	overflow: hidden;
	z-index: 100000;
}

.cqisa-search-modal:not([open]) {
	display: none;
}

.cqisa-search-modal::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

/* Browsers without <dialog>: no ::backdrop, so the shadow does the work. */
.cqisa-search-modal.is-fallback {
	box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45), 0 20px 60px rgba(0, 0, 0, 0.3);
}

.cqisa-search-modal__inner {
	display: flex;
	flex-direction: column;
	max-height: inherit;
}

.cqisa-search-modal__head {
	display: flex;
	justify-content: flex-end;
	flex: 0 0 auto;
	padding: 8px 8px 0;
}

.cqisa-search-modal__close {
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font-size: 28px;
	line-height: 1;
	cursor: pointer;
}

.cqisa-search-modal__close:hover,
.cqisa-search-modal__close:focus-visible {
	background: var(--cqisa-search-rule);
}

.cqisa-search-modal .cqisa-search-modal__body {
	flex: 1 1 auto;
	margin: 0;
	padding: 0 24px 24px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.cqisa-search-modal .cqisa-search-modal__body:empty {
	display: block;
}

html.cqisa-search-modal-open {
	overflow: hidden;
}

@media (max-width: 600px) {
	.cqisa-search-modal {
		width: 100vw;
		max-height: 100vh;
		max-height: 100dvh;
		height: 100%;
		border-radius: 0;
	}

	.cqisa-search-modal .cqisa-search-modal__body {
		padding: 0 16px 16px;
	}

	.cqisa-search-modal .cqisa-search__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 12px;
	}
}

/* While the window is open, the form sits in its header. */
.cqisa-search-modal .cqisa-search-modal__head {
	align-items: center;
	gap: 8px;
	padding: 16px 16px 16px 24px;
}

.cqisa-search-modal__head .cqisa-search__form {
	flex: 1 1 auto;
	min-width: 0;
	max-width: none;
}

@media (max-width: 600px) {
	.cqisa-search-modal .cqisa-search-modal__head {
		padding: 12px 8px 12px 16px;
	}
}

/* align="center" / align="right": where the form sits once it stops
   growing at --cqisa-search-form-max. The results stay full width. */
/* Centered by default (align="center"); align="left" / "right" opt out. */
.cqisa-search > .cqisa-search__form {
	margin-left: auto;
	margin-right: auto;
}

.cqisa-search--align-left > .cqisa-search__form {
	margin-left: 0;
	margin-right: auto;
}

.cqisa-search--align-right > .cqisa-search__form {
	margin-left: auto;
	margin-right: 0;
}

/* The box and the microphone share one border color: the muted grey
   (--cqisa-search-rule) by default, or border_color when set. Specific
   enough to win over a theme's own search-field border color (for
   example "form.search-form input[type=search]"). The theme keeps the
   border's width and radius. */
.cqisa-search .cqisa-search__form .cqisa-search__input,
.cqisa-search .cqisa-search__form .cqisa-search__mic {
	border-color: var(--cqisa-search-border, var(--cqisa-search-rule));
}
