/*
 * Nexus forms block, on the Nexus Foundry UI/UX kit (docs/design/NEXUS_FOUNDRY_UI_UX_KIT.md §2, §5, §15.6, §15.7).
 * The wrapper carries the kit scope `.nxn` (assets/kit/nexus-kit.css: tokens for dark, light and auto, the
 * IBM Plex families, and the primitives .nf-ui-field, .nf-ui-label, .nf-ui-btn, .nf-ui-banner, .nf-ui-card,
 * .nf-ui-dot, .nf-ui-meta, .nf-ui-title). This file only lays the form out: one column, labels above, "(required)"
 * in the label, errors under the field in 12px critical text, 5px radius, hairlines, no shadow, no tint, no
 * gradient. Colours come from the --nx-* tokens only; no literal colour or font size.
 */

.nxn.nxf-root.nxf-form {
  --nxf-form-ink: var(--nx-text-primary);
  --nxf-form-body: var(--nx-text-secondary);
  --nxf-form-muted: var(--nx-text-muted);
  --nxf-form-canvas: var(--nx-bg-canvas);
  --nxf-form-surface: var(--nx-bg-surface);
  --nxf-form-line: var(--nx-border-hairline-strong);
  --nxf-form-hairline: var(--nx-border-hairline);
  --nxf-form-accent: var(--nx-accent);
  --nxf-form-accent-ink: var(--nx-primary-ink);
  --nxf-form-critical: var(--nx-critical);
  --nxf-form-focus: var(--nx-focus);
  --nxf-form-gap: var(--nx-space-5);
  --nxf-form-gap-s: var(--nx-space-2);
  --nxf-form-radius: var(--nx-radius-md);
  max-inline-size: 100%;
  color: var(--nxf-form-body);
  background: transparent;
  font-family: var(--nx-font-sans);
  font-size: var(--nx-text-sm);
  line-height: var(--nx-leading-normal);
}

.nxf-form .nxf-form__form {
  display: grid;
  gap: var(--nxf-form-gap);
  max-inline-size: 100%;
}

.nxf-form .nxf-form__title,
.nxf-form .nxf-form__section-title,
.nxf-form .nxf-form__summary-title {
  margin: 0;
  font-size: var(--nx-text-md);
}

.nxf-form .nxf-form__required-note,
.nxf-form .nxf-field__help,
.nxf-form .nxf-form__step {
  margin: 0;
  color: var(--nxf-form-muted);
  font-size: var(--nx-text-xs);
}

.nxf-form .nxf-form__page,
.nxf-form .nxf-field__group,
.nxf-form .nxf-repeater__row {
  margin: 0;
  padding: var(--nxf-form-gap);
  border: 1px solid var(--nxf-form-hairline);
  border-radius: var(--nxf-form-radius);
  display: grid;
  gap: var(--nxf-form-gap);
  min-inline-size: 0;
}

