:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #dde1e7;
  --accent: #2f6f9f;
  --danger: #b42318;
  --warn: #b54708;
  --ok-bg: #ecfdf3;
  --err-bg: #fef3f2;
  --pos: #067647;
  --notice-bg: #fffaeb;
  --border-strong: #c3c9d2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2129;
    --text: #e6e8eb;
    --muted: #9aa3af;
    --border: #2e3440;
    --accent: #6aa8d8;
    --danger: #f97066;
    --warn: #fdb022;
    --ok-bg: #0f2a1d;
    --err-bg: #3a1714;
    --pos: #47cd89;
    --notice-bg: #2b2210;
    --border-strong: #454d5c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 4px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.logout { display: flex; align-items: center; gap: 8px; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px 20px; margin-bottom: 20px; overflow-x: auto;
}
.card.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.card.company { border-top: 4px solid var(--border); }
.card ul { margin: 0; padding-left: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head h2 { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a + a { margin-left: 12px; }

.muted { color: var(--muted); }
.warn { color: var(--warn); font-weight: 600; }
.mono { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: .9em; }
.nowrap { white-space: nowrap; }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; border: 1px solid var(--border); }

form > div { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
input[type="color"] { width: 64px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
input[type="checkbox"] { margin-right: 6px; }
.helptext { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }
.errorlist { color: var(--danger); margin: 4px 0; padding-left: 18px; }
.narrow-form { max-width: 480px; }

button, .button {
  display: inline-block; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer;
  color: #fff; background: var(--accent); border: 0; border-radius: 6px; text-decoration: none;
}
button.danger { background: var(--danger); }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 400; }
.actions { display: flex; gap: 16px; align-items: center; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; border: 1px solid var(--border); }
.msg-success { background: var(--ok-bg); }
.msg-error { background: var(--err-bg); color: var(--danger); }

.pagination { display: flex; gap: 16px; justify-content: center; margin-top: 12px; }

.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--danger); }
.zero { color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--notice-bg); }
.badge { display: inline-block; font-size: .75rem; padding: 0 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
button.secondary, .button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--border); }
table.compact th, table.compact td { padding: 5px 8px; }
tfoot th { border-bottom: 0; color: var(--text); }
tr.day-start td { border-top: 1px solid var(--border-strong); }

