:root {
  --bg: #f6f4ef;
  --surface: #fffdf9;
  --surface-2: #efece5;
  --ink: #1f2328;
  --muted: #6d7078;
  --faint: #a6a8ad;
  --line: #e5e1d8;
  --accent: #2f6f5e;
  --accent-soft: #dcebe5;
  --accent-ink: #ffffff;
  --progress: #b7791f;
  --late: #c2410c;
  --warn: #92400e;
  --warn-bg: #fbefd9;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(40, 32, 18, .18);
  --radius: 16px;
  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1c1e21;
    --surface-2: #25282c;
    --ink: #ececea;
    --muted: #9b9ea4;
    --faint: #62666c;
    --line: #2d3034;
    --accent: #63b59d;
    --accent-soft: #1d3530;
    --accent-ink: #0c1d18;
    --progress: #e0a84a;
    --late: #f0895b;
    --warn: #f2c27a;
    --warn-bg: #3a2c14;
    --danger: #f97066;
    --shadow: 0 18px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
  border-bottom: 1px solid var(--line);
}
.titlebar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
h1 { font: 600 30px/1.05 var(--serif); margin: 6px 0 2px; letter-spacing: -.01em; }
.today { color: var(--muted); font-size: 14px; }
.today::first-letter { text-transform: uppercase; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.searchbar { display: flex; gap: 8px; margin-top: 10px; }
.searchbar input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 9px 12px; outline: none; }
.searchbar input:focus { border-color: var(--accent); }
.link-btn { color: var(--accent); font-weight: 600; padding: 0 4px; }

