/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { -webkit-font-smoothing: antialiased; }
ul { list-style: none; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; }
textarea { resize: vertical; }
a { text-decoration: none; color: inherit; }
[hidden] { display: none !important; }

/* ─── Design Tokens ──────────────────────────────────────── */
:root {
  --color-bg:            #ffffff;
  --color-text:          #222222;
  --color-text-muted:    #6a6a6a;
  --color-text-disabled: rgba(0,0,0,0.24);
  --color-brand:         #ff385c;
  --color-brand-dark:    #e00b41;
  --color-border:        #c1c1c1;
  --color-surface:       #f2f2f2;
  --color-sidebar-bg:    #f7f7f7;

  --color-todo-bg:       #f2f2f2;
  --color-todo-text:     #6a6a6a;
  --color-progress-bg:   #fff3d6;
  --color-progress-text: #7a5200;
  --color-done-bg:       #e6f4ea;
  --color-done-text:     #1e6e37;

  --color-high:   #ff385c;
  --color-medium: #d69e2e;
  --color-low:    #c1c1c1;

  --shadow-card:  rgba(0,0,0,0.02) 0px 0px 0px 1px,
                  rgba(0,0,0,0.04) 0px 2px 6px,
                  rgba(0,0,0,0.10) 0px 4px 8px;
  --shadow-hover: rgba(0,0,0,0.08) 0px 4px 12px;
  --shadow-modal: rgba(0,0,0,0.04) 0px 0px 0px 1px,
                  rgba(0,0,0,0.08) 0px 8px 24px,
                  rgba(0,0,0,0.12) 0px 16px 48px;

  --radius-sm:    4px;
  --radius-btn:   8px;
  --radius-badge: 14px;
  --radius-card:  20px;
  --radius-large: 32px;
  --radius-pill:  50%;

  --font: -apple-system, BlinkMacSystemFont, 'Circular', system-ui, Roboto, 'Helvetica Neue', sans-serif;

  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;

  --sidebar-width: 240px;
}

/* ─── Dark Mode Tokens ──────────────────────────────────── */
[data-theme="dark"] {
  --color-bg:            #1a1a1a;
  --color-text:          #e8e8e8;
  --color-text-muted:    #9a9a9a;
  --color-text-disabled: rgba(255,255,255,0.22);
  --color-brand:         #ff385c;
  --color-brand-dark:    #ff5a7a;
  --color-border:        #3a3a3a;
  --color-surface:       #252525;
  --color-sidebar-bg:    #141414;

  --color-todo-bg:       #2a2a2a;
  --color-todo-text:     #9a9a9a;
  --color-progress-bg:   #3a2e10;
  --color-progress-text: #e8b830;
  --color-done-bg:       #132a1a;
  --color-done-text:     #4ade80;

  --color-high:   #ff5a7a;
  --color-medium: #e8b830;
  --color-low:    #555555;

  --shadow-card:  rgba(0,0,0,0.20) 0px 0px 0px 1px,
                  rgba(0,0,0,0.16) 0px 2px 6px,
                  rgba(0,0,0,0.24) 0px 4px 8px;
  --shadow-hover: rgba(0,0,0,0.30) 0px 4px 12px;
  --shadow-modal: rgba(0,0,0,0.30) 0px 0px 0px 1px,
                  rgba(0,0,0,0.30) 0px 8px 24px,
                  rgba(0,0,0,0.40) 0px 16px 48px;

  color-scheme: dark;
}

