:root,
html[data-theme="light"] {
  --bg: #f0efe8;
  --bg-accent: #e4e2d6;
  --surface: #fafaf6;
  --surface-raised: #ffffff;
  --ink: #1c1b16;
  --muted: #5c5a50;
  --line: #c8c5b4;
  --accent: #0f5c4c;
  --accent-hover: #0a463a;
  --warn-bg: #f7ecd4;
  --warn-border: #c4922a;
  --danger: #8b2e2e;
  --ok: #0f5c4c;
  --top-bg: rgba(250, 250, 246, 0.92);
  --grad-a: #dde8e2;
  --grad-b: #ebe6d4;
  --input-bg: #ffffff;
  --input-placeholder: #8a8778;
  --log-bg: #f3f2eb;
  --log-ink: #3a392f;
  --subsection-bg: rgba(240, 239, 232, 0.45);
  --success-bg: #eef6f3;
  --success-border: #9cbcb2;
  --success-ink: #0f5c4c;
  --error-bg: #faf0f0;
  --error-border: #d4a0a0;
  --tab-hover: rgba(255, 255, 255, 0.45);
  --danger-hover-bg: #f3e4e4;
  --focus-ring: rgba(15, 92, 76, 0.35);
  --ocr-bg: #ffffff;
  --radius: 6px;
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
  --mono: "Cascadia Mono", "Consolas", monospace;
}

html[data-theme="dark"] {
  --bg: #0f1218;
  --bg-accent: #1a2030;
  --surface: #171c27;
  --surface-raised: #1e2533;
  --ink: #f0f2f7;
  --muted: #b0b8c9;
  --line: #2f384a;
  --accent: #4fb89f;
  --accent-hover: #6acca8;
  --warn-bg: #2f2818;
  --warn-border: #c4922a;
  --danger: #f08080;
  --ok: #6acca8;
  --top-bg: rgba(15, 18, 24, 0.94);
  --grad-a: #152028;
  --grad-b: #1c1814;
  --input-bg: #0f1218;
  --input-placeholder: #7a8499;
  --log-bg: #0f1218;
  --log-ink: #d5dae6;
  --subsection-bg: rgba(15, 18, 24, 0.55);
  --success-bg: #15241f;
  --success-border: #2f5c4e;
  --success-ink: #e8f5f0;
  --error-bg: #2a1818;
  --error-border: #7a3a3a;
  --tab-hover: rgba(255, 255, 255, 0.06);
  --danger-hover-bg: #2a1818;
  --focus-ring: rgba(79, 184, 159, 0.4);
  --ocr-bg: #0f1218;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, var(--grad-a) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 10%, var(--grad-b) 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.45;
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
  padding: 0.85rem 1.5rem;
  background: var(--top-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.top h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* The Back button lives inside the panel it takes you out of, not on the bar:
   it is about this screen, while the bar is about where you can go. */
.panel-back {
  display: flex;
  margin-bottom: 0.6rem;
}
.panel-back:has(> [hidden]) { display: none; }

.top-nav {
  display: flex;
  gap: 0.4rem;
  padding-right: 0.5rem;
  margin-right: 0.1rem;
  border-right: 1px solid var(--line);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* A class with display:flex/grid outranks the UA rule for [hidden], so panels
   toggled from JS stay on screen without this. */
[hidden] { display: none !important; }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
}

/* The intake is wider than the gate and the job list, which stay at a
   readable 920px. Nothing else on the page wants 1200px. */
main:has(#form-wrap:not([hidden])) { max-width: 1240px; }

/* Rail down the left, form in the middle. The gutters were ~325px of nothing
   on a 1570px screen; the left one now carries the rail so it is on screen the
   whole time instead of only when scrolled to the top. */
.form-layout {
  display: grid;
  grid-template-columns: 11.5rem minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn:hover { background: var(--bg-accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-hover-bg); }

.status {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  white-space: pre-wrap;
}
.status.error {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--danger);
}
.status.ok {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--ok);
}
.status.info { border-color: var(--line); }

.result {
  margin-bottom: 1.25rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--success-border);
  background: var(--success-bg);
  color: var(--success-ink);
}
.result h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--success-ink);
}
.result p,
.result li {
  color: var(--success-ink);
}
.result ul {
  margin: 0.4rem 0 0.75rem;
  padding-left: 1.2rem;
}
.result a { color: var(--accent); font-weight: 600; }
.result .log {
  margin-top: 0.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--log-ink);
  white-space: pre-wrap;
  max-height: 10rem;
  overflow: auto;
  background: var(--log-bg);
  border: 1px solid var(--line);
  padding: 0.5rem 0.65rem;
  border-radius: 4px;
}

