:root {
  --bg: #f5f1ea;
  --surface: #fbf8f3;
  --surface-2: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #4a4540;
  --ink-3: #847e76;
  --line: rgba(26, 26, 26, 0.08);
  --line-2: rgba(26, 26, 26, 0.12);
  --accent: #c9645a;
  --accent-soft: #e8d5d0;
  --high: #c9645a;
  --med: #c79152;
  --low: #847e76;
  --done: #6b8466;
  --shadow-sm: 0 1px 2px rgba(26, 26, 26, 0.04), 0 0 0 1px var(--line);
  --shadow-md: 0 4px 16px rgba(26, 26, 26, 0.06), 0 0 0 1px var(--line);
  --shadow-lg: 0 12px 40px rgba(26, 26, 26, 0.18);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --safe-top: env(safe-area-inset-top);
  --safe-bot: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --surface: #1c1a16;
    --surface-2: #24211c;
    --ink: #f5f1ea;
    --ink-2: #c9c2b6;
    --ink-3: #847e76;
    --line: rgba(245, 241, 234, 0.08);
    --line-2: rgba(245, 241, 234, 0.16);
    --accent-soft: #3a2826;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(48px + var(--safe-bot)); }

/* HEADER ---------------------------------------------------- */
.hdr {
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 80%, transparent);
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: 12px;
  z-index: 10;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
}
.hdr-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 32px;
  letter-spacing: -0.02em;
  font-weight: 500;
  margin: 0;
}
.date { color: var(--ink-3); font-size: 14px; margin-top: 2px; }

.counters {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-2);
}
.counters .pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-variant-numeric: tabular-nums;
}
.counters .pill.high b { color: var(--high); }
.counters .pill.med b { color: var(--med); }
.counters .pill.low b { color: var(--low); }
.counters .pill b { font-weight: 600; }

/* USER BUTTON ----------------------------------------------- */
.btn-ghost {
  background: transparent;
  border: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 999px;
}
.btn-ghost:hover { background: var(--surface); }
#user-pic img { width: 28px; height: 28px; border-radius: 50%; vertical-align: middle; }

/* QUICK ADD ------------------------------------------------- */
.add { margin-top: 18px; }
#quick-add { display: flex; gap: 8px; }
#quick-add-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 120ms;
}
#quick-add-input:focus { border-color: var(--ink-2); }
#quick-add-input::placeholder { color: var(--ink-3); }
.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border: 0;
  border-radius: var(--r-md);
  padding: 0 20px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 120ms;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.add-options { margin-top: 8px; }
.add-options summary {
  cursor: pointer;
  color: var(--ink-3);
  font-size: 12px;
  padding: 6px 4px;
  list-style: none;
  user-select: none;
}
.add-options summary::-webkit-details-marker { display: none; }
.add-options summary::before { content: '⌄ '; }
.add-options[open] summary::before { content: '⌃ '; }
.add-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 8px 0;
}
.add-options-grid label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--ink-3);
  gap: 4px;
}
.add-options-grid select,
.add-options-grid input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}

/* FILTERS --------------------------------------------------- */
.filters {
  display: flex;
  gap: 8px;
  margin: 16px -16px 8px;
  padding: 4px 16px 8px;
  overflow-x: auto;
  scroll-padding: 16px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms;
}
.chip:hover { border-color: var(--line-2); }
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* LIST ------------------------------------------------------ */
.list { margin-top: 8px; }
.group { margin: 16px 0 12px; }
.group-h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 4px;
}
.group-h .count { color: var(--ink-3); font-weight: 400; }

.todo {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: all 160ms;
}
.todo:hover { background: var(--surface-2); border-color: var(--line-2); }
.todo.done { opacity: 0.5; }
.todo.done .todo-task { text-decoration: line-through; color: var(--ink-3); }

.todo-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line-2);
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  transition: all 160ms;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}
.todo-check:hover { border-color: var(--ink-2); }
.todo-check.checked { background: var(--done); border-color: var(--done); color: white; }
.todo-check.checked::after { content: '✓'; font-size: 13px; }

.todo-body { flex: 1; min-width: 0; }
.todo-task {
  font-size: 15px;
  color: var(--ink);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.todo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-3);
}
.todo-meta .tag {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}
.todo-meta .prio-h { color: var(--high); font-weight: 600; }
.todo-meta .prio-m { color: var(--med); font-weight: 600; }
.todo-meta .prio-l { color: var(--low); }
.todo-meta .due { color: var(--ink-2); }
.todo-meta .due.overdue { color: var(--high); font-weight: 600; }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 60px 20px;
  font-size: 14px;
}

/* FOOTER ---------------------------------------------------- */
.footer {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.btn-ghost-sm {
  background: transparent;
  border: 0;
  color: var(--ink-3);
  font: inherit;
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}
.btn-ghost-sm:hover { color: var(--ink); }
.btn-ghost-sm.danger { color: var(--ink-3); }
.btn-ghost-sm.danger:hover { color: var(--high); }

/* MODAL ----------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fade 200ms;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 16px 20px calc(20px + var(--safe-bot));
  box-shadow: var(--shadow-lg);
  animation: slide-up 240ms ease-out;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (min-width: 640px) {
  .modal { align-items: center; padding: 20px; }
  .modal-card { border-radius: var(--r-lg); animation: fade 200ms; }
}
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 17px;
}
#edit-form label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  gap: 6px;
  margin-bottom: 14px;
}
#edit-form input,
#edit-form select,
#edit-form textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  text-transform: none;
  letter-spacing: normal;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

/* LOGIN ----------------------------------------------------- */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 400px;
  width: 100%;
}
.login-card h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  font-weight: 500;
}
.login-card p { color: var(--ink-3); margin: 0 0 24px; font-size: 14px; }
#g_id_signin { display: flex; justify-content: center; }

/* TOAST ----------------------------------------------------- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toast-in 240ms ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
