/**
 * WLRE Theme — Saved Searches.
 *
 * Covers:
 *   - toolbar "Save search" button (listings)
 *   - /account/saved-searches/ page (card list, dialogs, empty state)
 *   - shared .wlre-confirm-dialog (used by Batch 8 rename + delete)
 */

/* === Toolbar "Save search" button === */
.wlre-save-search-btn {
	display: inline-flex;
	align-items: center;
	gap: var(--wlre-space-8);
	padding: var(--wlre-space-8) 14px;
	background: var(--wlre-color-white);
	border: 1px solid var(--wlre-color-neutral-200);
	border-radius: 999px;
	color: var(--wlre-color-text-900);
	font-family: var(--wlre-font-body);
	font-weight: 700;
	font-size: 13px;
	line-height: 1.2;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.wlre-save-search-btn:hover {
	background: var(--wlre-color-surface-50);
	border-color: var(--wlre-color-neutral-400);
}

.wlre-save-search-btn.is-saved {
	background: var(--wlre-color-brand-900);
	border-color: var(--wlre-color-brand-900);
	color: var(--wlre-color-white);
}

.wlre-save-search-btn__icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	display: inline-block;
}

.wlre-save-search-btn__icon--on {
	display: none;
	color: var(--wlre-color-accent-500);
}

.wlre-save-search-btn.is-saved .wlre-save-search-btn__icon--off {
	display: none;
}

.wlre-save-search-btn.is-saved .wlre-save-search-btn__icon--on {
	display: inline-block;
}

.wlre-save-search-btn[disabled] {
	opacity: 0.6;
	cursor: wait;
}

/* === /account/saved-searches/ === */
.wlre-saved-searches {
	background: var(--wlre-color-white);
	min-height: calc(100vh - 80px);
	padding-block: var(--wlre-space-40) var(--wlre-space-64);
}

.wlre-saved-searches__header {
	margin-bottom: var(--wlre-space-24);
}

.wlre-saved-searches__title {
	color: var(--wlre-color-text-900);
	margin: 0 0 var(--wlre-space-8);
}

.wlre-saved-searches__count {
	color: var(--wlre-color-neutral-600);
	margin: 0;
}

/* === Chip row — above toolbar (Figma 6163-158622) === */
.wlre-saved-searches-chip-row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wlre-space-8);
	margin-bottom: var(--wlre-space-16);
}

/* === Toolbar (Figma 6081-52956) — count left / sort right, NO view toggle === */
.wlre-saved-searches-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--wlre-space-16);
	margin-bottom: var(--wlre-space-24);
	flex-wrap: wrap;
}

.wlre-saved-searches-toolbar__count {
	display: inline-flex;
	align-items: baseline;
	gap: var(--wlre-space-4);
	margin: 0;
	color: var(--wlre-color-text-900);
}

.wlre-saved-searches-toolbar__count-num {
	font-family: var(--wlre-font-heading);
	font-weight: 600;
	font-size: 28px;
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}

.wlre-saved-searches-toolbar__count-label {
	font-family: var(--wlre-font-body);
	font-size: 16px;
	line-height: 1.48;
}

.wlre-saved-searches-toolbar__sort {
	display: inline-flex;
	align-items: center;
	gap: var(--wlre-space-8);
}

.wlre-saved-searches-toolbar__sort-label {
	font-family: var(--wlre-font-body);
	font-size: 14px;
	color: var(--wlre-color-text-900);
	white-space: nowrap;
}

.wlre-saved-searches__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--wlre-space-20);
}