.tabs { display: flex; gap: 2px; margin: 12px -16px 0; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; padding: 8px 12px 10px; color: var(--muted); font-weight: 500; font-size: 15px;
  border-bottom: 2px solid transparent; display: inline-flex; align-items: center; gap: 6px;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.badge { background: var(--late); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: inline-grid; place-items: center; padding: 0 5px; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 10px 16px 12px; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; color: var(--ink); white-space: nowrap;
}
.chip i, .cat-pill i, .group-head i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.ghost { color: var(--muted); border-style: dashed; }
.chip.ghost.on { background: var(--surface-2); color: var(--ink); border-color: var(--line); border-style: solid; }
.chip small { color: var(--muted); font-size: 12px; }

/* ---------- Lijst ---------- */
main { padding: 4px 0 0; }
.group { margin-top: 14px; }
.group-head {
  font: 600 13px/1 var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 16px;
}
.group-head span { margin-left: auto; font-weight: 500; letter-spacing: 0; }
.tasks { list-style: none; margin: 0; padding: 0; background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
@media (min-width: 640px) {
  .tasks { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 16px; overflow: hidden; }
}

.task {
  display: grid; grid-template-columns: 48px 1fr 40px; align-items: start;
  border-top: 1px solid var(--line); position: relative;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: background .15s;
}
.task:first-child { border-top: 0; }
.task.pressing { background: var(--surface-2); }
.task.fresh { animation: fresh 1.4s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }

.dot { width: 48px; height: 48px; display: grid; place-items: center; color: var(--faint); }
.dot svg { width: 24px; height: 24px; transition: transform .15s; }
.dot:active svg { transform: scale(.85); }
.dot .ring { stroke: currentColor; }
.dot .fill { fill: var(--progress); stroke: none; }
.dot .solid { fill: var(--accent); stroke: var(--accent); }
.dot .check { stroke: var(--accent-ink); stroke-width: 2.4; }
.dot .slash { stroke: currentColor; stroke-width: 2; }
.s-in_progress > .dot, .s-in_progress .dot { color: var(--progress); }
.s-moved > .dot { color: var(--muted); }
.p-high:not(.s-done):not(.s-cancelled) > .dot { color: var(--late); }

.body { padding: 13px 0 12px; min-width: 0; cursor: pointer; }
.title { font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.prio { color: var(--late); font-weight: 800; margin-right: 5px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 13px; color: var(--muted); align-items: center; }
.meta-ic { display: inline-flex; align-items: center; gap: 3px; }
.mini { width: 14px; height: 14px; stroke-width: 2; }
.cat-pill { display: inline-flex; align-items: center; gap: 5px; }
.due.late { color: var(--late); font-weight: 600; }
.due.moved { color: var(--ink); font-weight: 500; }
.flag { color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 12px; }
.next { font-size: 13px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { width: 40px; height: 48px; display: grid; place-items: center; color: var(--faint); }
.more:hover { color: var(--ink); }

.s-done .title { color: var(--muted); }
.s-done .meta, .s-done .next { color: var(--faint); }
.s-moved .title { color: var(--muted); }
.s-cancelled .body { text-decoration: line-through; text-decoration-color: var(--muted); text-decoration-thickness: 1.5px; color: var(--faint); }
.s-cancelled .title { color: var(--faint); }

.empty { text-align: center; color: var(--muted); padding: 64px 24px; }
.empty svg { width: 44px; height: 44px; opacity: .35; }
.empty svg .solid { fill: var(--accent); stroke: var(--accent); }
.empty svg .check { stroke: var(--accent-ink); stroke-width: 2.4; }
.empty p { margin: 12px 0 4px; font: 500 18px var(--serif); color: var(--ink); }
.hint { color: var(--faint); font-size: 13px; text-align: center; margin: 18px 16px; }

/* ---------- Snel toevoegen ---------- */
.quickadd {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex; gap: 8px; max-width: 760px; margin: 0 auto;
}
.quickadd input {
  flex: 1; min-width: 0; height: 50px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 16px; outline: none; box-shadow: 0 4px 18px rgba(40, 32, 18, .08); font-size: 16px;
}
.quickadd input:focus { border-color: var(--accent); }
.add-btn { width: 50px; height: 50px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.add-btn svg { stroke-width: 2.4; }

/* ---------- Sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(15, 12, 8, .38); z-index: 20; opacity: 0; transition: opacity .2s; }
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.tall { max-height: 94vh; }
.sheet.show { transform: none; }
.sheet + .sheet.show { z-index: 22; }
#menuSheet { z-index: 23; }
@media (min-width: 700px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; width: 540px; max-height: 86vh; border-radius: 20px;
    transform: translate(-50%, -46%); opacity: 0; transition: transform .2s, opacity .2s; padding-bottom: 20px;
  }
  .sheet.show { transform: translate(-50%, -50%); opacity: 1; }
  #menuSheet { width: 400px; }
  .grab { display: none; }
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.loading { color: var(--muted); text-align: center; padding: 30px; }

.menu-title { font: 600 17px/1.3 var(--serif); margin: 4px 4px 12px; overflow-wrap: anywhere; }
.menu-opts { display: grid; gap: 2px; }
.menu-opt { display: flex; align-items: center; gap: 12px; padding: 4px 8px 4px 0; border-radius: 12px; text-align: left; min-height: 52px; }
.menu-opt:hover { background: var(--surface-2); }
.menu-opt .dot { width: 44px; height: 44px; }
.menu-opt b { font-weight: 500; display: block; }
.menu-opt small { color: var(--muted); font-size: 13px; }
.menu-opt.current { background: var(--accent-soft); }
.menu-opt.s-cancelled b { text-decoration: line-through; text-decoration-color: var(--muted); }
.move-panel { background: var(--surface-2); border-radius: 14px; padding: 12px; margin: 6px 0 4px; }
.quick-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.quick-dates .chip { justify-content: space-between; border-radius: 12px; padding: 10px 12px; }
.pick-date { display: flex; gap: 8px; margin-top: 8px; }
.pick-date input { flex: 1; min-width: 0; }
.menu-link { width: 100%; padding: 14px; color: var(--accent); font-weight: 600; margin-top: 6px; border-top: 1px solid var(--line); }

input[type=date], select, .fields input {
  height: 42px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); padding: 0 10px; outline: none; width: 100%;
}
input[type=date]:focus, select:focus { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); width: 100%; margin-top: 18px; background: transparent; }

/* Detail */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.detail-head h3 { font: 600 20px var(--serif); margin: 0; }
.status-seg { display: flex; gap: 2px; background: var(--surface-2); border-radius: 14px; padding: 3px; flex: 1; max-width: 420px; }
.status-seg button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 2px 6px; border-radius: 11px; color: var(--muted); min-width: 0; }
.status-seg .dot { width: 30px; height: 30px; color: inherit; }
.status-seg small { font-size: 11px; line-height: 1.1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.status-seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.status-seg button.on.s-in_progress .dot { color: var(--progress); }
.status-seg button.on.s-cancelled small { text-decoration: line-through; }

.moved-note, .warn-note { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
.moved-note { background: var(--surface-2); }
.warn-note { background: var(--warn-bg); color: var(--warn); }

.title-input {
  width: 100%; border: 0; background: transparent; outline: none; resize: none; overflow: hidden;
  font: 600 22px/1.3 var(--serif); padding: 8px 0; margin: 4px 0 6px;
}
.title-input:focus { box-shadow: 0 2px 0 var(--accent); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields label span, .notes-label span { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.date-wrap { position: relative; }
.date-wrap .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 16px; line-height: 1; }

.steps-block { margin-top: 18px; }
.steps-block h4, .settings-block h4 { font: 600 13px var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 4px; display: flex; gap: 8px; }
.steps-block h4 span { font-weight: 500; }
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--line); }
.step .dot { width: 40px; height: 42px; flex: none; }
.step .dot svg { width: 20px; height: 20px; }
.step-text { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 10px 0; }
.step-text:focus { box-shadow: 0 2px 0 var(--accent); }
.step.done .step-text { color: var(--muted); }
.step time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.step .icon-btn { opacity: .5; }
.step:hover .icon-btn { opacity: 1; }
.step-add input { width: 100%; border: 0; border-bottom: 1px dashed var(--line); background: transparent; padding: 11px 0 11px 40px; outline: none; color: var(--ink); }
.step-add input::placeholder { color: var(--faint); }
.step-add input:focus { border-bottom-color: var(--accent); border-bottom-style: solid; }

.notes-label { display: block; margin-top: 18px; }
.notes-label textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 10px 12px; outline: none; resize: vertical; min-height: 80px; line-height: 1.45; }
.notes-label textarea:focus { border-color: var(--accent); }

.history { margin-top: 16px; }
.history summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; padding: 6px 0; list-style: none; }
.history summary::-webkit-details-marker { display: none; }
.history summary::before { content: "▸ "; }
.history[open] summary::before { content: "▾ "; }
.history summary span { color: var(--faint); font-weight: 500; }
.history ul { list-style: none; margin: 4px 0 0; padding: 0; font-size: 14px; }
.history li { display: grid; grid-template-columns: 26px 1fr auto; gap: 6px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); }
.history time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.h-dot { color: var(--faint); display: grid; place-items: center; }
.h-dot svg { width: 18px; height: 18px; }
.h-dot .solid { fill: var(--accent); stroke: var(--accent); }
.h-dot .check { stroke: var(--accent-ink); stroke-width: 2.4; }
.h-dot .fill { fill: var(--progress); stroke: none; }
.h-dot.s-in_progress { color: var(--progress); }

/* Instellingen */
.settings-block { margin-top: 18px; }
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.cat-list input[type=color] { width: 30px; height: 30px; border: 0; padding: 0; background: none; border-radius: 50%; overflow: hidden; flex: none; }
.cat-list input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.cat-list input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.cat-name { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 6px 0; }
.cat-name:focus { box-shadow: 0 2px 0 var(--accent); }
.cat-list small { color: var(--faint); }
#catAdd input { padding-left: 38px; }
.syntax { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 8px 0; font-size: 14px; }
.syntax dt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--accent); }
.syntax dd { margin: 0; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; transition: transform .2s, opacity .2s;
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); width: max-content; max-width: min(calc(100vw - 24px), 520px); font-size: 15px;
}
.toast span { flex: 1; min-width: 0; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast button { color: var(--accent-soft); font-weight: 700; padding: 6px 8px; border-radius: 8px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--accent-ink); background: var(--accent); } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login h1 { font-size: 36px; margin-bottom: 8px; }
.login input { height: 50px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 0 16px; outline: none; font-size: 16px; }
.login input:focus { border-color: var(--accent); }
.login .btn { height: 50px; }
.login .error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
