/* ============================================================================
   DevPlan — client questionnaire styles
   Tokens only (see styles.css :root). No literal colours anywhere.
   Mobile first: designed at 390px; tap targets >= var(--tap).

   THE SCREEN IS THE CARD.
   There is one question in view at a time, so a border, a shadow or a raised
   surface around it communicates nothing and only adds weight. Questions are
   separated by a hairline and by space. Card treatment is kept for the things
   that genuinely need separating from their neighbours: the round hub at the
   top, an attached document, a recorded answer.

   Six spacing values, declared once on .qn-q and used everywhere below. No
   ad-hoc margins — that is what makes a 62-question column read as one rhythm.
   ========================================================================= */

/* ------------------------------------------------------- project switcher */
/* Only drawn when the client holds more than one engagement. Sits above the
   heading: the segment is the project's NAME, the heading under it is the legal
   entity, so which engagement is on screen is never in doubt. */

.tn-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  margin: 0 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.tn-switch__btn {
  flex: 1 1 140px;      /* two segments side by side at 390px; wraps below that */
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 6px 12px;
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--speed) ease, color var(--speed) ease,
              border-color var(--speed) ease;
}
.tn-switch__btn:hover { color: var(--text); }
/* Same "this one is selected" idiom as the round chips: accent on accent-wash. */
.tn-switch__btn[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-wash);
  border-color: var(--accent);
}
.tn-switch__btn[aria-pressed="true"]:hover { color: var(--accent); }

/* -------------------------------------------------------- reading column -- */
/* One measure for the whole screen. A question column at 34rem under an 880px
   heading reads as two unrelated pages. */

#client-switch,
#client-heading,
#client-tabs,
.qn-top,
.qn-roundhead,
.qn-list {
  max-width: 34rem;
  margin-left: auto;
  margin-right: auto;
}

/* Room under the last question for the fixed Saved chip. */
.qn-list { padding-bottom: 76px; }

/* ------------------------------------------------- top card: progress + nav */
/* The round hub, not a per-question progress bar. Progress met BEFORE the work
   makes people price the effort that is left; this is met on arrival, once,
   and describes the round as a whole. */

.qn-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.qn-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.qn-ring {
  width: 56px;
  height: 56px;
  flex: none;
  transform: rotate(-90deg); /* progress starts at 12 o'clock */
}
.qn-ring__track,
.qn-ring__bar {
  fill: none;
  stroke-width: 5;
}
.qn-ring__track { stroke: var(--border); }
.qn-ring__bar {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset var(--speed) ease;
}

.qn-progress__main { font-weight: 650; }
.qn-req--done { color: var(--ok); }

/* Round chips scroll horizontally on narrow screens. */
.qn-rounds {
  display: flex;
  gap: 8px;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.qn-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-height: var(--tap);
  padding: 0 14px;
  font: inherit;
  font-weight: 600;
  text-wrap: nowrap; /* chips also size to max-content in the flex row */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--speed) ease, border-color var(--speed) ease;
}
.qn-chip:hover { background: var(--surface-sunk); }
.qn-chip--active {
  color: var(--accent);
  background: var(--accent-wash);
  border-color: var(--accent);
}
.qn-chip__count {
  font-size: .85rem;
  color: var(--text-faint);
}
.qn-chip--active .qn-chip__count { color: var(--accent); }
.qn-chip__closed {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-faint);
}

/* -------------------------------------------------------------- round head */

.qn-roundhead__title { margin-bottom: .2em; }
.qn-roundhead__blurb { margin: 0; }
.qn-roundhead .banner { margin-top: 10px; }

/* ---------------------------------------------------------- part sections */
/* A quiet divider with a count, not an accordion. No panel chrome, no fill, no
   shadow — the header is a hairline and two lines of restrained type, so eight
   of them stacked still read as one intake form rather than eight widgets.
   The header is also the position indicator: it sticks under the app chrome
   while its own questions scroll past, which costs no extra vertical space
   because it is a row that had to exist anyway. --qn-stick is the measured
   chrome height, published by client.js. */

.qn-part { margin: 28px 0 0; }        /* the only interstitial in the scale */
.qn-part:first-child { margin-top: 8px; }

