/* AI 工作台：沉浸式的深色介面。對話是主角，其他資訊退到邊上；淺色系統會自動切換配色。 */
:root {
  color-scheme: dark;
  --bg: #0a0c11;
  --solid: #12151c;
  --solid-2: #181c25;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.18);
  --text: #e9ebf1;
  --muted: #a1a9ba;
  --faint: #7c8496;
  --codex: #74bdff;
  --claude: #f2a57c;
  --mock: #b8a6ff;
  --ok: #5fd39a;
  --warn: #f1c35f;
  --bad: #ff8585;
  --accent: #9db4ff;
  --on-accent: #0a0c11;
  --glow: #5b7cff;
  --code: rgba(0, 0, 0, 0.32);
  --radius: 14px;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Noto Sans Mono CJK TC', monospace;
  --font: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f5f9;
    --solid: #ffffff;
    --solid-2: #f0f2f7;
    --panel: rgba(16, 24, 40, 0.035);
    --panel-2: rgba(16, 24, 40, 0.07);
    --line: rgba(16, 24, 40, 0.1);
    --line-2: rgba(16, 24, 40, 0.22);
    --text: #161a22;
    --muted: #535b6c;
    --faint: #6f7788;
    --codex: #1668c4;
    --claude: #b9541f;
    --mock: #6a4fd6;
    --ok: #15803d;
    --warn: #a16207;
    --bad: #c62828;
    --accent: #3b5bdb;
    --on-accent: #ffffff;
    --glow: #7b93ff;
    --code: rgba(16, 24, 40, 0.06);
  }
}
body[data-engine='codex'] { --accent: var(--codex); --glow: var(--codex); }
body[data-engine='claude'] { --accent: var(--claude); --glow: var(--claude); }
body[data-engine='mock'] { --accent: var(--mock); --glow: var(--mock); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.6 var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
/* 環境光：顏色跟著目前任務的引擎變化 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 560px at 88% -12%, color-mix(in srgb, var(--glow) 20%, transparent), transparent 70%),
    radial-gradient(720px 520px at -8% 108%, color-mix(in srgb, var(--glow) 10%, transparent), transparent 70%);
}
.hidden { display: none !important; }
.spacer { flex: 1; }
.icon { flex: none; }
h1, h2, h3, p { margin: 0; }
code, pre { font-family: var(--mono); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 基本元件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 550; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 86%, var(--text)); border-color: transparent; }
.btn.danger { background: color-mix(in srgb, var(--bad) 14%, transparent); border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.round { width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; }
.link:hover { text-decoration: underline; }
.hint { color: var(--faint); font-size: 13px; }
.pad { padding: 12px 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); white-space: nowrap;
}
button.pill { padding: 5px 12px; }
.tone-ok { color: var(--ok); }
.tone-warn, .pill.warn { color: var(--warn); }
.tone-bad { color: var(--bad); }
.tone-run { color: var(--accent); }
.tone-idle { color: var(--muted); }
.pill.tone-ok, .pill.tone-warn, .pill.warn, .pill.tone-bad, .pill.tone-run { border-color: color-mix(in srgb, currentColor 40%, transparent); background: color-mix(in srgb, currentColor 10%, transparent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.dot.tone-run { animation: breathe 1.4s ease-in-out infinite; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; font-size: 13px; color: var(--muted);
}
button.chip.on { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 14px 16px; }
.spin {
  width: 14px; height: 14px; flex: none; border-radius: 50%; display: inline-block;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 14px; font-weight: 700; color: #0a0c11; user-select: none;
}
.avatar.small { width: 22px; height: 22px; font-size: 11px; }
.avatar.hue-0 { background: #8fd3ff; } .avatar.hue-1 { background: #ffc48f; } .avatar.hue-2 { background: #a5e8b4; }
.avatar.hue-3 { background: #f4a6d3; } .avatar.hue-4 { background: #cdb8ff; } .avatar.hue-5 { background: #f3e08a; }
.avatar.engine-codex { background: linear-gradient(135deg, #9fd4ff, #4d8dff); border-radius: 10px; }
.avatar.engine-claude { background: linear-gradient(135deg, #ffc9a3, #e2733f); border-radius: 10px; }
.avatar.engine-mock { background: linear-gradient(135deg, #d6caff, #8d74f0); border-radius: 10px; }
.avatar.small[class*='engine-'] { border-radius: 7px; }
.avatar.chat { background: var(--panel-2); color: var(--text); border-radius: 10px; border: 1px solid var(--line); }
.avatar.pulse { animation: halo 1.6s ease-out infinite; }
.avatar.online { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ok); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
select option { background: var(--solid); color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- 存取碼畫面 ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.gate-card { width: min(420px, 100%); display: grid; gap: 14px; text-align: center; justify-items: center; }
.gate-card h1 { font-size: 26px; }
.gate-card p { color: var(--muted); }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background: conic-gradient(from 210deg, var(--codex), var(--claude), var(--codex));
}
.gate-card .brand-mark { width: 44px; height: 44px; border-radius: 14px; }

/* ---------- 版面 ---------- */
.app { display: grid; grid-template-columns: 284px minmax(0, 1fr); height: 100dvh; transition: grid-template-columns 0.2s; }
body.rail-collapsed .app, body.focus .app { grid-template-columns: 0 minmax(0, 1fr); }
body.rail-collapsed .rail, body.focus .rail { visibility: hidden; }
.rail {
  display: flex; flex-direction: column; gap: 12px; padding: 14px 12px; min-height: 0; overflow: hidden;
  border-right: 1px solid var(--line); background: color-mix(in srgb, var(--solid) 70%, transparent);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; font-weight: 700; font-size: 16px; padding: 4px 6px; border-radius: 8px; }
.project-row { display: flex; gap: 6px; align-items: center; }
.project-row select { padding: 7px 10px; }
.task-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.group-title { font-size: 12px; color: var(--faint); padding: 10px 8px 4px; letter-spacing: 0.04em; }
.task-item {
  display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%;
  padding: 9px 10px; border: 1px solid transparent; border-radius: 11px; background: transparent;
}
.task-item .dot { margin-top: 8px; }
.task-item:hover { background: var(--panel); }
.task-item.selected { background: var(--panel-2); border-color: var(--line); }
.task-item.unread .task-title { font-weight: 750; }
.task-item.unread .task-meta { color: var(--accent); }
.task-text { display: grid; min-width: 0; }
.task-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-meta { font-size: 12px; color: var(--faint); font-weight: 400; }
.rail-foot { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.foot-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; min-width: 0;
  background: none; border: 0; padding: 7px 8px; border-radius: 9px; color: var(--muted); font-size: 13px;
}
.foot-row:hover { background: var(--panel); color: var(--text); }
.foot-text { display: flex; gap: 10px; flex-wrap: wrap; min-width: 0; overflow: hidden; }
.engine-chip { display: inline-flex; align-items: center; gap: 6px; }
.me-text { display: grid; min-width: 0; line-height: 1.35; color: var(--text); }
.me-text .task-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; min-height: 50px; }
.topbar-title { font-weight: 600; color: var(--muted); }
.presence { display: flex; gap: 6px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.conn.online i { background: var(--ok); }
.conn.offline i { background: var(--bad); }

/* ---------- 首頁 ---------- */
.home { flex: 1; overflow-y: auto; padding: clamp(24px, 9vh, 96px) 20px 48px; }
.hero { width: min(780px, 100%); margin: 0 auto; display: grid; gap: 18px; }
.hero h1 { font-size: clamp(26px, 4.2vw, 40px); line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.hero-sub { color: var(--muted); max-width: 60ch; }
.hero-composer {
  display: grid; gap: 10px; padding: 16px; border-radius: 22px;
  border: 1px solid var(--line-2); background: color-mix(in srgb, var(--solid) 82%, transparent);
  box-shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.7); transition: border-color 0.2s, box-shadow 0.2s;
}
.hero-composer:focus-within { border-color: var(--accent); box-shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.7), 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }
.hero-composer > textarea { border: 0; background: transparent; resize: none; font-size: 17px; line-height: 1.6; min-height: 104px; padding: 4px 6px; }
.hero-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.seg-btn { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg-btn.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg-btn.on.engine-codex { color: var(--codex); } .seg-btn.on.engine-claude { color: var(--claude); } .seg-btn.on.engine-mock { color: var(--mock); }
.btn.go { padding: 9px 18px; border-radius: 12px; margin-left: auto; }
.adv { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.adv .check { align-self: end; padding-bottom: 9px; }
.notice { display: flex; gap: 14px; align-items: flex-start; text-align: left; width: 100%; }
.notice p { color: var(--muted); margin: 2px 0 10px; }
.notice > .icon { margin-top: 3px; color: var(--accent); }
button.notice p { margin-bottom: 0; }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 7%, transparent); }
.notice.warn > .icon { color: var(--warn); }
.section-title { font-size: 13px; font-weight: 600; color: var(--faint); letter-spacing: 0.04em; margin: 14px 0 10px; }
.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.recent-card { display: grid; gap: 6px; text-align: left; transition: border-color 0.15s, transform 0.15s; }
.recent-card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.recent-card strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 600; }
.recent-top { display: flex; align-items: center; justify-content: space-between; }

