/**
 * LF Search — Matching livrariaferreira.pt design.
 * Cardo serif, charcoal tones, sharp corners, clean minimal.
 *
 * @package LF_Search
 */

/* === Design Tokens === */

.lf-search {
	--lf-font: 'Cardo', Georgia, serif;
	--lf-font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	--lf-color-text: #343a40;
	--lf-color-heading: #000;
	--lf-color-border: #dee2e6;
	--lf-color-bg: #fff;
	--lf-color-bg-hover: #f8f9fa;
	--lf-color-accent: #343a40;
	--lf-color-accent-hover: #212529;
	--lf-color-muted: #6c757d;
	--lf-color-danger: #dc3545;
}

/* === Base === */

.shop-advanced-search {
	width: 100%;
	grid-column: 1 / -1;
}

.lf-search {
	max-width: 100%;
	margin: 0 auto;
	padding: 0 0 20px;
	font-family: var(--lf-font);
	color: var(--lf-color-text);
}

.lf-search *,
.lf-search *::before,
.lf-search *::after {
	box-sizing: border-box;
}

/* === Sections (Pesquisar / Filtrar) === */

.lf-search__section {
	margin-bottom: 15px;
}

.lf-search__section-title {
	font-family: var(--lf-font-ui);
	font-size: 14px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: var(--lf-color-heading);
	margin: 20px 0 0;
}

.lf-search__pesquisar-row {
	display: flex;
	align-items: stretch;
	gap: 20px;
	background-color: #f4f4f4;
	padding: 20px;
	flex-wrap: wrap;
}

.lf-search__pesquisar-row .lf-search__section-title,
.lf-search__filters .lf-search__section-title {
	width: 100%;
	grid-column: 1 / -1;
	margin-top: 0;
}

.lf-search__pesquisar-row .lf-search__bars {
	flex: 1;
	min-width: 0;
	margin-bottom: 0;
}

.lf-search__pesquisar-row .lf-search__view-all-row {
	display: flex;
	align-items: end;
	margin-bottom: 31px;
	flex-shrink: 0;
}

.lf-search__pesquisar-row .lf-search__view-all {
	margin: 0;
	height: 43px;
	line-height: 12px;
}

.lf-search__submit-row {
	display: flex;
	justify-content: flex-end;
	margin-top: 16px;
	background-color: #f4f4f4;
	padding: 20px 20px 20px;
}

@media (max-width: 768px) {
	.lf-search__pesquisar-row {
		flex-direction: column;
	}

	.lf-search__pesquisar-row .lf-search__view-all {
		max-width: 100%;
		width: 100%;
	}

	.lf-search__submit-row {
		justify-content: stretch;
	}

	.lf-search__submit-row .lf-search__submit {
		max-width: 100%;
	}
}

/* === Search Bars — stacked full-width === */

.lf-search__bars {
	display: flex;
	flex-direction: column;
	gap: 16px;
	margin-bottom: 12px;
}

.lf-search__bar-group {
	width: 100%;
}

.lf-search__label {
	display: block;
	font-size: 13px;
	font-weight: 700;
	margin-bottom: 6px;
	color: var(--lf-color-heading);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	font-family: var(--lf-font-ui);
}

.lf-search__input-wrap {
	position: relative;
	display: flex;
	align-items: stretch;
	border: 1px solid var(--lf-color-border);
}

.lf-search__input {
	flex: 1;
	min-width: 0;
	padding: 12px 40px 12px 14px;
	border: none;
	font-size: 15px;
	font-family: var(--lf-font);
	color: var(--lf-color-text);
	background: var(--lf-color-bg);
	outline: none;
}

.lf-search__input::placeholder {
	color: #adb5bd;
}

.lf-search__input:focus {
	outline: none;
}

.lf-search__input-wrap:focus-within {
	border-color: var(--lf-color-accent);
}

.lf-search__clear-btn {
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	background: none;
	border: none;
	font-size: 20px;
	color: #adb5bd;
	cursor: pointer;
	padding: 4px 8px;
	line-height: 1;
	z-index: 2;
}

.lf-search__clear-btn:hover {
	color: var(--lf-color-text);
}

