/*
 * Advico Map front-end. Buttons reuse the theme's .graybtn / .backbtn styles;
 * this file adds layout, the farm card and states.
 */

.advmap {
	--advmap-green: #3a6531;
	--advmap-green-light: #eef3ec;
	--advmap-text: #333;
	--advmap-muted: #666;
	--advmap-map-height: 445px;
	margin: 0 0 40px;
	/* Room for the sticky site header when a farm link scrolls the map into view. */
	scroll-margin-top: 110px;
}

.advmap-page .advmap-intro {
	margin-bottom: 24px;
}

.advmap-page .advmap-heading {
	font-size: 24px;
	margin: 5px 0 0;
}

.advmap-page .advmap-lead {
	margin-bottom: 20px;
	text-align: justify;
}

.advmap-page .demoheader {
	font-size: 24px;
}

.advmap-page .mobiledemodescription {
	text-align: justify;
}

/* Layout: map 2/3, list 1/3; stacked on phones. */
.advmap__layout {
	display: grid;
	gap: 24px;
	grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

.advmap__map-wrap {
	position: relative;
}

.advmap__map {
	background: #dfe6dc;
	border-radius: 4px;
	height: var(--advmap-map-height);
	width: 100%;
}

.advmap__map-failed {
	background: #fff8e5;
	border-left: 4px solid #dba617;
	margin: 0;
	padding: 12px 16px;
}

.advmap--no-map .advmap__map {
	display: none;
}

.advmap__panel {
	display: flex;
	flex-direction: column;
	max-height: var(--advmap-map-height);
}

.advmap__panel-title {
	font-size: 18px;
	margin: 5px 0 0 10px;
	padding: 0;
}

.advmap__panel-body {
	flex: 1;
	overflow-y: auto;
	padding: 0 4px 8px 0;
}

.advmap__level-title {
	font-size: 15px;
	font-weight: 600;
	margin: 12px 0 8px 10px;
	padding: 0;
}

/* Headings only receive focus from the script (to move screen readers along), never from Tab. */
.advmap__level-title:focus,
.advmap__card-title:focus,
.advmap__details-title:focus {
	outline: none;
}

.advmap__list,
.advmap__reports,
.advmap__plain-list,
.advmap__list li,
.advmap__reports li {
	list-style: none !important;
	margin: 0;
	padding: 0 !important;
}

.advmap .advmap__item {
	align-items: center;
	display: flex;
	gap: 8px;
	justify-content: space-between;
	text-align: left;
}

.advmap .advmap__item::after {
	flex: none;
}

.advmap__count {
	font-size: 13px;
	margin-left: auto;
	opacity: 0.85;
	white-space: nowrap;
}

.advmap .advmap__back {
	text-align: left;
}

/* Farm card */
.advmap__card {
	background: #fff;
	border: 1px solid var(--advmap-green);
	border-radius: 5px;
	margin: 0 0 0 10px;
	padding: 14px 16px;
	width: 90%;
}

.advmap__card-title {
	color: var(--advmap-green);
	font-size: 20px;
	font-weight: 700;
	margin: 0;
	padding: 0;
}

.advmap__card-meta {
	color: var(--advmap-muted);
	margin: 2px 0 10px;
	padding: 0;
}

.advmap__card-subtitle {
	font-size: 14px;
	font-weight: 600;
	margin: 10px 0 6px;
	padding: 0;
	text-transform: uppercase;
}

.advmap__reports li {
	border-top: 1px solid #e5e5e5;
}

.advmap__reports li:first-child {
	border-top: 0;
}

.advmap__report {
	color: var(--advmap-green);
	display: block;
	font-weight: 500;
	padding: 8px 0;
	text-decoration: underline;
}

.advmap__report:hover,
.advmap__report:focus {
	color: #23401e;
}

.advmap__muted {
	color: var(--advmap-muted);
	font-style: italic;
}

.advmap__copy {
	align-items: center;
	border-top: 1px solid #e5e5e5;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 12px;
	padding-top: 12px;
}

.advmap .advmap__copy-button {
	background: var(--advmap-green-light);
	border: 1px solid var(--advmap-green);
	border-radius: 5px;
	color: var(--advmap-green);
	cursor: pointer;
	font-size: 14px;
	padding: 6px 12px;
}

.advmap .advmap__copy-button:hover,
.advmap .advmap__copy-button:focus {
	background: var(--advmap-green);
	color: #fff;
}

.advmap__copy-status {
	color: var(--advmap-green);
	font-size: 14px;
	font-weight: 600;
}

.advmap__copy-input {
	font-size: 13px;
	padding: 6px;
	width: 100%;
}

/* Notice (missing / unknown demo) */
.advmap__notice {
	align-items: flex-start;
	background: #fff8e5;
	border-left: 4px solid #dba617;
	display: flex;
	gap: 12px;
	justify-content: space-between;
	margin: 0 0 16px;
	padding: 12px 16px;
}

.advmap__notice[hidden] {
	display: none;
}

.advmap__notice-close {
	background: none;
	border: 0;
	cursor: pointer;
	font-size: 20px;
	line-height: 1;
	margin-left: 8px; /* Spacing where flex gap isn't supported (iOS < 14.5). */
	min-height: 32px;
	min-width: 32px;
	padding: 0 4px;
}

.advmap__retry {
	background: #fff;
	border: 1px solid currentColor;
	border-radius: 4px;
	cursor: pointer;
	font: inherit;
	margin-top: 6px;
	min-height: 32px;
	padding: 4px 12px;
}

.advmap__charts-failed {
	margin: 16px 0;
}

/* Map label (hover / selected) */
.advmap__label {
	color: var(--advmap-text);
	font-weight: 600;
	padding: 2px 4px;
}

/* Hover preview with the farm photo (same size as the old map's). The photo has a fixed size,
   so the card has its final size before the photo loads. */
.advmap__photo-card {
	position: absolute;
	z-index: 1;
	padding: 8px;
	background: #fff;
	border-radius: 8px;
	box-shadow: 0 2px 7px 1px rgba(0, 0, 0, 0.3);
	pointer-events: none;
}

.advmap__photo-card[hidden] {
	display: none;
}

.advmap__photo-card img {
	display: block;
	width: 200px;
	max-width: none;
	height: 150px;
	margin-bottom: 4px;
	object-fit: cover;
}

.advmap .screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	height: 1px;
	overflow: hidden;
	position: absolute !important;
	width: 1px;
}

