/* AI 任务控制台样式:手机优先,深色模式跟随系统 */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1b1f27;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #2f6fed;
  --danger: #d6453d;
  --running: #22a06b;
  --idle: #9aa3b2;
  --stale: #cfd4dc;
  --claude: #d97757;
  --codex: #111827;
  --codex-text: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --card: #1a1d24;
    --text: #e6e8ee;
    --muted: #8b93a3;
    --border: #2a2f3a;
    --accent: #6b9bff;
    --danger: #ff6b61;
    --running: #3ccf8e;
    --idle: #5c6677;
    --stale: #3a4150;
    --claude: #e08a6b;
    --codex: #e6e8ee;
    --codex-text: #111318;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

.view {
  min-height: 100vh;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.danger {
  color: var(--danger);
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: 13px;
}

button {
  font: inherit;
  color: inherit;
}

/* ---------- 登录 ---------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 16px;
}

.login-card label {
  display: block;
  margin-bottom: 14px;
}

.login-card label span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-card input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.login-card button[disabled] {
  opacity: 0.6;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 6px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  max-width: 55vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex: 0 0 auto;
}

.agent-status.online .dot {
  background: var(--running);
}

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 4px;
  cursor: pointer;
  font-size: 13px;
}

/* ---------- 通知铃铛与面板 ---------- */
.icon-btn {
  position: relative;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.icon-btn[aria-expanded="true"],
.icon-btn.on {
  color: var(--accent);
}

.notify-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.notify-dot.ok {
  background: var(--running);
}

.notify-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 8px;
  box-shadow: var(--shadow);
}

.notify-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.notify-actions {
  display: inline-flex;
  gap: 6px;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}

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

.pill-btn[disabled] {
  opacity: 0.6;
  cursor: default;
}

#notify-hint {
  margin: 6px 0 0;
}

#notify-hint:empty {
  display: none;
}

.card.highlight {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 8px;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1 0 auto;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.tab.active {
  background: var(--card);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab .count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--border);
  font-size: 11px;
  text-align: center;
}

.tab .count.danger {
  background: var(--danger);
  color: #fff;
}

/* ---------- 列表 ---------- */
main {
  padding: 8px 12px calc(24px + env(safe-area-inset-bottom));
  max-width: 820px;
  margin: 0 auto;
}

#refresh-info {
  margin: 4px 2px 8px;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.needs-decision {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
}

.card-head {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  cursor: pointer;
}

.tool-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  margin-top: 2px;
}

.tool-icon.claude {
  background: var(--claude);
  color: #fff;
}

.tool-icon.codex {
  background: var(--codex);
  color: var(--codex-text);
}

.card-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--idle);
}

.status-dot.running {
  background: var(--running);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--running) 25%, transparent);
  animation: pulse 1.6s ease-in-out infinite;
}

.status-dot.stale {
  background: var(--stale);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.45;
  }
}

.badge {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.decision {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}

.card-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta .cwd {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-stale .title,
.status-stale .last-message {
  color: var(--muted);
}

.last-message {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  border-top: 1px solid var(--border);
  padding: 8px 12px 10px;
}

.detail-meta {
  margin: 0 0 8px;
  word-break: break-all;
}

.recent {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 2px 8px;
  font-size: 13px;
}

.msg .who {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}

.msg.user .who {
  color: var(--accent);
}

.msg .text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.tool_use .text,
.msg.tool_result .text {
  color: var(--muted);
  font-size: 12px;
}

.msg .ts {
  grid-column: 2;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- 自动任务折叠组 ---------- */
.auto-group {
  border: 1px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.auto-group-head {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.auto-group-head strong {
  color: var(--text);
}

.chevron {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin-right: 2px;
}

.auto-group-head[aria-expanded="true"] .chevron {
  transform: rotate(45deg);
}

.auto-group-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px 8px;
}

@media (min-width: 640px) {
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tab {
    flex: 0 0 auto;
  }
}

/* ---------- 阶段③:控 ---------- */
.controls { margin: 8px 0 10px; }
.control-reason { padding: 6px 0; }
.control-row { display: flex; gap: 8px; }
.control-input { flex: 1; min-height: 44px; resize: vertical; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border, #d0d4dc); background: var(--card-bg, #fff); color: inherit; font: inherit; }
.control-btns { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.pill-btn.danger { background: #c62828; color: #fff; border-color: #c62828; }
.pill-btn.small-btn { padding: 4px 10px; font-size: 13px; }
.new-task-panel form { display: grid; gap: 8px; }
.new-task-row { display: flex; gap: 8px; }
.new-task-row label.grow { flex: 1; }
.new-task-panel label { display: grid; gap: 4px; font-size: 13px; }
.new-task-panel input, .new-task-panel select, .new-task-panel textarea { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border, #d0d4dc); background: var(--card-bg, #fff); color: inherit; font: inherit; width: 100%; box-sizing: border-box; }
.new-task-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 92vw; padding: 10px 16px; border-radius: 12px; background: #263238; color: #fff; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 50; }
.toast.ok { background: #2e7d32; }
.toast.error { background: #c62828; }
@media (prefers-color-scheme: dark) {
  .control-input, .new-task-panel input, .new-task-panel select, .new-task-panel textarea { background: #1b1e26; border-color: #333845; }
}