/* ---------- 任務畫面 ---------- */
.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage-head { display: grid; gap: 12px; padding: 0 18px 14px; }
.title-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-wrap { min-width: 0; flex: 1; }
.title-wrap h2 { font-size: 19px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-meta { font-size: 12.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-meta code { color: var(--muted); }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: 40px; z-index: 20; min-width: 230px; padding: 6px; display: grid;
  background: var(--solid-2); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}
.menu-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; }
.menu-item:hover { background: var(--panel-2); }
.menu-item.danger { color: var(--bad); }

.pipeline { display: flex; list-style: none; margin: 0; padding: 0 4px; }
.pipeline li { display: flex; align-items: center; gap: 8px; flex: 1; color: var(--faint); font-size: 13px; white-space: nowrap; }
.pipeline li::after { content: ''; flex: 1; height: 1px; background: var(--line); margin: 0 12px; }
.pipeline li:last-child { flex: 0; }
.pipeline li:last-child::after { display: none; }
.step-dot { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line-2); display: grid; place-items: center; flex: none; }
.pipeline li.done { color: var(--muted); }
.pipeline li.done .step-dot { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.pipeline li.done::after { background: color-mix(in srgb, var(--ok) 55%, transparent); }
.pipeline li.current { color: var(--text); font-weight: 650; }
.pipeline li.current .step-dot { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.pipeline li.current.busy .step-dot { animation: halo 1.6s ease-out infinite; }

.next {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 10px 10px 16px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
}
.next.tone-warn { border-color: color-mix(in srgb, var(--warn) 50%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.next.tone-bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 7%, transparent); }
.next.tone-ok { border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.next-text { display: flex; align-items: center; gap: 10px; flex: 1 1 260px; min-width: 0; font-weight: 550; }
.next-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.mobile-tabs { display: none; }
.tab { padding: 7px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--panel-2); color: var(--text); }

.stage-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); border-top: 1px solid var(--line); }
body.focus .stage-body, .stage-body.single { grid-template-columns: minmax(0, 1fr); }
body.focus .col.side { display: none; }
.col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.col.side { border-left: 1px solid var(--line); background: color-mix(in srgb, var(--solid) 55%, transparent); }
.timeline { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 18px 10px; overscroll-behavior: contain; }
.log { display: flex; flex-direction: column; gap: 12px; width: min(820px, 100%); margin: 0 auto; }
.enter { animation: rise 0.22s ease-out; }

