:root {
  color-scheme: dark;
  --bg: #0e1013;
  --surface: #171a1f;
  --surface-2: #20242b;
  --border: #2b3038;
  --text: #eceef1;
  --muted: #98a1ad;
  --faint: #6b7380;
  --accent: #5fd38d;
  --accent-ink: #072112;
  --warn: #f3b54a;
  --danger: #ff7a7a;
  --radius: 14px;
  --header-h: 76px;
  --bar-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  isolation: isolate;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 8px;
  border-bottom: 1px solid var(--border);
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sync {
  border: 0;
  background: none;
  padding: 6px 0 6px 8px;
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
}
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sync[data-state="busy"]::before { background: var(--muted); }
.sync[data-state="offline"] { color: var(--warn); }
.sync[data-state="offline"]::before { background: var(--warn); }
.sync[data-state="pending"]::before { background: var(--warn); }

.progress { margin-top: 8px; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 200ms ease-out; }
.progress-label { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- Lijst ---------- */
.list { padding: 4px 12px calc(var(--bar-h) + var(--safe-b) + 88px); }

.cat { margin-top: 14px; }
.cat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.cat-count { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; font-weight: 500; }
.cat.done .cat-head { color: var(--faint); }
.cat.done .cat-count { color: var(--accent); }

.items { display: flex; flex-direction: column; gap: 6px; }

.item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  user-select: none;
  -webkit-user-select: none;
}
.item:active { background: var(--surface-2); }

.check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--faint);
  display: grid;
  place-items: center;
  flex: none;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; color: var(--accent-ink); }

.item-text { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.name { font-size: 18px; font-weight: 500; overflow-wrap: anywhere; }
.qty { margin-left: auto; font-size: 15px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Afgevinkt: zelfde plek, enkel visueel gedempt */
.item[aria-pressed="true"] .item-text { opacity: 0.42; }
.item[aria-pressed="true"] .name { text-decoration: line-through; text-decoration-thickness: 2px; }
.item[aria-pressed="true"] .check { background: var(--accent); border-color: var(--accent); }
.item[aria-pressed="true"] .check svg { opacity: 1; }

.item.pending .name::after { content: " •"; color: var(--warn); }

.item.new { animation: flash 1.6s ease-out; }
@keyframes flash {
  from { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
  to { background: var(--surface); }
}

/* ---------- Lege staat ---------- */
.empty { padding: 56px 28px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 8px; }
.empty p { margin: 0; max-width: 34ch; margin-inline: auto; }
.empty q { color: var(--text); }

/* ---------- Duimbalk ---------- */
.bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  isolation: isolate;
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1.25fr;
  gap: 6px;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bar-btn {
  min-height: var(--bar-h);
  border: 1px solid transparent;
  border-radius: 12px;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--muted);
}
.bar-btn:active:not(:disabled) { background: var(--surface-2); }
.bar-btn:disabled { color: var(--faint); opacity: 0.6; }
.bar-btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.bar-btn.primary:active { background: color-mix(in srgb, var(--accent) 85%, white); }
#btn-clear:not(:disabled) { color: var(--text); }
#btn-clear.ready { border-color: var(--accent); color: var(--accent); }
#btn-wake[aria-pressed="true"] { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
#btn-refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--bar-h) + var(--safe-b) + 28px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 16px;
  min-height: 52px;
  border-radius: 12px;
  background: #2c323b;
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  font-size: 15px;
}
.toast.error { background: #4a2326; }
.toast-msg { flex: 1; }
.toast-action {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  min-height: 44px;
}

/* ---------- Toevoeg-sheet ---------- */
.sheet {
  width: min(100%, 560px);
  max-width: 100%;
  max-height: 100dvh;
  margin: 0 auto auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 18px;
  border: 0;
  border-radius: 0 0 18px 18px;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-head .btn-text { justify-self: start; }
.sheet-head .btn-primary { justify-self: end; }

.field { display: block; margin-top: 12px; }
.field-label { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.hint { font-weight: 400; color: var(--faint); }
.field input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 18px;
}
.field input:focus { border-color: var(--accent); outline: none; }

.btn-primary {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.45; }
.btn-text { min-height: 44px; padding: 0 6px; border: 0; background: none; color: var(--muted); }
.btn-block { width: 100%; min-height: 52px; margin-top: 16px; font-size: 17px; }

.suggestions { margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-2);
  font-size: 15px;
}
.chip:active { background: var(--border); }
.chip[aria-checked="true"] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.cat-picker { margin-top: 14px; }
.cat-picker summary { min-height: 44px; display: flex; align-items: center; gap: 6px; font-size: 15px; color: var(--muted); cursor: pointer; list-style: none; }
.cat-picker summary::-webkit-details-marker { display: none; }
.cat-picker summary #add-cat-label { color: var(--text); font-weight: 600; }
.cat-picker[open] summary .hint { visibility: hidden; }
.cat-picker .chips { padding-top: 4px; }

.error { margin: 10px 0 0; color: var(--danger); font-size: 15px; }

/* ---------- Login ---------- */
.login { max-width: 420px; margin: 0 auto; padding: 72px 24px 24px; text-align: center; }
.login img { border-radius: 18px; }
.login h1 { font-size: 24px; margin: 16px 0 8px; }
.login p { color: var(--muted); margin: 0 0 8px; }
.login form { text-align: left; }

@media (prefers-reduced-motion: reduce) {
  .item.new, #btn-refresh.spinning svg { animation: none; }
  .progress-bar { transition: none; }
}
