:root {
  --bg: #f3f5f8;
  --bg-soft: #eef1f5;
  --card: #fdfdfe;
  --text: #1d2129;
  --muted: #5e6776;
  --line: #e6e9ee;
  --accent: #2f5fd8;        /* 文字/链接/激活态，AA 达标 */
  --accent-bg: #2f5fd8;     /* 按钮实底，配白字 AA 达标 */
  --accent-hover: #284fb5;
  --accent-soft: #e8eefe;
  --pending: #9aa3af;
  --claimed: #3b6ef5;
  --done: #22c55e;
  --failed: #ef4444;
  --cancelled: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, 0.05);
  --shadow-md: 0 4px 14px rgba(20, 30, 60, 0.07);
  --shadow-lg: 0 8px 24px rgba(20, 30, 60, 0.10);
  --radius: 16px;
  --radius-sm: 11px;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #161a20;
    --card: #1a1e25;
    --text: #e8eaed;
    --muted: #919aab;
    --line: #262b33;
    --accent: #6a90ff;       /* 深色底上文字用更亮的蓝，AA 达标 */
    --accent-bg: #2f5fd8;    /* 按钮实底保持深蓝，配白字 AA 达标 */
    --accent-hover: #284fb5;
    --accent-soft: #1e2a45;
    --pending: #6b7280;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s var(--ease), color 0.15s var(--ease),
              transform 0.12s var(--ease), box-shadow 0.15s var(--ease),
              opacity 0.15s var(--ease);
}

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  width: 100%;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
textarea { resize: vertical; min-height: 124px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

/* Phosphor 图标尺寸对齐 */
#app-header .title i { font-size: 17px; vertical-align: -0.12em; margin-right: 5px; color: var(--accent); }
#tabbar .icon i { font-size: 21px; line-height: 1; }
.sheet h2 i { font-size: 18px; vertical-align: -0.14em; margin-right: 6px; color: var(--accent); }
.detail-section h3 i { font-size: 14px; vertical-align: -0.08em; margin-right: 5px; }
.att-item i { font-size: 16px; color: var(--muted); flex: none; }

/* ---------- 登录 ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(160deg, var(--accent-soft) 0%, var(--bg) 55%);
}
#login-view h1 { font-size: 24px; letter-spacing: -0.02em; }
#login-view h1 i { font-size: 28px; vertical-align: -0.1em; margin-right: 8px; color: var(--accent); }
#login-view .muted { margin-bottom: 6px; }
#login-form { display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }

/* ---------- 布局 ---------- */
#app-view { display: flex; flex-direction: column; min-height: 100vh; }

#app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  padding: 13px 16px;
  padding-top: max(13px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
}
#app-header::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
#app-header .title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; flex: none; }
#overview-chips { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; margin-left: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
#overview-chips::-webkit-scrollbar { display: none; }
.stat-chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
  flex: none;
}
.stat-chip b { color: var(--text); font-weight: 600; }

main { flex: 1; padding: 14px 14px 96px; max-width: 720px; width: 100%; margin: 0 auto; }

/* ---------- 底部 Tab ---------- */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  box-shadow: 0 -1px 12px rgba(20, 30, 60, 0.06);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1;
  background: none;
  color: var(--muted);
  padding: 9px 0 11px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-radius: 0;
  position: relative;
}
#tabbar button.active { color: var(--accent); font-weight: 600; }
#tabbar button.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 22px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}
#tabbar .icon { font-size: 21px; line-height: 1; }

/* ---------- 筛选条 ---------- */
.filter-bar {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar button {
  background: var(--card);
  color: var(--muted);
  border: 1.5px solid var(--line);
  padding: 6px 15px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  flex: none;
}
.filter-bar button.active {
  background: var(--accent-bg);
  color: #fff;
  border-color: var(--accent-bg);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(47, 95, 216, 0.3);
}

/* 状态筛选按钮：颜色与任务卡一致；选中态实底 + 白字 */
.filter-bar button[data-status="pending"]   { background: color-mix(in srgb, var(--pending)   14%, var(--card)); color: color-mix(in srgb, var(--pending)   75%, var(--text)); border-color: transparent; }
.filter-bar button[data-status="claimed"]   { background: color-mix(in srgb, var(--claimed)   14%, var(--card)); color: color-mix(in srgb, var(--claimed)   75%, var(--text)); border-color: transparent; }
.filter-bar button[data-status="done"]      { background: color-mix(in srgb, var(--done)      14%, var(--card)); color: color-mix(in srgb, var(--done)      75%, var(--text)); border-color: transparent; }
.filter-bar button[data-status="failed"]    { background: color-mix(in srgb, var(--failed)    14%, var(--card)); color: color-mix(in srgb, var(--failed)    75%, var(--text)); border-color: transparent; }
.filter-bar button[data-status="cancelled"] { background: color-mix(in srgb, var(--cancelled) 14%, var(--card)); color: color-mix(in srgb, var(--cancelled) 75%, var(--text)); border-color: transparent; }

.filter-bar button[data-status="pending"].active   { background: var(--pending);   color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--pending)   35%, transparent); }
.filter-bar button[data-status="claimed"].active   { background: var(--claimed);   color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--claimed)   35%, transparent); }
.filter-bar button[data-status="done"].active      { background: var(--done);      color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--done)      35%, transparent); }
.filter-bar button[data-status="failed"].active    { background: var(--failed);    color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--failed)    35%, transparent); }
.filter-bar button[data-status="cancelled"].active { background: var(--cancelled); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--cancelled) 35%, transparent); }

