/**
 * Estimating Cards calculator.
 *
 * Every colour comes from `06-design-tokens.css`; no literals are introduced
 * here. The tokens are defined on :root by the theme, and redefined for dark
 * under both the media query and [data-theme], so styling through them is what
 * makes this component work in both themes without a second palette.
 */

.pem-calc {
	display: grid;
	gap: 1.5rem;
	grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
	align-items: start;
	font-family: var(--font-sans);
	color: var(--ink);
}

@media (max-width: 60rem) {
	.pem-calc { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------------- form -- */

.pem-calc__form {
	display: grid;
	gap: 1rem;
	padding: 1.25rem;
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.pem-calc__field { display: grid; gap: .35rem; }

.pem-calc__field label {
	font-family: var(--font-mono);
	font-size: .6875rem;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--ink-2);
}

.pem-calc__form select,
.pem-calc__form input[type="number"],
.pem-calc__form input[type="text"] {
	font: inherit;
	padding: .5rem .6rem;
	color: var(--ink);
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	min-height: 44px;
}

.pem-calc__form :is(select, input):focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 1px;
}

/* A disabled option still has to be readable — the user is entitled to see
   that the equipment exists and why there is no number for it. */
.pem-calc__form option:disabled { color: var(--ink-3); }

.pem-calc__hint { margin: 0; font-size: var(--step--1); color: var(--ink-2); }
.pem-calc__reason { margin: 0; font-size: var(--step--1); color: var(--stop); }
.pem-calc__error { margin: 0; font-size: var(--step--1); color: var(--stop); font-weight: 600; }
.pem-calc__expr  { margin: 0; font-family: var(--font-mono); font-size: .75rem; color: var(--ink-2); }

.pem-calc__units { display: flex; flex-wrap: wrap; gap: .25rem; }
.pem-calc__units input { position: absolute; opacity: 0; pointer-events: none; }

.pem-calc__units label {
	padding: .3rem .6rem;
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	cursor: pointer;
	text-transform: none;
	letter-spacing: 0;
	font-size: var(--step--1);
}

.pem-calc__units input:checked + label {
	background: var(--accent-wash);
	border-color: var(--accent);
	color: var(--accent-deep);
}

.pem-calc__units input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 1px; }

.pem-calc__assumptions,
.pem-calc__pdf-fields {
	display: grid;
	gap: .6rem;
	margin: 0;
	padding: .9rem;
	border: 1px solid var(--rule-soft);
	border-radius: var(--radius);
	background: var(--paper-2);
}

.pem-calc__assumptions legend,
.pem-calc__pdf-fields legend {
	font-family: var(--font-mono);
	font-size: .6875rem;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--ink-2);
	padding-inline: .3rem;
}

.pem-calc__privacy {
	margin: 0;
	font-size: var(--step--1);
	color: var(--ink-2);
	border-left: 3px solid var(--accent);
	padding-left: .6rem;
}

/* -------------------------------------------------------------- output -- */

.pem-calc__output { min-height: 2rem; }

.pem-calc__result,
.pem-calc__refusal {
	display: grid;
	gap: 1.1rem;
	padding: 1.25rem;
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
}

.pem-calc__refusal { border-left: 4px solid var(--stop); }
.pem-calc__refusal h3 { margin: 0; color: var(--stop); font-size: var(--step-1); }
.pem-calc__range { font-family: var(--font-mono); font-weight: 600; }

.pem-calc__band { display: grid; gap: .5rem; }

.pem-calc__class {
	margin: 0;
	font-family: var(--font-mono);
	font-size: .6875rem;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--ink-2);
}

.pem-calc__p50 {
	margin: 0;
	font-size: var(--step-3);
	line-height: 1.05;
	font-weight: 700;
	color: var(--ink);
}

/* The band is a list, not a bar: it is asymmetric and must never be read as a
   symmetrical ± around the P50. Words as well as numbers, so it does not rely
   on position or colour. */
.pem-calc__band-list,
.pem-calc__costs {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: .3rem .9rem;
	margin: 0;
	font-size: var(--step--1);
}

.pem-calc__band-list dt,
.pem-calc__costs dt { color: var(--ink-2); }

.pem-calc__band-list dd,
.pem-calc__costs dd { margin: 0; text-align: right; font-weight: 600; }

.pem-calc__ref {
	display: block;
	font-weight: 400;
	font-size: .75rem;
	color: var(--ink-3);
}

.pem-calc__warning,
.pem-calc__notice {
	margin: 0;
	padding: .6rem .8rem;
	border-radius: var(--radius);
	font-size: var(--step--1);
}

.pem-calc__warning { background: var(--warn-wash); color: var(--warn); border: 1px solid color-mix(in oklab, var(--warn) 30%, transparent); }
.pem-calc__notice  { background: var(--paper-2); color: var(--ink-2); border: 1px solid var(--rule-soft); }

.pem-calc__conversion {
	display: grid;
	gap: .3rem;
	padding: .7rem .8rem;
	background: var(--paper-2);
	border-radius: var(--radius);
}

.pem-calc__conversion p { margin: 0; }

