/* EnergyGuide repair-or-replace calculator. Scoped to .egrr; inherits the theme's fonts. */

.egrr {
	/* Brand: EnergyGuide purple (#462186), taken from the site's buttons. */
	--egrr-ink: #2f2f35;
	--egrr-muted: #5f5d68;
	--egrr-line: #e2dfe8;
	--egrr-soft: #f6f4fa;
	--egrr-card: #ffffff;
	--egrr-accent: #462186;
	--egrr-accent-ink: #ffffff;
	--egrr-seg-now: #462186;
	--egrr-seg-future: #8b6cc6;
	--egrr-seg-gas: #cbbde9;
	--egrr-seg-replace: #6a6875;
	--egrr-repair-bg: #efeaf8;
	--egrr-replace-bg: #fbeee0;
	--egrr-replace-ink: #8a4a0c;
	--egrr-close-bg: #edf1f4;
	--egrr-radius: 10px;

	color: var(--egrr-ink);
	font-size: 1rem;
	line-height: 1.6;
	margin: 0 0 2em;
	container-type: inline-size;
	container-name: egrr;
}

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

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

.egrr-lead {
	font-size: 1.15em;
	line-height: 1.55;
	margin: 0 0 0.5em;
}

.egrr-meta,
.egrr-note,
.egrr-help,
.egrr-based,
.egrr-disclosure {
	color: var(--egrr-muted);
	font-size: 0.875em;
}

.egrr-meta {
	margin: 0 0 1.5em;
}

.egrr-h2 {
	margin: 0 0 0.6em;
}

.egrr-h3 {
	margin: 1.4em 0 0.4em;
}

.egrr-section {
	margin-top: 2.5em;
}

.egrr-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Card and form ------------------------------------------------------- */

.egrr-card {
	background: var(--egrr-card);
	border: 1px solid var(--egrr-line);
	border-radius: var(--egrr-radius);
	padding: 1.5em;
	box-shadow: 0 1px 2px rgba(16, 32, 40, 0.04);
}

.egrr-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1em 1.25em;
}

.egrr-field {
	display: flex;
	flex-direction: column;
	gap: 0.35em;
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.egrr-wide {
	grid-column: 1 / -1;
}

.egrr-field > label,
.egrr-field > legend {
	font-weight: 600;
	font-size: 0.95em;
	padding: 0;
	margin: 0 0 0.35em;
}

.egrr select,
.egrr input[type="number"] {
	width: 100%;
	min-height: 44px;
	padding: 0.5em 0.7em;
	font: inherit;
	color: var(--egrr-ink);
	background: #fff;
	border: 1px solid #b9c4cc;
	border-radius: 8px;
	margin: 0;
}

.egrr select:focus-visible,
.egrr input:focus-visible,
.egrr summary:focus-visible,
.egrr-submit:focus-visible,
.egrr-button:focus-visible,
.egrr-scroll:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--egrr-accent) 45%, transparent);
	outline-offset: 2px;
}

.egrr-money {
	position: relative;
}

.egrr-money > span {
	position: absolute;
	left: 0.75em;
	top: 50%;
	transform: translateY(-50%);
	color: var(--egrr-muted);
	pointer-events: none;
}

.egrr-money input[type="number"] {
	padding-left: 1.7em;
}

.egrr-help {
	margin: 0;
	line-height: 1.45;
}

.egrr-segmented {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5em;
}

.egrr-segmented label {
	position: relative;
	margin: 0;
	cursor: pointer;
}

.egrr-segmented input {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
	cursor: pointer;
}

.egrr-segmented span {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 0 1.1em;
	border: 1px solid #b9c4cc;
	border-radius: 999px;
	background: #fff;
	font-size: 0.95em;
}

.egrr-segmented input:checked + span {
	background: var(--egrr-accent);
	border-color: var(--egrr-accent);
	color: var(--egrr-accent-ink);
}

.egrr-segmented input:focus-visible + span {
	outline: 3px solid color-mix(in srgb, var(--egrr-accent) 45%, transparent);
	outline-offset: 2px;
}

.egrr-more {
	margin: 1.25em 0 0;
	border-top: 1px solid var(--egrr-line);
	padding-top: 0.9em;
}

.egrr-more summary {
	cursor: pointer;
	font-weight: 600;
	font-size: 0.95em;
	color: var(--egrr-accent);
}

.egrr-more[open] summary {
	margin-bottom: 0.9em;
}

