:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #d9dce1;
  --line-strong: #b7bcc4;
  --accent: #14532d;
  --accent-ink: #ffffff;
  --accent-soft: #e7f2ec;
  --warn-bg: #fdf2e3;
  --warn-ink: #8a5200;
  --warn-line: #f0c674;
  --danger: #a3241f;
  --ok: #1d7a4c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16,18,29,.06), 0 4px 16px rgba(16,18,29,.06);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
}
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.topbar .brand span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.verlader-tabs { display: flex; gap: 8px; }
.verlader-tabs button {
  padding: 8px 16px; border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 999px; font-size: 15px; cursor: pointer; color: var(--ink);
}
.verlader-tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.mode-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.mode-toggle .pill {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  cursor: pointer; background: var(--surface); font-size: 13px; font-weight: 600;
}
.mode-toggle .pill.test { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.mode-toggle .pill.live { background: #fbeaea; color: var(--danger); border-color: #e6b3b0; }

/* ---- layout ---- */
.wrap { max-width: 1220px; margin: 0 auto; padding: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 20px; }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel-body { padding: 18px; }

/* ---- header fields ---- */
.headfields { display: flex; flex-wrap: wrap; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input {
  height: 42px; min-width: 200px; padding: 0 12px; font-size: 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- grid ---- */
.gridwrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; }
table.grid th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
table.grid td { padding: 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
/* lichte kolomscheiding voor leesbaarheid bij snel invullen */
table.grid th, table.grid td { border-right: 1px solid var(--line); }
table.grid th:last-child, table.grid td:last-child { border-right: none; }
table.grid td.num { width: 34px; text-align: center; color: var(--muted); font-size: 13px; }
table.grid td.rm { width: 40px; text-align: center; }
.cell-input {
  width: 100%; height: 46px; border: 1px solid transparent; background: transparent;
  padding: 0 10px; font-size: 16px; color: var(--ink);
}
.cell-input:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: #fff; }
.cell-input.num-cell { text-align: right; }
td.auto .cell-input { color: var(--muted); background: #fafbfc; }
td.col-select { min-width: 220px; }
td.col-int { width: 120px; }
td.col-date8 { width: 170px; }
td.col-auto { width: 130px; }
td.status { width: 150px; font-size: 13px; padding: 0 10px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--accent-soft); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.rm-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 6px; }
.rm-btn:hover { background: #fbeaea; color: var(--danger); }

/* ---- combobox dropdown ---- */
.combo-pop {
  position: absolute; z-index: 50; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; min-width: 320px;
}
.combo-pop .opt { padding: 8px 12px; cursor: pointer; font-size: 15px; display: flex; gap: 10px; }
.combo-pop .opt .code { font-weight: 700; font-variant-numeric: tabular-nums; }
.combo-pop .opt .desc { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-pop .opt.active { background: var(--accent-soft); }
.combo-pop .empty { padding: 10px 12px; color: var(--muted); font-size: 14px; }

/* ---- actions ---- */
.actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.btn {
  height: 46px; padding: 0 22px; border-radius: var(--radius); font-size: 16px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary.live { background: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { border-style: dashed; }
.summ { color: var(--muted); font-size: 14px; }
.summ b { color: var(--ink); }

/* ---- toast / result ---- */
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: 440px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; }
.toast.ok { border-left: 5px solid var(--ok); }
.toast.err { border-left: 5px solid var(--danger); }
.toast h3 { margin: 0 0 6px; font-size: 15px; }
.toast p { margin: 4px 0; font-size: 14px; color: var(--muted); }
.toast .warns { margin: 8px 0 0; padding: 8px 10px; background: var(--warn-bg); border-radius: 6px; color: var(--warn-ink); font-size: 13px; }
.toast a { color: var(--accent); font-weight: 600; }
.toast .close { position: absolute; top: 10px; right: 12px; cursor: pointer; color: var(--muted); border: none; background: none; font-size: 18px; }

/* ---- history ---- */
.histwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.hist { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 720px; }
table.hist th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.hist td { padding: 8px; border-bottom: 1px solid var(--line); }
table.hist tr:hover td { background: #fafbfc; }
tr.day-row td { background: #f1f3f5; padding: 6px 8px; border-bottom: 1px solid var(--line); }
tr.day-row:hover td { background: #f1f3f5; }
.day-label { font-weight: 700; font-size: 13px; text-transform: capitalize; }
.day-count { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-strong); font-size: 12px; color: var(--muted); }
#histRange { height: 34px; padding: 0 10px; font-size: 14px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--ink); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.tag.test { background: var(--warn-bg); color: var(--warn-ink); }
.tag.live { background: #fbeaea; color: var(--danger); }
.tag.sent { background: var(--accent-soft); color: var(--ok); }
.tag.held { background: #eef0f3; color: var(--muted); }

/* ---- gate ---- */
.gate { max-width: 360px; margin: 12vh auto; text-align: center; }
.gate .panel-body { display: flex; flex-direction: column; gap: 12px; }
.gate input { height: 46px; font-size: 18px; text-align: center; letter-spacing: .1em; }

/* ==========================================================================
   TABLET / TOUCH (iPad in het magazijn)
   Let op: invoervelden blijven >= 16px, anders zoomt iOS Safari automatisch in
   zodra je een veld aanraakt.
   ========================================================================== */
* { -webkit-tap-highlight-color: rgba(20, 83, 45, .12); }
button, input, .combo-pop .opt { touch-action: manipulation; }   /* geen dubbeltik-zoom */
.gridwrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
input { -webkit-appearance: none; appearance: none; border-radius: 0; }
.field input, .btn, .gate input { border-radius: var(--radius); }

@media (pointer: coarse) {
  .cell-input { height: 58px; font-size: 17px; }
  table.grid th { font-size: 13px; padding: 10px 8px; }
  table.grid td.num { width: 42px; font-size: 15px; }
  .field input { height: 52px; font-size: 17px; }
  .btn { height: 54px; font-size: 17px; padding: 0 26px; }
  .rm-btn { font-size: 22px; padding: 10px 14px; }
  .combo-pop .opt { padding: 14px 14px; font-size: 17px; }
  .combo-pop { max-height: 46vh; }        /* laat ruimte voor het schermtoetsenbord */
  .verlader-tabs button { padding: 11px 20px; font-size: 16px; }
  .mode-toggle .pill { padding: 9px 16px; font-size: 15px; }
  .badge { font-size: 13px; padding: 4px 11px; }
}

/* iPad liggend (1024px): kolommen krapper zodat de invoertabel past zonder scrollen */
@media (max-width: 1100px) {
  td.col-select { min-width: 150px; }
  td.col-auto   { width: 92px; }
  td.col-date8  { width: 132px; }
  td.col-int    { width: 92px; }
  td.status     { width: 104px; }
  .cell-input   { padding: 0 8px; }
  table.grid th { padding: 6px; letter-spacing: 0; }
  /* Puur informatieve cijferkolommen weglaten op tablet, zodat Artikel t/m Status
     samen in beeld passen zonder horizontaal scrollen. De totalen staan al in de
     samenvattingsregel onder de tabel. */
  .k-stuks_pal, .k-totaal { display: none; }
}

/* Smallere tablets / portretstand: kopvelden onder elkaar, tabel blijft scrollen */
@media (max-width: 900px) {
  .wrap { padding: 12px; }
  .headfields { gap: 12px; }
  .field { flex: 1 1 220px; }
  .field input { min-width: 0; width: 100%; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar .brand { font-size: 16px; }
  .actions { gap: 10px; }
  .actions .summ { order: 3; width: 100%; }
}