.pem-calc__params { width: 100%; border-collapse: collapse; font-size: var(--step--1); }

.pem-calc__params caption {
	caption-side: top;
	text-align: left;
	font-family: var(--font-mono);
	font-size: .6875rem;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--ink-2);
	padding-bottom: .4rem;
}

.pem-calc__params :is(th, td) {
	border-bottom: 1px solid var(--rule-soft);
	padding: .35rem .4rem;
	text-align: left;
}

.pem-calc__params th { font-family: var(--font-mono); font-weight: 500; color: var(--ink-2); }
.pem-calc__params td { text-align: right; }

.pem-calc__disclaimer {
	margin: 0;
	font-size: var(--step--1);
	color: var(--ink-2);
	border-top: 1px solid var(--rule);
	padding-top: .8rem;
}

.pem-calc__print {
	justify-self: start;
	font: inherit;
	padding: .6rem 1.1rem;
	min-height: 44px;
	color: var(--paper);
	background: var(--accent-deep);
	border: 1px solid var(--accent-deep);
	border-radius: var(--radius);
	cursor: pointer;
}

.pem-calc__print:hover { background: var(--accent); }
.pem-calc__print:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- gate -- */

.pem-calc-gate {
	padding: 1.25rem;
	background: var(--paper-2);
	border: 1px solid var(--rule);
	border-left: 4px solid var(--accent);
	border-radius: var(--radius);
}

.pem-calc-gate h3 { margin-top: 0; font-size: var(--step-1); }

/* -------------------------------------------------------------------------
 * Display preferences — unit system, currency, cost intensity.
 *
 * Above the first input and in the same place on every page, so a reader who
 * has set them once knows where to find them. `13-units-and-currency.md` §1.
 * ---------------------------------------------------------------------- */

