:root {
  /* Palette after kbw-walzen.de: slate header #597580, teal #2ba0a3, orange highlights #ff7600, text #242930 / #5a5d62.
     --brand is the site's teal for decoration (progress, active tab, top strip); --accent is a darker teal that keeps
     white button text and teal link text at WCAG AA contrast. */
  --bg: #f1f4f5;
  --surface: #ffffff;
  --surface-2: #f6f8f8;
  --border: #dce3e6;
  --border-strong: #c2ccd0;
  --text: #242930;
  --muted: #5a5d62;
  --faint: #6b7176;
  --brand: #2ba0a3;
  --accent: #187679;
  --accent-hover: #125e61;
  --accent-soft: #e1f1f1;
  --on-accent: #ffffff;
  --focus: rgba(43, 160, 163, 0.32);
  --topbar: #597580;
  --topbar-text: #ffffff;
  --sheet-bg: #e8eef0;
  --stated-bg: #e3f2e8; --stated: #1f6b45;
  --derived-bg: #e4ecef; --derived: #3b5868;
  --absent-bg: #edeff0; --absent: #5a5d62;
  --review-bg: #fff0e2; --review: #a14a00; --review-line: #ff7600;
  --edited-bg: #eeebf6; --edited: #5b4a8c; --edited-line: #8c7bc0;
  --danger: #b42318; --danger-bg: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36, 41, 48, 0.05), 0 1px 3px rgba(36, 41, 48, 0.07);
  --mono: ui-monospace, 'SFMono-Regular', 'DejaVu Sans Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #161b1f; --surface: #1e252b; --surface-2: #242c33; --border: #313b43; --border-strong: #43505a;
    --text: #e7ebed; --muted: #a7b1b7; --faint: #87929a;
    --brand: #3db3b6; --accent: #3db3b6; --accent-hover: #5cc4c6; --accent-soft: #163536; --on-accent: #0e2223;
    --focus: rgba(61, 179, 182, 0.35);
    --topbar: #2c3c47; --sheet-bg: #12171b;
    --stated-bg: #15301f; --stated: #7fd29d; --derived-bg: #1d2d35; --derived: #a3c0ce;
    --absent-bg: #252c32; --absent: #a7b1b7; --review-bg: #3a2412; --review: #ffab66; --review-line: #ff7600;
    --edited-bg: #2a2340; --edited: #c6b8f0; --edited-line: #8c7bc0;
    --danger: #f28b82; --danger-bg: #3b1a17;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #161b1f; --surface: #1e252b; --surface-2: #242c33; --border: #313b43; --border-strong: #43505a;
  --text: #e7ebed; --muted: #a7b1b7; --faint: #87929a;
  --brand: #3db3b6; --accent: #3db3b6; --accent-hover: #5cc4c6; --accent-soft: #163536; --on-accent: #0e2223;
  --focus: rgba(61, 179, 182, 0.35);
  --topbar: #2c3c47; --sheet-bg: #12171b;
  --stated-bg: #15301f; --stated: #7fd29d; --derived-bg: #1d2d35; --derived: #a3c0ce;
  --absent-bg: #252c32; --absent: #a7b1b7; --review-bg: #3a2412; --review: #ffab66; --review-line: #ff7600;
  --edited-bg: #2a2340; --edited: #c6b8f0; --edited-line: #8c7bc0;
  --danger: #f28b82; --danger-bg: #3b1a17;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 58px; padding: 8px 24px;
  background: var(--topbar); color: var(--topbar-text);
  border-top: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 12px; }
