/* Hapklaar – eigen ontwerp */
:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #ece9e1;
  --line: #ddd8cc;
  --text: #1d2420;
  --muted: #69716c;
  --accent: #1f6b4c;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe2;
  --kcal: #1f6b4c;
  --prot: #c4532d;
  --carb: #c9930f;
  --fat: #3f6fc0;
  --danger: #b3261e;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4b00;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 18px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614; --surface: #19211e; --surface-2: #232d29; --line: #2e3a35; --text: #e8eee9; --muted: #96a29b;
    --accent: #5cc493; --accent-ink: #08130e; --accent-soft: #1d3a2d; --kcal: #5cc493; --prot: #f08a63; --carb: #e8b938; --fat: #7ea5ee;
    --danger: #ff8a80; --warn-bg: #3a2f12; --warn-ink: #f5d98b; --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101614; --surface: #19211e; --surface-2: #232d29; --line: #2e3a35; --text: #e8eee9; --muted: #96a29b;
  --accent: #5cc493; --accent-ink: #08130e; --accent-soft: #1d3a2d; --kcal: #5cc493; --prot: #f08a63; --carb: #e8b938; --fat: #7ea5ee;
  --danger: #ff8a80; --warn-bg: #3a2f12; --warn-ink: #f5d98b; --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(var(--safe-t) + 10px) 16px 10px; display: flex; align-items: center; gap: 8px; min-height: 56px;
}
.topbar h1 { font-size: 1.35rem; margin: 0; flex: 1; letter-spacing: -.01em; }
.view { padding: 4px 16px 16px; outline: none; }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .7rem; padding: 6px 0; max-width: 110px; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tab-add {
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; margin-top: -22px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); flex: none;
}
.tab-add svg { width: 28px; height: 28px; stroke-width: 2.4; }
@media (min-width: 900px) {
  .tabbar { max-width: 640px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; }
}