.msg { display: flex; gap: 10px; align-items: flex-start; }
.bubble { min-width: 0; max-width: min(620px, 86%); padding: 8px 14px 10px; border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; background: var(--panel); }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .bubble { border-radius: 16px 4px 16px 16px; background: color-mix(in srgb, var(--accent) 15%, var(--solid)); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.msg.note .bubble { border-style: dashed; background: color-mix(in srgb, var(--warn) 7%, transparent); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.msg.agent .bubble { flex: 1; max-width: none; padding: 3px 0 0; border: 0; background: none; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.when { font-weight: 400; color: var(--faint); }
.msg.agent.engine-codex .who { color: var(--codex); } .msg.agent.engine-claude .who { color: var(--claude); } .msg.agent.engine-mock .who { color: var(--mock); }
.text, .md { white-space: pre-wrap; overflow-wrap: anywhere; }
.md .h { display: block; font-weight: 700; font-size: 1.04em; margin-top: 4px; }
.md code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
.md pre { margin: 6px 0; padding: 10px 12px; background: var(--code); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; font-size: 13px; white-space: pre; }
.md.streaming::after { content: '▍'; color: var(--accent); animation: blink 1s steps(2) infinite; }

.act, .cmd, .approval, .relay, .diff-card { margin-left: 42px; }
.act { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--muted); }
.act code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--faint); }
.cmd { border: 1px solid var(--line); border-radius: 10px; background: var(--code); font-size: 13px; overflow: hidden; }
.cmd summary { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; list-style: none; }
.cmd summary::-webkit-details-marker { display: none; }
.cmd summary code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd .prompt { color: var(--accent); font-family: var(--mono); }
.cmd .exit { font-size: 12px; }
.cmd .exit.ok { color: var(--ok); } .cmd .exit.bad { color: var(--bad); }
.cmd pre { margin: 0; padding: 8px 12px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; color: var(--muted); }
.relay { border: 1px dashed var(--line-2); border-radius: 10px; font-size: 13px; }
.relay summary { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; color: var(--muted); }
.relay .md { padding: 4px 12px 12px; max-height: 360px; overflow: auto; }
.diff-card {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.diff-card:hover { border-color: var(--line-2); }
.diff-card > span:nth-of-type(1) { display: grid; flex: 1; min-width: 0; }
.divider { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--faint); }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.sys { text-align: center; font-size: 13px; color: var(--muted); }
.sys.error { text-align: left; color: var(--bad); padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 9%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); white-space: pre-wrap; overflow-wrap: anywhere; }
.approval {
  display: grid; gap: 10px; padding: 14px 16px; border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--warn) 60%, transparent); background: color-mix(in srgb, var(--warn) 9%, var(--solid));
  box-shadow: 0 12px 40px -24px var(--warn);
}
.approval-head { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--warn); }
.approval pre { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--code); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; max-height: 240px; overflow: auto; }
.approval-actions { display: flex; gap: 8px; align-items: center; }
.approval.resolved { border-color: var(--line); background: var(--panel); box-shadow: none; }
.approval.resolved .approval-head { color: var(--muted); }
.approval.flash { animation: flash 0.9s ease-in-out 2; }

