:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #5b6370;
  --line: #e6e7eb;
  --accent: #6d4aff;
  --accent-soft: #efeaff;
  --accent-fill: #6d4aff;
  --ok: #15803d;
  --ok-soft: #e8f6ee;
  --bad: #c2410c;
  --bad-soft: #fff1e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1013;
    --panel: #17191e;
    --text: #e8e9ec;
    --muted: #9097a3;
    --line: #2a2d35;
    --accent: #a28bff;
    --accent-soft: #241d3d;
    --accent-fill: #6d4aff;
    --ok: #4ade80;
    --ok-soft: #13261b;
    --bad: #fb923c;
    --bad-soft: #2b1b10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--accent-soft); padding: 2px 6px; border-radius: 5px; }

.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 650; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo { color: var(--accent); }
.top-mid { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.proj-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-right { display: flex; gap: 8px; align-items: center; }
select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 220px; }

.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.btn { font: inherit; font-weight: 550; border-radius: 9px; padding: 8px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost:hover { background: var(--bg); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }

/* start screen */
.start { flex: 1; overflow: auto; display: flex; justify-content: center; padding: 8vh 16px 40px; background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent); }
.hero { width: 100%; max-width: 720px; }
.hero h1 { font-size: clamp(26px, 4vw, 38px); letter-spacing: -.02em; margin: 0 0 8px; text-align: center; }
.hero > p { text-align: center; margin: 0 auto 24px; max-width: 560px; }
.start-form { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; }
.start-form textarea { width: 100%; border: 0; outline: 0; resize: vertical; font: inherit; font-size: 15px; background: transparent; color: var(--text); min-height: 110px; }
.start-row { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); border-radius: 99px; padding: 4px 12px; cursor: pointer; }
.chip:hover { color: var(--text); }
.recent { margin-top: 36px; }
.recent h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recent a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--text); text-decoration: none; }
.recent a:hover { border-color: var(--accent); }

