:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a2330;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --over: #b42318;
  --over-bg: #fde8e7;
  --radius: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --shadow-lift: 0 12px 28px rgba(15, 23, 42, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #19212b;
    --text: #e8edf2;
    --muted: #9aa8b8;
    --line: #2c3742;
    --primary: #4c8dff;
    --ok: #5fd07c;
    --ok-bg: #16301f;
    --warn: #f2c14e;
    --warn-bg: #33290f;
    --over: #ff7b72;
    --over-bg: #3a1714;
    --shadow-lift: 0 12px 28px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* viewport-fit=cover: inhoud niet onder de notch/statusbalk (geïnstalleerde app, liggend) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(48px + env(safe-area-inset-bottom)); }
nav {
  display: flex; gap: 4px; flex-wrap: wrap; align-items: center;
  max-width: 640px; margin: 0 auto; padding: 8px 16px;
}
nav .tabs { display: flex; gap: 4px; }
nav .account { display: flex; gap: 4px; align-items: center; margin-left: auto; min-width: 0; }
nav .user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav a, nav button {
  color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 8px;
  background: none; border: 0; font: inherit; cursor: pointer;
  transition: background-color .2s var(--ease), color .2s;
}
nav a svg { display: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
nav a.active { background: var(--card); font-weight: 600; }
h1 { font-size: 1.4rem; margin: 8px 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

button, .btn {
  font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); padding: 10px 14px; cursor: pointer; touch-action: manipulation;
  transition: background-color .15s, border-color .15s, color .15s, opacity .2s, transform .12s var(--ease);
}
button:active:not(:disabled), .btn:active { transform: scale(.94); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button:disabled { opacity: .45; cursor: default; }
input, select {
  font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
label { display: block; margin: 8px 0 4px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* Status-kaart bovenaan */
.status { text-align: center; border-width: 2px; transition: background-color .3s, border-color .3s; }
.status .total { font-size: 3rem; font-weight: 800; line-height: 1.1; transition: color .3s; }
.status .sub { font-size: 1.1rem; margin-top: 4px; }
.status .msg { margin-top: 8px; font-weight: 700; }
.status.ok { border-color: var(--ok); }
.status.warn { border-color: var(--warn); background: var(--warn-bg); }
.status.over { border-color: var(--over); background: var(--over-bg); }
.status.warn .msg { color: var(--warn); }
.status.over .msg, .status.over .total { color: var(--over); }
.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin-top: 10px; }
.bar > div { height: 100%; background: var(--ok); width: 0; transition: width .6s var(--ease), background-color .3s; }
.status.warn .bar > div { background: var(--warn); }
.status.over .bar > div { background: var(--over); }

.banner { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); font-weight: 600; margin-bottom: 12px; }
.banner a { color: inherit; }
.error { color: var(--over); font-weight: 600; margin-top: 8px; white-space: pre-line; }
.success { white-space: pre-line; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
label.check input { width: 22px; height: 22px; margin: 0; }
.success { color: var(--ok); font-weight: 600; margin-top: 8px; }

/* Productlijst */
#products { position: relative; }  /* offsetTop van de rijen t.o.v. de lijst (slepen) */
.product { display: flex; align-items: center; gap: 8px 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap;
  transition: box-shadow .2s var(--ease), background-color .2s; }
.product:first-child { border-top: 0; }
.product .handle {
  flex: none; width: 28px; height: 48px; padding: 0; margin-right: -4px; border: 0; background: none;
  color: var(--muted); font-size: 1.3rem; cursor: grab; touch-action: none; }
.product.dragging { position: relative; z-index: 2; background: var(--card); box-shadow: var(--shadow-lift);
  border-top-color: transparent; }
.product.dragging + .product { border-top-color: transparent; }
.product.dragging, .product.dropped { border-radius: 10px; }
.product.dropped { animation: settle .7s ease-out; }
body.sorting, body.sorting * { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.product .info { flex: 1 1 140px; min-width: 0; }
.product .name { font-weight: 600; }
.product .meta { font-size: .9rem; color: var(--muted); }
.picon {
  flex: none; width: 48px; height: 48px; border-radius: 12px; background: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
}
.picon img { width: 38px; height: 38px; display: block; }
.picon.small { width: 40px; height: 40px; border-radius: 10px; }
.picon.small img { width: 32px; height: 32px; }
.picon.letter { font-weight: 700; font-size: 1.2rem; color: var(--muted); }

/* Iconenkiezer (beheer) */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 4px; }
.icon-opt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; font-weight: 400;
  padding: 6px 2px; border: 2px solid transparent; border-radius: 12px; cursor: pointer; background: var(--bg);
  font-size: .7rem; line-height: 1.15; text-align: center; color: var(--muted); }
.icon-opt input { position: absolute; opacity: 0; pointer-events: none; }
.icon-opt img { width: 40px; height: 40px; }
.icon-opt .none { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.icon-opt:has(input:checked) { border-color: var(--primary); color: var(--text); }
.icon-opt:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.stepper { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.stepper button { width: 48px; height: 52px; font-size: 1.5rem; font-weight: 700; padding: 0; }
.stepper button.big { background: var(--bg); font-size: 1.2rem; letter-spacing: 1px; }
.stepper .count { display: inline-block; min-width: 52px; text-align: center; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.weight { display: flex; gap: 6px; align-items: center; }
.weight input { width: 90px; height: 52px; text-align: right; }
.weight button { height: 52px; }

.undo-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.undo-row .last { font-size: .95rem; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tr.day { cursor: pointer; transition: background-color .15s; }
tr.detail td { animation: fade .25s ease-out; }
.summary > div { animation: rise .35s var(--ease) both; }
.summary > div:nth-child(2) { animation-delay: .05s; }
.summary > div:nth-child(3) { animation-delay: .1s; }
tr.day.over td { color: var(--over); font-weight: 700; }
tr.day.over td:first-child::before { content: "⚠ "; }
tr.detail td { background: var(--bg); white-space: normal; text-align: left; font-size: .95rem; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.summary .v { font-size: 1.3rem; font-weight: 700; }
.summary .k { font-size: .85rem; color: var(--muted); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.list-item { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1 1 180px; min-width: 0; }
a.btn { text-decoration: none; display: inline-block; }
.list-item .actions { display: flex; gap: 6px; margin-left: auto; flex: none; }
.tag { font-size: .8rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.tag.off { color: var(--over); }

/* Hulpklassen (geen inline styles i.v.m. Content-Security-Policy) */
.full { width: 100%; }
.small { font-size: .9rem; }
.mt-0 { margin-top: 0; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }

/* Tweestapsverificatie */
.code-input { font-size: 1.5rem; letter-spacing: .2em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { background: #ffffff; padding: 10px; border-radius: 12px; width: 220px; max-width: 100%; margin: 8px 0; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { font-family: ui-monospace, monospace; word-break: break-all; background: var(--bg); padding: 6px 8px; border-radius: 8px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: ui-monospace, monospace; font-size: 1.05rem; }
.codes span { background: var(--bg); padding: 6px 8px; border-radius: 8px; text-align: center; }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin: 4px 0; }
.tag.on { color: var(--ok); }

/* 404 */
.notfound { text-align: center; margin-top: 10vh; padding: 32px 16px; }
.notfound-icon { width: 72px; height: 72px; }
a.primary-link { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* Alleen met muis: op een touchscreen blijft :hover na een tik "hangen". */
@media (hover: hover) {
  nav a:hover { background: var(--card); }
  .product .handle:hover { color: var(--text); }
  tr.day:hover { background: var(--bg); }
}

/* Telefoon: navigatie als tabbalk onderaan, binnen bereik van de duim. */
@media (max-width: 640px) {
  nav { padding: 6px 12px 0; }
  nav .account { font-size: .95rem; }
  nav .tabs {
    position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; gap: 0;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  nav .tabs a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    min-height: 56px; padding: 7px 4px 6px; border-radius: 0; font-size: .75rem; color: var(--muted);
  }
  nav .tabs a svg { display: block; }
  nav .tabs a.active { background: none; color: var(--primary); }
  nav .tabs a:hover { background: none; }
  /* Ruimte voor de tabbalk (alleen op pagina's met navigatie). */
  nav ~ main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  /* Toetsenbord open: tabbalk weg, anders schuift hij over de invoer heen. */
  body:has(input:not([type=checkbox], [type=radio]):focus, select:focus, textarea:focus) nav .tabs { display: none; }

  main { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px 12px; }
  h1 { font-size: 1.3rem; margin-top: 4px; }
  th, td { padding: 8px 4px; }
  .status .total { font-size: 2.6rem; }
  .undo-row button { flex: none; white-space: nowrap; }
  /* Overzicht: datums naast elkaar op volle breedte, "Toon" eronder. */
  #period input[type=date] { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }
  #period button { flex-basis: 100%; }
  .quick button { flex: 1 1 auto; padding-left: 8px; padding-right: 8px; }
}
@media (max-width: 360px) {
  .stepper { gap: 4px; }
  .stepper button { width: 42px; }
  .stepper .count { min-width: 40px; }
  .weight input { width: 76px; }
  .undo-row { flex-wrap: wrap; }
  .undo-row button { margin-left: auto; }
}

/* Animaties */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes bump { 40% { transform: scale(1.18); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes settle { from { background-color: color-mix(in srgb, var(--primary) 16%, transparent); } }

/* Pagina-opbouw: kaarten komen kort na elkaar binnen (ook als een verborgen kaart verschijnt). */
main > h1, main > .card, main > form, .banner { animation: rise .4s var(--ease) both; }
main > :nth-child(2) { animation-delay: .04s; }
main > :nth-child(3) { animation-delay: .08s; }
main > :nth-child(4) { animation-delay: .12s; }
main > :nth-child(n+5) { animation-delay: .16s; }
.bump { animation: bump .32s var(--ease); }
.fade-in { animation: fade .35s ease-out; }
.error:not(:empty), .success:not(:empty) { animation: shake .35s ease-in-out; }
.success:not(:empty) { animation-name: fade; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-delay: 0s !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
