/**
 * Giveaway filter component.
 *
 * Mobile-first: filters live in a slide-in drawer below the toolbar.
 * Desktop (≥992px): dropdown bar at the top, count line, results
 * underneath. WCAG 2.1 AA contrast + visible focus throughout.
 *
 * Native CSS nesting only — the project has no preprocessor, so
 * `&__elem` Sass-style concatenation is NOT used (it does not exist
 * in the spec). `&` is a selector reference: pseudo-class states
 * (&:hover), modifier classes (&.is-active), and descendants
 * (& .child) are nested; BEM child elements stay as top-level rules.
 */

/* ─────────────────────────── design tokens ─────────────────────────── */
/* :where() keeps tokens at specificity 0 so a single source applies to
   every filter-component root without contributing to specificity wars. */
:where(.ilg-gf-toolbar, .ilg-gf-active, .ilg-gf-drawer, .ilg-gf-bar) {
	--gf-fg:           #1f2937;
	--gf-fg-muted:     #6b7280;
	--gf-bg:           #ffffff;
	--gf-bg-soft:      #f8fafc;
	--gf-bg-hover:     #e2e8f0;
	--gf-border:       #d1d5db;
	--gf-border-strong:#9ca3af;
	--gf-accent:       #1d3557; /* selected/active states, checked, count badges */
	--gf-accent-fg:    #ffffff;
	--gf-accent-soft:  #eef4ff; /* tinted bg for active trigger/chip */
	--gf-btn:          #1d3557; /* primary action button (Apply) */
	--gf-btn-hover:    #142540;
	--gf-btn-fg:       #ffffff;
	--gf-danger:       #b91c1c;
	--gf-radius:       8px;
	--gf-radius-sm:    6px;
	--gf-radius-pill:  9999px;
	--gf-gap:          12px;
	--gf-pad:          16px;
	--gf-shadow:       0 8px 24px rgba(15, 23, 42, 0.10);
	--gf-focus:        0 0 0 3px rgba(29, 53, 87, 0.45);
	--gf-tap:          44px; /* WCAG touch target */
}

/* Screen-reader-only utility (legend on flag fieldset, etc.) */
.ilg-gf-screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

/* ─────────────────────────── toolbar (mobile) ─────────────────────────── */
.ilg-gf-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--gf-gap);
	margin: 0 0 var(--gf-gap);
	padding: 12px var(--gf-pad);
	background: var(--gf-bg-soft);
	border: 1px solid var(--gf-border);
	border-radius: var(--gf-radius);
	color: var(--gf-fg);
}

.ilg-gf-toolbar__toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: var(--gf-tap);
	padding: 8px 14px;
	border: 1px solid var(--gf-border-strong);
	background: var(--gf-bg);
	color: var(--gf-fg);
	border-radius: var(--gf-radius-pill);
	font: inherit;
	font-weight: 600;
	cursor: pointer;

	&:hover { background: var(--gf-bg-hover); }

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
		border-color: var(--gf-accent);
	}
}

.ilg-gf-toolbar__icon { flex: 0 0 auto; }

.ilg-gf-toolbar__count {
	margin: 0;
	color: var(--gf-fg-muted);
	font-weight: 500;
}

/* ─────────────────────────── active-filter chips ─────────────────────────── */
.ilg-gf-active {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--gf-gap);
	margin: 0 0 var(--gf-gap);
}

.ilg-gf-active__label {
	color: var(--gf-fg-muted);
	font-weight: 600;
}

.ilg-gf-active__list {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ilg-gf-active__item { margin: 0; }

.ilg-gf-active__clear {
	margin-left: auto;
	min-height: var(--gf-tap);
	display: inline-flex;
	align-items: center;
	padding: 6px 10px;
	color: var(--gf-danger);
	text-decoration: underline;
	border-radius: var(--gf-radius);

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
	}
}

