:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e3e5ea;
  --text: #1c1e26;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 6px;
  --radius-sm: 4px;

  --prio-high: #ef4444;
  --prio-medium: #f59e0b;
  --prio-low: #10b981;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #191c22;
  --surface-2: #21252d;
  --border: #2b303a;
  --text: #e7e9ee;
  --text-muted: #9aa3b2;
  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --primary-soft: #20243a;
  --danger: #f87171;
  --danger-soft: #2a1d1f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
svg { display: block; flex-shrink: 0; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: inline-flex; color: var(--primary); }
.logo svg { width: 26px; height: 26px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.stats { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 38px; height: 38px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, transform .05s;
}
.icon-btn:hover { color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.95); }

/* Overview / overall progress */
.overview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.overview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.overview-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.overview-pct { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.overview-track { height: 10px; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.overview-fill { height: 100%; background: var(--primary); border-radius: inherit; transition: width .3s ease; }
.overview-fill.complete { background: var(--prio-low); }

.overview-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
}
.stat-chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.overview-breakdown { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 16px; }
.bd-item { min-width: 0; }
.bd-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; margin-bottom: 5px; }
.bd-label { font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.bd-label.high { color: var(--prio-high); }
.bd-label.medium { color: var(--prio-medium); }
.bd-label.low { color: var(--prio-low); }
.bd-meta { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.bd-track { height: 5px; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.bd-fill { height: 100%; border-radius: inherit; transition: width .3s ease; }
.bd-fill.high { background: var(--prio-high); }
.bd-fill.medium { background: var(--prio-medium); }
.bd-fill.low { background: var(--prio-low); }

/* Sync button + status dot */
.sync-btn { position: relative; }
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.sync-btn .sync-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  box-shadow: 0 0 0 2px var(--surface);
}
.sync-dot[data-state="ok"] { background: #10b981; }
.sync-dot[data-state="connecting"] { background: #f59e0b; }
.sync-dot[data-state="error"] { background: #ef4444; }
.sync-dot[data-state="off"] { background: var(--text-muted); }

/* Sync dialog */
.sync-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 480px;
  width: calc(100% - 32px);
}
.sync-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.sync-dialog-inner {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.sync-dialog h2 { margin: 0 0 8px; font-size: 18px; letter-spacing: -0.01em; }
.sync-desc { font-size: 13px; color: var(--text-muted); margin: 0 0 16px; line-height: 1.55; }
.sync-desc code {
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}
.sync-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.sync-field span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--text-muted); }
.sync-field input {
  font-family: inherit;
  font-size: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
.sync-field input:focus { border-color: var(--primary); }
.sync-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); margin: 0 0 18px; }
.sync-actions { display: flex; align-items: center; gap: 8px; }
.sync-spacer { flex: 1; }

/* Composer */
.composer {
  display: flex;
  gap: 10px;
  background: var(--surface);
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.task-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  min-width: 0;
}
.task-input::placeholder { color: var(--text-muted); }

.priority-select, .sort-select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 14px;
  cursor: pointer;
  outline: none;
}
.priority-select { height: 42px; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 16px;
  height: 42px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: #fff; border-color: transparent; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--border); padding: 4px; border-radius: var(--radius); }
.chip {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--primary-soft); color: var(--primary); }

.toolbar-right { display: flex; align-items: center; gap: 12px; }
.sort-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.sort-select { height: 36px; }

/* Task list */
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.task {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--prio-medium);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s, opacity .15s, transform .08s, box-shadow .15s;
}
.task-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}
.task[data-priority="high"] { border-left-color: var(--prio-high); }
.task[data-priority="medium"] { border-left-color: var(--prio-medium); }
.task[data-priority="low"] { border-left-color: var(--prio-low); }
.task.done { opacity: 0.55; }
.task.done .task-title { text-decoration: line-through; }
.task.dragging { opacity: 0.4; }
.task.drag-over { transform: translateY(2px); box-shadow: 0 -2px 0 var(--primary) inset; }

.grip {
  cursor: grab;
  color: var(--text-muted);
  line-height: 0;
  user-select: none;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  opacity: .6;
}
.grip:hover { opacity: 1; }
.grip:active { cursor: grabbing; }

.checkbox {
  appearance: none;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.checkbox:checked { background: var(--primary); border-color: var(--primary); }
.checkbox:checked::after {
  content: "";
  position: absolute;
  top: 45%; left: 50%;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -55%) rotate(45deg);
}

.task-body { flex: 1; min-width: 0; }
.task-title {
  font-size: 15px;
  word-break: break-word;
  cursor: default;
}
.task-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.meta-note { display: inline-flex; opacity: .8; }
.meta-note svg { width: 13px; height: 13px; }

/* Progress (row) */
.progress-mini { display: flex; align-items: center; gap: 8px; width: 116px; flex-shrink: 0; }
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width .2s ease;
}
.progress-fill.complete { background: var(--prio-low); }
.progress-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Detail panel */
.task-detail {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.task-detail[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  font-weight: 700;
}
.field textarea, .field .date-input {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  outline: none;
  transition: border-color .15s;
}
.field textarea { resize: vertical; min-height: 56px; }
.field textarea:focus, .field .date-input:focus { border-color: var(--primary); }
.progress-row { display: flex; align-items: center; gap: 12px; }
.progress-range { flex: 1; accent-color: var(--primary); cursor: pointer; }
.progress-value { font-size: 13px; font-weight: 700; width: 42px; text-align: right; font-variant-numeric: tabular-nums; }

.expand-btn svg { transition: transform .2s ease; }
.task.expanded .expand-btn svg { transform: rotate(180deg); }

.task-edit {
  width: 100%;
  font-size: 15px;
  padding: 6px 8px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.prio-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: .03em;
  flex-shrink: 0;
}
.prio-badge.high { background: rgba(239,68,68,.14); color: var(--prio-high); }
.prio-badge.medium { background: rgba(245,158,11,.16); color: var(--prio-medium); }
.prio-badge.low { background: rgba(16,185,129,.14); color: var(--prio-low); }

.task-actions { display: flex; gap: 2px; flex-shrink: 0; }
.act-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.act-btn:hover { background: var(--surface-2); color: var(--text); }
.act-btn.delete:hover { background: var(--danger-soft); color: var(--danger); }

/* Empty + footer */
.empty { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-emoji { display: flex; justify-content: center; opacity: .5; }
.empty-emoji svg { width: 48px; height: 48px; }
.empty-title { font-size: 16px; font-weight: 600; margin: 12px 0 4px; color: var(--text); }
.empty-sub { font-size: 13px; margin: 0; }

.footer {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 8px;
}
.footer-hint { display: inline-flex; align-items: center; gap: 4px; }
.grip-mini { display: inline-flex; vertical-align: middle; opacity: .6; }
.grip-mini svg { width: 14px; height: 14px; }

@media (max-width: 560px) {
  .composer { flex-wrap: wrap; }
  .task-input { flex-basis: 100%; }
  .priority-select { flex: 1; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { justify-content: space-between; }
  .task-detail { grid-template-columns: 1fr; }
  .progress-mini { width: 84px; }
  .overview-breakdown { grid-template-columns: 1fr; }
}
