/*!
 * RoofingWala - calculators
 *
 * Loaded on views that show calculators: a page or article carrying one of the
 * shortcodes, and the homepage, which lists them.
 *
 * Almost every rule is written as `.rw-calc .rw-calc__thing` rather than
 * `.rw-calc__thing`. A calculator normally sits inside `.rw-entry__content`,
 * whose prose rules are class-plus-element and would otherwise win on
 * specificity no matter which sheet prints last. Two classes settles it once,
 * for the whole file, without a single !important.
 */

/* ==========================================================================
   1. Frame
   ========================================================================== */

/*
 * Inside an article the calculator breaks out of the reading measure the same
 * way a wide image does, because two columns of controls at 66ch is a column
 * of controls and a column of air.
 */
.rw-entry__content > .rw-calc {
	grid-column: 1 / -1;
	width: 100%;
	max-width: var(--rw-wide);
	margin-inline: auto;
}

.rw-calc {
	margin-block: var(--rw-space-xl);
	border: 1px solid var(--rw-line);
	border-radius: var(--rw-radius);
	background: var(--rw-bg);
	padding: var(--rw-space-md);
}

/*
 * Fields and verdicts the script toggles. `hidden` alone loses to any rule
 * that sets display on the same element — .rw-calc__field is a grid, so a bare
 * `.rw-calc [hidden]` would tie on specificity and lose on order. Naming the
 * two attributes the script actually toggles takes this past every layout rule
 * in the file and keeps the intent readable.
 */
.rw-calc [data-rw-when][hidden],
.rw-calc [data-rw-result-when][hidden] {
	display: none;
}

@media (min-width: 40em) {
	.rw-calc {
		padding: var(--rw-space-lg);
	}
}

/* ==========================================================================
   2. Header
   ========================================================================== */

.rw-calc .rw-calc__title {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-h2);
	font-weight: 600;
	line-height: var(--rw-leading-snug);
	letter-spacing: var(--rw-tracking-tight);
	color: var(--rw-ink);
	margin: 0;
}

/* The chalk rule under article headings is not part of this component. */
.rw-calc .rw-calc__title::after {
	content: none;
}

.rw-calc .rw-calc__summary {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-small);
	line-height: 1.6;
	color: var(--rw-muted);
	max-width: 54ch;
	margin: var(--rw-space-2xs) 0 0;
}

/* ==========================================================================
   3. Unit switch
   ========================================================================== */

/*
 * Hidden until the script runs. A segmented control that does nothing is worse
 * than no control, and this is the one part of the component that is useless
 * without JavaScript.
 */
.rw-calc .rw-calc__units {
	display: none;
}

.rw-calc.is-ready .rw-calc__units {
	display: inline-flex;
	margin-top: var(--rw-space-md);
	border: 1px solid var(--rw-line-strong);
	border-radius: var(--rw-radius);
	overflow: hidden;
}

.rw-calc .rw-calc__unit {
	appearance: none;
	border: 0;
	background: var(--rw-bg);
	color: var(--rw-muted);
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--rw-tracking-label);
	padding: 0.6em 1.2em;
	min-height: 44px;
	cursor: pointer;
}

.rw-calc .rw-calc__unit + .rw-calc__unit {
	border-left: 1px solid var(--rw-line-strong);
}

.rw-calc .rw-calc__unit:hover {
	color: var(--rw-ink);
	background: var(--rw-surface);
}

.rw-calc .rw-calc__unit[aria-pressed="true"] {
	background: var(--rw-accent);
	color: #fff;
}

/* ==========================================================================
   4. No-script notice
   ========================================================================== */

.rw-calc .rw-calc__nojs {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-small);
	line-height: 1.6;
	color: var(--rw-body);
	background: var(--rw-surface);
	border-left: 3px solid var(--rw-line-strong);
	padding: var(--rw-space-xs) var(--rw-space-sm);
	margin: var(--rw-space-md) 0 0;
}

.rw-calc.is-ready .rw-calc__nojs {
	display: none;
}

