:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #1d2321;
  --muted: #5e6a66;
  --line: #dfe4e1;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #dcece6;
  --warn: #9a6200;
  --warn-soft: #fbefd6;
  --bad: #b3261e;
  --bad-soft: #fbe2df;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --surface: #1b1f1e;
    --surface-2: #242a28;
    --text: #e6ebe9;
    --muted: #9aa7a2;
    --line: #2f3633;
    --accent: #6cc3a8;
    --accent-ink: #0d1f19;
    --accent-soft: #1f3a32;
    --warn: #f0b85a;
    --warn-soft: #3a2d14;
    --bad: #ff8a80;
    --bad-soft: #3d1c19;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd { font: 0.9em ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  display: none;
  width: 240px; flex: none; padding: 16px 10px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 16px; }
#sidenav button, .tabbar button, .menu button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; background: none; cursor: pointer; text-align: left;
}
#sidenav button { padding: 9px 10px; border-radius: 8px; color: var(--muted); }
#sidenav button:hover { background: var(--surface-2); color: var(--text); }
#sidenav button.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
#sidenav button span:nth-child(2), .menu button span:nth-child(2) { flex: 1; }
.badge { min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text); font-size: 12px; font-weight: 600; text-align: center; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.content { flex: 1; min-width: 0; max-width: 820px; margin: 0 auto; padding: 0 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); }
main:focus { outline: none; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); position: relative; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); font-size: 11px; min-width: 18px; padding: 0 5px; background: var(--accent); color: var(--accent-ink); }
.tabbar .badge.warn { background: var(--warn); color: var(--surface); }

@media (min-width: 900px) {
  .sidebar { display: block; }
  .tabbar { display: none; }
  .content { padding: 0 32px 48px; }
}

