:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1c1f26;
  --text-muted: #7a8091;
  --accent: #3457d5;

  --status-planned: #b9bec9;
  --status-on_track: #2fa15a;
  --status-struggling: #d99a2b;
  --status-blocked: #d8483f;
  --status-done: #3457d5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --panel: #1d2028;
    --border: #2b2f3a;
    --text: #e7e9ee;
    --text-muted: #8b8fa3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }

nav.tabs { display: flex; gap: 4px; }
nav.tabs button {
  background: none; border: none; padding: 8px 14px; border-radius: 6px;
  cursor: pointer; font-size: 14px; color: var(--text-muted);
}
nav.tabs button.active { background: var(--accent); color: white; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 16px;
}

.pivot-select { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.pivot-select button {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.pivot-select button.active { background: var(--accent); border-color: var(--accent); color: white; }

.completion-badge { margin-left: auto; font-size: 11px; color: var(--text-muted); }

.grid-scroll { overflow-x: auto; }

table.grid { border-collapse: collapse; width: 100%; font-size: 12px; }
table.grid th, table.grid td {
  border: 1px solid var(--border); padding: 4px; text-align: left; vertical-align: top;
  min-width: 64px;
}
table.grid th { background: var(--bg); font-weight: 500; color: var(--text-muted); white-space: nowrap; }
table.grid td.row-label { font-weight: 500; white-space: nowrap; position: sticky; left: 0; background: var(--panel); }

.chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; padding: 2px 5px; border-radius: 4px; margin: 1px 0;
  color: white; cursor: pointer; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.chip.status-planned { background: var(--status-planned); color: #24262b; }
.chip.status-on_track { background: var(--status-on_track); }
.chip.status-struggling { background: var(--status-struggling); }
.chip.status-blocked { background: var(--status-blocked); }
.chip.status-done { background: var(--status-done); }
.chip .recur-badge { font-size: 9px; opacity: 0.85; }

.legend { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); margin-bottom: 10px; flex-wrap: wrap; }
.legend span.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

button.primary {
  background: var(--accent); color: white; border: none; border-radius: 6px;
  padding: 8px 14px; cursor: pointer; font-size: 13px;
}
button.secondary {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 14px; cursor: pointer; font-size: 13px;
}

.field { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); font-size: 13px; font-family: inherit;
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: var(--panel); border-radius: 10px; padding: 20px; width: 480px; max-width: 92vw; max-height: 86vh; overflow-y: auto; }
.modal h2 { margin-top: 0; font-size: 15px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.category-tree-label { font-size: 12px; color: var(--text-muted); }
.category-tree-label .top { opacity: 0.55; }

.post {
  border-bottom: 1px solid var(--border); padding: 12px 0;
}
.post:last-child { border-bottom: none; }
.post .meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.post .body { white-space: pre-wrap; font-size: 13px; }
.post .comments { margin-top: 8px; padding-left: 12px; border-left: 2px solid var(--border); }
.comment { font-size: 12px; margin-bottom: 6px; }

.truncate-body {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; cursor: pointer;
}

.invite-row, .user-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.invite-row .grow, .user-row .grow { flex: 1; }
.tag { font-size: 10px; padding: 2px 6px; border-radius: 10px; background: var(--bg); color: var(--text-muted); }

.error-banner { background: #fbe4e2; color: #8a231c; padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { .error-banner { background: #3a1e1c; color: #f2a29c; } }

.hint { font-size: 11px; color: var(--text-muted); }