.qn-part__h {
  position: sticky;
  top: var(--qn-stick, 67px);
  z-index: 3;                 /* over the questions, under the chrome (20) */
  margin: 0;
  font-size: 1rem;            /* not a UA h2: the parts below set their own */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Zero-height, no box: it exists only for the IntersectionObserver in
   client.js to watch. Must not be display:none — a hidden element never
   intersects anything. */
.qn-part__sentinel { height: 0; }

/* PINNED ------------------------------------------------------------------
   Unpinned, the header introduces a section and the eyebrow, title and
   "N required left" all earn their place. Pinned, it is answering "which part
   am I in" — and the reader already knows the answer, having just scrolled
   through it. Three stacked lines came to 92px, which on a 390x844 phone is a
   ninth of the screen permanently covering the questions. One line instead.
   The count stays: that is the part people actually re-check. */
.qn-part--stuck > .qn-part__h .qn-part__label,
.qn-part--stuck > .qn-part__h .qn-part__hint { display: none; }

.qn-part--stuck > .qn-part__h .qn-part__btn {
  min-height: 42px;
  padding: 4px 0;
}

/* One line means it has to be allowed to end in an ellipsis — but only here.
   In flow the title always wraps in full. */
.qn-part--stuck > .qn-part__h .qn-part__title {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.qn-part__btn {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 9px 0;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
}

.qn-part__caret {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
  transition: transform var(--speed) ease, color var(--speed) ease;
}
.qn-part--open .qn-part__caret {
  color: var(--accent);
  transform: rotate(180deg);
}

.qn-part__text { min-width: 0; }

.qn-part__label {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.qn-part__title {
  display: block;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.3;
  color: var(--text);
  overflow-wrap: anywhere;
}
.qn-part__hint {
  display: block;
  margin-top: 2px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.qn-part__meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;   /* the count must not jitter on 9 -> 10 */
  color: var(--text-faint);
}
.qn-part__tick {
  display: none;
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--ok);
}

/* Done is deliberately quiet: a tick, a dimmer title, and nothing else. There
   is nothing left to do in here, so it should stop asking to be looked at. */
.qn-part--done .qn-part__tick { display: block; }
.qn-part--done .qn-part__title { font-weight: 600; color: var(--text-muted); }
.qn-part--done .qn-part__count { color: var(--ok); }

.qn-part__panel { padding-top: 4px; }

/* ============================================================================
   ONE QUESTION
   Visible at rest: caption · question · hint · control · quick answer ·
   utility row. Everything else — the operator's reasoning, the comment box,
   the file picker, older versions of a document — is disclosed on demand.
   ========================================================================= */

.qn-q {
  --sp-1: 8px;      /* caption → label, label → hint */
  --sp-2: 12px;     /* hint → why, control → quick, utils → status */
  --sp-3: 16px;     /* quick → utils */
  --sp-4: 20px;     /* why → control */

  padding: 24px 0 28px;
  border-top: 1px solid var(--border);
  /* Anything that scrolls a question into view has to clear the sticky part
     header, or it lands under it. */
  scroll-margin-top: calc(var(--qn-stick, 67px) + 56px);
}
/* Matches both the first question of an open part and a question that belongs
   to no part at the top of the list — in either case the rule above it is the
   part hairline or nothing, and a second line would be a double rule. */
.qn-q:first-child { border-top: 0; padding-top: 12px; }

/* .qn-q--answered carries no styling on purpose — the check in the caption is
   the whole "this one is done" signal. It stays as a state hook so a future
   review screen can select answered questions without re-deriving it. */

/* A radio group needs a real fieldset; a single input does not. Both are laid
   out identically, and the legend must be told to behave like a block. */
.qn-q__fs {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.qn-q__head {
  display: block;
  width: 100%;
  padding: 0;
}

/* ------------------------------------------------------------- caption --- */

.qn-q__caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: .75rem;
  line-height: 1.4;
  letter-spacing: .02em;
  color: var(--text-faint);
}
.qn-q__code {
  font-family: var(--mono);
  font-weight: 600;
}
/* GOV.UK: mark the optional ones, never asterisk the required ones. */
.qn-q__optional { font-style: italic; }
.qn-q__done {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--ok);
}
.qn-q__donetick {
  flex: none;
  width: 14px;
  height: 14px;
}

/* ------------------------------------------------------- question text --- */

.qn-q__label {
  margin: var(--sp-1) 0 0;
  font-size: 1.3rem;          /* ~21px — the largest thing on the screen */
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
}
.qn-q__label label { display: block; cursor: pointer; }

.qn-q__hint {
  margin: var(--sp-1) 0 0;
  font-size: .875rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.qn-q__hint p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------- disclosures --- */
/* A quiet text affordance with a full var(--tap) hit area. The caret carries
   the only colour, so the row itself never competes with the question. */

.qn-disc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: var(--tap);
  margin: 0;
  padding: 0;
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
  transition: color var(--speed) ease;
}
.qn-disc:hover { color: var(--text); }
.qn-disc--filled { color: var(--text); }
.qn-disc--sm { font-size: .8125rem; }

.qn-disc__caret,
.qn-disc__glyph {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--accent);
}
.qn-disc__caret { transition: transform var(--speed) ease; }
.qn-disc--open .qn-disc__caret { transform: rotate(180deg); }