/* Keyboard focus ring. :focus first, for Safari < 15.4 (no :focus-visible); the second rule,
   which such browsers ignore, takes it away again for mouse and touch in newer ones. */
.advmap button:focus,
.advmap a:focus,
.advmap button:focus-visible,
.advmap a:focus-visible {
	outline: 2px solid #1d4ed8;
	outline-offset: 2px;
}

.advmap button:focus:not(:focus-visible),
.advmap a:focus:not(:focus-visible) {
	outline: none;
}

@media (max-width: 767px) {
	.advmap {
		--advmap-map-height: 340px;
		scroll-margin-top: 0;
	}

	.advmap__layout {
		grid-template-columns: 1fr;
	}

	.advmap__panel {
		max-height: none;
	}

	.advmap__panel-body {
		overflow: visible;
	}

	.advmap .graybtn,
	.advmap .backbtn,
	.advmap__card {
		margin-left: 0;
		width: 100%;
	}
}

/* List breadcrumb (e.g. "White › Roussanne") */
.advmap__crumbs {
	color: var(--advmap-muted);
	font-size: 13px;
	margin: 4px 0 0 10px;
	padding: 0;
}

/* Farm demos: photo + "View demo details" in the card */
.advmap__card-photo {
	border-radius: 4px;
	display: block;
	margin: 8px 0;
	max-height: 140px;
	object-fit: cover;
	width: 100%;
}

.advmap .advmap__view-details {
	margin: 6px 0 0;
	text-align: center;
	width: 100%;
}

/* Farm details below the map */
.advmap__details {
	background: #fff;
	border-radius: 6px;
	margin-top: 32px;
	padding: 24px;
	scroll-margin-top: 110px;
}

.advmap__details[hidden] {
	display: none;
}

.advmap__details-title {
	color: var(--advmap-text);
	font-size: 25px;
	font-weight: 700;
	margin: 0 0 16px;
	padding: 0;
}