.egrr-submit,
.egrr-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 46px;
	padding: 0 1.4em;
	border: 0;
	border-radius: 8px;
	background: var(--egrr-accent);
	color: var(--egrr-accent-ink);
	font: inherit;
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}

.egrr-submit {
	margin-top: 1.25em;
}

.egrr-submit:hover,
.egrr-button:hover {
	background: color-mix(in srgb, var(--egrr-accent) 85%, #000);
	color: var(--egrr-accent-ink);
}

/* With JS the result updates live, so the button is only a fallback. */
.egrr-live .egrr-submit {
	display: none;
}

/* Result -------------------------------------------------------------- */

.egrr-result {
	margin-top: 1.5em;
	padding: 1.25em 1.25em 1.1em;
	border-radius: var(--egrr-radius);
	background: var(--egrr-close-bg);
	scroll-margin-top: 1em;
}

.egrr-result[data-verdict="repair"] {
	background: var(--egrr-repair-bg);
}

.egrr-result[data-verdict="replace"] {
	background: var(--egrr-replace-bg);
}

.egrr-kicker {
	margin: 0;
	font-size: 0.8em;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--egrr-muted);
}

.egrr-verdict {
	margin: 0.1em 0 0.3em;
	font-size: 1.9em;
	font-weight: 700;
	line-height: 1.15;
	color: var(--egrr-accent);
}

.egrr-result[data-verdict="replace"] .egrr-verdict {
	color: var(--egrr-replace-ink);
}

.egrr-result[data-verdict="close"] .egrr-verdict {
	color: var(--egrr-ink);
}

.egrr-summary {
	margin: 0 0 0.6em;
}

.egrr-be {
	margin: 0 0 1.1em;
}

.egrr-be strong {
	font-weight: 600;
}

.egrr-compare {
	margin: 0 0 1em;
	padding: 1em;
	background: rgba(255, 255, 255, 0.75);
	border-radius: 8px;
}

.egrr-compare figcaption {
	font-weight: 600;
	font-size: 0.9em;
	margin: 0 0 0.75em;
}

.egrr-bars {
	display: grid;
	grid-template-columns: max-content minmax(0, 1fr) max-content;
	align-items: center;
	gap: 0.5em 0.75em;
	font-size: 0.95em;
}

.egrr-bar-row {
	display: contents;
}

.egrr-bar-label {
	white-space: nowrap;
}

.egrr-bar {
	display: flex;
	height: 18px;
	border-radius: 4px;
	overflow: hidden;
	background: rgba(29, 42, 51, 0.06);
}

.egrr-seg {
	display: block;
	height: 100%;
	transition: width 0.25s ease;
}

.egrr-seg + .egrr-seg {
	box-shadow: inset 2px 0 0 #fff;
}

.egrr-seg-now { background: var(--egrr-seg-now); }
.egrr-seg-future { background: var(--egrr-seg-future); }
.egrr-seg-gas { background: var(--egrr-seg-gas); }
.egrr-seg-replace { background: var(--egrr-seg-replace); }

.egrr-bar-value {
	text-align: right;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
	.egrr-seg { transition: none; }
}

.egrr-breakdown {
	width: 100%;
	margin: 1em 0 0;
	border-collapse: collapse;
	font-size: 0.9em;
	border: 0;
}

.egrr-breakdown th,
.egrr-breakdown td {
	padding: 0.3em 0;
	border: 0;
	border-bottom: 1px solid var(--egrr-line);
	background: transparent;
	text-align: left;
	font-weight: 400;
	vertical-align: top;
}

.egrr-breakdown td {
	text-align: right;
	white-space: nowrap;
	padding-left: 1em;
	font-variant-numeric: tabular-nums;
}

.egrr-breakdown .egrr-group th {
	padding-top: 0.8em;
	font-weight: 600;
	font-size: 0.85em;
	color: var(--egrr-muted);
	border-bottom: 0;
}

.egrr-breakdown tr:first-child th {
	padding-top: 0;
}

.egrr-breakdown .egrr-total th,
.egrr-breakdown .egrr-total td {
	font-weight: 600;
}

.egrr-key {
	display: inline-block;
	width: 10px;
	height: 10px;
	border-radius: 2px;
	margin-right: 0.5em;
	vertical-align: 0;
}

.egrr-based {
	margin: 0 0 0.5em;
}

.egrr-notes {
	margin: 0 0 0.5em;
	padding-left: 1.2em;
	font-size: 0.9em;
}

.egrr-notes li {
	margin: 0 0 0.25em;
}

.egrr-cta {
	margin: 1em 0 0;
}

