/**
 * BG Logistics location picker.
 *
 * Themes can restyle the picker through the custom properties below.
 */

.bgl-picker,
.bgl-dialog {
	--bgl-accent: var(--wp--preset--color--contrast, #1e1e1e);
	--bgl-accent-contrast: var(--wp--preset--color--base, #fff);
	--bgl-surface: #fff;
	--bgl-text: #1e1e1e;
	--bgl-muted: #5f6368;
	--bgl-border: #dcdcde;
	--bgl-hover: #f3f4f6;
	--bgl-selected: #eef4ff;
	--bgl-office: #0b57d0;
	--bgl-locker: #b06000;
	--bgl-error: #cc1818;
	--bgl-radius: 8px;
}

/*
 * Theme resistance. Themes often style every button and text input (dark backgrounds,
 * uppercase, letter-spacing, padding, shadows), and rules such as `body.some-class button`
 * outrank a single class. So every control rule in this file is scoped to .bgl-picker or
 * .bgl-dialog (two classes), and this block, which comes first, resets what such theme
 * rules typically set. Each control's base rule also applies on :focus, because themes
 * restyle `button:focus` too and a clicked button keeps focus; :hover and pressed rules
 * come later and still win. The picker also sits in table cells that themes right-align.
 */
:is(.bgl-picker, .bgl-dialog) :is(.bgl-choose, .bgl-summary__change, .bgl-dialog__close, .bgl-chip, .bgl-near-me, .bgl-retry, .bgl-more, .bgl-search__input) {
	box-sizing: border-box;
	width: auto;
	max-width: none;
	height: auto;
	min-height: 0;
	margin: 0;
	font: inherit;
	line-height: 1.3;
	text-transform: none;
	letter-spacing: normal;
	text-decoration: none;
	text-shadow: none;
	box-shadow: none;
}

/* ---- Inline summary ---------------------------------------------- */

.bgl-picker {
	margin: 0.25em 0 0.75em;
	text-align: start;
}

.bgl-summary {
	display: flex;
	align-items: center;
	gap: 0.75em;
}

.bgl-summary--selected {
	padding: 0.75em 0.9em;
	border: 1px solid var(--bgl-border);
	border-radius: var(--bgl-radius);
	background: var(--bgl-surface);
	color: var(--bgl-text);
}

.bgl-summary__point {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 0.15em;
	min-width: 0;
	line-height: 1.35;
}

.bgl-summary__eyebrow {
	display: flex;
	align-items: center;
	gap: 0.35em;
	font-size: 0.8em;
	color: var(--bgl-muted);
}

.bgl-summary__name {
	font-weight: 600;
}

.bgl-summary__address {
	font-size: 0.9em;
	color: var(--bgl-muted);
}

.bgl-picker .bgl-summary__change,
.bgl-picker .bgl-summary__change:focus {
	flex: none;
	padding: 0.4em 0.8em;
	border: 1px solid var(--bgl-border);
	border-radius: var(--bgl-radius);
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 0.9em;
	cursor: pointer;
}

.bgl-picker .bgl-summary__change:hover {
	background: var(--bgl-hover);
	color: inherit;
}

.bgl-picker .bgl-choose,
.bgl-picker .bgl-choose:focus {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5em;
	box-sizing: border-box;
	width: 100%;
	min-height: 3em;
	padding: 0.75em 1em;
	border: 1px dashed var(--bgl-accent);
	border-radius: var(--bgl-radius);
	background: var(--bgl-surface);
	color: var(--bgl-text);
	font: inherit;
	font-weight: 600;
	line-height: 1.3;
	text-align: center;
	cursor: pointer;
}

.bgl-choose::before {
	content: "";
	flex: none;
	width: 1.1em;
	height: 1.1em;
	background: currentColor;
	/* Map pin */
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.bgl-picker .bgl-choose:hover {
	border-style: solid;
	background: var(--bgl-hover);
	color: var(--bgl-text);
}

.bgl-picker .bgl-choose:focus-visible,
.bgl-picker .bgl-summary__change:focus-visible {
	outline: 2px solid var(--bgl-accent);
	outline-offset: 2px;
}

/* Classic checkout: address fields an office/locker order does not need (classic-checkout.js). */
.bgl-field-hidden {
	display: none !important;
}

.bgl-note {
	margin: 0.5em 0 0;
	font-size: 0.875em;
	color: var(--bgl-muted);
}

.bgl-blocks-picker {
	margin-top: 1em;
}

.bgl-blocks-picker.has-error .bgl-choose {
	outline: 2px solid var(--bgl-error);
	outline-offset: 2px;
}

.bgl-error {
	margin: 0.5em 0 0;
	color: var(--bgl-error);
	font-size: 0.875em;
}

.bgl-badge {
	display: inline-block;
	padding: 0.1em 0.5em;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.5;
	white-space: nowrap;
	color: var(--bgl-office);
	background: color-mix(in srgb, var(--bgl-office) 12%, transparent);
}

.bgl-badge--locker {
	color: var(--bgl-locker);
	background: color-mix(in srgb, var(--bgl-locker) 14%, transparent);
}

/* ---- Dialog ------------------------------------------------------ */

html.bgl-scroll-lock {
	overflow: hidden;
}

.bgl-dialog {
	width: min(640px, calc(100vw - 2rem));
	max-width: none;
	height: min(720px, calc(100vh - 4rem));
	max-height: none;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: var(--bgl-surface);
	color: var(--bgl-text);
	box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
	font-size: 16px;
	line-height: 1.4;
	text-align: start;
}

.bgl-dialog::backdrop {
	background: rgba(0, 0, 0, 0.5);
}

.bgl-dialog__inner {
	display: flex;
	flex-direction: column;
	height: 100%;
}

.bgl-dialog__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1em;
	padding: 1rem 1.25rem 0.5rem;
}

.bgl-dialog__title {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 600;
	line-height: 1.3;
	text-transform: none;
	letter-spacing: normal;
}

.bgl-dialog .bgl-dialog__close,
.bgl-dialog .bgl-dialog__close:focus {
	display: grid;
	place-items: center;
	flex: none;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font-size: 1.6rem;
	line-height: 1;
	cursor: pointer;
}

.bgl-dialog .bgl-dialog__close:hover {
	background: var(--bgl-hover);
	color: inherit;
}

.bgl-dialog__controls {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	padding: 0.5rem 1.25rem 0.75rem;
	border-bottom: 1px solid var(--bgl-border);
}

.bgl-dialog .bgl-search__input {
	box-sizing: border-box;
	width: 100%;
	padding: 0.7rem 0.9rem;
	border: 1px solid var(--bgl-border);
	border-radius: var(--bgl-radius);
	background: var(--bgl-surface);
	color: inherit;
	/* 16px stops iOS from zooming into the field. */
	font: inherit;
	font-size: 16px;
}

.bgl-dialog .bgl-search__input:focus {
	outline: 2px solid var(--bgl-accent);
	outline-offset: -1px;
	box-shadow: none;
}

.bgl-filters {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
}

.bgl-chips {
	display: flex;
	gap: 0.4rem;
}

.bgl-dialog .bgl-chip,
.bgl-dialog .bgl-chip:focus,
.bgl-dialog .bgl-near-me,
.bgl-dialog .bgl-near-me:focus,
.bgl-dialog .bgl-retry,
.bgl-dialog .bgl-retry:focus,
.bgl-dialog .bgl-more,
.bgl-dialog .bgl-more:focus {
	padding: 0.35rem 0.85rem;
	border: 1px solid var(--bgl-border);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 0.875rem;
	cursor: pointer;
}

.bgl-dialog .bgl-chip:hover,
.bgl-dialog .bgl-near-me:hover,
.bgl-dialog .bgl-retry:hover,
.bgl-dialog .bgl-more:hover {
	background: var(--bgl-hover);
	color: inherit;
}

.bgl-dialog .bgl-chip[aria-pressed="true"],
.bgl-dialog .bgl-near-me[aria-pressed="true"] {
	border-color: var(--bgl-accent);
	background: var(--bgl-accent);
	color: var(--bgl-accent-contrast);
}

.bgl-dialog .bgl-near-me {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
}

.bgl-near-me::before {
	content: "";
	width: 1em;
	height: 1em;
	background: currentColor;
	/* Location arrow */
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 3 3 10.53v.98l6.84 2.65L12.48 21h.98L21 3z'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 3 3 10.53v.98l6.84 2.65L12.48 21h.98L21 3z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.bgl-status {
	padding: 0.5rem 1.25rem;
	font-size: 0.875rem;
	color: var(--bgl-muted);
}

.bgl-dialog__body {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 0 0.5rem 1rem;
}

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

.bgl-result {
	display: flex;
	gap: 0.75rem;
	margin: 0;
	padding: 0.7rem 0.75rem;
	border-radius: var(--bgl-radius);
	cursor: pointer;
}

.bgl-result.is-active {
	background: var(--bgl-hover);
}

.bgl-result.is-selected {
	background: var(--bgl-selected);
	box-shadow: inset 3px 0 0 var(--bgl-accent);
}

.bgl-result__main {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 0.15rem;
	min-width: 0;
}

.bgl-result__name {
	font-weight: 600;
}

.bgl-result__address,
.bgl-result__hours,
.bgl-result__note {
	font-size: 0.875rem;
	color: var(--bgl-muted);
}

.bgl-result__note {
	font-style: italic;
}

.bgl-result__side {
	display: flex;
	flex: none;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.3rem;
}

.bgl-result__distance {
	font-size: 0.8rem;
	color: var(--bgl-muted);
	white-space: nowrap;
}

.bgl-dialog .bgl-more {
	display: block;
	margin: 0.75rem auto 0;
}

.bgl-dialog .bgl-more[hidden] {
	display: none;
}

/* Phones: the dialog takes over the screen. */
@media (max-width: 600px) {
	.bgl-dialog {
		width: 100vw;
		height: 100dvh;
		max-height: 100dvh;
		margin: 0;
		border-radius: 0;
	}

	.bgl-dialog__header,
	.bgl-dialog__controls {
		padding-left: 1rem;
		padding-right: 1rem;
	}

	.bgl-status {
		padding-left: 1rem;
		padding-right: 1rem;
	}
}

@media (prefers-reduced-motion: no-preference) {
	.bgl-dialog[open] {
		animation: bgl-dialog-in 0.15s ease-out;
	}
}

@keyframes bgl-dialog-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
}