.defaults-note {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.gate-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem 1.35rem 1.5rem;
  margin-bottom: 1.25rem;
  color: var(--ink);
}
.gate-panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  color: var(--ink);
}
.gate-lead { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; }
.gate-card { display: flex; flex-direction: column; gap: 0.85rem; }
.state-tabs{display:flex; gap:10px; flex-wrap:wrap; margin-top:4px}
.state-tab{
  flex:1 1 200px; text-align:left; cursor:pointer; font:inherit;
  background:var(--card, #fff); border:2px solid var(--line, #d7dde6);
  border-radius:12px; padding:12px 14px; transition:.15s; color:inherit;
}
.state-tab:hover{border-color:var(--accent, #2f6fdd)}
.state-tab.is-on{border-color:var(--accent, #2f6fdd); box-shadow:0 0 0 3px rgba(47,111,221,.14)}
.state-tab .st-name{display:block; font-size:16px; font-weight:650}
.state-tab .st-sub{display:block; font-size:12px; opacity:.7; margin-top:2px}

.gate-choices { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: 0.35rem; }
.choice {
  display: flex; align-items: center; gap: 0.4rem;
  font-weight: 600; font-size: 0.95rem; color: var(--ink);
}
.gate-bos { padding-top: 0.25rem; }

.dev-badge {
  font-size: 0.55em;
  font-weight: 600;
  letter-spacing: 0.04em;
  vertical-align: middle;
  opacity: 0.75;
}

.gate-optional-forms {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.gate-import {
  margin: 1rem 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border, #ccc);
  border-radius: 6px;
}

.gate-import summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.upload-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-accent);
  align-self: stretch;
}
.upload-tab {
  flex: 1;
  appearance: none;
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}
.upload-tab:last-child { border-right: none; }
.upload-tab:hover { color: var(--ink); background: var(--tab-hover); }
.upload-tab.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.upload-panel { display: flex; flex-direction: column; gap: 0.65rem; }
.upload-panel[hidden] { display: none !important; }
.upload-blurb {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}
.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}
.upload-row input[type="file"] {
  flex: 1 1 12rem;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.date-titles {
  grid-column: 1 / -1;
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.mailing-fields { margin-top: 0.75rem; }

.ocr-preview {
  margin: 0;
  padding: 0.65rem 0.75rem;
  background: var(--ocr-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  white-space: pre-wrap;
  max-height: 10rem;
  overflow: auto;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
  color: var(--ink);
}

.section > summary,
.section-head {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1.1rem;
  font-weight: 650;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--bg-accent);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.15s;
}
.section[open] > summary::before { transform: rotate(90deg); }

.section-body {
  padding: 1rem 1.1rem 1.15rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem 1rem;
  background: var(--surface);
}

.subsection {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  background: var(--subsection-bg);
}

.subsection-title {
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.65rem;
}

/* A price list: the label does the talking, the box holds at most 4 digits.
   These used to be ordinary stacked fields, so a quantity box ran the whole
   width of the card for a number like "4". */
.qty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0 1.4rem;
}

.subsection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
}

.field.full { grid-column: 1 / -1; }

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.field .hint {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.9;
}

.field input[type="text"],
.field input[type="tel"],
.field select,
.field textarea {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--ink);
  caret-color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--input-placeholder);
  -webkit-text-fill-color: var(--input-placeholder);
  opacity: 1;
}

.field textarea { min-height: 4rem; resize: vertical; }

/* Must come after the `.field input { width: 100% }` block above, which this
   would otherwise lose to on source order alone. */
/* The whole price-list row, placed after `.field` so it wins on source order:
   `.field` is a column flexbox, and these need the label and the box side by
   side. */
.field.qty-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}

.field.qty-row:last-child { border-bottom: 0; }

.field.qty-row label {
  flex: 1;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: inherit;
}

.field.qty-row input[type="text"] {
  flex: 0 0 4.2rem;
  width: 4.2rem;
  text-align: center;
  padding: 0.3rem 0.35rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--accent);
}

