:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e7e5e0;
  --soft: #f1f0ec;
  --primary: #111827;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; line-height: 1.2; color: var(--text);
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--err); border-color: #f5c2c2; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.btn.round { width: 34px; height: 34px; border-radius: 50%; padding: 0; justify-content: center; font-size: 18px; }
.btn.warn { background: #fff7ed; border-color: #fdba74; color: #9a3412; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.brand.big { font-size: 22px; justify-content: center; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
}

.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 400px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: 0 8px 30px rgba(0,0,0,.05); }
.login-sub { color: var(--muted); text-align: center; line-height: 1.6; margin: 14px 0 24px; }
.login-card label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; }
.login-hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 18px; }
.form-error { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 10px; }

.app { display: flex; height: 100vh; }
.sidebar { width: 260px; flex-shrink: 0; border-right: 1px solid var(--line); background: #fbfbfa; display: flex; flex-direction: column; padding: 16px 12px; gap: 14px; }
.new-task { justify-content: center; }
.task-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.task-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: flex-start; }
.task-item:hover { background: var(--soft); }
.task-item.active { background: #ebeae6; }
.task-item .t { flex: 1; min-width: 0; }
.task-item .name { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-item .time { font-size: 11px; color: var(--muted); margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; margin-top: 6px; flex-shrink: 0; }
.dot.running, .dot.queued { background: var(--accent); animation: pulse 1.4s infinite; }
.dot.waiting_user { background: var(--warn); }
.dot.done { background: var(--ok); }
.dot.error { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.home h1 { font-size: 30px; font-weight: 600; margin: 0 0 28px; }
.composer { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.03); }
.composer.big { width: 760px; max-width: 100%; padding: 14px 16px; }
.composer textarea { width: 100%; border: none; outline: none; resize: none; background: transparent; line-height: 1.6; max-height: 220px; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.composer-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.model-select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--panel); font-size: 13px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; width: 760px; max-width: 100%; }
.example { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; color: #374151; }
.example:hover { background: var(--soft); }

.task { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.task-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 12px; }
.task-title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.task-title-wrap h2 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-actions { display: flex; gap: 8px; flex-shrink: 0; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.running, .badge.queued { background: #e0ecff; color: #1d4ed8; }
.badge.waiting_user { background: #fff3dc; color: #b45309; }
.badge.done { background: #dcfce7; color: #15803d; }
.badge.error { background: #fee2e2; color: #b91c1c; }

.task-body { flex: 1; display: flex; min-height: 0; }
.conversation { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 20px 16px; }
.timeline { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 4px; display: flex; flex-direction: column; gap: 12px; }
.timeline > * { flex-shrink: 0; }

.plan { margin-top: 14px; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.plan-head { display: flex; justify-content: space-between; cursor: pointer; font-size: 13px; font-weight: 600; }
.plan ol { margin: 8px 0 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.plan li { font-size: 13px; display: flex; gap: 8px; align-items: flex-start; color: #374151; }
.plan li.done { color: var(--muted); text-decoration: line-through; }
.plan li.in_progress { color: var(--accent); font-weight: 600; }
.plan .ck { width: 16px; flex-shrink: 0; text-align: center; }
.plan.collapsed ol { display: none; }

.msg-user { align-self: flex-end; background: #ebeae6; border-radius: 14px 14px 4px 14px; padding: 10px 14px; max-width: 80%; white-space: pre-wrap; line-height: 1.6; }
.msg-ai { line-height: 1.7; max-width: 100%; }
.msg-ai.thinking { color: #4b5563; font-size: 14px; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--soft); }
.md pre { background: #f6f8fa; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.md code { background: #f3f4f6; padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.md pre code { background: none; padding: 0; }
.md img { max-width: 100%; }
.md blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }

.step { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; font-size: 13px; overflow: hidden; }
.step-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; }
.step-row:hover { background: #fafaf9; }
.step-icon { width: 22px; height: 22px; border-radius: 6px; background: var(--soft); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 12px; }
.step-label { font-weight: 600; white-space: nowrap; }
.step-detail { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.step-state { font-size: 11px; flex-shrink: 0; }
.step-state.running { color: var(--accent); }
.step-state.ok { color: var(--ok); }
.step-state.fail { color: var(--err); }
.step-out { display: none; border-top: 1px solid var(--line); background: #fafaf9; padding: 8px 10px; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; max-height: 300px; overflow: auto; color: #374151; }
.step.open .step-out { display: block; }
.step-media { display: block; width: 100%; max-height: 360px; border-top: 1px solid var(--line); background: #000; }
img.step-media { object-fit: contain; object-position: top; background: #f3f4f6; cursor: zoom-in; }

.card { border-radius: var(--radius); padding: 12px 14px; line-height: 1.7; }
.card.ask { background: #fffbeb; border: 1px solid #fde68a; }
.card.finish { background: var(--panel); border: 1px solid #bbf7d0; box-shadow: 0 2px 10px rgba(22,163,74,.06); }
.card.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; white-space: pre-wrap; font-size: 13px; }
.card-title { font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.note { font-size: 12px; color: var(--muted); text-align: center; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-chip { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; background: var(--soft); cursor: pointer; }
.file-chip:hover { background: #e7e5e0; }

.computer { width: 46%; max-width: 760px; min-width: 380px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.computer-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 8px; }
.computer-head strong { font-size: 13.5px; margin-right: 6px; }
.tabs { display: flex; gap: 4px; }
.tab { border: none; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.tab.active { background: var(--soft); color: var(--text); }
.computer-activity { padding: 6px 14px; border-bottom: 1px solid var(--line); min-height: 28px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.computer-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen-wrap { flex: 1; background: #111; position: relative; min-height: 0; }
.screen-wrap iframe { width: 100%; height: 100%; border: none; display: block; }
.screen-placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #e5e7eb; text-align: center; padding: 24px; gap: 4px; }
.screen-placeholder .muted { color: #9ca3af; max-width: 340px; line-height: 1.6; }
.screen-placeholder .btn { margin-top: 10px; color: #e5e7eb; border-color: #374151; }
.screen-placeholder .btn:hover { background: #1f2937; }
.screen-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); }
.files-head { padding: 8px 14px; border-bottom: 1px solid var(--line); }
.file-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; font-size: 13px; }
.file-row:hover { background: var(--soft); }
.file-row .fp { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.file-row .fs { color: var(--muted); font-size: 11px; }

.preview { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.preview-card { background: var(--panel); width: 1000px; max-width: 100%; height: 86vh; border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.preview-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 8px; }
.preview-head > div { display: flex; gap: 6px; }
.preview-card iframe { flex: 1; border: none; width: 100%; background: #fff; }

@media (max-width: 1100px) {
  .computer { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; width: 92vw; min-width: 0; box-shadow: -8px 0 30px rgba(0,0,0,.12); }
  .computer.collapsed { display: none; }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .home h1 { font-size: 24px; }
}
.computer.collapsed { display: none; }