/* Chip — used for active-filter pills above the results grid. */
.ilg-gf-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 32px;
	padding: 4px 10px;
	background: var(--gf-bg);
	border: 1px solid var(--gf-border-strong);
	border-radius: var(--gf-radius-pill);
	color: var(--gf-fg);
	text-decoration: none;
	font-size: 0.9375rem;
	line-height: 1.2;

	&:hover {
		background: var(--gf-bg-hover);
		color: var(--gf-fg);
		text-decoration: none;
	}

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
	}

	&.ilg-gf-chip--active {
		background: var(--gf-accent-soft);
		border-color: var(--gf-accent);
		color: var(--gf-accent);

		&:hover { color: var(--gf-accent); }
	}
}

.ilg-gf-chip__x {
	font-size: 1.1rem;
	line-height: 1;
}

/* ─────────────────────────── drawer (mobile) ─────────────────────────── */
.ilg-gf-drawer {
	position: fixed;
	inset: 0;
	/* Must layer above the theme's sticky .ilg-header (z-index: 9999) so
	   the close button isn't hidden behind the mobile menu bar. */
	z-index: 10000;
	display: block;

	&[hidden] { display: none; }

	&.is-open .ilg-gf-drawer__panel { transform: translateX(0); }
}

.ilg-gf-drawer__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(15, 23, 42, 0.5);
}

.ilg-gf-drawer__panel {
	position: absolute;
	top: 0; right: 0; bottom: 0;
	width: min(420px, 100%);
	background: var(--gf-bg);
	box-shadow: var(--gf-shadow);
	display: flex;
	flex-direction: column;
	transform: translateX(100%);
	transition: transform 220ms ease;
}

@media (prefers-reduced-motion: reduce) {
	.ilg-gf-drawer__panel { transition: none; }
}

.ilg-gf-drawer__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--gf-gap);
	padding: var(--gf-pad);
	border-bottom: 1px solid var(--gf-border);
}

.ilg-gf-drawer__title {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 700;
	color: var(--gf-fg);
}

/* !important defends against the theme's generic button rules that
   would otherwise paint this control as a dark block and hide the ×. */
.ilg-gf-drawer__close {
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	width: var(--gf-tap);
	height: var(--gf-tap);
	background: transparent !important;
	border: 1px solid var(--gf-border) !important;
	border-radius: var(--gf-radius);
	color: var(--gf-fg) !important;
	cursor: pointer;
	font-size: 28px;
	font-weight: 400;
	line-height: 1;
	padding: 0 !important;

	& > span {
		display: block;
		margin-top: -3px; /* visually center the × glyph */
	}

	&:hover {
		background: var(--gf-bg-hover) !important;
		border-color: var(--gf-fg) !important;
	}

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
	}
}

.ilg-gf-drawer__form {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
}

.ilg-gf-drawer__body {
	flex: 1;
	overflow-y: auto;
	padding: var(--gf-pad);

	/* Each fieldset reads as a clearly bounded section so users see
	   where one filter ends and the next begins. */
	& .ilg-gf-fieldset {
		padding-bottom: 20px;
		margin-bottom: 20px;
		border-bottom: 2px solid var(--gf-border);

		&:last-child {
			border-bottom: 0;
			padding-bottom: 0;
			margin-bottom: 0;
		}
	}

	& .ilg-gf-fieldset__legend {
		font-size: 1.05rem;
		margin-bottom: 12px;
	}

	/* Per-list inner scroll so a 250-item country list doesn't blow the
	   drawer into a 4000px column. */
	& .ilg-gf-fieldset__list {
		max-height: 240px;
		overflow-y: auto;
		border: 1px solid var(--gf-border);
		border-radius: var(--gf-radius);
		padding: 8px;
		background: var(--gf-bg-soft);
	}
}

.ilg-gf-drawer__footer {
	display: flex;
	gap: var(--gf-gap);
	padding: var(--gf-pad);
	border-top: 1px solid var(--gf-border);
	background: var(--gf-bg);
}

/* ─────────────────────────── fieldset (shared) ─────────────────────────── */
.ilg-gf-fieldset {
	border: 0;
	padding: 0;
	margin: 0 0 24px;
}

.ilg-gf-fieldset__legend {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0 0 10px;
	padding: 0;
	font-weight: 700;
	color: var(--gf-fg);
}