/* Single Pesquisar button below all search bars */
.lf-search__submit {
	max-width: 225px;
	width: 100%;
	padding: 14px 24px;
	background: var(--lf-color-accent);
	color: #fff;
	border: none;
	font-size: 15px;
	font-weight: 700;
	font-family: var(--lf-font-ui);
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	transition: background-color 0.2s, opacity 0.2s;
	white-space: nowrap;
}

.lf-search__submit:hover:not(:disabled) {
	background: var(--lf-color-accent-hover);
}

.lf-search__submit:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* Clear row */
.lf-search__clear-row {
	margin-bottom: 0;
	margin-top: 15px;
}

.lf-search__clear-all {
	max-width: 225px;
	width: 100%;
	padding: 14px 24px;
	background: var(--lf-color-accent);
	color: #fff;
	border: none;
	font-size: 15px;
	font-weight: 700;
	font-family: var(--lf-font-ui);
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	transition: background-color 0.2s, opacity 0.2s;
	white-space: nowrap;
	border-radius: 0;
}

.lf-search__clear-all:hover {
	background: var(--lf-color-accent-hover);
}

/* === Filters — 4-column select-style dropdowns === */

.lf-search__filters {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 20px;
	margin-bottom: 8px;
	align-items: start;
	background-color: #f4f4f4;
	padding: 20px;
}

.lf-search__filter {
	position: relative;
}

.lf-search__filter-label-text {
	display: block;
	font-size: 13px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--lf-color-heading);
	margin-bottom: 6px;
	font-family: var(--lf-font-ui);
}

.lf-search__filter-toggle {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 10px 12px;
	background: var(--lf-color-bg);
	border: 1px solid var(--lf-color-border);
	border-radius: 0;
	font-size: 14px;
	font-family: var(--lf-font);
	color: var(--lf-color-muted);
	cursor: pointer;
	transition: border-color 0.15s, box-shadow 0.15s;
	text-align: left;
	appearance: none;
	-webkit-appearance: none;
}

.lf-search__filter-toggle:hover {
	border-color: var(--lf-color-accent);
}

.lf-search__filter-toggle:focus-visible {
	outline: none;
	border-color: var(--lf-color-accent);
	box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.lf-search__filter-toggle[aria-expanded="true"] {
	border-color: var(--lf-color-accent);
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
}

.lf-search__filter-toggle--loading {
	position: relative;
	pointer-events: none;
	opacity: 0.7;
}

.lf-search__filter-toggle--loading .lf-search__filter-value {
	visibility: hidden;
}

.lf-search__filter-toggle--loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 16px;
	height: 16px;
	margin: -8px 0 0 -8px;
	border: 2px solid var(--lf-color-border);
	border-top-color: var(--lf-color-accent);
	border-radius: 50%;
	animation: lf-spin 0.7s linear infinite;
}

.lf-search__filter-toggle[aria-expanded="true"] .lf-search__filter-chevron {
	transform: rotate(180deg);
}

.lf-search__filter-value {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
	min-width: 0;
}

.lf-search__filter-value--active {
	color: var(--lf-color-text);
	font-weight: 700;
}

.lf-search__filter-chevron {
	flex-shrink: 0;
	margin-left: auto;
	color: var(--lf-color-muted);
	transition: transform 0.2s;
}

.lf-search__filter-dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 100;
	min-width: 100%;
	max-height: 320px;
	background: var(--lf-color-bg);
	border: 1px solid var(--lf-color-accent);
	border-top: none;
	border-bottom-left-radius: 4px;
	border-bottom-right-radius: 4px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
}

/* CRITICAL: hidden attribute must win over display:flex */
.lf-search__filter-dropdown[hidden] {
	display: none !important;
}

.lf-search__filter-search {
	margin: 8px;
	padding: 7px 10px;
	border: 1px solid var(--lf-color-border);
	font-size: 13px;
	font-family: var(--lf-font);
	flex-shrink: 0;
}

.lf-search__filter-search:focus {
	outline: none;
	border-color: var(--lf-color-accent);
}

.lf-search__filter-list {
	list-style: none;
	margin: 0;
	padding: 0 8px 8px;
	overflow-y: auto;
	flex: 1;
}

