:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --wash: #f0efec;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --good: #006300;
  --good-bg: #e4f3e1;
  --warn: #7a5200;
  --warn-bg: #fdf0cf;
  --bad: #b02a2a;
  --bad-bg: #fbe4e2;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a09e97;
    --line: #2c2c2a;
    --line-strong: #44443f;
    --wash: #262624;
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --good: #5fd05f;
    --good-bg: #12301a;
    --warn: #fab219;
    --warn-bg: #3a2c08;
    --bad: #f08a8a;
    --bad-bg: #3d1717;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* iOS vergroot tekst zelf bij draaien naar liggend; dat houden we tegen. */
html { font-size: 15px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 0 0 0.8rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
h3 { font-size: 0.95rem; margin: 1.4rem 0 0.5rem; }
p { margin: 0.4rem 0; }

.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.nowrap { white-space: nowrap; }

/* ---- indeling ---- */

.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }

.nav {
  position: sticky; top: 0; align-self: start; height: 100vh;
  padding: 1.4rem 0.9rem; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 0.15rem;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 0 0.6rem 1.1rem; }
.brand span { display: block; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 0.5rem 0.6rem; border-radius: 6px;
}
.nav a:hover { background: var(--wash); color: var(--ink); }
.nav a.current { background: var(--wash); color: var(--ink); font-weight: 600; }

.nav #logout { margin-top: auto; justify-content: flex-start; }
body.locked .nav a { display: none; }
.login { max-width: 420px; margin-top: 3rem; }
.login h1 { margin-bottom: 1rem; }

main { padding: 1.6rem 2rem 4rem; max-width: 1120px; width: 100%; outline: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 0.6rem 1rem; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 0.8rem 0 0; }
  .brand span { display: none; }
  main { padding: 1rem 1rem 3rem; }
}

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}

.step {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--ink); color: var(--surface); font-size: 0.8rem; font-weight: 600;
}

/* ---- formulieren ---- */

.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.row.actions { align-items: center; margin-top: 0.9rem; }
.add-row { margin-top: 0.9rem; }
.grow { flex: 1 1 240px; }
.grow .field, .grow input { width: 100%; }

.field { display: flex; flex-direction: column; gap: 0.25rem; max-width: 100%; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.field.inline select { min-width: 0; max-width: 100%; }
.field-label { font-size: 0.82rem; color: var(--ink-2); }
.hint { font-size: 0.8rem; color: var(--muted); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.42rem 0.55rem; min-height: 2.3rem; max-width: 100%;
}
textarea { width: 100%; margin-top: 0.7rem; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
/* iOS Safari zoomt in op elk veld met tekst kleiner dan 16px en zoomt daarna niet terug,
   waardoor de pagina breder lijkt dan het scherm. Op aanraakschermen dus 16px. */
@media (hover: none) and (pointer: coarse) {
  input[type="text"], input[type="number"], input[type="date"], select, textarea { font-size: 16px; }
}
/* Datumvelden op iOS: eigen breedte en gecentreerde tekst negeren onze maten en
   duwen rasters breder dan het scherm; leeg zakt het veld bovendien in. */
@supports (-webkit-touch-callout: none) {
  input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; text-align: left; }
  input[type="date"]::-webkit-date-and-time-value { text-align: left; min-height: 1.45em; margin: 0; }
}
/* WebKit telt afgeknipte tekst in een keuzemenu mee als overloop, waardoor de pagina
   zijwaarts gaat schuiven terwijl het menu zelf past. */
select { contain: paint; }
input.narrow { width: 5.5rem; text-align: right; font-variant-numeric: tabular-nums; }

.check { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 2.3rem; }

.btn {
  font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.3rem; padding: 0.42rem 0.85rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--wash); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 1.8rem; padding: 0.15rem 0.55rem; font-size: 0.87rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.file-btn input { display: none; }


details { margin-top: 0.9rem; }
summary { cursor: pointer; color: var(--ink-2); }

/* ---- tabellen ---- */

.table-wrap { overflow-x: auto; margin-top: 0.6rem; }
.table-wrap.tall { max-height: 45vh; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.r { text-align: right; }
tfoot td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--line-strong); }
table.entry td { padding-top: 0.25rem; padding-bottom: 0.25rem; }

/* ---- status ---- */

.chip {
  display: inline-block; font-size: 0.8rem; font-weight: 500; padding: 0.08rem 0.5rem; border-radius: 999px;
  background: var(--wash); color: var(--ink-2); white-space: nowrap;
}
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.start { background: var(--ink); color: var(--surface); }


.notice {
  background: var(--wash); border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.8rem 0; font-size: 0.92rem;
}
.notice.row { align-items: center; }



/* ---- kerncijfers ---- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem; }
.tile-label { font-size: 0.82rem; color: var(--ink-2); }
.tile-value { font-size: 1.35rem; font-weight: 600; margin: 0.15rem 0; }
.tile-value .chip { font-size: 1rem; padding: 0.15rem 0.7rem; }
.tile-sub { font-size: 0.82rem; color: var(--muted); }
.tile-sub .chip { white-space: normal; border-radius: 8px; }
/* ---- dialoog en melding ---- */