/* The brand links to the customer configurator, on every page. */
a.brand { margin: -4px -8px; padding: 4px 8px; border-radius: 8px; color: inherit; text-decoration: none; }
a.brand:hover { background: rgba(255, 255, 255, 0.1); }
.brand-mark { width: 30px; height: 30px; color: #ffffff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; letter-spacing: 0.01em; }
.brand-text span { font-size: 12px; opacity: 0.7; }
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 12.5px; white-space: nowrap;
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: #8a949e; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.logout { margin: 0; }
.topbar-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22); background: transparent; color: inherit; font-size: 13px; cursor: pointer;
}
.topbar-btn:hover { background: rgba(255, 255, 255, 0.12); }
.topbar-btn svg { width: 16px; height: 16px; }
.badge.ok .badge-dot { background: #4cc38a; }
.badge.offline .badge-dot { background: #f0645a; }

/* ------------------------------------------------------------ layout */

/* A container: the layout follows the width left next to the assistant panel, not the window width. */
main { max-width: 1520px; margin: 0 auto; padding: 24px 24px 56px; container-type: inline-size; }
.view-narrow { max-width: 640px; margin: 5vh auto 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.link-btn {
  padding: 2px 0; border: 0; background: none; cursor: pointer;
  color: var(--accent); font-weight: 600; font-size: 13.5px;
}
.link-btn:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------ upload */

.hero { padding: 36px 36px 30px; }
.hero h1 { font-size: 26px; margin-bottom: 8px; }
.lead { color: var(--muted); margin: 0 0 24px; }

.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 36px 20px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: 12px;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone-icon { width: 48px; height: 48px; color: var(--accent); margin-bottom: 6px; }
.dropzone strong { font-size: 16px; }
.dropzone span { color: var(--muted); }
.dropzone small { color: var(--faint); margin-top: 6px; }
.fake-link { color: var(--accent) !important; font-weight: 600; text-decoration: underline; }

.privacy { display: flex; align-items: center; gap: 8px; margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.privacy svg { width: 16px; height: 16px; flex: none; color: var(--stated); }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--faint); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.error-text { color: var(--danger); margin: 12px 0 0; font-size: 14px; }

/* ------------------------------------------------------------ progress */

.progress-card { padding: 32px 36px; }
.file-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 5px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--muted);
}
.file-pill svg { width: 16px; height: 16px; flex: none; }
.file-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-card h2 { font-size: 21px; margin: 18px 0 18px; }
.progressbar { height: 10px; border-radius: 999px; background: var(--absent-bg); overflow: hidden; }
.progressbar-fill {
  height: 100%; width: 0; border-radius: inherit;
  background-color: var(--brand);
  background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.18) 50%, rgba(255, 255, 255, 0.18) 75%, transparent 75%);
  background-size: 22px 22px;
  animation: stripes 0.9s linear infinite;
  transition: width 0.4s ease;
}
.progressbar.is-done .progressbar-fill { animation: none; background-image: none; background-color: var(--stated); }
.progressbar.is-error .progressbar-fill { animation: none; background-image: none; background-color: var(--danger); }
@keyframes stripes { to { background-position: 22px 0; } }
.progress-meta { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }

.stages { list-style: none; display: flex; gap: 8px; padding: 0; margin: 24px 0 0; }
.stages li {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--faint);
}
.stage-dot { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid var(--border-strong); }
.stages li.is-active { color: var(--text); border-color: var(--accent); }
.stages li.is-active .stage-dot { border-color: var(--accent); border-right-color: transparent; animation: spin 0.8s linear infinite; }
.stages li.is-done { color: var(--text); }
.stages li.is-done .stage-dot { border-color: var(--stated); background: var(--stated); box-shadow: inset 0 0 0 2px var(--surface); }
@keyframes spin { to { transform: rotate(360deg); } }
.elapsed { margin: 18px 0 0; color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }
.error-box { margin-top: 20px; padding: 14px 16px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); }
.error-box p { margin: 4px 0 12px; }

/* ------------------------------------------------------------ configurator */