/* ---------- capture ---------- */
.capture {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px 0 10px; background: var(--bg);
}
.capture input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.capture input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.capture .btn { height: 48px; }
.capture-preview { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.capture-preview:empty { display: none; }
.sync-dot { width: 14px; height: 14px; padding: 0; border-radius: 50%; border: 0; background: var(--muted); cursor: pointer; flex: none; }
.sync-dot[data-state="ok"] { background: #3aa57a; }
.sync-dot[data-state="syncing"] { background: var(--accent); animation: pulse 1s infinite alternate; }
.sync-dot[data-state="error"] { background: var(--bad); }
@keyframes pulse { to { opacity: 0.3; } }

/* ---------- common ---------- */
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin: 12px 0 16px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; }
.sub, .hint { color: var(--muted); margin: 4px 0 0; }
.hint { font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.group { display: flex; align-items: center; gap: 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 22px 0 8px; }
.count { font-weight: 500; opacity: 0.7; text-transform: none; }
.bad-text { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
details { margin: 16px 0; }
summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
ul.plain { padding-left: 18px; margin: 6px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn.big { width: 100%; min-height: 52px; margin-top: 16px; font-size: 17px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-weight: 500; }
.link.more { display: block; margin: 12px auto; }
.link.back { margin-top: 12px; }

.pill {
  min-height: 36px; padding: 4px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px;
}
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill-check input { position: absolute; opacity: 0; pointer-events: none; }
.pill-check span { display: inline-flex; align-items: center; min-height: 36px; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.pill-check input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill-check input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.filter-label { width: 100%; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
@media (min-width: 600px) { .filter-label { width: 92px; } }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-size: 12.5px; background: var(--surface-2); color: var(--muted); border: 0; white-space: nowrap; }
.chip.ctx { color: var(--accent); background: var(--accent-soft); }
.chip.proj { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.chip.warn, .chip.energy-high { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }

.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; margin-bottom: 12px; border-radius: var(--radius); background: var(--accent-soft); }
.banner.review { background: var(--warn-soft); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner span { flex: 1 1 240px; }

/* ---------- tasks ---------- */
.tasks, .projects, .menu, .review-steps { list-style: none; margin: 0; padding: 0; }
.task {
  display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; column-gap: 4px;
  padding: 6px 4px; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.task > .chips, .task > .btn { grid-column: 2; padding: 0 8px 6px; }
.task > .btn { justify-self: start; margin: 0 8px 6px; }
.task .star { grid-column: 3; grid-row: 1; }
.check {
  grid-row: 1; width: 40px; height: 40px; border: 0; background: none; cursor: pointer; position: relative;
}
.check::before { content: ""; position: absolute; inset: 10px; border: 2px solid var(--muted); border-radius: 50%; }
.check:hover::before { border-color: var(--accent); }
.is-done .check::before { background: var(--accent); border-color: var(--accent); }
.is-done .check::after { content: ""; position: absolute; left: 16px; top: 13px; width: 6px; height: 11px; border: solid var(--accent-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-body { grid-row: 1; display: flex; flex-direction: column; min-width: 0; padding: 8px; border: 0; background: none; text-align: left; cursor: pointer; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-notes { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star { width: 40px; height: 40px; border: 0; background: none; cursor: pointer; color: var(--line); display: grid; place-items: center; }
.star:hover { color: var(--muted); }
.star.on { color: #e3a008; }
.star.on .icon { fill: currentColor; }

.project { margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.project.stalled { border-color: var(--bad); }
.project-main { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; cursor: pointer; }
.project .inline-add { padding: 0 12px 12px; margin: 0; }
.inline-add { display: flex; gap: 8px; margin: 0 0 16px; }
.inline-add input { flex: 1; min-width: 0; }

input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { color: var(--text); font-size: 16px; }
.project-edit .title-input { font-size: 22px; font-weight: 700; margin: 8px 0 12px; }

.menu button { padding: 14px 12px; border-bottom: 1px solid var(--line); font-size: 17px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; margin-bottom: 16px; }

/* ---------- wizard ---------- */
.wizard { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.wizard-item { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); margin-bottom: 8px; }
.wizard-item .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.q { font-size: 20px; margin: 18px 0 4px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 16px 0 4px; }
.choices .btn { min-height: 56px; flex-direction: column; gap: 0; }
.choices small { font-weight: 400; opacity: 0.75; }
.vague-hint { color: var(--warn); font-size: 14px; margin: -6px 0 8px; min-height: 1em; }
.wizard-nav { display: flex; justify-content: space-between; margin-top: 12px; font-size: 14px; color: var(--muted); }
.dates label { flex: 1 1 160px; }
.done-card { text-align: center; }
.big-emoji { font-size: 48px; margin: 0; color: var(--accent); }

/* ---------- review ---------- */
.review-stats { display: flex; gap: 12px; margin-bottom: 12px; }
.stat { flex: 1; padding: 10px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.stat strong { display: block; font-size: 22px; color: var(--text); }
.review-steps li { padding: 12px 14px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.review-steps li.checked { opacity: 0.6; }
.review-steps p { margin: 4px 0 8px 32px; color: var(--muted); font-size: 14px; }
.review-steps .btn { margin-left: 32px; }
.review-check { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--text); cursor: pointer; }
.review-check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- dialog / toast ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 18px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 40%); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 14px; color: var(--muted); padding: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  display: flex; gap: 16px; align-items: center; max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
}
.toast .link { color: var(--accent-soft); }
@media (prefers-color-scheme: dark) { .toast .link { color: var(--accent-ink); font-weight: 700; } }
@media (min-width: 900px) { .toast { bottom: 24px; } }
[hidden] { display: none !important; }

/* Phones: one swipeable line per filter row so actions stay above the fold. */
@media (max-width: 599px) {
  .filters .filter-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 4px -12px; padding: 0 12px; }
  .filters .filter-row::-webkit-scrollbar { display: none; }
  .filters .filter-label { width: auto; flex: none; min-width: 52px; }
  .filters .pill, .filters .link { flex: none; }
}