/* ==========================================================================
   5. Layout
   ========================================================================== */

.rw-calc .rw-calc__layout {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--rw-space-lg);
	margin-top: var(--rw-space-md);
}

@media (min-width: 48em) {
	.rw-calc .rw-calc__layout {
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		gap: var(--rw-space-xl);
		align-items: start;
	}
}

/* ==========================================================================
   6. Fields
   ========================================================================== */

.rw-calc .rw-calc__form {
	display: grid;
	gap: var(--rw-space-md);
	margin: 0;
}

.rw-calc .rw-calc__field {
	display: grid;
	gap: var(--rw-space-3xs);
}

.rw-calc .rw-calc__label {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-small);
	font-weight: 600;
	line-height: 1.35;
	color: var(--rw-ink);
}

/*
 * Input and suffix share one border so the unit reads as part of the box
 * rather than as a separate control someone might try to click.
 */
.rw-calc .rw-calc__control {
	display: flex;
	align-items: stretch;
	border: 1px solid var(--rw-line-strong);
	border-radius: var(--rw-radius);
	background: var(--rw-bg);
	overflow: hidden;
}

.rw-calc .rw-calc__control:focus-within {
	outline: 2px solid var(--rw-accent);
	outline-offset: 2px;
}

.rw-calc .rw-calc__input,
.rw-calc .rw-calc__select {
	flex: 1 1 auto;
	min-width: 0;
	appearance: none;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--rw-ink);
	font-family: var(--rw-font-heading);
	font-size: 1rem;
	font-variant-numeric: tabular-nums;
	line-height: 1.4;
	min-height: 46px;
	padding: 0 var(--rw-space-xs);
}

.rw-calc .rw-calc__select {
	padding-right: var(--rw-space-lg);
	background-image: linear-gradient(45deg, transparent 50%, var(--rw-muted) 50%), linear-gradient(135deg, var(--rw-muted) 50%, transparent 50%);
	background-position: calc(100% - 20px) calc(50% + 2px), calc(100% - 14px) calc(50% + 2px);
	background-size: 6px 6px, 6px 6px;
	background-repeat: no-repeat;
	cursor: pointer;
	text-overflow: ellipsis;
}

/* The focus ring belongs to the whole box, not to the control inside it. */
.rw-calc .rw-calc__input:focus,
.rw-calc .rw-calc__input:focus-visible,
.rw-calc .rw-calc__select:focus,
.rw-calc .rw-calc__select:focus-visible {
	outline: 0;
}

.rw-calc .rw-calc__suffix {
	display: flex;
	align-items: center;
	flex: 0 0 auto;
	padding-inline: var(--rw-space-xs);
	border-left: 1px solid var(--rw-line);
	background: var(--rw-surface);
	color: var(--rw-muted);
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	white-space: nowrap;
}

.rw-calc .rw-calc__hint {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-meta);
	line-height: 1.5;
	color: var(--rw-muted);
	margin: 0;
}

/* ==========================================================================
   7. Product coverage panel
   ========================================================================== */

.rw-calc .rw-calc__advanced {
	border-top: 1px solid var(--rw-line);
	padding-top: var(--rw-space-md);
}

.rw-calc .rw-calc__advanced-summary {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--rw-tracking-label);
	color: var(--rw-accent);
	cursor: pointer;
	list-style: none;
	padding-block: var(--rw-space-2xs);
}

.rw-calc .rw-calc__advanced-summary::-webkit-details-marker {
	display: none;
}

.rw-calc .rw-calc__advanced-summary::before {
	content: "+";
	display: inline-block;
	width: 1.2em;
	font-weight: 700;
}

.rw-calc .rw-calc__advanced[open] .rw-calc__advanced-summary::before {
	content: "\2212";
}

.rw-calc .rw-calc__advanced-intro {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-meta);
	line-height: 1.5;
	color: var(--rw-muted);
	margin: var(--rw-space-2xs) 0 var(--rw-space-md);
}

.rw-calc .rw-calc__advanced .rw-calc__field + .rw-calc__field {
	margin-top: var(--rw-space-md);
}

