/* Tool pages and the home entry. Loaded only on sites with tools; builds on styles.css tokens. */

.tool-entries {
  margin-block: clamp(1rem, 2vw, 1.75rem);
}

.tool-entries h2 {
  margin-bottom: 0.6rem;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  letter-spacing: -0.03em;
}

.tool-entry-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: 0.9rem;
  padding: 0;
  list-style: none;
}

.tool-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2rem;
  align-items: center;
  gap: 0.35rem 1rem;
  min-height: 44px;
  height: 100%;
  padding: clamp(1rem, 1.8vw, 1.4rem) clamp(1rem, 2vw, 1.6rem);
  border-radius: 0.55rem;
  background: var(--wash);
  color: var(--ink);
  text-decoration: none;
}

.tool-entry-title {
  color: var(--heading);
  font: 700 clamp(1.35rem, 2vw, 1.8rem)/1.12 var(--serif);
  letter-spacing: -0.025em;
}

.tool-entry-summary { grid-column: 1; }

.tool-entry svg {
  grid-column: 2;
  grid-row: 1 / span 2;
  color: var(--green);
}

.tool-entry:hover .tool-entry-title, .tool-entry:focus-visible .tool-entry-title { text-decoration: underline; }

.tool-layout {
  max-width: 56rem;
  margin-top: clamp(1.25rem, 2.3vw, 2rem);
  font-size: clamp(1rem, 1.38vw, 1.125rem);
}

.tool-layout > .reading-section + .tool, .tool + .reading-section, .tool + .tool-meta { margin-top: clamp(1.25rem, 2.25vw, 2rem); }

/* On a tool page the note on artificial intelligence and the link to the sources stand under the tool, in full size. */
.tool-meta { font-size: 1rem; }

.tool-meta + .reading-section { margin-top: clamp(1rem, 2vw, 1.5rem); }

/* The page keeps the control under the reader's finger itself (core.mjs), so the browser's own scroll anchoring is off,
   and a field scrolled into view is not hidden under the narrow answer line. */
:root:has(.tool) { overflow-anchor: none; scroll-padding-top: 4.5rem; }

@media (max-width: 37.5rem) {
  /* A shorter title on a phone, so the answer stands on the first screen. */
  .tool-page .hero { padding-block: 0.9rem 1rem; }

  .tool-page .hero h1 { font-size: clamp(1.75rem, 7.6vw, 2.35rem); line-height: 1.05; }
}

.tool {
  padding: clamp(1rem, 2vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--field);
}

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

.tool-fields {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
  gap: 1rem clamp(0.8rem, 2vw, 1.4rem);
  align-items: start;
  min-width: 0;
  padding: 0;
  border: 0;
}

.tool-repeat, .tool-group, .tool-checks {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 0.75rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.tool-repeat legend, .tool-group legend, .tool-checks legend {
  padding: 0;
  color: var(--heading);
  font-weight: 650;
}

.tool-repeat-rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr));
  gap: 0.8rem;
  margin-top: 0.5rem;
}

.tool-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
  gap: 0.8rem;
}

.tool-group > legend { margin-bottom: 0.5rem; }

.tool-check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
}

.tool-check input { width: 1.25rem; height: 1.25rem; accent-color: var(--green); }

.field-help {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.4;
}

.tool-group > .field-help, .tool-checks > .field-help, .tool-repeat > .field-help { grid-column: 1 / -1; }

/* Text in a tool is at least 16 px: labels, errors and figure labels are raised from the shared form styles. */
.tool .field label, .tool .field-error, .tool legend { font-size: 1rem; }

/* A label with its »?« help button on one line. */
.tool-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.tool .tool-label-row label { margin-bottom: 0; }

.tool-help-toggle {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--field);
  color: var(--green);
  font: 700 1.1rem/1 var(--sans);
  cursor: pointer;
}

.tool-help-toggle[aria-expanded="true"] { border-color: var(--green); background: var(--wash); }