[data-theme="dark"] .sidebar {
  border-right-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .sidebar-divider {
  background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .nav-item:hover,
[data-theme="dark"] .list-item:hover,
[data-theme="dark"] .btn-add-space:hover,
[data-theme="dark"] .btn-add-list:hover {
  background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .list-item.active {
  background: var(--color-surface);
}

[data-theme="dark"] .modal-header {
  border-bottom-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .modal-footer {
  border-top-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .kanban-card-detail {
  border-top-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .form-input:focus {
  border-color: var(--color-text);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
}

[data-theme="dark"] .btn-primary {
  background: #e8e8e8;
  color: #1a1a1a;
}

[data-theme="dark"] .btn-primary:hover {
  background: var(--color-brand);
  color: #ffffff;
}

[data-theme="dark"] .btn-icon.btn-danger:hover {
  background: #3a1a1a;
  color: var(--color-brand);
}

[data-theme="dark"] .pill.active {
  background: var(--color-text);
  color: var(--color-bg);
}

[data-theme="dark"] .due-date-placeholder {
  border-color: rgba(255,255,255,0.12);
}

[data-theme="dark"] .due-date-placeholder:hover {
  border-color: var(--color-text-muted);
}

[data-theme="dark"] .color-swatch.active {
  box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-text-muted);
}

[data-theme="dark"] .sidebar-toggle {
  background: var(--color-surface);
}

/* ─── Base ───────────────────────────────────────────────── */
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}

/* ─── App Shell ──────────────────────────────────────────── */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
  border-right: 1px solid rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4) var(--space-3);
  text-decoration: none;
  color: var(--color-text);
  transition: opacity 0.12s;
}

.sidebar-logo:hover { opacity: 0.8; }

.sidebar-logo-icon { flex-shrink: 0; }

.sidebar-logo-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.3px;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--space-4);
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 2px; }

/* ─── Sidebar User (in footer) ─────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  color: var(--color-text);
  transition: opacity 0.12s;
}

.sidebar-user:hover { opacity: 0.8; }

.sidebar-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-admin-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.12s;
}

.sidebar-admin-link:hover { color: var(--color-text); }

/* ─── Sidebar Nav Section ───────────────────────────────── */
.sidebar-nav-section {
  padding: var(--space-2) var(--space-3) 0;
}

.sidebar-divider {
  height: 1px;
  background: rgba(0,0,0,0.06);
  margin: var(--space-2) var(--space-3);
}

/* ─── Sidebar Space ─────────────────────────────────────── */
.sidebar-space {
  padding: var(--space-2) var(--space-3);
}

.sidebar-space-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.sidebar-space-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-space-shared {
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ─── Sidebar List Items ────────────────────────────────── */
.sidebar-list-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 2px;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  user-select: none;
}

.list-item:hover { background: rgba(0,0,0,0.05); color: var(--color-text); cursor: grab; }
.list-item.active { background: var(--color-bg); color: var(--color-text); box-shadow: var(--shadow-card); }
.list-item.dragging { opacity: 0.4; }
.list-item.drag-over-above { box-shadow: 0 -2px 0 0 var(--color-brand); }
.list-item.drag-over-below { box-shadow: 0 2px 0 0 var(--color-brand); }

.list-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.list-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-add-list {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px var(--space-3);
  margin-top: 2px;
  border-radius: var(--radius-btn);
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-disabled);
  transition: background 0.12s, color 0.12s;
  width: 100%;
}

.btn-add-list:hover { background: rgba(0,0,0,0.05); color: var(--color-text-muted); }

/* ─── Sidebar Footer ────────────────────────────────────── */
.sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  border-top: 1px solid rgba(0,0,0,0.06);
  padding-top: var(--space-2);
}

[data-theme="dark"] .sidebar-footer {
  border-top-color: rgba(255,255,255,0.06);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-4) var(--space-3);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: color 0.12s;
}

.btn-logout:hover { color: var(--color-brand); }

.sidebar-version {
  display: block;
  padding: var(--space-1) var(--space-4) var(--space-3);
  font-size: 11px;
  color: var(--color-text-disabled);
}

/* ─── Nav Items ──────────────────────────────────────────── */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}

.nav-item:hover { background: rgba(0,0,0,0.05); color: var(--color-text); }
.nav-item.active { background: var(--color-bg); color: var(--color-text); box-shadow: var(--shadow-card); }

/* ─── Space List ─────────────────────────────────────────── */
.space-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 4px;
}

.space-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  user-select: none;
}