/* ==========================================================================
   8. Actions
   ========================================================================== */

.rw-calc .rw-calc__actions {
	display: flex;
}

.rw-calc .rw-calc__reset {
	appearance: none;
	background: transparent;
	border: 1px solid var(--rw-line-strong);
	border-radius: var(--rw-radius);
	color: var(--rw-body);
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--rw-tracking-label);
	min-height: 44px;
	padding-inline: var(--rw-space-md);
	cursor: pointer;
}

.rw-calc .rw-calc__reset:hover {
	background: var(--rw-surface);
	color: var(--rw-ink);
}

/* ==========================================================================
   9. Results
   ========================================================================== */

.rw-calc .rw-calc__results {
	background: var(--rw-surface);
	border-radius: var(--rw-radius);
	padding: var(--rw-space-md);
}

@media (min-width: 48em) {
	.rw-calc .rw-calc__results {
		position: sticky;
		top: var(--rw-space-md);
	}
}

.rw-calc .rw-calc__headline {
	display: grid;
	gap: var(--rw-space-3xs);
	margin: 0 0 var(--rw-space-md);
	padding-bottom: var(--rw-space-md);
	border-bottom: 1px solid var(--rw-line-strong);
}

.rw-calc .rw-calc__headline-label {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--rw-tracking-label);
	color: var(--rw-muted);
}

.rw-calc .rw-calc__headline-value {
	font-family: var(--rw-font-heading);
	font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem);
	font-weight: 700;
	line-height: var(--rw-leading-tight);
	letter-spacing: var(--rw-tracking-tight);
	font-variant-numeric: tabular-nums;
	color: var(--rw-accent);
	overflow-wrap: break-word;
}

.rw-calc .rw-calc__headline-hint {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-meta);
	line-height: 1.5;
	color: var(--rw-muted);
}

.rw-calc .rw-calc__breakdown {
	margin: 0;
}

.rw-calc .rw-calc__row {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: baseline;
	gap: var(--rw-space-2xs);
	padding-block: var(--rw-space-2xs);
}

.rw-calc .rw-calc__row + .rw-calc__row {
	border-top: 1px solid var(--rw-line);
}

.rw-calc .rw-calc__row-label {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-small);
	line-height: 1.4;
	color: var(--rw-body);
	margin: 0;
	flex: 1 1 12ch;
}

.rw-calc .rw-calc__row-hint {
	display: block;
	font-size: var(--rw-size-meta);
	color: var(--rw-muted);
	margin-top: 2px;
}

.rw-calc .rw-calc__row-value {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-small);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--rw-ink);
	text-align: right;
	margin: 0;
	flex: 0 1 auto;
}

/* ==========================================================================
   10. Verdict and note
   ========================================================================== */

.rw-calc .rw-calc__verdict-item {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-small);
	line-height: 1.6;
	color: var(--rw-body);
	background: var(--rw-accent-soft);
	border-left: 3px solid var(--rw-accent);
	border-radius: 0 var(--rw-radius) var(--rw-radius) 0;
	padding: var(--rw-space-sm);
	margin: var(--rw-space-md) 0 0;
}

.rw-calc .rw-calc__note {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-meta);
	line-height: 1.6;
	color: var(--rw-muted);
	margin: var(--rw-space-md) 0 0;
	padding-top: var(--rw-space-md);
	border-top: 1px solid var(--rw-line);
}

/* ==========================================================================
   11. Index
   ========================================================================== */

/*
 * Doubled class for the same specificity reason as the rest of the file: the
 * index is a <ul>, and article prose styles list items.
 */
.rw-calc-index.rw-calc-index {
	list-style: none;
	display: grid;
	gap: var(--rw-space-md);
	margin: var(--rw-space-lg) 0;
	padding: 0;
}