/* Tables -------------------------------------------------------------- */

.egrr-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	margin: 0 0 0.75em;
	border: 1px solid var(--egrr-line);
	border-radius: 8px;
}

.egrr-table {
	width: 100%;
	margin: 0;
	border-collapse: collapse;
	font-size: 0.92em;
	border: 0;
}

.egrr-table th,
.egrr-table td {
	padding: 0.6em 0.8em;
	border: 0;
	border-bottom: 1px solid var(--egrr-line);
	text-align: left;
	vertical-align: top;
}

.egrr-table thead th {
	background: var(--egrr-soft);
	font-weight: 600;
	white-space: nowrap;
}

.egrr-table tbody tr:last-child th,
.egrr-table tbody tr:last-child td {
	border-bottom: 0;
}

.egrr-table tbody th {
	font-weight: 600;
	white-space: nowrap;
}

.egrr-table-grid td {
	text-align: right;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.egrr-table-grid thead th {
	white-space: normal;
	vertical-align: bottom;
}

.egrr-table-grid thead th:not(:first-child) {
	text-align: right;
}

.egrr-table-grid td.egrr-replace {
	color: var(--egrr-replace-ink);
	background: color-mix(in srgb, var(--egrr-replace-bg) 70%, transparent);
	font-weight: 600;
}

.egrr-formula {
	margin: 0 0 1em;
	padding: 0.8em 1em;
	background: var(--egrr-soft);
	border-left: 3px solid var(--egrr-accent);
	border-radius: 0 6px 6px 0;
	font-weight: 600;
}

.egrr-sources {
	padding-left: 1.2em;
	font-size: 0.92em;
}

.egrr-disclosure {
	margin-top: 2em;
	padding-top: 1em;
	border-top: 1px solid var(--egrr-line);
}

/* Wide containers: inputs on the left, verdict pinned on the right, so the
   result stays in view while people change the inputs. */

@container egrr (min-width: 820px) {
	.egrr-layout {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
		gap: 2em;
		align-items: start;
	}

	.egrr-layout .egrr-grid {
		grid-template-columns: minmax(0, 1fr);
		gap: 1em;
	}

	.egrr-layout .egrr-result {
		position: sticky;
		top: 1.5em;
		margin-top: 0;
	}

	.admin-bar .egrr-layout .egrr-result {
		top: calc(32px + 1.5em);
	}
}

/* Small screens ------------------------------------------------------- */

@media (max-width: 600px) {
	.egrr-card {
		padding: 1.1em;
		border-radius: 8px;
	}

	.egrr-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.egrr-result {
		padding: 1em;
	}

	.egrr-verdict {
		font-size: 1.6em;
	}

	.egrr-bars {
		gap: 0.5em;
	}

	.egrr-table {
		font-size: 0.85em;
	}

	.egrr-table th,
	.egrr-table td {
		padding: 0.55em 0.5em;
	}

	.egrr-table thead th {
		white-space: normal;
	}

	/* Break-even table: one block per boiler age, label and value side by side. */
	.egrr-table-grid thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}

	.egrr-table-grid tbody tr {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		column-gap: 1em;
		padding: 0.7em 0.8em;
		border-bottom: 1px solid var(--egrr-line);
	}

	.egrr-table-grid tbody tr:last-child {
		border-bottom: 0;
	}

	.egrr-table-grid tbody th {
		grid-column: 1 / -1;
		padding: 0 0 0.3em;
		border: 0;
	}

	.egrr-table-grid td {
		display: flex;
		justify-content: space-between;
		gap: 0.5em;
		padding: 0.15em 0;
		border: 0;
	}

	.egrr-table-grid td::before {
		content: attr(data-label);
		color: var(--egrr-muted);
		font-weight: 400;
	}

	.egrr-table-grid td.egrr-replace {
		background: transparent;
	}

	/* Stack the wide assumptions table into one block per row. */
	.egrr-table-stack thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}

	.egrr-table-stack tr {
		display: block;
		padding: 0.7em 0.8em;
		border-bottom: 1px solid var(--egrr-line);
	}

	.egrr-table-stack tbody tr:last-child {
		border-bottom: 0;
	}

	.egrr-table-stack th,
	.egrr-table-stack td {
		display: block;
		padding: 0;
		border: 0;
		white-space: normal;
	}

	.egrr-table-stack td + td {
		margin-top: 0.2em;
		color: var(--egrr-muted);
	}

	.egrr-compare {
		padding: 0.8em;
	}
}