.source-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 14px 18px; margin-bottom: 20px;
}
.source-file { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 300px; }
.source-file svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
.source-file div { display: flex; flex-direction: column; min-width: 0; }
.source-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-file span { color: var(--muted); font-size: 13px; }
.source-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.config-grid { display: grid; grid-template-columns: minmax(360px, 460px) minmax(0, 1fr); gap: 20px; align-items: start; }
.config-side { position: sticky; top: 16px; display: grid; gap: 20px; min-width: 0; }

/* Each group is an accordion panel (panels.js): header button, summary when collapsed, body with the fields. */
.group { --pad: 20px; padding: 0 var(--pad); margin-bottom: 20px; }
.group-head { font-size: 16px; }
.group-toggle {
  display: flex; align-items: center; gap: 10px; width: calc(100% + 2 * var(--pad)); margin: 0 calc(-1 * var(--pad));
  padding: 16px var(--pad); border: 0; border-radius: var(--radius); background: none;
  color: inherit; font: inherit; font-weight: 700; text-align: left; cursor: pointer;
}
.group:not(.is-collapsed) .group-toggle { padding-bottom: 6px; }
.group-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-num {
  display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 13px;
}
.group-num svg { width: 16px; height: 16px; }
.group.is-complete .group-num { background: var(--stated-bg); color: var(--stated); }
.group-badge {
  display: inline-flex; align-items: center; gap: 5px; flex: none; padding: 3px 9px 3px 7px; border-radius: 999px;
  background: var(--review-bg); color: var(--review); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.group-badge svg { width: 14px; height: 14px; }
.group-action { display: inline-flex; align-items: center; gap: 4px; flex: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.group-action svg { width: 16px; height: 16px; }
.group.is-collapsed .group-action, .group-toggle:hover .group-action { color: var(--accent); }

.group-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.25s ease; }
.group.is-collapsed .group-body { grid-template-rows: 0fr; }
.group.no-anim .group-body { transition: none; }
/* Clips while collapsing. Horizontal padding only (vertical padding would stay visible when collapsed); it keeps
   the fields' status bar, left of each field, inside the clip. */
.group-inner { min-height: 0; overflow: hidden; margin: 0 calc(-1 * var(--pad)); padding: 0 var(--pad); }
.group-inner > .field:first-child { border-top: 0; }
.group-inner::after { content: ''; display: block; height: 6px; }

.group-summary {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 0 16px;
  margin: -6px 0 0; padding-bottom: 16px; font-size: 14px; cursor: pointer;
}
.group-summary > div { padding: 6px 0; border-top: 1px solid var(--border); }
.group-summary > .is-wide { grid-column: 1 / -1; }
.group-summary dt { font-size: 12px; color: var(--muted); }
.group-summary dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.group-summary small { font-size: 11.5px; font-weight: 500; color: var(--faint); }
.group-summary .is-review dd, .group-summary .is-missing dd { color: var(--review); }
.group-summary .is-invalid dd { color: var(--danger); }

.field { position: relative; padding: 14px 0; border-top: 1px solid var(--border); }
.field::before {
  content: ''; position: absolute; left: -20px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0;
  background: transparent; transition: background 0.2s;
}
.field.is-review::before { background: var(--review-line); }
.field.is-edited::before { background: var(--edited-line); }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.field-head label, .field-head .label { font-weight: 600; font-size: 14px; }
.field-help { margin: 6px 0 0; color: var(--faint); font-size: 12.5px; }
.field-foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.field-foot:empty { display: none; }
.foot-label { font-weight: 600; color: var(--faint); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.06em; }
.evidence { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); quotes: none; }
.derived { margin: 2px 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.derived.is-error { background: var(--danger-bg); color: var(--danger); }

.chip { padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; cursor: default; }
.chip-stated { background: var(--stated-bg); color: var(--stated); }
.chip-derived { background: var(--derived-bg); color: var(--derived); }
.chip-absent { background: var(--absent-bg); color: var(--absent); }
.chip-review { background: var(--review-bg); color: var(--review); }
.chip-edited { background: var(--edited-bg); color: var(--edited); }
.chip-recommended { background: var(--accent-soft); color: var(--accent); }

/* Simple and advanced view (usage.js, HLR-104): each shows only its own parts of the form. */
body:not([data-view='simple']) [data-view-only='simple'], body:not([data-view='advanced']) [data-view-only='advanced'] { display: none !important; }
.source-actions { align-items: center; }
.view-switch { display: inline-flex; padding: 3px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-2); }
.view-switch button { padding: 6px 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.view-switch button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.recommendation { margin: 2px 0 14px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 13.5px; }
.recommendation h3 { font-size: 14px; }
.recommendation p { margin: 8px 0 0; color: var(--muted); }
.recommendation .recommendation-lead { margin: 0; color: var(--text); }
.recommendation-list { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 14px; margin: 8px 0 0; }
.recommendation-list dt { color: var(--muted); }
.recommendation-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.recommendation-list small { margin-left: 6px; color: var(--faint); font-size: 11.5px; font-weight: 500; }
.recommendation .recommendation-warning { padding: 8px 10px; border-radius: 8px; background: var(--review-bg); color: var(--review); }
.recommendation .link-btn { margin-top: 8px; }

.input-unit {
  display: flex; align-items: stretch; min-width: 0;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-unit:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input-unit input { flex: 1; min-width: 0; padding: 9px 12px; border: 0; background: transparent; outline: none; font-variant-numeric: tabular-nums; }
.input-unit .unit { display: flex; align-items: center; padding: 0 12px; color: var(--muted); background: var(--surface-2); border-left: 1px solid var(--border); font-size: 13.5px; }
.input-unit:has(input[aria-invalid='true']) { border-color: var(--danger); }
.input-unit.sm input { padding: 6px 8px; }
.input-unit.sm .unit { padding: 0 8px; font-size: 12.5px; }

select, .input-swatch input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
}
select:focus, .input-swatch input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); outline: none; }
select.sm { padding: 6px 8px; }
.field.is-review .input-unit, .field.is-review select, .field.is-review .tags { border-color: var(--review-line); }

