:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #15171c;
  --muted: #6b7180;
  --line: #e2e5eb;
  --accent: #5b4df0;
  --accent-soft: #ebe8ff;
  --due: #d63b3b;
  --flag: #e8850c;
  --ok: #1f9d55;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --surface: #16191f;
    --surface-2: #1f232b;
    --text: #eef0f4;
    --muted: #8b92a1;
    --line: #262a33;
    --accent: #7c6cff;
    --accent-soft: #262245;
    --due: #ff5c5c;
    --flag: #ff9f1c;
    --ok: #3ccf7a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center;
  background: var(--surface); padding: 28px 20px; border-radius: 20px; border: 1px solid var(--line);
}
.auth-card img { justify-self: center; border-radius: 14px; }
.auth-card h1 { margin: 0 0 8px; font-size: 22px; }
.auth-msg { margin: 0; min-height: 1.4em; color: var(--muted); font-size: 14px; }

input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }

.btn {
  padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--due); }
.btn.link { background: none; border: none; color: var(--accent); font-weight: 500; }
.btn.small { padding: 6px 12px; font-size: 14px; }

/* Layout */
.app { min-height: 100%; }
.view {
  max-width: 760px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px);
}
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.view-head h1 { margin: 0; font-size: 34px; letter-spacing: -0.5px; }
.view-head h1.inbox { color: var(--accent); }
.view-head h1.today { color: var(--due); }
.view-head h1.tags { color: #a855f7; }
.view-sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--accent); text-decoration: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs a.active { color: var(--accent); }
.tab-icon { font-size: 22px; line-height: 1; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.badge.due { background: var(--due); }
.badge:empty { display: none; }
.signout { display: none; }

.fab {
  position: fixed; z-index: 11; right: 20px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer;
}

@media (min-width: 900px) {
  .tabs {
    top: 0; right: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start;
    padding: 24px 12px; gap: 4px; border-top: none; border-right: 1px solid var(--line);
  }
  .tabs a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
  .tabs a.active { background: var(--accent-soft); }
  .tab-icon { font-size: 18px; }
  .badge { position: static; margin-left: auto; }
  .signout { display: block; margin-top: auto; background: none; border: none; color: var(--muted); text-align: left; padding: 10px 12px; cursor: pointer; }
  .view { margin-left: 220px; margin-right: 0; padding: 32px 40px 120px; max-width: 820px; }
  .fab { bottom: 32px; right: 32px; }
}

/* Capture bar */
.capture { display: flex; gap: 8px; margin-bottom: 12px; }
.capture input { flex: 1; }

/* Lists */
.section-title { margin: 22px 0 6px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:active { background: var(--surface-2); }
.check {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--muted); background: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; color: transparent; font-size: 14px;
}
.check.flagged { border-color: var(--flag); }
.check.overdue { border-color: var(--due); }
.check.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow-wrap: anywhere; }
.row.completed .row-title { color: var(--muted); text-decoration: line-through; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; font-size: 13px; color: var(--muted); align-items: center; }
.chip { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.meta-due.overdue { color: var(--due); font-weight: 600; }
.meta-flag { color: var(--flag); }
.row-sub { padding-left: 38px; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

.group-row { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.group-row .count { margin-left: auto; color: var(--muted); font-size: 14px; }
.group-row .count.due { color: #fff; background: var(--due); padding: 0 7px; border-radius: 6px; }
.group-row.muted { color: var(--muted); }
.folder-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 4px; font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.tag-child { padding-left: 26px; }

/* Sheet (task editor, quick entry) */
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0; padding: 0;
  border: none; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.45); }
@media (min-width: 900px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet form { display: grid; gap: 12px; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sheet .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet .actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.sheet .actions .right { display: flex; gap: 8px; margin-left: auto; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-toggle { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 14px; }
.tag-toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.flag-toggle { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text) !important; }
.flag-toggle input { width: 20px; height: 20px; accent-color: var(--flag); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px);
}
.toast button { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; }
