:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-card: #161b22;
  --bg-card-2: #1e252e;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --accent: #f7c948;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
  --border: #30363d;
  --r: 8px;
  --pad: 10px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(80px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.status { display: flex; align-items: center; gap: 12px; }
.dot { font-size: 18px; }
.dot.on { color: var(--ok); }
.dot.off { color: var(--err); }
.dot.warn { color: var(--warn); }
header button {
  background: transparent; color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px 10px; font-size: 16px; cursor: pointer;
}
main { padding: 12px 12px 0; display: flex; flex-direction: column; gap: 18px; }

.group h2 {
  margin: 8px 4px;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--fg-dim);
}
.group .count { color: var(--fg-dim); margin-left: 6px; font-weight: 400; }
.todos { display: flex; flex-direction: column; gap: 8px; }

.todo {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px var(--pad);
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.todo:active { background: var(--bg-card-2); }
.todo.in_progress { border-left: 3px solid var(--accent); padding-left: calc(var(--pad) - 2px); }
.todo.blocked { border-left: 3px solid var(--err); padding-left: calc(var(--pad) - 2px); opacity: 0.85; }
.todo.done { opacity: 0.55; }
.todo.done .name { text-decoration: line-through; }

.todo .row1 { display: flex; align-items: center; gap: 8px; }
.todo .name {
  font-weight: 600; font-size: 15px;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.todo .id { color: var(--fg-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.todo .desc {
  color: var(--fg-dim); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--bg-card-2); color: var(--fg-dim);
  border: 1px solid var(--border);
}
.badge.approval-needs_approval { color: var(--warn); border-color: #6b4d10; background: #2a1f08; }
.badge.approval-approved { color: var(--ok); border-color: #1f5128; background: #0e2412; }
.badge.status-in_progress { color: var(--accent); border-color: #6b551a; background: #2b220c; }
.badge.status-blocked { color: var(--err); border-color: #6b1a1a; background: #2b0c0c; }
.badge.status-done { color: var(--fg-dim); }

#add {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  font-size: 28px;
  background: var(--accent); color: #1a1a1a; border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  cursor: pointer;
  z-index: 20;
}
#add:active { transform: scale(0.95); }

dialog {
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  max-width: min(94vw, 480px);
  width: 100%;
}
dialog::backdrop { background: rgba(0,0,0,0.7); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--fg-dim); }
dialog input, dialog textarea, dialog select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 8px 0 0; }
dialog menu.row { justify-content: space-between; flex-wrap: wrap; }
dialog button {
  background: var(--bg-card-2); color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit; cursor: pointer;
}
dialog button[type=submit], dialog button.primary {
  background: var(--accent); color: #1a1a1a; border: none; font-weight: 600;
}
dialog button.danger { color: var(--err); border-color: #6b1a1a; }
.meta { color: var(--fg-dim); font-size: 12px; margin: -4px 0 4px; }
.dates { font-size: 11px; }

.empty {
  color: var(--fg-dim); text-align: center; padding: 24px 12px;
  font-size: 14px;
}

@media (min-width: 700px) {
  main { max-width: 720px; margin: 0 auto; }
}