.working { display: flex; align-items: center; gap: 10px; width: min(820px, 100%); margin: 12px auto 0; font-size: 13px; color: var(--muted); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; } .typing i:nth-child(3) { animation-delay: 0.3s; }

.composer {
  display: flex; align-items: flex-end; gap: 6px; width: min(820px, calc(100% - 28px)); margin: 6px auto 0; padding: 7px 7px 7px 16px;
  border: 1px solid var(--line-2); border-radius: 24px; background: var(--solid); transition: border-color 0.2s, box-shadow 0.2s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; padding: 7px 0; max-height: 200px; }
.composer.done { justify-content: space-between; align-items: center; padding: 10px 10px 10px 18px; color: var(--muted); }
.composer-hint { text-align: center; font-size: 12px; color: var(--faint); padding: 6px 12px 10px; }

.side-tabs { display: flex; gap: 4px; padding: 10px 12px 8px; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.side-bar { display: flex; align-items: center; gap: 8px; padding: 6px 14px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.rounds { display: flex; gap: 6px; padding: 0 14px 8px; flex-wrap: wrap; }
.empty { margin: auto; padding: 32px 28px; max-width: 380px; display: grid; gap: 10px; justify-items: center; text-align: center; color: var(--muted); }
.empty strong { color: var(--text); font-size: 16px; }
.empty > .icon { color: var(--faint); }
.diff-view { flex: 1; min-height: 0; overflow-y: auto; }
.file { border-bottom: 1px solid var(--line); }
.file summary { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; position: sticky; top: 0; background: var(--solid); z-index: 1; font-size: 13px; }
.file summary code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file .add { color: var(--ok); } .file .del { color: var(--bad); }
.file pre { margin: 0; padding: 4px 0 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; }
.line { display: block; width: max-content; min-width: 100%; padding: 0 14px; white-space: pre; }
.line.add { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--text); }
.line.del { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--text); }
.line.hunk { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---------- 對話框與通知 ---------- */
dialog {
  width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0; color: var(--text);
  border: 1px solid var(--line-2); border-radius: 20px; background: var(--solid); box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.8);
}
dialog::backdrop { background: rgba(4, 6, 10, 0.6); backdrop-filter: blur(6px); }
.modal-body, .modal-body > form, .invite { display: grid; gap: 14px; }
.modal-body { padding: 24px; }
.modal-body h2 { font-size: 20px; }
.modal-body h3 { font-size: 15px; }
.modal-text { color: var(--muted); }
.modal-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.engine-card { display: grid; gap: 8px; }
.engine-card p { color: var(--muted); font-size: 14px; }
.engine-top { display: flex; align-items: center; gap: 12px; }
.cmdline { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 10px; background: var(--code); border: 1px solid var(--line); }
.cmdline code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.member { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.member-info { flex: 1; min-width: 180px; display: grid; gap: 4px; }
.invite { border-top: 1px solid var(--line); padding-top: 16px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: 12px; background: var(--solid-2); border: 1px solid var(--line-2); box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.6); animation: rise 0.2s ease-out; max-width: min(520px, 90vw); }
.toast.error { border-color: color-mix(in srgb, var(--bad) 60%, transparent); color: var(--bad); }

