/* Calculator additions on top of section 25 of style.css.
   Everything shared already exists there: .calc, .calc__fields, .calc__field,
   .calc__out, .calc__result, .calc__rows. This file only adds what the three
   free calculators need on top of that frame: field-level errors, the error
   line inside the result region, the substituted arithmetic, the no-JavaScript
   worksheet, and the embed wrapper used inside the guides.

   No new colours and no new type family. The error red is #a4262c, the value
   .form-status already uses for its error state. --calc-border is a mix of two
   existing tokens, not a new palette entry.

   Loaded only by the three calculator pages and the three guides, so the
   .tablewrap overrides at the bottom cannot reach any other page. */

:root {
  /* 75% --muted on 25% --surface. Measured 3.45:1 against the card (#ffffff)
     and 3.19:1 against the field fill (#f5f6f8); WCAG 1.4.11 wants 3:1. */
  --calc-border: #838b95;
  --calc-border: color-mix(in srgb, var(--muted) 75%, var(--surface));
  /* .masthead is sticky and 88px tall at desktop, where the result column
     starts to follow the scroll. */
  --calc-header: 88px;
}

/* Field errors ---------------------------------------------------------- */

/* `.wrap p` and `.wrap li` in style.css are more specific than a single class,
   which is why 13px and 14px declarations used to be dead. Naming the wrap is
   the fix; !important is not. Each of these stays below the 18px body text. */
.wrap .calc__error {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  color: #a4262c;
  overflow-wrap: anywhere;
}

.wrap .calc__field input {
  border-color: var(--calc-border);
}

.calc__field input[aria-invalid="true"] {
  border-color: #a4262c;
  box-shadow: inset 0 0 0 1px #a4262c;
}

