/*
 * wf.css - SHARED_WORKFLOWS pages. rem units only. Mobile-first: the base
 * rules are the phone layout, min-width queries widen it.
 *
 * TOKEN BRIDGE. Every rule below the token blocks reads only --wf-* custom
 * properties. Each --wf-* token resolves, in order:
 *   1. the site token: --site-* from the SHARED_AUTH branding theme.css
 *      (branding/tokens.py) or a site's own site-theme.css (site theme
 *      contract v1, branding/conformance/site_check.py), or --status-danger
 *      (branding/tokens.py);
 *   2. the dashboard token: --dash-*, --radius-*, --touch-min from
 *      SHARED_DASHBOARD dashboard-shell.css, defined only where that
 *      stylesheet is loaded;
 *   3. a literal equal to this file's pre-bridge value, so an unbranded page
 *      outside the dashboard renders exactly as before, light and dark.
 * Deliberately site-only (no dashboard step):
 *   --wf-accent / --wf-on-accent  read as a pair (the generator derives both
 *      from one block); --dash-accent has no on-accent partner, and its
 *      #3b82f6 default under white button text is below 4.5:1.
 *   --wf-border  --dash-border is translucent (alpha 0.06 to 0.08), below the
 *      3:1 a form control's boundary needs.
 *   --wf-link    no dashboard token is a text-safe accent ink.
 * --wf-success stays literal: neither SHARED_AUTH nor SHARED_DASHBOARD defines
 * a success token.
 *
 * Theme states, matching the SHARED_AUTH render_theme_css emission and the
 * SHARED_DASHBOARD theme-hydrate.js stamp:
 *   1. :root                                      light (unstamped)
 *   2. @media (prefers-color-scheme: dark) on :root:not([data-theme="light"])
 *                                                 dark (OS dark, unstamped)
 *   3. html[data-theme="dark"] / html[data-theme="light"]   explicit
 * Each block reads the site tokens of its own theme: theme.css emits the same
 * blocks with the same guards, and is linked AFTER this file.
 */

