/*
 * Lista dystrybutorów – kolory i zaokrąglenia z palety Blocksy (Customizer → Colors), z fallbackiem.
 * --theme-palette-color-1 = akcent, -2 = hover, -3 = tekst, -4 = nagłówki, -5 = linie, -6 = jasne tło, -8 = biel.
 */
.atd {
	--atd-accent: var(--theme-palette-color-1, #a01518);
	--atd-accent-hover: var(--theme-palette-color-2, #7d1013);
	--atd-text: var(--theme-palette-color-3, #3a4f66);
	--atd-heading: var(--theme-palette-color-4, #192a3d);
	--atd-line: var(--theme-palette-color-5, #e1e8ed);
	--atd-soft: var(--theme-palette-color-6, #f2f5f7);
	--atd-card-bg: #f7f9fa; /* karty dystrybutorów – jaśniejsze niż --atd-soft */
	--atd-white: var(--theme-palette-color-8, #ffffff);
	--atd-radius: var(--theme-button-border-radius, 6px);
	--atd-land: #dbe1e6;
	--atd-green: #ccd40f; /* jasna zieleń Agro-Tom – regiony z dystrybutorami */
	--atd-gap: clamp(14px, 2vw, 24px);
	color: var(--atd-text);
	container-type: inline-size;
	container-name: atd;
}

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

.atd [hidden] {
	display: none !important;
}

.atd button {
	min-height: 0;
	margin: 0;
	font: inherit;
	letter-spacing: 0;
	text-transform: none;
	box-shadow: none;
}

.atd :focus-visible {
	outline: 2px solid var(--atd-accent);
	outline-offset: 2px;
}

/* ============ Pole górne: wyszukiwarka + mapa + lista ============ */

.atd__explorer {
	margin-bottom: calc(var(--atd-gap) * 3);
	background: transparent;
}

.atd__search {
	margin-bottom: 40px;
}

.atd .atd__search-input {
	display: block;
	width: 100%;
	height: auto;
	min-height: 0;
	margin: 0;
	padding: 12px 20px 12px 46px;
	border: 1px solid #edf0f3;
	border-radius: 999px !important;
	background: var(--atd-white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a96a3' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 18px center / 18px;
	color: var(--atd-heading);
	font: inherit;
	font-size: .875rem;
	line-height: 1.4;
	box-shadow: none;
	transition: border-color .15s;
}

.atd .atd__search-input:focus {
	border-color: #c9d1d9;
	outline: none;
}

.atd__explorer-body {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: clamp(24px, 5cqi, 72px);
	align-items: start;
}

.atd__explorer.has-map .atd__explorer-body {
	grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
}

.atd__explorer:not(.has-map) .atd__maps {
	display: none;
}

/* --- Najbliższy dystrybutor: lokalizacja w polu wyszukiwania --- */

.atd__search-hint {
	margin: 0 0 16px;
	color: var(--atd-text);
	font-size: .875rem;
	line-height: 1.45;
}

.atd__search-hint strong {
	color: var(--atd-heading);
	font-weight: 600;
}

.atd__search-field {
	position: relative;
}

.atd__search-field .atd__search-input {
	padding-right: 54px;
}

.atd .atd__locate {
	position: absolute;
	top: 50%;
	right: 6px;
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--atd-heading);
	cursor: pointer;
	transform: translateY(-50%);
	transition: background-color .15s, color .15s;
}

.atd .atd__locate:hover {
	background: var(--atd-soft);
	color: var(--atd-accent);
}

.atd__locate svg {
	width: 19px;
	height: 19px;
	fill: currentColor;
}

.atd__locate.is-busy svg {
	animation: atd-pulse 1s ease-in-out infinite;
}

@keyframes atd-pulse {
	50% { opacity: .3; }
}

.atd .atd__suggest {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-top: 14px;
	padding: 7px 14px;
	border: 0;
	border-radius: 999px;
	background: var(--atd-soft);
	color: var(--atd-heading);
	font-size: .875rem;
	text-align: left;
	cursor: pointer;
	transition: background-color .15s;
}

.atd .atd__suggest::before {
	content: "";
	flex: 0 0 auto;
	width: 8px;
	height: 8px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: var(--atd-accent);
	box-shadow: 0 0 0 1px var(--atd-accent);
}

.atd__suggest strong {
	font-weight: 600;
}

.atd .atd__suggest:hover {
	background: var(--atd-green);
}

.atd__near-msg {
	margin: 14px 0 0;
	font-size: .85rem;
}

/* --- Wyniki „najbliżsi” --- */

.atd.is-near .atd__panel,
.atd.is-near .atd__empty {
	display: none !important;
}

.atd__near {
	margin-bottom: calc(var(--atd-gap) * 3);
}

.atd__near-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 8px 16px;
}

.atd__near-title {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin: 0;
	color: var(--atd-heading);
	font-size: 1.15rem;
	font-weight: 600;
}

.atd__near-note {
	margin: 4px 0 var(--atd-gap);
	font-size: .85rem;
}

.atd__near .atd__card {
	position: relative;
}

.atd__near .atd__name {
	padding-right: 78px; /* miejsce na odległość w rogu */
}

.atd__dist {
	position: absolute;
	top: 14px;
	right: 14px;
	padding: 3px 10px;
	border-radius: 999px;
	background: var(--atd-green);
	color: var(--atd-heading);
	font-size: .75rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.atd__me {
	pointer-events: none;
}

.atd__me-halo {
	fill: rgba(25, 42, 61, .14);
	animation: atd-halo 2.4s ease-out infinite;
	transform-box: fill-box;
	transform-origin: center;
}

.atd__me-dot {
	fill: var(--atd-heading);
	stroke: #fff;
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
}

@keyframes atd-halo {
	0% { transform: scale(.4); opacity: 1; }
	100% { transform: scale(1.2); opacity: 0; }
}

/* --- Mapa --- */

.atd__maps {
	position: relative;
}

.atd__mapsvg {
	display: block;
	width: 100%;
	height: auto;
	max-height: 572px;
	overflow: hidden;
}

.atd__shape {
	fill: var(--atd-land);
	stroke: var(--atd-white);
	stroke-width: 1;
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
	transition: fill .15s;
}

.atd__shape.is-on {
	cursor: pointer;
	outline: none;
}

/* Mapy neutralne – zieleń marki tylko po najechaniu i dla wybranego regionu. */
.atd__shape.is-on:hover,
.atd__shape.is-on.is-hover,
.atd__shape.is-on:focus-visible,
.atd__shape.is-on.is-selected {
	fill: var(--atd-green);
}

/* --- Pinezki dystrybutorów --- */

.atd__pin {
	fill: var(--atd-accent);
	stroke: var(--atd-white);
	stroke-width: 1.5;
	vector-effect: non-scaling-stroke;
	cursor: pointer;
	outline: none;
	transform-box: fill-box;
	transform-origin: center;
	transition: transform .15s, opacity .2s;
}

.atd__pin:hover,
.atd__pin:focus-visible {
	transform: scale(1.6);
}

.atd__pin:focus-visible {
	stroke: var(--atd-heading);
}

.atd__pin.is-dim {
	opacity: .18;
	pointer-events: none;
}

.atd__shape:focus-visible {
	stroke: var(--atd-heading);
	stroke-width: 2;
}

/* Podgląd pod mapą (zamiast dymka nad punktem) */
.atd__peek {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: fit-content;
	max-width: 100%;
	min-height: 40px;
	margin: 14px auto 0;
	padding: 8px 18px;
	border-radius: 999px;
	background: var(--atd-card-bg);
	color: var(--atd-text);
	font-size: .875rem;
	line-height: 1.35;
	text-align: center;
	transition: background-color .15s;
}

.atd__peek-dot {
	flex: 0 0 auto;
	width: 10px;
	height: 10px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: var(--atd-land);
	box-shadow: 0 0 0 1px var(--atd-line);
	transition: background-color .15s, box-shadow .15s;
}

.atd__peek.is-on .atd__peek-dot {
	background: var(--atd-green);
	box-shadow: 0 0 0 1px var(--atd-green);
}

.atd__peek.is-pin .atd__peek-dot {
	background: var(--atd-accent);
	box-shadow: 0 0 0 1px var(--atd-accent);
}

.atd__peek strong {
	color: var(--atd-heading);
	font-weight: 600;
}

.atd__peek-place {
	margin-left: 8px;
	padding-left: 8px;
	border-left: 1px solid var(--atd-line);
}

/* Bez myszki (telefony) podgląd jest zbędny – wybór i tak przewija do karty. */
@media (hover: none) {
	.atd__peek {
		display: none;
	}
}

/* --- Zakładki (Polska / Europa / …) --- */

.atd__tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 32px;
	padding-bottom: 24px;
	border-bottom: 1px solid var(--atd-line);
}

.atd .atd__tab {
	padding: 6px 12px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--atd-heading);
	font-size: .875rem;
	font-weight: 500;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color .15s, color .15s;
}

.atd .atd__tab:hover {
	background: var(--atd-soft);
}

.atd .atd__tab[aria-selected="true"] {
	background: var(--atd-accent);
	color: #fff;
}

.atd .atd__tab.is-empty {
	opacity: .4;
}

/* --- Lista regionów --- */

.atd__regions-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 20px;
}

.atd__regions-title {
	margin: 0;
	color: var(--atd-heading);
	font-size: 1.1rem;
	font-weight: 600;
	line-height: 1.3;
}

.atd .atd__reset {
	padding: 0;
	border: 0;
	background: none;
	color: var(--atd-accent);
	font-size: .85rem;
	font-weight: 500;
	cursor: pointer;
}

.atd .atd__reset::after {
	content: " ×";
}

.atd .atd__reset:hover {
	color: var(--atd-accent-hover);
}

.atd__regions-list {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 2px 12px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.atd__regions-list li {
	margin: 0;
}

.atd .atd__region {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	width: 100%;
	padding: 6px 10px;
	border: 0;
	border-radius: var(--atd-radius);
	background: transparent;
	color: var(--atd-heading);
	font-size: .875rem;
	line-height: 1.3;
	text-align: left;
	cursor: pointer;
	transition: background-color .15s, color .15s;
}

.atd .atd__region:hover,
.atd .atd__region.is-hover {
	background: var(--atd-soft);
}

.atd .atd__region.is-selected {
	background: var(--atd-accent);
	color: #fff;
}

.atd .atd__region:disabled {
	background: transparent;
	color: var(--atd-text);
	opacity: .4;
	cursor: default;
}

.atd__region-count {
	color: var(--atd-text);
	font-size: .8rem;
	font-variant-numeric: tabular-nums;
}

.atd__region.is-selected .atd__region-count {
	color: rgba(255, 255, 255, .8);
}

/* ============ Lista dystrybutorów ============ */

.atd__panel-title {
	margin: 0 0 var(--atd-gap);
}

/* Z JS nazwa regionu jest na zakładce – nagłówek zostaje dla czytników ekranu. */
.atd--js .atd__panel-title {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.atd__panel + .atd__panel {
	margin-top: calc(var(--atd-gap) * 2);
}

.atd--js .atd__panel + .atd__panel {
	margin-top: 0;
}

.atd__group + .atd__group {
	margin-top: calc(var(--atd-gap) * 2.5);
}

.atd__group-title {
	display: flex;
	align-items: center;
	gap: 14px;
	margin: 0 0 var(--atd-gap);
	color: var(--atd-heading);
	font-size: .95rem;
	font-weight: 600;
	letter-spacing: .06em;
	text-transform: uppercase;
}

.atd__group-title::after {
	content: "";
	flex: 1;
	height: 1px;
	background: var(--atd-line);
}

.atd__grid {
	display: grid;
	grid-template-columns: repeat(var(--atd-cols, 4), minmax(0, 1fr));
	gap: var(--atd-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

@keyframes atd-flash {
	0%, 60% { box-shadow: 0 0 0 2px var(--atd-accent); }
	100% { box-shadow: 0 0 0 2px transparent; }
}

.atd__card.is-flash {
	animation: atd-flash 2.2s ease-out;
}

.atd__card {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin: 0;
	padding: clamp(16px, 1.6vw, 20px);
	border: 0;
	border-radius: var(--atd-radius);
	background: var(--atd-card-bg);
}

.atd__name {
	margin: 0;
	color: var(--atd-heading);
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.35;
}

.atd__details {
	display: grid;
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: .9rem;
	line-height: 1.45;
}

.atd__row {
	display: grid;
	grid-template-columns: 16px 1fr;
	gap: 10px;
	align-items: start;
	margin: 0;
	overflow-wrap: anywhere;
}

.atd__row svg {
	width: 14px;
	height: 14px;
	margin-top: .25em;
	fill: var(--atd-accent);
}

.atd__label {
	color: var(--atd-heading);
	font-weight: 600;
}

.atd__card a:not(.atd__button) {
	color: inherit;
	text-decoration: none;
	transition: color .15s;
}

.atd__card a:not(.atd__button):hover {
	color: var(--atd-accent);
}

.atd__button {
	align-self: flex-start;
	margin-top: auto;
	padding: 8px 14px;
	border-radius: var(--atd-radius);
	background: var(--atd-accent);
	color: #fff !important;
	font-size: .85rem;
	font-weight: 600;
	text-decoration: none;
}

.atd__button:hover {
	background: var(--atd-accent-hover);
}

.atd__empty {
	padding: 24px;
	border-radius: var(--atd-radius);
	background: var(--atd-soft);
	text-align: center;
}

/* ============ Układ zależny od szerokości bloku ============ */

@container atd (max-width: 1100px) {
	.atd__grid {
		grid-template-columns: repeat(min(var(--atd-cols, 4), 3), minmax(0, 1fr));
	}
}

@container atd (max-width: 860px) {
	.atd__explorer.has-map .atd__explorer-body {
		grid-template-columns: minmax(0, 1fr);
	}

	/* Jedna kolumna: zakładki → mapa → lista regionów. */
	.atd__explorer-body {
		gap: 16px;
	}

	.atd__side {
		display: contents;
	}

	.atd__search {
		order: -2;
		margin-bottom: 0;
	}

	.atd__tabs {
		order: -1;
		margin-bottom: 0;
	}

	.atd__mapsvg {
		max-height: 420px;
	}

	.atd__regions-list {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.atd__grid {
		grid-template-columns: repeat(min(var(--atd-cols, 4), 2), minmax(0, 1fr));
	}
}

@container atd (max-width: 560px) {
	.atd__grid {
		grid-template-columns: minmax(0, 1fr);
	}

	/* Zakładki i regiony jako przewijane rzędy – mniej miejsca w pionie. */
	.atd__tabs,
	.atd__regions-list {
		display: flex;
		flex-wrap: nowrap;
		gap: 6px;
		margin-right: -16px;
		padding-right: 16px;
		overflow-x: auto;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
	}

	.atd__tabs::-webkit-scrollbar,
	.atd__regions-list::-webkit-scrollbar {
		display: none;
	}

	.atd .atd__tab,
	.atd__regions-list li {
		flex: 0 0 auto;
	}

	.atd .atd__region {
		width: auto;
		background: var(--atd-soft);
		border-radius: 999px;
		white-space: nowrap;
	}

	.atd .atd__region:disabled {
		display: none;
	}

	/* Większe pinezki pod palec. */
	.atd__pin {
		transform: scale(1.5);
	}

	.atd__pin:hover,
	.atd__pin:focus-visible {
		transform: scale(2);
	}

	/* Telefon: wybór tylko na mapie – lista regionów ukryta (gdy mapa jest dostępna). */
	.atd__explorer.has-map .atd__regions-list {
		display: none;
	}

	.atd__explorer.has-map .atd__regions-head {
		margin-bottom: 0;
	}
}

/* Podgląd w edytorze bloków – bez skryptu frontowego pokazujemy pierwszą mapę i listę. */
.editor-styles-wrapper .atd__panel + .atd__panel {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.atd * {
		transition: none !important;
	}
}
