:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --surface: #1a222c;
  --border: #2a3544;
  --text: #e8eef5;
  --muted: #9aa8b8;
  --accent: #3d8bfd;
  --accent-hover: #5a9dff;
  --danger: #e85d6a;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #d7dee8;
    --text: #1a222c;
    --muted: #5c6b7d;
    --accent: #1a6edb;
    --accent-hover: #155cc0;
    --danger: #c42d3a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

body.role-worker .admin-only {
  display: none !important;
}

.header {
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.header-titles {
  flex: 1 1 16rem;
  min-width: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.role-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text);
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.25rem, 2.5vw, 1.6rem);
}

.sub {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
}

.sub a {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.sub a:hover {
  text-decoration: underline;
}

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--border) 55%, transparent);
}

.layout {
  display: grid;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
  max-width: 960px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  margin: 0;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field span {
  font-weight: 600;
  font-size: 0.9rem;
}

.field input,
.field textarea {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
  color: var(--text);
  font-size: 1rem;
}

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

.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.btn {
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, var(--bg));
  color: var(--text);
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.btn.small {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.empty {
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.product-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.product-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

@media (min-width: 640px) {
  .product-row {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

.product-main {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.p-name {
  font-size: 1rem;
}

.p-sku {
  font-size: 0.88rem;
  color: var(--muted);
}

.p-letter {
  font-size: 0.82rem;
  color: var(--muted);
}

.product-batch {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: flex-start;
}

.next-batch {
  font-size: 1rem;
  padding: 0.25rem 0.45rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.footer {
  padding: 1rem clamp(1rem, 4vw, 2.5rem) 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ——— Inlog / rollen ——— */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: color-mix(in srgb, var(--bg) 88%, #000);
}

.auth-overlay[hidden] {
  display: none !important;
}

.auth-card {
  width: min(100%, 26rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.auth-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.auth-sub {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.auth-panel .field {
  margin-bottom: 0.75rem;
}

.auth-hint {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-or {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.75rem 0;
}

.auth-footnote {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.print-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.qty-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.zebra-intro {
  margin: 0 0 1rem;
  max-width: 70ch;
}

.zebra-form {
  margin-top: 0.25rem;
}

.field.inline-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field.inline-check span {
  font-weight: 500;
  font-size: 0.9rem;
}

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

.qty-label input {
  width: 4.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
  color: var(--text);
  font-size: 0.95rem;
}

/* ——— Afdruk-overlay (102 × 102 mm per vel) ——— */
.print-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--bg) 92%, #000);
  color: #111;
}

.print-overlay[hidden] {
  display: none !important;
}

.print-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: #f0f0f0;
  border-bottom: 1px solid #ccc;
}

.print-bar button {
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

.print-bar button.primary {
  background: #1a6edb;
  color: #fff;
  border-color: #1a6edb;
}

.print-bar .meta {
  margin-left: auto;
  font-size: 0.85rem;
  color: #333;
  max-width: min(50ch, 100%);
}

.print-sheets {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  background: #ddd;
}

#print-overlay .sheet {
  width: 102mm;
  height: 102mm;
  background: #fff;
  border: 1px solid #333;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: 2.5mm 3mm;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #111;
}

/* Interbun — boven producttitel (zelfde volgorde als ZPL-voorbeeld) */
.sheet-brandbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 2.5mm;
  padding-bottom: 1.5mm;
  margin-bottom: 1mm;
  border-bottom: 1pt solid #c8c8c8;
  min-height: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 0.03) 100%);
}

.sheet-brandbar__img {
  display: block;
  max-height: 9mm;
  width: auto;
  object-fit: contain;
}

.sheet-brandbar__text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
  text-align: right;
}

.sheet-brandbar__name {
  font-weight: 800;
  font-size: 8pt;
  letter-spacing: 0.06em;
}

.sheet-brandbar__tag {
  font-size: 5.5pt;
  color: #444;
  max-width: 52mm;
}

#print-overlay .sheet-header {
  font-weight: 800;
  font-size: 17pt;
  line-height: 1.12;
  text-align: center;
  letter-spacing: 0.02em;
  border-bottom: 2.5pt solid #000;
  padding-bottom: 2mm;
  margin-bottom: 0;
}

#print-overlay .sheet-mid {
  display: grid;
  grid-template-columns: 1fr 45mm;
  gap: 2mm;
  margin-top: 1.5mm;
  min-height: 0;
  align-items: stretch;
}

#print-overlay .sheet-mid--no-weigh {
  grid-template-columns: 1fr;
}

#print-overlay .sheet-ingredients {
  border: 1.5pt solid #111;
  border-radius: 1mm;
  padding: 3mm 3.2mm;
  font-size: 11pt;
  line-height: 1.38;
  overflow: hidden;
  min-height: 0;
  background: linear-gradient(180deg, #fafafa 0%, #fff 35%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

#print-overlay .sheet-mid:not(.sheet-mid--no-weigh) .sheet-ingredients {
  min-height: 65mm;
}

#print-overlay .sheet-mid--no-weigh .sheet-ingredients {
  min-height: 52mm;
}

#print-overlay .sheet-ingredients strong {
  font-size: 13pt;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#print-overlay .sheet-ingredients .muted {
  color: #444;
}

/* Vak voor Digi-weegschaal: ca. 4,5 cm × 6,5 cm (zoals fysiek etiket) */
#print-overlay .sheet-scale-slot {
  width: 45mm;
  height: 65mm;
  min-width: 45mm;
  min-height: 65mm;
  max-height: 65mm;
  box-sizing: border-box;
  border: 1.2pt dashed #333;
  border-radius: 0.8mm;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 8.5pt;
  line-height: 1.28;
  color: #3a3a3a;
  padding: 1.5mm;
  flex-shrink: 0;
  background: #fafafa;
}

