/* qodiqa form engine (assets/js/forms.mjs): right-hand drawer on desktop, full-screen sheet on phones.
   Uses the shared controls: .btn, .field inputs, the .bdg badge, the panel look of .ipanel. Motion only inside prefers-reduced-motion: no-preference. */

html.qf-lock { overflow: hidden; padding-right: var(--qf-sbw, 0); }

.qf { position: fixed; inset: 0; z-index: 200; display: flex; justify-content: flex-end; }
.qf__backdrop { position: absolute; inset: 0; background: rgba(3, 4, 8, .72); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.qf__panel { position: relative; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; width: 100%; height: 100%; height: 100dvh; background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, .008)), var(--surface-1); color: var(--text); border-left: 1px solid var(--border); box-shadow: -24px 0 60px -30px rgba(0, 0, 0, .8); overscroll-behavior: contain; }
@media (min-width: 48rem) { .qf__panel { width: 34rem; max-width: 100%; } }

/* header */
.qf__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.4rem 1.5rem .9rem; }
.qf__titles { min-width: 0; }
.qf__count { margin: 0 0 .35rem; }
.qf__head h2 { margin: 0; }
.qf__intro { margin: .45rem 0 0; color: var(--text-dim); font-size: var(--text-body-size); line-height: 1.55; }
.qf__x.btn { flex: none; width: var(--btn-h); padding: 0; }

/* stepper */
.qf-steps { display: flex; align-items: center; gap: .5rem; margin: 0; padding: 0 1.5rem 1rem; border-bottom: 1px solid var(--border); list-style: none; }
.qf-steps__i { display: flex; align-items: center; gap: .5rem; min-width: 0; color: var(--text-faint); font-size: var(--text-small-size); }
.qf-steps__i[data-current] { color: var(--text); }
.qf-steps__i:not(:last-child)::after { content: ''; flex: none; width: 1rem; height: 1px; background: var(--border-hover); margin-left: .25rem; }
.qf-steps__t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qf-steps__i .bdg { margin: 0; }
@media (max-width: 47.99rem) {
  .qf-steps__i { flex: none; }
  .qf-steps__i:not([data-current]) .qf-steps__t { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .qf-steps__i:not(:last-child)::after { width: .75rem; }
  .qf-steps__i[data-current] { flex: 0 1 auto; }
}

/* body */
.qf__body { overflow-y: auto; overscroll-behavior: contain; padding: 1.4rem 1.5rem 1.6rem; scrollbar-width: thin; scrollbar-color: var(--border-hover) transparent; }
.qf-step { display: grid; gap: 1.15rem; align-content: start; }
.qf-h { margin: 0; outline: none; scroll-margin-top: 1rem; }
.qf-stepintro { margin: -.5rem 0 0; color: var(--text-dim); font-size: var(--text-body-size); line-height: 1.6; }
.qf-note { margin: -.5rem 0 0; color: var(--text-faint); font-size: var(--text-small-size); }
.qf-label { display: block; padding: 0; font-size: var(--text-body-size); font-weight: 500; color: var(--text); }
.qf-req { color: var(--invalid); }
.qf-opt-tag { color: var(--text-faint); font-weight: 400; font-size: var(--text-small-size); }
.qf-hint { margin: 0; color: var(--text-faint); font-size: var(--text-small-size); line-height: 1.5; }
.qf-err { margin: 0; color: var(--invalid); font-size: var(--text-body-size); line-height: 1.5; }
:is(.qf, .ct-form) .field { gap: .45rem; }
:is(.qf, .ct-form) .field textarea { resize: vertical; min-height: 7rem; line-height: 1.55; }
:is(.qf, .ct-form) .field select { appearance: none; -webkit-appearance: none; padding-right: 2.4rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a5adbd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; background-size: 1.1rem; }
:is(.qf, .ct-form) .field select option { background: var(--surface-2); color: var(--text); }
:is(.qf, .ct-form) .field input:hover, :is(.qf, .ct-form) .field textarea:hover, :is(.qf, .ct-form) .field select:hover { border-color: var(--border-hover); }
:is(.qf, .ct-form) .field input:focus-visible, :is(.qf, .ct-form) .field textarea:focus-visible, :is(.qf, .ct-form) .field select:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(138, 180, 255, .18); }
:is(.qf, .ct-form) .field input[aria-invalid="true"], :is(.qf, .ct-form) .field textarea[aria-invalid="true"], :is(.qf, .ct-form) .field select[aria-invalid="true"] { border-color: var(--invalid); }

