:root {
  --bg: #f4f6f8; --surface: #fff; --text: #1d232a; --muted: #5d6b78; --line: #dde3e9;
  --brand: #1f4e79; --brand-text: #fff; --accent: #2f7dd1; --danger: #b3261e; --ok: #1e7b3a;
  --c0: #e8eef5; --c1: #d4e6f9; --c2: #a9cdf2; --c3: #6aa6e3;
  --item: #6b3fa0; --bosch: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b; --surface: #1b2128; --text: #e6ebf0; --muted: #98a6b3; --line: #2c343d;
    --brand: #183e60; --accent: #5aa2ec; --danger: #ef6b62; --ok: #4cc072;
    --c0: #26303a; --c1: #22405e; --c2: #285986; --c3: #2f73b4;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--brand); color: var(--brand-text); }
.brand { color: inherit; text-decoration: none; font-weight: 600; font-size: 17px; }
.top-actions { display: flex; gap: 6px; }
.top .chip { background: rgba(255,255,255,.15); color: inherit; border-color: transparent; }
.tabs { display: flex; gap: 4px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 900px; margin: 0 auto; padding: 12px 16px 80px; }
h2 { margin: 8px 0 4px; font-size: 22px; }
h3 { margin: 18px 0 8px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--danger); font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 12px; }
.filters input[type=search], .filters input[type=number] { flex: 1 1 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
input, button { font: inherit; }
input[type=search], input[type=number], input[type=text], dialog input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0; }
button, .chip { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; min-height: 40px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.list a.card { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.grow { flex: 1 1 auto; min-width: 0; }
.code { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.name { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; flex: 0 0 auto; }
.sys { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 10px; color: #fff; }
.sys.Item { background: var(--item); }
.sys.Bosch { background: var(--bosch); }
.cats { display: inline-flex; gap: 3px; }
.cat { display: inline-block; min-width: 30px; padding: 2px 6px; border-radius: 6px; font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.cat.c0 { background: var(--c0); } .cat.c1 { background: var(--c1); } .cat.c2 { background: var(--c2); } .cat.c3 { background: var(--c3); color: #fff; }
.cat.zero { opacity: .35; }
.cat-legend { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.back { display: inline-block; margin-top: 4px; text-decoration: none; }
.add .fields { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.add label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); flex: 1 1 110px; }
.add label.wide { flex: 3 1 200px; }
.add h3 { margin: 0 0 8px; }
.group h3 { display: flex; gap: 8px; align-items: center; }
.rem { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.rem .len { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 90px; }
.rem .qty { font-size: 18px; font-variant-numeric: tabular-nums; min-width: 50px; }
.rem .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
.log th, .log td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.log .num { text-align: right; font-variant-numeric: tabular-nums; }
.log .neg { color: var(--danger); } .log .pos { color: var(--ok); }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); max-width: 360px; width: calc(100% - 32px); }
dialog input { width: 100%; }
dialog menu { padding: 0; margin: 12px 0 0; display: flex; justify-content: flex-end; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(120px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; transition: transform .2s; max-width: calc(100% - 32px); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }
@media (max-width: 560px) {
  .list a.card { flex-wrap: wrap; }
  .right { text-align: left; width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .rem .btns { width: 100%; }
  .rem .btns button { flex: 1 1 auto; }
}

/* requirement lists */
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
a.button, .button { display: inline-flex; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none; min-height: 40px; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--c0); color: var(--text); margin: 2px 4px 2px 0; }
.badge.st-draft { background: #f6e3b4; color: #5a4300; } .badge.st-reviewed { background: #cdebd5; color: #154d26; } .badge.st-done { background: var(--c1); }
.badge.warn-b { background: #fbe0de; color: #8a1c14; } .badge.info-b { background: var(--c0); color: var(--muted); } .badge.ok-b { background: #cdebd5; color: #154d26; }
.stack { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); width: 100%; resize: vertical; }
.stack input[type=text] { width: 100%; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 14px; margin-bottom: 8px; text-align: center; }
.drop.over { border-color: var(--accent); background: var(--c0); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.actions.sticky { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; }
.hint { color: var(--muted); font-size: 14px; }
.card.line { padding: 8px 10px; }
.card.line.off { opacity: .55; }
.line-main { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.line-main select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 40px; }
.inc { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.inc input { width: 22px; height: 22px; }
.code-cell { flex: 2 1 200px; min-width: 0; }
.code-in { width: 100%; font-family: ui-monospace, Consolas, monospace; }
.name-out { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.num-in { width: 92px; }
.note-in { flex: 1 1 160px; min-width: 0; }
.badges { margin-top: 4px; }
.src summary { cursor: pointer; }
.src pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--bg); padding: 6px 8px; border-radius: 6px; margin: 4px 0 0; }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: flex; align-items: center; gap: 6px; }
.bar-no { width: 22px; text-align: right; flex: 0 0 auto; }
.bar { display: flex; height: 26px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--surface); }
.bar.rem-bar { border-color: var(--accent); border-style: dashed; }
.piece { background: var(--c2); border-right: 2px solid var(--surface); font-size: 11px; display: flex; align-items: center; justify-content: center; overflow: hidden; min-width: 0; white-space: nowrap; }
.rest { font-size: 11px; display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden; min-width: 0; }
.rest.remnant { background: repeating-linear-gradient(45deg, var(--c0), var(--c0) 6px, var(--surface) 6px, var(--surface) 12px); }
.rest.scrap { background: #fbe0de; }

/* cutting jobs */
.piece.mach { background: #ffe08a; color: #3b2f00; }
.bar-row.job { cursor: pointer; }
.bar-row.job input { width: 20px; height: 20px; flex: 0 0 auto; }
.bar-row.done .bar { opacity: .4; }
.bar-row .shelf { flex: 0 0 auto; white-space: nowrap; }
.mach-note { color: #6b5200; }
p.ok { color: var(--ok); font-weight: 600; }
.log td.wrap { white-space: normal; }
.book-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
dialog.book-dlg { max-width: 520px; }
dialog.book-dlg menu { gap: 8px; }

/* printable sheet */
.sheet-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid var(--text); padding-bottom: 6px; margin-bottom: 10px; }
.sheet-head .big { font-size: 22px; font-weight: 700; }
.head-tbl th { text-align: left; padding-right: 10px; color: var(--muted); font-weight: 500; }
.sheet-profile { margin-bottom: 18px; }
.sheet-profile h3 { margin: 10px 0 2px; }
.sheet-cols { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-top: 8px; }
.sheet-cols table { width: auto; }
.sheet-cols caption { text-align: left; font-weight: 600; font-size: 13px; padding: 4px 0; }
.box { display: inline-block; width: 13px; height: 13px; border: 1.5px solid var(--text); border-radius: 2px; vertical-align: middle; flex: 0 0 auto; }
.mach-row td { background: #fff4cc; }
.sheet-seq { margin-top: 8px; }
@media print {
  @page { size: A4 portrait; margin: 10mm; }
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --line: #999; }
  body { background: #fff; font-size: 11px; }
  .top, .tabs, .no-print, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  /* the header and the first profile on one page; only a bar or a table row is never split */
  .sheet-profile h3, .sheet-profile > p { break-after: avoid; }
  .bar-row, tr, .signatures { break-inside: avoid; }
  /* pieces white with a black outline (cheaper to print, easier to read) */
  .piece { background: #fff !important; color: #000 !important; border: 1px solid #000; border-right-width: 2px; }
  .piece.mach { background: #fff3c4 !important; }
  .bar { border-color: #000; }
  .bar { height: 20px; }
  .piece, .rest { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .log th, .log td { padding: 2px 6px; }
  .table-wrap { border: 0; }
}
body.print-mode .tabs { display: none; }
.bar-row .bar-no { width: 52px; white-space: nowrap; }
@media print { dialog { display: none !important; } }

.signatures { display: flex; gap: 32px; flex-wrap: wrap; margin-top: 18px; }
.sig { flex: 1 1 240px; }
.sig-title { font-weight: 600; margin-bottom: 6px; }
.sig-line { display: flex; gap: 8px; align-items: flex-end; margin: 10px 0; font-size: 13px; }
.sig-line .fill { flex: 1; border-bottom: 1px solid var(--text); min-height: 18px; }

/* offer helper sheet */
table.offer td { vertical-align: top; }
table.offer .mono { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
table.offer td.wrap { white-space: normal; min-width: 220px; }
table.offer tr.missing td { background: #fff7d6; }
table.offer tr.group-row td { background: var(--c0); font-weight: 600; }
table.offer .num-in { width: 110px; text-align: right; }
table.offer .num-in.over { border-color: var(--accent); background: var(--c0); }
table.offer .strong { font-weight: 600; }
table.offer tfoot td { border-bottom: 0; }
.add .fields select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }

/* login, settings */
main.login { max-width: 420px; }
main.login .card { padding: 18px; }
.button.wide { width: 100%; justify-content: center; margin: 8px 0 16px; }
main.login form button { width: 100%; }
h4 { margin: 14px 0 6px; font-size: 14px; }
tr.off td { opacity: .5; }
.tabs a[hidden] { display: none; }
main.login { width: 100%; margin: 0 auto; }
main.login .stack input { width: 100%; }
main.login .card { width: 100%; }
.md-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 16px; }
.log td.mono { font-family: ui-monospace, Consolas, monospace; }
