:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #808080);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --card: var(--tg-theme-secondary-bg-color, #f2f4f7);
}

* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 12px 12px 90px;
}

header h1 { font-size: 1.3rem; margin-bottom: 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 8px; border: none; border-radius: 10px;
  background: var(--card); color: var(--hint); font-size: 0.95rem; cursor: pointer;
}
.tab.active { background: var(--accent); color: var(--accent-text); }

.tagbar { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.tagbar:empty { display: none; }
.tagchip {
  border: none; border-radius: 20px; padding: 4px 12px; white-space: nowrap;
  background: var(--card); color: var(--hint); font-size: 0.85rem; cursor: pointer;
}
.tagchip.active { background: var(--accent); color: var(--accent-text); }

.list { display: flex; flex-direction: column; gap: 8px; }

.task {
  background: var(--card); border-radius: 12px; padding: 10px 12px;
  display: flex; align-items: flex-start; gap: 10px;
  border-left: 4px solid transparent;
}
.task.p0 { border-left-color: #9e9e9e; }
.task.p1 { border-left-color: #2481cc; }
.task.p2 { border-left-color: #f39c12; }
.task.p3 { border-left-color: #e74c3c; }
.task.overdue .due { color: #e74c3c; font-weight: 600; }
.task.done .title { text-decoration: line-through; color: var(--hint); }

.task .check {
  width: 24px; height: 24px; min-width: 24px; margin-top: 2px;
  border: 2px solid var(--hint); border-radius: 50%;
  background: transparent; cursor: pointer; font-size: 14px; line-height: 1;
  color: var(--accent-text);
}
.task.done .check { background: #27ae60; border-color: #27ae60; }

.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; word-wrap: break-word; }
.task .meta { font-size: 0.8rem; color: var(--hint); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 8px; }
.task .notes { font-size: 0.85rem; color: var(--hint); margin-top: 4px; white-space: pre-wrap; word-wrap: break-word; }
.task .tag {
  display: inline-block; background: var(--bg); border-radius: 8px;
  padding: 1px 7px; font-size: 0.75rem; color: var(--accent);
}

.task .actions { display: flex; flex-direction: column; gap: 6px; }
.task .actions button {
  border: none; background: none; cursor: pointer; font-size: 1rem; padding: 2px;
}

.empty { text-align: center; color: var(--hint); margin-top: 40px; font-size: 1.1rem; }

#fab {
  position: fixed; right: 18px; bottom: 24px; width: 56px; height: 56px;
  border-radius: 50%; border: none; background: var(--accent); color: var(--accent-text);
  font-size: 1.8rem; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; z-index: 10;
}
.sheet[hidden] { display: none; }
.sheet-content {
  background: var(--bg); width: 100%; border-radius: 16px 16px 0 0;
  padding: 18px 16px 24px; max-height: 88vh; overflow-y: auto;
}
.sheet-content h2 { font-size: 1.1rem; margin-bottom: 12px; }
.sheet-content label { display: block; font-size: 0.85rem; color: var(--hint); margin-bottom: 10px; }
.sheet-content input, .sheet-content textarea, .sheet-content select {
  display: block; width: 100%; margin-top: 4px; padding: 10px;
  border: 1px solid var(--card); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 1rem;
}
.hint { font-size: 0.85rem; color: var(--accent); margin: -4px 0 10px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1; padding: 12px; border: none; border-radius: 10px; font-size: 1rem; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--card); color: var(--text); }
