:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --ink: #23302a;
  --muted: #6c7a72;
  --line: #e6dfd0;
  --accent: #2e6b4f;
  --accent-soft: #dcebe2;
  --today: #b9770e;
  --late: #b3412f;
  --shadow: 0 1px 2px rgba(35, 48, 42, .06), 0 6px 20px rgba(35, 48, 42, .07);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161c19; --surface: #1f2723; --ink: #ecefe9; --muted: #98a59d;
    --line: #2f3a34; --accent: #6fbf95; --accent-soft: #23392d;
    --today: #e3a640; --late: #ea7b68;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.4 var(--sans); -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { display: flex; min-height: 100dvh; }

/* ---------- menu ---------- */
#drawer {
  width: 280px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px calc(14px + var(--safe-b));
  height: 100dvh; position: sticky; top: 0; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand strong { font-family: var(--serif); font-size: 19px; display: block; }
.brand span { color: var(--muted); font-size: 13px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-head { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left;
  padding: 10px; border-radius: 10px; width: 100%;
}
.nav-item:hover { background: var(--accent-soft); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 400; }
.nav-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.nav-item .who { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
.drawer-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 0; }
.sync-state { font-size: 12px; color: var(--muted); }
.sync-state::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.sync-state.ok::before { background: var(--accent); }
.sync-state.offline::before { background: var(--today); }
#scrim { display: none; }

/* ---------- hoofdvlak ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; width: 100%; }
.top {
  display: flex; align-items: center; gap: 8px; padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 10px;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.title-wrap { flex: 1; min-width: 0; }
.top h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; margin: 0; line-height: 1.15; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.icon-btn { border: 0; background: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--accent-soft); }
#menu-btn { display: none; }

#content { flex: 1; padding: 4px 16px 150px; }
.group { margin: 14px 0 4px; }
.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 4px 8px; font-weight: 600; }
.group h2.late { color: var(--late); }
.group h2.today { color: var(--today); }
.tasks { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); background: none; flex: none;
  display: grid; place-items: center; margin-top: -1px; padding: 0; transition: background .15s, border-color .15s;
}
.check:hover { border-color: var(--accent); }
.check svg { opacity: 0; }
.task.done .check, .check.on { background: var(--accent); border-color: var(--accent); }
.task.done .check svg, .check.on svg { opacity: 1; }
.task-body { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.task-title { display: block; overflow-wrap: anywhere; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 3px; }
.meta .late { color: var(--late); font-weight: 600; }
.meta .today { color: var(--today); font-weight: 600; }
.meta .listtag { display: inline-flex; align-items: center; gap: 5px; }
.meta .listtag i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.task.leaving { animation: leave .45s ease forwards; }
@keyframes leave { 0% { opacity: 1; } 60% { opacity: .5; } 100% { opacity: 0; transform: translateX(24px); } }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-family: var(--serif); font-size: 22px; color: var(--ink); margin-bottom: 6px; }

/* ---------- snel toevoegen ---------- */
#quick-add {
  position: fixed; bottom: 0; left: 280px; right: 0; padding: 10px 16px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, var(--bg) 30%); z-index: 6;
}
#quick-add > * { max-width: 728px; margin: 0 auto; }
.qa-row { display: flex; gap: 8px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 6px 6px 6px 16px; }
#qa-title { flex: 1; border: 0; background: none; outline: none; min-width: 0; font-size: 17px; }
.add-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; }
@media (prefers-color-scheme: dark) { .add-btn { color: #10241a; } }
.qa-chips { display: flex; gap: 6px; padding-top: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 14px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #10241a; } }

/* ---------- bladen ---------- */
#sheet-wrap { position: fixed; inset: 0; background: rgba(20, 28, 24, .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b)); max-height: 92dvh; overflow-y: auto; animation: up .2s ease;
}
@media (min-width: 900px) { #sheet-wrap { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h3 { font-family: var(--serif); font-size: 22px; margin: 0 0 14px; }
.sheet .title-input { width: 100%; font-size: 20px; border: 0; border-bottom: 2px solid var(--line); background: none; padding: 6px 0 8px; outline: none; margin-bottom: 14px; }
.sheet .title-input:focus { border-color: var(--accent); }
#f-note { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; resize: vertical; font: 15px/1.45 var(--sans); color: inherit; min-height: 64px; }
#f-note:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.field label { color: var(--muted); font-size: 15px; flex: none; }
.field input, .field select { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; min-width: 0; max-width: 62%; }
.field .inline { display: flex; gap: 6px; align-items: center; }
.field .inline input { max-width: none; }
.field input[type=date] { min-width: 158px; }
.field input[type=time] { min-width: 112px; }
.field .clear { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px 6px; }
.sheet-actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 18px; }
.btn { border: 0; border-radius: 12px; padding: 11px 18px; background: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn { color: #10241a; } }
.btn.ghost, .ghost { background: none; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.ghost.wide { width: 100%; margin-top: 10px; text-align: left; color: var(--muted); }
.btn.danger { background: none; color: var(--late); border: 1px solid var(--line); }
.link { border: 0; background: none; color: var(--muted); padding: 4px; text-decoration: underline; text-underline-offset: 3px; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack input[type=text], .stack input[type=password] { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.colors { display: flex; gap: 8px; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: var(--ink); }

/* ---------- welkom / inloggen ---------- */
.welcome { max-width: 420px; margin: 12vh auto 0; padding: 24px; }
.welcome h1 { font-family: var(--serif); font-size: 30px; margin: 14px 0 6px; }
.welcome p { color: var(--muted); }

/* ---------- melding onderin ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(130px + var(--safe-b)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 14px 10px 16px; border-radius: 12px; box-shadow: var(--shadow);
  display: flex; gap: 14px; align-items: center; font-size: 15px; max-width: calc(100vw - 32px);
}
#toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 700; padding: 4px; }
@media (prefers-color-scheme: dark) { #toast button { color: var(--accent); } }

/* ---------- telefoon ---------- */
@media (max-width: 899px) {
  #drawer { position: fixed; left: 0; top: 0; z-index: 15; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  #app.menu-open #drawer { transform: none; }
  #app.menu-open #scrim { display: block; position: fixed; inset: 0; background: rgba(20, 28, 24, .35); z-index: 14; }
  #menu-btn { display: grid; margin-left: -8px; }
  #quick-add { left: 0; }
  .top h1 { font-size: 26px; }
}