/* ---------- 卡片与列表 ---------- */
.card {
  background: var(--card);
  border: none;
  border-radius: var(--radius);
  padding: 15px 15px 15px 18px;
  margin-bottom: 11px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: box-shadow 0.18s var(--ease), transform 0.12s var(--ease);
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { box-shadow: var(--shadow-md); }
.card.clickable:active { transform: scale(0.985); }

/* 任务卡左侧状态色条（语义状态，唯一指示，不再配冗余圆点） */
.card[data-status]::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--pending);
}
.card[data-status="pending"]::before { background: var(--pending); }
.card[data-status="claimed"]::before { background: var(--claimed); }
.card[data-status="done"]::before { background: var(--done); }
.card[data-status="failed"]::before { background: var(--failed); }
.card[data-status="cancelled"]::before { background: var(--cancelled); }

/* 任务卡按状态着色：淡色底强化一眼区分，左侧色条保留作为锐色强调 */
.card[data-status="pending"]   { background: color-mix(in srgb, var(--pending)   8%, var(--card)); }
.card[data-status="claimed"]   { background: color-mix(in srgb, var(--claimed)   8%, var(--card)); }
.card[data-status="done"]      { background: color-mix(in srgb, var(--done)      8%, var(--card)); }
.card[data-status="failed"]    { background: color-mix(in srgb, var(--failed)    8%, var(--card)); }
.card[data-status="cancelled"] { background: color-mix(in srgb, var(--cancelled) 8%, var(--card)); }

/* 已取消任务：标题划删除线并置灰，强化"已作废"语义 */
.card[data-status="cancelled"] .title-line { text-decoration: line-through; color: var(--muted); }

.row { display: flex; align-items: center; gap: 8px; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); font-size: 12px; }
.title-line { font-weight: 600; font-size: 15.5px; flex: 1; word-break: break-word; letter-spacing: -0.01em; }

/* 圆点仅用于真实语义状态：智能体在线/离线 */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }
.dot.online { background: var(--done); color: var(--done); }
.dot.offline { background: var(--pending); color: var(--pending); }

/* 智能体头像 + 启用/停用状态环 */
.avatar {
  position: relative; width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--av) 16%, var(--card));
  color: var(--av);
}
.avatar > svg { width: 22px; height: 22px; }
.avatar-ring {
  position: absolute; inset: -3px; border-radius: 50%;
  border: 2.5px solid; pointer-events: none;
}
.avatar-ring.on { border-color: var(--done); }
.avatar-ring.off { border-color: var(--failed); }
.stopped { color: var(--failed); }

.tag {
  font-size: 11px;
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 6px;
  padding: 2.5px 8px;
  font-weight: 500;
}
.status-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.status-badge.pending { color: var(--pending); background: var(--bg-soft); }
.status-badge.claimed { color: var(--accent-hover); background: var(--accent-soft); }
.status-badge.done { color: #1a9d47; background: #e7f6ec; }
.status-badge.failed { color: var(--failed); background: #fde8e8; }
.status-badge.cancelled { color: var(--cancelled); background: var(--bg-soft); }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--accent-bg);
  color: #fff;
  padding: 13px;
  width: 100%;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 2px 8px rgba(47, 95, 216, 0.28);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.985); box-shadow: 0 1px 4px rgba(47, 95, 216, 0.2); }