:root {
  --wf-bg: var(--site-bg, var(--dash-bg-primary, #ffffff));
  --wf-surface: var(--site-surface, var(--dash-bg-secondary, #f8fafc));
  --wf-text: var(--site-text, var(--dash-text-primary, #0f172a));
  --wf-muted: var(--site-text-muted, var(--dash-text-secondary, #475569));
  --wf-border: var(--site-border, #cbd5e1);
  --wf-link: var(--site-accent-ink, #1d4ed8);
  --wf-danger: var(--status-danger, #b91c1c);
  --wf-success: #15803d;
  --wf-focus: var(--site-focus, var(--site-accent-ink, var(--dash-accent, #2563eb)));
  --wf-accent: var(--site-accent-fill, #1d4ed8);
  --wf-on-accent: var(--site-on-accent, #ffffff);
  --wf-radius: var(--radius-md, 0.5rem);
  --wf-radius-sm: var(--radius-sm, 0.375rem);
  --wf-touch: var(--touch-min, 2.75rem);
  --wf-font: var(--site-font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not(.light) {
    --wf-bg: var(--site-bg, var(--dash-bg-primary, #0b1120));
    --wf-surface: var(--site-surface, var(--dash-bg-secondary, #111827));
    --wf-text: var(--site-text, var(--dash-text-primary, #e5e7eb));
    --wf-muted: var(--site-text-muted, var(--dash-text-secondary, #9ca3af));
    --wf-border: var(--site-border, #374151);
    --wf-link: var(--site-accent-ink, #93c5fd);
    --wf-danger: var(--status-danger, #f87171);
    --wf-success: #4ade80;
    --wf-focus: var(--site-focus, var(--site-accent-ink, var(--dash-accent, #93c5fd)));
    color-scheme: dark;
  }
}

html[data-theme="dark"] {
  --wf-bg: var(--site-bg, var(--dash-bg-primary, #0b1120));
  --wf-surface: var(--site-surface, var(--dash-bg-secondary, #111827));
  --wf-text: var(--site-text, var(--dash-text-primary, #e5e7eb));
  --wf-muted: var(--site-text-muted, var(--dash-text-secondary, #9ca3af));
  --wf-border: var(--site-border, #374151);
  --wf-link: var(--site-accent-ink, #93c5fd);
  --wf-danger: var(--status-danger, #f87171);
  --wf-success: #4ade80;
  --wf-focus: var(--site-focus, var(--site-accent-ink, var(--dash-accent, #93c5fd)));
  color-scheme: dark;
}

html[data-theme="light"] {
  --wf-bg: var(--site-bg, var(--dash-bg-primary, #ffffff));
  --wf-surface: var(--site-surface, var(--dash-bg-secondary, #f8fafc));
  --wf-text: var(--site-text, var(--dash-text-primary, #0f172a));
  --wf-muted: var(--site-text-muted, var(--dash-text-secondary, #475569));
  --wf-border: var(--site-border, #cbd5e1);
  --wf-link: var(--site-accent-ink, #1d4ed8);
  --wf-danger: var(--status-danger, #b91c1c);
  --wf-success: #15803d;
  --wf-focus: var(--site-focus, var(--site-accent-ink, var(--dash-accent, #2563eb)));
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.wf-body {
  margin: 0;
  background: var(--wf-bg);
  color: var(--wf-text);
  font-family: var(--wf-font);
  font-size: 1rem;
  line-height: 1.5;
}

.wf-page {
  max-width: 45rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.wf-page:focus {
  outline: none;
}

.wf-skip {
  position: absolute;
  left: -100rem;
  top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--wf-surface);
  color: var(--wf-link);
}

/* Above the fixed SHARED_DASHBOARD header (.he-header, z-index 1000). */
.wf-skip:focus {
  left: 0.5rem;
  z-index: 1200;
}

/*
 * Inside the SHARED_DASHBOARD iframe: content-loader stamps html.hh-embedded
 * and hides .he-header, so the dashboard shell owns the chrome. The skip link
 * would jump past a header that is not there, and the page's own outer
 * padding and background would double the shell's.
 */
html.hh-embedded .wf-skip {
  display: none;
}

html.hh-embedded .wf-body {
  background: transparent;
}

html.hh-embedded .wf-page {
  padding: 0;
}

.wf-heading {
  font-size: 1.75rem;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}

.wf-heading:focus {
  outline: 0.125rem solid var(--wf-focus);
  outline-offset: 0.25rem;
}

.wf-subheading {
  font-size: 1.125rem;
  margin: 0 0 0.5rem;
}

.wf-status {
  min-height: 1.5rem;
  margin: 0 0 0.75rem;
  color: var(--wf-muted);
}

.wf-muted,
.wf-progress {
  color: var(--wf-muted);
}

.wf-lead,
.wf-message {
  margin: 0 0 1rem;
}

.wf-success {
  margin: 0 0 1rem;
  color: var(--wf-success);
  font-weight: 600;
}

.wf-card {
  background: var(--wf-surface);
  border: 0.0625rem solid var(--wf-border);
  border-radius: var(--wf-radius);
  padding: 1rem 1.25rem;
  margin: 0 0 1rem;
}

.wf-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.wf-rows {
  list-style: none;
  padding-left: 0;
}

/* Phone: title above its control. Inline from 30rem. */
.wf-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-top: 0.0625rem solid var(--wf-border);
}

.wf-row:first-child {
  border-top: 0;
}

.wf-row-title {
  font-weight: 600;
}

.wf-totals {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin: 0 0 1rem;
}

.wf-totals dt {
  color: var(--wf-muted);
}

.wf-totals dd {
  margin: 0;
}

/*
 * Progress stepper. Phone: the one-line ".wf-stepper__compact" summary only.
 * From 30rem: the ordered list as a horizontal track. Each item has a fixed
 * flex basis and min-width 0, so a state change (weight, ring width) never
 * moves anything; the track scrolls sideways instead of wrapping.
 * State is never color alone: done shows a check mark, current is bold with
 * a thicker ring, upcoming has a dashed ring.
 */
.wf-stepper {
  margin: 0 0 1.25rem;
}

.wf-stepper__compact {
  margin: 0;
  color: var(--wf-muted);
  font-weight: 600;
}

.wf-stepper__list {
  display: none;
}

.wf-stepper__list:focus-visible,
.wf-stepper a:focus-visible {
  outline: 0.1875rem solid var(--wf-focus);
  outline-offset: 0.125rem;
}

.wf-stepper__item {
  position: relative;
  display: flex;
  flex: 1 0 6rem;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  max-width: 12rem;
  text-align: center;
}

/* Connector: drawn by each item back to the center of the previous one. */
.wf-stepper__item + .wf-stepper__item::before {
  content: "";
  position: absolute;
  top: 0.8125rem;
  right: 50%;
  width: 100%;
  height: 0.125rem;
  background: var(--wf-border);
}

.wf-stepper__item--done + .wf-stepper__item::before {
  background: var(--wf-accent);
}

.wf-stepper__index {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 0.125rem solid var(--wf-border);
  border-radius: 50%;
  background: var(--wf-bg);
  color: var(--wf-muted);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.wf-stepper__label {
  display: block;
  max-width: 100%;
  margin: 0.375rem 0 0;
  padding: 0 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--wf-muted);
}

/* Done: filled, the number replaced by a check mark (silent to readers). */
.wf-stepper__item--done .wf-stepper__index {
  font-size: 0;
  background: var(--wf-accent);
  border-color: var(--wf-accent);
  color: var(--wf-on-accent);
}

.wf-stepper__item--done .wf-stepper__index::before {
  content: "\2713";
  content: "\2713" / "";
  font-size: 0.875rem;
}

.wf-stepper__item--done .wf-stepper__label {
  color: var(--wf-text);
}

.wf-stepper__item--current .wf-stepper__index {
  border-width: 0.1875rem;
  border-color: var(--wf-accent);
  color: var(--wf-text);
  font-weight: 700;
}

.wf-stepper__item--current .wf-stepper__label {
  color: var(--wf-text);
  font-weight: 700;
}

.wf-stepper__item--upcoming .wf-stepper__index {
  border-style: dashed;
}

.wf-form {
  margin: 0;
}

.wf-field {
  margin: 0 0 1.25rem;
}

.wf-label {
  display: block;
  font-weight: 600;
  margin: 0 0 0.375rem;
}

.wf-req {
  font-weight: 400;
  color: var(--wf-muted);
}

.wf-input {
  display: block;
  width: 100%;
  min-height: var(--wf-touch);
  padding: 0.5rem 0.75rem;
  font: inherit;
  color: var(--wf-text);
  background: var(--wf-bg);
  border: 0.0625rem solid var(--wf-border);
  border-radius: var(--wf-radius-sm);
}

.wf-textarea {
  min-height: 6rem;
  resize: vertical;
}

.wf-input:focus,
.wf-checkbox:focus,
.wf-radio:focus,
.wf-button:focus,
.wf-link:focus,
.wf-skip:focus {
  outline: 0.1875rem solid var(--wf-focus);
  outline-offset: 0.125rem;
}

.wf-input[aria-invalid="true"],
.wf-fieldset[aria-invalid="true"] {
  border-color: var(--wf-danger);
}

.wf-fieldset {
  border: 0.0625rem solid var(--wf-border);
  border-radius: var(--wf-radius-sm);
  margin: 0;
  padding: 0.75rem 1rem;
}

.wf-fieldset .wf-label {
  padding: 0 0.25rem;
}

.wf-choice {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.25rem 0;
}

.wf-choice .wf-label {
  font-weight: 400;
  margin: 0;
}

.wf-checkbox,
.wf-radio {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.125rem 0 0;
  flex: none;
}

.wf-consent {
  padding: 0.75rem;
  border: 0.0625rem solid var(--wf-border);
  border-radius: var(--wf-radius-sm);
}

.wf-field-error {
  margin: 0.375rem 0 0;
  color: var(--wf-danger);
  font-weight: 600;
}

.wf-error-summary {
  border: 0.125rem solid var(--wf-danger);
  border-radius: var(--wf-radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}

/* A neutral confirmation, e.g. "Your answers are saved." */
.wf-notice {
  border: 0.125rem solid var(--wf-success);
  border-radius: var(--wf-radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}

.wf-notice > p {
  margin: 0;
}

.wf-error-summary:focus {
  outline: 0.1875rem solid var(--wf-focus);
  outline-offset: 0.125rem;
}

.wf-summary-title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--wf-danger);
}

/*
 * Action row. Phone: stacked, full width, the primary button first in visual
 * order (wf.js puts "Back" before "Next" in the DOM), then "Save and exit"
 * (after Next in the DOM), then Back. Inline from 30rem, in DOM order.
 */
.wf-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  margin: 1.5rem 0 0;
}

.wf-actions > .wf-button {
  width: 100%;
}

.wf-actions > .wf-button--primary {
  order: -1;
}

/* After the primary button (later in the DOM, same order), before Back. */
.wf-actions > .wf-save-exit {
  order: -1;
}

.wf-actions > .wf-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--wf-touch);
}

.wf-button {
  min-height: var(--wf-touch);
  padding: 0.5rem 1.25rem;
  font: inherit;
  font-weight: 600;
  color: var(--wf-text);
  background: var(--wf-surface);
  border: 0.0625rem solid var(--wf-border);
  border-radius: var(--wf-radius-sm);
  cursor: pointer;
}

.wf-button--primary {
  color: var(--wf-on-accent);
  background: var(--wf-accent);
  border-color: var(--wf-accent);
}

.wf-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.wf-link {
  color: var(--wf-link);
  text-decoration: underline;
  text-underline-offset: 0.15rem;
}

[hidden] {
  display: none !important;
}

@media (min-width: 30rem) {
  .wf-page {
    padding: 2rem 1rem 4rem;
  }

  .wf-row {
    flex-direction: row;
    align-items: center;
  }

  .wf-stepper__compact {
    display: none;
  }

  .wf-stepper__list {
    display: flex;
    margin: 0;
    padding: 0 0 0.25rem;
    list-style: none;
    overflow-x: auto;
  }

  .wf-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
  }

  .wf-actions > .wf-button {
    width: auto;
  }

  .wf-actions > .wf-button--primary {
    order: 0;
  }

  .wf-actions > .wf-save-exit {
    order: 0;
  }

  .wf-actions > .wf-link {
    display: block;
    min-height: 0;
  }
}

/* Keeps the cancel box clear of the action buttons above it. */
.wf-cancel {
  margin-top: 1.5rem;
}

/* Text for screen readers only (the stepper's "(completed)" marker). */
.wf-visually-hidden {
  position: absolute;
  width: 0.0625rem;
  height: 0.0625rem;
  margin: -0.0625rem;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* A link styled as a button: the confirmed page's next-destination link. */
a.wf-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-decoration: none;
}

.wf-row-text {
  min-width: 0;
}

.wf-row-description {
  margin: 0.25rem 0 0;
}

.wf-row-steps {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }

  .wf-stepper__index {
    transition: none;
  }
}
