:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-hover: #f0f1f5;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e4e9;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 8px;
  --col-backlog: #94a3b8;
  --col-todo: #6366f1;
  --col-doing: #f59e0b;
  --col-review: #a855f7;
  --col-done: #22c55e;
  --col-failed: #ef4444;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* --- Header --- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

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

header h1 .logo {
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 6px;
  display: inline-block;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Nav/Tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
}

.tab {
  padding: 6px 16px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- Theme toggle --- */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* --- Project selector --- */
.project-bar {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.project-bar select,
.project-bar button {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.project-bar button {
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 600;
}

.project-bar button:hover { background: var(--accent-light); }

/* --- Kanban Board --- */
.board {
  display: flex;
  gap: 16px;
  padding: 0 24px 24px;
  overflow-x: auto;
  min-height: calc(100vh - 160px);
}

.column {
  min-width: 280px;
  max-width: 320px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.column-header .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}

.column-header .count {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.column-body {
  flex: 1;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 100px;
  transition: background 0.15s;
}

.column-body.drag-over {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* --- Task Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: grab;
  transition: box-shadow 0.15s, transform 0.1s;
  position: relative;
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
}

.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-assignee {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.badge-priority-urgent { background: #fef2f2; color: #dc2626; }
.badge-priority-high { background: #fff7ed; color: #ea580c; }
.badge-priority-medium { background: #fffbeb; color: #d97706; }
.badge-priority-low { background: #f0fdf4; color: #16a34a; }

[data-theme="dark"] .badge-priority-urgent { background: #451a1a; color: #fca5a5; }
[data-theme="dark"] .badge-priority-high { background: #431407; color: #fdba74; }
[data-theme="dark"] .badge-priority-medium { background: #422006; color: #fcd34d; }
[data-theme="dark"] .badge-priority-low { background: #052e16; color: #86efac; }

.badge-tag {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.badge-deadline {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
}

.badge-overdue {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
  font-weight: 600;
}

.card-overdue {
  border-left: 3px solid var(--danger);
}

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

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.modal input,
.modal textarea,
.modal select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
  font-family: inherit;
}

.modal textarea { min-height: 80px; resize: vertical; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-light); }

/* --- Task detail panel --- */
.detail-panel {
  position: fixed;
  right: 0;
  top: 56px;
  width: 420px;
  max-width: 100vw;
  height: calc(100vh - 56px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 150;
  overflow-y: auto;
  padding: 24px;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.detail-panel.open { transform: translateX(0); }

.detail-panel h2 { font-size: 18px; margin-bottom: 16px; }

.detail-field {
  margin-bottom: 16px;
}

.detail-field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.detail-field .value {
  font-size: 14px;
}

.comment-list {
  list-style: none;
  margin-top: 8px;
}

.comment-list li {
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}

.comment-list .comment-author {
  font-weight: 600;
  margin-right: 6px;
}

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

.comment-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.comment-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

/* --- Thread Panel (chat-style comments) --- */
.thread-panel {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.thread-panel > label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.thread-messages {
  flex: 1;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.thread-msg {
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.thread-msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.thread-msg-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.thread-msg-time {
  font-size: 10px;
  color: var(--text-muted);
}

.thread-msg-text {
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.thread-input {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thread-author-input {
  width: 120px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}

.thread-send-row {
  display: flex;
  gap: 8px;
}

.thread-text-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.thread-text-input:focus,
.thread-author-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- Agent list view --- */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 0 24px 24px;
}

.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.agent-card h3 { font-size: 15px; margin-bottom: 4px; }
.agent-card .role { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.agent-card .caps { display: flex; gap: 4px; flex-wrap: wrap; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .board { padding: 0 12px 12px; gap: 12px; }
  .column { min-width: 260px; }
  .detail-panel { width: 100vw; }
  header { padding: 0 12px; }
  .project-bar { padding: 12px; }
}

/* Add task btn in column */
.add-task-btn {
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
}

.add-task-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Hide */
.hidden { display: none !important; }

/* Stats View */
.stats-view { padding: 24px; max-width: 900px; margin: 0 auto; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.stat-number { font-size: 2em; font-weight: 700; color: var(--accent); }
.stat-title { font-size: 0.85em; color: var(--text-muted); margin-top: 4px; }
.stat-bars { display: flex; flex-direction: column; gap: 8px; }
.stat-bar { display: flex; align-items: center; gap: 8px; }
.stat-label { min-width: 70px; font-size: 0.85em; color: var(--text-muted); text-transform: capitalize; }
.stat-fill { height: 24px; border-radius: 4px; min-width: 8px; transition: width 0.3s; }
.stat-val { font-weight: 600; font-size: 0.9em; }
.stat-alert { background: #fef3c7; border: 1px solid #f59e0b; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; color: #92400e; font-weight: 500; }
[data-theme="dark"] .stat-alert { background: #451a0366; border-color: #f59e0b55; color: #fbbf24; }
.stats-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stats-table th, .stats-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9em; }
.stats-table th { background: var(--surface-hover); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 0.75em; letter-spacing: 0.05em; }
.stats-table tr:last-child td { border-bottom: none; }