/* A fieldset's »?« sits on the line of its legend. The legend is floated, so it is laid out with the fieldset's content
   instead of in its border, and the button is placed against the top of that content, beside the legend and never over
   the first control. The legend is at least as tall as the button. */
.tool-group, .tool-checks, .tool-repeat, .tool-choice { position: relative; }

:is(.tool-group, .tool-checks, .tool-repeat, .tool-choice) > legend:not(.sr-only) {
  float: left;
  grid-column: 1 / -1;
  width: 100%;
}

:is(.tool-group, .tool-checks, .tool-repeat, .tool-choice) > legend:not(.sr-only) ~ :not(.tool-help-toggle) { clear: both; }

:is(.tool-group, .tool-checks, .tool-repeat, .tool-choice):has(> .tool-help-toggle) > legend:not(.sr-only) {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding-right: 3.25rem;
}

:is(.tool-group, .tool-checks, .tool-repeat, .tool-choice) > .tool-help-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0;
}

.tool-choice > .tool-help-toggle { top: 0; }

/* A start value that is only an example, such as a price, carries a word beside its label until the reader changes it. */
.tool-field-example {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0 0.5rem;
  border-radius: 0.3rem;
  background: var(--wash);
  color: var(--heading);
  font-weight: 650;
}

/* A number with a minus and a plus button. */
.tool-stepper {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 0.4rem;
}

.tool-stepper input { text-align: center; }

.tool-step {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--green);
  border-radius: 0.35rem;
  background: var(--field);
  color: var(--green);
  font: 700 1.4rem/1 var(--sans);
  cursor: pointer;
}

.tool-step:hover { background: var(--wash); }

/* One choice among 2-5, shown as large buttons. The radio button fills its button, so the whole button is the target. */
.tool-choice {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.tool-choice > legend {
  margin-bottom: 0.5rem;
  padding-left: 0;
  color: var(--heading);
  font-weight: 650;
}

.tool-choice-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  gap: 0.5rem;
}

.tool-choice-option {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 3.25rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  background: var(--field);
  cursor: pointer;
}

.tool-choice-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* Two buttons side by side on a phone: a long word is hyphenated, never cut at a random letter. */
.tool-choice-label { color: var(--heading); font-weight: 650; overflow-wrap: normal; hyphens: auto; }

.tool-choice-detail { color: var(--muted); }

.tool-choice-option:hover { border-color: var(--green); }

.tool-choice-option:has(input:checked) {
  border-color: var(--green);
  background: var(--wash);
  box-shadow: inset 0 0 0 2px var(--green);
}

.tool-choice-option:has(input:focus-visible) {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

/* »Finjustér« and »Se hele beregningen«: closed until the reader opens them. */
.tool-fold {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
}

.tool-fold > summary, .tool-details > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--green);
  font-weight: 650;
  cursor: pointer;
}

.tool-fold > .tool-group { padding-top: 0.25rem; border-top: 0; }

/* The browser's own marker goes with display: flex, so the fold draws its own: an arrow that turns when open. */
.tool-fold > summary::before, .tool-details > summary::before {
  content: '▸' / '';
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  margin-right: 0.15em;
  line-height: 1;
}

.tool-fold[open] > summary::before, .tool-details[open] > summary::before { transform: rotate(90deg); }

.tool-fold > summary::-webkit-details-marker, .tool-details > summary::-webkit-details-marker { display: none; }

.field select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--muted);
  border-radius: 0.35rem;
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

.tool-result {
  box-sizing: border-box;
  padding: 1rem 1.25rem;
  border-radius: 0.55rem;
  background: var(--wash);
}

.tool-result > p:first-child { color: var(--green); font-weight: 650; }

.tool-figures {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr));
  gap: 0.75rem 1.25rem;
  margin: 0;
}

.tool-figures dt { color: var(--muted); font-size: 1rem; }

.tool-figures dd {
  margin: 0.1rem 0 0;
  color: var(--heading);
  font: 700 clamp(1.3rem, 2vw, 1.65rem)/1.15 var(--serif);
}

