/**
 * Foliora: search form and search panel.
 */

/* ---------- Search form (used everywhere via get_search_form) ---------- */
.foliora-search-form {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	margin: 0;
	padding-block: 6px;
	padding-inline: 18px 6px;
	background: var(--foliora-bg);
	border: 2px solid var(--foliora-field, #7d819e);
	border-radius: calc(16px * var(--foliora-corner-scale, 1));
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.foliora-search-form:focus-within {
	border-color: var(--foliora-accent, #262f5c);
	box-shadow: 0 0 0 4px color-mix(in srgb, var(--foliora-accent) 12%, transparent);
}

.foliora-search-form__icon {
	flex-shrink: 0;
	color: var(--foliora-muted, #5c6286);
}

/* Reset the template's global input styles. */
.foliora-search-form .foliora-search-form__input {
	flex: 1;
	min-width: 0;
	height: 52px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	outline: none;
	font-family: inherit;
	font-size: 18px;
	font-weight: 500;
	color: var(--foliora-text, #262f5c);
	-webkit-appearance: none;
	appearance: none;
}

.foliora-search-form .foliora-search-form__input::placeholder {
	color: var(--foliora-faint);
	font-weight: 400;
	opacity: 1;
}

/* Hide the browser's own clear button; it clashes with the layout. */
.foliora-search-form__input::-webkit-search-cancel-button {
	-webkit-appearance: none;
}

.foliora-search-form .foliora-search-form__submit {
	flex-shrink: 0;
	height: 48px;
	margin: 0;
	padding: 0 24px; /* Measured centred: flex centring needs no optical nudge here. */
	border: 0;
	border-radius: calc(12px * var(--foliora-corner-scale, 1));
	background: var(--foliora-accent, #262f5c);
	color: var(--foliora-on-accent);
	font-family: var(--foliora-font-heading);
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background 0.2s ease;
}

.foliora-search-form__submit-icon {
	display: none;
}

.foliora-search-form .foliora-search-form__submit:hover {
	background: var(--foliora-link, #0a6fab);
}

.foliora-search-form .foliora-search-form__submit:focus-visible {
	outline: 3px solid var(--foliora-link, #0a6fab);
	outline-offset: 3px;
}

/* Inside "Nothing found" messages. */
.foliora-empty .foliora-search-form {
	max-width: 560px;
	margin-top: 16px;
}

/* ---------- Search panel ---------- */
.foliora-search {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: none;
	align-items: flex-start;
	justify-content: center;
	padding: 12vh 20px 20px;
	font-family: var(--foliora-font-body);
}

.foliora-search.is-open,
.foliora-search:target {
	display: flex;
}

/* Lock page scrolling while search is open. Only <html> is locked: if
   <body> also clipped its overflow (the template gives it overflow-x:
   hidden) it would become its own scroll box, and the sticky header,
   measured from it, would drop below the admin bar by the bar's height. */
.foliora-search-open {
	overflow: hidden;
}

.foliora-search-open body {
	overflow: visible;
}

.foliora-search__backdrop {
	position: absolute;
	inset: 0;
	padding: 0;
	background: color-mix(in srgb, var(--foliora-shade) 55%, transparent);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
	cursor: default;
	animation: foliora-search-fade 0.2s ease both;
}

.foliora-search__panel {
	position: relative;
	width: 100%;
	max-width: 720px;
	padding: 24px 32px 28px;
	background: var(--foliora-bg);
	border-radius: calc(24px * var(--foliora-corner-scale, 1));
	box-shadow: 0 24px 64px color-mix(in srgb, var(--foliora-shade) 25%, transparent);
	color: var(--foliora-text, #262f5c);
	animation: foliora-search-in 0.25s ease both;
}

.foliora-search__bar {
	display: flex;
	align-items: center;
	gap: 12px;
}

.foliora-search__bar .foliora-search-form {
	flex: 1;
	min-width: 0;
}

.foliora-search .foliora-search__close {
	display: inline-flex;
	flex-shrink: 0;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	padding: 0;
	border-radius: 999px;
	background: var(--foliora-surface, #f4f5f9);
	background-image: none;
	color: var(--foliora-text, #262f5c);
	transition: background 0.2s ease;
}

.foliora-search .foliora-search__close:hover {
	background: var(--foliora-surface-hover);
}

.foliora-search a:focus-visible {
	outline: 3px solid var(--foliora-link, #0a6fab);
	outline-offset: 3px;
}

.foliora-search__section {
	margin-top: 28px;
}

.foliora-search .foliora-search__label {
	margin: 0 0 12px;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--foliora-muted, #5c6286);
}

.foliora-search__chips,
.foliora-search__stories {
	margin: 0;
	padding: 0;
	list-style: none;
}

.foliora-search__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

/* The template makes every "ul li" inline-block with a grey !important colour. */
.foliora-search__chips li,
.foliora-search__stories li {
	display: block;
	margin: 0;
}

.foliora-search .foliora-search__chips a {
	display: inline-flex;
	align-items: center;
	height: 40px;
	padding: 0 16px;
	border: 1px solid var(--foliora-line-strong);
	border-radius: 999px;
	background-image: none;
	color: var(--foliora-text, #262f5c);
	font-size: 14px;
	font-weight: 500;
	transition: border-color 0.2s ease, color 0.2s ease;
}

.foliora-search .foliora-search__chips a:hover {
	border-color: var(--foliora-accent, #262f5c);
	color: var(--foliora-link, #0a6fab);
}

/* Latest stories: compact rows. */
.foliora-search__stories {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0 -10px;
}

.foliora-search .foliora-search__stories a {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 8px 10px;
	border-radius: calc(12px * var(--foliora-corner-scale, 1));
	background-image: none;
	color: var(--foliora-text, #262f5c);
	transition: background 0.2s ease;
}

.foliora-search .foliora-search__stories a:hover {
	background: var(--foliora-surface, #f4f5f9);
}

.foliora-search__thumb {
	flex-shrink: 0;
	width: 52px;
	height: 52px;
	border-radius: calc(10px * var(--foliora-corner-scale, 1));
	object-fit: cover;
}

.foliora-search__thumb--empty {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--foliora-surface-hover);
	color: var(--foliora-muted, #5c6286);
}

.foliora-search__story-text {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.foliora-search__story-title {
	font-family: var(--foliora-font-heading);
	font-size: 15px;
	line-height: 1.35;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.foliora-search .foliora-search__stories a:hover .foliora-search__story-title {
	color: var(--foliora-link, #0a6fab);
}

.foliora-search__story-date {
	font-size: 13px;
	color: var(--foliora-muted, #5c6286);
}

/* ---------- Live search (inc/search.php, search.js) ---------- */
.foliora-search [hidden] {
	display: none !important;
}

/* Results: titles get up to two lines (one line cut most titles short on
   phones), the rows line up at the top. */
.foliora-search .foliora-search__results a {
	align-items: flex-start;
}

.foliora-search__results .foliora-search__story-title {
	display: -webkit-box;
	white-space: normal;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.foliora-search__results .foliora-search__story-text {
	padding-top: 3px;
}

/* Words the reader typed, in the result titles. */
.foliora-search__story-title mark {
	padding: 0 1px;
	border-radius: 3px;
	background: color-mix(in srgb, var(--foliora-accent) 16%, transparent);
	color: inherit;
}

/* Earlier results stay, dimmed, while new ones load. */
.foliora-search__results {
	transition: opacity 0.15s ease;
}

.foliora-search.is-loading .foliora-search__results {
	opacity: 0.55;
}

/* Placeholder rows on the first load. */
.foliora-search .foliora-search__skeleton {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 8px 10px;
}

.foliora-search__skeleton .foliora-search__thumb,
.foliora-search__skeleton .foliora-search__story-text span {
	background: var(--foliora-surface-hover);
	animation: foliora-search-pulse 1.2s ease-in-out infinite;
}

.foliora-search__skeleton .foliora-search__story-text {
	flex: 1;
	gap: 8px;
}

.foliora-search__skeleton .foliora-search__story-text span {
	display: block;
	height: 12px;
	border-radius: 6px;
}

.foliora-search__skeleton .foliora-search__story-text span:first-child {
	width: 70%;
}

.foliora-search__skeleton .foliora-search__story-text span:last-child {
	width: 35%;
}

.foliora-search.is-loading .foliora-search__results:has(.foliora-search__skeleton) {
	opacity: 1;
}

@keyframes foliora-search-pulse {
	50% { opacity: 0.45; }
}

.foliora-search .foliora-search__none {
	margin: 4px 0 0;
	padding: 18px 20px;
	border-radius: calc(12px * var(--foliora-corner-scale, 1));
	background: var(--foliora-surface);
	font-size: 15px;
	line-height: 1.5;
	color: var(--foliora-muted, #5c6286);
}

/* "See all results for …": the way to the full results page. */
.foliora-search .foliora-search__all {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 14px;
	font-family: var(--foliora-font-heading);
	font-size: 14px;
	font-weight: 600;
	background-image: none;
	color: var(--foliora-link, #0a6fab);
}

.foliora-search .foliora-search__all .foliora-icon {
	width: 16px;
	height: 16px;
	transition: transform 0.2s ease;
}

.foliora-search .foliora-search__all:hover .foliora-icon,
.foliora-search .foliora-search__all:focus-visible .foliora-icon {
	transform: translateX(calc(3px * var(--foliora-dir, 1)));
}

/* A result reached with the arrow keys looks like a hovered one. */
.foliora-search .foliora-search__stories a:focus-visible {
	outline-offset: 0;
	background: var(--foliora-surface, #f4f5f9);
}

/* Keyboard hints (desktop only). */
.foliora-search .foliora-search__hints {
	display: flex;
	gap: 20px;
	margin: 24px -32px -28px;
	padding: 14px 32px;
	border-top: 1px solid var(--foliora-line, #dfe2ec);
	border-radius: 0 0 calc(24px * var(--foliora-corner-scale, 1)) calc(24px * var(--foliora-corner-scale, 1));
	background: var(--foliora-surface);
	font-size: 13px;
	font-weight: 400;
	color: var(--foliora-muted, #5c6286);
}

.foliora-search__hints kbd {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 24px;
	margin-inline-end: 4px;
	padding: 2px 6px;
	border: 1px solid var(--foliora-line-strong);
	border-bottom-width: 2px;
	border-radius: calc(6px * var(--foliora-corner-scale, 1));
	background: var(--foliora-bg);
	color: var(--foliora-text, #262f5c);
	font-family: var(--foliora-font-heading);
	font-size: 11px;
	font-weight: 600;
	box-shadow: none;
}

@keyframes foliora-search-fade {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes foliora-search-in {
	from { opacity: 0; transform: translateY(-12px); }
	to { opacity: 1; transform: none; }
}

@media (max-width: 767px) {
	.foliora-search {
		padding: 16px 12px;
	}

	.foliora-search__panel {
		padding: 16px 16px 20px;
		border-radius: calc(20px * var(--foliora-corner-scale, 1));
	}

	.foliora-search-form {
		padding-inline-start: 14px;
	}

	.foliora-search-form .foliora-search-form__input {
		height: 48px;
		font-size: 16px; /* 16px stops iOS from zooming in on focus. */
	}

	/* Phones: give the field the room; the button becomes an arrow icon. */
	.foliora-search-form__icon {
		display: none;
	}

	.foliora-search-form .foliora-search-form__submit {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
	}

	.foliora-search-form__submit-icon {
		display: block;
	}

	/* Hidden visually, still read by screen readers. */
	.foliora-search-form__submit-text {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.foliora-search .foliora-search__hints {
		display: none; /* No keyboard on phones. */
	}

	.foliora-search .foliora-search__close {
		width: 44px;
		height: 44px;
	}

	.foliora-search__section {
		margin-top: 24px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.foliora-search__backdrop,
	.foliora-search__panel,
	.foliora-search__skeleton .foliora-search__thumb,
	.foliora-search__skeleton .foliora-search__story-text span {
		animation: none;
	}
}

/* The arrow on the phone-size button points the way the text reads. */
[dir="rtl"] .foliora-search-form__submit-icon {
	scale: -1 1;
}

/* A search widget in a narrow column (footer, sidebar): same compact form
   as on phones, so the field keeps room for its text. */
.widget_search {
	container-type: inline-size;
}

@container (max-width: 300px) {

	.foliora-search-form {
		padding-inline-start: 14px;
	}

	.foliora-search-form .foliora-search-form__input {
		height: 44px;
		font-size: 16px;
	}

	.foliora-search-form__icon {
		display: none;
	}

	.foliora-search-form .foliora-search-form__submit {
		width: 40px;
		height: 40px;
		padding: 0;
	}

	.foliora-search-form__submit-icon {
		display: block;
	}

	.foliora-search-form__submit-text {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		clip-path: inset(50%);
		white-space: nowrap;
	}
}