.lf-search__filter-item {
	padding: 0;
}

.lf-search__filter-label {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 4px;
	font-size: 13px;
	font-family: var(--lf-font);
	cursor: pointer;
	transition: background-color 0.1s;
}

.lf-search__filter-label:hover {
	background: var(--lf-color-bg-hover);
}

.lf-search__filter-label input[type='checkbox'] {
	flex-shrink: 0;
	accent-color: var(--lf-color-accent);
}

/* Disabled state — keywords mode */
.lf-search__filter--disabled {
	opacity: 0.4;
	pointer-events: none;
}

/* Per-dropdown clear */
.lf-search__filter-clear-btn {
	display: block;
	width: 100%;
	padding: 6px 4px;
	background: none;
	border: none;
	border-bottom: 1px solid var(--lf-color-border);
	font-size: 13px;
	font-family: var(--lf-font);
	color: var(--lf-color-danger);
	cursor: pointer;
	text-align: left;
	margin-bottom: 4px;
}

.lf-search__filter-clear-btn:hover {
	background: #fff5f5;
}

/* Apply filters button inside each dropdown */
.lf-search__filter-apply {
	display: block;
	width: calc(100% - 16px);
	margin: 0 8px 8px;
	padding: 8px 12px;
	background: var(--lf-color-accent);
	color: #fff;
	border: none;
	font-size: 13px;
	font-family: var(--lf-font-ui);
	font-weight: 700;
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.lf-search__filter-apply:hover:not(:disabled) {
	background: var(--lf-color-accent-hover);
}

.lf-search__filter-apply:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.lf-search__filter-apply--loading {
	position: relative;
	color: transparent;
}

.lf-search__filter-apply--loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 16px;
	height: 16px;
	margin: -8px 0 0 -8px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: #fff;
	border-radius: 50%;
	animation: lf-spin 0.7s linear infinite;
}

/* View all books */
.lf-search__view-all-row {
	text-align: left;
	margin-bottom: 24px;
}

.lf-search__view-all {
	max-width: 225px;
	width: 100%;
	margin: 30px auto 0 0;
	padding: 14px 24px;
	background: var(--lf-color-accent);
	color: #fff;
	border: none;
	font-size: 15px;
	font-weight: 700;
	font-family: var(--lf-font-ui);
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	transition: background-color 0.2s, opacity 0.2s;
}

.lf-search__view-all:hover {
	background: var(--lf-color-accent-hover);
}

/* Clear all filters */
.lf-search__clear-filters-row {
	margin-bottom: 24px;
}

.lf-search__clear-filters {
	max-width: 100%;
	width: 100%;
	padding: 14px 24px;
	background: var(--lf-color-accent);
	color: #fff;
	border: none;
	font-size: 15px;
	font-weight: 700;
	font-family: var(--lf-font-ui);
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	transition: background-color 0.2s, opacity 0.2s;
	white-space: nowrap;
	border-radius: 0;
}

.lf-search__clear-filters:hover {
	background: var(--lf-color-accent-hover);
}

/* === Results meta === */

.lf-search__meta {
	padding: 12px 0;
	font-size: 14px;
	color: var(--lf-color-muted);
	border-bottom: 1px solid var(--lf-color-border);
	margin-bottom: 20px;
	align-items: center;
	justify-content: space-between;
}

.lf-search__meta:not([hidden]) {
	display: flex;
}

.lf-search__ordering-wrap {
	min-height: auto;
}

.lf-search__orderby-select {
	padding: 8px 32px 8px 12px;
	font-size: 14px;
	border: 1px solid var(--lf-color-border);
	background: var(--lf-color-bg);
	color: var(--lf-color-text);
	cursor: pointer;
	appearance: auto;
	min-width: 200px;
}

.lf-search__loading {
	text-align: center;
	padding: 40px;
	color: var(--lf-color-muted);
	font-size: 16px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
}

.lf-search__loading[hidden] {
	display: none !important;
}

.lf-search__spinner {
	width: 32px;
	height: 32px;
	border: 3px solid var(--lf-color-border);
	border-top-color: var(--lf-color-accent);
	border-radius: 50%;
	animation: lf-spin 0.7s linear infinite;
}