.ilg-gf-fieldset__count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: var(--gf-radius-pill);
	background: var(--gf-accent);
	color: var(--gf-accent-fg);
	font-size: 0.8125rem;
	font-weight: 700;
	line-height: 1;
}

.ilg-gf-fieldset__list {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	padding: 0;
	list-style: none;
	/* Default: no inner scroll. Drawer body and dropdown panel each
	   add their own cap via descendant rules. */
}

.ilg-gf-fieldset__item { margin: 0; }

/* ─────────────────────────── checkbox/radio row ─────────────────────────── */
.ilg-gf-check {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	min-height: var(--gf-tap);
	padding: 6px 8px;
	border-radius: var(--gf-radius);
	color: var(--gf-fg);
	cursor: pointer;
	transition: background-color 100ms ease, box-shadow 100ms ease;

	/* Dual cue (WCAG 1.4.11): darker bg + left-accent stripe gives clear
	   non-text contrast against unhovered rows, not just against panel. */
	&:hover {
		background: var(--gf-bg-hover);
		box-shadow: inset 3px 0 0 0 var(--gf-accent);
		color: var(--gf-fg);

		& .ilg-gf-check__label,
		& .ilg-gf-check__count { color: inherit; }
	}
}

/* Hide native input but keep it accessible. The visible square / circle
   is rendered by .ilg-gf-check__box / __radio, state mirrored via + sibling. */
.ilg-gf-check__input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	border: 0;

	&:checked + .ilg-gf-check__box {
		background: var(--gf-accent);
		border-color: var(--gf-accent);
		background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='5 12 10 17 19 8'/></svg>");
		background-repeat: no-repeat;
		background-position: center;
	}

	&:checked + .ilg-gf-check__radio { border-color: var(--gf-accent); }

	&:checked + .ilg-gf-check__radio::after {
		content: "";
		position: absolute;
		inset: 4px;
		border-radius: 50%;
		background: var(--gf-accent);
	}

	&:focus-visible + .ilg-gf-check__box,
	&:focus-visible + .ilg-gf-check__radio { box-shadow: var(--gf-focus); }
}

.ilg-gf-check__box {
	flex: 0 0 auto;
	display: inline-block;
	width: 20px;
	height: 20px;
	border: 2px solid var(--gf-border-strong);
	border-radius: 4px;
	background: var(--gf-bg);
	transition: background-color 100ms ease, border-color 100ms ease;
}

.ilg-gf-check__radio {
	flex: 0 0 auto;
	display: inline-block;
	width: 20px;
	height: 20px;
	border: 2px solid var(--gf-border-strong);
	border-radius: 50%;
	background: var(--gf-bg);
	position: relative;
	transition: border-color 100ms ease;
}

.ilg-gf-check__label { flex: 1 1 auto; }

.ilg-gf-check__count {
	color: var(--gf-fg-muted);
	font-variant-numeric: tabular-nums;
}

/* ─────────────────────────── buttons ─────────────────────────── */
.ilg-gf-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--gf-tap);
	padding: 10px 18px;
	border-radius: var(--gf-radius);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	text-decoration: none;
	border: 1px solid transparent;

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
	}
}

.ilg-gf-btn--primary {
	flex: 1;
	background: var(--gf-btn);
	color: var(--gf-btn-fg);
	border-color: var(--gf-btn);

	&:hover {
		background: var(--gf-btn-hover);
		border-color: var(--gf-btn-hover);
	}

	/* Loading state shown on submit so users see something happen
	   between click and page reload. Filled style with spinner left. */
	&.is-loading,
	&[aria-busy="true"],
	&:disabled {
		background: var(--gf-btn);
		color: var(--gf-btn-fg);
		border-color: var(--gf-btn);
		opacity: 0.85;
		cursor: progress;
		position: relative;
		padding: 8px 28px 8px 48px;
	}

	&.is-loading::before {
		content: "";
		position: absolute;
		top: 50%;
		left: 18px;
		width: 14px;
		height: 14px;
		margin-top: -7px;
		border: 2px solid currentColor;
		border-top-color: transparent;
		border-radius: 50%;
		animation: ilg-gf-spin 0.6s linear infinite;
	}
}