.advmap__details h3 {
	color: var(--advmap-green);
	font-size: 17px;
	font-weight: 700;
	margin: 16px 0 6px;
	padding: 0;
	text-transform: uppercase;
}

.advmap__details-grid {
	display: grid;
	gap: 24px;
	grid-template-columns: repeat(3, minmax(0, 1fr));
}

.advmap__details-grid > div > h3:first-child {
	margin-top: 0;
}

.advmap__facts {
	display: grid;
	gap: 2px 12px;
	/* Labels take what they need, up to half the width (then they wrap), so values always keep room. */
	grid-template-columns: fit-content(50%) minmax(0, 1fr);
	margin: 0;
}

.advmap__facts dt {
	font-weight: 600;
	text-transform: uppercase;
}

.advmap__facts dd {
	margin: 0;
}

.advmap__items {
	list-style: none !important;
	margin: 0;
	padding: 0 !important;
}

.advmap__items li {
	list-style: none !important;
}

.advmap__details-photo img {
	border-radius: 4px;
	display: block;
	max-width: 100%;
}

.advmap__notes {
	margin-top: 8px;
}

.advmap__details-next {
	margin: 20px 0 12px;
}

.advmap__more {
	color: var(--advmap-green);
	font-weight: 700;
	text-decoration: underline;
}

.advmap__table-wrap {
	margin: 12px 0 24px;
	overflow-x: auto;
}

.advmap__table {
	background: #fff;
	border-collapse: collapse;
	font-size: 14px;
	min-width: 100%;
}

.advmap__table th,
.advmap__table td {
	border: 1px solid #333;
	padding: 3px 6px;
	white-space: nowrap;
}

.advmap__table tbody th {
	background: #e3e3e3;
	left: 0;
	position: sticky;
	text-align: left;
}

.advmap__center {
	text-align: center;
}

.advmap__charts {
	display: grid;
	gap: 16px;
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.advmap__chart {
	background: #fff;
	height: 400px; /* Until the script sets the final height, which fits the legend. */
}

@media (max-width: 980px) {
	.advmap__details-grid {
		grid-template-columns: 1fr 1fr;
	}

	.advmap__charts {
		grid-template-columns: 1fr;
	}
}

@media (max-width: 767px) {
	.advmap__details {
		padding: 16px;
		scroll-margin-top: 0;
	}

	.advmap__details-grid {
		grid-template-columns: 1fr;
	}

	.advmap__chart {
		height: 360px;
	}

	/* The frozen name column wraps, so the figures next to it stay in view. */
	.advmap .advmap__table tbody th,
	.advmap .advmap__table thead tr > th:first-child {
		max-width: 120px;
		min-width: 90px;
		white-space: normal;
	}
}

/* Long WinEMS values (soil descriptions) wrap between words; a single over-long word still breaks.
   Labels wrap between words only. */
.advmap__facts dt {
	overflow-wrap: break-word;
}

.advmap__facts dd {
	min-width: 0;
	overflow-wrap: break-word;
}

/* Narrow columns (phones, or the three columns on a small laptop): each label above its value,
   so values get the full width. The media query covers browsers without container queries. */
.advmap__details-grid > div {
	container-type: inline-size;
}

@container (max-width: 359px) {
	.advmap__facts {
		display: block;
	}

	.advmap__facts dt {
		color: var(--advmap-muted);
		font-size: 13px;
		line-height: 1.3;
		margin-top: 10px;
	}

	.advmap__facts dt:first-child {
		margin-top: 0;
	}

	.advmap__facts dd {
		line-height: 1.4;
	}
}

@media (max-width: 480px) {
	.advmap__facts {
		display: block;
	}

	.advmap__facts dt {
		color: var(--advmap-muted);
		font-size: 13px;
		line-height: 1.3;
		margin-top: 10px;
	}

	.advmap__facts dt:first-child {
		margin-top: 0;
	}

	.advmap__facts dd {
		line-height: 1.4;
	}
}

/* Compact table: override the theme's generous table cell padding. */
.advmap .advmap__table th,
.advmap .advmap__table td {
	font-size: 13px;
	line-height: 1.4;
	padding: 4px 8px !important;
}

.advmap .advmap__table thead th {
	background: #f4f6f2;
	font-weight: 600;
}