@keyframes lf-spin {
	to { transform: rotate(360deg); }
}

/* Searching state — subtle feedback on the search bars */
.lf-search--searching .lf-search__submit {
	pointer-events: none;
	opacity: 0.6;
}

.lf-search--searching .lf-search__input {
	opacity: 0.6;
}

.lf-search__no-results {
	text-align: center;
	padding: 60px 20px;
	color: var(--lf-color-muted);
}

.lf-search__no-results p {
	font-size: 18px;
	margin: 0;
}

/* === Results list === */

.lf-search__results {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 0;
}

/*
 * Product cards use the same classes as the theme's product-list-card.
 * The theme CSS (.product-list-card, .product-card-image, etc.) will style them.
 * Below are fallback styles in case the theme CSS doesn't load.
 */

.lf-search__results .product-list-card {
	display: grid;
	grid-template-columns: 160px 1fr 120px;
	grid-template-rows: auto auto;
	grid-template-areas:
		"image content tags"
		"actions actions actions";
	gap: 16px;
	background: #fff;
	border: 1px solid #e5e5e5;
	padding: 20px;
	transition: all 0.3s ease;
	margin: -1px 0 0 0;
}

.lf-search__results .product-list-card:first-child {
	margin-top: 0;
}

.lf-search__results .product-list-card:hover {
	border-color: #ddd;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.lf-search__results .product-card-image {
	grid-area: image;
}

.lf-search__results .product-card-image img {
	width: 100%;
	height: auto;
	display: block;
}

.lf-search__results .product-card-content {
	grid-area: content;
}

.lf-search__results .product-card-author {
	font-size: 14px;
	font-weight: 700;
	text-transform: uppercase;
	color: var(--lf-color-text);
	margin: 0 0 4px;
	font-family: var(--lf-font-ui);
}

.lf-search__results .product-card-title {
	font-size: 15px;
	font-weight: 400;
	font-family: var(--lf-font);
	margin: 0 0 6px;
	line-height: 1.4;
}

.lf-search__results .product-card-title a {
	color: var(--lf-color-heading);
	text-decoration: none;
}

.lf-search__results .product-card-title a:hover {
	text-decoration: underline;
}

.lf-search__results .product-card-sku {
	display: block;
	font-size: 12px;
	color: var(--lf-color-muted);
	margin-bottom: 6px;
}

.lf-search__results .product-card-price {
	font-size: 16px;
	font-weight: 700;
	color: var(--lf-color-text);
}

.lf-search__results .product-card-tags-column {
	grid-area: tags;
}

.lf-search__results .product-card-tags {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.lf-search__results .product-tag {
	font-size: 12px;
	color: var(--lf-color-muted);
	text-decoration: none;
}

.lf-search__results .product-tag:hover {
	color: var(--lf-color-text);
	text-decoration: underline;
}

.lf-search__results .product-card-actions {
	grid-area: actions;
	display: flex;
	gap: 8px;
	align-items: center;
	justify-content: flex-end;
	padding-top: 12px;
	border-top: 1px solid #f0f0f0;
}

.lf-search__results .product-cta-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	font-size: 13px;
	font-family: var(--lf-font-ui);
	text-decoration: none;
	border: 1px solid var(--lf-color-border);
	cursor: pointer;
	transition: all 0.2s;
}

.lf-search__results .product-cta-view {
	background: var(--lf-color-bg);
	color: var(--lf-color-text);
}

.lf-search__results .product-cta-view:hover {
	background: #000000;
	border-color: #000000;
	color: #ffffff;
}

.lf-search__results .product-cta-view:hover svg {
	color: #ffffff;
}

.lf-search__results .product-cta-cart {
	background: var(--lf-color-accent);
	color: #fff;
	border-color: var(--lf-color-accent);
}

.lf-search__results .product-cta-cart:hover {
	background: var(--lf-color-accent-hover);
}

.lf-search__results .product-cta-disabled {
	opacity: 0.5;
	cursor: not-allowed;
	background: #f0f0f0;
	color: var(--lf-color-muted);
}