.nxf-form .nxf-form__page-title,
.nxf-form .nxf-repeater__legend {
  padding-inline: var(--nxf-form-gap-s);
  font-weight: 500;
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-field {
  display: grid;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-field[hidden],
.nxf-form [hidden] {
  display: none !important;
}

.nxf-form .nxf-field__label {
  font-weight: 500;
  font-size: var(--nx-text-sm);
  color: var(--nxf-form-body);
}

.nxf-form .nxf-field__required {
  font-weight: 400;
  color: var(--nxf-form-muted);
}

.nxf-form .nxf-field__input {
  inline-size: 100%;
  min-block-size: var(--nxf-touch);
}

.nxf-form .nxf-field__input[aria-invalid="true"],
.nxf-form [aria-invalid="true"] {
  border-color: var(--nxf-form-critical);
}

.nxf-form .nxf-field__choice {
  display: flex;
  align-items: flex-start;
  gap: var(--nxf-form-gap-s);
  min-block-size: var(--nxf-touch);
}

/* the box itself is the estate control standard (.nx-check, .nx-radio; kits/controls, block at the end of this file) */
.nxf-form .nxf-field__choice input {
  margin: 1px 0 0;
}

.nxf-form .nxf-field__error {
  margin: 0;
  color: var(--nxf-form-critical);
  font-size: var(--nx-text-xs);
  font-weight: 400;
}

.nxf-form .nxf-field__output {
  font-variant-numeric: tabular-nums;
  font-size: var(--nx-text-md);
}

.nxf-form .nxf-form__summary {
  display: block;
  padding: var(--nx-space-3) var(--nx-space-4);
  border-radius: var(--nxf-form-radius);
}

.nxf-form .nxf-form__summary-list {
  margin: var(--nxf-form-gap-s) 0 0;
}

.nxf-form .nxf-form__summary-list a {
  color: var(--nxf-form-ink);
  text-decoration: underline;
}

.nxf-form .nxf-form__progress {
  display: grid;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-form__bar {
  inline-size: 100%;
  block-size: 2px;
  appearance: none;
  border: 0;
  border-radius: 0;
  background: var(--nxf-form-hairline);
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-form__bar::-webkit-progress-bar {
  background: var(--nxf-form-hairline);
}

.nxf-form .nxf-form__bar::-webkit-progress-value {
  background: var(--nxf-form-ink);
}

.nxf-form .nxf-form__bar::-moz-progress-bar {
  background: var(--nxf-form-ink);
}

.nxf-form .nxf-form__nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-form__button:disabled {
  cursor: progress;
}

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

.nxf-form .nxf-signature__pad {
  inline-size: 100%;
  block-size: auto;
  aspect-ratio: 15 / 4;
  color: var(--nxf-form-ink);
  background: var(--nxf-form-surface);
  border: 1px dashed var(--nxf-form-line);
  border-radius: var(--nxf-form-radius);
  touch-action: none;
}

.nxf-form .nxf-form__hp {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.nxf-form .nxf-visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Field library: matrix and Likert, ranking, rating, address, save and resume. Logical properties only, so the
   layout mirrors in right-to-left locales. */
.nxf-form .nxf-matrix__scroll {
  overflow-x: auto;
  max-inline-size: 100%;
}

.nxf-form .nxf-matrix__table {
  inline-size: 100%;
  border-collapse: collapse;
}

.nxf-form .nxf-matrix__table th,
.nxf-form .nxf-matrix__table td {
  padding: var(--nxf-form-gap-s);
  border-block-end: 1px solid var(--nxf-form-line);
  text-align: center;
  vertical-align: middle;
}

.nxf-form .nxf-matrix__table th[scope="row"] {
  text-align: start;
  font-weight: 600;
}

.nxf-form .nxf-matrix__table input[type="radio"] {
  margin: 0;
}

.nxf-form .nxf-ranking__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(8ch, max-content);
  align-items: center;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-rating__choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-rating__ends {
  display: flex;
  justify-content: space-between;
  margin: 0;
  color: var(--nxf-form-muted);
  font-size: var(--nx-text-xs);
}

.nxf-form .nxf-address {
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.nxf-form .nxf-address > legend,
.nxf-form .nxf-address > .nxf-field__help,
.nxf-form .nxf-address > .nxf-field__error {
  grid-column: 1 / -1;
}

.nxf-form .nxf-address__part {
  display: grid;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-form__resume {
  display: grid;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-form__resume-open {
  display: grid;
  gap: var(--nxf-form-gap-s);
}

.nxf-form .nxf-form__resume-open summary {
  min-block-size: var(--nxf-touch);
  cursor: pointer;
}

/* Quiz result and the editing screen. */
.nxf-form .nxf-form__result {
  display: grid;
  gap: var(--nxf-form-gap-s);
  padding: var(--nxf-form-gap);
  border: 1px solid var(--nxf-form-hairline);
  border-radius: var(--nxf-form-radius);
}

.nxf-form .nxf-form__result-message {
  margin: 0;
  font-size: var(--nx-text-md);
  font-weight: 500;
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-form__result-score {
  margin: 0;
  color: var(--nxf-form-muted);
  font-variant-numeric: tabular-nums;
}

.nxf-form .nxf-form__edit-note {
  margin: 0;
  padding: var(--nxf-form-gap-s) var(--nxf-form-gap);
  background: var(--nxf-form-surface);
  border: 1px solid var(--nxf-form-line);
  border-radius: var(--nxf-form-radius);
}

.nxf-form .nxf-form__edit-list {
  display: grid;
  gap: var(--nxf-form-gap-s);
  margin: 0;
  padding-inline-start: var(--nxf-form-gap);
}

/* The conversational layout: one question at a time, with room to read it. */
.nxf-form--conversational .nxf-form__page {
  padding: 0;
  border: 0;
  min-block-size: 14rem;
  align-content: start;
}

.nxf-form--conversational .nxf-form__bar {
  block-size: 2px;
}

.nxf-form--conversational .nxf-form__step {
  font-weight: 600;
}

.nxf-form--conversational .nxf-field__label {
  font-size: var(--nx-text-md);
}

.nxf-form--conversational .nxf-field__input {
  min-block-size: calc(var(--nxf-touch) * 1.25);
  font-size: var(--nx-text-md);
}

.nxf-form--conversational .nxf-field__choice {
  padding-block: var(--nxf-form-gap-s);
}

.nxf-form--conversational .nxf-form__nav {
  position: sticky;
  inset-block-end: 0;
  padding-block: var(--nxf-form-gap-s);
  background: var(--nxf-form-canvas);
}

@media (prefers-reduced-motion: reduce) {
  .nxf-form * {
    transition: none;
    animation: none;
  }
}

/* Kit form element (§15.6): textarea, choices, outcome and refusal. */
.nxf-form textarea.nxf-field__input {
  padding-block: var(--nx-space-2);
  line-height: var(--nx-leading-normal);
}

.nxf-form .nxf-field__group {
  padding: 0;
  border: 0;
}

.nxf-form .nxf-field__choice label {
  color: var(--nxf-form-body);
}

.nxf-form .nxf-form__title {
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-form__required-note {
  color: var(--nxf-form-muted);
  font-size: var(--nx-text-xs);
}

.nxf-form .nxf-form__summary-title {
  margin: 0 0 var(--nx-space-1);
  font-size: var(--nx-text-sm);
  font-weight: 500;
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-form__refusal {
  align-items: flex-start;
}

.nxf-form .nxf-form__refusal p {
  margin: 0;
}

.nxf-form .nxf-form__refusal svg {
  flex: none;
  margin-block-start: 0.125rem;
  color: var(--nx-caution);
}

.nxf-form .nxf-form__refusal code {
  font-family: var(--nx-font-mono);
}

.nxf-form .nxf-form__outcome {
  display: grid;
  gap: var(--nx-space-2);
  padding: var(--nx-space-5);
}

.nxf-form .nxf-form__outcome[hidden] {
  display: none;
}

.nxf-form .nxf-form__outcome p {
  margin: 0;
}

.nxf-form .nxf-form__outcome-state {
  display: inline-flex;
  align-items: center;
  gap: var(--nx-space-2);
  color: var(--nx-positive);
  font-weight: 500;
}

.nxf-form .nf-ui-dot[data-tone="positive"] {
  background: var(--nx-positive);
}

.nxf-form .nxf-form__outcome-text {
  color: var(--nxf-form-ink);
}

.nxf-form .nxf-form__outcome-boundary {
  color: var(--nxf-form-muted);
  font-size: var(--nx-text-xs);
}

.nxf-form .nxf-form__again {
  margin: var(--nx-space-3) 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .nxf-form * {
    transition: none;
  }
}

/*
 * The inbox: the status page ([nexus_form_status]) and the list of request pages ([nexus_form_links]). They carry no
 * script, so they cannot mirror the page's colour switch: each draws its own surface, which keeps its text at AA
 * contrast whatever the page behind it. Links inside running text are underlined; list links are at least 24px high.
 */
.nxn.nxf-root.nxf-status,
.nxn.nxf-links {
  padding: var(--nx-space-5);
  border: 1px solid var(--nx-border-hairline);
  border-radius: var(--nx-radius-md);
  background: var(--nx-bg-surface);
  color: var(--nx-text-secondary);
  max-inline-size: 100%;
}
.nxn.nxf-links {
  font-family: var(--nx-font-sans);
}
.nxf-form .nxf-form__outcome-follow a,
.nxn.nxf-links a {
  color: var(--nx-accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.nxn.nxf-links .nxf-links__list {
  margin: 0 0 var(--nx-space-4);
  padding-inline-start: var(--nx-space-5);
}
.nxn.nxf-links .nxf-links__list a {
  display: inline-block;
  min-block-size: 1.5rem;
  padding-block: var(--nx-space-1);
}
.nxn.nxf-root.nxf-status .nxf-status__facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--nx-space-1) var(--nx-space-4);
  margin: 0 0 var(--nx-space-4);
}
.nxn.nxf-root.nxf-status .nxf-status__facts dt {
  color: var(--nx-text-muted);
}
.nxn.nxf-root.nxf-status .nxf-status__facts dd {
  margin: 0;
  color: var(--nx-text-primary);
}
.nxn.nxf-root.nxf-status .nxf-status__replies {
  margin: 0;
  padding-inline-start: var(--nx-space-5);
}
.nxn.nxf-root.nxf-status .nxf-status__reply {
  color: var(--nx-text-primary);
  white-space: normal;
}

/* nx-controls:begin */
.nx-switch, .nx-check, .nx-radio {
  --_ink: var(--nx-ctl-ink, var(--nx-text-primary, CanvasText));
  --_canvas: var(--nx-ctl-canvas, var(--nx-bg-canvas, Canvas));
  --_line: var(--nx-ctl-line, var(--nx-border-hairline-strong, GrayText));
  --_hover: var(--nx-ctl-hover, var(--nx-bg-hover, transparent));
  --_focus: var(--nx-ctl-focus, var(--nx-focus, Highlight));
  --_crit: var(--nx-ctl-critical, var(--nx-critical, CanvasText));
  --_r: var(--nx-ctl-radius, var(--nx-radius-sm, 5px));
  --_rs: var(--nx-ctl-radius-xs, var(--nx-radius-xs, 4px));
  --_fast: var(--nx-ctl-fast, var(--nx-motion-fast, 120ms));
  --_ease: var(--nx-ctl-ease, cubic-bezier(.2, 0, 0, 1));
}

/* ---- checkbox: 18px box, 4px corners, a drawn tick; indeterminate is a bar. */
input[type="checkbox"].nx-check,
input[type="radio"].nx-radio {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: inline-block;
  flex: none;
  box-sizing: border-box;
  inline-size: 18px;
  block-size: 18px;
  min-inline-size: 18px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--_line);
  border-radius: var(--_rs);
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  vertical-align: middle;
  transition: background-color var(--_fast) var(--_ease), border-color var(--_fast) var(--_ease);
}
input[type="checkbox"].nx-check::before {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 5px;
  inline-size: 5px;
  block-size: 9px;
  margin: 0;
  border: solid var(--_canvas);
  border-width: 0 2px 2px 0;
  background: none;
  transform: rotate(45deg) scale(0);
  transition: transform var(--_fast) var(--_ease);
  filter: none;
}
input[type="checkbox"].nx-check:is(:checked, :indeterminate) {
  background: var(--_ink);
  border-color: var(--_ink);
}
input[type="checkbox"].nx-check:checked::before {
  content: "";
  transform: rotate(45deg) scale(1);
}
input[type="checkbox"].nx-check:indeterminate::before {
  content: "";
  inset-block-start: 7px;
  inset-inline-start: 3px;
  inline-size: 10px;
  block-size: 0;
  border-width: 2px 0 0;
  transform: none;
}
/* radio: the one circle in the set (a dot, as in the kit) */
input[type="radio"].nx-radio { border-radius: 50%; }
input[type="radio"].nx-radio::before {
  content: "";
  position: absolute;
  inset: 3px;
  margin: 0;
  inline-size: auto;
  block-size: auto;
  border-radius: 50%;
  background: var(--_canvas);
  transform: scale(0);
  transition: transform var(--_fast) var(--_ease);
  line-height: 0;
}
input[type="radio"].nx-radio:checked { background: var(--_ink); border-color: var(--_ink); }
input[type="radio"].nx-radio:checked::before { content: ""; transform: scale(1); }
input.nx-check:hover:not(:disabled),
input.nx-radio:hover:not(:disabled) { border-color: var(--_ink); }
input.nx-check:focus-visible,
input.nx-radio:focus-visible { outline: 2px solid var(--_focus); outline-offset: 2px; }
input.nx-check:disabled,
input.nx-radio:disabled { opacity: .45; cursor: not-allowed; }
input.nx-check[aria-invalid="true"],
input.nx-radio[aria-invalid="true"] { border-color: var(--_crit); }
/* the labelled row: box, then text; the whole row is the target */
.nx-ctl { display: flex; align-items: flex-start; gap: 10px; min-block-size: 24px; color: var(--nx-ctl-ink, var(--nx-text-primary, CanvasText)); font: inherit; line-height: 1.4; cursor: pointer; }
.nx-ctl > :is(.nx-check, .nx-radio) { margin-block-start: 1px; }
.nx-ctl__hint { display: block; color: var(--nx-ctl-muted, var(--nx-text-muted, GrayText)); font-size: .8125em; }

/* ---- switch: an input[type=checkbox][role=switch] or a button[role=switch][aria-checked]. Off = line track and
   canvas thumb; on = ink track and canvas-coloured thumb; mixed = thumb centred over a half-ink track. */
:is(input, button).nx-switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: inline-block;
  flex: none;
  box-sizing: border-box;
  inline-size: 40px;
  min-inline-size: 40px;
  block-size: 24px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--_line);
  border-radius: var(--_r);
  background: var(--_line);
  color: inherit;
  box-shadow: none;
  cursor: pointer;
  vertical-align: middle;
  transition: background-color var(--_fast) var(--_ease), border-color var(--_fast) var(--_ease);
}
:is(input, button).nx-switch::before {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  inline-size: 18px;
  block-size: 18px;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: var(--_canvas);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--_ink) 28%, transparent);
  transform: none;
  filter: none;
  transition: inset-inline-start var(--_fast) var(--_ease), background-color var(--_fast) var(--_ease);
}
/* a 44px-tall target around the 24px track (WCAG 2.5.8) without growing the layout */
:is(input, button).nx-switch::after {
  content: "";
  position: absolute;
  inset: -10px -4px;
}
:is(input, button).nx-switch:is(:checked, [aria-checked="true"]) {
  background: var(--_ink);
  border-color: var(--_ink);
}
:is(input, button).nx-switch:is(:checked, [aria-checked="true"])::before {
  content: "";
  inset-inline-start: calc(100% - 20px);
  background: var(--_canvas);
  transform: none;
}
:is(input, button).nx-switch:is([aria-checked="mixed"], :indeterminate) {
  background: color-mix(in srgb, var(--_ink) 45%, var(--_line));
  border-color: color-mix(in srgb, var(--_ink) 45%, var(--_line));
}
:is(input, button).nx-switch:is([aria-checked="mixed"], :indeterminate)::before { inset-inline-start: calc(50% - 10px); }
:is(input, button).nx-switch:hover:not(:disabled) { border-color: var(--_ink); }
:is(input, button).nx-switch:focus-visible { outline: 2px solid var(--_focus); outline-offset: 2px; }
:is(input, button).nx-switch:is(:disabled, [aria-disabled="true"]) { opacity: .45; cursor: not-allowed; }
:is(input, button).nx-switch[aria-invalid="true"] { border-color: var(--_crit); }
/* compact: 34x20 */
:is(input, button).nx-switch.nx-switch--sm { inline-size: 34px; min-inline-size: 34px; block-size: 20px; }
:is(input, button).nx-switch.nx-switch--sm::before { inline-size: 14px; block-size: 14px; }
:is(input, button).nx-switch.nx-switch--sm:is(:checked, [aria-checked="true"])::before { inset-inline-start: calc(100% - 16px); }
:is(input, button).nx-switch.nx-switch--sm:is([aria-checked="mixed"], :indeterminate)::before { inset-inline-start: calc(50% - 8px); }

@media (prefers-reduced-motion: reduce) {
  .nx-switch, .nx-switch::before, .nx-check, .nx-check::before, .nx-radio, .nx-radio::before { transition: none; }
}
@media (forced-colors: active) {
  :is(input, button).nx-switch { border-color: CanvasText; }
  :is(input, button).nx-switch:is(:checked, [aria-checked="true"]) { background: Highlight; border-color: Highlight; }
  :is(input, button).nx-switch::before { background: ButtonText; }
  input.nx-check:checked,
  input.nx-radio:checked { background: Highlight; border-color: Highlight; }
}
/* nx-controls:end */