.dialog {
  width: min(860px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 1.2rem 1.4rem;
  background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem);
  background: var(--ink); color: var(--surface); padding: 0.6rem 1rem; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s; max-width: min(560px, calc(100vw - 2rem)); z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) { #toast, .scan-frame { transition: none; } }

.notice.warn { background: var(--warn-bg); color: var(--ink); border-left: 4px solid var(--warn); }
button.link {
  background: none; border: 0; padding: 0; font: inherit; color: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}

/* ---- inklapbare blokken ---- */

details.module { margin-top: 0; padding: 0; }
details.module > summary {
  list-style: none; display: flex; align-items: center; gap: 0.7rem;
  padding: 0.9rem 1.25rem; color: var(--ink); border-radius: 10px;
}
details.module > summary::-webkit-details-marker { display: none; }
details.module > summary:hover { background: var(--wash); }
details.module[open] > summary { border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; }
.module-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.module-title h2 { margin: 0; }
.module-status { font-size: 0.85rem; color: var(--muted); }
.module-body { padding: 0.4rem 1.25rem 1.1rem; }
.status-icon {
  flex: none; display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  font-weight: 700; font-size: 0.95rem; color: #fff;
}
.status-icon.good { background: var(--good); }
.status-icon.bad { background: var(--bad); }
@media (prefers-color-scheme: dark) { .status-icon { color: #0b0b0b; } }
.chevron {
  flex: none; width: 0.55rem; height: 0.55rem; margin: 0 0.2rem 0.2rem;
  border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(45deg);
}
details.module[open] .chevron { transform: rotate(-135deg); margin-bottom: -0.2rem; }

.btn.wide { width: 100%; min-height: 3rem; font-size: 1.05rem; margin: 0.6rem 0 0.2rem; }
@media (min-width: 761px) { .btn.wide { width: auto; padding: 0.5rem 1.6rem; } }
.btn.icon { min-width: 2.4rem; min-height: 2.4rem; padding: 0; }

input[type="search"], input[type="password"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.42rem 0.55rem; min-height: 2.3rem; max-width: 100%;
}
@media (hover: none) and (pointer: coarse) {
  input[type="search"], input[type="password"] { font-size: 16px; }
}
.btn.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.row-inline { display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.crumb { margin: 0 0 0.4rem; }
.crumb a { text-decoration: none; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; }
h1::first-letter { text-transform: uppercase; }

/* ---- leveringen ---- */

.delivery-list, .unknown-list, .check-list, .scan-list, .product-list, .code-list { list-style: none; margin: 0; padding: 0; }
.delivery-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem 1rem; flex-wrap: wrap;
  padding: 0.8rem 0.4rem; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; border-radius: 6px;
}
.delivery-list li:last-child .delivery-item { border-bottom: 0; }
.delivery-item:hover { background: var(--wash); }
.delivery-main { display: flex; flex-direction: column; }
.delivery-main strong::first-letter { text-transform: uppercase; }
.delivery-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; color: var(--ink-2); font-size: 0.9rem; }
.card.empty .btn.wide { margin-top: 0.8rem; }

.scan-card .btn.wide { margin-top: 0; }
.hand-form { margin-top: 0.8rem; }
.hand-form .field, .hand-form input { width: 100%; }

.tile.good .tile-value { color: var(--good); }
.tile.bad .tile-value { color: var(--bad); }
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
  .tile { padding: 0.6rem 0.7rem; }
  .tile-value { font-size: 1.25rem; }
  .tile-sub { font-size: 0.75rem; }
}

.notice-card { border-color: var(--warn); background: var(--warn-bg); }
.notice-card .muted { color: var(--ink-2); }
.unknown-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.55rem 0; border-top: 1px solid var(--line-strong);
}
.unknown-code code { font-size: 1rem; }

/* checklist: naam links, gescand / bon rechts, − en + ernaast */
.check-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 0.3rem 0.7rem; align-items: center;
  padding: 0.6rem 0; border-bottom: 1px solid var(--line);
}
.check-item:last-child { border-bottom: 0; }
.status-dot {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  font-size: 0.8rem; font-weight: 700; border: 2px solid var(--line-strong); color: var(--surface);
}
.status-dot.good { background: var(--good); border-color: var(--good); }
.status-dot.warn { background: var(--warn); border-color: var(--warn); }
.status-dot.bad { background: transparent; border-color: var(--bad); }
.check-name { font-weight: 600; overflow-wrap: anywhere; }
.check-item.good .check-name { color: var(--ink-2); font-weight: 500; }
.check-meta { margin-top: 0.1rem; }
.check-count { display: flex; align-items: center; gap: 0.2rem; font-variant-numeric: tabular-nums; }
.check-count strong { font-size: 1.2rem; min-width: 1.6rem; text-align: right; }
.check-expected input { width: 4.2rem; }
.check-buttons { display: flex; gap: 0.3rem; }
.check-buttons .btn.icon { font-size: 1.2rem; }
@media (max-width: 520px) {
  .check-item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .check-buttons { grid-column: 2 / -1; justify-content: flex-end; }
}

