/* Design follows the Dahlia "Data Glue" tool (http://dataglue.dahlia):
   zinc palette, IBM Plex Sans/Mono, white navbar, dark status bar, bordered cards
   with mono labels and numbered step rows. */
:root {
  --ink: #18181b;
  --ink-2: #27272a;
  --muted: #71717a;
  --faint: #a1a1aa;
  --border: #e4e4e7;
  --surface: #ffffff;
  --head: #fafafa;
  --bg: #f4f4f5;
  --link: #2563eb;
  --brand: #b0185f;  /* Dahlia logo magenta: used only for keyboard focus */
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --err: #b91c1c; --err-bg: #fff5f5; --err-line: #fecaca; --err-on-dark: #fca5a5;
  --warn: #b45309; --warn-bg: #fffbeb; --warn-line: #fde68a; --warn-on-dark: #fcd34d;
  --info: #1d4ed8; --info-bg: #eff6ff; --info-line: #bfdbfe;
  --ok: #047857; --ok-bg: #f0fdf4; --ok-line: #6ee7b7; --ok-on-dark: #86efac;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--ink); }
a { color: var(--ink); }
a:hover { color: var(--link); }
h1, h2, h3 { font-weight: 600; margin: 0; }
code, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ── impersonation banner: stays visible while scrolling ── */
.impersonate-bar { position: sticky; top: 0; z-index: 100; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; padding: 8px 30px; font-size: .85rem; background: var(--warn-bg); color: var(--warn);
  border-bottom: 1px solid var(--warn-line); }
.impersonate-bar form { margin: 0; }
.impersonate-bar button { font: 500 .85rem var(--sans); padding: 6px 12px; border-radius: 6px; cursor: pointer;
  background: var(--surface); color: var(--warn); border: 1px solid var(--warn-line); }
.impersonate-intro { padding: 14px 16px; margin: 0; font-size: .88rem; }

/* ── question layout: text + input left, explanation images right (phone: images between text and input) ── */
.step-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto 1fr;
  grid-template-areas: "head media" "main media"; column-gap: 28px; align-items: start; }
.step-head { grid-area: head; }
.step-main { grid-area: main; min-width: 0; }
.step-media { grid-area: media; width: 320px; max-width: 34vw; }
.step-media:not(:has(figure)) { width: auto; }  /* staff view without images: just the "+ Add image" link */
.step-media:has(.qhelp-add[open]) { width: 320px; }
.q-images { display: flex; flex-direction: column; gap: 14px; margin: 2px 0 8px; }
.q-images figure { margin: 0; min-width: 0; }
.q-images img { display: block; width: auto; height: auto; max-width: 100%; max-height: 240px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: zoom-in; }
.q-images a:hover img { border-color: var(--faint); }
.q-images figcaption { font-size: .76rem; color: var(--muted); margin-top: 5px; line-height: 1.45; }
@media (max-width: 768px) {
  .step-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "head" "media" "main"; }
  .step-media, .step-media:not(:has(figure)) { width: auto; max-width: none; }
  .q-images img { max-height: 260px; width: auto; max-width: 100%; }
}