.space-item:hover { background: rgba(0,0,0,0.05); color: var(--color-text); }
.space-item.active { background: var(--color-bg); color: var(--color-text); box-shadow: var(--shadow-card); }
.space-item.drag-over { border-top: 2px solid var(--color-brand); padding-top: 4px; }
.space-item.dragging { opacity: 0.4; }

.space-dot { width: 8px; height: 8px; border-radius: var(--radius-pill); flex-shrink: 0; }

.space-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-add-space {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  margin-top: 2px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-disabled);
  transition: background 0.12s, color 0.12s;
  width: 100%;
}

.btn-add-space:hover { background: rgba(0,0,0,0.05); color: var(--color-text-muted); }

/* ─── Theme Toggle ──────────────────────────────────────── */
.theme-toggle-wrapper {
  padding: var(--space-3) var(--space-4) var(--space-1);
}

.theme-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-btn);
  padding: 2px;
  width: 100%;
}

.theme-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 6px 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle-btn:hover { color: var(--color-text); }
.theme-toggle-btn.active {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ─── Main Content ───────────────────────────────────────── */
.main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

/* ─── Empty States ───────────────────────────────────────── */
.empty-root, .empty-tasks {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
}

.empty-root-title { font-size: 20px; font-weight: 600; letter-spacing: -0.18px; }
.empty-root-sub, .empty-tasks p { font-size: 14px; color: var(--color-text-muted); max-width: 280px; line-height: 1.5; }

/* ─── View Container ─────────────────────────────────────── */
.view-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6) var(--space-4);
  gap: var(--space-4);
  flex-shrink: 0;
}

.main-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.view-color-dot {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.view-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ─── View Toggle ────────────────────────────────────────── */
.view-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-btn);
  padding: 2px;
}

.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.toggle-btn:hover { color: var(--color-text); }
.toggle-btn.active { background: var(--color-bg); color: var(--color-text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ─── Section Toggle (modal) ─────────────────────────────── */
.section-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-btn);
  padding: 2px;
}

.section-toggle .toggle-btn {
  flex: 1;
  justify-content: center;
  padding: 6px 12px;
  font-size: 13px;
}

/* ─── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-6) var(--space-3);
  overflow-x: auto;
  flex-shrink: 0;
}

.filter-bar::-webkit-scrollbar { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px var(--space-3);
  border-radius: var(--radius-badge);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  border: 1px solid transparent;
}

.pill:hover { background: var(--color-surface); color: var(--color-text); }
.pill.active { background: var(--color-text); color: var(--color-bg); }

/* ─── Task Counts ────────────────────────────────────────── */
.task-counts {
  padding: 0 var(--space-6) var(--space-3);
  font-size: 13px;
  color: var(--color-text-muted);
  min-height: 20px;
  flex-shrink: 0;
}

/* ─── Space Group (All / This Week views) ─────────────────── */
.space-group { margin-bottom: var(--space-5); }
.space-group:last-child { margin-bottom: 0; }

.space-group-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: var(--space-1) 0;
}

.space-group-dot { width: 8px; height: 8px; border-radius: var(--radius-pill); }
.space-group-name { font-size: 14px; font-weight: 600; color: var(--color-text); }
.space-group-count { font-size: 11px; color: var(--color-text-muted); }

.space-group-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ─── Task List ──────────────────────────────────────────── */
.task-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-6) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.task-list::-webkit-scrollbar { width: 4px; }
.task-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

/* ─── Task Card ──────────────────────────────────────────── */
.task-card {
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  transition: box-shadow 0.15s, transform 0.1s;
  position: relative;
}

.task-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.task-card.dragging { opacity: 0.4; }
.task-card.drag-over-above { box-shadow: 0 -2px 0 0 var(--color-brand), var(--shadow-card); }
.task-card.drag-over-below { box-shadow: 0 2px 0 0 var(--color-brand), var(--shadow-card); }
.task-card[draggable="true"] { cursor: grab; }
.task-card[draggable="true"]:active { cursor: grabbing; }

