:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --indigo: #4f46e5;
  --green: #10b981;
  --green-soft: #d1fae5;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --red: #ef4444;
  --red-soft: #fee2e2;
  --gray-soft: #f1f5f9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px -12px rgba(15, 23, 42, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* ---------- header ---------- */

.app-header {
  margin-bottom: 16px;
}

.header-main {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.header-text h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.field-inline input {
  border: none;
  background: transparent;
  font: inherit;
  color: var(--text);
  outline: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

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

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: var(--gray-soft);
  overflow: hidden;
}

.stat-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--indigo));
  transition: width 0.25s ease;
}

/* ---------- toolbar ---------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  margin: 14px 0 8px;
  background: rgba(244, 246, 251, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.filters,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filters {
  flex: 1 1 420px;
}

.search-input {
  flex: 1 1 200px;
  min-width: 160px;
}

input[type="search"],
input[type="text"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  outline: none;
  min-width: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea {
  resize: vertical;
}

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-soft);
  border-color: var(--text-muted);
}

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

.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--gray-soft);
  border-color: transparent;
}

.btn-danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.btn-danger-ghost {
  color: var(--red);
  border-color: var(--red-soft);
  background: var(--surface);
}

.btn-danger-ghost:hover {
  background: var(--red-soft);
  border-color: var(--red-soft);
}

.btn-icon {
  padding: 4px 7px;
  font-size: 13px;
  line-height: 1.2;
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.btn-icon:hover {
  background: var(--gray-soft);
  border-color: transparent;
  color: var(--text);
}

.hidden {
  display: none !important;
}

.match-info {
  margin: 2px 2px 10px;
  min-height: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- stage / module ---------- */

.plan-root {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-soft), var(--surface));
}

.stage-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.stage-title {
  margin: 0;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stage-weeks {
  font-size: 12px;
  font-weight: 600;
  color: var(--indigo);
  background: #eef2ff;
  border-radius: 999px;
  padding: 2px 9px;
}

.stage-goal {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.stage-controls {
  display: flex;
  gap: 2px;
  align-items: center;
}

.stage-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--gray-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--indigo));
  transition: width 0.25s ease;
}

.progress-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  min-width: 74px;
  text-align: right;
}

.modules {
  display: flex;
  flex-direction: column;
}

.module {
  padding: 12px 16px 14px;
  border-top: 1px dashed var(--line);
}

.module:first-child {
  border-top: none;
}

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

.module-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.module-goal {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

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

.module-controls {
  display: flex;
  gap: 2px;
  align-items: center;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 8px;
  border-radius: var(--radius-sm);
  padding: 2px;
}

.task-list.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.task-list-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 4px;
}

/* ---------- task ---------- */

.task {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.task:hover {
  border-color: var(--line-strong);
}

.task.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.task.dragging {
  opacity: 0.5;
}

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

.drag-handle {
  cursor: grab;
  color: var(--line-strong);
  font-size: 16px;
  line-height: 1.4;
  user-select: none;
  padding: 4px 2px 0;
}

.drag-handle:active {
  cursor: grabbing;
}

.status-select {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 7px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
}

.status-select.status-todo {
  background: var(--gray-soft);
  color: var(--text-soft);
}

.status-select.status-doing {
  background: var(--amber-soft);
  color: #92400e;
}

.status-select.status-done {
  background: var(--green-soft);
  color: #047857;
}

.task-main {
  flex: 1 1 260px;
  min-width: 0;
}

.task-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.chip {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.prio-high {
  color: #b91c1c;
  background: var(--red-soft);
  border-color: #fecaca;
}

.chip.prio-medium {
  color: #92400e;
  background: var(--amber-soft);
  border-color: #fde68a;
}

.chip.prio-low {
  color: var(--text-soft);
  background: var(--gray-soft);
}

.chip.date-overdue {
  color: #b91c1c;
  background: var(--red-soft);
  border-color: #fecaca;
}

.chip.note-chip {
  max-width: 320px;
  color: var(--text-soft);
}

.repo-cell {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  max-width: 100%;
}

.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  text-decoration: none;
  white-space: nowrap;
}

.repo-link:hover {
  background: #bfdbfe;
}

.repo-inline {
  display: flex;
  gap: 4px;
  align-items: center;
}

.repo-inline input {
  width: 190px;
  font-size: 12.5px;
  padding: 5px 7px;
}

.task-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
  align-items: center;
  margin-left: auto;
}

/* ---------- dialog ---------- */

.task-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(640px, 94vw);
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, 0.45);
}

.task-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.task-dialog form {
  padding: 18px 18px 14px;
}

.task-dialog h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-soft);
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}

.dialog-actions .spacer {
  flex: 1;
}

/* ---------- footer / toast ---------- */

.app-footer {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 16px);
  background: #0f172a;
  color: #fff;
  font-size: 13px;
  padding: 9px 15px;
  border-radius: 999px;
  box-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .app {
    padding: 14px 10px 40px;
  }

  .header-text h1 {
    font-size: 21px;
  }

  .toolbar {
    position: static;
  }

  .filters,
  .actions {
    flex: 1 1 100%;
  }

  .filters > *,
  .actions > * {
    flex: 1 1 auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .task {
    align-items: center;
  }

  .task-main {
    flex: 1 1 100%;
    order: 3;
  }

  .repo-cell {
    order: 4;
    flex: 1 1 100%;
  }

  .task-actions {
    order: 2;
  }

  .repo-inline {
    flex: 1 1 100%;
  }

  .repo-inline input {
    flex: 1;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- 云端同步 ---------- */

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.sync-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sync-pill.sync-synced {
  color: #047857;
  border-color: #a7f3d0;
  background: var(--green-soft);
}

.sync-pill.sync-dirty {
  color: #92400e;
  border-color: #fde68a;
  background: var(--amber-soft);
}

.sync-pill.sync-invalid,
.sync-pill.sync-error {
  color: #b91c1c;
  border-color: #fecaca;
  background: var(--red-soft);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex: 0 0 auto;
}

.sync-dot-syncing {
  background: var(--accent);
  animation: syncPulse 1s ease-in-out infinite;
}

.sync-dot-synced {
  background: var(--green);
}

.sync-dot-dirty {
  background: var(--amber);
}

.sync-dot-invalid,
.sync-dot-error {
  background: var(--red);
}

@keyframes syncPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.sync-dialog .sync-body {
  padding: 18px 18px 14px;
}

.sync-dialog .sync-hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.sync-state {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-soft);
}

.sync-last-time {
  margin-left: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.sync-key-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-soft);
}

.sync-key-label input {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 13px;
}

.sync-note {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

.sync-note code {
  background: var(--gray-soft);
  border-radius: 4px;
  padding: 1px 5px;
}

@media (max-width: 720px) {
  .sync-pill {
    order: -1;
  }
}
