:root {
  --primary: #1f3a5f;
  --accent: #3fa38a;
  --accent-soft: #eef7f4;
  --accent-tint: #f4faf7;
  --bg: #f6f8f7;
  --card: #ffffff;
  --text: #22303f;
  --muted: #5b6875;   /* 5,3:1 op wit — #7a8794 haalde de norm van 4,5:1 niet */
  --line: #e5e9e7;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(31, 58, 95, 0.08), 0 4px 14px rgba(31, 58, 95, 0.05);
  --font: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar h1 {
  flex: 1; font-size: 19px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; flex: none;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }
.user-chip {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-weight: 800; font-size: 15px; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center;
}
.sync { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #62c99f; transition: background 0.3s; }
.sync.pending { background: #f0b429; animation: pulse 1.2s infinite; }
.sync.offline { background: #f0b429; }
.sync.error { background: #e05d4e; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ---------- Layout ---------- */
.layout { max-width: 1080px; margin: 0 auto; }
.pane-home, .pane-list { padding: 14px; }
.app[data-view="home"] .pane-list { display: none; }
.app[data-view="home"] .addbar { display: none; }
.app[data-view="home"] #btn-back { display: none; }
.app[data-view="home"] #btn-menu { display: none; }
.app[data-view="list"] .pane-home { display: none; }
.pane-list { padding-bottom: 130px; }

/* ---------- Lijstjes-overzicht ---------- */
.list-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 10px;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
@media (hover: hover) {
  .list-card:hover { background: var(--accent-tint); }
}
.list-card .list-name { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Rond bij één cijfer, een pil bij drie — een vaste cirkel knijpt 100 af. */
.list-card .list-count {
  flex: none; min-width: 32px; height: 32px; padding: 0 9px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--accent-soft); color: var(--primary);
  font-size: 14px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
}
.list-card .list-count.leeg { background: var(--bg); color: var(--muted); }
.list-card .ring {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--accent);
}
.newlist { display: flex; gap: 8px; margin-top: 14px; }
.newlist input {
  flex: 1; min-width: 0; height: 48px; padding: 0 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--card); outline: none;
}
.newlist input:focus { border-color: var(--accent); }

.btn-accent {
  height: 48px; min-width: 48px; padding: 0 16px;
  background: var(--accent); color: #fff;
  border-radius: var(--radius); font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s;
}
.btn-accent:active { transform: scale(0.94); }

/* ---------- Filterchips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--card); border: 1.5px solid var(--line);
  font-weight: 700; font-size: 14px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- Items ---------- */
.item-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px 6px 6px 12px; margin-bottom: 8px;
  min-height: 56px;
}
/* Alleen écht nieuwe rijen animeren. Bij een volledige re-render (elke poll)
   zou anders elke rij opnieuw invliegen — en tijdens die fade zie je het rode
   wegveeg-vlak eronder doorschijnen: rode knippering over de hele lijst. */
.item-row.nieuw { animation: item-in 0.18s ease-out; }
@keyframes item-in { from { opacity: 0; transform: translateY(6px); } }
.item-check {
  flex: none; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.item-check .box {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 800;
  transition: background 0.15s, transform 0.15s;
}
.item-row.checked .box, .item-row.just-checked .box { background: var(--accent); transform: scale(1.05); }
.item-main { flex: 1; min-width: 0; padding: 6px 0; }
.item-text { font-weight: 600; font-size: 16px; overflow-wrap: break-word; }
.item-row.checked .item-text { text-decoration: line-through; color: var(--muted); }
.item-meta { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 1px; }
.assign-btn {
  flex: none; width: 40px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
}
.assign-btn:active { background: var(--accent-soft); }
.assign {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff;
  border: 2px dashed var(--line);
}
.item-row.checked .assign-btn { opacity: 0.45; }
.menu-list .assign { vertical-align: middle; }
.item-more { flex: none; width: 44px; height: 44px; border-radius: 12px; color: var(--muted); font-size: 20px; display: flex; align-items: center; justify-content: center; }
.item-more:active { background: var(--accent-soft); }

.badge {
  display: inline-flex; align-items: center;
  height: 20px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.02em;
}

.section-title {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  color: var(--muted); font-weight: 800; font-size: 13.5px;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 18px 0 8px; padding: 4px 2px;
}
.section-title .arrow { transition: transform 0.15s; font-size: 11px; }
.section-title.collapsed .arrow { transform: rotate(-90deg); }
.item-row.checked { box-shadow: none; background: transparent; border: 1.5px dashed var(--line); }

.empty {
  text-align: center; color: var(--muted); font-weight: 600;
  padding: 42px 20px; font-size: 15.5px;
}
.empty .big { font-size: 38px; display: block; margin-bottom: 10px; }

/* ---------- Toevoegbalk ---------- */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1.5px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.addrow { display: flex; gap: 8px; max-width: 1080px; margin: 0 auto; }
.addrow input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--bg); outline: none;
}
.addrow input:focus { border-color: var(--accent); background: #fff; }
.store-btn {
  flex: none; height: 48px; min-width: 48px; padding: 0 10px;
  border-radius: var(--radius); border: 1.5px dashed var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: var(--muted);
}
.store-btn.has-store { border-style: solid; }
.storepick {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-width: 1080px; margin: 0 auto 10px;
}
.storepick .chip { height: 40px; }
.storepick input {
  height: 40px; padding: 0 12px; border: 1.5px solid var(--accent);
  border-radius: 999px; outline: none; width: 150px; background: #fff;
}

/* ---------- Autocomplete ---------- */
.suggest {
  max-width: 1080px; margin: 0 auto 10px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.suggest-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; padding: 0 14px; height: 48px;
  font-weight: 600; font-size: 15.5px;
  border-bottom: 1px solid var(--line);
}
.suggest-row:last-child { border-bottom: none; }
.suggest-row:hover, .suggest-row:active { background: var(--accent-tint); }
.suggest-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Pincode ---------- */
#input-pin {
  width: 100%; height: 54px; padding: 0 14px; margin-top: 14px;
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
  font-size: 26px; letter-spacing: 0.4em; text-align: center;
}
#input-pin:focus { border-color: var(--accent); }
.pin-error { color: var(--danger) !important; font-weight: 700 !important; margin-top: 10px; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(31, 58, 95, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay-card {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  padding: 24px; width: 100%; max-width: 380px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  animation: item-in 0.15s ease-out;
}
.overlay-card h1, .overlay-card h2 { font-size: 20px; font-weight: 800; color: var(--primary); margin-bottom: 6px; }
.overlay-card p { color: var(--muted); font-weight: 600; font-size: 14.5px; }
.userpick-buttons { display: flex; gap: 12px; margin-top: 18px; }
.btn-user {
  flex: 1; height: 58px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--primary);
  font-weight: 800; font-size: 18px;
  border: 2px solid transparent;
}
.btn-user:active, .btn-user:hover { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }
.modal-actions button { height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 800; font-size: 15px; }
.btn-plain { background: var(--accent-soft); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-primary { background: var(--accent); color: #fff; }
.overlay-card input[type="text"] {
  width: 100%; height: 48px; padding: 0 14px; margin-top: 14px;
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
}
.overlay-card input[type="text"]:focus { border-color: var(--accent); }
.menu-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.menu-list button {
  height: 50px; text-align: left; padding: 0 12px; border-radius: 10px;
  font-weight: 700; font-size: 15.5px;
}
.menu-list button:hover, .menu-list button:active { background: var(--accent-tint); }
.menu-list button.danger { color: var(--danger); }

/* ---------- Snackbar ---------- */
/* left+right in plaats van left:50% met een transform: bij dat laatste is de
   ruimte om in te passen maar een halve schermbreedte, en liep de knop
   "Ongedaan maken" buiten het balkje. De hoogte van de balk onderin meten we
   in JS (--onderbalk), zodat de melding nooit over de knoppen valt. */
.snackbar {
  position: fixed; left: 14px; right: 14px; margin: 0 auto;
  width: fit-content; max-width: calc(100vw - 28px);
  bottom: calc(var(--onderbalk, 68px) + 14px); z-index: 40;
  background: var(--primary); color: #fff;
  border-radius: 12px; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px;
  font-weight: 700; font-size: 14.5px;
  box-shadow: 0 6px 20px rgba(31, 58, 95, 0.35);
}
.snackbar > span { flex: 1 1 auto; }
.snackbar button { flex: none; color: #7fd8bd; font-weight: 800; text-transform: uppercase; font-size: 13.5px; letter-spacing: 0.04em; }

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; padding: 0 14px; }
  .app[data-view="home"] .pane-list,
  .app[data-view="list"] .pane-home { display: block; }
  .app[data-view="home"] .addbar { display: block; }
  .app[data-view="home"] #btn-menu { display: flex; }
  #btn-back { display: none !important; }
  .pane-home, .pane-list { padding-left: 0; padding-right: 0; }
  .item-row:hover .item-more { color: var(--primary); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Scherm aanhouden ---------- */
.schermbalk {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--onderbalk, 68px) + 14px); z-index: 45;
  background: #e0a92b; color: #3d2c05; border-radius: 999px;
  padding: 9px 16px; font-weight: 800; font-size: 13.5px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

/* ---------- Wegvegen ---------- */
.swipe-wrap { position: relative; margin-bottom: 8px; border-radius: var(--radius); overflow: hidden; }
.swipe-wrap .item-row {
  margin-bottom: 0; position: relative; z-index: 1;
  touch-action: pan-y;              /* verticaal scrollen blijft van de pagina */
  will-change: transform;
}
/* Standaard onzichtbaar: het rood hoort alleen bij een veeg die bezig is.
   Anders schijnt het door zodra de rij ook maar even doorzichtig is —
   bij een afgevinkte rij (transparante achtergrond) zelfs permanent. */
.swipe-bg {
  position: absolute; inset: 0; z-index: 0;
  background: var(--danger); color: #fff;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 20px; font-weight: 800; font-size: 15px;
  visibility: hidden;
}
.swipe-wrap.vegen .swipe-bg { visibility: visible; }
.swipe-wrap.op-scherp .swipe-bg { background: #9b2d21; }
.swipe-wrap.op-scherp .swipe-bg span { transform: scale(1.08); }
.swipe-bg span { transition: transform 0.12s; }
@media (prefers-reduced-motion: reduce) { .swipe-wrap .item-row { transition: none !important; } }

.btn-link { color: var(--accent); font-weight: 800; font-size: 13.5px; background: none; }

/* ---------- Basisvoorraad ---------- */
.pane-voorraad { padding: 14px 14px 120px; }
.app[data-view="home"] .pane-voorraad,
.app[data-view="list"] .pane-voorraad { display: none; }
.app[data-view="voorraad"] .pane-home,
.app[data-view="voorraad"] .pane-list { display: none; }
.app[data-view="voorraad"] .addbar { display: none; }
.app[data-view="voorraad"] #btn-menu { display: none; }
.app[data-view="voorraad"] #btn-back { display: flex !important; }
.voorraad-uitleg { color: var(--muted); font-weight: 600; font-size: 14.5px; margin-bottom: 6px; }
.voorraad-groep {
  color: var(--muted); font-weight: 800; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 18px 0 6px; padding: 0 2px;
}
.voorraad-status { flex: none; color: var(--accent); font-weight: 800; font-size: 12.5px; }
.staple-main { flex: 1; min-width: 0; }
.staple-meta { color: var(--accent); font-weight: 800; font-size: 12px; margin-top: 1px; }
.staple-winkel {
  flex: none; min-height: 34px; padding: 4px 2px 4px 8px;
  display: flex; align-items: center;
}
.staple-winkel.leeg {
  height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1.5px dashed var(--line); color: var(--muted);
  font-size: 12px; font-weight: 800;
}
.staple-winkel.leeg:active { border-color: var(--accent); color: var(--accent); }
.voorraadbalk { display: none; }
.app[data-view="voorraad"] .voorraadbalk {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 8px; align-items: center;
  background: var(--card); border-top: 1.5px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.voorraad-hoofd { flex: 1; font-size: 16px; }
.voorraad-beheer { flex: none; height: 48px; padding: 0 18px; border-radius: var(--radius); font-weight: 800; font-size: 15px; }
.voorraad-beheer.aan { background: var(--primary); color: #fff; }
.voorraad-invoer {
  width: 100%; margin-top: 12px; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
  font-family: inherit; font-size: 15.5px; line-height: 1.5; resize: vertical;
}
.voorraad-invoer:focus { border-color: var(--accent); }
.voorraad-subkop {
  margin-top: 18px; color: var(--muted); font-weight: 800; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.staple-row.kies { width: 100%; text-align: left; }
.staple-row.kies[disabled] { opacity: 0.55; }
.vinkvak {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  border: 2px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 800;
}
.vinkvak.aan { background: var(--accent); border-color: var(--accent); }
.staplesbar { max-width: 1080px; margin: 0 auto 8px; display: flex; }
.staples-btn {
  height: 34px; padding: 0 14px; border-radius: 999px;
  background: var(--accent-soft); color: var(--primary);
  font-weight: 800; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 6px;
}
.staples-btn:active { background: var(--accent-tint); }
.staple-list { margin-top: 14px; max-height: 46vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.staple-row {
  display: flex; align-items: center; gap: 11px;
  padding: 5px 2px; border-bottom: 1px solid var(--line);
}
.staple-row:last-child { border-bottom: none; }
.staple-text {
  flex: 1; min-width: 0; font-weight: 700; font-size: 15.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staple-row.erop .staple-text { color: var(--muted); }
.staple-btn {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 21px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.staple-btn:active { transform: scale(0.92); }
.staple-btn.erop, .staple-btn[disabled] {
  background: var(--accent-soft); color: var(--accent); font-size: 16px;
}
.staple-btn.beheer { background: var(--accent-soft); color: var(--primary); font-size: 19px; }

/* ---------- Noodherstel ---------- */
.herstel {
  background: #fdf1dc; border: 2px solid #e0a92b; color: #6b4a08;
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  font-weight: 700; font-size: 14.5px; line-height: 1.5;
}
