:root {
  --paper: #eef0ee;
  --surface: #ffffff;
  --ink: #14181d;
  --muted: #6a7480;
  --rule: #d8dcd8;
  --in: #1f6b4f;
  --out: #a33a2c;
  --mark: #2b6b4f;
  --mark-ink: #ffffff;
  --pending: #8a6d23;
  --radius: 12px;
  --tabs-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101317;
    --surface: #171b21;
    --ink: #e7eae7;
    --muted: #8b95a1;
    --rule: #272d35;
    --in: #5bbd92;
    --out: #e7836f;
    --mark: #6cc39a;
    --mark-ink: #101317;
    --pending: #d0ab55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 0; }
h2 { font-size: 15px; font-weight: 600; margin: 24px 0 10px; }
.card h2 { margin-top: 0; }
a { color: var(--mark); }
.note { color: var(--muted); font-size: 14px; }
.pending { color: var(--pending); }
.in { color: var(--in); }
.out { color: var(--out); }
.back { display: inline-block; font-size: 14px; text-decoration: none; margin-bottom: 4px; }
.code { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; font-size: 14px; overflow-x: auto; }

/* --- formulieren --- */
input, select, button, .button {
  font: inherit; /* 16px: voorkomt dat iOS inzoomt bij focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
button, .button { cursor: pointer; font-weight: 550; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .button.primary { background: var(--mark); color: var(--mark-ink); border-color: var(--mark); }
button.danger, .button.danger { color: var(--out); }
button:disabled { opacity: 0.55; cursor: default; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; min-height: 0; padding: 0; font-weight: 400; }
.button.wide, button.wide { display: flex; width: 100%; margin-top: 12px; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
.stack { display: grid; gap: 12px; }
.stack label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.stack label input, .stack label select { color: var(--ink); width: 100%; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; }

/* --- kop --- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { overflow-wrap: anywhere; }
.totals { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.figure { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.figure.grow { margin-left: auto; text-align: right; color: var(--muted); font-size: 16px; }
.figure small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }

/* --- kaarten en lijsten --- */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.hero { display: grid; gap: 8px; color: inherit; text-decoration: none; }
.hero-main { font-size: 20px; font-weight: 600; line-height: 1.3; }
.amt { font-variant-numeric: tabular-nums; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 12px 14px; color: inherit; text-decoration: none;
}
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--muted); font-size: 13px; }
.row-side { display: grid; gap: 4px; justify-items: end; flex: none; }
.row-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--paper); color: var(--muted); white-space: nowrap; }
.badge.pending { color: var(--pending); background: color-mix(in srgb, var(--pending) 14%, var(--surface)); }
.badge.ok { color: var(--in); background: color-mix(in srgb, var(--in) 14%, var(--surface)); }
.badge.warn { color: var(--out); background: color-mix(in srgb, var(--out) 14%, var(--surface)); }
.flash { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-size: 14px; }
.flash.ok { background: color-mix(in srgb, var(--in) 14%, var(--surface)); color: var(--in); }
.flash.error { background: color-mix(in srgb, var(--out) 14%, var(--surface)); color: var(--out); }
.footer { margin-top: 32px; text-align: center; }

