/* AgentPilot · A · 白（暖纸 / 墨 / 朱砂 / 宋体）
   token 与 design/DESIGN-DIRECTIONS.md、design/chat-v4/prototype.html 一致。
   反 slop：不用渐变、不用阴影、不用 emoji 图标、不用彩色胶囊。 */

:root {
  --paper: #F6F1E8;
  --surface: #FBF8F2;
  --surface2: #EFE7D9;
  --ink: #1D1A16;
  --ink2: #4A4236;
  --muted: #8A7F6E;
  --seal: #B23A26;
  --moss: #4F5B45;
  --gold: #B4862B;
  --border: #DCD2C2;
  --hair: #E7DED0;

  /* 兼容旧类名：全部指向暖色 token */
  --bg: var(--paper);
  --bg-soft: var(--surface2);
  --card: var(--surface);
  --card-2: var(--surface2);
  --line: var(--border);
  --text: var(--ink);
  --accent: var(--ink);
  --accent-2: var(--ink);
  --green: var(--moss);
  --red: var(--seal);
  --amber: var(--gold);

  --radius: 14px;
  --serif: "Songti SC", "STSong", serif;
  --sans: "PingFang SC", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  overflow-x: hidden;
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  overscroll-behavior-y: contain;
}
h1, h3, .card h3, .topbar-title, .greet, .brand-mark { font-family: var(--serif); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }

/* ── 登录 ── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: var(--paper);
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo { display: block; width: 68px; height: 68px; margin: 0 auto 10px; }
.login-card h1 { margin: 8px 0 6px; font-size: 26px; font-weight: 600; letter-spacing: .04em; }
.login-card form { margin-top: 22px; display: grid; gap: 12px; }
.login-card input {
  width: 100%; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 16px;
}
.login-card input:focus { outline: none; border-color: #C8B9A3; }
.err { color: var(--seal); min-height: 20px; font-size: 14px; margin: 10px 0 0; }

/* ── 按钮：墨色实底，无渐变 ── */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 12px 18px; border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity .15s ease;
}
.btn:active { opacity: .7; }
.btn.primary { background: var(--ink); border: 1px solid var(--ink); color: var(--paper); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 9px; }
.btn.tiny { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .4; }
.x {
  border: none; background: transparent; color: var(--muted);
  font-size: 18px; padding: 6px 10px; cursor: pointer;
}

/* ── 框架 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--hair);
}
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border: 1px solid var(--seal); color: var(--seal); font-size: 13px; line-height: 1;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--moss); }
.dot.bad { background: var(--seal); }

#main { padding: 12px 14px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.view { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; border-bottom: 1px solid var(--hair); }
.row:last-child { border-bottom: none; }
.row span { color: var(--muted); }
.row b { font-weight: 600; text-align: right; word-break: break-all; }

/* ── 任务列表 ── */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.task-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; cursor: pointer; transition: border-color .15s;
}
.task-card:active { border-color: var(--ink2); }
.task-card.running { border-color: var(--seal); }
.tc-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tc-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-sub { margin-top: 6px; color: var(--muted); font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tc-snippet {
  margin-top: 8px; color: var(--ink2); font-size: 13px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pill {
  font-size: 11.5px; padding: 3px 9px; border-radius: 4px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface2);
}
.pill.running { color: var(--seal); border-color: rgba(178,58,38,.45); background: rgba(178,58,38,.07); animation: pulse 1.4s infinite; }
.pill.done { color: var(--moss); border-color: rgba(79,91,69,.4); background: rgba(79,91,69,.08); }
.pill.failed { color: var(--seal); border-color: rgba(178,58,38,.4); background: rgba(178,58,38,.08); }
.pill.cancelled { color: var(--gold); border-color: rgba(180,134,43,.4); background: rgba(180,134,43,.10); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }

.empty { text-align: center; padding: 64px 20px; }
.empty-icon { font-family: var(--serif); font-size: 34px; color: var(--seal); margin-bottom: 10px; }

/* ── chips / crumbs ── */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.chip {
  padding: 8px 14px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border);
  font-size: 13.5px; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.crumbs {
  font-size: 13px; color: var(--muted); margin: 4px 0 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

/* ── 文件列表 ── */
.file-row {
  display: flex; min-width: 0; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}
.file-row:active { border-color: var(--ink2); }
.fr-icon { font-family: var(--serif); font-size: 15px; width: 22px; text-align: center; color: var(--muted); }
.fr-name { flex: 1; min-width: 0; font-size: 14.5px; word-break: break-all; }
.fr-meta { color: var(--muted); font-size: 12px; }

/* ── 底部导航：编号 01–04，不用 emoji ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: var(--paper);
  border-top: 1px solid var(--hair);
}
.tab {
  flex: 1; display: grid; gap: 2px; justify-items: center; padding: 6px 0;
  background: transparent; border: none; color: var(--muted); font-size: 11px; cursor: pointer;
}
.tab span { font-family: var(--serif); font-size: 12px; letter-spacing: .08em; }
.tab.active { color: var(--ink); }
.tab.active span { color: var(--seal); }

/* 新任务：唯一的朱砂实心块 */
.fab {
  position: fixed; right: 18px; bottom: calc(80px + var(--safe-b)); z-index: 31;
  width: 52px; height: 52px; border-radius: 6px; border: none; cursor: pointer;
  background: var(--seal); color: var(--paper);
  font-size: 26px; line-height: 1;
}
.fab:active { opacity: .8; }

/* ── 抽屉 ── */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(29,26,22,.42); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--paper); border: 1px solid var(--border); border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(18px + var(--safe-b));
  max-height: 88vh; overflow-y: auto; animation: up .22s ease;
}
.sheet-panel.full { top: 6vh; bottom: 0; max-height: none; display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(4%) } to { transform: none } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.head-left { display: flex; align-items: center; gap: 4px; }

