:root {
  --bg: #f7f5fc;
  --surface: #ffffff;
  --border: #e9e3f5;
  --text: #3d3856;
  --text-muted: #8d87a8;
  --primary: #6f57d6;
  --primary-hover: #5f47c4;
  --primary-soft: #efe9fc;
  --on-primary: #ffffff;
  --danger: #b84e48;
  --danger-soft: #fbe9e8;

  --status-not-started: #5d59b8;
  --status-not-started-bg: #eceafa;
  --status-wip: #9c631f;
  --status-wip-bg: #fbf0e0;
  --status-complete: #237857;
  --status-complete-bg: #e2f3ea;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(90, 70, 130, 0.05), 0 4px 16px rgba(90, 70, 130, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221f2e;
    --surface: #2b2740;
    --border: #3c3654;
    --text: #ece9f7;
    --text-muted: #a79fc4;
    --primary: #b7a6f7;
    --primary-hover: #c7b9fa;
    --primary-soft: #392f52;
    --on-primary: #2b2140;
    --danger: #f0a8a2;
    --danger-soft: #3c2529;

    --status-not-started: #b0aee0;
    --status-not-started-bg: #302c47;
    --status-wip: #eac07f;
    --status-wip-bg: #3c3120;
    --status-complete: #8fd9b8;
    --status-complete-bg: #1f3c30;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, 'Leelawadee UI', sans-serif;
  min-height: 100vh;
}

button, input, select {
  font-family: inherit;
  font-size: 14px;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 8px;
  font-size: 15px;
}

.user-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.user-switch select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}

.tabs {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--bg);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.filter-row select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

/* ---------- Forms ---------- */
.add-task-form, .add-user-form {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.add-task-form input[type="text"],
.add-user-form input[type="text"] {
  flex: 1;
  min-width: 180px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.add-task-form select, .add-user-form select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-icon:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Task list ---------- */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  flex-wrap: wrap;
}

.task-title {
  flex: 1;
  min-width: 140px;
  font-weight: 500;
}

.task-owner {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}

.status-select {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}

.status-not_started { background: var(--status-not-started-bg); color: var(--status-not-started); }
.status-wip { background: var(--status-wip-bg); color: var(--status-wip); }
.status-complete { background: var(--status-complete-bg); color: var(--status-complete); }

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

/* ---------- Dashboard ---------- */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-card.accent-total .stat-value { color: var(--text); }
.stat-card.accent-not_started .stat-value { color: var(--status-not-started); }
.stat-card.accent-wip .stat-value { color: var(--status-wip); }
.stat-card.accent-complete .stat-value { color: var(--status-complete); }

.chart-row {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.donut-wrap {
  position: relative;
  flex-shrink: 0;
}

.donut-chart {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.donut-hole {
  position: absolute;
  inset: 20%;
  background: var(--surface);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.donut-total {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}

.donut-total-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.donut-mini .donut-hole { inset: 22%; }
.donut-mini .donut-total { font-size: 13px; }

.legend-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13.5px;
  flex: 1;
  min-width: 180px;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.legend-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-row-value {
  color: var(--text-muted);
  font-weight: 600;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.legend-dot.not_started { background: var(--status-not-started); }
.legend-dot.wip { background: var(--status-wip); }
.legend-dot.complete { background: var(--status-complete); }

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

.member-card-body {
  display: flex;
  align-items: center;
  gap: 14px;
}

.member-name {
  font-weight: 600;
}

.member-count {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ---------- Roster ---------- */
.roster-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.roster-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.roster-name { font-weight: 600; }
.roster-meta { font-size: 12.5px; color: var(--text-muted); }

.danger-zone {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .add-task-form, .add-user-form { flex-direction: column; }
  .add-task-form select, .add-task-form input,
  .add-user-form select, .add-user-form input { width: 100%; }
}