.task-card.done .task-card-title {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

/* ─── Task Checkbox ──────────────────────────────────────── */
.task-checkbox {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--color-border);
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, background 0.12s;
  background: transparent;
  cursor: pointer;
}

.task-checkbox:hover { border-color: var(--color-text-muted); }

.task-card.done .task-checkbox {
  border-color: var(--color-done-text);
  background: var(--color-done-text);
}

.task-checkbox-check { display: none; color: white; }
.task-card.done .task-checkbox-check { display: block; }

/* ─── Task Card Body ─────────────────────────────────────── */
.task-card-body { flex: 1; min-width: 0; }

.task-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
  line-height: 1.35;
}

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

.task-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-todo      { background: var(--color-todo-bg);     color: var(--color-todo-text); }
.badge-progress  { background: var(--color-progress-bg); color: var(--color-progress-text); }
.badge-done      { background: var(--color-done-bg);     color: var(--color-done-text); }

.badge-clickable { cursor: pointer; transition: filter 0.12s; }
.badge-clickable:hover { filter: brightness(0.92); }

/* ─── Priority ───────────────────────────────────────────── */
.priority-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); flex-shrink: 0; }
.priority-dot.high   { background: var(--color-high); }
.priority-dot.medium { background: var(--color-medium); }
.priority-dot.low    { background: var(--color-low); }

.priority-label { font-size: 11px; font-weight: 500; color: var(--color-text-muted); }

.priority-clickable {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.priority-clickable:hover { background: var(--color-surface); }

/* ─── Due Date ───────────────────────────────────────────── */
.due-date {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 2px 6px;
  margin: -2px -4px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.due-date:hover { background: var(--color-surface); }
.due-date.overdue { color: var(--color-brand); }

.due-date-placeholder {
  color: var(--color-text-disabled);
  border: 1px dashed rgba(0,0,0,0.12);
  padding: 1px 8px;
  border-radius: var(--radius-badge);
}

.due-date-placeholder:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text-muted);
  background: var(--color-surface);
}

.due-date-input {
  font-size: 11px;
  padding: 1px 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: var(--font);
  color: var(--color-text);
}

/* ─── Task Card Actions ──────────────────────────────────── */
.task-card-actions {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity 0.12s;
}

.task-card:hover .task-card-actions { opacity: 1; }

/* ─── Task Card Click-to-Expand ─────────────────────────── */
.task-card.has-subtasks { cursor: pointer; }

/* ─── Subtask Progress Toggle ───────────────────────────── */
.subtask-progress-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-1) 0;
  margin-top: var(--space-1);
  transition: color 0.12s;
  user-select: none;
}

.subtask-progress-toggle:hover .subtask-progress { color: var(--color-text); }

.subtask-toggle-icon {
  transition: transform 0.25s ease;
  display: inline-block;
}

.subtask-toggle-icon.open {
  transform: rotate(90deg);
}

/* ─── Collapsible Subtask Container ──────────────────────── */
.subtask-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.subtask-collapse.open {
  grid-template-rows: 1fr;
}

.subtask-collapse-inner {
  overflow: hidden;
}

/* ─── Subtask List ───────────────────────────────────────── */
.subtask-list {
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.subtask-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
}

.subtask-checkbox {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  background: transparent;
}

.subtask-checkbox:hover { border-color: var(--color-text-muted); }

.subtask-item.done .subtask-checkbox {
  border-color: var(--color-done-text);
  background: var(--color-done-text);
}

.subtask-check-icon { display: none; color: white; }
.subtask-item.done .subtask-check-icon { display: block; }

.subtask-title { font-size: 13px; color: var(--color-text); }
.subtask-item.done .subtask-title { text-decoration: line-through; color: var(--color-text-muted); }

.subtask-delete {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-disabled);
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
  margin-left: auto;
}

.subtask-item:hover .subtask-delete { opacity: 1; }
.subtask-delete:hover { color: var(--color-brand); }