.input-swatch { position: relative; }
.input-swatch input { padding-left: 40px; }
.swatch { position: absolute; left: 11px; top: 50%; width: 20px; height: 20px; margin-top: -10px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.25); }
.swatch.is-empty { background-image: linear-gradient(135deg, transparent 45%, var(--border-strong) 45%, var(--border-strong) 55%, transparent 55%) !important; }

.tags {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 42px; padding: 5px 6px; cursor: text;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
}
.tags:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.tag { display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; border-radius: 6px; background: var(--accent-soft); color: var(--text); font-size: 13.5px; font-weight: 600; }
.tag-x { width: 22px; height: 22px; border: 0; border-radius: 4px; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.tag-x:hover { background: rgba(0, 0, 0, 0.08); color: var(--text); }
.tag-entry { flex: 1; min-width: 90px; border: 0; padding: 4px 6px; background: transparent; outline: none; }
.tag-entry[aria-invalid='true'] { color: var(--danger); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); transition: background 0.15s; }
.switch-track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.subfields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.subfields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.list { display: grid; gap: 6px; }
.list-row { display: grid; gap: 6px; align-items: center; }
.list-row.chamfers { grid-template-columns: 1.1fr 1.2fr 1fr 32px; }
.list-row.grooves { grid-template-columns: 1.3fr 0.85fr 1fr 1fr 32px; }
.list-head span { font-size: 11.5px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.list-empty { margin: 0; color: var(--faint); font-size: 13.5px; }
.list-actions { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; }
.icon-btn { width: 32px; height: 32px; border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; color: var(--muted); font-size: 18px; }
.icon-btn:hover { border-color: var(--border); background: var(--surface-2); color: var(--danger); }

/* ------------------------------------------------------------ side panel */

.viewer-card { overflow: hidden; }
.tab-panel.diagram { padding: 12px; background: var(--sheet-bg); }
.diagram svg { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 3px rgba(36, 41, 48, 0.15); }

.tabs { display: flex; gap: 4px; padding: 0 10px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { flex: none; white-space: nowrap; padding: 12px 10px 10px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--brand); }
.tab .count:not(:empty) { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--review-bg); color: var(--review); font-size: 12px; }
.tab-panel { padding: 16px; }