.btn:disabled { opacity: 0.5; box-shadow: none; }
.btn.secondary {
  background: var(--bg-soft);
  color: var(--text);
  box-shadow: none;
  border: 1.5px solid var(--line);
}
.btn.secondary:hover { background: var(--line); }
.btn.danger { background: transparent; color: var(--failed); border: 1.5px solid var(--failed); box-shadow: none; }
.btn.danger:hover { background: #fde8e8; }
.btn.small { width: auto; padding: 7px 14px; font-size: 13px; font-weight: 500; box-shadow: none; }
.btn.small.secondary { background: var(--bg-soft); }

/* ---------- 表单 ---------- */
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
.chip-select { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-select button {
  background: var(--bg-soft);
  border: 1.5px solid transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}
.chip-select button:hover { color: var(--text); }
.chip-select button.on {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: var(--accent);
  font-weight: 600;
}
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch-row input { width: 22px; height: 22px; transform: scale(1.15); accent-color: var(--accent); }

/* 高级设置折叠 */
.advanced { margin-bottom: 16px; border-top: 1px dashed var(--line); padding-top: 4px; }
.advanced-toggle {
  width: 100%; text-align: left; background: none; color: var(--muted);
  padding: 10px 0; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.advanced-toggle:hover { color: var(--text); }
.advanced-toggle i { font-size: 14px; transition: transform 0.2s var(--ease); }
.advanced-toggle.open i { transform: rotate(180deg); }
.advanced-body { padding-top: 6px; }

/* 附件选择标签 */
.file-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-soft); border-radius: 999px;
  padding: 5px 6px 5px 10px; font-size: 13px; margin: 4px 4px 0 0;
  max-width: 100%;
}
.file-chip > i.ph-paperclip { font-size: 13px; color: var(--muted); flex: none; }
.file-chip { word-break: break-all; }
.file-del {
  background: none; color: var(--muted); padding: 2px 4px;
  border-radius: 999px; line-height: 1; display: inline-flex; flex: none;
}
.file-del:hover { color: var(--failed); }
.file-del i { font-size: 13px; }

/* 旋转图标 */
.spin { animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 详情 ---------- */
.detail-section { margin-bottom: 18px; }
.detail-section h3 { font-size: 12px; color: var(--muted); margin-bottom: 9px; font-weight: 600; letter-spacing: 0.02em; }
.markdown-body {
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 14px;
  line-height: 1.65;
  overflow-x: auto;
  word-break: break-word;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 0.6em 0 0.3em; letter-spacing: -0.01em; }
.markdown-body h1 { font-size: 18px; } .markdown-body h2 { font-size: 16px; } .markdown-body h3 { font-size: 14.5px; }
.markdown-body p { margin: 0.4em 0; }
.markdown-body ul, .markdown-body ol { margin: 0.4em 0; padding-left: 1.3em; }
.markdown-body li { margin: 0.2em 0; }
.markdown-body pre { background: var(--card); padding: 11px; border-radius: 9px; overflow-x: auto; margin: 0.5em 0; box-shadow: var(--shadow-sm); }
.markdown-body code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.markdown-body :not(pre) > code { background: var(--card); padding: 1px 5px; border-radius: 5px; }
.markdown-body blockquote { border-left: 3px solid var(--accent); margin: 0.5em 0; padding-left: 12px; color: var(--muted); }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body a { color: var(--accent); }

.timeline { list-style: none; }
.timeline li {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
  align-items: baseline;
}
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--muted); font-size: 12px; flex: none; width: 108px; }

.att-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 7px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s var(--ease);
}
.att-item:hover { background: var(--line); }
.att-item .size { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }

/* 追问再派 */
.task-link { color: var(--accent); cursor: pointer; }
.att-item.task-link .status-badge { margin-left: auto; flex: none; }
#f-followup {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  background: var(--accent-soft); color: var(--accent-hover);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 13.5px; margin-bottom: 14px;
}
#f-followup[hidden] { display: none; }
#f-followup i { font-size: 16px; }
#f-followup button { background: none; border: none; color: inherit; margin-left: auto; cursor: pointer; padding: 2px; }

/* 附件预览弹窗 */
.preview-img { text-align: center; max-height: 58vh; overflow: auto; }
.preview-img img { max-width: 100%; max-height: 58vh; border-radius: 10px; }
.preview-text { max-height: 58vh; overflow: auto; background: var(--bg-soft); border-radius: 10px; padding: 12px; }
.preview-text pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; line-height: 1.5; margin: 0; }
.preview-html { width: 100%; height: 58vh; border: none; border-radius: 10px; background: #fff; }
.preview-toggle { display: flex; gap: 8px; margin-bottom: 8px; }
.preview-toggle .btn { padding: 4px 14px; font-size: 13px; }
.preview-toggle .btn.active { border-color: var(--accent, #4f7cff); color: var(--accent, #4f7cff); }

.detail-actions { display: flex; gap: 10px; margin-top: 10px; }
.detail-actions .btn { flex: 1; }

/* ---------- 弹层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 20, 35, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s var(--ease);
}
.overlay .sheet {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: min(720px, 100%);
  padding: 8px 16px calc(22px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s var(--ease);
}
.sheet::before {
  content: "";
  display: block;
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 16px;
}
.sheet h2 { font-size: 17px; margin-bottom: 12px; letter-spacing: -0.01em; }
.token-box {
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 13px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  word-break: break-all;
  margin: 10px 0;
  user-select: all;
}
.warn-text { color: var(--failed); font-size: 13px; margin-bottom: 10px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: rgba(20, 25, 40, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.empty { text-align: center; color: var(--muted); padding: 56px 0; font-size: 14px; }
.back-link { background: none; color: var(--accent); padding: 6px 0 10px; font-size: 14px; font-weight: 500; }
[hidden] { display: none !important; }

/* ---------- 无障碍：尊重减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
