/* ==========================================================================
   调度中枢(DispatchHub) 样式
   设计 token 来源：tokens.css（与 design-web.html / design-swift.html 一致）
   ========================================================================== */

:root {
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-ring: rgba(37, 99, 235, 0.16);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --ink: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --surface-solid: #ffffff;
  --canvas: #f6f7f9;
  --completed: #f3f4f6;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.06);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

body {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--canvas);
  min-height: 100vh;
}

#app {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
}

/* ── 通用 ──────────────────────────────────────────────────── */
.input {
  font-family: inherit; font-size: 14px; color: var(--ink);
  padding: 10px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  width: 100%; outline: none; background: var(--surface-solid);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.input::placeholder { color: var(--faint); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

.btn {
  font-family: inherit; font-size: 14px; padding: 10px 20px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-solid); cursor: pointer;
  color: var(--ink); transition: all 0.18s var(--ease);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { opacity: 0.9; }
.btn.full { width: 100%; }

.icon-btn {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-solid); cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: all 0.18s var(--ease);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.icon-btn.add { border: 1.5px dashed var(--line-strong); border-radius: var(--radius-full); font-size: 15px; }
.icon-btn.add:hover { border-color: var(--accent); border-style: solid; }
.icon-btn.more { font-size: 18px; letter-spacing: -2px; }

:focus-visible { outline: 2px solid rgba(37, 99, 235, 0.35); outline-offset: 2px; }

/* ── 登录视图 ──────────────────────────────────────────────── */
.login-view {
  display: flex; align-items: center; justify-content: center; min-height: 80vh;
}
.login-card {
  width: 100%; max-width: 360px; padding: 32px;
  background: var(--surface-solid); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.login-card h3 { font-size: 20px; font-weight: 700; margin-bottom: 22px; text-align: center; }
.login-card .input { margin-bottom: 12px; }
.login-error {
  background: var(--danger-soft); color: var(--danger); padding: 8px 12px;
  border-radius: 6px; font-size: 13px; margin-bottom: 12px;
}
.login-switch { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.login-switch a { color: var(--accent); text-decoration: none; font-weight: 600; }
.login-switch a:hover { text-decoration: underline; }

/* ── 顶栏 ──────────────────────────────────────────────────── */
.app-shell {
  background: var(--surface-solid); border-radius: var(--radius-lg);
  border: 1px solid var(--line); overflow: hidden;
}
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  background: var(--surface-solid);
}
.ah-left { display: flex; align-items: baseline; gap: 10px; }
.ah-title { font-size: 18px; font-weight: 700; }
.ah-sub { font-size: 12px; color: var(--muted); }
.ah-right { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }

/* ── 管理后台 ──────────────────────────────────────────────── */
.admin-panel { padding: 16px 20px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.admin-header h3 { font-size: 16px; font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--line); color: var(--muted); font-weight: 600; font-size: 12px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.disabled-row td { color: var(--faint); text-decoration: line-through; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; }
.role-badge.admin { background: var(--accent-soft); color: var(--accent); }
.role-badge.user { background: var(--canvas); color: var(--muted); }
.admin-act { display: inline-flex; gap: 6px; }
.admin-act button, .admin-act select {
  font-family: inherit; font-size: 12px; padding: 3px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface-solid);
  cursor: pointer; color: var(--muted); transition: all 0.18s var(--ease);
}
.admin-act button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.admin-act button.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.admin-act button:disabled { opacity: 0.4; cursor: not-allowed; }
.admin-act select { color: var(--ink); }

/* ── 新建任务条 ────────────────────────────────────────────── */
.composer { padding: 12px 20px; border-bottom: 1px solid var(--line); }

/* ── 任务列表 ──────────────────────────────────────────────── */
.task-board { }
.empty-state { padding: 40px 20px; text-align: center; color: var(--faint); font-size: 14px; }

.task-line {
  display: flex; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line); gap: 0;
}
.task-line:last-child { border-bottom: none; }
.task-line.done { background: var(--completed); }

.title-cell {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 10px 20px; width: 260px; min-width: 180px;
  flex-shrink: 0; border-right: 1px solid var(--line);
}

/* 拖拽手柄（规范 §8.4：长按拖拽的可视入口） */
.drag-handle {
  cursor: grab; color: var(--faint); font-size: 14px; font-weight: 700;
  letter-spacing: -3px; user-select: none; padding: 0 2px; flex-shrink: 0;
  line-height: 1; touch-action: none; display: inline-block;
}
.drag-handle:hover { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }
.drag-handle.sub { font-size: 11px; letter-spacing: -2px; padding: 0 1px; }

/* 复选框 */
.checkbox {
  width: 24px; height: 24px; border: 2px solid var(--line-strong);
  border-radius: 7px; flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s var(--ease);
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.checked { background: var(--success); border-color: var(--success); }
.checkbox.checked::after {
  content: ''; width: 6px; height: 11px; border: solid #fff;
  border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px);
}

/* 任务名 */
.task-name {
  font-size: 15px; font-weight: 600; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: text; padding: 2px 4px; border-radius: 4px;
}
.task-name:hover { background: rgba(37, 99, 235, 0.06); }
.task-line.done .task-name { color: var(--faint); text-decoration: line-through; }

/* 行内编辑 */
.inline-edit {
  font-family: inherit; font-size: 15px; color: var(--ink); border: none; outline: none;
  flex: 1; min-width: 0; padding: 2px 4px; border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.22);
}

/* ⋯ 菜单 */
.menu-wrap { position: static; }
.action-menu {
  position: fixed; z-index: 200;
  min-width: 120px; background: var(--surface-solid);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card); padding: 4px;
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 12px;
  border: none; border-radius: 6px; background: transparent;
  font-family: inherit; font-size: 13px; color: var(--ink); cursor: pointer;
}
.menu-item:hover { background: var(--accent-soft); color: var(--accent); }
.menu-item.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ── 子任务横向滚动区 ──────────────────────────────────────── */
.subtask-strip {
  display: flex; align-items: center; gap: 8px; overflow-x: auto; flex: 1;
  padding: 10px 14px; min-width: 0; scrollbar-width: none;
}
.subtask-strip::-webkit-scrollbar { display: none; }