.subtask-add {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 0;
  font-size: 12px;
  color: var(--color-text-disabled);
  transition: color 0.12s;
  cursor: pointer;
}

.subtask-add:hover { color: var(--color-text-muted); }

.subtask-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--color-text);
  padding: 2px 0;
  background: transparent;
  font-family: var(--font);
}

.subtask-input::placeholder { color: var(--color-text-disabled); }

.subtask-progress {
  font-size: 11px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.subtask-progress-bar {
  display: inline-block;
  width: 40px;
  height: 4px;
  background: var(--color-surface);
  border-radius: 2px;
  overflow: hidden;
  vertical-align: middle;
}

.subtask-progress-fill {
  display: block;
  height: 100%;
  background: var(--color-done-text);
  border-radius: 2px;
  transition: width 0.2s;
}

/* ─── Kanban ─────────────────────────────────────────────── */
.kanban {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-3);
  flex: 1;
  overflow: hidden;
  padding: 0 var(--space-6) var(--space-6);
}

.kanban-column {
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar-bg);
  border-radius: var(--radius-card);
  padding: var(--space-3);
  overflow: hidden;
}

.kanban-column.drag-over {
  outline: 2px dashed var(--color-brand);
  outline-offset: -2px;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-2) var(--space-3);
}

.kanban-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.kanban-cards {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.kanban-cards::-webkit-scrollbar { width: 3px; }
.kanban-cards::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 2px; }

/* ─── Kanban Card ────────────────────────────────────────── */
.kanban-card {
  background: var(--color-bg);
  border-radius: var(--radius-badge);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
  cursor: pointer;
  transition: box-shadow 0.12s, transform 0.1s;
}

.kanban-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

.kanban-card.dragging { opacity: 0.4; }

.kanban-card.done .kanban-card-title {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

.kanban-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-1);
  line-height: 1.35;
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.kanban-card-space {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 3px;
}

.kanban-card-space-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); }

/* ─── Kanban Expandable Detail ───────────────────────────── */
.kanban-card-expand {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.kanban-card.expanded .kanban-card-expand {
  grid-template-rows: 1fr;
}

.kanban-card-expand-inner {
  overflow: hidden;
}

.kanban-card-detail {
  padding-top: var(--space-2);
  border-top: 1px solid rgba(0,0,0,0.06);
  margin-top: var(--space-2);
}

.kanban-card-description {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
  margin-bottom: var(--space-2);
}

.kanban-card-actions {
  display: flex;
  gap: var(--space-1);
  padding-top: var(--space-2);
}

/* ─── Popover ────────────────────────────────────────────── */
.popover {
  position: fixed;
  z-index: 200;
  background: var(--color-bg);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-modal);
  min-width: 120px;
  padding: var(--space-1);
  animation: fade-in 0.1s ease;
}

.popover-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.1s;
}

.popover-option:hover { background: var(--color-surface); }
.popover-option.active { color: var(--color-brand); font-weight: 600; }
.popover-option .option-dot { width: 6px; height: 6px; border-radius: var(--radius-pill); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 14px;
  font-weight: 500;
  padding: 0 var(--space-4);
  height: 36px;
  border-radius: var(--radius-btn);
  transition: background 0.12s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover  { background: var(--color-brand); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-border);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background 0.12s;
}

.btn-secondary:hover { background: var(--color-surface); }

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
}

.btn-icon:hover { background: var(--color-surface); color: var(--color-text); }
.btn-icon.btn-danger:hover { background: #fef2f2; color: var(--color-brand); }

.btn-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background 0.12s;
}

.btn-close:hover { background: var(--color-surface); }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
  animation: fade-in 0.12s ease;
}

.modal {
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 520px;
  animation: slide-up 0.15s ease;
}