.ilg-gf-btn--secondary {
	background: var(--gf-bg);
	color: var(--gf-fg);
	border-color: var(--gf-border-strong);

	&:hover { background: var(--gf-bg-hover); }
}

/* Low-emphasis text button (Clear in dropdown footers). */
.ilg-gf-btn--ghost {
	background: transparent;
	color: var(--gf-fg-muted);
	border-color: transparent;
	text-decoration: underline;
	padding: 8px 10px;

	&:hover {
		color: var(--gf-fg);
		background: var(--gf-bg-hover);
	}

	&.is-loading,
	&[aria-busy="true"] {
		cursor: progress;
		opacity: 0.85;
		position: relative;
		padding-left: 28px;
	}

	&.is-loading::before {
		content: "";
		position: absolute;
		top: 50%;
		left: 6px;
		width: 14px;
		height: 14px;
		margin-top: -7px;
		border: 2px solid currentColor;
		border-top-color: transparent;
		border-radius: 50%;
		animation: ilg-gf-spin 0.6s linear infinite;
	}
}

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

/* Loading state for the theme's Load More button — same spinner
   treatment as the Apply/Clear buttons. Scoped tightly so we don't
   change the button's normal hover/active appearance. */
.ilg-load-more-btn.is-loading,
.ilg-load-more-btn[aria-busy="true"] {
	cursor: progress;
	opacity: 0.85;
	position: relative;
	padding-left: 36px !important;
}

.ilg-load-more-btn.is-loading::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 14px;
	width: 14px;
	height: 14px;
	margin-top: -7px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: ilg-gf-spin 0.6s linear infinite;
}

/* Secondary button loading state (bar's Reset all, drawer's Reset). */
.ilg-gf-btn--secondary.is-loading,
.ilg-gf-btn--secondary[aria-busy="true"] {
	cursor: progress;
	opacity: 0.85;
	position: relative;
	padding-left: 32px;
}

.ilg-gf-btn--secondary.is-loading::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 10px;
	width: 14px;
	height: 14px;
	margin-top: -7px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: ilg-gf-spin 0.6s linear infinite;
}

/* Active-chip-row "Clear all" link loading state — underlined text
   variant matching the same pattern. */
.ilg-gf-active__clear.is-loading,
.ilg-gf-active__clear[aria-busy="true"] {
	cursor: progress;
	opacity: 0.85;
	position: relative;
	padding-left: 28px;
}

.ilg-gf-active__clear.is-loading::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 6px;
	width: 14px;
	height: 14px;
	margin-top: -7px;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: ilg-gf-spin 0.6s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
	.ilg-gf-btn--primary.is-loading::before,
	.ilg-gf-btn--ghost.is-loading::before,
	.ilg-gf-btn--secondary.is-loading::before,
	.ilg-gf-active__clear.is-loading::before,
	.ilg-load-more-btn.is-loading::before { animation: none; }
}

/* ─────────────────────────── desktop dropdown bar ─────────────────────────── */
/* Hidden on mobile (drawer takes over). Activated by the desktop
   media query at the bottom of the file. */
.ilg-gf-bar { display: none; }

.ilg-gf-bar__form {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	padding: 12px 16px;
	background: var(--gf-bg-soft);
	border: 1px solid var(--gf-border);
	border-radius: var(--gf-radius);
}

.ilg-gf-bar__list {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
	flex: 1 1 auto;
}

.ilg-gf-bar__item { margin: 0; }

.ilg-gf-bar__actions {
	display: inline-flex;
	gap: 8px;
	flex: 0 0 auto;

	& .ilg-gf-btn--primary { flex: 0 0 auto; }
}

/* ─────────────────────────── dropdown trigger + popover panel ─────────────────────────── */
.ilg-gf-dd { position: relative; }

