/* ========== Base ========== */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  background: #F7F6F3;
  color: #1F1E1B;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-muted: #FBFAF8;
  --border: #ECEAE4;
  --border-strong: #DDDAD3;
  --text: #1F1E1B;
  --text-muted: #6B6864;
  --text-soft: #9C9893;
  --accent: #5B5BD6;
  --accent-soft: #EEEEFB;
  --accent-hover: #4A4AC4;

  --todo: #8B8B98;
  --todo-bg: #EFEFF1;
  --inprogress: #D97706;
  --inprogress-bg: #FEF3C7;
  --done: #047857;
  --done-bg: #D1FADF;
  --overdue: #B91C1C;
  --overdue-bg: #FEE2E2;

  --shadow-sm: 0 1px 2px rgba(15, 15, 14, 0.04);
  --shadow-md: 0 2px 8px rgba(15, 15, 14, 0.06), 0 1px 2px rgba(15, 15, 14, 0.04);
  --shadow-lg: 0 16px 40px -8px rgba(15, 15, 14, 0.16), 0 4px 12px rgba(15, 15, 14, 0.06);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

/* ========== App layout ========== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #6B6BE6 0%, #4747C4 100%);
  display: grid; place-items: center; color: white;
  font-weight: 800; font-size: 14px;
  box-shadow: 0 2px 6px rgba(91, 91, 214, 0.3);
}
.brand-sub {
  font-size: 12px; color: var(--text-soft); font-weight: 500;
  padding-left: 12px; border-left: 1px solid var(--border-strong);
  margin-left: 4px;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

/* role switcher */
.role-switch {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.role-switch button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 600;
  border-radius: 999px;
  color: var(--text-muted);
  transition: all 0.15s ease;
}
.role-switch button.active {
  background: white;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* member picker */
.member-picker {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 6px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  position: relative;
}
.member-picker:hover { border-color: var(--border-strong); }
.member-picker .caret { color: var(--text-soft); font-size: 10px; }

.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  color: white; font-weight: 700; font-size: 11px;
  flex-shrink: 0;
}
.avatar.lg { width: 36px; height: 36px; font-size: 14px; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.xs { width: 18px; height: 18px; font-size: 9px; }

.dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  padding: 6px;
  z-index: 100;
}
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.dropdown-item:hover { background: var(--surface-muted); }
.dropdown-item.active { background: var(--accent-soft); color: var(--accent); }

/* ========== Page container ========== */
.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px;
  flex: 1;
  width: 100%;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-title {
  font-size: 26px; font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px 0;
}
.page-sub {
  font-size: 14px; color: var(--text-muted); margin: 0;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-muted); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-muted); color: var(--text); }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ========== Status pills ========== */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.status-pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.status-todo { color: var(--todo); background: var(--todo-bg); }
.status-inprogress { color: var(--inprogress); background: var(--inprogress-bg); }
.status-done { color: var(--done); background: var(--done-bg); }
.status-overdue { color: var(--overdue); background: var(--overdue-bg); }

/* ========== KANBAN (member view) ========== */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.kanban-col {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 420px;
  display: flex; flex-direction: column;
}
.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}
.kanban-col-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700;
}
.kanban-col-title .dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.kanban-col-count {
  font-size: 12px; color: var(--text-soft); font-weight: 600;
  background: white;
  padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border);
}
.kanban-add-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px;
  font-size: 13px; font-weight: 600;
  color: var(--text-soft);
  border-radius: 8px;
  transition: all 0.15s ease;
  border: 1px dashed transparent;
  margin-top: 4px;
}
.kanban-add-btn:hover {
  background: white;
  color: var(--accent);
  border-color: var(--border-strong);
}
.kanban-cards {
  display: flex; flex-direction: column; gap: 10px;
  flex: 1;
}