/* keeps the 44px target and the visible focus ring while the border is red */
.calc__field input[aria-invalid="true"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* A stretched field used to hand its spare height to the input, so five fields
   in one row came out 49, 51, 55 and 57px tall. Start the content instead. */
.calc__field { align-content: start; }

.wrap .calc__field small {
  font-size: 0.875rem;
}

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

.calc__out .calc__status {
  margin: 0 0 var(--space-4);
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.5;
  color: #a4262c;
  overflow-wrap: anywhere;
}

/* An empty status is not information; it should not take up space. */
.calc__out .calc__status:empty { display: none; }

/* A loss must not read like a gain. The minus sign stays on the number and
   this line says the same thing in words, in the error red already in use. */
.wrap .calc__verdict {
  margin: 0 0 var(--space-3);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  color: #a4262c;
}

/* Label left, value right, on every row: the value keeps its column instead of
   dropping to a new line when the label is long. */
.calc__rows div { align-items: baseline; }

.calc__rows dt { flex: 1 1 auto; }

.calc__rows dd {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.wrap .calc__note {
  margin: var(--space-5) 0 0;
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: none;
}

/* The two ways out of the result block: print it, or read the guide it comes
   from. Two targets, both 44px, both with the site's focus ring. */
.calc__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}

.calc__actions button,
.calc__actions a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.calc__actions button {
  border: 1px solid var(--calc-border);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.calc__actions button:hover { border-color: var(--ink); }

.calc__actions a {
  padding-left: 0;
  padding-right: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.calc__actions :is(button, a):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Substituted arithmetic ------------------------------------------------ */

.calc__working {
  margin: var(--space-4) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--rule);
}

.wrap .calc__working > p {
  margin: 0 0 var(--space-2);
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.calc__working ol {
  margin: 0;
  padding-left: 1.25rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.wrap .calc__working li {
  margin: 0 0 var(--space-1);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.calc__working li:last-child { margin-bottom: 0; }

/* Single column on a phone, two columns from 1024px: the form on the left, the
   result block beside it, so the number is on screen without scrolling. Under
   1024px the result block already follows the last field and precedes every
   explanatory section, because that is where it sits in the markup. */
@media (min-width: 1024px) {
  .calc--page {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    align-items: start;
    gap: var(--space-6) var(--space-8);
  }

  .calc--page .calc__fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
  }

  .calc--page .calc__out {
    position: sticky;
    top: calc(var(--calc-header) + var(--space-4));
    align-self: start;
    margin-top: 0;
    padding-top: 0;
    padding-left: var(--space-5);
    border-top: 0;
    border-left: 2px solid var(--ink);
  }
}

/* No JavaScript: formula, worksheet, and a sentence that says why --------- */

/* The block is for readers without scripting only. The `js` class is set on
   <html> in the head of every calculator page, so it disappears as soon as the
   calculator can compute. Print keeps it: the worksheet is the paper version. */
.js .calc-noscript { display: none; }

.calc-noscript {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  border-left: 3px solid var(--rule-strong);
  background: var(--surface);
}

.wrap .calc-noscript p {
  max-width: none;
  margin: 0 0 var(--space-3);
  font-size: 1rem;
  color: var(--ink-soft);
}

.calc-noscript strong { color: var(--ink); }

.calc-worksheet {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.875rem;
}

.calc-worksheet caption {
  caption-side: top;
  text-align: left;
  padding-bottom: var(--space-2);
  font-weight: 600;
  color: var(--ink);
}

.calc-worksheet th,
.calc-worksheet td {
  border: 1px solid var(--rule-strong);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.calc-worksheet thead th {
  background: var(--note);
  font-weight: 600;
}

/* The shared rules drop column headers to 12px (`.wrap table:not(:has(...))
   thead th` in style.css, which is more specific than two classes); the
   worksheet is read on paper as well, so nothing in it goes below 14px. */
.wrap .tablewrap .calc-worksheet thead th { font-size: 0.875rem; }

/* The second column is the one a reader fills in with a pen. */
.calc-worksheet th:last-child,
.calc-worksheet td:last-child { width: 38%; }

/* Embedded copy inside a guide ------------------------------------------ */

.calc-embed {
  margin: var(--space-8) 0;
}

.calc-embed > h2 { margin-top: 0; }

.calc-embed .calc { margin-top: var(--space-4); }

/* Worksheet inside .tablewrap ------------------------------------------- */

/* The worksheet is a fill-in sheet, so it keeps its two columns at every
   width; the shared mobile stack in style.css would turn each row into two
   blocks and make it longer, not shorter. Higher specificity than
   `.wrap .tablewrap table`, hence the wrap and the class both named. */
.wrap .tablewrap .calc-worksheet {
  display: table;
  table-layout: fixed;
}

/* Same reason: the shared rule turned the caption into a block, which then
   rendered below the column headers. */
.wrap .tablewrap .calc-worksheet caption {
  display: table-caption;
  caption-side: top;
}

/* The shared stack gives every cell 16px of padding and repeats the column
   name above every value; that is what made a nine-row table 2,407px tall on
   a phone. Same pattern, tighter spacing, values unchanged. */
@media (max-width: 1000px) {
  .wrap .tablewrap table tbody tr { padding: var(--space-2) 0; }

  .wrap .tablewrap table tbody :is(th, td):nth-child(n) {
    padding: var(--space-2) var(--space-3);
  }

  .wrap .tablewrap table td::before {
    margin-bottom: 2px;
    font-size: 0.875rem;
  }
}

/* Guided flow: step indicator, employee rows, look-up notes --------------- */

/* The wizard is one column: a step is read top to bottom, and the result
   arrives in the last step rather than beside the fields. Field height, label
   size, result size and button height come from the shared rules above and
   below, so a step and a single-page form stay the same size. */

.calc__steps { display: none; }

.js .wrap .calc__steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0 0 var(--space-5);
  padding: 0 0 var(--space-2);
  border-bottom: 1px solid var(--rule);
  list-style: none;
  font-family: var(--sans);
}

.wrap .calc__steps li {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.3;
}

.calc__step-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-1);
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.calc__step-link:hover { color: var(--ink); }

.calc__step-link[aria-current="step"] {
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--ink);
}

.calc__step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.8125rem;
  font-weight: 700;
}

.calc__step-link:focus-visible,
.calc__step-link[aria-current="step"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.wrap .calc__step-title {
  margin: 0 0 var(--space-2);
  font-family: var(--sans);
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--ink);
}

/* The step heading takes focus on every step change so a screen reader reads
   the step. Keyboard users keep the ring; a mouse click does not draw a box the
   width of the form. */
.wrap .calc__step-title:focus { outline: none; }

.wrap .calc__step-title:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* The masthead is sticky; a jump to a step must not land underneath it. */
.calc__step,
.calc__step-title {
  scroll-margin-top: calc(var(--calc-header) + var(--space-4));
}

.wrap .calc__step-intro {
  max-width: 46rem;
  margin: 0 0 var(--space-4);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.calc__step .calc__fields { margin-top: var(--space-3); }

/* The three answer lines and the year: text that belongs to the step, not a
   field. */
.wrap .calc__note-line {
  margin: 0 0 var(--space-4);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.calc__note-line strong { color: var(--ink); }

/* Employee rows ---------------------------------------------------------- */

.calc__employee {
  margin: 0 0 var(--space-5);
  padding: var(--space-4) 0 0;
  border: 0;
  border-top: 1px solid var(--rule);
  min-width: 0;
}

.calc__employee:first-of-type { padding-top: 0; border-top: 0; }

.wrap .calc__employee > legend,
.wrap .calc__choice > legend,
.wrap .calc__block-title {
  padding: 0;
  margin: 0 0 var(--space-3);
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.calc__roster {
  display: none;
  margin: var(--space-4) 0 0;
  padding: var(--space-4);
  border: 1px solid var(--rule);
}

.js .calc__roster { display: block; }

.wrap .calc__roster-title {
  margin: 0 0 var(--space-2);
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.calc__roster-list {
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.wrap .calc__roster-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  min-height: 44px;
  padding: var(--space-1) 0;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9375rem;
}

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

.calc__roster-name { font-weight: 600; }

/* Buttons: the same height as an input, on every page and in both embeds. */

.calc__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid var(--calc-border);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.calc__button:hover:not(:disabled) { border-color: var(--ink); }

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

.calc__button:disabled {
  color: var(--muted);
  border-color: var(--rule-strong);
  cursor: not-allowed;
}

.calc__button--quiet {
  border-color: transparent;
  padding-left: var(--space-1);
  padding-right: var(--space-1);
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.calc__button--quiet:hover:not(:disabled) { border-color: transparent; color: var(--ink); }

.calc__button--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.calc__button--primary:hover:not(:disabled) { border-color: var(--ink); }

.calc__nav { display: none; }

.js .calc__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}

.calc__nav [data-step-next] { margin-left: auto; }

/* Workers' compensation: three answers, each with its own fields ---------- */

.calc__choice {
  display: grid;
  gap: 0;
  margin: var(--space-5) 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.calc__choice label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-1) 0;
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.4;
  cursor: pointer;
}

.calc__choice input[type="radio"] {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--ink);
}

.calc__choice input[type="radio"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.calc__comp-panel { margin-top: var(--space-3); }

/* Select matches the inputs: same height, same border, same focus ring. */

.calc__field select {
  font: inherit;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--calc-border);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
}

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

.calc__field select[aria-invalid="true"] {
  border-color: #a4262c;
  box-shadow: inset 0 0 0 1px #a4262c;
}

/* "Where do I find this?" — a disclosure, 44px to open, no script needed. */

.wrap .calc__find {
  margin-top: var(--space-1);
  font-family: var(--sans);
}

.wrap .calc__find > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}

.wrap .calc__find > summary::-webkit-details-marker { display: none; }

.wrap .calc__find > summary::before {
  content: "+";
  display: inline-block;
  width: 0.75rem;
  font-weight: 700;
}

.wrap .calc__find[open] > summary::before { content: "\2212"; }

.wrap .calc__find > summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.wrap .calc__find p {
  max-width: 44rem;
  margin: 0 0 var(--space-2);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.wrap .calc__find p:last-child { margin-bottom: 0; }

.wrap .calc__find a { color: var(--accent); }

/* What is not known, and what the page assumes -------------------------- */

.wrap .calc__summary {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.5;
  color: #a4262c;
  overflow-wrap: anywhere;
}

/* A partial answer is information, not an error: it keeps the ink colour. */
.calc__out .calc__status[data-tone="info"] { color: var(--ink); }

.calc__missing-wrap {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}

.wrap .calc__block-title--plain {
  margin-bottom: var(--space-2);
  font-size: 0.875rem;
}

.wrap .calc__missing {
  margin: 0;
  padding-left: 1.25rem;
  font-family: var(--sans);
}

.wrap .calc__missing li {
  margin: 0 0 var(--space-1);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.wrap .calc__missing li:last-child { margin-bottom: 0; }

.calc__assumptions {
  margin: var(--space-5) 0 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}

.wrap .calc__assumptions ul {
  margin: 0;
  padding-left: 1.25rem;
  font-family: var(--sans);
}

.wrap .calc__assumptions li {
  margin: 0 0 var(--space-2);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.wrap .calc__assumptions li:last-child { margin-bottom: 0; }

.wrap .calc__assumptions a { color: var(--accent); }

/* A line the engine cannot know yet reads "Not known", not zero and not a
   dash, and it is visibly different from a computed number. */
.calc__out [data-missing="true"] {
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}

/* Print: the form and the results are one block, the worksheet one page ----- */

@media print {
  .calc,
  .calc-noscript { break-inside: avoid; page-break-inside: avoid; }

  /* Hiding the worksheet is a screen rule; on paper it is the receipt. */
  .js .calc-noscript { display: block; }

  .calc-note,
  .calc__note { break-inside: avoid; }

  .calc--page { display: block; }

  .calc--page .calc__out {
    position: static;
    padding-left: 0;
    border-left: 0;
    padding-top: var(--space-4);
    border-top: 2px solid var(--ink);
  }

  .calc__actions { display: none; }

  /* The nav and the roster are screen controls; the printed sheet keeps every
     step, not only the one that happened to be open. The `.js` prefix matches
     the display rules above, which are never `display: none` without it. */
  .js .calc__nav,
  .js .wrap .calc__steps,
  .js .calc__roster { display: none; }

  .calc__step[hidden] { display: block !important; }
}

@media (max-width: 420px) {
  .calc-worksheet { font-size: 0.875rem; }

  .calc-worksheet th,
  .calc-worksheet td { padding: var(--space-2); }
}

/* A row with one field in it would stretch that field to the width of the
   card, which reads like a missing column. Keep it at a field's width. */
.calc__fields:has(> .calc__field:only-child) {
  grid-template-columns: minmax(0, 26rem);
}

/* Four step labels on a 320px screen: tighter, so the indicator stays two rows
   and does not push the first field off the screen. */
@media (max-width: 520px) {
  .wrap .calc__steps { gap: 0 var(--space-3); }

  .calc__step-link {
    gap: var(--space-1);
    padding: 0;
    font-size: 0.875rem;
  }

  .calc__step-num { width: 1.375rem; height: 1.375rem; font-size: 0.75rem; }

  .calc__nav [data-step-next] { margin-left: 0; }
  .calc__nav { gap: var(--space-2); }
  .calc__nav .calc__button { flex: 1 1 auto; }
}

@media print {
  .masthead, .site-footer, .calc__actions, .related, .disclosure-line { display: none !important; }
  .calc__out, .calc__working { display: block !important; position: static !important; border: 0 !important; }
  .calc__field { break-inside: avoid; }
}

/* textarea fields (average calculator) */
.calc__field textarea { font: inherit; width: 100%; min-width: 0; max-width: 100%; min-height: 6rem; padding: var(--space-2) var(--space-3); border: 1px solid var(--calc-border, var(--rule-strong)); border-radius: 2px; background: var(--paper); color: var(--ink); resize: vertical; }
.calc__field textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.calc__field textarea[aria-invalid="true"] { border-color: #a4262c; box-shadow: inset 0 0 0 1px #a4262c; }