.pem-calc__display {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem 1.5rem;
	align-items: end;
	padding: 0 0 1rem;
	margin: 0 0 1.25rem;
	border-bottom: 1px solid var(--rule, #d4d8dd);
}

.pem-calc__display .pem-calc__field { gap: .35rem; }

/* Matches the label typography of a real <label>, since one of these is a
   <span> labelling a radio group rather than a single control. */
.pem-calc__label {
	font-size: var(--step--1, .875rem);
	font-weight: 600;
	color: var(--ink-2, #4a5058);
}

/* A segmented control, not a dropdown: two options, both worth showing (§6). */
.pem-calc__segmented { display: flex; gap: 0; }
.pem-calc__segmented input { position: absolute; opacity: 0; pointer-events: none; }

.pem-calc__segmented label {
	padding: .4rem .85rem;
	border: 1px solid var(--rule, #d4d8dd);
	cursor: pointer;
	font-size: var(--step--1, .875rem);
	background: var(--ground, #fff);
	user-select: none;
}

.pem-calc__segmented label:first-of-type { border-radius: 4px 0 0 4px; }
.pem-calc__segmented label:last-of-type { border-radius: 0 4px 4px 0; margin-left: -1px; }

.pem-calc__segmented input:checked + label {
	background: var(--accent, #0b4f6c);
	border-color: var(--accent, #0b4f6c);
	color: #fff;
}

.pem-calc__segmented input:focus-visible + label {
	outline: 3px solid var(--accent, #0b4f6c);
	outline-offset: 1px;
}

/* -------------------------------------------------------------------------
 * The cost-basis label.
 *
 * Adjacent to the figure and at readable size — never a tooltip, never small
 * print. DO-NOT item 13. It is deliberately NOT styled down: a figure in GBP
 * is a US cost basis with a pound sign on it, and this sentence is the only
 * thing standing between that and a misread number.
 * ---------------------------------------------------------------------- */

.pem-calc__cost-basis {
	margin: .75rem 0 1rem;
	padding: .75rem .9rem;
	border-left: 4px solid var(--warn, #a2621c);
	background: var(--warn-bg, #fdf6ec);
	font-size: var(--step-0, 1rem);
	line-height: 1.5;
	max-width: var(--measure, 62ch);
}

/* An exact conversion is not a measurement and must not borrow its styling. */
.pem-tag--exact {
	background: var(--exact-bg, #eaf2f6);
	color: var(--exact-ink, #0b4f6c);
	border: 1px solid var(--exact-ink, #0b4f6c);
}

/* -----------------------------------------------------------------------
 * IPR and DEU — 18-ipr-and-deu.md §5.
 *
 * The partial-estimate notice sits ABOVE the figure, not below it, and is
 * styled at least as loudly as the cost-basis label. A subtotal presented as
 * a total is the most damaging output this tool can produce (DO-NOT 23), and
 * a caveat placed under a large number is a caveat that gets scrolled past.
 * --------------------------------------------------------------------- */

.pem-calc__partial {
	margin: 0 0 1rem;
	padding: .85rem 1rem;
	border-left: 4px solid var(--stop, #9b2226);
	background: var(--stop-bg, #fdecec);
	max-width: var(--measure, 62ch);
}

.pem-calc__partial-label {
	margin: 0 0 .35rem;
	font-weight: 700;
	font-size: var(--step-0, 1rem);
	letter-spacing: .01em;
}

.pem-calc__partial p:last-child {
	margin: 0;
	font-size: var(--step--1);
	line-height: 1.5;
}

.pem-calc__adjustments {
	display: grid;
	grid-template-columns: minmax(12rem, auto) 1fr;
	gap: .35rem 1.25rem;
	margin: 1rem 0 .5rem;
}

.pem-calc__adjustments dt { font-weight: 600; }
.pem-calc__adjustments dd { margin: 0; }

.pem-calc__adjustments .pem-calc__ref {
	display: block;
	font-size: var(--step--1);
	color: var(--ink-2);
	font-weight: 400;
}

/*
 * `not_assessed` must not read as a number, and must not read as an empty
 * cell either — an empty cell is indistinguishable from zero. Italic, in the
 * body ink rather than the muted grey, so it reads as a stated state.
 */
.pem-calc__unassessed {
	font-style: italic;
	color: var(--ink-1, inherit);
}

.pem-calc__scope {
	margin: .5rem 0;
	font-size: var(--step--1);
	line-height: 1.5;
	color: var(--ink-2);
	max-width: var(--measure, 62ch);
}

/* -----------------------------------------------------------------------
 * Cost escalation — 10-acceptance-criteria.md §T2.
 *
 * Styled like the cost-basis label rather than like a hint: an escalated
 * figure with no statement of what escalated it is indistinguishable from a
 * re-anchored one, and those are very different claims.
 * --------------------------------------------------------------------- */

.pem-calc__escalated {
	margin: .75rem 0 1rem;
	padding: .75rem .9rem;
	border-left: 4px solid var(--accent, #0b4f6c);
	background: var(--accent-bg, #eef4f7);
	max-width: var(--measure, 62ch);
}

.pem-calc__escalated p { margin: 0; line-height: 1.5; }
.pem-calc__escalated p + p { margin-top: .4rem; }

/*
 * The subscription note, where the detailed estimate is gated.
 *
 * Deliberately quiet. The visitor has just been given the number they came
 * for — v2.0 removed the whole-tool gate precisely so that happens — and a
 * loud upsell under a free answer reads as a bait-and-switch.
 */
.pem-calc__upsell {
	margin: 1rem 0 0;
	padding: .75rem .9rem;
	border: 1px solid var(--rule, #d8d8d8);
	border-radius: 2px;
	font-size: var(--step--1);
	line-height: 1.5;
	color: var(--ink-2);
	max-width: var(--measure, 62ch);
}

/* -----------------------------------------------------------------------
 * The Project ROM Estimator — 19-rom-estimator.md, §S2-S4.
 *
 * All thirteen blocks render, including the empty ones, so the form is long
 * by design: a reader must be able to see what has NOT been estimated as
 * easily as what has. Each block is a fieldset rather than a row, because a
 * value without its basis beside it is exactly the hidden allowance DO-NOT 24
 * forbids.
 * --------------------------------------------------------------------- */

.pem-rom__form {
	display: grid;
	gap: 1rem;
	max-width: var(--measure-wide, 78ch);
}

.pem-rom__block {
	display: grid;
	grid-template-columns: minmax(6rem, auto) 1fr;
	gap: .4rem .9rem;
	margin: 0;
	padding: .9rem 1rem;
	border: 1px solid var(--rule, #e0e0e0);
	border-radius: 2px;
}

.pem-rom__block legend {
	grid-column: 1 / -1;
	font-weight: 700;
	padding: 0;
}

.pem-rom__source {
	grid-column: 1 / -1;
	margin: 0 0 .35rem;
	font-size: var(--step--2, .8rem);
	color: var(--ink-2);
}

.pem-rom__block label { align-self: center; font-size: var(--step--1); }
.pem-rom__block input,
.pem-rom__block select { width: 100%; }

.pem-rom__output { margin: 2rem 0 0; max-width: var(--measure, 62ch); }

/*
 * The label sits ABOVE the figure, and the partial variant is loud. A subtotal
 * presented as a total is the most damaging output this tool can produce, and
 * a caveat under a large number is a caveat that gets scrolled past.
 */
.pem-rom__label {
	margin: 0 0 .35rem;
	font-weight: 700;
	font-size: var(--step-1, 1.125rem);
}

.pem-rom__label--partial { color: var(--stop, #9b2226); }

.pem-rom__partial {
	margin: 0 0 .75rem;
	padding: .75rem .9rem;
	border-left: 4px solid var(--stop, #9b2226);
	background: var(--stop-bg, #fdecec);
	font-size: var(--step--1);
	line-height: 1.5;
}

.pem-rom__figure {
	margin: 0;
	font-size: var(--step-4, 2.4rem);
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.pem-rom__envelope,
.pem-rom__grade {
	margin: .6rem 0 0;
	font-size: var(--step--1);
	color: var(--ink-2);
	line-height: 1.5;
}

.pem-rom__error {
	margin: .75rem 0 0;
	font-size: var(--step--1);
	font-weight: 600;
	color: var(--stop, #9b2226);
	line-height: 1.5;
}