.install {
  position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: flex-start; gap: 12px; padding: 14px; max-width: 520px; margin: 0 auto;
  border: 1px solid var(--line-2); border-radius: 18px; background: var(--solid-2); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
}
.install img { border-radius: 11px; flex: none; }
.install-text { flex: 1; min-width: 0; display: grid; gap: 4px; }
.install ol { margin: 2px 0; padding-left: 20px; color: var(--muted); font-size: 14px; }

.only-mobile { display: none; }

/* ---------- 手機與窄視窗：一次只看一欄 ---------- */
@media (max-width: 900px) {
  .app, body.rail-collapsed .app, body.focus .app { grid-template-columns: minmax(0, 1fr); }
  .rail, body.rail-collapsed .rail, body.focus .rail {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(320px, 86vw); visibility: visible;
    background: var(--solid); transform: translateX(-102%); transition: transform 0.22s ease-out;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  body.rail-open .rail { transform: none; }
  body.rail-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(4, 6, 10, 0.55); }
  .only-mobile { display: inline-grid; }
  .only-desktop { display: none !important; }
  .stage-head { padding: 0 12px 10px; gap: 10px; }
  .title-wrap h2 { font-size: 17px; }
  .pipeline li { font-size: 12px; gap: 6px; }
  .pipeline li::after { margin: 0 6px; }
  .next { padding: 10px 12px; }
  .next-actions { width: 100%; justify-content: stretch; }
  .next-actions .btn { flex: 1; }
  .mobile-tabs { display: flex; gap: 4px; padding: 0 10px 8px; }
  .mobile-tabs .tab { flex: 1; }
  .stage-body { grid-template-columns: minmax(0, 1fr); }
  .stage-body[data-tab='chat'] .col.side, .stage-body:not([data-tab='chat']) .col.chat { display: none; }
  .col.side { border-left: 0; }
  .side-tabs { display: none; }
  .timeline { padding: 14px 12px 8px; }
  .act, .cmd, .approval, .relay, .diff-card { margin-left: 0; }
  .bubble { max-width: 88%; }
  .composer { margin-bottom: max(0px, env(safe-area-inset-bottom)); }
  .home { padding: 20px 14px 40px; }
  .hero-composer > textarea { font-size: 16px; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes breathe { 50% { opacity: 0.35; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes halo { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes flash { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--warn) 35%, transparent); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