.modal-sm { max-width: 400px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.modal-title { font-size: 18px; font-weight: 600; letter-spacing: -0.2px; }

form {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.form-group { display: flex; flex-direction: column; gap: var(--space-1); }
.form-label { font-size: 13px; font-weight: 600; color: var(--color-text); }
.form-optional { font-weight: 400; color: var(--color-text-muted); }

.form-input {
  width: 100%;
  padding: 8px var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.12s, box-shadow 0.12s;
  outline: none;
}

.form-input:focus { border-color: var(--color-text); box-shadow: 0 0 0 2px rgba(34,34,34,0.08); }
.form-textarea { min-height: 72px; }

.form-select {
  width: 100%;
  padding: 8px var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236a6a6a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-select:focus { border-color: var(--color-text); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-3);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid rgba(0,0,0,0.06);
  margin-top: var(--space-1);
}

/* ─── Color Swatches ─────────────────────────────────────── */
.color-swatches {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  position: relative;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  transition: transform 0.1s, box-shadow 0.1s;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px currentColor; }

.color-swatch-custom {
  background: conic-gradient(#ff385c, #d69e2e, #38a169, #3d85c8, #805ad5, #ff385c) !important;
}

#color-picker-input, #edit-color-picker-input,
#list-color-picker, #space-color-picker, #edit-list-color-picker, #edit-space-color-picker {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Mobile Sidebar Toggle ─────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-btn);
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 70;
  opacity: 0;
  transition: opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.open {
  display: block;
  opacity: 1;
}

/* ─── iOS Safe Areas ────────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar-logo { padding-top: calc(var(--space-5) + env(safe-area-inset-top)); }
  .main-header { padding-top: calc(var(--space-5) + env(safe-area-inset-top)); }
  .sidebar-scroll { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
  .task-list { padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
  .kanban { padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
}

/* ─── Responsive: Tablet ────────────────────────────────── */
@media (max-width: 744px) {
  :root { --sidebar-width: 200px; }
  .main-header { padding: var(--space-4); }
  .filter-bar  { padding: 0 var(--space-4) var(--space-3); }
  .task-counts { padding: 0 var(--space-4) var(--space-2); }
  .task-list   { padding: 0 var(--space-4) var(--space-4); }
  .kanban      { padding: 0 var(--space-4) var(--space-4); gap: var(--space-2); }
  .form-row    { grid-template-columns: 1fr 1fr; }
}

/* ─── Responsive: Mobile ────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 80;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-modal);
  }

  .main {
    width: 100%;
    min-width: 0;
  }

  .main-header {
    padding: var(--space-3) var(--space-4);
    padding-left: 52px; /* room for hamburger */
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .main-header-left {
    flex: 1;
    min-width: 0;
  }

  .main-header-right {
    width: 100%;
    justify-content: space-between;
  }

  .view-title { font-size: 18px; }

  .filter-bar { padding: 0 var(--space-4) var(--space-2); }
  .task-counts { padding: 0 var(--space-4) var(--space-2); font-size: 12px; }

  .task-list { padding: 0 var(--space-3) var(--space-4); gap: var(--space-2); }

  .task-card {
    padding: var(--space-3) var(--space-4);
    border-radius: 16px;
  }

  .task-card-title { font-size: 14px; }
  .task-card-actions { opacity: 1; } /* always show on mobile — no hover */

  /* Bigger touch targets */
  .task-checkbox { width: 24px; height: 24px; }
  .subtask-checkbox { width: 20px; height: 20px; }
  .subtask-delete { opacity: 1; width: 24px; height: 24px; }

  .btn-primary { height: 40px; font-size: 14px; padding: 0 var(--space-4); }
  .btn-icon { width: 36px; height: 36px; }
  .pill { padding: 6px var(--space-3); }

  /* Kanban stacked on mobile */
  .kanban {
    grid-template-columns: 1fr;
    padding: 0 var(--space-3) var(--space-4);
    gap: var(--space-3);
    overflow-y: auto;
  }

  .kanban-column {
    border-radius: 16px;
    max-height: none;
    overflow: visible;
  }

  .kanban-cards { overflow: visible; }

  /* Modal full-width on mobile */
  .modal-backdrop { padding: var(--space-3); align-items: flex-end; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
  }
  .modal-sm { max-width: 100%; }
  .form-row { grid-template-columns: 1fr; }

  /* Popover: position at bottom on mobile */
  .popover {
    position: fixed;
    left: var(--space-3) !important;
    right: var(--space-3);
    bottom: var(--space-3) !important;
    top: auto !important;
    width: auto;
    border-radius: 16px;
    padding: var(--space-2);
  }

  .popover-option { padding: 10px var(--space-4); font-size: 15px; }

  /* Empty states */
  .empty-root, .empty-tasks { padding: var(--space-5); padding-left: 52px; }
}

/* ─── Space Settings Gear Button ────────────────────────── */
.btn-space-settings {
  opacity: 0;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: opacity 0.12s, background 0.12s, color 0.12s;
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar-space-header:hover .btn-space-settings { opacity: 1; }
.btn-space-settings:hover { background: rgba(0,0,0,0.08); color: var(--color-text); }
[data-theme="dark"] .btn-space-settings:hover { background: rgba(255,255,255,0.08); }

/* ─── Space Settings Modal ─────────────────────────────── */
.space-settings-body {
  padding: var(--space-4) var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 70vh;
  overflow-y: auto;
}

.space-settings-body form {
  padding: 0;
}

.space-settings-section {
  padding: var(--space-4) 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.space-settings-section:last-child { border-bottom: none; }

[data-theme="dark"] .space-settings-section { border-bottom-color: rgba(255,255,255,0.06); }

.space-settings-section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.space-settings-error {
  font-size: 13px;
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  background: #fef2f2;
  color: #b91c1c;
  border-radius: var(--radius-btn);
  margin-bottom: var(--space-3);
}

[data-theme="dark"] .space-settings-error { background: #3a1a1a; color: #fca5a5; }

/* ─── Members List ─────────────────────────────────────── */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.member-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  object-fit: cover;
  flex-shrink: 0;
}

.member-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.member-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.member-role-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-badge);
  text-transform: capitalize;
  flex-shrink: 0;
}

.member-role-owner       { background: #fef3cd; color: #856404; }
.member-role-admin       { background: #d4edda; color: #155724; }
.member-role-collaborator { background: var(--color-surface); color: var(--color-text-muted); }
.member-role-viewer      { background: var(--color-surface); color: var(--color-text-disabled); }

[data-theme="dark"] .member-role-owner { background: #3a2e10; color: #e8b830; }
[data-theme="dark"] .member-role-admin { background: #132a1a; color: #4ade80; }

.btn-remove-member {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* ─── Member Role Select ───────────────────────────────── */
.member-role-select {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 24px 2px 8px;
  border-radius: var(--radius-badge);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='6' viewBox='0 0 8 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l3 3 3-3' stroke='%236a6a6a' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ─── Task Assignee (on cards) ─────────────────────────── */
.task-assignee {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.task-assignee-avatar {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  object-fit: cover;
}

/* ─── Add Member Row ───────────────────────────────────── */
.add-member-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* ─── Danger Zone ──────────────────────────────────────── */
.space-settings-danger {
  border-bottom: none;
}

.btn-danger-outline {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-brand);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-brand);
  background: transparent;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.btn-danger-outline:hover {
  background: var(--color-brand);
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════
   Login Page
   ═══════════════════════════════════════════════════════════ */
.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.login-container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  padding: var(--space-6);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.login-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.3px;
}

.login-heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: var(--space-1);
}

.login-sub {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.login-error {
  background: #fef2f2;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-btn);
  margin-bottom: var(--space-4);
}

[data-theme="dark"] .login-error {
  background: #3a1a1a;
  color: #fca5a5;
}

.login-card form {
  padding: 0;
}

.login-submit {
  width: 100%;
  justify-content: center;
  height: 40px;
  margin-top: var(--space-2);
}

.login-submit:disabled {
  opacity: 0.6;
  pointer-events: none;
}