/* --- avatar / chips --- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; background: var(--mark); color: var(--mark-ink); font-weight: 700;
}
.avatar.small { width: 24px; height: 24px; font-size: 12px; vertical-align: middle; margin-right: 4px; }
.who { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border-radius: 999px; min-height: 40px; padding: 4px 14px 4px 6px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px; color: var(--ink); background: var(--surface); border: 1px solid var(--rule);
}
.chip.toggle { position: relative; cursor: pointer; }
.chip.toggle input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.chip.on { border-color: var(--mark); color: var(--mark); box-shadow: inset 0 0 0 1px var(--mark); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.quick .chip { padding: 4px 12px; min-height: 36px; font-weight: 500; }

/* --- foto kiezen --- */
.photo-pick {
  display: grid; place-items: center; min-height: 160px; border: 2px dashed var(--rule); border-radius: var(--radius);
  background: var(--surface); padding: 16px; text-align: center; cursor: pointer; position: relative; overflow: hidden;
}
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.photo-empty { display: grid; gap: 10px; justify-items: center; }
.photo-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.photo-buttons .button { position: relative; overflow: hidden; }
.photo-pick .link { margin-top: 8px; }
.photo-pick .link[hidden] { display: none; }
.photo-empty svg { width: 36px; height: 36px; fill: none; stroke: var(--mark); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.photo-pick.has-photo .photo-empty { display: none; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.previews img { max-width: 100%; max-height: 220px; border-radius: 8px; }
.previews img:not(:only-child) { width: 88px; height: 88px; object-fit: cover; }
.previews[hidden] { display: none; }
.batch-row .thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }

/* --- regels op een bon --- */
.hint { margin: 6px 0 10px; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 8px 8px 8px 12px;
}
.item.unassigned { border-left: 4px solid var(--pending); padding-left: 9px; }
.item.settled { opacity: 0.7; }
.item.settled .share.on { background: var(--muted); border-color: var(--muted); }
.item-name {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 4px 0; min-height: 0;
  display: grid; gap: 2px; color: inherit; font-weight: 500;
}
.item-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-name small { color: var(--muted); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.item-name:disabled { opacity: 1; }
.shares { display: flex; gap: 6px; flex: none; }
.share {
  display: grid; justify-items: center; gap: 0; width: 56px; min-height: 52px; padding: 6px 2px;
  border-radius: 10px; border: 1px solid var(--rule); background: var(--paper); color: var(--muted);
}
.share b { font-size: 17px; line-height: 1.1; }
.share small { font-size: 11px; font-variant-numeric: tabular-nums; opacity: 0.8; }
.share.on { background: var(--mark); color: var(--mark-ink); border-color: var(--mark); }
.share.on small { opacity: 0.95; }
.share:disabled { opacity: 0.8; }
.add-item { margin-top: 12px; }
.add-row { display: grid; grid-template-columns: 1fr 56px 90px 48px; gap: 8px; }
.add-row input { min-width: 0; padding: 10px 8px; }
.add-row .qty, .add-row .price { text-align: right; }

/* --- afrekening --- */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 12px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 0 0 6px; }
.table td { padding: 8px 0; border-top: 1px solid var(--rule); }
.table th:not(:first-child), .table td:not(:first-child) { text-align: right; }
.transfers { display: grid; gap: 6px; margin: 8px 0 4px; }
.transfer { background: var(--paper); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.transfer .amt { float: right; }

.ratio { font-style: normal; color: var(--mark); }
.info-btn { width: 44px; padding: 0; }
.info-i { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--mark); color: var(--mark); align-items: center; justify-content: center; font: italic 700 15px/1 Georgia, serif; }
.info-line { margin: -6px 0 12px; }
.info-head { margin: 0 0 8px; }
#info-text { margin: 0 0 8px; line-height: 1.5; }
.parts { border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px 4px; margin: 0; min-inline-size: 0; max-width: 100%; }
.two input, .parts-row input { min-width: 0; }
dialog { max-width: 92vw; }
.parts legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.parts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.parts-row label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.parts-row input { width: 100%; text-align: center; }
.parts .note { margin: 8px 0 6px; }

/* --- dialoog --- */
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 420px); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,0.45); }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog-actions .danger { margin-left: auto; }

/* --- tabs onderin --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs a {
  flex: 1; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a[aria-current=page] { color: var(--mark); font-weight: 600; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--ink); color: var(--paper); padding: 12px 14px; border-radius: 12px; font-size: 14px; z-index: 6;
}
.toast[hidden] { display: none; }

.login-page { padding-bottom: 0; }
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 16px; }
.login img { border-radius: 14px; }
.login h1 { margin: 0 0 8px; }

@media (min-width: 560px) {
  .tabs { position: sticky; top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--rule); order: -1; }
  body { display: flex; flex-direction: column; padding-bottom: 24px; }
  .toast { bottom: 16px; left: auto; right: 16px; max-width: 360px; }
}