/* A glyph does not rotate, so an open glyph-disclosure says so with its label.
   Without this the only difference between open and closed is the panel, which
   is plain enough for a comment box and thin for a paragraph of help. */
.qn-disc--open { color: var(--text); }

.qn-disc__text {
  min-width: 0;
  overflow-wrap: anywhere;
}
/* Non-empty overrides collapsed: the closed row shows what is inside it. */
.qn-disc__peek { color: var(--text-muted); }
.qn-disc__edit {
  margin-left: 8px;
  font-weight: 600;
  color: var(--accent);
}

.qn-panel { margin: 0; }

.qn-why__body {
  margin: 0 0 var(--sp-2);
  padding: 12px 14px;
  font-size: .9rem;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
}
.qn-why__body p { margin: 0 0 .6em; }
.qn-why__body p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------- control -- */

.qn-q__control { margin-top: var(--sp-4); }

/* A quick answer takes the control's place but must not take it out of reach:
   the markup sets aria-disabled, never disabled, so it stays focusable and a
   screen-reader user can find it and overrule the chip. */
.qn-q__control--muted { opacity: .55; }

/* --------------------------------------------------------------- choices -- */
/* Full-bleed selectable rows, native radios, no dot at rest. Selection reads
   as weight + a check glyph + a fill, so it is never colour alone. */

.qn-opts {
  display: grid;
  gap: 8px;
}

.qn-optwrap { border-radius: 12px; }

.qn-opt {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 14px 16px;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--speed) ease, box-shadow var(--speed) ease,
              border-color var(--speed) ease;
}
.qn-opt:hover { background: var(--surface-2); }

/* The radio is REAL and stays in the accessibility tree — display:none would
   remove it and take single-tab-stop + arrow-key navigation with it. */
.qn-opt__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  clip-path: inset(50%);
  pointer-events: none;   /* the whole row is the target, never the 1px input */
}

.qn-opt__text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.qn-opt__check {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--accent);
  opacity: 0;
  transform: scale(.75);
  transition: opacity var(--speed) ease, transform var(--speed) ease;
}

/* Inset ring, not a border: selection costs zero layout shift. */
.qn-opt--on,
.qn-opt:has(.qn-opt__input:checked) {
  font-weight: 600;
  background: var(--accent-wash);
  border-color: transparent;
  box-shadow: inset 0 0 0 2px var(--accent);
}
.qn-opt--on:hover,
.qn-opt:has(.qn-opt__input:checked):hover { background: var(--accent-wash); }

.qn-opt--on .qn-opt__check,
.qn-opt:has(.qn-opt__input:checked) .qn-opt__check {
  opacity: 1;
  transform: none;
}