/* choice groups */
.qf-group { display: grid; gap: .55rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.qf-group > legend { padding: 0; margin-bottom: .1rem; }
.qf-opts { display: grid; gap: .4rem; }
.qf-choice { display: flex; align-items: flex-start; gap: .7rem; min-height: 2.75rem; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--r-control); background: var(--bg); color: var(--text); font-size: var(--text-body-size); line-height: 1.45; cursor: pointer; transition: border-color var(--dg-hover) var(--ease), background var(--dg-hover) var(--ease); }
.qf-choice:hover { border-color: var(--border-hover); }
.qf-choice:has(input:checked) { border-color: color-mix(in srgb, var(--focus) 55%, transparent); background: color-mix(in srgb, var(--focus) 7%, var(--bg)); }
.qf-choice:has(input:focus-visible) { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(138, 180, 255, .18); }
.qf-choice input { flex: none; width: 1.1rem; height: 1.1rem; margin: .12rem 0 0; accent-color: var(--brand-blue); }
.has-error > .qf-opts .qf-choice, .qf-group--one.has-error .qf-choice { border-color: var(--invalid); }

/* error summary */
.qf-sum { margin: 0 0 1.15rem; padding: .95rem 1.1rem; border: 1px solid color-mix(in srgb, var(--invalid) 55%, transparent); border-radius: var(--r-control); background: color-mix(in srgb, var(--invalid) 8%, var(--bg)); outline: none; }
.qf-sum:focus-visible { box-shadow: 0 0 0 3px rgba(138, 180, 255, .25); }
.qf-sum__h { margin: 0 0 .5rem; color: var(--text); }
.qf-sum__l { display: grid; gap: .3rem; margin: 0; padding: 0; list-style: none; }
.qf-sum__l a { color: var(--text); font-size: var(--text-body-size); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--invalid) 70%, transparent); }
.qf-sum__l a:hover { text-decoration-color: var(--text); }