.subtask-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; background: var(--canvas); border-radius: var(--radius-full);
  border: 1px solid var(--line); flex-shrink: 0; height: 34px;
  transition: all 0.18s var(--ease);
}
.subtask-chip:hover { border-color: var(--line-strong); }
.subtask-chip.done { background: var(--completed); }
.subtask-chip.editing {
  background: var(--surface-solid); border: 1.5px solid rgba(37, 99, 235, 0.28);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
  border-radius: var(--radius-full);
}
.subtask-chip.done .subtask-label { color: var(--faint); text-decoration: line-through; }

.mini-check {
  width: 18px; height: 18px; border: 1.5px solid var(--line-strong);
  border-radius: 5px; flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.subtask-chip.done .mini-check { background: var(--success); border-color: var(--success); }
.subtask-chip.done .mini-check::after {
  content: ''; width: 3px; height: 6px; border: solid #fff;
  border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}

.subtask-label { font-size: 13px; cursor: text; }
.chip-more { margin-left: auto; color: var(--muted); font-weight: 700; font-size: 14px;
  cursor: pointer; opacity: 0; transition: opacity 0.18s var(--ease); }
.subtask-chip:hover .chip-more { opacity: 1; }

.subtask-input {
  font-family: inherit; font-size: 13px; color: var(--ink);
  border: none; outline: none; background: transparent;
  min-width: 60px; width: 90px;
}
.subtask-input::placeholder { color: var(--faint); }

.count-badge {
  font-size: 12px; color: var(--muted); padding: 0 14px; flex-shrink: 0;
  white-space: nowrap;
}

/* ── 拖拽排序视觉反馈 ────────────────────────────────────── */
.task-line.dragging { opacity: 0.5; background: var(--accent-soft); }
.task-line.drag-over-top { box-shadow: inset 0 2px 0 0 var(--accent); }
.task-line.drag-over-bottom { box-shadow: inset 0 -2px 0 0 var(--accent); }
.subtask-chip.dragging { opacity: 0.4; }
.subtask-chip.drag-over-left { box-shadow: inset 2px 0 0 0 var(--accent); }
.subtask-chip.drag-over-right { box-shadow: inset -2px 0 0 0 var(--accent); }
.task-line { transition: box-shadow 0.15s var(--ease); }
.subtask-chip { transition: box-shadow 0.15s var(--ease); }
.task-line { user-select: none; }
.subtask-strip { user-select: none; }

/* ── 响应式：手机端 ────────────────────────────────────────── */
@media (max-width: 640px) {
  #app { padding: 0; }
  .app-shell { border-radius: 0; border: none; }
  .title-cell { width: auto; min-width: 120px; padding-left: 12px; }
  .task-name { font-size: 14px; }
  .subtask-strip { padding: 8px 10px; }
}