@media (max-width: 768px) {
	.lf-search__results .product-list-card {
		grid-template-columns: 120px 1fr;
		grid-template-areas:
			"image content"
			"tags tags"
			"actions actions";
		padding: 12px;
	}
}

@media (max-width: 480px) {
	.lf-search__results .product-list-card {
		grid-template-columns: 100px 1fr;
	}
}

/* === Pagination === */

.lf-search__pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 4px;
	padding: 24px 0;
	flex-wrap: wrap;
}

.lf-search__page-btn {
	min-width: 36px;
	height: 36px;
	padding: 0 8px;
	border: 1px solid var(--lf-color-border);
	background: var(--lf-color-bg);
	color: var(--lf-color-text);
	font-size: 14px;
	font-family: var(--lf-font);
	cursor: pointer;
	transition: all 0.15s;
}

.lf-search__page-btn:hover:not(:disabled):not(.lf-search__page-btn--current) {
	background: var(--lf-color-bg-hover);
	border-color: var(--lf-color-accent);
}

.lf-search__page-btn--current {
	background: var(--lf-color-accent);
	color: #fff;
	border-color: var(--lf-color-accent);
	font-weight: 700;
	cursor: default;
}

.lf-search__page-btn:disabled {
	opacity: 0.3;
	cursor: not-allowed;
}

.lf-search__page-ellipsis {
	min-width: 36px;
	height: 36px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--lf-color-muted);
}

/* === Error === */

.lf-search__error {
	padding: 12px 16px;
	margin-bottom: 16px;
	background: #f8d7da;
	border: 1px solid var(--lf-color-danger);
	color: #721c24;
	font-size: 14px;
}

/* === Hide WooCommerce default product grid when search form exists === */

/* Direct siblings */
.lf-search ~ .woocommerce-result-count,
.lf-search ~ .woocommerce-ordering,
.lf-search ~ ul.products,
.lf-search ~ .woocommerce-pagination,
.lf-search ~ .products {
	display: none !important;
}

/* When body has our search form, hide WC products globally on this page.
   The JS adds this class on init. */
body.lf-search-active .woocommerce-result-count,
body.lf-search-active .woocommerce-ordering,
body.lf-search-active ul.products:not(.lf-search__results),
body.lf-search-active .woocommerce-pagination:not(.lf-search__pagination) {
	display: none !important;
}


/* === Filters content wrapper (desktop: transparent grid pass-through) === */

.lf-search__filters-content {
	display: contents;
}

/* === Accordion toggle — hidden on desktop === */

button.lf-search__section-title {
	font-family: var(--lf-font-ui);
	font-size: 14px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: var(--lf-color-heading);
	margin: 20px 0 0;
	background: none;
	border: none;
	padding: 0;
	cursor: pointer;
	text-align: left;
}

.lf-search__filters-accordion-toggle {
	display: none;
}

.lf-search__filters-accordion-chevron {
	transition: transform 0.2s;
}

.lf-search__filters-accordion-toggle[aria-expanded="true"] .lf-search__filters-accordion-chevron {
	transform: rotate(180deg);
}

/* === Responsive === */

@media (max-width: 992px) {
	.lf-search__filters {
		grid-template-columns: repeat(2, 1fr);
	}
}

@media (max-width: 768px) {
	.lf-search__filters {
		display: block;
	}

	/* Show accordion toggle on mobile */
	.lf-search__filters-accordion-toggle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		padding: 0;
		margin: 0 0 0 0;
		background: none;
		border: none;
		cursor: pointer;
		font-size: inherit;
		font-weight: inherit;
		font-family: inherit;
		color: inherit;
		text-align: left;
	}

	/* Filters content: collapsed by default */
	.lf-search__filters-content {
		display: none;
		padding-top: 16px;
	}

	.lf-search__filters-content--open {
		display: block;
	}

	.lf-search__filters-content .lf-search__filter {
		margin-bottom: 12px;
	}

	.lf-search__filters-content .lf-search__filter:last-of-type {
		margin-bottom: 0;
	}
}

@media (max-width: 768px) {
	.lf-search__results {
		grid-template-columns: 1fr;
	}
}

@media (max-width: 480px) {
	.lf-search__submit {
		padding: 12px 14px;
		font-size: 14px;
	}
}