#print-overlay .sheet-footer {
  border-top: 2pt solid #000;
  margin-top: 1.5mm;
  padding-top: 2mm;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2mm;
  align-items: end;
}

#print-overlay .sheet-batchline {
  font-size: 11pt;
  font-weight: 600;
}

#print-overlay .sheet-brand {
  font-size: 7.5pt;
  font-weight: 700;
  text-align: right;
  color: #222;
  line-height: 1.2;
}

#print-overlay .sheet-brand__sub {
  display: block;
  font-weight: 500;
  font-size: 6pt;
  color: #444;
  margin-top: 0.5mm;
}

#print-overlay .barcode-wrap {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-top: 1mm;
}

#print-overlay .barcode-wrap svg {
  max-width: 100%;
  height: auto;
}

#print-overlay .human-read {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10pt;
  margin-top: 0.5mm;
}

/* ——— Klanten & pakbon ——— */
.customer-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.customer-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.pakbon-toolbar {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
}

.pakbon-field-grow {
  flex: 1 1 14rem;
}

.pakbon-select {
  width: 100%;
  max-width: 32rem;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
  color: var(--text);
  font-size: 1rem;
}

.pakbon-hint {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.92rem;
  color: var(--accent);
  font-weight: 600;
}

.pakbon-scan-input {
  width: 100%;
  max-width: 100%;
  font-size: 1.15rem;
  padding: 0.65rem 0.75rem;
  letter-spacing: 0.02em;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
  color: var(--text);
}

.pakbon-table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pakbon-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.pakbon-table th,
.pakbon-table td {
  padding: 0.45rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.pakbon-table th {
  background: color-mix(in srgb, var(--border) 35%, transparent);
  font-weight: 600;
}

.pakbon-actions {
  margin-top: 0.5rem;
}

/* ——— Pakbon A4 printvoorbeeld ——— */
.pakbon-print-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: flex;
  flex-direction: column;
  background: rgba(15, 20, 25, 0.88);
}