/* file area */
.qf-file { position: relative; }
.qf-file__in { position: absolute; width: 1px; height: 1px; margin: -1px; opacity: 0; overflow: hidden; }
.qf-drop { display: grid; gap: .6rem; justify-items: center; padding: 1.35rem 1rem; border: 1px dashed var(--border-hover); border-radius: var(--r-control); background: rgba(255, 255, 255, .02); text-align: center; cursor: pointer; transition: border-color var(--dg-hover) var(--ease), background var(--dg-hover) var(--ease); }
.qf-drop:hover, .qf-file.is-over .qf-drop { border-color: var(--text-dim); background: rgba(255, 255, 255, .045); }
.qf-file__in:focus-visible + .qf-drop { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(138, 180, 255, .18); }
.qf-drop.has-error { border-color: var(--invalid); }
.qf-drop:hover .qf-drop__t { background: rgba(255, 255, 255, .075); border-color: rgba(255, 255, 255, .3); }
.qf-drop__s { color: var(--text-faint); font-size: var(--text-small-size); line-height: 1.5; }
.qf-files { display: grid; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.qf-files__i { display: flex; align-items: center; gap: .75rem; padding: .35rem .5rem .35rem .8rem; border: 1px solid var(--border); border-radius: var(--r-control); background: var(--bg); font-size: var(--text-body-size); }
.qf-files__n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qf-files__s { color: var(--text-faint); font-size: var(--text-small-size); font-variant-numeric: tabular-nums; }

/* review */
.qf-rev__g { display: grid; gap: .5rem; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: var(--r-control); background: rgba(255, 255, 255, .02); }
.qf-rev__gh { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.qf-rev__gh h4 { margin: 0; color: var(--text); }
.qf-rev__l { display: grid; gap: .55rem; margin: 0; }
.qf-rev__l > div { display: grid; gap: .1rem; min-width: 0; }
.qf-rev__l dt { color: var(--text-faint); font-size: var(--text-small-size); }
.qf-rev__l dd { margin: 0; color: var(--text); font-size: var(--text-body-size); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.qf-rev__l dd.is-empty { color: var(--text-faint); }
.qf-act { display: grid; gap: .8rem; }
.qf-act__main { width: 100%; }
.qf-or { display: flex; align-items: center; gap: .8rem; margin: 0; color: var(--text-faint); font-size: var(--text-small-size); }
.qf-or::before, .qf-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.qf-act__alt { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.qf-act__msg { min-height: 1.4rem; margin: 0; color: var(--valid); font-size: var(--text-body-size); line-height: 1.5; }
.qf-act__msg.is-bad { color: var(--invalid); }
.qf-copyfallback { width: 100%; padding: .7rem .9rem; background: var(--bg); border: 1px solid var(--border-hover); border-radius: var(--r-control); color: var(--text); font: 400 var(--text-code-size)/1.5 var(--mono); resize: vertical; }

/* success */
.qf-done { display: flex; align-items: center; gap: .8rem; }
.qf-done__b { flex: none; }
.qf-next { display: grid; gap: .9rem; margin: 0; padding: 0; list-style: none; }
.qf-next li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .8rem; align-items: start; --bl: 22.5px; color: var(--text-dim); font-size: var(--text-body-size); line-height: 1.5; overflow-wrap: anywhere; }
.qf-next b { display: block; color: var(--text); font-weight: 500; }
.qf-done__close { display: flex; justify-content: flex-start; }

/* footer */
.qf__foot { display: grid; gap: .8rem; padding: .9rem 1.5rem calc(1rem + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); background: var(--surface-1); }
.qf__priv { margin: 0; color: var(--text-faint); font-size: var(--text-small-size); line-height: 1.5; }
.qf__nav { display: flex; gap: .75rem; justify-content: space-between; }
.qf__nav .btn--primary { margin-left: auto; }

@media (max-width: 47.99rem) {
  .qf__panel { border-left: 0; box-shadow: none; }
  .qf__head { padding: 1.1rem 1.1rem .8rem; }
  .qf-steps { padding: 0 1.1rem .85rem; }
  .qf__body { padding: 1.15rem 1.1rem 1.4rem; }
  .qf__foot { padding: .8rem 1.1rem calc(.9rem + env(safe-area-inset-bottom, 0px)); }
  .qf-act__alt { grid-template-columns: minmax(0, 1fr); }
  :is(.qf, .ct-form) .field input, :is(.qf, .ct-form) .field textarea, :is(.qf, .ct-form) .field select { font-size: var(--text-body-size); }
}

@media (prefers-reduced-motion: no-preference) {
  .qf.is-open .qf__backdrop { animation: qf-fade var(--t-fast) var(--ease) both; }
  .qf.is-open .qf__panel { animation: qf-slide var(--t-fast) var(--ease) both; }
  .qf-step:not([hidden]) { animation: qf-rise var(--t-fast) var(--ease) both; }
  @keyframes qf-fade { from { opacity: 0; } to { opacity: 1; } }
  @keyframes qf-slide { from { transform: translateX(2.5rem); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes qf-rise { from { opacity: 0; transform: translateY(.4rem); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 47.99rem) {
  .qf.is-open .qf__panel { animation-name: qf-sheet; }
  @keyframes qf-sheet { from { transform: translateY(1.5rem); opacity: 0; } to { transform: none; opacity: 1; } }
}

.qf__priv a { color: inherit; text-decoration: underline; text-underline-offset: .18em; }
