/**
 * Fillerdepot Product Finder — front-end styles.
 *
 * Everything is scoped under .fdpf and driven by CSS custom properties, so a
 * theme can retint the whole widget by overriding the variables on .fdpf.
 *
 * Note: no font-size rules on desktop — text inherits the theme's typography.
 * The only sizes are a few em-based tweaks inside the small-screen media query.
 */

.fdpf {
	--fdpf-bg: #fafcff;
	--fdpf-fg: #363636;
	--fdpf-muted: #7b7b7b;
	--fdpf-line: #eef0f4;
	--fdpf-accent: #12294a;
	--fdpf-accent-hover: #1c3a63;
	--fdpf-accent-contrast: #ffffff;
	--fdpf-badge: #d83b4f;
	--fdpf-media-bg: #f6f7f9;
	--fdpf-radius: 14px;

	box-sizing: border-box;
	max-width: 100%;
	margin: 0 auto;
	padding: clamp(16px, 3vw, 28px);
	background: var(--fdpf-bg);
	border: 1px solid var(--fdpf-line);
	border-radius: var(--fdpf-radius);
	box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
	color: var(--fdpf-fg);
	position: relative;
}

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

/* ---------------------------------------------------------------- Header */

.fdpf__head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding-bottom: 18px;
	margin-bottom: 4px;
	border-bottom: 1px solid var(--fdpf-line);
}

.fdpf__title {
	margin: 0;
	font-weight: 700;
	font-size: var(--h3_font_size_desktop);
	line-height: 1.2;
	color: var(--fdpf-fg);
}

.fdpf__control {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-left: auto;
}

/* Visually hidden but available to screen readers. */
.fdpf__label {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Custom dropdown: a button that opens a menu panel of options. */
.fdpf__dropdown {
	position: relative;
	font-family: 'Lato';
}

.fdpf__toggle {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	max-width: 100%;
	padding: 8px 0px;
	margin: 0;
	background: none;
	border: 0;
	color: inherit;
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
}

.fdpf__toggle-text {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 220px;
}

/* Chevron: points down by default, flips up while the menu is open. */
.fdpf__toggle-arrow {
	flex-shrink: 0;
	width: 8px;
	height: 8px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: translateY(-2px) rotate(45deg);
	transition: transform 0.15s ease;
}

.fdpf__toggle[aria-expanded="true"] .fdpf__toggle-arrow {
	transform: translateY(2px) rotate(-135deg);
}

.fdpf__menu {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	z-index: 30;
	min-width: 240px;
	max-width: min(320px, 82vw);
	margin: 0;
	padding: 6px;
	list-style: none;
	background: #fff;
	border: 1px solid var(--fdpf-line);
	border-radius: 12px;
	box-shadow: 0 12px 32px rgba(16, 24, 40, 0.14);
	opacity: 0;
	visibility: hidden;
	transform: translateY(-6px);
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.fdpf__dropdown.is-open .fdpf__menu {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.fdpf__menu-item {
	padding: 10px 14px;
	border-radius: 8px;
	color: var(--fdpf-fg);
	line-height: 1.35;
	cursor: pointer;
}

.fdpf__menu-item:hover,
.fdpf__menu-item:focus,
.fdpf__menu-item.is-active {
	outline: none;
	background: var(--fdpf-media-bg);
}

.fdpf__menu-item.is-selected {
	font-weight: 700;
}

/* ------------------------------------------------------------- Product list */

.fdpf__body {
	transition: opacity 0.2s ease;
}

.fdpf-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.fdpf-card {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto auto;
	align-items: center;
	gap: 20px;
	padding: 18px 4px;
	border-bottom: 1px solid var(--fdpf-line);
}

.fdpf-card:last-child {
	border-bottom: 0;
}

.fdpf-card__media {
	position: relative;
	display: block;
	width: 100px;
	height: 100px;
	flex-shrink: 0;
	border-radius: 12px;
	overflow: hidden;
	background: var(--fdpf-media-bg);
}

.fdpf-card__media img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
}

.fdpf-card__badge {
	position: absolute;
	top: 6px;
	left: 6px;
	line-height: 1.4;
	border-radius: 6px;
	font-family: Lato;
	background: #f5d7cd;
	color: var(--fdpf-badge);
	font-weight: 700;
	padding: 2px 12px;
}

.fdpf-card__info {
	min-width: 0;
}

.fdpf-card__title {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	font-weight: 600;
	line-height: 1.35;
	color: var(--fdpf-fg);
	text-decoration: none;
}

.fdpf-card__title:hover,
.fdpf-card__title:focus-visible {
	color: var(--fdpf-accent);
}

.fdpf-card__price {
	display: flex;
	flex-direction: column;
	align-self: center;	
	font-weight: 700;
	white-space: nowrap;
	color: var(--fdpf-fg);
}

.fdpf-card__price del {
	margin-right: 6px;
	font-weight: 500;
	color: var(--fdpf-muted);
}

.fdpf-card__price ins {
	text-decoration: none;
}

.fdpf-card__buy {
	justify-self: end;
}

/* --------------------------------------------------------------- Buttons */

.fdpf-card__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 118px;
	padding: 12px 22px;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	color: var(--fdpf-accent-contrast);
	background: var(--fdpf-accent);
	border: 1px solid var(--fdpf-accent);
	border-radius: 10px;
	cursor: pointer;
	transition: background-color 0.15s ease, transform 0.05s ease;
}

.fdpf-card__btn:hover {
	background: var(--fdpf-accent-hover);
	border-color: var(--fdpf-accent-hover);
	color: var(--fdpf-accent-contrast);
}

.fdpf-card__btn:active {
	transform: translateY(1px);
}

.fdpf-card__btn:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px rgba(18, 41, 74, 0.25);
}

