/**
 * AWF Natural Language Search — Frontend Styles.
 *
 * Design principles:
 * 1. Inherit from theme wherever possible (font, input styles, border-radius).
 * 2. Use CSS custom properties so stores can override from their theme CSS.
 * 3. Zero layout opinions beyond the search bar itself — it flows with the
 *    existing sidebar / shop-loop layout.
 * 4. Mobile-first: 16 px font on small screens prevents iOS auto-zoom.
 * 5. ALL selectors prefixed with awf-nl- — no bare theme/WC selectors.
 *
 * @package Advanced_Woo_Filters
 * @since   1.0.0
 */

/* ============================================================
   CUSTOM PROPERTIES (theme-overridable)
   ============================================================ */

:root {
	--awf-nl-accent:        #2563eb;
	--awf-nl-accent-hover:  #1d4ed8;
	--awf-nl-border:        var(--clean-border, #ddd);
	--awf-nl-text:          var(--clean-text, inherit);
	--awf-nl-text-muted:    var(--clean-gray, #777);
	--awf-nl-bg:            var(--clean-bg, #fff);
	--awf-nl-bg-hover:      var(--clean-hover, #f7f7f7);
	--awf-nl-radius:        6px;
	--awf-nl-shadow:        0 4px 16px rgba(0, 0, 0, 0.1);
	--awf-nl-transition:    0.2s ease;
}

/* ============================================================
   WRAPPER
   ============================================================ */

.awf-nl-search-wrap {
	position: relative;
	max-width: 100%;
	margin: 0 0 20px;
	font-family: inherit;
}

/* When placed above the shop loop via woocommerce_before_shop_loop */
.woocommerce .awf-nl-search-wrap {
	margin-bottom: 24px;
}

/* ============================================================
   FORM (graceful fallback wrapper)
   ============================================================ */

.awf-nl-search-form {
	position: relative;
	display: flex;
	align-items: center;
}

/* ============================================================
   INPUT BAR
   ============================================================ */

.awf-nl-search-input-row {
	position: relative;
	display: flex;
	align-items: center;
	width: 100%;
	border: 1px solid var(--awf-nl-border);
	border-radius: var(--awf-nl-radius);
	background: var(--awf-nl-bg);
	transition: border-color var(--awf-nl-transition),
	            box-shadow var(--awf-nl-transition);
}

.awf-nl-search-input-row:focus-within {
	border-color: var(--awf-nl-accent);
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Searching state */
.awf-nl-searching .awf-nl-search-input-row {
	border-color: var(--awf-nl-accent);
}

/* Search icon */
.awf-nl-search-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 40px;
	color: var(--awf-nl-text-muted);
	pointer-events: none;
}

/* Input field — reset themes, inherit typography */
.awf-nl-search-input {
	flex: 1;
	width: 100%;
	padding: 10px 8px 10px 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--awf-nl-text);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	outline: none;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
}

.awf-nl-search-input::placeholder {
	color: var(--awf-nl-text-muted);
	font-style: italic;
	opacity: 0.7;
}

.awf-nl-search-input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	display: none;
}

/* Clear button — reset all theme styles */
.awf-nl-search-clear {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	margin-right: 4px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--awf-nl-text-muted);
	font-family: inherit;
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
	transition: color var(--awf-nl-transition),
	            background var(--awf-nl-transition);
}

.awf-nl-search-clear:hover {
	background: rgba(220, 38, 38, 0.08);
	color: #dc2626;
}

/* ============================================================
   AUTOCOMPLETE DROPDOWN
   ============================================================ */

.awf-nl-search-dropdown {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 1000;
	margin: 4px 0 0;
	padding: 4px 0;
	list-style: none;
	background: var(--awf-nl-bg);
	border: 1px solid var(--awf-nl-border);
	border-radius: var(--awf-nl-radius);
	box-shadow: var(--awf-nl-shadow);
	max-height: 380px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* Individual suggestion row */
.awf-nl-dd-item {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 8px 12px;
	cursor: pointer;
	color: var(--awf-nl-text);
	font-size: 13px;
	line-height: 1.4;
	list-style: none;
	transition: background var(--awf-nl-transition);
}

.awf-nl-dd-item:hover,
.awf-nl-dd-item.awf-nl-dd-active {
	background: var(--awf-nl-bg-hover);
}

.awf-nl-dd-icon {
	display: flex;
	align-items: center;
	flex-shrink: 0;
	color: var(--awf-nl-accent);
}

.awf-nl-dd-label {
	flex: 1;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.awf-nl-dd-type {
	flex-shrink: 0;
	margin-left: auto;
	padding: 2px 6px;
	border-radius: 3px;
	font-size: 10px;
	font-weight: 600;
	letter-spacing: 0.3px;
	text-transform: uppercase;
	color: var(--awf-nl-text-muted);
	background: var(--awf-nl-bg-hover);
	min-width: max-content;
}

/* ============================================================
   DROPDOWN — Section Dividers (Fix 2 + Fix 7)
   ============================================================ */

.awf-nl-dd-divider {
	display: flex;
	align-items: center;
	margin: 4px 0 0;
	padding: 6px 12px 4px;
	list-style: none;
	border-top: 1px solid var(--awf-nl-border);
	cursor: default;
}

.awf-nl-dd-divider__text {
	font-size: 10px;
	font-weight: 600;
	letter-spacing: 0.4px;
	text-transform: uppercase;
	color: var(--awf-nl-text-muted);
}

/* ============================================================
   DROPDOWN — Product Previews (Fix 2)
   ============================================================ */

.awf-nl-dd-product {
	gap: 10px;
	padding: 8px 12px;
}

.awf-nl-dd-thumb {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	border-radius: 4px;
	overflow: hidden;
	background: var(--awf-nl-bg-hover);
}

.awf-nl-dd-thumb img {
	display: block;
	width: 36px;
	height: 36px;
	object-fit: cover;
	border: 0;
	border-radius: 4px;
	margin: 0;
	padding: 0;
}

.awf-nl-dd-thumb--empty {
	background: var(--awf-nl-bg-hover);
}

.awf-nl-dd-product-info {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
	gap: 1px;
}

.awf-nl-dd-product-name {
	font-size: 13px;
	font-weight: 500;
	color: var(--awf-nl-text);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.awf-nl-dd-product-price {
	font-size: 12px;
	color: var(--awf-nl-text-muted);
}

/* ============================================================
   DROPDOWN — Popular Searches (Fix 7)
   ============================================================ */

.awf-nl-dd-popular .awf-nl-dd-icon {
	color: var(--awf-nl-text-muted);
}

.awf-nl-dd-popular .awf-nl-dd-label {
	font-style: italic;
}

/* ============================================================
   PARSED TAGS — Interactive with × remove button (Fix 4)
   ============================================================ */

.awf-nl-search-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 8px;
}

.awf-nl-tag {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 3px 6px 3px 10px;
	border-radius: 100px;
	font-size: 12px;
	font-weight: 500;
	line-height: 1.5;
	white-space: nowrap;
	text-transform: capitalize;
	cursor: default;
	transition: opacity var(--awf-nl-transition);
}

.awf-nl-tag:hover {
	opacity: 0.85;
}

/* Tag × remove button — fully reset */
.awf-nl-tag__remove {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 18px;
	height: 18px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.1);
	color: inherit;
	font-family: inherit;
	font-size: 12px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
	opacity: 0.6;
	transition: opacity var(--awf-nl-transition),
	            background var(--awf-nl-transition);
}

.awf-nl-tag__remove:hover {
	opacity: 1;
	background: rgba(0, 0, 0, 0.2);
}

/* Tag colour variants */
.awf-nl-tag--price {
	background: #fef3c7;
	color: #92400e;
}

.awf-nl-tag--attribute {
	background: #dbeafe;
	color: #1e40af;
}

.awf-nl-tag--category {
	background: #d1fae5;
	color: #065f46;
}

.awf-nl-tag--modifier {
	background: #ede9fe;
	color: #5b21b6;
}

.awf-nl-tag--keyword {
	background: #f3f4f6;
	color: #374151;
}

/* ============================================================
   STATUS MESSAGES
   ============================================================ */

.awf-nl-search-status {
	margin-top: 6px;
	font-size: 13px;
	line-height: 1.5;
}

/* Loading */
.awf-nl-status-loading {
	color: var(--awf-nl-accent);
}

.awf-nl-status-loading::before {
	content: '';
	display: inline-block;
	width: 12px;
	height: 12px;
	margin-right: 6px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	vertical-align: -2px;
	animation: awf-nl-spin 0.6s linear infinite;
}

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

/* Result count */
.awf-nl-status-count {
	color: #059669;
}

/* No results */
.awf-nl-status-empty {
	color: #d97706;
}

/* Error */
.awf-nl-status-error {
	color: #dc2626;
}

/* Fix 6: "Did you mean" correction message */
.awf-nl-status-correction {
	color: var(--awf-nl-accent);
	font-style: italic;
	font-size: 12px;
}

/* "Did you mean?" clickable suggestions */
.awf-nl-suggestions {
	margin-top: 6px;
	font-size: 13px;
	color: #666;
}

.awf-nl-suggestions__label {
	font-style: italic;
}

.awf-nl-suggestion-link {
	color: var(--awf-nl-accent, #4a7c59);
	font-weight: 600;
	text-decoration: underline;
	cursor: pointer;
}

.awf-nl-suggestion-link:hover {
	color: #333;
}

/* ============================================================
   LOADING STATE — product grid overlay during search
   ============================================================ */

.awf-loading {
	position: relative;
	opacity: 0.5;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

/* ============================================================
   RESPONSIVE — TABLET (1024px)
   ============================================================ */

@media ( max-width: 1024px ) {
	.awf-nl-search-dropdown {
		max-height: 320px;
	}
}

/* ============================================================
   RESPONSIVE — MOBILE (768px)
   ============================================================ */

@media ( max-width: 768px ) {
	.awf-nl-search-input {
		font-size: 16px; /* prevents iOS auto-zoom */
		padding: 12px 8px 12px 0;
	}

	.awf-nl-search-icon {
		width: 44px;
	}

	.awf-nl-dd-item {
		padding: 10px 12px;
	}

	.awf-nl-search-dropdown {
		max-height: 280px;
	}

	/* Make tags scrollable instead of wrapping on small screens */
	.awf-nl-search-tags {
		flex-wrap: nowrap;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		padding-bottom: 4px;
	}
}

/* ============================================================
   ACCESSIBILITY — reduced motion
   ============================================================ */

@media ( prefers-reduced-motion: reduce ) {
	.awf-nl-search-input-row,
	.awf-nl-search-clear,
	.awf-nl-dd-item,
	.awf-nl-tag,
	.awf-nl-tag__remove {
		transition: none;
	}

	.awf-nl-status-loading::before {
		animation: none;
	}
}