.wlre-saved-search {
	position: relative;
	background: var(--wlre-color-white);
	border-radius: var(--wlre-radius-lg);
	box-shadow: 0 8px 12px rgba(149, 157, 165, 0.2);
	padding: var(--wlre-space-16);
	display: flex;
	flex-direction: column;
	gap: var(--wlre-space-16);
	justify-content: space-between;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wlre-saved-search:hover {
	transform: translateY(-2px);
	box-shadow: 0 14px 34px rgba(10, 36, 56, 0.16);
}

.wlre-saved-search__link {
	position: absolute;
	inset: 0;
	z-index: 1;
	border-radius: inherit;
	text-indent: -9999px;
	overflow: hidden;
	white-space: nowrap;
}

.wlre-saved-search__link:focus { outline: none; }

.wlre-saved-search__body {
	position: relative;
	z-index: 2;
	pointer-events: none;
	display: flex;
	flex-direction: column;
	gap: var(--wlre-space-8);
	min-width: 0;
}

.wlre-saved-search__name {
	color: var(--wlre-color-text-900);
	margin: 0;
	word-break: break-word;
}

.wlre-saved-search__subtitle {
	color: var(--wlre-color-text-900);
	margin: 0;
	font-family: var(--wlre-font-body);
	font-size: 14px;
	line-height: 1.48;
}

.wlre-saved-search__criteria {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wlre-space-8);
	list-style: none;
	margin: 0;
	padding: 0;
}

.wlre-saved-search__criterion {
	display: inline-flex;
	align-items: center;
	padding: 4px var(--wlre-space-8);
	background: #f3faf4;
	color: var(--wlre-color-text-900);
	border-radius: var(--wlre-radius-sm);
	font-family: var(--wlre-font-body);
	font-size: 12px;
	line-height: 1.48;
}

.wlre-saved-search__notify {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: var(--wlre-space-4) 0 0;
	color: var(--wlre-color-brand-900);
}

.wlre-saved-search__notify-icon {
	width: 14px;
	height: 14px;
	color: var(--wlre-color-accent-500);
}

.wlre-saved-search__actions {
	position: relative;
	z-index: 2;
	display: flex;
	align-items: center;
	gap: var(--wlre-space-12);
}

.wlre-saved-search__primary {
	flex: 0 0 142px;
	height: 32px;
	padding-inline: var(--wlre-space-24);
	background: var(--wlre-color-white);
	border: 1px solid var(--wlre-color-brand-900);
	border-radius: var(--wlre-radius-sm);
	color: var(--wlre-color-text-900);
	font-family: var(--wlre-font-body);
	font-weight: 700;
	font-size: 12px;
	line-height: 1.48;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 4px;
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease;
}

.wlre-saved-search__primary:hover {
	background: var(--wlre-color-surface-50);
}

.wlre-saved-search__heart-icon {
	display: inline-flex;
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	color: #95231f;
}

.wlre-saved-search__heart-icon svg {
	width: 16px;
	height: 16px;
}

.wlre-saved-search__icon-btn {
	flex: 0 0 auto;
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--wlre-color-white);
	border: 1px solid var(--wlre-color-brand-900);
	border-radius: var(--wlre-radius-sm);
	color: var(--wlre-color-text-900);
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.wlre-saved-search__icon-btn svg {
	width: 13px;
	height: 13px;
}

.wlre-saved-search__icon-btn:hover {
	background: var(--wlre-color-surface-50);
	border-color: var(--wlre-color-neutral-400);
}

.wlre-saved-search__remove {
	color: var(--wlre-color-error);
}

.wlre-saved-search__remove:hover {
	background: rgba(229, 62, 62, 0.08);
	border-color: var(--wlre-color-error);
	color: var(--wlre-color-error);
}