@media (min-width: 40em) {
	.rw-calc-index.rw-calc-index {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/*
 * Three across at the theme's wide breakpoint. On the homepage that is one row
 * for the three calculators; on the index page a fourth would wrap onto a
 * second row rather than squeezing the set thinner.
 */
@media (min-width: 62.5em) {
	.rw-calc-index.rw-calc-index {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

/* ==========================================================================
   12. Homepage band
   ========================================================================== */

/*
 * Same full width construction as the promise and topic bands: the panel, not
 * the section, carries the band, so it scopes itself without :has(). The
 * padding-block replaces the padding-top .rw-home__section sets, which is what
 * keeps the tint evenly inset top and bottom.
 *
 * The tint is the accent wash rather than the surface grey those two use. On a
 * homepage of white article cards, a third grey band would separate this from
 * the articles and not from the other bands, and the whole point of this one is
 * that it is a tool and not something to read.
 */
.rw-tools__panel {
	margin-inline: calc(50% - 50vw);
	padding-inline: calc(50vw - 50%);
	padding-block: var(--rw-space-2xl);
	background-color: var(--rw-accent-soft);
}

.rw-tools__intro {
	max-width: 46rem;
	margin-inline: auto;
	margin-bottom: var(--rw-space-lg);
	text-align: center;
}

/*
 * The promise eyebrow is accent text on an accent wash pill. That pill would be
 * invisible here, the band being that wash, so this one drops the fill and
 * earns its separation from the heading with a rule instead.
 */
.rw-tools__eyebrow {
	display: inline-block;
	margin: 0 0 var(--rw-space-xs);
	padding-bottom: var(--rw-space-3xs);
	border-bottom: 2px solid var(--rw-accent);
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-meta);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--rw-tracking-label);
	color: var(--rw-accent);
}

.rw-tools__title {
	margin: 0;
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-h2);
	font-weight: 600;
	line-height: var(--rw-leading-snug);
	letter-spacing: var(--rw-tracking-tight);
	color: var(--rw-ink);
}

.rw-tools__lede {
	margin: var(--rw-space-2xs) 0 0;
	color: var(--rw-muted);
	font-size: 1.0625rem;
	line-height: 1.65;
}

.rw-tools .rw-calc-index.rw-calc-index {
	margin: 0;
}

/*
 * White is stated rather than inherited: on the homepage these sit on the
 * accent wash, and a transparent card would dissolve into it.
 */
.rw-calc-index.rw-calc-index .rw-calc-index__item {
	background-color: var(--rw-bg);
	border: 1px solid var(--rw-line);
	border-radius: var(--rw-radius);
	padding: var(--rw-space-md);
	margin: 0;
}

.rw-calc-index.rw-calc-index .rw-calc-index__item:hover {
	border-color: var(--rw-accent);
}

.rw-calc-index.rw-calc-index .rw-calc-index__title {
	font-family: var(--rw-font-heading);
	font-size: var(--rw-size-h3);
	font-weight: 600;
	line-height: var(--rw-leading-snug);
	letter-spacing: var(--rw-tracking-tight);
	margin: 0;
}

.rw-calc-index.rw-calc-index .rw-calc-index__title::after {
	content: none;
}

.rw-calc-index.rw-calc-index .rw-calc-index__link {
	color: var(--rw-ink);
	text-decoration: none;
	background-image: none;
}

.rw-calc-index.rw-calc-index .rw-calc-index__link:hover {
	color: var(--rw-accent);
}

.rw-calc-index.rw-calc-index .rw-calc-index__summary {
	font-family: var(--rw-font-body);
	font-size: var(--rw-size-small);
	line-height: 1.6;
	color: var(--rw-muted);
	margin: var(--rw-space-2xs) 0 0;
}

/* ==========================================================================
   13. Print
   ========================================================================== */

@media print {
	.rw-calc {
		break-inside: avoid;
		border-color: #999;
	}

	.rw-calc .rw-calc__units,
	.rw-calc .rw-calc__actions {
		display: none;
	}

	.rw-calc .rw-calc__layout {
		grid-template-columns: 1fr;
	}

	.rw-calc .rw-calc__results {
		position: static;
		background: transparent;
		border: 1px solid #999;
	}

	.rw-calc .rw-calc__advanced {
		display: none;
	}
}