/* workspace */
.work { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 430px) 1fr; }
.tabs { display: none; }
.left { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel); }
.right { min-height: 0; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

.progress { padding: 12px 16px 10px; border-bottom: 1px solid var(--line); }
.steps { list-style: none; margin: 0 0 10px; padding: 0; display: flex; gap: 3px; flex-wrap: wrap; }
.steps li { font-size: 11px; padding: 3px 9px; border-radius: 99px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); }
.steps li.done { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.steps li.now { color: #fff; background: var(--accent-fill); border-color: var(--accent-fill); }
.bar { height: 6px; border-radius: 99px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.fill { height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .4s; }
.progress-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: 12.5px; }
.activity { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.counts { font: inherit; color: var(--muted); white-space: nowrap; background: none; border: 0; padding: 0; }
.counts.has-plan { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.counts.has-plan:hover, .counts[aria-expanded="true"] { color: var(--text); }

.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.avatar { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.msg .body { min-width: 0; flex: 1; }
.msg .who { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.msg .who b { color: var(--text); font-weight: 600; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { flex-direction: row-reverse; }
.msg.user .body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .text { background: var(--accent-fill); color: #fff; padding: 8px 12px; border-radius: 14px 14px 4px 14px; max-width: 92%; }
.msg.user .who { justify-content: flex-end; }
.msg.done .text { color: var(--ok); }
.msg.error .text { color: var(--bad); }
.msg.question .text { background: var(--accent-soft); padding: 10px 12px; border-radius: 4px 14px 14px 14px; }
.msg details { margin-top: 4px; }
.msg summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.msg pre { white-space: pre-wrap; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 360px; overflow: auto; }
.compact .text { font-size: 13px; }

.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: grid; gap: 8px; }
.to-row, .busy-row, .interview-row { display: flex; align-items: center; gap: 8px; }
.busy-row { font-size: 13px; color: var(--muted); }
.busy-row .btn { margin-left: auto; }
#busyText { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); }
.seg button { font: inherit; font-size: 12.5px; border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; resize: none; max-height: 160px; }
.input-row textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.browser { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.chrome { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.icon { font: inherit; font-size: 15px; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; text-decoration: none; }
.icon:hover { background: var(--bg); color: var(--text); }
.addr { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; margin: 0 6px; }
.addr input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.lock { color: var(--ok); font-size: 9px; }
.frame-wrap { flex: 1; position: relative; background: #fff; }
.frame-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.frame-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: var(--panel); }
.frame-empty b { display: block; font-size: 16px; margin-bottom: 4px; }
.hint { padding: 6px 12px; border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand .muted, .top-right .btn { display: none; }
  .work { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .tabs { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .tab { flex: 1; font: inherit; border: 0; padding: 6px; border-radius: 8px; background: transparent; color: var(--muted); }
  .tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .left, .right { grid-row: 2; grid-column: 1; }
  .work[data-tab="chat"] .right, .work[data-tab="preview"] .left { display: none; }
  .right { padding: 8px; }
  .left { border-right: 0; }
}
.msg.info .text { color: var(--muted); }
.text.clickable { cursor: pointer; }
.text.clickable:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
.prompt .sessions { display: grid; gap: 10px; margin-top: 6px; }
.session-head { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.session pre { margin: 0; }
.session details { margin-top: 4px; }
.session details summary { color: var(--muted); }

/* start: review the plan first */
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); cursor: pointer; }
.check-row input { accent-color: var(--accent-fill); width: 15px; height: 15px; margin: 0; }

/* the plan's tasks, under the progress bar */
.plan-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 42vh; overflow-y: auto; display: grid; gap: 6px; }
.plan-task { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg); }
.plan-head { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.plan-head .owner { color: var(--muted); }
.plan-head .tstatus { margin-left: auto; font-size: 11.5px; padding: 3px 9px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.plan-task.running .tstatus { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.plan-task.done .tstatus { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.plan-task.failed .tstatus { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.plan-task .ttext { font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
.plan-task .tcheck { display: block; margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11.5px; }

/* the review pause */
.review-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.review-row span { margin-right: auto; }

/* each task's steps, under its chat line */
.msg details.task-steps summary { color: var(--muted); }
.step-list { list-style: none; margin: 6px 0 0; padding: 4px 0 4px 12px; border-left: 2px solid var(--line); display: grid; gap: 3px; font-size: 12.5px; }
.step { overflow-wrap: anywhere; }
.step > details { margin: 0; }
.step > details > summary { color: inherit; font-size: inherit; }
.step pre { margin: 4px 0; }
.step-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.step-result { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.step.error .step-text, .step.error .step-result { color: var(--bad); }
.step.fail { color: var(--bad); font-weight: 600; }
.step.fail .step-result { color: var(--bad); font-weight: 400; }
.step.ok { color: var(--ok); font-weight: 600; }
.step.note .step-text { color: var(--muted); font-style: italic; }

/* the right panel: preview or files */
.view-tabs { flex: none; display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--panel); }
.view-tabs button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--muted); padding: 5px 14px; border-radius: 7px; cursor: pointer; }
.view-tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.browser, .files { min-height: 0; }
.files { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(180px, 240px) 1fr; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.file-tree { border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 0; }
.file-tree > p { padding: 0 12px; }
.tree-group { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px 4px; }
.tree-dir { font-size: 12.5px; color: var(--muted); padding: 3px 12px; }
.tree-file { display: block; width: 100%; text-align: left; font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); background: none; border: 0; padding: 4px 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-file:hover { background: var(--bg); }
.tree-file.active { background: var(--accent-soft); color: var(--accent); }
.file-view { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.file-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 46px; }
.file-path { font: 600 13px ui-monospace, SFMono-Regular, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-head .muted { margin-right: auto; }
.file-error { margin: 0; padding: 8px 12px; background: var(--bad-soft); }
.file-text, .file-edit { flex: 1; min-height: 0; margin: 0; overflow: auto; padding: 12px 16px; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); background: var(--panel); }
.file-edit { border: 0; outline: 0; resize: none; }
.file-edit:focus { box-shadow: inset 0 0 0 2px var(--accent-soft); }

@media (max-width: 860px) {
  .files { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .file-tree { max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
}