/* WooCommerce toggles .loading / .added while the AJAX add runs. */
.fdpf-card__btn.loading {
	opacity: 0.7;
	pointer-events: none;
}

.fdpf-card__btn.added {
	background: var(--fdpf-accent-hover);
}

.fdpf-card__btn--oos {
	color: var(--fdpf-muted);
	background: #eceef2;
	border-color: #eceef2;
	cursor: not-allowed;
}

.fdpf-card__btn--oos:hover {
	color: var(--fdpf-muted);
	background: #eceef2;
	border-color: #eceef2;
}

/* WooCommerce injects an "added to cart" link after the button; hide it inside
   the finder to keep the row layout tidy — the mini-cart already updates. */
.fdpf-card__buy .added_to_cart {
	display: none;
}

/* ------------------------------------------------------ Empty & loading state */

.fdpf-empty {
	margin: 0;
	padding: 32px 8px;
	text-align: center;
	color: var(--fdpf-muted);
}

.fdpf-empty--error {
	color: var(--fdpf-badge);
}

.fdpf__loader {
	position: absolute;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.55);
	border-radius: var(--fdpf-radius);
}

.fdpf.is-loading .fdpf__loader {
	display: flex;
}

.fdpf.is-loading .fdpf__body {
	opacity: 0.4;
	pointer-events: none;
}

.fdpf__spinner {
	width: 34px;
	height: 34px;
	border: 3px solid rgba(18, 41, 74, 0.2);
	border-top-color: var(--fdpf-accent);
	border-radius: 50%;
	animation: fdpf-spin 0.7s linear infinite;
}

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

/* Admin-only hint shown when nothing is configured. */
.fdpf-admin-hint {
	padding: 16px 18px;
	color: #7a5900;
	background: #fff8e5;
	border: 1px solid #f5e2a3;
	border-radius: 10px;
}

/* ------------------------------------------------------------- Responsive */

@media (max-width: 640px) {
	.fdpf__head {
		align-items: center;
	}

	/* Keep the toggle label from crowding the heading on narrow screens. */
	.fdpf__toggle-text {
		max-width: 42vw;
	}

	/* Heading tuned for phones (em is relative to the inherited theme size;
	   desktop is untouched). The .fdpf prefix raises specificity so it wins
	   over the theme's heading styles. */
	.fdpf .fdpf__title {
		font-size: var(--h3_font_size_mobile);
	}

	.fdpf-card {
		grid-template-columns: 96px minmax(0, 1fr) auto;
		grid-template-areas:
			"media info info"
			"media price buy";
		gap: 4px 12px;
		padding: 14px 2px;
	}

	.fdpf-card__media {
		grid-area: media;
		width: 96px;
		height: 96px;
		align-self: start;
	}

	.fdpf-card__info {
		grid-area: info;
	}

	/* Product title, allowed up to 3 lines. */
	.fdpf .fdpf-card__title {
		-webkit-line-clamp: 3;
		line-clamp: 3;
	}

	/* Stack the strikethrough regular price UNDER the sale price and shrink it,
	   so the price no longer crowds the button. `order` keeps the sale price on
	   top regardless of the order WooCommerce outputs <del>/<ins> in. */
	.fdpf-card__price {
		grid-area: price;
		align-self: center;
		line-height: 1.25;
	}

	.fdpf-card__price ins {
		order: 0;
	}

	.fdpf-card__price del {
		order: 1;
		margin: 1px 0 0;
		font-size: 0.82em;
	}

	.fdpf-card__buy {
		grid-area: buy;
		align-self: center;
	}

	.fdpf .fdpf-card__btn {
		min-width: 0;
		padding: 9px 14px;
		font-size: 0.9em;
	}
}

@media (prefers-reduced-motion: reduce) {
	.fdpf__body,
	.fdpf-card__btn {
		transition: none;
	}

	.fdpf__spinner {
		animation-duration: 2s;
	}
}