.scopebar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented a { padding: 4px 12px; text-decoration: none; color: var(--muted); border-right: 1px solid var(--border); }
.segmented a:last-child { border-right: 0; }
.segmented a[aria-current] { background: var(--accent); color: #fff; }
.segmented a[aria-current] .swatch { border-color: #fff; }

.range { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.range a { text-decoration: none; }
.range a[aria-current] { font-weight: 700; color: var(--text); }
.range input[type="date"] { width: auto; padding: 4px 8px; }
.range button { padding: 4px 12px; }
label.inline { display: inline; font-weight: 400; margin: 0; }
input[type="date"] { padding: 8px 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }


/* --- Order grid --- */
body.wide main { max-width: none; }
.toolbar { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.badge.attention { color: var(--warn); border-color: var(--warn); text-decoration: none; }
.grid-card { padding: 0; }
.order-grid { width: auto; min-width: 100%; }
.order-grid th, .order-grid td { padding: 0; border: 1px solid var(--border); }
.order-grid thead th { padding: 4px 6px; text-align: center; position: sticky; top: 0; background: var(--surface); }
.order-grid thead tr:nth-child(2) th { top: 29px; }
.order-grid th.group { color: var(--text); }
.order-grid th.product { cursor: help; }
.order-grid .row-head {
  padding: 4px 10px; text-align: left; white-space: nowrap; min-width: 140px;
  position: sticky; left: 0; background: var(--surface); z-index: 1; font-weight: 600; color: var(--text); font-size: .9rem;
}
.order-grid thead .row-head { z-index: 2; }
.order-grid .row-head a { color: var(--text); text-decoration: none; }
.order-grid .row-head a:hover { text-decoration: underline; }
.order-grid .row-head .badge { font-weight: 400; }
.order-grid td.cell input {
  width: 3.4em; padding: 5px 4px; border: 0; border-radius: 0; background: transparent; color: var(--text);
  text-align: right; font: inherit; font-variant-numeric: tabular-nums;
}
.order-grid td.cell input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--bg); }
.order-grid td.cell input.saving { opacity: .5; }
.order-grid td.cell input.invalid { background: var(--err-bg); color: var(--danger); }
.order-grid td.differs { background: var(--notice-bg); }
.order-grid td.differs input { font-weight: 700; }
.order-grid tr.kind-internal .row-head { color: var(--muted); }
.order-grid tr.kind-internal:first-child .row-head,
.order-grid tr.kind-b2b + tr.kind-internal > *,
.order-grid tr:not(.kind-one_time) + tr.kind-one_time > * { border-top: 2px solid var(--border-strong); }
.order-grid tfoot th { padding: 5px 6px; font-variant-numeric: tabular-nums; background: var(--bg); }
.order-grid .row-actions { padding: 2px 8px; }
.order-grid .row-actions form { display: flex; gap: 10px; margin: 0; }
button.link.danger { color: var(--danger); }
.inline-form { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.inline-form select, .inline-form input[type="text"] { width: auto; flex: 1 1 160px; }
.inline-form input.short, input.short { flex: 0 0 6em; width: 6em; text-align: right; }
.narrow-left { max-width: 720px; }

/* --- Print --- */
body.print main { max-width: none; }
@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --border: #999; }
  .topbar, .messages { display: none; }
  main { padding: 0; }
}

/* --- Delivery notes --- */
form.inline { display: inline; margin: 0; }
button[disabled] { opacity: .45; cursor: not-allowed; }
pre.payload { max-height: 320px; overflow: auto; font-size: .78rem; background: var(--bg); padding: 8px; border-radius: 6px; }
td ul.small { margin: 0; padding-left: 16px; }

/* --- Dough calculation --- */
.batches { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 20px; }
.batch table { margin-bottom: 8px; }
.batch tr.group-start th { padding-top: 10px; color: var(--text); }
.batch tr.total th { border-top: 2px solid var(--border-strong); color: var(--text); }
details > summary { cursor: pointer; margin: 12px 0 8px; }
@media print { .batch { break-inside: avoid; } }

/* --- Day picker --- */
.daypicker { position: relative; }
.daypicker-toggle { padding: 4px 12px; }
.daypicker-panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; width: 18.5em; padding: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgb(0 0 0 / .15);
}
.daypicker-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.daypicker-head button { font-size: 1.3rem; padding: 0 8px; }
.daypicker-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.daypicker-wd { text-align: center; font-size: .75rem; color: var(--muted); padding: 2px 0; }
.daypicker-grid button {
  padding: 5px 0; font: inherit; font-weight: 400; font-variant-numeric: tabular-nums; cursor: pointer;
  color: var(--text); background: transparent; border: 1px solid transparent; border-radius: 6px;
}
.daypicker-grid button:hover { border-color: var(--border-strong); }
.daypicker-grid button.other { color: var(--muted); opacity: .6; }
.daypicker .bake { background: var(--ok-bg); border-color: var(--pos); }
.daypicker .delivery { background: var(--notice-bg); border-color: var(--warn); }
.daypicker-grid button.today { font-weight: 700; text-decoration: underline; }
.daypicker-grid button.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.daypicker-grid button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.daypicker-legend { display: flex; gap: 10px; margin-top: 8px; }
.daypicker-legend span { padding: 0 6px; border: 1px solid; border-radius: 4px; }
.shift { margin-bottom: 28px; }
.shift > .section-head { border-bottom: 2px solid var(--border-strong); padding-bottom: 4px; margin-bottom: 12px; }
p.schedule { margin: 0 0 6px; }
p.instructions { white-space: normal; border-left: 3px solid var(--border-strong); padding-left: 8px; }
h3.shift-time { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 18px 0 8px; }
.hint { font-size: .85em; color: var(--warn); font-weight: 600; }
.distribution { grid-column: span 2; }
@media (max-width: 720px) { .distribution { grid-column: auto; } }
/* Bold line between product groups (BF, ST, Dinkel, Bauern, Brötchen …), as in the old Backlisten */
.order-grid .group-start { border-left: 2px solid var(--muted); }

/* --- Compact Backzettel (print views of shifts; same look on screen as preview) --- */
body.print-sheet { background: #fff; color: #000; font-size: 9pt; line-height: 1.3; }
body.print-sheet main { max-width: 190mm; padding: 6mm 0; }
.print-actions { margin: 0 0 4mm; font-size: 10pt; }
.sheet + .sheet { break-before: page; margin-top: 10mm; }
.sheet-head { display: flex; justify-content: space-between; border-bottom: 1.5pt solid #000; padding-bottom: 1mm; margin-bottom: 2mm; font-size: 11pt; }
.sheet-body { columns: 3; column-gap: 5mm; column-rule: 0.5pt solid #bbb; }
h3.sheet-time { column-span: all; margin: 3mm 0 1.5mm; padding-top: 0.5mm; border-top: 0.75pt solid #000; font-size: 10pt;
  text-transform: none; letter-spacing: 0; color: #000; }
.pstep, .pdist { break-inside: avoid; margin: 0 0 3mm; }
.pdist { column-span: all; }
.ptitle { font-size: 10pt; margin-bottom: 0.5mm; }
.ptitle strong { margin-right: 1.5mm; }
.pmeta { color: #444; font-size: 8pt; }
.pflag { display: inline-block; border: 0.75pt solid #000; padding: 0 1mm; font-size: 7.5pt; font-weight: 700; }
.pnote { font-size: 8pt; font-style: italic; margin-top: 0.5mm; }
.pwarn { font-size: 8pt; font-weight: 700; }
.plist, .ptable { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.plist td { padding: 0.2mm 0; border: 0; vertical-align: baseline; }
.plist td:last-child { text-align: right; white-space: nowrap; padding-left: 2mm; }
.plist tr.pgroup td { padding-top: 0.8mm; font-weight: 700; font-size: 8pt; text-align: left; padding-left: 0; }
.plist tr.ptotal td { border-top: 0.5pt solid #000; font-weight: 700; }
.plist em, .ptable em { font-style: normal; font-weight: 700; font-size: 8pt; }
.ptable th, .ptable td { padding: 0.4mm 1.5mm 0.4mm 0; border: 0; border-bottom: 0.25pt solid #ccc; text-align: left; font-size: 9pt; color: #000; }
.ptable th:nth-child(2), .ptable td:nth-child(2), .ptable th:nth-child(3), .ptable td:nth-child(3) { text-align: right; white-space: nowrap; }
.ptable th { font-weight: 700; border-bottom: 0.75pt solid #000; }
.ptable tfoot td { font-weight: 700; border-top: 0.75pt solid #000; border-bottom: 0; }
@media print {
  @page { size: A4; margin: 10mm; }
  body.print-sheet main { padding: 0; max-width: none; }
  .print-actions { display: none; }
  .sheet + .sheet { margin-top: 0; }
}
.takeoff { border-left: 4px solid var(--accent); }
/* Grundmenge: Laden/Markt cells filled automatically, header with production */
.order-grid td.auto input { font-style: italic; color: var(--muted); }
.order-grid .quota-head { font-size: .72rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.order-grid .quota-head.raised { color: var(--warn); font-weight: 700; }
.order-grid td.quota { background: var(--bg); }

/* --- Day grid for A4 landscape --- */
body.print-day { background: #fff; color: #000; }
body.print-day main { padding: 4mm 0; }
.day-sheet { page: landscape; margin-bottom: 6mm; }
@page landscape { size: A4 landscape; margin: 8mm; }
.print-grid { width: 100%; border-collapse: collapse; font-size: 9pt; font-variant-numeric: tabular-nums; }
.print-grid th, .print-grid td { padding: 0.6mm 1.2mm; border: 0.25pt solid #aaa; color: #000; font-size: 9pt; }
.print-grid thead th { text-align: center; font-weight: 700; }
.print-grid .row-head { text-align: left; white-space: nowrap; font-weight: 700; }
.print-grid td.num { text-align: right; min-width: 7mm; }
.print-grid td.auto { font-style: italic; }
.print-grid .group-start { border-left: 1.5pt solid #000; }
.print-grid tr.kind-internal:first-child > *, .print-grid tr.kind-b2b + tr.kind-internal > *,
.print-grid tr:not(.kind-one_time) + tr.kind-one_time > * { border-top: 1.2pt solid #000; }
.print-grid tfoot th { border-top: 1.2pt solid #000; text-align: right; }
.print-grid tfoot .row-head { text-align: left; }
.print-grid .quota-head { font-size: 7pt; font-weight: 400; }
@media print {
  body.print-day main { padding: 0; }
  .day-sheet { break-inside: avoid; }
}
/* every other customer row shaded; browsers drop backgrounds in print unless told otherwise */
.print-grid tbody tr:nth-child(even) > * { background: #e8e8e8; }
.print-grid { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