/* Task card */
.task-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.task-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.task-card-title {
  font-size: 14px; font-weight: 600;
  line-height: 1.35;
  margin: 0 0 6px 0;
  letter-spacing: -0.005em;
}
.task-card-desc {
  font-size: 12px; color: var(--text-muted);
  line-height: 1.45;
  margin: 0 0 10px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.task-card-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.task-card-deadline {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
}
.task-card-deadline.overdue {
  color: var(--overdue);
  background: var(--overdue-bg);
}
.task-card-deadline.soon {
  color: var(--inprogress);
  background: var(--inprogress-bg);
}

.empty-col {
  text-align: center;
  font-size: 12px; color: var(--text-soft);
  padding: 30px 12px;
  font-style: italic;
}

/* ========== MANAGER: stats grid ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.stat-card-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px 0;
  letter-spacing: 0.01em;
}
.stat-card-value {
  font-size: 32px; font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1;
}
.stat-card-sub {
  font-size: 12px; font-weight: 500;
  color: var(--text-soft);
  margin-top: 6px;
}
.stat-card-accent {
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent);
}
.stat-card-accent.todo { background: var(--todo); }
.stat-card-accent.inprogress { background: var(--inprogress); }
.stat-card-accent.done { background: var(--done); }
.stat-card-accent.overdue { background: var(--overdue); }

/* ========== Panels ========== */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 22px;
}
.panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.panel-title {
  font-size: 15px; font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.panel-sub {
  font-size: 12px; color: var(--text-muted);
  margin-top: 2px;
}

/* Status chart (horizontal bars) */
.status-chart { display: flex; flex-direction: column; gap: 14px; }
.status-row { display: flex; flex-direction: column; gap: 6px; }
.status-row-head { display: flex; align-items: center; justify-content: space-between; }
.status-row-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
}
.status-row-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-row-count {
  font-size: 13px; font-weight: 700; color: var(--text);
}
.status-row-count span { color: var(--text-soft); font-weight: 500; }
.status-bar {
  height: 8px; background: var(--surface-muted);
  border-radius: 999px; overflow: hidden;
}
.status-bar-fill {
  height: 100%; border-radius: 999px;
  transition: width 0.4s ease;
}

/* Workload heatmap */
.workload {
  display: flex; flex-direction: column; gap: 10px;
}
.workload-row {
  display: grid;
  grid-template-columns: 120px 1fr 60px;
  align-items: center;
  gap: 12px;
}
.workload-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
}
.workload-name span { 
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.workload-bar {
  position: relative;
  height: 24px;
  background: var(--surface-muted);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
}
.workload-seg {
  height: 100%;
  transition: width 0.4s ease;
}
.workload-seg.todo { background: #C9C9D2; }
.workload-seg.inprogress { background: #FBBF24; }
.workload-seg.done { background: #34D399; }
.workload-seg.overdue { background: #EF4444; }
.workload-total {
  font-size: 13px; font-weight: 700;
  text-align: right;
}
.workload-legend {
  display: flex; gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.workload-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted); font-weight: 500;
}
.workload-legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ========== Table ========== */
.table-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table-toolbar {
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  gap: 14px;
  flex-wrap: wrap;
}
.table-toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  font-size: 12px; font-weight: 600;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid transparent;
}
.filter-chip:hover { background: white; border-color: var(--border-strong); color: var(--text); }
.filter-chip.active { background: var(--accent-soft); color: var(--accent); }

.search-input {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  min-width: 240px;
}
.search-input input {
  border: none; outline: none; background: transparent; flex: 1;
  font-size: 13px;
}
.search-input svg { color: var(--text-soft); flex-shrink: 0; }

.task-table {
  width: 100%;
  border-collapse: collapse;
}
.task-table th {
  text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}
.task-table td {
  padding: 14px 20px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.task-table tr:last-child td { border-bottom: none; }
.task-table tr:hover td { background: var(--surface-muted); }

.cell-task-title { font-weight: 600; }
.cell-task-desc {
  font-size: 12px; color: var(--text-muted); margin-top: 2px;
  max-width: 360px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-deadline {
  font-size: 12px; color: var(--text-muted); font-weight: 600;
  white-space: nowrap;
}
.cell-deadline.overdue { color: var(--overdue); }
.cell-deadline.soon { color: var(--inprogress); }
.cell-owner { display: flex; align-items: center; gap: 8px; font-weight: 500; }

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 20, 18, 0.4);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title {
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.modal-close {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--text-soft);
}
.modal-close:hover { background: var(--surface-muted); color: var(--text); }

.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field-input, .field-textarea, .field-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field-input:focus, .field-textarea:focus, .field-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.status-radio-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.status-radio {
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  text-align: center;
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: white;
  transition: all 0.15s ease;
}
.status-radio:hover { background: var(--surface-muted); }
.status-radio.active {
  border-color: currentColor;
}
.status-radio .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-radio.todo.active { color: var(--todo); background: var(--todo-bg); }
.status-radio.inprogress.active { color: var(--inprogress); background: var(--inprogress-bg); }
.status-radio.done.active { color: var(--done); background: var(--done-bg); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-soft);
}
.empty-state h3 {
  font-size: 16px; font-weight: 600; color: var(--text); margin: 12px 0 4px;
}
.empty-state p { font-size: 13px; margin: 0; }

/* Task detail modal */
.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 0;
  margin: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.detail-meta-item .label {
  font-size: 11px; font-weight: 600; color: var(--text-soft);
  letter-spacing: 0.04em; text-transform: uppercase;
  margin-bottom: 6px;
}
.detail-meta-item .value { font-size: 14px; font-weight: 600; }
.detail-desc {
  font-size: 14px; color: var(--text-muted); line-height: 1.6;
  white-space: pre-wrap;
}

/* Misc */
.scroll-x { overflow-x: auto; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
}