.ilg-gf-dd__trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: var(--gf-tap);
	padding: 8px 14px;
	background: var(--gf-bg);
	border: 1px solid var(--gf-border-strong);
	border-radius: var(--gf-radius-sm);
	color: var(--gf-fg);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	white-space: nowrap;

	&:hover {
		background: var(--gf-bg-hover);
		border-color: var(--gf-fg);
		color: var(--gf-fg);
	}

	&:focus-visible {
		outline: none;
		box-shadow: var(--gf-focus);
		border-color: var(--gf-accent);
	}

	&.is-active {
		background: var(--gf-accent-soft);
		border-color: var(--gf-accent);
		color: var(--gf-accent);

		&:hover { color: var(--gf-accent); }

		& .ilg-gf-dd__count {
			background: var(--gf-accent);
			color: var(--gf-accent-fg);
		}
	}

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

.ilg-gf-dd__caret {
	transition: transform 120ms ease;
	flex: 0 0 auto;
}

@media (prefers-reduced-motion: reduce) {
	.ilg-gf-dd__caret { transition: none; }
}

.ilg-gf-dd__count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: var(--gf-radius-pill);
	background: var(--gf-accent);
	color: var(--gf-accent-fg);
	font-size: 0.8125rem;
	font-weight: 700;
	line-height: 1;
}

.ilg-gf-dd__panel {
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	z-index: 1500;
	width: min(320px, calc(100vw - 32px));
	padding: 12px;
	background: var(--gf-bg);
	border: 1px solid var(--gf-border);
	border-radius: var(--gf-radius);
	box-shadow: var(--gf-shadow);

	&[hidden] { display: none; }

	/* Inside the popover the fieldset doesn't need its default bottom
	   margin (the footer below handles spacing) and the list gets its
	   own scroll cap so Clear/Apply stay in view. */
	& .ilg-gf-fieldset { margin: 0; }

	& .ilg-gf-fieldset__list {
		max-height: 280px;
		overflow-y: auto;
	}
}

.ilg-gf-dd__footer {
	display: flex;
	gap: 12px;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
	margin: 12px -12px -12px; /* pull to panel edges */
	padding: 12px;
	border-top: 1px solid var(--gf-border);
	background: var(--gf-bg);
	border-bottom-left-radius: var(--gf-radius);
	border-bottom-right-radius: var(--gf-radius);

	/* Apply (left): outlined pill — reference pattern. */
	& .ilg-gf-btn--primary {
		background: transparent;
		color: var(--gf-btn);
		border: 2px solid var(--gf-btn);
		border-radius: var(--gf-radius-pill);
		padding: 6px 22px;
		min-height: 36px;
		flex: 0 0 auto;
		font-weight: 600;

		&:hover {
			background: var(--gf-btn);
			color: var(--gf-btn-fg);
		}

		/* Loading-state padding scoped here so it wins over the outlined
		   pill padding above (same specificity, written later). */
		&.is-loading,
		&[aria-busy="true"],
		&:disabled { padding: 8px 28px 8px 48px; }
	}

	/* Clear (right): underlined text link, no button chrome. */
	& .ilg-gf-btn--ghost {
		background: transparent;
		color: var(--gf-fg);
		border: 0;
		text-decoration: underline;
		font-weight: 500;
		padding: 6px 4px;
		min-height: auto;
		order: 2; /* visually right side */

		&:hover {
			color: var(--gf-btn);
			background: transparent;
		}

		&.is-loading,
		&[aria-busy="true"] { padding: 6px 4px 6px 28px; }
	}
}

/* Load More button uses the theme's existing .ilg-load-more-btn styles
   (see child-theme.css). We just hook the button by id in filters.js
   for fetch+append behavior. */

/* ─────────────────────────── activate desktop at 992px ─────────────────────────── */
@media (min-width: 992px) {

	/* Mobile drawer + its toggle off. */
	.ilg-gf-toolbar__toggle { display: none; }
	.ilg-gf-drawer          { display: none !important; }

	/* Keep the toolbar visible — strip its mobile chrome so the count
	   reads as a clean line under the dropdown bar. */
	.ilg-gf-toolbar {
		background: transparent;
		border: 0;
		padding: 0;
		margin: 0 0 8px;
	}

	/* Desktop UI on. */
	.ilg-gf-bar { display: block; margin: 0 0 12px; }
}
