/**
 * The following styles get applied both on the front of your site
 * and in the editor.
 */

/* Dropdown Facet */
.wpengine-smart-dropdown-facet {
	.wpengine-smart-search-dropdown-facet__label {
		display: block;
		margin: 0 0 0.75rem 0;
		font-weight: 600;
		font-size: var(--wp--preset--font-size--medium, 1rem);
		color: var(--wp--preset--color--contrast, inherit);
	}

	.wpengine-smart-dropdown-facet__fields {
		display: flex;
		flex: auto;
		flex-wrap: nowrap;
		max-width: 100%;
	}

	.wpengine-smart-dropdown-facet__field {
		width: var(--wp--custom--input-width, 100%);
		appearance: none;
		background-color: var(--wp--preset--color--base, #fff);
		border: var(--wp--custom--input-border-width, 1px) solid var(--wp--custom--input-border-color, #949494);
		flex-grow: var(--wp--custom--input-flex-grow, 1);
		padding: var(--wp--custom--input--padding, 0.625rem);
		border-radius: var(--wp--custom--input-border-radius, 4px);
		min-height: var(--wp--custom--input-min-height, 2.5em);
		font-size: var(--wp--preset--font-size--small, 0.875rem);
		color: var(--wp--preset--color--contrast, inherit);
		cursor: pointer;
		transition: border-color 0.15s ease-in-out;
		background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="%23949494" d="M1.41 0L6 4.59L10.59 0L12 1.41l-6 6l-6-6z"/></svg>');
		background-repeat: no-repeat;
		background-position: right 0.625rem center;
		padding-right: 2.25rem;

		&:hover {
			border-color: var(--wp--preset--color--contrast, #666);
		}

		&:focus {
			outline: 2px solid var(--wp--preset--color--primary, #007cba);
			outline-offset: 2px;
		}

		&:disabled {
			opacity: 0.5;
			cursor: not-allowed;
		}
	}

	.wpengine-smart-dropdown-facet__apply-button {
		margin-top: 1rem;
		width: 100%;
	}
}

/* Checkbox Facet */
.wpengine-smart-checkbox-facet {
	.wpengine-smart-search-checkbox-facet__label {
		display: block;
		margin: 0 0 0.75rem 0;
		font-weight: 600;
		font-size: var(--wp--preset--font-size--medium, 1rem);
		color: var(--wp--preset--color--contrast, inherit);
	}

	.wpengine-smart-checkbox-facet__search {
		margin-bottom: 0.75rem;

		.wpengine-smart-checkbox-facet__search-input {
			width: 100%;
			max-width: 100%;
			box-sizing: border-box;
			appearance: none;
			background-color: var(--wp--preset--color--base, #fff);
			border: var(--wp--custom--input-border-width, 1px) solid var(--wp--custom--input-border-color, #949494);
			padding: var(--wp--custom--input--padding, 0.625rem);
			border-radius: var(--wp--custom--input-border-radius, 4px);
			font-size: var(--wp--preset--font-size--small, 0.875rem);
			color: var(--wp--preset--color--contrast, inherit);
			min-height: var(--wp--custom--input-min-height, 2.5em);
			transition: border-color 0.15s ease-in-out;

			&::placeholder {
				color: var(--wp--preset--color--contrast-3, #999);
				opacity: 1;
			}

			&:hover {
				border-color: var(--wp--preset--color--contrast, #666);
			}

			&:focus {
				outline: 2px solid var(--wp--preset--color--primary, #007cba);
				outline-offset: 2px;
			}
		}
	}

	.wpengine-smart-checkbox-facet__fields {
		display: flex;
		flex-direction: column;
		gap: var(--wp--custom--checkbox-gap, 0.5rem);
		max-width: 100%;
		padding: 0.25rem 0;

		&.scrollable {
			overflow-y: auto;
			padding-right: 0.25rem;

			/* Custom scrollbar */
			&::-webkit-scrollbar {
				width: 8px;
			}

			&::-webkit-scrollbar-track {
				background: var(--wp--preset--color--base-2, #f0f0f0);
				border-radius: 4px;
			}

			&::-webkit-scrollbar-thumb {
				background: var(--wp--preset--color--contrast-3, #999);
				border-radius: 4px;

				&:hover {
					background: var(--wp--preset--color--contrast-2, #666);
				}
			}
		}

		/* Empty state message */
		> div:only-child {
			padding: 1rem;
			text-align: center;
			color: var(--wp--preset--color--contrast-2, #666);
			font-style: italic;
			font-size: var(--wp--preset--font-size--small, 0.875rem);
		}
	}

	.wpengine-smart-checkbox-facet__field {
		display: flex;
		align-items: center;
		padding: 0.375rem 0.5rem 0.375rem 0;
		border-radius: var(--wp--custom--checkbox-border-radius, 4px);
		transition: background-color 0.15s ease-in-out;

		&:hover {
			background-color: var(--wp--preset--color--base-2, #f5f5f5);
		}

		label {
			display: flex;
			align-items: center;
			cursor: pointer;
			user-select: none;
			width: 100%;
			margin: 0;
			font-size: var(--wp--preset--font-size--small, 0.875rem);
			line-height: 1.5;
			color: var(--wp--preset--color--contrast, inherit);
		}

		input[type="checkbox"] {
			appearance: none;
			-webkit-appearance: none;
			-moz-appearance: none;
			width: 1.125rem;
			height: 1.125rem;
			margin: 0 0.625rem 0 0;
			cursor: pointer;
			flex-shrink: 0;
			border: var(--wp--custom--input-border-width, 1px) solid var(--wp--custom--input-border-color, #949494);
			border-radius: var(--wp--custom--checkbox-border-radius, 4px);
			background-color: var(--wp--preset--color--base, #fff);
			position: relative;
			transition: all 0.15s ease-in-out;

			&:hover {
				border-color: var(--wp--preset--color--contrast, #666);
			}

			&:checked {
				background-color: var(--wp--preset--color--primary, #007cba);
				border-color: var(--wp--preset--color--primary, #007cba);

				&::after {
					content: '';
					position: absolute;
					left: 50%;
					top: 50%;
					transform: translate(-50%, -50%) rotate(45deg);
					width: 0.3125rem;
					height: 0.5625rem;
					border: solid var(--wp--preset--color--base, #fff);
					border-width: 0 2px 2px 0;
				}
			}

			&:focus {
				outline: 2px solid var(--wp--preset--color--primary, #007cba);
				outline-offset: 2px;
			}

			&:disabled {
				opacity: 0.5;
				cursor: not-allowed;
			}
		}
	}

	.wpengine-smart-checkbox-facet__apply-button {
		margin-top: 1rem;
		width: 100%;
	}

	// Hierarchical expansion controls
	.term-expand-toggle {
		background: none;
		border: none;
		padding: 0;
		margin-right: 0.5rem;
		width: 1.25rem;
		height: 1.25rem;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
		transition: transform 0.2s ease;
		flex-shrink: 0;
		color: var(--wp--preset--color--contrast, #666);
		vertical-align: middle;

		&:hover {
			color: var(--wp--preset--color--contrast, #333);
		}

		&:focus {
			outline: 2px solid var(--wp--preset--color--primary, #007cba);
			outline-offset: 2px;
			border-radius: 2px;
		}

		.expand-icon {
			display: block;
			width: 0;
			height: 0;
			border-left: 4px solid transparent;
			border-right: 4px solid transparent;
			border-top: 6px solid currentColor;
			transition: transform 0.2s ease;
		}

		&[aria-expanded="true"] .expand-icon {
			transform: rotate(180deg);
		}
	}

	.term-spacer {
		display: inline-block;
		width: 1.25rem;
		margin-right: 0.5rem;
		flex-shrink: 0;
	}

	.wpengine-smart-checkbox-facet__field {
		&.term-collapsed {
			display: none !important;
		}

		&.term-expanded {
			display: flex;
		}
	}
}

/* Radio Facet */
.wpengine-smart-radio-facet {
	.wpengine-smart-search-radio-facet__label {
		display: block;
		margin: 0 0 0.75rem 0;
		font-weight: 600;
		font-size: var(--wp--preset--font-size--medium, 1rem);
		color: var(--wp--preset--color--contrast, inherit);
	}

	.wpengine-smart-radio-facet__fields {
		display: flex;
		flex-direction: column;
		gap: var(--wp--custom--radio-gap, 0.5rem);
		max-width: 100%;
		padding: 0.25rem 0;
	}

	.wpengine-smart-radio-facet__field {
		display: flex;
		align-items: center;
		padding: 0.375rem 0.5rem;
		border-radius: var(--wp--custom--radio-border-radius, 4px);
		transition: background-color 0.15s ease-in-out;

		&:hover {
			background-color: var(--wp--preset--color--base-2, #f5f5f5);
		}

		label {
			display: flex;
			align-items: center;
			cursor: pointer;
			user-select: none;
			width: 100%;
			margin: 0;
			font-size: var(--wp--preset--font-size--small, 0.875rem);
			line-height: 1.5;
			color: var(--wp--preset--color--contrast, inherit);
		}

		input[type="radio"] {
			margin: 0 0.625rem 0 0;
			cursor: pointer;
			flex-shrink: 0;
			/* Inherit theme's radio styling - minimal custom styles */
			accent-color: var(--wp--preset--color--primary, currentColor);

			&:focus {
				outline: 2px solid var(--wp--preset--color--primary, #007cba);
				outline-offset: 2px;
			}

			&:disabled {
				opacity: 0.5;
				cursor: not-allowed;
			}
		}
	}

	.wpengine-smart-radio-facet__apply-button {
		margin-top: 1rem;
		width: 100%;
	}
}