:root {
  --bg: #ffffff;
  --sidebar: #f7f7f5;
  --surface: #ffffff;
  --hover: #f1f1ef;
  --border: #e6e6e3;
  --text: #1f1f1e;
  --muted: #7a7a76;
  --accent: #2f6fed;
  --accent-soft: #e8effd;
  --on-accent: #ffffff;
  --danger: #d6336c;
  --danger-soft: #fdecf1;
  --warn: #c76a00;
  --success: #2b8a3e;
  --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Light is the default; the toggle sets data-theme="dark" on <html>. */
:root[data-theme="dark"] {
  --bg: #19191a;
  --sidebar: #141415;
  --surface: #1f1f21;
  --hover: #262628;
  --border: #2e2e31;
  --text: #e9e9e7;
  --muted: #8d8d89;
  --accent: #6b9bff;
  --accent-soft: #1f2a42;
  --on-accent: #0d1626;
  --danger: #f06595;
  --danger-soft: #3a1f29;
  --warn: #f0a742;
  --success: #69db7c;
  color-scheme: dark;
}
:root[data-theme="dark"] .chip { color: color-mix(in srgb, var(--c) 55%, white); background: color-mix(in srgb, var(--c) 22%, transparent); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- layout ---------- */

.app { display: flex; min-height: 100%; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  min-width: 0;
  max-width: 800px;
  padding: 32px 48px 80px;
}

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.topbar .date { position: relative; top: 2px; }
.offline { font-size: 12px; color: var(--danger); }
.topbar h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.date { color: var(--muted); font-size: 13px; }
.icon-btn.menu-btn { display: none; }

/* ---------- sidebar ---------- */

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  text-align: left;
  color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.nav-item.active .count { color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; margin: 0 4px; flex-shrink: 0; }

.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tags .muted, .projects .muted { padding: 0 10px; margin: 2px 0; }
.side-head + .side-head, .projects + .side-head { margin-top: 20px; }
.link { color: var(--accent); font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; }

.shortcuts {
  margin-top: auto;
  padding: 16px 10px 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 2;
}
kbd {
  font: 11px var(--font);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  background: var(--surface);
}

/* ---------- add form ---------- */

.add {
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 12px;
}
.add:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.add input { border: 0; outline: 0; background: transparent; }
#addTitle { flex: 1; min-width: 0; padding: 6px 8px; }
#addDue { width: 130px; color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: var(--danger-soft); }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 13px; }

/* ---------- list ---------- */

.section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 24px 0 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.section-title:first-child { margin-top: 8px; }
.section { min-height: 8px; border-radius: var(--radius); }
.section.drop-into { box-shadow: inset 0 0 0 2px var(--accent-soft); }

.task {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
  border-radius: 6px;
}
.task:hover { background: var(--hover); }
.task.selected { background: var(--accent-soft); }
.task.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.task.drop-after { box-shadow: 0 2px 0 var(--accent); }

.check {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.check svg { width: 13px; height: 13px; stroke-width: 3; }
.check:hover { border-color: var(--success); color: var(--success); }
.task.done .check { background: var(--success); border-color: var(--success); color: #fff; }

.body { flex: 1; min-width: 0; cursor: text; }
.title { word-wrap: break-word; }
.task.done .title { color: var(--muted); text-decoration: line-through; }
.task.done .body { cursor: default; }
.notes {
  color: var(--muted);
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }

.chip {
  font-size: 12px;
  color: var(--c);
  padding: 0 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 12%, transparent);
}
.chip:hover { background: color-mix(in srgb, var(--c) 22%, transparent); }
.chip.removable span { margin-left: 2px; opacity: 0.7; }

.due { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.due svg { width: 13px; height: 13px; }
.due.overdue { color: var(--danger); }
.due.soon { color: var(--warn); }

.moves {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}
.task:hover .moves, .task.selected .moves, .task:focus-within .moves { opacity: 1; }
.seg { font-size: 11.5px; padding: 2px 8px; color: var(--muted); background: var(--surface); }
.seg + .seg { border-left: 1px solid var(--border); }
.seg:hover { color: var(--text); background: var(--hover); }
.seg.on { color: var(--accent); background: var(--accent-soft); font-weight: 550; cursor: default; }

.icon-btn { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.subtle { opacity: 0; }
.task:hover .icon-btn.subtle { opacity: 1; }

.empty { color: var(--muted); padding: 24px 8px; text-align: center; font-size: 13px; }

.done-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 24px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}
.done-toggle svg { width: 14px; height: 14px; transition: transform 0.15s; }
.done-toggle svg.open { transform: rotate(90deg); }

/* ---------- editor ---------- */

.editor {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px;
  margin: 6px 0;
  border: 1px solid var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}
.editor:hover { background: var(--surface); }
.editor input, .editor textarea, .editor select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--bg);
  outline: 0;
}
.editor input:focus, .editor textarea:focus, .editor select:focus { border-color: var(--accent); }
.editor input[name="title"] { font-weight: 550; }
.editor textarea { resize: vertical; }
.editor-row { display: flex; gap: 8px; flex-wrap: wrap; }
.editor-row label { flex: 1; min-width: 130px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.editor-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* ---------- archive ---------- */

.sign-out { align-self: flex-start; padding: 10px 10px 0; color: var(--muted); }
.sign-out:hover { color: var(--text); }

/* Login */
.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
}
.login-box { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-box h2 { margin: 0; font-size: 22px; }
.login-box p { margin: 0; color: var(--muted); font-size: 14px; }
.login-box input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  outline: 0;
}
.login-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-box .btn { justify-content: center; padding: 9px 14px; }
.login-box .login-error { color: var(--danger); }

.archive-nav { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.archive-bar { display: flex; justify-content: space-between; align-items: center; min-height: 34px; margin-bottom: 8px; font-size: 13px; }
.btn.danger.confirm { background: var(--danger); color: #fff; border-color: var(--danger); }
.task.archived { align-items: center; padding-left: 12px; }
.task.archived .body { cursor: default; }
.task.archived .title { color: var(--muted); }
.btn svg { width: 14px; height: 14px; margin-right: 6px; flex-shrink: 0; }
.small-btn { padding: 3px 10px; font-size: 12.5px; }

/* ---------- drag ---------- */

.handle {
  width: 16px;
  height: 22px;
  margin: 0 -6px 0 -4px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  opacity: 0;
  flex-shrink: 0;
}
.handle svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.handle-space { width: 6px; flex-shrink: 0; }
.task:hover .handle, .task.selected .handle { opacity: 1; }
.task.dragging { opacity: 0.35; }
.ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  transform: rotate(0.6deg);
}
.ghost .moves { opacity: 0; }
.ghost .handle { opacity: 1; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast button { color: var(--accent-soft); font-weight: 600; }
:root[data-theme="dark"] .toast button { color: var(--accent); }

/* ---------- projects ---------- */

.new-project input, .rename input {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--surface);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.new-project { margin: 2px 0 6px; }
.rename input { font-size: 20px; font-weight: 650; padding: 2px 8px; width: 320px; max-width: 60vw; }
.view-actions { display: flex; align-items: center; gap: 4px; }
.view-actions .icon-btn svg { width: 15px; height: 15px; }

.proj-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  padding: 0 6px 0 4px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.proj-chip:hover { color: var(--text); background: var(--hover); }
.proj-chip svg { width: 12px; height: 12px; }

.badge { font-size: 11px; font-weight: 550; padding: 0 6px; border-radius: 4px; background: var(--hover); color: var(--muted); }
.badge.b-today { background: var(--accent-soft); color: var(--accent); }
.badge.b-next { color: var(--text); }

/* ---------- board ---------- */

body.board-mode .main { max-width: none; padding-right: 0; }
body.board-mode .add, body.board-mode .filter-bar, body.board-mode .board-bar { max-width: 752px; }
.board-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; font-size: 13px; }

.board {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 48px 16px 0;
  min-height: 300px;
}
.column {
  flex: 0 0 290px;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 210px);
}
.column-head { display: flex; align-items: center; gap: 4px; padding: 4px 6px 8px; font-weight: 600; font-size: 13px; }
.column-head .dot { margin: 0 4px 0 0; }
.col-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.column-body { flex: 1; overflow-y: auto; min-height: 40px; border-radius: 8px; padding: 1px; }
.column-body.drop-into { box-shadow: inset 0 0 0 2px var(--accent); }
.column .empty { padding: 14px 6px; }

.task.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  padding: 8px 8px 8px 6px;
}
.task.card:hover { background: var(--surface); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.task.card.selected { background: var(--accent-soft); }
.task.card .title { font-size: 13.5px; }
.editor.card { margin: 0 0 6px; padding: 10px; }
.editor.card .editor-row label { min-width: 100%; }
.ghost.card { border-color: var(--accent); }

.col-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  margin-top: 2px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}
.col-add-btn:hover { background: var(--hover); color: var(--text); }
.col-add-btn svg { width: 14px; height: 14px; }
.col-add input {
  width: 100%;
  margin-top: 2px;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  outline: 0;
}

/* ---------- checklist ---------- */

.ci-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px 0 5px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.ci-chip:hover { background: var(--hover); color: var(--text); }
.ci-chip svg { width: 13px; height: 13px; }
.ci-chip svg:last-child { width: 11px; height: 11px; transition: transform 0.15s; }
.ci-chip.open svg:last-child { transform: rotate(90deg); }
.ci-chip.complete { color: var(--success); }

.checklist { margin: 6px 0 2px; cursor: default; }
.ci {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 0;
  border-radius: 5px;
  font-size: 13px;
}
.ci:hover { background: color-mix(in srgb, var(--hover) 70%, transparent); }
.ci.ci-dragging { background: var(--accent-soft); }
.ci-handle {
  display: grid;
  place-items: center;
  width: 14px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  opacity: 0;
}
.ci-handle svg { width: 13px; height: 13px; fill: currentColor; stroke: none; }
.ci:hover .ci-handle { opacity: 1; }
.ci-check {
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--muted);
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: transparent;
  flex-shrink: 0;
}
.ci-check svg { width: 11px; height: 11px; stroke-width: 3; }
.ci-check:hover { border-color: var(--success); color: var(--success); }
.ci.done .ci-check { background: var(--success); border-color: var(--success); color: #fff; }
.ci-text { flex: 1; min-width: 0; word-wrap: break-word; }
.ci.done .ci-text { color: var(--muted); text-decoration: line-through; }
.ci-del { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 4px; color: var(--muted); opacity: 0; flex-shrink: 0; }
.ci-del svg { width: 12px; height: 12px; }
.ci:hover .ci-del, .ed-ci:hover .ci-del { opacity: 1; }
.ci-del:hover { background: var(--danger-soft); color: var(--danger); }
.ci-add {
  width: 100%;
  margin-top: 4px;
  padding: 4px 8px 4px 24px;
  font-size: 13px;
  border: 1px dashed transparent;
  border-radius: 5px;
  background: transparent;
  outline: 0;
}
.ci-add:hover { border-color: var(--border); }
.ci-add:focus { border-style: solid; border-color: var(--accent); background: var(--surface); }

.ed-checklist { display: flex; flex-direction: column; gap: 4px; }
.ed-ci { display: flex; align-items: center; gap: 8px; }
.editor .ed-ci input[type="checkbox"] { width: 15px; height: 15px; flex-shrink: 0; accent-color: var(--success); }
.editor .ed-ci-text { padding: 4px 8px; }
.editor .ed-ci-new { padding: 4px 8px; border-style: dashed; }
.editor .ed-ci-new:focus { border-style: solid; }

/* ---------- mobile ---------- */

.scrim { display: none; }

@media (max-width: 760px) {
  .main { padding: 16px 16px 80px; }
  .icon-btn.menu-btn { display: grid; margin-left: -6px; align-self: center; }
  .topbar { align-items: center; }
  .sidebar {
    position: fixed;
    z-index: 20;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgba(0, 0, 0, 0.15); }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.3); }
  .shortcuts { display: none; }
  .board { scroll-snap-type: x mandatory; padding-right: 16px; min-height: 0; }
  .column { flex-basis: 84vw; scroll-snap-align: start; max-height: none; }
  body.board-mode .main { padding-right: 16px; }
  .view-actions .btn { font-size: 0; padding: 4px 6px; }
  .view-actions .btn svg { margin: 0; }
  .view-actions .btn.confirm { font-size: 12px; }
  .task.card::after { display: none; }
  .moves { opacity: 1; }
  .handle { opacity: 0.6; }
  .ci-handle, .ci-del { opacity: 0.6; }
  .icon-btn.subtle { opacity: 1; }
  .task { flex-wrap: wrap; row-gap: 4px; }
  .moves { flex-basis: auto; margin-left: 46px; }
  .body { flex: 1 1 0; }
  .task > .moves { order: 9; }
  .task::after { content: ""; order: 8; flex-basis: 100%; }
  #addDue { width: 34px; padding: 0; }
  #addDue::-webkit-datetime-edit { display: none; }
}