.dropzone-sm { padding: 28px 16px; }
.dropzone-sm .dropzone-icon { width: 40px; height: 40px; }
.attach-note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.attach-progress .progressbar { margin-top: 16px; }

.pages { display: grid; gap: 12px; }
.pages a { display: block; }
.pages img { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.page { margin: 0; }
.page-tools { display: flex; justify-content: flex-end; gap: 6px; margin-bottom: 8px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
/* Turned pages (app.js rotatePage): --angle is the turn, --ratio the image's width / height. Sideways, the frame takes the
   swapped aspect ratio and the image, as wide as the frame is high, is turned around the frame's centre. */
.page .page-frame img { transform: rotate(var(--angle, 0deg)); }
.page.is-sideways .page-frame { position: relative; aspect-ratio: 1 / var(--ratio); overflow: hidden; }
.page.is-sideways .page-frame img {
  position: absolute; top: 50%; left: 50%; width: calc(var(--ratio) * 100%);
  transform: translate(-50%, -50%) rotate(var(--angle));
}
.page-caption { margin: 4px 0 0; color: var(--faint); font-size: 12px; }
.empty { margin: 0; color: var(--faint); font-size: 14px; }

.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.warnings li { padding: 10px 12px; border-radius: 8px; background: var(--review-bg); color: var(--review); font-size: 14px; }
.warnings li small { display: block; margin-top: 2px; opacity: 0.8; font-family: var(--mono); font-size: 11.5px; }

.json-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.json-head h3 { font-size: 13px; color: var(--muted); }
pre { margin: 0 0 16px; padding: 12px; max-height: 380px; overflow: auto; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font: 12px/1.5 var(--mono); }

/* ------------------------------------------------------------ completion dialog */

.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 64px rgba(16, 22, 27, 0.4);
}
.modal[open] { display: flex; flex-direction: column; animation: modal-in 0.22s ease-out; }
.modal::backdrop { background: rgba(22, 30, 36, 0.62); backdrop-filter: blur(2px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.modal-banner { position: relative; flex: none; height: 160px; background: var(--sheet-bg); }
.modal-banner img { display: block; width: 100%; height: 100%; object-fit: cover; }
.modal-check {
  position: absolute; left: 24px; bottom: -22px; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--stated); color: var(--surface); box-shadow: 0 0 0 4px var(--surface);
}
.modal-check svg { width: 24px; height: 24px; }
.modal-body { padding: 34px 24px 4px; overflow-y: auto; }
.modal-body h2 { font-size: 21px; }
.modal-lead { margin: 6px 0 0; color: var(--muted); }
.modal-section { margin-top: 18px; }
.modal-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); }
.modal-section p { margin: 4px 0 0; font-size: 13.5px; }
.modal-section.is-review, .modal-section.is-kept { padding: 12px 14px 4px; border-radius: 10px; }
.modal-section.is-review { background: var(--review-bg); color: var(--review); }
.modal-section.is-kept { background: var(--edited-bg); color: var(--edited); }
.modal-section.is-review h3, .modal-section.is-kept h3 { color: inherit; }
.modal-list { margin: 6px 0 0; font-size: 14px; }
.modal-list > div { display: grid; grid-template-columns: 11em minmax(0, 1fr); gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.modal-list dt, .modal-list dd { margin: 0; }
.modal-list dt { color: var(--muted); }
.modal-list dd { font-weight: 600; overflow-wrap: anywhere; }
.modal-list.is-tiles { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
.modal-list.is-tiles > div { display: block; padding: 6px 0; }
.modal-list.is-tiles dt { font-size: 12px; }
.modal-section.is-review dt, .modal-section.is-kept dt { color: inherit; opacity: 0.85; }
.modal-section.is-review .modal-list > div, .modal-section.is-kept .modal-list > div { border-top-color: color-mix(in srgb, currentColor 22%, transparent); }
.modal-missing { margin: 16px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-body { padding-bottom: 20px; }
.modal-foot { display: flex; justify-content: flex-end; margin: 0; padding: 16px 24px 18px; border-top: 1px solid var(--border); }
.modal-foot .btn { min-width: 128px; }

/* The field the dialog leads to lights up briefly. */
.field:focus { outline: none; }
.field.is-flash { animation: flash 1.8s ease-out; border-radius: 8px; }
.field.is-review.is-flash { --flash: var(--review-bg); }
@keyframes flash {
  0%, 35% { background: var(--flash, var(--accent-soft)); box-shadow: 0 0 0 10px var(--flash, var(--accent-soft)); }
  100% { background: transparent; box-shadow: 0 0 0 10px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .modal[open] { animation: none; }
  .group-body { transition: none; }
}
@media (max-height: 820px) {
  .modal-banner { height: 112px; }
}

/* ------------------------------------------------------------ assistant (assistant.js) */

:root { --assistant-w: 420px; scrollbar-color: var(--border-strong) transparent; }  /* scrollbars follow the theme */
body { transition: padding-right 0.25s ease; }
/* The open panel pushes the whole page (top bar included) to the left. */
body.assistant-open { padding-right: var(--assistant-w); }

.assistant-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 15;
  display: inline-flex; align-items: center; gap: 10px; padding: 12px 20px 12px 14px;
  border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: 0 8px 24px rgba(16, 22, 27, 0.28);
  transition: background 0.15s, transform 0.15s;
}
.assistant-fab:hover { background: var(--accent-hover); transform: translateY(-1px); }
.assistant-fab svg { width: 26px; height: 26px; }
.assistant-fab svg circle { fill: var(--accent); }
.assistant-fab:hover svg circle { fill: var(--accent-hover); }

.assistant {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: var(--assistant-w);
  display: flex; flex-direction: column; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: -10px 0 30px rgba(16, 22, 27, 0.1);
  animation: assistant-in 0.25s ease-out;
}
@keyframes assistant-in { from { transform: translateX(100%); } }
.assistant-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 10px 11px 16px;
  background: var(--topbar); color: var(--topbar-text); border-top: 3px solid var(--brand);
}
.assistant-avatar { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; }
.assistant-avatar svg { width: 22px; height: 22px; }
.assistant-title { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.25; }
.assistant-title strong { font-size: 15px; }
.assistant-title span { font-size: 12px; opacity: 0.78; }
.assistant-icon { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer; }
.assistant-icon:hover { background: rgba(255, 255, 255, 0.14); }
.assistant-icon svg { width: 18px; height: 18px; }

.assistant-messages { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 16px; overflow-y: auto; background: var(--bg); }
.msg { max-width: 90%; padding: 10px 13px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; overflow-wrap: anywhere; }
.msg-assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-user { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg p { margin: 0; }
.msg p + p, .msg p + ul, .msg p + ol, .msg ul + p, .msg ol + p { margin-top: 8px; }
.msg ul, .msg ol { margin: 6px 0 0; padding-left: 20px; }
.msg li + li { margin-top: 3px; }
.msg-error { align-self: stretch; margin: 0; padding: 9px 12px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); font-size: 13.5px; }
.typing { display: flex; gap: 5px; padding: 14px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.assistant-composer { display: flex; align-items: flex-end; gap: 8px; margin: 0; padding: 12px 12px 6px; border-top: 1px solid var(--border); }
.assistant-composer textarea {
  flex: 1; min-height: 42px; max-height: 140px; padding: 10px 12px; resize: none; overflow-y: hidden;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit;
}
.assistant-composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); outline: none; }
.assistant-send { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.assistant-send:hover { background: var(--accent-hover); }
.assistant-send svg { width: 20px; height: 20px; }
.assistant-send .icon-stop, .assistant-send.is-stop .icon-send { display: none; }
.assistant-send.is-stop .icon-stop { display: block; }
.assistant-note { margin: 0; padding: 0 14px 10px; font-size: 11.5px; color: var(--faint); }

@media (max-width: 760px) {
  /* No room to push: the panel covers the screen. */
  body.assistant-open { padding-right: 0; overflow: hidden; }
  .assistant { width: 100vw; }
  .assistant-fab { right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  body, .assistant { transition: none; animation: none; }
}

/* ------------------------------------------------------------ superuser area (admin.html) */

.chip-danger { background: var(--danger-bg); color: var(--danger); }
a.btn { color: var(--text); text-decoration: none; }
a.btn-primary { color: var(--on-accent); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100dvh - 60px); }
.admin-nav {
  position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; gap: 2px;
  height: calc(100dvh - 60px); padding: 20px 12px; border-right: 1px solid var(--border); background: var(--surface);
}
.admin-link { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-size: 14.5px; font-weight: 600; text-decoration: none; }
.admin-link svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.admin-link:hover { background: var(--surface-2); }
.admin-link.is-active { background: var(--accent-soft); color: var(--accent); }
.admin-link.is-active svg { color: var(--accent); }
.admin-count { margin-left: auto; color: var(--faint); font-size: 12px; }
.admin-nav-label { margin: 18px 12px 6px; color: var(--faint); font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.admin-retention { margin: auto 4px 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; }
/* Not centred like the app's <main>: auto margins would keep it from filling its grid cell (it is a size container). */
.admin-main { min-width: 0; max-width: 1440px; margin: 0; padding: 24px 28px 56px; }
.admin-heading { margin-bottom: 18px; }
.admin-back { display: inline-block; margin-bottom: 8px; font-size: 13.5px; text-decoration: none; }
.admin-heading-text { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }
.admin-heading h1 { font-size: 24px; overflow-wrap: anywhere; }
.admin-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th {
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  color: var(--faint); font-size: 11.5px; letter-spacing: 0.05em; text-align: left; text-transform: uppercase; white-space: nowrap;
}
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: break-word; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr.is-link { cursor: pointer; }
.admin-table tr.is-link:hover td, .admin-table tr.is-link:focus-visible td { background: var(--accent-soft); }
.admin-table tr.is-link:focus-visible { outline: none; }
.admin-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
.admin-stack { display: grid; gap: 20px; min-width: 0; }
.admin-card { padding: 18px 20px; min-width: 0; }
.admin-card .admin-table-wrap { border-radius: 8px; }
.admin-card-title { margin-bottom: 12px; font-size: 16px; }
.admin-page-img { display: block; width: 100%; height: auto; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.admin-raw summary { margin-top: 12px; color: var(--accent); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.admin-raw pre { margin-top: 8px; }
.admin-warnings { margin: 10px 0 0; color: var(--review); font-size: 13px; }
.admin-transcript { display: flex; flex-direction: column; gap: 10px; max-width: 880px; padding: 20px; background: var(--sheet-bg); }
.admin-round { margin: -2px 0 8px; color: var(--muted); font-size: 12.5px; }
.admin-round summary { cursor: pointer; }
.admin-round ul { margin: 6px 0 0; padding-left: 18px; columns: 2; column-gap: 24px; }
.admin-empty, .admin-loading { color: var(--faint); }

/* Owner configurator: index.html with data-mode="owner" on the body (D-015). Each variant shows only its own elements. */
body:not([data-mode='owner']) [data-for='owner'], body[data-mode='owner'] [data-for='customer'] { display: none !important; }
/* The superuser navigation left of the configurator, as in .admin. Without auto margins in the grid cell: main is a
   size container and would shrink to nothing. */
body[data-mode='owner'] .shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100dvh - 60px); }
body[data-mode='owner'] .shell > main { width: 100%; margin: 0; }

/* ------------------------------------------------------------ price panel (pricing.js) */

/* Sketch and price stay in view together: the pinned column scrolls by itself when it is taller than the window. */
.config-side { max-height: calc(100dvh - 32px); overflow-y: auto; scrollbar-width: thin; }
/* Room to scroll the price panel's last lines above the assistant button. */
body:not([data-mode='owner']) .config-side { padding-bottom: 72px; }
.calc-card { padding: 16px 18px; }
.calc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.calc-card h2 { font-size: 16px; }
.price-inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; margin-top: 12px; }
.price-inputs label { display: flex; flex-direction: column; gap: 4px; min-width: 0; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.price-inputs .price-compound { grid-column: span 2; }
.price-inputs select { padding: 6px 8px; color: var(--text); font-weight: 400; }
.price-inputs .input-unit input { color: var(--text); font-weight: 400; }
.price-body { margin-top: 14px; transition: opacity 0.15s; }
.calc-card.is-busy .price-body { opacity: 0.55; }
.price-result { display: grid; gap: 2px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.price-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; }
.price-row strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-row.is-main { font-size: 16px; }
.price-row.is-main strong { font-size: 20px; color: var(--accent); }
.price-row.is-total { padding-bottom: 4px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.price-row:last-child.is-total { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }
.price-included { margin: 10px 0 0; font-size: 13.5px; }
.price-note { margin: 8px 0 0; color: var(--faint); font-size: 12.5px; }
.price-missing { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 13.5px; }
.price-missing p { margin: 0; }
.price-missing ul { margin: 6px 0 0; padding-left: 18px; }
.price-warning { margin: 0 0 10px; padding: 8px 12px; border-radius: 8px; background: var(--review-bg); color: var(--review); font-size: 13.5px; }
.price-section { margin-top: 10px; border-top: 1px solid var(--border); }
.price-section summary { padding: 9px 0 6px; color: var(--text); font-size: 13.5px; font-weight: 700; cursor: pointer; }
.price-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.price-table th { padding: 4px 6px; color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.price-table td { padding: 4px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.price-table th:first-child, .price-table td:first-child { padding-left: 0; }
.price-table.is-pairs td:last-child, .price-table.is-numbers td:not(:first-child), .price-table.is-numbers th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); }
.price-table.is-pairs tr:last-child td { font-weight: 700; }

@media (max-width: 900px) {
  .admin, body[data-mode='owner'] .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .admin-nav { position: static; flex-direction: row; flex-wrap: wrap; height: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .admin-nav-label, .admin-retention { display: none; }
  .admin-main { padding: 16px; }
  .admin-detail { grid-template-columns: minmax(0, 1fr); }
  .admin-round ul { columns: 1; }
}

/* ------------------------------------------------------------ responsive */

@container (max-width: 952px) {
  .config-grid { grid-template-columns: minmax(0, 1fr); }
  .config-side { position: static; order: -1; }
  .config-side, body:not([data-mode='owner']) .config-side { max-height: none; overflow: visible; padding-bottom: 0; }
}
@media (max-width: 640px) {
  main { padding: 16px 16px 40px; }
  .topbar { padding: 8px 16px; }
  .badge { display: none; }
  .hero, .progress-card { padding: 24px 20px; }
  .stages { flex-direction: column; }
  .group { --pad: 16px; }
  /* Icon only; the text stays for screen readers. */
  .group-action span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .field::before { left: -16px; }
  .subfields { grid-template-columns: 1fr; }
  .tabs { gap: 0; padding: 0 4px; }
  .tab { padding: 12px 7px 10px; font-size: 13.5px; }
}