.scan-list li { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0; border-bottom: 1px solid var(--line); }
.scan-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.87rem; }
.scan-what { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ---- producten ---- */

.product-list > li { padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.product-list > li:last-child { border-bottom: 0; }
.product-list > li.inactive strong { color: var(--muted); }
.product-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; flex-wrap: wrap; }
.code-list { margin-top: 0.4rem; }
.code-list li { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.15rem 0; }

/* ---- vensters ---- */

.form-dialog { width: min(520px, calc(100vw - 1.5rem)); overflow-y: auto; padding: 1rem 1.1rem; }
.small-dialog { width: min(420px, calc(100vw - 1.5rem)); padding: 1rem 1.1rem; }
.form-dialog .actions, .small-dialog .actions { justify-content: flex-end; }
.form-dialog form > * + * { margin-top: 0.8rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }
@media (max-width: 520px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.gtin-line code { font-size: 1.15rem; font-weight: 600; }
.picker { display: flex; flex-direction: column; gap: 0.4rem; }
.picker select, .picker input { width: 100%; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; padding: 2px; gap: 2px; background: var(--wash); }
.segmented .seg {
  font: inherit; border: 0; background: transparent; color: var(--ink-2); padding: 0.35rem 0.8rem; border-radius: 6px; cursor: pointer; min-height: 2.1rem;
}
.segmented .seg.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

/* ---- camera ---- */

.scan-dialog { width: min(640px, calc(100vw - 1rem)); max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); overflow-y: auto; padding: 0.8rem 0.9rem; }
.scan-top { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.scan-top h2 { margin: 0; }
.scan-view {
  position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 62vh; max-height: 62dvh;
  border-radius: 8px; overflow: hidden; background: #000;
}
@media (min-aspect-ratio: 1/1) { .scan-view { aspect-ratio: 4 / 3; } }
.scan-view video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scan-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* Kader voor "één per één": zelfde stuk als de scanner uitsnijdt (85% breed, 40% hoog, gecentreerd). */
.scan-frame {
  position: absolute; left: 7.5%; right: 7.5%; top: 30%; bottom: 30%;
  border: 2px solid #fff; border-radius: 6px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.4); pointer-events: none;
}
.scan-hint { font-size: 0.87rem; color: var(--ink-2); margin: 0.6rem 0 0.3rem; }
.key { font-weight: 600; padding: 0 0.3rem; border-radius: 4px; color: #000; }
.key.good { background: #38d26a; }
.key.bad { background: #ff5c5c; }
.scan-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; margin-top: 0.3rem; }
.scan-counter { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.scan-status { font-size: 0.8rem; margin: 0.3rem 0; }
.scan-recent { list-style: none; margin: 0.2rem 0 0; padding: 0; font-size: 0.92rem; }
.scan-recent li { padding: 0.3rem 0.5rem; border-radius: 6px; margin-top: 0.2rem; }
.scan-recent li.good { background: var(--good-bg); color: var(--good); }
.scan-recent li.warn { background: var(--warn-bg); color: var(--warn); }
.scan-recent li.bad { background: var(--bad-bg); color: var(--bad); }

/* ---- foto van de doos ---- */

.scan-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.scan-buttons .btn.wide { width: 100%; margin: 0; }
@media (max-width: 420px) { .scan-buttons { grid-template-columns: 1fr; } }
.scan-card .hint { margin-top: 0.5rem; }
.photo-dialog { width: min(760px, calc(100vw - 1rem)); max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); overflow-y: auto; padding: 0.8rem 0.9rem; }
.photo-dialog .actions { justify-content: flex-end; }
.photo-progress { display: grid; gap: 0.5rem; padding: 1.5rem 0; }
.photo-progress .meter { height: 8px; border-radius: 4px; background: var(--wash); overflow: hidden; }
.photo-progress .meter div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.photo-stage { position: relative; border-radius: 8px; overflow: auto; background: #000; max-height: 70vh; max-height: 70dvh; }
/* De hele foto in beeld: zo breed als het venster, maar niet hoger dan het scherm toelaat. */
.photo-canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 70vh; max-height: 70dvh; margin: 0 auto; }
.photo-stage.zoomed .photo-canvas { width: 250%; max-width: none; max-height: none; }
.photo-zoom { position: sticky; left: 0.5rem; bottom: 0.5rem; margin: -2.4rem 0 0.5rem 0.5rem; }
.photo-summary { margin-top: 0.6rem; }
.photo-line { margin: 0.4rem 0; padding: 0.45rem 0.7rem; border-radius: 8px; background: var(--wash); }
.photo-line.good { background: var(--good-bg); color: var(--good); }
.photo-line.warn { background: var(--warn-bg); color: var(--ink); }
.photo-line.bad { background: var(--bad-bg); color: var(--bad); }
.photo-loose { margin: 0.4rem 0; }
.photo-loose-list { list-style: none; margin: 0.3rem 0 0.5rem; padding: 0; }