/* Kaarten & knoppen */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h2, .section-title { font-size: 1.02rem; margin: 0 0 10px; }
.section-title { margin: 18px 4px 8px; color: var(--muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: .9rem; border-radius: 11px; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:active, .btn:active { transform: scale(.97); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* Formulieren */
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin: 0 0 4px 2px; }
.input, select.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seg { display: flex; background: var(--surface-2); border-radius: 13px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 42px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); padding: 0 6px; font-size: .92rem; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.choice { display: flex; flex-direction: column; gap: 8px; }
.choice button { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 14px; min-height: 52px; }
.choice button.on { border-color: var(--accent); background: var(--accent-soft); }
.choice small { display: block; color: var(--muted); }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: .9rem; margin-top: 10px; }

/* Dagoverzicht */
.datebar { display: flex; align-items: center; gap: 4px; }
.datebar .label { font-weight: 700; font-size: 1.15rem; min-width: 0; text-align: center; flex: 1; }
.summary { padding: 18px 16px 16px; }
.kcal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.kcal-left { font-size: 2.1rem; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.kcal-left small { font-size: .95rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kcal-left.over { color: var(--danger); }
.bar { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--c, var(--accent)); transition: width .35s ease; }
.bar.over > i { background: repeating-linear-gradient(45deg, var(--c), var(--c) 6px, color-mix(in srgb, var(--c) 70%, #fff) 6px, color-mix(in srgb, var(--c) 70%, #fff) 12px); }
.bar.big { height: 16px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.macro .name { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.macro .name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.macro .val { font-weight: 700; margin: 2px 0 6px; font-size: 1.02rem; }
.macro .val small { font-weight: 500; color: var(--muted); }
.macro .left { font-size: .78rem; color: var(--muted); margin-top: 5px; }
.macro .bar { height: 8px; }

.meal { padding: 0; overflow: hidden; }
.meal-head { display: flex; align-items: center; gap: 10px; padding: 12px 8px 12px 16px; }
.meal-head .t { font-weight: 700; }
.meal-head .k { color: var(--muted); font-size: .88rem; }
.meal-ico { width: 36px; height: 36px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.meal-ico svg { width: 20px; height: 20px; }
.meal-add { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.meal-add svg { stroke-width: 2.4; }
.meal-actions { display: flex; gap: 8px; padding: 0 16px 12px; }
.chip-btn { border: 1px dashed var(--line); background: transparent; border-radius: 99px; padding: 7px 12px; font-size: .85rem; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; min-height: 36px; }
.chip-btn svg { width: 16px; height: 16px; }

.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-top: 1px solid var(--line); min-height: 58px; position: relative; background: var(--surface); }
.item .main { flex: 1; min-width: 0; cursor: pointer; }
.item .nm { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .kc { font-weight: 650; font-size: .95rem; text-align: right; white-space: nowrap; }
.item .kc small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.item .thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); font-size: .7rem; font-weight: 700; }
.quick-add { width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent); background: transparent; display: grid; place-items: center; flex: none; }
.quick-add.done { background: var(--accent); color: var(--accent-ink); }
.swipe-wrap { position: relative; overflow: hidden; }
.swipe-del { position: absolute; inset: 0 0 0 auto; width: 100%; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: flex-end; padding-right: 22px; font-weight: 600; }
.swipe-wrap .item { transition: transform .2s; touch-action: pan-y; }

.badge { display: inline-block; font-size: .68rem; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); vertical-align: 1px; text-transform: uppercase; letter-spacing: .03em; }
.badge.better { background: var(--accent-soft); color: var(--accent); text-transform: none; letter-spacing: 0; font-size: .75rem; }
.ns { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; font-size: .7rem; font-weight: 800; color: #fff; text-transform: uppercase; vertical-align: -3px; }
.ns-a { background: #1e8a4c; } .ns-b { background: #7bb33a; } .ns-c { background: #e3b51b; } .ns-d { background: #e07a1f; } .ns-e { background: #d0402a; }

/* Sheets (volledig scherm op mobiel) */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; top: 0; background: var(--bg); display: flex; flex-direction: column;
  animation: up .25s cubic-bezier(.2, .8, .2, 1); max-width: 640px; margin: 0 auto;
}
@media (min-width: 700px) { .sheet { top: 4vh; bottom: 4vh; border-radius: 22px; box-shadow: 0 20px 60px rgb(0 0 0 / .3); overflow: hidden; } }
.sheet-head { display: flex; align-items: center; gap: 6px; padding: calc(var(--safe-t) + 8px) 8px 8px; }
@media (min-width: 700px) { .sheet-head { padding-top: 8px; } }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.1rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 16px 20px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.searchbar { display: flex; gap: 8px; align-items: center; }
.searchbox { flex: 1; position: relative; }
.searchbox svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.searchbox .input { padding-left: 42px; }
.scan-btn { width: 52px; height: 48px; border-radius: 13px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.meal-pick { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.meal-pick button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 13px; font-size: .88rem; white-space: nowrap; min-height: 36px; }
.meal-pick button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs { display: flex; gap: 4px; margin: 12px 0 8px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 10px 12px; font-weight: 600; color: var(--muted); border-bottom: 2.5px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-color: var(--accent); }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list .item:first-child { border-top: 0; }
.list-label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 14px 4px 6px; display: flex; gap: 8px; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 26px 16px; }
.empty svg { width: 36px; height: 36px; opacity: .6; margin-bottom: 6px; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Product-detail */
.prod-head { display: flex; gap: 14px; align-items: center; margin: 4px 0 14px; }
.prod-head img, .prod-head .thumb { width: 64px; height: 64px; border-radius: 14px; object-fit: contain; background: #fff; flex: none; }
.prod-head h3 { margin: 0; font-size: 1.15rem; }
.amount { display: flex; gap: 10px; align-items: stretch; }
.amount .input { font-size: 1.5rem; font-weight: 700; text-align: center; min-height: 58px; }
.amount .unit { display: grid; place-items: center; padding: 0 10px; color: var(--muted); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button { width: 50px; min-height: 58px; border: 1px solid var(--line); background: var(--surface); font-size: 1.4rem; font-weight: 600; }
.stepper button:first-child { border-radius: 13px 0 0 13px; }
.stepper button:last-child { border-radius: 0 13px 13px 0; }
.stepper .input { border-radius: 0; border-left: 0; border-right: 0; width: 90px; }
.portions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.portions button { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 12px; min-height: 44px; font-size: .9rem; text-align: left; }
.portions button small { color: var(--muted); display: block; font-size: .75rem; }
.portions button.on { border-color: var(--accent); background: var(--accent-soft); }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 16px 0 6px; text-align: center; }
.preview div { background: var(--surface); border-radius: 14px; padding: 10px 4px; box-shadow: var(--shadow); }
.preview b { display: block; font-size: 1.15rem; }
.preview span { font-size: .72rem; color: var(--muted); }
.preview .p b { color: var(--prot); } .preview .c b { color: var(--carb); } .preview .f b { color: var(--fat); } .preview .k b { color: var(--kcal); }
table.nutr { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.nutr td { padding: 7px 2px; border-top: 1px solid var(--line); }
table.nutr td:last-child { text-align: right; }
table.nutr tr.sub td:first-child { padding-left: 16px; color: var(--muted); }
table.nutr th { text-align: right; font-size: .75rem; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
table.nutr th:first-child { text-align: left; }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: 20px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; left: 10%; right: 10%; top: 25%; bottom: 25%; border: 3px solid rgb(255 255 255 / .9); border-radius: 18px; box-shadow: 0 0 0 999px rgb(0 0 0 / .35); }
.scanner .laser { position: absolute; left: 14%; right: 14%; top: 50%; height: 2px; background: #ff5a3c; box-shadow: 0 0 10px #ff5a3c; animation: laser 1.6s ease-in-out infinite alternate; }
@keyframes laser { from { transform: translateY(-40px); } to { transform: translateY(40px); } }
.scanner .msg { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 3px #000; padding: 0 16px; }

/* Voortgang */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); stroke: none; }
.chart .goal { stroke: var(--text); stroke-dasharray: 4 4; stroke-width: 1.2; opacity: .5; fill: none; }
.chart .bar-k { fill: var(--kcal); }
.chart .bar-k.over { fill: var(--prot); }
.chart .bar-empty { fill: var(--surface-2); }
.chart .line-p { stroke: var(--prot); stroke-width: 2.5; fill: none; }
.chart .dot-p { fill: var(--surface); stroke: var(--prot); stroke-width: 2; }
.chart .line-w { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.chart .dot-w { fill: var(--accent); stroke: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 12px; }
.stat b { font-size: 1.25rem; display: block; }
.stat span { font-size: .8rem; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); transform: translate(-50%, 20px); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 10px 10px 16px; border-radius: 14px; display: flex; gap: 12px; align-items: center;
  opacity: 0; pointer-events: none; transition: all .25s; max-width: calc(100% - 32px); font-size: .93rem; box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: transparent; color: var(--accent-soft); font-weight: 700; padding: 6px 8px; }
:root[data-theme="dark"] .toast button { color: var(--accent-ink); }

/* Welkom */
.hero { text-align: center; padding: 26px 8px 8px; }
.hero .logo { width: 84px; height: 84px; border-radius: 24px; }
.hero h1 { margin: 12px 0 4px; font-size: 1.8rem; letter-spacing: -.02em; }
.goal-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.goal-tiles .stat b { font-size: 1.4rem; }
.ing-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.ing-row:first-child { border-top: 0; }
.ing-row .input { width: 88px; min-height: 42px; text-align: right; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.footer-note { font-size: .78rem; color: var(--muted); text-align: center; margin: 22px 0 8px; }