.qn-opt:has(.qn-opt__input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.qn-opt:has(.qn-opt__input:disabled) {
  cursor: not-allowed;
  opacity: .75;
}

/* The custom-answer option owns the highlight, so the text box it reveals
   visibly belongs to that choice rather than floating under the group. */
.qn-optwrap--custom.qn-optwrap--on,
.qn-optwrap--custom:has(.qn-opt__input:checked) {
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.qn-optwrap--custom.qn-optwrap--on > .qn-opt,
.qn-optwrap--custom:has(.qn-opt__input:checked) > .qn-opt {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.qn-opt__reveal {
  display: grid;
  grid-template-rows: 0fr;
  padding: 0 16px;
}
.qn-opt__reveal--open { grid-template-rows: 1fr; }
.qn-opt__revealin {
  min-height: 0;
  overflow: hidden;
  padding-bottom: 14px;
}
.qn-opt__reveallabel {
  display: block;
  margin: 0 0 6px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
@media (prefers-reduced-motion: no-preference) {
  .qn-opt__reveal { transition: grid-template-rows 160ms ease-out; }
}

/* ------------------------------------------------------- multi sub-fields -- */

.qn-sub + .qn-sub { margin-top: 12px; }
.qn-sub__label {
  display: block;
  margin-bottom: 6px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}

/* ----------------------------------------------------------- quick answers */

.qn-q__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: var(--sp-2);
}

/* 36px of ink so it reads as secondary, var(--tap) of target so it is still
   usable one-handed — the pseudo-element carries the extra height without
   pushing the layout around. */
.qn-quick {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin: 5px 0;
  padding: 0 14px;
  font: inherit;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--speed) ease, border-color var(--speed) ease,
              color var(--speed) ease;
}
.qn-quick::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: var(--tap);
  transform: translateY(-50%);
}
.qn-quick:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.qn-quick:disabled { opacity: .5; cursor: not-allowed; }
.qn-quick--on {
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-wash);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 .5px var(--accent);
}

/* --------------------------------------------------------- utility row --- */

.qn-q__utils {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 18px;
  margin-top: var(--sp-3);
}

/* Each disclosure panel is the immediate next sibling of the button that opens
   it, so activating the button leaves you ON the thing you opened. It claims a
   whole row of the wrap container, which puts it directly under its own button
   instead of squeezing in beside it. Closed panels are [hidden], take no space
   and force no line break, so at rest the row is still one line of actions. */
.qn-q__utils > .qn-panel {
  flex: 1 0 100%;
  margin-top: 4px;
}

/* Clearing is an interaction, not an answer — so it is a text button here and
   never a "None of the above" option in the group. */
.qn-clear {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0;
  font: inherit;
  font-size: .875rem;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.qn-clear:hover { color: var(--danger); }

/* ------------------------------------------------------------- comment --- */
/* Optional, on every question, and deliberately weightless: it must be easy to
   find and impossible to read as an obligation. */

.qn-note { margin: 0 0 var(--sp-2); }
.qn-note__label {
  display: block;
  margin: 0 0 4px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
.qn-note__hint {
  margin: 0 0 8px;
  font-size: .8125rem;
  line-height: 1.45;
  color: var(--text-muted);
}
.qn-note__field { min-height: 92px; }

/* ------------------------------------------------------------ attachments -- */

.qn-file { margin: 0 0 var(--sp-2); }
.qn-fileui { display: flex; }
.qn-upload { max-width: 100%; }

/* An attached file is an answer. It shows at rest, always — a document behind
   a disclosure is a document the client believes he never sent. */
.qn-docs:not(:empty) { margin-top: var(--sp-2); }

.qn-doc {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.qn-doc__icon {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  color: var(--ok);
}
.qn-doc__meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.qn-doc__name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.qn-doc__sub {
  font-size: .8125rem;
  color: var(--text-muted);
}

.qn-prev { padding-left: 30px; }
.qn-prev__row {
  padding: 3px 0;
  font-size: .8125rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------- status --- */
/* One polite live region per question: what the upload did, and what the last
   tap did. Empty at rest, and an empty block takes no height. */

.qn-q__status {
  margin: 0;
  font-size: .8125rem;
  line-height: 1.45;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.qn-q__status:not(:empty) { margin-top: var(--sp-2); }
.qn-q__status--ok { color: var(--ok); }
.qn-q__status--danger { color: var(--danger); }

/* Recorded-answer fallback: a stored value the control cannot show (a legacy
   free-text answer to a choice question that offers no custom option, or a
   value_text-only multi from the seed). Never leave a real answer invisible. */
.qn-q__recorded {
  margin: var(--sp-2) 0 0;
  padding: 10px 12px;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------- Saved chip -- */

.qn-savedchip {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  max-width: calc(100vw - 24px);
  padding: 10px 18px;
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
}
.qn-savedchip--ok {
  color: var(--ok);
  background: var(--ok-wash);
  border-color: var(--ok);
}
.qn-savedchip--offline {
  color: var(--warn);
  background: var(--warn-wash);
  border-color: var(--warn);
}
.qn-savedchip--error {
  color: var(--danger);
  background: var(--danger-wash);
  border-color: var(--danger);
}