.field.needs-input input,
.field.needs-input select,
.field.needs-input textarea {
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.field.needs-input label::after {
  content: " needed";
  color: var(--warn-border);
  font-weight: 700;
  text-transform: lowercase;
}

.check-field {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  padding-top: 1.35rem;
}

.check-field label {
  font-size: 0.88rem;
  color: var(--ink);
  font-weight: 500;
  order: 1;
}

.check-field input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.name-block {
  grid-column: 1 / -1;
}

.name-format-hint {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted, #667);
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 0.5rem;
  grid-column: 1 / -1;
}

.date-row .field { min-width: 0; }

.dl-state-row {
  grid-template-columns: minmax(0, 1.6fr) minmax(10rem, 1fr);
  margin-top: 0.35rem;
}

.dl-only-row {
  grid-template-columns: 1fr;
  margin-top: 0.35rem;
}

.state-combo {
  position: relative;
}

.state-combo-input {
  width: 100%;
}

.state-combo-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 14rem;
  overflow: auto;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--panel, #fff);
  border: 1px solid var(--border, #ccc);
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.state-combo-option,
.state-combo-empty {
  padding: 0.4rem 0.65rem;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
}

.state-combo-option:hover,
.state-combo-option.is-selected {
  background: var(--tab-hover, rgba(0, 0, 0, 0.06));
}

.state-combo-empty {
  color: var(--muted);
  cursor: default;
}

.note-banner {
  grid-column: 1 / -1;
  padding: 0.65rem 0.8rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--ink);
}

@media (max-width: 640px) {
  .top { padding: 0.75rem 1rem; }
  .section-body { grid-template-columns: 1fr; }
  .date-row { grid-template-columns: 1fr 1fr 1fr; }
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.top-bar-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* --- jobs list + autosave status ---------------------------------------- */

.jobs-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem 1.35rem 1.5rem;
  margin-bottom: 1.25rem;
  color: var(--ink);
}
.jobs-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.jobs-panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  color: var(--ink);
}
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.9rem;
}
.job-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  padding: 0.65rem 0.75rem;
}
.job-open {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  background: none;
  border: 0;
  padding: 0.2rem;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--ink);
  border-radius: var(--radius);
}
.job-open:hover { background: var(--tab-hover); }
.job-open:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.job-title { font-weight: 600; font-size: 0.98rem; }
.job-sub { color: var(--muted); font-size: 0.82rem; }
.job-flag {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--warn-border);
}
.job-tools { display: flex; gap: 0.35rem; flex-shrink: 0; }
.jobs-empty { color: var(--muted); font-size: 0.9rem; margin: 1rem 0 0; }

.save-status {
  font-size: 0.8rem;
  color: var(--muted);
  padding-right: 0.25rem;
  white-space: nowrap;
}
.save-status.is-dirty { color: var(--warn-border); }
.save-status.is-local { color: var(--warn-border); font-weight: 600; }
.save-status.is-saved, .save-status.is-idle { color: var(--ok); }
.save-status.is-conflict { color: var(--danger); font-weight: 600; }

.conflict-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  margin-bottom: 0.85rem;
  color: var(--ink);
  font-size: 0.9rem;
}

/* --- the address book screen -------------------------------------------- */

.book-head-actions { display: flex; gap: 0.5rem; align-items: center; }

.book-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.4rem 0 0.9rem;
}
.book-toolbar input[type="text"] {
  flex: 1 1 18rem;
  padding: 0.45rem 0.6rem;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.book-count { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.book-list { display: flex; flex-direction: column; gap: 0.5rem; }
.book-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.book-name { font-weight: 600; }
.book-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }
.book-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.book-editor {
  margin-top: 1.1rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
}
.book-editor h3 { margin: 0 0 0.6rem; font-size: 1rem; }

/* The address book row at the top of a party block. */
.address-book {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.6rem;
  background: var(--subsection-bg);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.address-book .ab-label {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.address-book .ab-select {
  flex: 1 1 14rem;
  min-width: 10rem;
  padding: 0.3rem 0.4rem;
  font: inherit;
  font-size: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

/* A finished section folds to its title plus what is in it. Reopening it once
   stops it folding again - see keptOpen in app.js. */
.section.is-complete > summary { color: var(--muted); }
.section.is-complete > summary::before { color: var(--ok); }
.section-done {
  margin-left: 0.6rem;
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--ok);
}
.section.is-complete > summary::after {
  content: "complete";
  margin-left: auto;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ok);
}

/* --- section rail: what is left, and where ------------------------------ */

.progress-rail {
  position: sticky;
  /* parks under the sticky header; JS keeps --rail-top in step with its height */
  top: var(--rail-top, 4.75rem);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem 0.7rem;
  background: var(--top-bg);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.rail-chips { display: flex; flex-direction: column; gap: 0.25rem; }
/* chip jumps must clear the sticky header + rail */
.section { scroll-margin-top: var(--sticky-top, 8rem); }
.rail-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}
.rail-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-chip:hover { border-color: var(--accent); color: var(--accent); }
.rail-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.rail-chip-count {
  min-width: 1.15rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--warn-border);
}
.rail-chip.is-done { border-color: var(--success-border); }
.rail-chip.is-done .rail-chip-label { color: var(--muted); }
.rail-chip.is-done .rail-chip-count { color: var(--ok); }
.rail-total {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--warn-border);
  white-space: nowrap;
  padding: 0.1rem 0.2rem;
  border-top: 1px solid var(--line);
  padding-top: 0.45rem;
}