.tool-warning {
  margin-top: 1rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--error);
  color: var(--error);
  font-weight: 600;
}

.tool-result .table-region { background: var(--field); }

/* Result tables keep whole words; a table wider than the column scrolls inside its focusable region. */
.tool-result .table-region :is(th, td) {
  overflow-wrap: normal;
  hyphens: manual;
}

@media (max-width: 37.5rem) {
  .tool-result .table-region :is(th, td) { padding: 0.45rem 0.5rem; }
}

.tool-result caption {
  padding: 0.5rem 0.8rem;
  color: var(--heading);
  font-weight: 650;
  text-align: left;
}

.tool-list { margin-top: 1rem; }

.tool-list h3 { font-size: 1.2rem; letter-spacing: -0.01em; }

.tool-list ul { margin-top: 0.4rem; padding-left: 1.35rem; }

.tool-result > p + p, .tool-result > * + p:not(.tool-warning) { margin-top: 0.8rem; }

/* The answer: one big figure with its label and one sentence; the rest of the result folds away. */
.tool-example-mark { margin-bottom: 0.35rem; }

.tool-example-badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 0.3rem;
  background: var(--field);
  color: var(--heading);
  font-weight: 700;
}

/* A blank or half-written field: the last answer stays in place, greyed out, under one line that says what to do. */
.tool-message { color: var(--green); font-weight: 650; }

.tool-stale { margin-top: 0.6rem; opacity: 0.4; }

.tool-result > .tool-stale:first-child { margin-top: 0; }

/* The narrow answer line: it takes no room in the page and is pinned to the top of the screen while it shows. */
.tool-sticky {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 0;
}

.tool-sticky-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--green);
  border-radius: 0 0 0.5rem 0.5rem;
  background: var(--wash);
  color: var(--heading);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
}

.tool-sticky-bar::after { content: '↑' / ''; margin-left: auto; color: var(--green); }

.tool-sticky-bar:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

.tool-headline-label { color: var(--muted); }

.tool-headline {
  margin-top: 0.1rem;
  color: var(--heading);
  font: 700 clamp(2.25rem, 7vw, 3.25rem)/1.05 var(--serif);
  letter-spacing: -0.02em;
}

.tool-headline-unit { font-size: 0.55em; }

.tool-headline-text { margin-top: 0.5rem; font-size: clamp(1.05rem, 1.6vw, 1.2rem); }

.tool-answer .tool-warning { margin-top: 0.75rem; }

.tool-notes { margin: 0.75rem 0 0; padding-left: 1.25rem; }

.tool-details { margin-top: 1rem; border-top: 1px solid var(--line); }

.tool-details-body > * + * { margin-top: 0.8rem; }

.tool-details-body > .tool-figures { margin-top: 0.25rem; }

.tool-actions { margin-top: 0.75rem; }

/* The print button under the answer, at the same distance whether the answer is current or greyed out. */
.tool-stale > .tool-actions { margin-top: 0.8rem; }

.tool-print {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--green);
  border-radius: 0.35rem;
  background: var(--field);
  color: var(--green);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.tool-print:hover { background: var(--wash); }

.tool-noscript { margin-top: 0.75rem; color: var(--muted); }

@media print {
  .skip-link, .site-header nav, .site-footer nav, .tool-actions, .tool-noscript, .field-error, .field-help, .tool-help-toggle, .tool-step, .tool-sticky { display: none; }

  .tool { padding: 0; border: 0; }

  .tool-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem 0.8rem; }

  .tool-repeat-rows { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .field input, .field select { min-height: 0; padding: 0.15rem 0.3rem; border-color: var(--line); }

  .tool-result { padding: 0; background: none; break-inside: avoid; }

  .tool-result .table-region { overflow: visible; break-inside: avoid; }

  .tool-result table { font-size: 9pt; }

  .tool-layout { max-width: none; }
}