/* ── navbar ── */
.navbar { background: var(--surface); padding: 12px 30px; box-shadow: 0 2px 8px rgba(0,0,0,.1);
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-container { display: flex; align-items: center; gap: 15px; text-decoration: none; color: #343a40; }
.logo-image { height: 40px; width: auto; }
.logo-text-container { display: flex; flex-direction: column; gap: 3px; }
.logo-title { color: #343a40; font-weight: 600; font-size: 20px; letter-spacing: .5px; line-height: 1; }
.logo-subtitle { color: #6c757d; font-size: 12px; letter-spacing: .3px; line-height: 1; }
.user-info-bar { display: flex; align-items: center; gap: 6px; color: #495057; font-size: 14px; flex-wrap: wrap; }
.user-info-bar a, .user-info-bar button { color: #495057; text-decoration: none; padding: 8px 14px; border-radius: 6px;
  font: 500 14px var(--sans); background: none; border: 0; cursor: pointer; transition: background-color .2s; }
.user-info-bar a:hover, .user-info-bar button:hover { background: #f8f9fa; color: var(--ink); }
.user-info-bar form { margin: 0; }
.user-name { font-weight: 600; padding: 8px 12px; background: #f8f9fa; border-radius: 6px; }
.main-content { max-width: 1240px; margin: 0 auto; padding: 20px 20px 90px; }

/* language switch: EN | DE */
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin: 0 0 0 6px; }
.user-info-bar .lang-switch button { font: 500 12px var(--mono); padding: 6px 9px; border-radius: 0; color: var(--muted); }
.user-info-bar .lang-switch button.active { background: var(--ink); color: #fff; }

/* ── status bar ── */
.status-bar { background: var(--ink); border-radius: 8px; padding: 12px 20px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px 22px; flex-wrap: wrap; }
.status-bar-title { font-family: var(--mono); font-size: .9rem; font-weight: 500; color: #fff; letter-spacing: .02em; }
.status-bar-sub { font-family: var(--mono); font-size: .72rem; color: var(--faint); display: flex; gap: 4px 14px; flex-wrap: wrap; }
.status-chips { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.status-bar .right { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.s-chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: .72rem; color: var(--faint); white-space: nowrap; }
.s-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.s-chip.ok { color: var(--ok-on-dark); } .s-chip.err { color: var(--err-on-dark); } .s-chip.warn { color: var(--warn-on-dark); }
.s-chip.live .dot { animation: blink 2s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
/* Buttons in the black bar are light so they stand out from it (Torsten, 2026-11-23: "make the buttons stand out more"). */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 4px; background: #e4e4e7;
  color: var(--ink); font-family: var(--mono); font-size: .72rem; font-weight: 500; text-decoration: none; white-space: nowrap; border: 0; cursor: pointer; }
.pill:hover { background: #fff; color: var(--ink); }
.pill.danger { background: #fecaca; color: #7f1d1d; }
.pill.danger:hover { background: #fee2e2; color: #7f1d1d; }

/* ── cards (phase cards) ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.card-head { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--head); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-label { font-family: var(--mono); font-size: .62rem; font-weight: 500; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.card-name { font-size: .85rem; font-weight: 600; }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card-body { padding: 14px 16px; }
.card-body > :first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: 3fr 2fr; gap: 14px; align-items: start; }
.narrow { max-width: 440px; margin: 48px auto; }

/* ── steps (one question / item per row) ── */
.step { display: flex; align-items: flex-start; gap: 11px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: none; }
.step:hover { background-color: var(--head); }  /* -color: keeps the sub-question separator image */
.step-n { font-family: var(--mono); font-size: .66rem; color: var(--faint); width: 34px; flex-shrink: 0; padding-top: 2px; }
.step-body { flex: 1; min-width: 0; }
.step-title { font-size: .84rem; font-weight: 500; margin-bottom: 3px; }
.step-title .opt { font-family: var(--mono); font-size: .68rem; font-weight: 400; color: var(--faint); margin-left: 6px; }
.step-desc { font-size: .74rem; color: var(--muted); line-height: 1.4; margin-bottom: 6px; }
.step.has-error { box-shadow: inset 3px 0 0 var(--err); }
.step.has-warning:not(.has-error) { box-shadow: inset 3px 0 0 #f59e0b; }
/* Red = blocks submitting: errors and required questions not answered yet. Yellow = warning, doesn't block. */
.step.has-missing:not(.has-error) { box-shadow: inset 3px 0 0 var(--err-line); }
.missing-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.missing-row .sl { padding: 2px 8px; font-size: .7rem; }
.issues li.missing { border: 0; padding: 0; background: none; }
.issues li.missing .tag { color: var(--err); }
.missing-label { font-size: .78rem; font-weight: 600; color: var(--err); }
.missing-row .sl { color: var(--err); border-color: var(--err-line); background: var(--err-bg); }
.checks-why { font-size: .8rem; margin: 0 0 10px; color: var(--muted); }
.checks-why.err { color: var(--err); font-weight: 500; }
details.card.checks.blocked { border-color: var(--err-line); }
.submit-check.blocked { border: 2px solid var(--err); }
.submit-check.blocked .card-head { background: var(--err-bg); color: var(--err); }
.submit-check.confirm { border: 2px solid #f59e0b; }
.submit-check.confirm .card-head { background: var(--warn-bg); color: var(--warn); }
.submit-check p { margin: 0 0 10px; font-size: .86rem; }
.submit-check .confirm-form { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.submit-check .confirm-box { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; font-size: .86rem; }
.submit-check .actions { display: flex; gap: 12px; align-items: center; }
.submit-hint { font-size: .76rem; font-weight: 500; }
.submit-hint.err { color: var(--err); }
.submit-hint.warn { color: var(--warn); }

/* ── buttons & link chips ── */
.sl, button, .button { font-family: var(--sans); font-size: .78rem; font-weight: 500; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 5px; background: var(--bg); color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; transition: all .12s; }
.sl:hover, button:hover, .button:hover { border-color: var(--faint); background: #ececee; color: var(--ink); }
button.primary, .button.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
button.primary:hover, .button.primary:hover { background: #3f3f46; color: #fff; }
.sl.danger, button.danger { color: var(--err); border-color: var(--err-line); background: var(--err-bg); }
.sl.danger:hover, button.danger:hover { border-color: #ef4444; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; font-size: inherit; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ── forms ── */
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
  font: 14px var(--sans); color: var(--ink); padding: 6px 9px; border: 1px solid #d4d4d8; border-radius: 5px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #a1a1aa; outline-offset: 0; border-color: var(--faint); }
input[type=number] { width: 9em; }
/* unit right after a number input: [ 1.60 ] m */
.unit-input { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; }
label > .unit-input { display: flex; margin-top: 3px; }
label > .unit-input > input { margin: 0; }
.unit-input .unit { font: 500 .85rem var(--mono); color: var(--muted); }
textarea { width: 100%; }
input[type=file] { font: .78rem var(--sans); color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { font: 500 .78rem var(--sans); padding: 5px 11px; margin-right: 10px; border: 1px solid var(--border);
  border-radius: 5px; background: var(--bg); color: var(--ink); cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: var(--faint); background: #ececee; }
label { display: block; margin: 6px 0; font-size: .8rem; color: var(--muted); }
label > input, label > select, label > textarea { display: block; margin-top: 3px; }
label.inline { display: flex; gap: 7px; align-items: baseline; color: var(--ink); font-size: .82rem; }
.wide { width: 100%; }
.field-row { display: flex; gap: 6px 16px; flex-wrap: wrap; }
.step-body div:has(> div > label > input[type=checkbox]),
.step-body div:has(> div > label > input[type=radio]) { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0; }
.step-body div > div > label:has(> input[type=checkbox]),
.step-body div > div > label:has(> input[type=radio]) { margin: 0; display: inline-flex; gap: 7px; align-items: center; color: var(--ink);
  font-size: .8rem; padding: 4px 11px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg); cursor: pointer; }
.step-body div > div > label:has(> input:checked) { background: var(--ink); color: #fff; border-color: var(--ink); }
.step-body div > div > label > input { margin: 0; accent-color: var(--ink); }
.errorlist { list-style: none; color: var(--err); margin: 4px 0; padding: 0; font-size: .74rem; }
.current-file { font-family: var(--mono); font-size: .74rem; }
.sensor-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px;
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; margin: 8px 0; background: var(--head); }
.save-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06); padding: 10px 20px; z-index: 10; }
.save-bar-inner { max-width: 1240px; margin: 0 auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#autosave-status { margin-right: auto; font-family: var(--mono); font-size: .72rem; color: var(--muted); }

/* ── issues ── */
.issues { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 4px; }
.issues li { font-size: .76rem; padding: 5px 10px; border-radius: 5px; border: 1px solid; line-height: 1.4; }
.issues li .tag { font-family: var(--mono); font-size: .68rem; font-weight: 500; margin-right: 6px; }
.issues .error { color: var(--err); background: var(--err-bg); border-color: var(--err-line); }
.issues .warning { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.step .q-issues:empty { display: none; }
.issues .info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.issues a { color: inherit; }
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .card-name::after { content: " ▸"; color: var(--faint); }
details.card[open] > summary .card-name::after { content: " ▾"; }

/* ── badges / status ── */
.badge { font-family: var(--mono); font-size: .7rem; padding: 2px 8px;
  border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.badge.err { color: var(--err); background: var(--err-bg); border-color: var(--err-line); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.badge.info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }

/* ── flash messages ── */
.flash { font-size: .82rem; padding: 9px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid var(--info-line); background: var(--info-bg); color: var(--info); }
.flash.success { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok); }
.flash.error { border-color: var(--err-line); background: var(--err-bg); color: var(--err); }
.flash.warning { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn); }

/* ── tables ── */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.table th, .table td { padding: 9px 16px; border-bottom: 1px solid var(--border); text-align: left; font-size: .82rem; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table th { font-family: var(--mono); font-size: .7rem; font-weight: 500; color: var(--muted); background: var(--head); }
.table tbody tr:hover { background: var(--head); }
.table td.n, .table td.num { font-family: var(--mono); font-size: .72rem; color: var(--faint); white-space: nowrap; }
.table a { text-decoration: none; font-weight: 500; } .table a:hover { text-decoration: underline; }
.kv { table-layout: fixed; }
.kv td { padding: 6px 16px; overflow-wrap: anywhere; }
.kv td.n { width: 64px; }
.kv td:nth-child(2) { color: var(--muted); width: 46%; }
.sub-head { font-family: var(--mono); font-size: .7rem; font-weight: 500; color: var(--muted);
  padding: 10px 16px 6px; border-bottom: 1px solid var(--border); background: var(--head); }
table.cables { width: auto; }
table.cables td { padding: 3px 14px 3px 0; font-size: .8rem; border: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filters input[type=search] { flex: 1; min-width: 200px; }

/* ── messages thread ── */
.msg { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.msg.dahlia { box-shadow: inset 3px 0 0 var(--ink); }
.msg.resolved { opacity: .55; }
.msg .meta { font-family: var(--mono); font-size: .66rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 3px; }
.msg .meta form { margin: 0; }
.msg .text { font-size: .82rem; }

/* ── offer (print) ── */
.offer { background: #fff; padding: 36px 44px; border: 1px solid var(--border); border-radius: 8px; max-width: 840px; margin: 0 auto; }
.offer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.offer h1 { font-family: var(--mono); font-size: 1.2rem; font-weight: 500; }
.offer h2 { font-family: var(--mono); font-size: .74rem; color: var(--muted); margin: 22px 0 6px; font-weight: 500; }
.offer .table th, .offer .table td { padding: 5px 8px; }
.fineprint { font-size: .74rem; color: #3f3f46; }

/* ── accessibility ── */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.status-bar :focus-visible { outline-color: #f9a8d4; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.list-title { font-weight: 500; }
.list-meta { display: none; }
/* The order list has to fit the 1240px page with the admin columns: long statuses ("Eingereicht – in Prüfung
   bei Dahlia") wrap instead of pushing the table into a horizontal scrollbar (Torsten, 2026-11-19). */
.list-table .status-col .badge { white-space: normal; display: inline-block; }
.list-table td.pick { white-space: nowrap; }
.list-table td.pick input { margin: 0 4px 0 0; vertical-align: -2px; }
.list-table tr.picked { background: var(--info-bg); }
/* Green once orders are ticked, grey until then (Torsten, 2026-11-19). */
#pool-button:not(:disabled), .pill.go { background: var(--ok); color: #fff; }
#pool-button:not(:disabled):hover, .pill.go:hover { background: #065f46; color: #fff; }  /* green: "New order" (Torsten, 2026-11-23) */
#pool-button:disabled { opacity: .45; cursor: not-allowed; }
.bom th.qty, .bom td.qty { text-align: right; white-space: nowrap; }
.bom .bom-machine { font-weight: 400; text-transform: none; }
.bom td.zero { color: var(--faint); }
.bom td.total { font-weight: 600; }

/* ── responsive ── */
@media (max-width: 960px) { .grid { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  /* compact navbar: logo + title on one row, links on a second row; no username pill */
  .navbar { padding: 8px 12px; gap: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
  .navbar { position: relative; }
  .user-info-bar .lang-switch { position: absolute; top: 10px; right: 12px; margin: 0; }
  .logo-container { gap: 10px; }
  .logo-image { height: 28px; } .logo-title { font-size: 15px; } .logo-subtitle { display: none; }
  .user-info-bar { width: 100%; gap: 2px; margin: 0 -8px; }
  .user-info-bar a, .user-info-bar button { min-height: 40px; padding: 8px 10px; display: inline-flex; align-items: center; font-size: 13px; }
  .user-info-bar form:not(.lang-switch) { margin-left: auto; }
  .user-info-bar .lang-switch button { min-height: 40px; padding: 6px 10px; }
  .user-name { display: none; }
  .main-content { padding: 12px 12px 130px; }

  .status-bar { padding: 12px 14px; gap: 8px 14px; }
  .status-bar-title { width: 100%; font-size: .95rem; }
  .status-chips { gap: 6px 12px; }
  .status-bar .right { margin-left: 0; width: 100%; }
  .pill { padding: 7px 10px; }

  .card-head { padding: 10px 12px; }
  .card-head .right { margin-left: 0; }
  .card-body { padding: 12px; }
  .step { padding: 12px; gap: 8px; } .step-n { width: 30px; }

  /* 16px inputs stop iOS from zooming in on focus; 44px touch targets */
  input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea { font-size: 16px; min-height: 44px; }
  input[type=text], input[type=search], input[type=date], select, textarea { width: 100%; }
  textarea { min-height: 88px; }
  .step-body div > div > label:has(> input) { min-height: 40px; padding: 8px 12px; font-size: .85rem; }
  .sl, button, .button { min-height: 40px; }
  .missing-row .sl { min-height: 34px; padding: 4px 10px; }
  label.inline { padding: 6px 0; }
  .field-row { flex-direction: column; gap: 0; }
  .q-images figure { flex-basis: 100%; }
  .field-row label, table.cables { width: 100%; }
  .sensor-row { grid-template-columns: 1fr; }

  /* order list as stacked rows */
  .list-table thead { display: none; }
  .list-table, .list-table tbody, .list-table tr, .list-table td { display: block; width: 100%; }
  .list-table tr { padding: 12px; border-bottom: 1px solid var(--border); }
  .list-table tr:last-child { border-bottom: 0; }
  .list-table td { padding: 0; border: 0; }
  .list-table .list-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0 10px; font-size: .78rem; color: var(--muted); }
  .list-table .hide-mobile, .list-table .status-col { display: none; }
  .filters { padding: 12px; }
  .filters input[type=search] { min-width: 0; flex-basis: 100%; }
  .filters select { flex: 1; width: auto; }

  /* answer tables: number + label on one line, value below */
  .kv, .kv tbody, .kv tr { display: block; width: 100%; }
  .kv tr { display: grid; grid-template-columns: 40px 1fr; padding: 8px 12px; border-bottom: 1px solid var(--border); }
  .kv td { display: block; padding: 0; border: 0; width: auto !important; }
  .kv td:nth-child(3) { grid-column: 2; font-weight: 500; }

  .save-bar { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .save-bar-inner button { flex: 1; justify-content: center; min-height: 44px; }
  #autosave-status { width: 100%; }
  .hide-mobile { display: none; }
  .offer { padding: 20px; }
  .offer-head { flex-direction: column; }
}
@media print {
  .impersonate-bar { display: none; }
  .navbar, .noprint, .flash { display: none !important; }
  body { background: #fff; } .main-content { padding: 0; } .offer { border: 0; padding: 0; }
}

/* Discussion threads (per question and general) */
.threads { margin-top: 8px; }
.threads .thread-error { color: var(--err); font-size: .8rem; margin: 4px 0; }
.thread { border: 1px solid var(--border); border-left: 3px solid var(--warn-line); border-radius: 4px; margin: 6px 0; background: var(--surface); }
.thread.resolved { border-left-color: var(--ok-line); }
.thread.resolved .msg { opacity: .7; }
.thread .msg { padding: 6px 10px; border-bottom: 0; }
.thread .msg.reply { margin-left: 14px; border-top: 1px dashed var(--border); }
.thread .msg.dahlia { box-shadow: inset 3px 0 0 var(--ink); }
.thread-event { margin-left: 14px; padding: 2px 10px; font-family: var(--mono); font-size: .66rem; color: var(--muted); border-top: 1px dashed var(--border); }
.thread-actions { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; padding: 6px 10px; border-top: 1px solid var(--border); }
.thread-actions textarea { flex: 1 1 220px; min-width: 0; margin: 0; }
.thread-new > summary { cursor: pointer; font-size: .8rem; color: var(--muted); text-decoration: underline; margin: 4px 0; }
.thread-new .thread-actions { border-top: 0; padding: 4px 0; }
.q-open { font-family: var(--mono); font-size: .66rem; margin-left: 6px; }
[data-open-wrap][hidden], .threads [hidden] { display: none !important; }

/* Order history */
.hist { padding: 8px 16px; border-top: 1px solid var(--border); }
.hist .meta { font-family: var(--mono); font-size: .66rem; color: var(--muted); margin-bottom: 3px; }
.hist-rows { font-size: .78rem; margin: 0; }
.hist-rows td { padding: 2px 6px 2px 0; vertical-align: top; border: 0; }
.hist-rows td.old { color: var(--muted); text-decoration: line-through; }
.hist-rows td.arrow { color: var(--faint); }

/* Explanation editor (admins/staff): images + texts per question */
.qhelp-bar { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.qhelp-add > summary, .qhelp-tools > summary { cursor: pointer; font-size: .78rem; color: var(--link); margin: 2px 0; }
.qhelp-add[open] { flex-basis: 100%; }
.qhelp-form { display: grid; gap: 6px; padding: 8px; border: 1px dashed var(--info-line); background: var(--info-bg); border-radius: 4px; margin: 4px 0; }
.qhelp-form label { font-size: .75rem; color: var(--muted); }
.qhelp-form textarea { width: 100%; box-sizing: border-box; }
.qhelp-form .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.qhelp-drop { border: 2px dashed var(--info-line); border-radius: 6px; padding: 18px 12px; text-align: center; font-size: .8rem; color: var(--muted); background: var(--surface); cursor: pointer; }
.qhelp-drop:focus { outline: 2px solid var(--brand); outline-offset: 2px; }
.qhelp-drop.over { border-color: var(--info); background: var(--info-bg); }
.qhelp-preview { max-width: 100%; max-height: 220px; display: block; margin: 0 auto; }
.qhelp-error { color: var(--err); font-size: .8rem; margin: 4px 0; }
.qhelp-tools .qhelp-form { min-width: 240px; }
button.link.danger { color: var(--err); }
.small { font-size: .72rem; }
[data-not-order] [hidden], .qhelp-error[hidden] { display: none !important; }

/* Hide / show a question (admins): a hidden question collapses to its title + "Show again" */
.qvis { font-size: .74rem; margin: 0 0 4px; }
.qvis .qvis-hide { color: var(--muted); }
.qvis .qvis-note { display: none; font-family: var(--mono); font-size: .68rem; color: var(--warn); }
.step.q-hidden { background: repeating-linear-gradient(-45deg, var(--head), var(--head) 8px, var(--bg) 8px, var(--bg) 16px); }
.step.q-hidden .step-title { color: var(--faint); text-decoration: line-through; }
.step.q-hidden .qvis .qvis-hide, .step.q-hidden .qhelp-text, .step.q-hidden .step-media, .step.q-hidden .step-main { display: none; }
.step.q-hidden .qvis .qvis-note { display: inline; }

/* ── terms and conditions per order (admins, orders/terms_views.py) ── */
.terms-page { max-width: 920px; margin: 0 auto; }
.terms-warn { font-size: .82rem; padding: 10px 14px; border-radius: 6px; margin-bottom: 12px;
  border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.terms-warn strong { display: block; margin-bottom: 2px; }
.terms-hint { font-size: .78rem; margin: 0 0 10px; }
.terms-confirm { color: var(--warn); font-weight: 500; margin: 6px 0; }
.terms-note { font-size: .78rem; margin: 2px 0 4px; }
.terms-lang { font-size: .62rem; margin-top: 4px; }
.terms-diff { font-family: var(--mono); font-size: .72rem; margin: 4px 0; padding: 6px 8px; background: var(--head);
  border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.terms-diff .add { color: var(--ok); } .terms-diff .del { color: var(--err); text-decoration: line-through; }
.terms-full summary { font-size: .72rem; color: var(--muted); cursor: pointer; }
.terms-page input[name=note] { width: 100%; box-sizing: border-box; }

/* ── terms sets (orders/termset_views.py) and one-click buttons ── */
.set-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.set-buttons form { margin: 0; }
.set-buttons .set-active { border-color: var(--ok-line); color: var(--ok); background: var(--ok-bg); opacity: 1; cursor: default; }
.set-buttons .set-manage { font-size: .74rem; margin-left: 4px; }
.set-label { font-family: var(--mono); font-size: .66rem; color: var(--muted); margin-bottom: 2px; }
.offer-admin { margin-bottom: 12px; }
.offer-layout.with-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.offer-layout.with-side .offer { max-width: none; margin: 0; }
.offer-side { position: sticky; top: 12px; }
.offer-side label { display: block; margin-bottom: 8px; }
.offer-side label input[type=text] { display: block; width: 100%; margin-top: 3px; }
.offer-side ul.plain li { margin-bottom: 6px; overflow-wrap: anywhere; }
.pool-delete { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; }
.offer-send { margin: 8px 0 4px; }
.warn-text { color: var(--warn); }
.offer-stale { border-left: 3px solid var(--warn); background: var(--warn-bg, #fff6e0); padding: 8px 10px; margin: 8px 0; font-size: .92em; }
.offer-stale ul { margin: 4px 0; }
.locked { border-left: 3px solid var(--ok-line); padding-left: 8px; }
button.send { background: var(--ok); border-color: var(--ok); color: #fff; width: 100%; justify-content: center; }
button.send:hover { background: #065f46; border-color: #065f46; color: #fff; }
.offer-latest { margin: 0 0 6px; line-height: 1.6; }
.offer-history { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.offer-history summary { cursor: pointer; font-size: .8rem; color: var(--muted); }
.offer-history .revisions li { margin: 6px 0; font-size: .8rem; }
.inline-form { display: inline; margin: 0; }
@media (max-width: 960px) { .offer-layout.with-side { grid-template-columns: minmax(0, 1fr); } .offer-side { position: static; order: -1; } }
@media print { .offer-layout.with-side { display: block; } }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 4px; }
.tabs [data-tab] { border: 1px solid transparent; border-bottom: 0; border-radius: 5px 5px 0 0; background: none;
  margin-bottom: -1px; padding: 7px 12px; color: var(--muted); font-size: .8rem; }
.tabs [data-tab]:hover { background: var(--head); color: var(--ink); }
.tabs [data-tab][aria-selected=true] { background: #fff; border-color: var(--border); color: var(--ink); font-weight: 600; }
.tab-panel.inactive { display: none; }
@media print { .tab-panel.inactive { display: block; } }
.offer-admin .card-body { padding-top: 8px; padding-bottom: 8px; }
.termsets td { vertical-align: middle; }
.termsets .archived td { opacity: .55; }

/* The hidden attribute must win over display rules like `.step { display: flex }`; without this,
   questions that don't apply (e.g. 4.4.4–4.4.6 with identical solenoids) stayed visible. */
[hidden] { display: none !important; }

/* ── foldable form sections and sub-questions ── */
details.fold > summary.card-head { border-bottom: 0; }
details.fold[open] > summary.card-head { border-bottom: 1px solid var(--border); }
details.fold > summary .card-name { font-size: .95rem; }
details.fold > summary:hover { background: #f1f1f3; }
.sec-counts { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.fold-tools { font-size: .78rem; color: var(--faint); margin: -4px 0 10px; text-align: right; }

/* Three levels: plain question (3.4) · question with sub-questions (3.5, or a group heading like 4.1)
   · sub-question (3.5.1). The parent is a tinted header band; a rail runs from its number past its
   sub-questions (a tick to each, a corner at the last one). The status bar (.has-missing etc.) stays
   on the card's left edge for every row, so it never looks like an indent. */
details.fold .step-n { color: var(--muted); }  /* form rows only; other step lists keep --faint */
.step.parent { background-color: var(--head); }
.step.parent:hover { background-color: #f1f1f3; }
.step.parent > .step-n { color: var(--ink); font-weight: 600; font-size: .72rem; padding-top: 3px; }
.step.parent > .step-body > .step-head .step-title, .group-head .step-title { font-weight: 600; font-size: .95rem; }
.step.parent, .step.sub { position: relative; --rail-x: 22px; --sub-pad: 44px; }
.step.sub { padding-left: var(--sub-pad); background-repeat: no-repeat;
  background-size: calc(100% - var(--sub-pad)) 1px; background-position: var(--sub-pad) 100%; }
.step.sub::before, .step.sub::after, .step.parent::after { content: ""; position: absolute; left: var(--rail-x); background: #d4d4d8; }
.step.sub::before { top: -1px; height: 25px; width: 1px; }   /* └ : rail down to the tick */
.step.sub::after { top: 23px; width: 14px; height: 1px; }      /* the tick */
.step.parent::after { top: 36px; bottom: -1px; width: 1px; display: none; }
.step.sub .step-n { width: 40px; color: var(--ink-2); font-weight: 500; }
.step.sub .step-n .n-pre { color: var(--faint); font-weight: 400; }
.step.sub .step-title { font-size: .82rem; }
/* When another visible sub-question follows (rows that don't apply are [hidden], up to three in a
   row, e.g. 4.4.4–4.4.6). Then the rail runs on to the row's bottom and the separator below is inset.
   Without it the row is the group's last: the rail ends at the tick and a full-width line closes it. */
.step.parent:is(:has(+ .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden])))::after { display: block; }
.step.sub:is(:has(+ .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden]))) {
  border-bottom-color: transparent; background-image: linear-gradient(var(--border), var(--border)); }
.step.sub:is(:has(+ .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden])),
  :has(+ .step.sub[hidden] + .step.sub[hidden] + .step.sub[hidden] + .step.sub:not([hidden])))::before { height: auto; bottom: -1px; }

/* ── toggle buttons for questions with two answers ── */
/* !important: the generic chip rules above use :has() and are more specific */
.step-body div.toggle { display: inline-flex !important; gap: 0 !important; flex-wrap: nowrap !important; }
.step-body div.toggle > div > label { border-radius: 0 !important; margin-left: -1px !important; min-width: 64px; justify-content: center; }
.step-body div.toggle > div:first-child > label { border-radius: 5px 0 0 5px !important; margin-left: 0 !important; }
.step-body div.toggle > div:last-child > label { border-radius: 0 5px 5px 0 !important; }
.step-body div.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.step-body div.toggle > div > label:has(> input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 1px; }

/* "OR" between alternative fields (resistance OR rated current) */
.or-sep { align-self: center; font: 600 .72rem var(--mono); color: var(--muted); padding: 14px 2px 0; }

/* requested vs. confirmed delivery date */
.delivery-note { font-size: .76rem; margin-top: 6px; padding: 5px 10px; border-radius: 5px; border: 1px solid var(--warn-line);
  background: var(--warn-bg); color: var(--warn); }
.delivery-note.confirmed { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok); }
@media (max-width: 700px) {
  .step.parent, .step.sub { --rail-x: 16px; --sub-pad: 34px; }
  .step.sub::after { width: 12px; }
  .step.sub .step-n { width: 36px; }
  .or-sep { padding: 0; }
}
.basics td:first-child { width: 46%; color: var(--muted); }
.small { font-size: .76rem; }
.delivery-form input[type=text] { width: 12em; }
.group-head .step-body { display: block; }

/* ── machine drawing (section 6, orders/static/orders/cable_layout.js) ── */
.layout-step .step-body { display: block; }
.layout-ui { display: grid; gap: 10px; min-width: 0; }
.layout-tools { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; font-size: .8rem; }
.layout-tool { display: inline-flex; gap: 8px; align-items: center; }
.lseg { display: inline-flex; }
.lseg button { border-radius: 0; margin-left: -1px; padding: 4px 10px; background: var(--surface); }
.lseg button:first-child { border-radius: 5px 0 0 5px; margin-left: 0; }
.lseg button:last-child { border-radius: 0 5px 5px 0; }
.lseg button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.layout-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .74rem; color: var(--muted); }
.layout-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border: 1.5px solid #27272a; border-radius: 2px; }
.sw-tractor { background: #ececec; } .sw-implement { background: #9ca3af; } .sw-agai { background: #fde047; }
.sw-crop { border: 0; border-left: 3px dotted #16a34a; width: 3px; border-radius: 0; }
.layout-frame { position: relative; border: 1px dashed var(--border); border-radius: 6px; background: var(--surface); }
.layout-view { position: absolute; top: 8px; right: 8px; z-index: 2; }
.layout-drawing { position: relative; overflow-x: auto; min-height: 60px; }
.layout-drawing svg { display: block; }
.layout-drawing svg text { font-family: var(--mono); font-size: 11px; fill: var(--muted); }
.layout-drawing svg text.lbl { fill: var(--ink); font: 600 12.5px var(--sans); }
.layout-drawing svg text.view { fill: var(--ink); font: 600 13px var(--sans); }
.layout-drawing svg text.dimtext { fill: #2563eb; cursor: pointer; }
.layout-drawing .dim { cursor: pointer; outline: none; }
.layout-drawing .dim rect { fill: var(--info-bg); stroke: #2563eb; stroke-width: 1; }
.layout-drawing .dim text { fill: #2563eb; font-weight: 600; }
.layout-drawing .dim.example rect { stroke-dasharray: 3 2; }
.layout-drawing .dim:hover rect, .layout-drawing .dim:focus-visible rect { fill: #2563eb; }
.layout-drawing .dim:hover text, .layout-drawing .dim:focus-visible text { fill: #fff; }
.layout-edit { position: absolute; width: 84px; font: 600 12px var(--mono); padding: 3px 6px; border: 2px solid #2563eb;
  border-radius: 4px; background: var(--surface); text-align: center; }
.layout-empty { margin: 0; padding: 16px; font-size: .8rem; color: var(--muted); }
.layout-msg { font-size: .78rem; color: var(--warn); min-height: 1.2em; }
.sugg-wrap { overflow-x: auto; }
table.sugg td, table.sugg th { white-space: nowrap; font-size: .8rem; padding: 4px 12px 4px 0; }
table.sugg .num { text-align: right; }
table.sugg tr[data-paths]:hover { background: var(--info-bg); }
.sugg-head { margin-bottom: 6px; }

/* Commercial review (orders/offers.py) */
#commercial form { display: flex; flex-direction: column; gap: 8px; }
#commercial form + form { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
#commercial p { margin: 0; }
fieldset.pool { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
fieldset.pool legend { font-size: .76rem; color: var(--muted); padding: 0 4px; }
ul.plain { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 6px; }
.parts-totals td.num { font-family: var(--mono); text-align: right; width: 4em; }

/* Commercial to-do count in the navbar (orders/context.py) */
.nav-count { display: inline-block; min-width: 1.4em; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: .75em; text-align: center; }
/* Long state badges in the narrow side column wrap instead of running out of the card (2026-11-19). */
.offer-latest .badge { white-space: normal; display: inline-block; max-width: 100%; }
/* Order page: the answer and the threads of the question the user jumped to (question_focus.js) */
.thread-group, tr[data-answer] { scroll-margin-top: 16px; }
.thread-group { border-radius: 8px; padding: 0 8px; margin: 0 -8px; transition: background-color .3s, box-shadow .3s; }
.thread-group.q-focus { background: var(--warn-bg); box-shadow: inset 4px 0 0 var(--warn); }
tr.q-focus > td { background: var(--warn-bg); }
tr.q-focus > td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
.q-flash { animation: q-flash 1.6s ease-out 1; }
@keyframes q-flash { 0%, 30% { outline: 3px solid var(--warn); outline-offset: 2px; } 100% { outline: 3px solid transparent; outline-offset: 2px; } }
.back-to-answer { display: inline-block; margin: 2px 0 8px; }
@media (prefers-reduced-motion: reduce) { .q-flash { animation: none; } }

/* Footer: imprint and privacy links on every page */
.site-footer { text-align: center; font-size: .75rem; color: #71717a; padding: 24px 16px 32px; }
.site-footer a { color: #71717a; }
