/* "The working" - the part of a tool page that exists to be read rather than
 * used, plus the static heading that makes the page a document before any
 * JavaScript runs.
 *
 * Design brief, from BRAND.md: subtraction is the default direction, and
 * "working and caveats live inside the tool or deliverable, never on the index
 * page". So the depth belongs here, on the tool page - but it must not turn a
 * clean calculator into a wall of text. Everything below the tool is therefore
 * collapsed by default.
 *
 * The important property: <details> content is present in the HTML whether it
 * is open or shut. A crawler reads all of it; a visitor sees four quiet lines
 * until they choose otherwise. Nothing is hidden from a machine to keep it
 * tidy for a human, which would be cloaking - it is the same document, just
 * folded.
 */

.tool-working {
  max-width: 46rem;
  margin: 3.5rem auto 0;
  padding: 0 1.5rem;
}

.working-head {
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faded, #8B8270);
  margin: 0 0 1rem;
}

/* Each fold ------------------------------------------------------------- */

.tool-working details {
  border-top: 1px solid var(--rule-soft, #B3A887);
}

.tool-working details:last-of-type {
  border-bottom: 1px solid var(--rule-soft, #B3A887);
}

.tool-working summary {
  /* list-style on the marker is the reliable cross-browser removal; the
   * ::-webkit-details-marker rule below catches older Safari. */
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: 1.05rem 0;
  font-family: var(--font-display, Newsreader, Georgia, serif);
  font-size: 1.12rem;
  line-height: 1.35;
  color: var(--ink, #141414);
}

.tool-working summary::-webkit-details-marker { display: none; }

.tool-working summary:hover { color: var(--orange-deep, #B8431A); }

.tool-working summary:focus-visible {
  outline: 2px solid var(--orange, #DF5911);
  outline-offset: 3px;
}

/* The caret is drawn rather than typed so it rotates smoothly and never
 * inherits a font that lacks the glyph. */
.tool-working summary::before {
  content: "";
  flex: none;
  width: .5rem;
  height: .5rem;
  margin-top: .42rem;
  border-right: 2px solid var(--orange, #DF5911);
  border-bottom: 2px solid var(--orange, #DF5911);
  transform: rotate(-45deg);
  transition: transform .18s ease;
}

.tool-working details[open] > summary::before {
  transform: rotate(45deg);
}

.tool-working details[open] > summary {
  color: var(--orange-deep, #B8431A);
}

.working-body {
  padding: 0 0 1.4rem 1.25rem;
  font-size: .98rem;
  line-height: 1.65;
  color: var(--ink-2, #2A2724);
}

.working-body > *:first-child { margin-top: 0; }
.working-body > *:last-child { margin-bottom: 0; }

.working-body p { margin: 0 0 .9rem; }

.working-body ul {
  margin: 0 0 .9rem;
  padding-left: 1.1rem;
}

.working-body li { margin-bottom: .4rem; }

.working-body strong { font-weight: 600; }

.working-body a {
  color: var(--orange-deep, #B8431A);
  text-underline-offset: 2px;
}

/* The formula line - set in mono so the arithmetic reads as arithmetic.
 *
 * pre-wrap, not pre: the line breaks written in the source are meaningful
 * (they separate a formula from the definition of its terms) and HTML would
 * otherwise collapse them into one run-on line. pre-wrap keeps those breaks
 * while still letting a long line wrap on a narrow phone rather than forcing
 * a horizontal scroll. */
.working-formula {
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: .88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  background: var(--paper-2, #E8DFCC);
  border-left: 2px solid var(--orange, #DF5911);
  padding: .85rem 1rem;
  margin: 0 0 1rem;
  overflow-x: auto;
}

/* Rates tables. These scroll inside themselves rather than pushing the page
 * sideways on a phone. */
.working-table-wrap {
  overflow-x: auto;
  margin: 0 0 1rem;
}

.working-table {
  border-collapse: collapse;
  width: 100%;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
}

.working-table th,
.working-table td {
  text-align: left;
  padding: .5rem .85rem .5rem 0;
  border-bottom: 1px solid var(--rule-soft, #B3A887);
  vertical-align: top;
}

/* Cells wrap. Several of these tables carry a prose column ("Effective 26.5%
 * on each extra pound"), so forcing nowrap on every cell pushed the table off
 * the page. Where a single figure must be held on one line, mark it .nw. */
.working-table td .nw,
.working-table td.nw { white-space: nowrap; }

.working-table th {
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: .68rem;
  letter-spacing: .06em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--ink-faded, #8B8270);
  font-weight: 500;
}

.working-table td:last-child,
.working-table th:last-child { padding-right: 0; }

/* Source line. Every figure on the page is traceable to a GOV.UK page, and
 * saying so is the cheapest trust signal available. */
.working-source {
  font-size: .85rem;
  color: var(--ink-muted, #5A5347);
  margin: 1rem 0 0;
}

.working-source a { color: var(--orange-deep, #B8431A); }

/* Static heading -------------------------------------------------------- *
 * Present in the HTML for a no-JS visitor and for crawlers. flow.js removes
 * it once the interactive flow has mounted, so the two never coexist. On the
 * self-styled calculator pages there is no flow and it simply stays. */

.static-intro { margin: 0 0 2rem; }

.static-intro h1 {
  font-family: var(--font-display, Newsreader, Georgia, serif);
  font-size: clamp(1.9rem, 5.2vw, 2.55rem);
  line-height: 1.14;
  margin: 0 0 .75rem;
  color: var(--ink, #141414);
}

.static-intro .lede {
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ink-2, #2A2724);
  margin: 0;
  max-width: 34rem;
}

/* Related tools ---------------------------------------------------------- *
 * Sits below the working, so it reads as the next step once someone has their
 * answer rather than an invitation to leave mid-calculation.
 *
 * Set as a plain list of links, not cards. BRAND.md's subtraction principle
 * applies hardest here: a row of bordered, shadowed cards would make the exit
 * louder than the tool, and this block is the least important thing on the
 * page to a human even though it is among the most important to a crawler.
 * Restraint is the whole design. */

.tool-related {
  max-width: 46rem;
  margin: 3rem auto 0;
  padding: 0 1.5rem;
}

.related-head {
  font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faded, #8B8270);
  margin: 0 0 .35rem;
}

.tool-related ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tool-related li { border-top: 1px solid var(--rule-soft, #B3A887); }
.tool-related li:last-child { border-bottom: 1px solid var(--rule-soft, #B3A887); }

.tool-related a {
  display: block;
  padding: .95rem 0;
  text-decoration: none;
  color: var(--ink, #141414);
}

.tool-related a:hover .related-name { color: var(--orange-deep, #B8431A); }

.tool-related a:focus-visible {
  outline: 2px solid var(--orange, #DF5911);
  outline-offset: 3px;
}

.related-name {
  display: block;
  font-family: var(--font-display, Newsreader, Georgia, serif);
  font-size: 1.12rem;
  line-height: 1.3;
}

.related-blurb {
  display: block;
  font-size: .93rem;
  line-height: 1.5;
  color: var(--ink-muted, #5A5347);
  margin-top: .12rem;
}

.related-all {
  margin: 1rem 0 0;
  font-size: .92rem;
}

.related-all a {
  color: var(--orange-deep, #B8431A);
  text-underline-offset: 2px;
}

@media (max-width: 34rem) {
  .tool-working { margin-top: 2.75rem; }
  .tool-working summary { font-size: 1.04rem; }
  .working-body { padding-left: 0; }
  .tool-related { margin-top: 2.5rem; }
  .related-name { font-size: 1.04rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tool-working summary::before { transition: none; }
}
