:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1c2321;
  --muted: #5d6763;
  --line: #dfe3df;
  --accent: #0f5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #e3efeb;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --warn: #8a5300;
  --warn-soft: #fff4e0;
  --ok: #1f6f3a;
  --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .88rem; margin: .5rem 0 0; }
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 12px 110px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 12px;
}

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px; background: var(--accent); color: var(--accent-ink);
}
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand span { font-size: .8rem; opacity: .85; }
.top form { margin: 0; }
button.link { background: none; border: 0; color: inherit; font: inherit; font-size: .88rem; text-decoration: underline; padding: 8px 0; cursor: pointer; }

/* inputs + buttons */
input {
  font: inherit; font-size: 1rem; color: var(--ink); background: #fff;
  border: 1.5px solid #b9c1bd; border-radius: 10px; padding: 10px 12px; min-height: 46px; width: 100%;
}
input:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
input:disabled { background: #f0f1ef; color: #9aa29e; }
input.invalid { border-color: var(--bad); background: var(--bad-soft); }
button { font: inherit; cursor: pointer; border-radius: 10px; min-height: 46px; padding: 0 18px; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 600; }
.secondary { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); font-weight: 600; }
.wide { width: 100%; }
.icon { min-width: 44px; padding: 0; background: #fff; border: 1.5px solid var(--line); color: var(--ink); font-size: 1.1rem; }

/* login */
.login { max-width: 420px; margin: 0 auto; padding: 40px 16px; }
.login label { display: block; margin: 14px 0 6px; font-weight: 600; }
.login button { margin-top: 20px; }

/* totaal dagbudget */
.hero { padding: 18px 16px; }
.big-label { display: block; font-weight: 700; font-size: 1.15rem; margin-bottom: 8px; }
.money { display: flex; align-items: center; gap: 10px; }
.money .cur { font-size: 2rem; font-weight: 700; color: var(--accent); }
.money input { font-size: 2.1rem; font-weight: 700; min-height: 64px; padding: 6px 12px; flex: 1; min-width: 0; }
.money .unit { color: var(--muted); white-space: nowrap; }
.distributed { margin: .7rem 0 0; font-weight: 600; color: var(--accent); min-height: 1.4em; }
.distributed.busy { color: var(--muted); font-weight: 400; }
.field-error { color: var(--bad); font-weight: 600; margin: .5rem 0 0; }

.notice {
  background: var(--accent-soft); color: var(--accent); border-radius: 10px;
  padding: 10px 14px; margin: 0 0 12px; font-size: .92rem; font-weight: 600;
}
.banner { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; font-size: .95rem; }
.banner.error { background: var(--bad-soft); color: var(--bad); border: 1px solid #f3c2bd; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f1d7a8; }
.banner.ok { background: #e7f4ea; color: var(--ok); border: 1px solid #bfe0c8; }
.banner ul { margin: .3rem 0 0; padding-left: 1.2rem; }

/* niveau-kop met teller */
.level-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 6px; }
.level-head h2 { margin: 0; }
.counter { font-size: .9rem; font-weight: 600; color: var(--accent); }
.counter.over { color: var(--bad); }
.counter.zero { color: var(--warn); }
.counter small { font-weight: 400; color: var(--muted); }

/* percentage + bedrag */
.ctl { display: grid; grid-template-columns: minmax(0, 7.5rem) 1fr; align-items: center; gap: 10px; }
.pct { position: relative; }
.pct input { padding-right: 30px; text-align: right; }
.pct::after { content: "%"; position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount small { font-weight: 400; color: var(--muted); }

/* collecties */
.coll { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.coll:first-of-type { border-top: 0; }
.coll-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; }
.coll-title .order { display: flex; gap: 6px; }
.cpc { display: grid; grid-template-columns: 1fr minmax(0, 8rem); align-items: center; gap: 10px; margin-top: 10px; }
.cpc label { font-size: .92rem; }
.cpc .money-sm { position: relative; }
.cpc .money-sm input { padding-left: 28px; text-align: right; }
.cpc .money-sm::before { content: "€"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* categorieën */
.cat { border-top: 1px solid var(--line); padding: 10px 0; }
.cat:first-of-type { border-top: 0; }
.cat-head {
  display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 4px 0 8px;
  text-align: left; color: var(--ink); min-height: 40px;
}
.cat-head .chev { display: inline-block; width: 1.1em; transition: transform .15s; color: var(--accent); font-size: .85rem; }
.cat-head[aria-expanded="true"] .chev { transform: rotate(90deg); }
.cat-head .name { font-weight: 600; overflow-wrap: anywhere; }
.cat-head .count { color: var(--muted); font-size: .85rem; white-space: nowrap; margin-left: auto; }
.cat.inactive .cat-head .name, .cat.inactive .amount { color: #9aa29e; }
.cat .note { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.products { margin: 10px 0 2px; padding: 10px; background: #f8f9f7; border-radius: 10px; }
.products .level-head { margin-bottom: 8px; }
.prod { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.prod:first-of-type { border-top: 0; }
.prod img, .prod .noimg { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: #e6e9e6; }
.prod .pinfo { min-width: 0; }
.prod .ptitle { display: block; font-weight: 600; font-size: .95rem; overflow-wrap: anywhere; color: var(--ink); text-decoration: none; }
.prod .price { color: var(--muted); font-size: .88rem; }
.prod .ctl { grid-column: 1 / -1; }
.prod.soldout { opacity: .55; filter: grayscale(1); }
.prod .so { display: block; color: var(--bad); font-size: .82rem; font-weight: 600; filter: none; }

/* feed + geschiedenis */
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history .when { font-size: .92rem; }
.history button { min-height: 40px; padding: 0 12px; flex-shrink: 0; }
details pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .78rem; background: #f3f4f2; padding: 8px; border-radius: 8px; max-height: 260px; overflow: auto; }

/* opslaan-balk */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.savebar #save-status { font-size: .88rem; color: var(--muted); min-width: 0; }
.savebar #save-status.dirty { color: var(--warn); font-weight: 600; }
.savebar button { min-width: 130px; }
#toast {
  position: fixed; left: 12px; right: 12px; bottom: 84px; z-index: 7; max-width: 600px; margin: 0 auto;
  background: #1c2321; color: #fff; border-radius: 10px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.loading { padding: 20px 4px; }