.log {
  flex: 1; overflow-y: auto; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  display: flex; flex-direction: column; gap: 8px; color: var(--ink2);
}
.ev { white-space: pre-wrap; word-break: break-word; }
.ev.agent { color: var(--ink); }
.ev.think { color: var(--muted); font-style: italic; }
.ev.tool { color: var(--ink2); }
.ev.tool pre { color: var(--muted); margin-top: 4px; font-size: 11.5px; max-height: 120px; overflow: hidden; }
.ev.logline, .ev.stderr, .ev.statusline { color: var(--muted); }
.ev.error { color: var(--seal); }
.ev.usage { color: var(--moss); font-size: 11.5px; }
.task-meta { display: flex; gap: 14px; margin-bottom: 8px; }

.result-wrap { margin-top: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.result-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.result { font-size: 13.5px; line-height: 1.65; color: var(--ink); max-height: 34vh; overflow-y: auto; }

.sheet-foot { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.reply-row { display: flex; gap: 8px; flex: 1; }
.reply-row input, .inline-form input {
  flex: 1; min-width: 0; padding: 11px 13px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 14px;
}
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.ws-list { display: grid; gap: 6px; }
.ws-item {
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink2);
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
  word-break: break-all;
}

.field { display: grid; gap: 6px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
select, textarea {
  width: 100%; padding: 12px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 14.5px; font-family: inherit;
}
textarea { resize: vertical; min-height: 110px; }
.preview { flex: 1; overflow: auto; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-b));
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
  padding: 10px 16px; border-radius: 8px; font-size: 13.5px; z-index: 60;
}
.toast.err { border-color: var(--seal); }

/* ── v2：一句话派活 ── */
#main { padding-bottom: calc(210px + var(--safe-b)); }

.composer {
  position: fixed; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); z-index: 29;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; max-width: 720px; margin: 0 auto;
  background: var(--paper);
  border-top: 1px solid var(--hair);
}
.composer textarea {
  flex: 1; min-width: 0; min-height: 42px; max-height: 140px; resize: none;
  padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 15px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { outline: none; border-color: #C8B9A3; }
.send {
  width: 42px; height: 42px; flex: none; border-radius: 50%; border: none; cursor: pointer;
  background: var(--ink); color: var(--paper);
  font-size: 18px; font-weight: 700;
}
.send:disabled { opacity: .35; }
.send:active { opacity: .8; }

.route-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; margin-bottom: 10px;
}
.route-line { min-width: 0; font-size: 12.5px; line-height: 1.5; }
.route-label { color: var(--seal); font-size: 12px; margin-right: 6px; white-space: nowrap; }
.route-text { color: var(--ink); }
#route-correct { flex: none; }

.task-usage { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); margin: -4px 0 10px; }

.confirm-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(180,134,43,.10); border: 1px solid rgba(180,134,43,.45);
  border-radius: 10px; padding: 9px 12px; margin-bottom: 10px; font-size: 13px; color: var(--ink2);
}

.changes {
  margin-top: 10px; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; background: var(--surface);
}
.changes summary { font-size: 13.5px; cursor: pointer; }
.changes-list {
  max-height: 180px; overflow: auto; margin: 8px 0;
  display: flex; flex-direction: column; gap: 3px;
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.change-item.created { color: var(--moss); }
.change-item.deleted { color: var(--seal); }
.change-item.modified { color: var(--gold); }
.btn.danger { border-color: rgba(178,58,38,.5); color: var(--seal); }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 0; font-size: 14px;
}
.switch {
  appearance: none; width: 46px; height: 27px; border-radius: 999px;
  background: var(--surface2); border: 1px solid var(--border); position: relative; cursor: pointer; flex: none;
}
.switch:checked { background: var(--ink); border-color: var(--ink); }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: var(--paper); transition: transform .18s;
}
.switch:checked::after { transform: translateX(19px); }

.rule-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-top: 6px;
}
.rule-text { font-size: 12.5px; color: var(--ink2); word-break: break-all; }

.pill.confirming {
  color: var(--gold); border-color: rgba(180,134,43,.5);
  background: rgba(180,134,43,.12);
}

/* 用量：表格化，不用卡片套卡片 */
.usage-grid { display: grid; gap: 0; }
.usage-grid .row:first-child { border-top: 1px solid var(--hair); }
.usage-num { font-family: var(--serif); font-size: 18px; font-weight: 600; }