/* Narrow screens: back to the horizontal strip it was, above the form. */
@media (max-width: 1100px) {
  main:has(#form-wrap:not([hidden])) { max-width: 920px; }
  .form-layout { display: block; }
  .progress-rail {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
  }
  .rail-chips { flex-direction: row; flex-wrap: wrap; gap: 0.4rem; }
  .rail-chip { width: auto; border-radius: 999px; }
  .rail-total { border-top: 0; padding-top: 0.1rem; }
}
.rail-total.is-done { color: var(--ok); }

/* --- who are you ---------------------------------------------------------- */

.who-card { max-width: 32rem; }

.who-people {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.9rem 0 0.2rem;
}
.who-people .btn { font-size: 0.95rem; }
.who-add { margin-top: 0.9rem; }
.who-add summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}
.who-add .btn { margin-top: 0.6rem; }

.who-manage { margin-top: 0.9rem; }
.who-manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.25rem 0;
  font-size: 0.88rem;
}
.who-manage-row .btn { margin-top: 0; }
.who-card h2 { margin: 0 0 0.35rem; }
.who-card .btn { margin-top: 0.9rem; }
.who-error { color: var(--danger, #b3261e); }

/* The name against a job in the list, and in the header. */
.job-author {
  color: var(--muted);
  font-size: 0.78rem;
}
.top-user {
  color: var(--muted);
  font-size: 0.8rem;
  margin-right: 0.35rem;
}

/* --- lien holder toggle + address copy ---------------------------------- */

/*
 * The expanded lien block is a plain <div>, so as a single grid item it became
 * one narrow column beside the checkbox while every other section laid its
 * fields out across the full width. Span the row and use the same grid as
 * .section-body so it reads like the rest of the form.
 */
.lien-fields,
.reg227-lien-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem 1rem;
  align-items: start;
}

/* The toggle that opens them belongs on its own line above, not in a column. */
.check-field.lien-toggle {
  grid-column: 1 / -1;
  padding-top: 0;
}

.lien-off-note { margin-top: 0.4rem; }
.subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.btn-inline {
  padding: 0.18rem 0.55rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* --- inline field errors ------------------------------------------------- */

.field-error {
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--danger);
}
input.is-bad {
  border-color: var(--danger);
  background: var(--error-bg);
}

/* --- pre-generate "still blank" warning --------------------------------- */

.missing-lead { font-weight: 600; }
.missing-list { display: flex; gap: 0.35rem; flex-wrap: wrap; flex: 1 1 100%; }
.missing-chip {
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--warn-border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
}
.missing-chip:hover { border-color: var(--accent); color: var(--accent); }
.missing-more { font-size: 0.78rem; color: var(--muted); align-self: center; }

/* --- VIN decode suggestions --------------------------------------------- */

.vin-button-row { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.4rem; flex-wrap: wrap; }
.vin-panel {
  margin-top: 0.6rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--subsection-bg);
}
.vin-lead { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.vin-warn {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.6rem;
}
.vin-rows { display: flex; flex-direction: column; gap: 0.3rem; }
.vin-row {
  display: grid;
  grid-template-columns: auto 10rem minmax(6rem, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.25rem 0.35rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.vin-row:hover { background: var(--tab-hover); }
.vin-field { color: var(--muted); }
.vin-value { font-weight: 600; }
.vin-current { font-size: 0.76rem; color: var(--warn-border); }
.vin-note { font-size: 0.76rem; color: var(--muted); text-align: right; }
.vin-row.is-check .vin-note { color: var(--warn-border); font-weight: 600; }
.vin-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
@media (max-width: 720px) {
  .vin-row { grid-template-columns: auto 1fr; }
  .vin-note, .vin-current { grid-column: 2; text-align: left; }
}

/* --- recover an earlier workspace ---------------------------------------- */

.recover-panel {
  margin-top: 1.25rem;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}
.recover-panel > summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}
.recover-panel > summary:hover { color: var(--accent); }
.recover-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.recover-row { cursor: default; }
.recover-row:hover { background: none; }

/* --- job tabs + storage banner ------------------------------------------ */

.jobs-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.9rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.5rem;
}
.jobs-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}
.jobs-tab:hover { color: var(--ink); background: var(--tab-hover); }
.jobs-tab:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.jobs-tab.is-active {
  color: var(--ink);
  font-weight: 600;
  background: var(--surface-raised);
  border-color: var(--line);
}
.jobs-tab-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg-accent);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  min-width: 1.3rem;
  text-align: center;
}
.jobs-tab.is-active .jobs-tab-count { color: var(--accent); }

.storage-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-top: 0.85rem;
  font-size: 0.88rem;
  color: var(--ink);
}

/* USPS "Check address" control - sits under an address grid. */
.usps-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.usps-row .hint { margin: 0; }
.usps-row .vin-panel { flex-basis: 100%; }