.wlre-saved-search.is-removing {
	opacity: 0;
	transform: translateX(24px);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.wlre-saved-search[hidden] {
	display: none;
}

/* No-results inline when every chip filter hides all cards. */
.wlre-saved-searches__no-results {
	text-align: center;
	padding: var(--wlre-space-40) var(--wlre-space-16);
	color: var(--wlre-color-neutral-600);
	font-family: var(--wlre-font-body);
	font-size: 16px;
	margin: 0;
}

/* Empty state: see empty-state.css (.wlre-empty). */

/* === Shared confirm / rename / save dialog =========================== */
.wlre-confirm-dialog {
	border: none;
	border-radius: var(--wlre-radius-lg);
	padding: 0;
	max-width: 800px; /* Figma 6081-80554 / 6081-75326 — 800px centered modal. */
	width: calc(100% - 32px);
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.wlre-confirm-dialog--save {
	border-radius: var(--wlre-radius-20);
}

/* Figma 6081-80554: outer padding 40px, gap 32px between title / form-group / buttons. */
.wlre-confirm-dialog--save .wlre-confirm-dialog__inner {
	gap: var(--wlre-space-32);
	padding: var(--wlre-space-40) var(--wlre-space-40) 0;
}

/* Form field + toggle sub-group: 20px gap between the two. */
.wlre-confirm-dialog__form {
	display: flex;
	flex-direction: column;
	gap: var(--wlre-space-20);
	width: 100%;
}

/* Suppress the global .wlre-form__group margin-bottom so the flex gap
 * is the sole spacing source (avoids 20 + 20 = 40px double-gap). Applies
 * to the wrapped `__form` variant (save-search dialog) AND the inline
 * variant where __group is a direct child of __inner (rename dialog). */
.wlre-confirm-dialog__form .wlre-form__group,
.wlre-confirm-dialog__inner > .wlre-form__group {
	margin-bottom: 0;
}

/* Save/rename dialogs with `--save` modifier keep the 800px spec; tight
 * confirmation dialogs (delete, logout, account-deletion) use `--compact`
 * to stay at the legacy 528px width. */
.wlre-confirm-dialog--compact {
	max-width: 528px;
}

.wlre-confirm-dialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

.wlre-confirm-dialog__inner {
	padding: var(--wlre-space-40);
	display: flex;
	flex-direction: column;
	gap: var(--wlre-space-16);
	margin: 0;
}

/* === Bottom-sheet variant of confirm-dialog (mobile) =================
 * Applied automatically at ≤767px when the dialog carries the `--sheet`
 * modifier. Mirrors modals.css `.wlre-modal--sheet` spec. */
@media (max-width: 767px) {
	/* Same lesson as the service modal: layout + display must be gated on
	 * [open], otherwise the browser's native display:none for a closed
	 * <dialog> is overridden and the sheet shows on page load — overlapping
	 * the search filter bar and confusing the user. */
	.wlre-confirm-dialog--sheet:not([open]) {
		display: none;
	}

	.wlre-confirm-dialog--sheet[open] {
		max-width: 100%;
		width: 100%;
		max-height: 90vh;
		margin: 0 auto;
		position: fixed;
		inset-block-end: 0;
		inset-block-start: auto;
		border-radius: var(--wlre-radius-20) var(--wlre-radius-20) 0 0;
		box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
		display: flex;
		flex-direction: column;
		padding: 0;
		opacity: 1;
		transition: none;
		animation: none;
	}

	.wlre-confirm-dialog--sheet::backdrop {
		background: rgba(10, 36, 56, 0.96);
		transition: none;
		animation: none;
	}

	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__grabber {
		flex-shrink: 0;
		width: 60px;
		height: 6px;
		margin: var(--wlre-space-12) auto;
		background: var(--wlre-color-neutral-400);
		border-radius: 20px;
	}

	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__inner {
		padding: var(--wlre-space-16) var(--wlre-space-24);
		padding-block-end: var(--wlre-space-24);
		gap: var(--wlre-space-24);
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
	}

	.wlre-confirm-dialog--sheet.wlre-confirm-dialog--save .wlre-confirm-dialog__actions,
	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__actions {
		flex-shrink: 0;
		display: flex;
		gap: var(--wlre-space-12);
		padding: var(--wlre-space-8) var(--wlre-space-16) calc(var(--wlre-space-24) + env(safe-area-inset-bottom, 0));
		background: var(--wlre-color-white);
		box-shadow: 0 -4px 7px -1px rgba(99, 99, 99, 0.04);
		margin: 0;
		justify-content: stretch;
	}

	.wlre-confirm-dialog--sheet.wlre-confirm-dialog--save .wlre-confirm-dialog__actions > .wlre-btn,
	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__actions > .wlre-btn {
		flex: 1 1 0;
		min-width: 0;
		width: auto;
		height: 56px;
		border-radius: var(--wlre-radius-md);
	}

	.wlre-confirm-dialog--sheet.wlre-confirm-dialog--save .wlre-confirm-dialog__title {
		font-size: var(--wlre-font-size-h3);
		line-height: 1.15;
		text-align: center;
		max-width: 320px;
		margin-inline: auto;
	}

	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__title {
		font-size: var(--wlre-font-size-h4);
		text-align: start;
	}

	/* Enlarge the checkbox inside the mobile rename/save sheet to match the
	 * Figma 24×24 spec — the default 16×16 reads as too small at sheet width. */
	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__check input[type="checkbox"] {
		width: 24px;
		height: 24px;
		border-radius: 4px;
		background-size: 18px 18px;
		margin: 0;
	}

	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__check {
		align-items: center;
		gap: var(--wlre-space-12);
	}
}

@media (min-width: 768px) {
	.wlre-confirm-dialog--sheet .wlre-confirm-dialog__grabber {
		display: none;
	}
}

.wlre-confirm-dialog__title {
	color: var(--wlre-color-text-900);
	margin: 0;
}

.wlre-confirm-dialog--save .wlre-confirm-dialog__title {
	text-align: center;
}

.wlre-confirm-dialog__body {
	color: var(--wlre-color-neutral-600);
	margin: 0;
}

.wlre-confirm-dialog__check {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	color: var(--wlre-color-text-900);
}

.wlre-confirm-dialog__check input {
	margin-top: 2px;
}

.wlre-confirm-dialog--save .wlre-confirm-dialog__check {
	justify-content: flex-start;
	align-items: center;
	gap: 12px;
}

.wlre-confirm-dialog__actions {
	display: flex;
	justify-content: flex-end;
	gap: var(--wlre-space-8);
	margin-top: var(--wlre-space-4);
}

/* === Delete-style confirm dialog — shared by account-delete + document-remove === */
.wlre-confirm-dialog--delete {
	max-width: 528px;
	border-radius: var(--wlre-radius-20);
}

.wlre-confirm-dialog--delete::backdrop {
	background: rgba(10, 36, 56, 0.96);
}

.wlre-confirm-dialog--delete .wlre-confirm-dialog__inner {
	gap: var(--wlre-space-20);
	align-items: center;
	text-align: center;
}

.wlre-confirm-dialog__text {
	display: flex;
	flex-direction: column;
	gap: var(--wlre-space-12);
	width: 100%;
}

.wlre-confirm-dialog--delete .wlre-confirm-dialog__title {
	font-family: var(--wlre-font-heading);
	font-weight: 600;
	font-size: var(--wlre-font-size-h4);
	line-height: var(--wlre-line-height-heading);
	color: var(--wlre-color-text-900);
	margin: 0;
	text-align: center;
}

.wlre-confirm-dialog--delete .wlre-confirm-dialog__body {
	font-family: var(--wlre-font-body);
	font-size: var(--wlre-font-size-m);
	line-height: var(--wlre-line-height-body);
	color: var(--wlre-color-text-900);
	margin: 0;
	text-align: center;
}

.wlre-confirm-dialog--delete .wlre-confirm-dialog__actions {
	justify-content: center;
	gap: var(--wlre-space-12);
	margin-top: 0;
}

.wlre-confirm-dialog--delete .wlre-confirm-dialog__actions .wlre-btn {
	height: 56px;
	min-width: 130px;
}

/* Red destructive CTA — used by both delete-account and remove-document dialogs. */
.wlre-confirm-dialog__confirm--destructive {
	background: var(--wlre-color-error);
	border-color: var(--wlre-color-error);
	color: var(--wlre-color-white);
}

.wlre-confirm-dialog__confirm--destructive:hover {
	background: #a53131;
	border-color: #a53131;
}

.wlre-confirm-dialog--save .wlre-confirm-dialog__actions {
	justify-content: stretch;
	gap: 20px;
	padding: var(--wlre-space-32) var(--wlre-space-40) var(--wlre-space-40);
	margin-top: 0;
}

.wlre-confirm-dialog--save .wlre-confirm-dialog__actions .wlre-btn {
	flex: 1 1 0;
	min-width: 0;
	height: 56px;
}

/* Dark button variant used by the save-search confirm button. */
.wlre-btn--dark {
	background: #1a1a1a;
	color: #fff;
	border-color: #1a1a1a;
	border-radius: var(--wlre-radius-sm);
}

.wlre-btn--dark:hover,
.wlre-btn--dark:focus-visible {
	background: #333;
	border-color: #333;
}

/* Toggle switch — 42×24px — used in save-search dialog. */
.wlre-toggle {
	position: relative;
	display: inline-block;
	width: 42px;
	height: 24px;
	flex-shrink: 0;
}

.wlre-toggle__input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	margin: 0;
	cursor: pointer;
	z-index: 1;
}

.wlre-toggle__track {
	display: block;
	width: 42px;
	height: 24px;
	border-radius: 12px;
	background: var(--wlre-color-neutral-300);
	transition: background 0.2s ease;
	position: relative;
}

.wlre-toggle__track::after {
	content: '';
	position: absolute;
	top: 2px;
	inset-inline-start: 2px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
	transition: transform 0.2s ease;
}

.wlre-toggle__input:checked + .wlre-toggle__track {
	background: var(--wlre-color-brand-900);
}

.wlre-toggle__input:checked + .wlre-toggle__track::after {
	transform: translateX(18px);
}

/* Inline validation / server-error slot inside a confirm dialog. */
.wlre-confirm-dialog__error {
	color: var(--wlre-color-error-700);
	margin: var(--wlre-space-8) 0 0;
	font-family: var(--wlre-font-body);
}

/* Save-button micro-states (rename dialog) — design-system additions
 * that any .wlre-btn can reuse. Kept in saved-searches.css since the
 * rename dialog is where the canonical animation lives; promote to
 * global.css in a later phase if other dialogs adopt the pattern. */
.wlre-btn--loading {
	position: relative;
	opacity: 0.85;
	cursor: wait;
}

.wlre-btn--loading::before {
	content: "";
	position: absolute;
	left: var(--wlre-space-12);
	top: 50%;
	width: 14px;
	height: 14px;
	margin-top: -7px;
	border-radius: 50%;
	border: 2px solid currentColor;
	/* Purely-visual spinner: one edge transparent creates the arc.
	 * The 360° rotation is direction-agnostic, so using the logical
	 * edge keeps the rule RTL-safe. */
	border-inline-end-color: transparent;
	animation: wlre-btn-spin 0.7s linear infinite;
	opacity: 0.7;
}

.wlre-btn--success {
	background: var(--wlre-color-success-700);
	border-color: var(--wlre-color-success-700);
	color: var(--wlre-color-white);
}

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

/* === Tablet (2-col) === */
@media (max-width: 1023px) {
	.wlre-saved-searches__list {
		grid-template-columns: repeat(2, 1fr);
	}
}

/* === Mobile === */
@media (max-width: 767px) {
	.wlre-saved-searches {
		padding-block: var(--wlre-space-32) var(--wlre-space-40);
	}
	.wlre-saved-searches .wlre-container {
		padding-inline: var(--wlre-space-16);
	}
	.wlre-saved-searches__header {
		display: none;
	}
	.wlre-saved-searches-chip-row {
		display: none;
	}
	.wlre-saved-searches__title {
		font-size: var(--wlre-font-size-h3);
	}
	.wlre-saved-searches-toolbar {
		flex-direction: column;
		align-items: flex-start;
		gap: var(--wlre-space-16);
		margin-bottom: var(--wlre-space-12);
	}
	.wlre-saved-searches-toolbar__count-num {
		font-size: 22px;
	}
	.wlre-saved-searches-toolbar__sort {
		margin-inline-start: 0;
	}
	.wlre-saved-searches .wlre-saved-sort__trigger {
		height: 32px;
		padding-inline: var(--wlre-space-12);
		font-size: 12px;
	}
	.wlre-saved-searches__list {
		grid-template-columns: 1fr;
		gap: var(--wlre-space-16);
	}
	.wlre-save-search-btn {
		min-height: var(--wlre-tap-target);
		padding: 10px 16px;
	}

	.wlre-saved-search__icon-btn {
		width: 32px;
		height: 32px;
	}
}