.pakbon-print-overlay[hidden] {
  display: none !important;
}

.pakbon-print-root {
  flex: 1;
  overflow: auto;
  padding: 1.25rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.pakbon-a4 {
  display: flex;
  flex-direction: column;
  width: 210mm;
  min-height: 297mm;
  max-width: 100%;
  box-sizing: border-box;
  background: #fff;
  color: #1a1a1a;
  padding: 18mm 16mm 20mm;
  font-family: "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
}

.pakbon-a4__brand {
  border-bottom: 3px solid #111;
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.pakbon-a4__mark {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4mm 6mm;
}

.pakbon-a4__logo-img {
  display: block;
  max-height: 22mm;
  width: auto;
  object-fit: contain;
}

.pakbon-a4__wordmark {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.pakbon-a4__logo {
  font-size: 22pt;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.pakbon-a4__tag {
  font-size: 9pt;
  color: #444;
  margin-top: 2px;
}

.pakbon-a4__title {
  margin: 0 0 6px;
  font-size: 18pt;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pakbon-a4__subtitle {
  margin: 0 0 16px;
  font-size: 10pt;
  color: #555;
}

.pakbon-a4__meta {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 6px 14px;
  font-size: 10.5pt;
  margin: 0 0 18px;
}

.pakbon-a4__meta dt {
  margin: 0;
  font-weight: 700;
  color: #333;
}

.pakbon-a4__meta dd {
  margin: 0;
}

.pakbon-a4__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10pt;
  margin-bottom: 22px;
}

.pakbon-a4__table th,
.pakbon-a4__table td {
  border: 1px solid #222;
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

.pakbon-a4__table th {
  background: #f0f0f0;
  font-weight: 700;
}

.pakbon-a4__table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pakbon-a4__foot {
  font-size: 9pt;
  color: #555;
  margin-bottom: 20px;
}

.pakbon-a4__signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12mm;
  margin-top: auto;
  padding-top: 10mm;
  font-size: 10pt;
}

.pakbon-a4__sign {
  border-top: 1px solid #333;
  padding-top: 6px;
}

@media print {
  /* Standaard A4; etiketten gebruiken aparte @page label (zie #print-overlay .sheet). */
  @page {
    size: A4;
    margin: 12mm;
  }

  @page label {
    size: 102mm 102mm;
    margin: 0;
  }

  body.printing-pakbon #session-header,
  body.printing-pakbon #app-root,
  body.printing-pakbon #auth-overlay,
  body.printing-pakbon #print-overlay {
    display: none !important;
  }

  body.printing-pakbon {
    background: #fff;
  }

  .pakbon-print-overlay {
    position: static !important;
    display: block !important;
    background: #fff;
  }

  .pakbon-print-bar {
    display: none !important;
  }

  .pakbon-print-root {
    padding: 0;
    overflow: visible;
    display: block;
  }

  .pakbon-a4 {
    display: block;
    box-shadow: none;
    width: 100%;
    min-height: auto;
    max-width: none;
    padding: 0;
  }

  .pakbon-a4__signatures {
    margin-top: 10mm;
    padding-top: 4mm;
  }
}

@media print {
  body {
    margin: 0;
    background: #fff;
  }

  body.printing-labels #app-root,
  body.printing-labels #session-header {
    display: none !important;
  }

  .print-overlay {
    position: static !important;
    display: block !important;
    background: #fff;
  }

  .print-bar {
    display: none !important;
  }

  .print-sheets {
    padding: 0;
    gap: 0;
    background: #fff;
    overflow: visible;
  }

  #print-overlay .sheet {
    page: label;
    border: none;
    page-break-after: always;
    break-after: page;
  }

  #print-overlay .sheet-ingredients {
    background: #fff;
    box-shadow: none;
  }

  #print-overlay .sheet-scale-slot {
    background: #fff;
  }

  #print-overlay .sheet:last-of-type {
    page-break-after: auto;
    break-after: auto;
  }
}
