:root {
  --bg: #f6f5f2; --card: #ffffff; --ink: #1b1d21; --muted: #6b7078; --line: #e3e1dc;
  --accent: #1f6f5c; --accent-ink: #ffffff; --soft: #e8f1ee; --warn: #b4441f; --warn-soft: #fbece6;
  --chip: #efeeea; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b; --card: #1f2226; --ink: #eceef1; --muted: #9aa0a8; --line: #30343a;
    --accent: #4fb89d; --accent-ink: #0d1512; --soft: #1d2f2a; --warn: #f08a66; --warn-soft: #38231c;
    --chip: #2a2e33; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); padding: 12px 16px 10px; }
.top > *, main { max-width: 760px; margin-left: auto; margin-right: auto; }
.top-row { display: flex; align-items: center; gap: 6px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; flex: none; }
.status { flex: 1; text-align: right; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn { flex: none; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--chip); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.add { display: flex; gap: 8px; margin-top: 10px; }
.add input[type=text] { flex: 1; min-width: 0; }
.add input[type=date] { flex: none; width: 150px; }
input[type=text], input[type=date], input[type=password], input[type=email], textarea, select {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 180px; line-height: 1.45; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer; white-space: nowrap; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .55; cursor: default; }

.filters { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.filters button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.filters button[aria-pressed=true] { background: var(--ink); color: var(--bg); }
.filters .count { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

main { padding: 12px 16px 96px; }
.banner { background: var(--soft); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.banner p { margin: 0; flex: 1 1 260px; font-size: 14.5px; }
.banner.warn { background: var(--warn-soft); }

.group-title { font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; display: flex; align-items: center; gap: 8px; }
.group-title.overdue { color: var(--warn); }
.group-title button { border: 0; background: none; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; }
.group { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }

.task { display: flex; gap: 12px; padding: 12px 14px; align-items: flex-start; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.check { flex: none; appearance: none; -webkit-appearance: none; width: 24px; height: 24px; margin: 1px 0 0; border: 2px solid var(--muted); border-radius: 50%; cursor: pointer; background: transparent; display: grid; place-items: center; }
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.task-main { flex: 1; min-width: 0; cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
.task-title { font-weight: 550; overflow-wrap: anywhere; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.task-notes { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chip { font-size: 12.5px; background: var(--chip); color: var(--muted); border-radius: 6px; padding: 2px 7px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.due-over { background: var(--warn-soft); color: var(--warn); }
.chip.folder { background: var(--soft); color: var(--accent); }
.task-actions { flex: none; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

dialog { border: 0; padding: 0; background: var(--card); color: var(--ink); border-radius: 18px; width: min(560px, calc(100vw - 24px)); max-height: min(86vh, 760px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet-head { display: flex; align-items: center; padding: 12px 10px 8px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { padding: 16px 18px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row .grow { flex: 1; }
.quote { background: var(--chip); border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--muted); max-height: 130px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 0; }
.folder-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; max-height: 300px; overflow: auto; }
.folder-list button { text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 10px 12px; cursor: pointer; }
.folder-list button:first-child { border-top: 0; }
.folder-list button:hover, .folder-list button.sel { background: var(--soft); }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
label.inline input { width: auto; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); max-width: calc(100vw - 24px); z-index: 20; font-size: 14.5px; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; cursor: pointer; padding: 4px 2px; text-decoration: underline; white-space: nowrap; }

@media (max-width: 520px) {
  .add { flex-wrap: wrap; }
  .add input[type=text] { flex: 1 1 100%; }
  .add input[type=date] { flex: 1; width: auto; }
  .task-actions .btn { padding: 5px 8px; }
}
