:root {
  --bg: #ffffff;
  --side: #fcfaf8;
  --hover: #f2efed;
  --active: #ffefe5;
  --active-text: #c3392c;
  --text: #202020;
  --muted: #808080;
  --line: #eeeeee;
  --accent: #dc4c3e;
  --accent-hover: #c3392c;
  --card: #ffffff;
  --shadow: 0 10px 40px rgba(0, 0, 0, .18);
  --p1: #d1453b;
  --p2: #eb8909;
  --p3: #246fe0;
  --p4: #999999;
  --overdue: #d1453b;
  --today: #058527;
  --soon: #8f4ec8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e1e;
    --side: #282828;
    --hover: #333333;
    --active: #3d2a26;
    --active-text: #ff8a7a;
    --text: #e8e8e8;
    --muted: #9a9a9a;
    --line: #333333;
    --card: #282828;
    --shadow: 0 10px 40px rgba(0, 0, 0, .6);
    --p1: #ff7066;
    --p2: #ff9a14;
    --p3: #5297ff;
    --p4: #888888;
    --overdue: #ff7066;
    --today: #3dbd5d;
    --soon: #b88af0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- sign in */
body.signin { display: grid; place-items: center; padding: 16px; background: var(--side); }
.signin-card {
  width: 100%; max-width: 380px; text-align: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 40px 28px;
}
.signin-card h1 { margin: 14px 0 6px; font-size: 26px; }
.signin-card p { color: var(--muted); margin: 0 0 28px; }
.btn-google {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 11px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  text-decoration: none; font-weight: 600;
}
.btn-google:hover { background: var(--hover); }

/* ---------- layout */
.app { display: flex; height: 100%; }
.sidebar {
  width: 280px; flex-shrink: 0; background: var(--side); padding: 12px 10px;
  overflow-y: auto; border-right: 1px solid var(--line);
}
.main { flex: 1; overflow-y: auto; min-width: 0; }
.scrim { display: none; }

.user { display: flex; gap: 10px; align-items: center; padding: 6px 8px 12px; }
.user img { width: 30px; height: 30px; border-radius: 50%; background: var(--hover); }
.user img:not([src]) { visibility: hidden; }
.user-text { min-width: 0; }
.user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

.add-task-side {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none;
  color: var(--accent); font-weight: 600; padding: 7px 8px; border-radius: 6px; cursor: pointer;
}
.add-task-side:hover { background: var(--hover); }
.plus {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 17px; line-height: 1;
}
.search-wrap { padding: 4px 0 6px; }
.search-wrap input {
  width: 100%; border: 1px solid transparent; background: var(--hover); border-radius: 6px; padding: 6px 10px; outline: none;
}
.search-wrap input:focus { border-color: var(--muted); background: var(--bg); }

.nav a {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px;
  cursor: pointer; text-decoration: none; user-select: none;
}
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--active); color: var(--active-text); }
.nav a[data-view="inbox"] svg { color: #246fe0; }
.nav a[data-view="today"] svg { color: var(--today); }
.nav a[data-view="upcoming"] svg { color: var(--soon); }
.nav a[data-view="completed"] svg { color: var(--muted); }
.nav .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.nav .dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 5px; flex-shrink: 0; }
.nav .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.projects-head {
  display: flex; align-items: center; justify-content: space-between; margin: 18px 0 4px;
  padding: 0 8px; color: var(--muted); font-weight: 600; font-size: 13px;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 18px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.topbar {
  position: sticky; top: 0; background: var(--bg); z-index: 2; display: flex; align-items: flex-start; gap: 8px;
  max-width: 820px; margin: 0 auto; padding: 32px 40px 12px;
}
.menu-btn { display: none; margin-top: 2px; }
.title-wrap { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 24px; overflow-wrap: anywhere; }
.view-sub { color: var(--muted); font-size: 13px; }
.view-actions { display: flex; gap: 4px; }

.list { max-width: 820px; margin: 0 auto; padding: 0 40px 120px; }

/* ---------- sections */
.section-head {
  display: flex; align-items: baseline; gap: 8px; font-weight: 700; padding: 18px 0 6px;
  border-bottom: 1px solid var(--line);
}
.section-head .muted { font-weight: 400; color: var(--muted); font-size: 13px; }
.section-head.overdue { color: var(--overdue); }

/* ---------- tasks */
.tasks { min-height: 8px; }
.task { position: relative; background: var(--bg); }
.task::before {
  content: "⋮⋮"; position: absolute; left: -22px; top: 10px; color: var(--muted); font-size: 12px;
  letter-spacing: -3px; opacity: 0; cursor: grab;
}
.task:hover::before { opacity: 1; }
body.dragging .task::before { opacity: 0; }
body.dragging, body.dragging * { cursor: grabbing !important; }
.drag-ghost { opacity: .4; }
body.dragging .tasks:empty, body.dragging .tasks:has(> .drag-ghost:only-child) {
  min-height: 40px; border: 1px dashed var(--line); border-radius: 6px; margin: 4px 0;
}
.drag-chosen { box-shadow: var(--shadow); border-radius: 6px; }
.task {
  display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start;
  cursor: pointer;
}
.task:hover .task-title { color: var(--text); }
.check {
  --c: var(--p4);
  width: 20px; height: 20px; margin-top: 1px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--c); background: color-mix(in srgb, var(--c) 8%, transparent);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.check svg { width: 12px; height: 12px; stroke-width: 3; color: var(--c); opacity: 0; transition: opacity .1s; }
.check:hover svg, .task.done .check svg { opacity: 1; }
.task.done .check { background: var(--c); }
.task.done .check svg { color: #fff; }
.check.p1 { --c: var(--p1); } .check.p2 { --c: var(--p2); } .check.p3 { --c: var(--p3); }
.task-body { flex: 1; min-width: 0; }
.task-title { overflow-wrap: anywhere; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-desc {
  color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.meta { display: inline-flex; align-items: center; gap: 4px; }
.meta svg { width: 13px; height: 13px; }
.meta.overdue { color: var(--overdue); }
.meta.today { color: var(--today); }
.meta.tomorrow { color: var(--p2); }
.meta.week { color: var(--soon); }
.meta.project { margin-left: auto; }
.meta .dot { width: 8px; height: 8px; border-radius: 50%; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 40px; }

/* ---------- quick add */
.add-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; color: var(--muted); cursor: pointer;
  border: 0; background: none; width: 100%; text-align: left;
}
.add-row .plus-sm { color: var(--accent); font-size: 20px; width: 20px; text-align: center; line-height: 1; }
.add-row:hover { color: var(--accent); }
.add-row:hover .plus-sm { background: var(--accent); color: #fff; border-radius: 50%; }

.composer { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; background: var(--card); }
.composer:focus-within { border-color: var(--muted); }
.composer input.q {
  width: 100%; border: 0; outline: none; background: none; padding: 12px 12px 4px; font-weight: 600;
}
.composer input.qd {
  width: 100%; border: 0; outline: none; background: none; padding: 2px 12px 8px; font-size: 13px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; font-size: 12.5px; color: var(--muted); background: none; position: relative; cursor: pointer;
}
.chip.set { color: var(--text); }
.chip.set.p1 { color: var(--p1); border-color: var(--p1); }
.chip.set.p2 { color: var(--p2); border-color: var(--p2); }
.chip.set.p3 { color: var(--p3); border-color: var(--p3); }
.chip svg { width: 14px; height: 14px; }
.chip select, .chip input[type="date"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
}
.composer-foot {
  display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 8px 12px;
}
.composer-foot .hint { color: var(--muted); font-size: 12px; flex: 1; min-width: 0; }
.composer-foot .hint b { font-weight: 600; }

/* ---------- buttons */
.btn { border: 0; border-radius: 6px; padding: 7px 14px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: var(--hover); }
.btn-danger-text { background: none; color: var(--p1); padding-left: 0; }
.spacer { flex: 1; }

/* ---------- modals */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: grid; place-items: start center;
  padding: 10vh 16px 16px; z-index: 20;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 18px;
}
.modal-card.small { max-width: 420px; }
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.edit-title {
  width: 100%; border: 0; outline: none; background: none; font-size: 18px; font-weight: 600; padding: 4px 0;
}
.edit-desc {
  width: 100%; border: 0; outline: none; background: none; resize: vertical; color: var(--text); padding: 4px 0; min-height: 60px;
}
.edit-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.edit-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1 1 140px; }
.edit-row input, .edit-row select, label.block input {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--bg); color: var(--text); font-size: 14px;
}
label.block, div.block { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.sel { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--card); }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #202020; color: #fff;
  padding: 10px 14px 10px 16px; border-radius: 8px; display: flex; gap: 14px; align-items: center;
  box-shadow: var(--shadow); z-index: 30; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 0; color: #ff9f94; font-weight: 700; cursor: pointer; }

/* ---------- mobile */
@media (max-width: 760px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s;
    width: min(300px, 85vw); box-shadow: var(--shadow);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .3); z-index: 9; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 14px 16px 10px; }
  .list { padding: 0 16px 120px; }
  .composer-foot .hint { display: none; }
  .modal { padding-top: 5vh; }
}
