:root {
  --paper: #f6f4ef;
  --panel: #fffefb;
  --ink: #1d1d1b;
  --ink-2: #55534d;
  --ink-3: #8a877f;
  --line: #e2ded4;
  --line-2: #cfcabd;
  --accent: #c8452c;
  --accent-soft: #f6e3dd;
  --ok: #2f7d55;
  --ok-soft: #e1f0e7;
  --warn: #a5650c;
  --warn-soft: #f8ebd5;
  --blue: #2b5c8a;
  --blue-soft: #e3ecf5;
  --radius: 8px;
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--paper);
  font-size: 15px; line-height: 1.65;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px; background-position: -1px -1px;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.hidden { display: none !important; }

/* —— 顶栏 —— */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 20px; background: var(--ink); color: #f3f1ea;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.brand-mark i { background: #f3f1ea; border-radius: 2px; }
.brand-mark i:nth-child(2) { background: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav button {
  background: none; border: 0; color: #bdb9ae; padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.nav button.on { color: #fff; background: rgba(255,255,255,.12); }
.nav button:hover { color: #fff; }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; white-space: nowrap; }
.me button { background: none; border: 1px solid #55534d; color: #e7e4db; border-radius: 6px; padding: 3px 10px; cursor: pointer; font-size: 13px; }
.region { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #3a3936; color: #e7e4db; }

/* —— 通用 —— */
.page { max-width: 1240px; margin: 0 auto; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.btn {
  border: 1px solid var(--line-2); background: var(--panel); padding: 7px 14px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.danger { color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.muted { color: var(--ink-3); font-size: 13px; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.pending { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip.verified { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.question { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip.model { font-family: var(--mono); font-size: 11px; background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.error-text { color: var(--accent); font-size: 13px; min-height: 1em; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 100; max-width: 90vw;
}

/* —— 登录 —— */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; padding: 32px; }
.login h1 { font-size: 20px; margin: 16px 0 4px; }
.login p { margin: 0 0 24px; }

/* —— 工作台 —— */
.workbench { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - 56px - 40px); }
.side { display: flex; flex-direction: column; overflow: hidden; }
.side h3 { font-size: 12px; letter-spacing: .08em; color: var(--ink-3); font-weight: 500; margin: 14px 16px 6px; }
.agent-list { padding: 0 8px; }
.agent {
  display: block; width: 100%; text-align: left; border: 1px solid transparent; background: none; border-radius: 6px;
  padding: 8px 10px; cursor: pointer; margin-bottom: 2px;
}
.agent:hover { background: var(--paper); }
.agent.on { background: var(--paper); border-color: var(--line-2); }
.agent b { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.agent b::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--line-2); flex: none; }
.agent.brain b::before { background: var(--accent); }
.agent small { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.45; margin-left: 14px; }
.thread-head { display: flex; align-items: center; justify-content: space-between; margin: 14px 16px 6px; }
.thread-head h3 { margin: 0; }
.thread-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.thread {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; border: 0; background: none;
  padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--ink-2);
}
.thread span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread:hover, .thread.on { background: var(--paper); color: var(--ink); }
.thread .del { visibility: hidden; color: var(--ink-3); border: 0; background: none; cursor: pointer; padding: 0 4px; }
.thread:hover .del { visibility: visible; }
.agent-select { display: none; }

.chat { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chat-head h2 { margin: 0; font-size: 17px; }
.messages { flex: 1; overflow-y: auto; padding: 20px; }
.empty { max-width: 520px; margin: 40px auto; text-align: center; color: var(--ink-3); }
.empty h3 { color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.suggests { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.suggests button { text-align: left; border: 1px dashed var(--line-2); background: var(--paper); border-radius: 6px; padding: 8px 12px; cursor: pointer; color: var(--ink-2); }
.suggests button:hover { border-color: var(--ink-3); color: var(--ink); }
.msg { max-width: 820px; margin: 0 auto 18px; }
.msg.user .bubble { background: var(--ink); color: #fff; margin-left: auto; max-width: 80%; width: fit-content; white-space: pre-wrap; }
.bubble { border-radius: 10px; padding: 10px 14px; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); }
.msg-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--ink-3); }
.msg-meta .btn { margin-left: auto; }
details.consult { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
details.consult summary { cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--ink-2); }
.consult-item { border-top: 1px solid var(--line); padding: 10px 14px; background: var(--panel); }
.consult-item h4 { margin: 0 0 4px; font-size: 14px; }
.consult-item .q { font-size: 13px; color: var(--ink-3); margin-bottom: 6px; }
.thinking { color: var(--ink-3); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.thinking::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 200px; }

/* —— Markdown —— */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-size: 15px; margin: 14px 0 6px; }
.md h1, .md h2 { font-size: 16px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--paper); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--paper); padding: 10px; border-radius: 6px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line-2); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--paper); font-weight: 600; }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line-2); color: var(--ink-2); }

/* —— 信息板 —— */
.board-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.board-tools select, .board-tools input { width: auto; min-width: 140px; }
.board-tools .btn.primary { margin-left: auto; }
.board-list { display: grid; gap: 12px; }
.item { padding: 16px 18px; }
.item-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.item h3 { margin: 0 0 6px; font-size: 16px; }
.item .md { font-size: 14px; color: var(--ink-2); }
.item.collapsed .md { max-height: 140px; overflow: hidden; mask-image: linear-gradient(#000 60%, transparent); }
.item-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--ink-3); }
.item-foot .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.comments { margin-top: 10px; border-top: 1px dashed var(--line-2); padding-top: 8px; font-size: 14px; }
.comment { margin-bottom: 4px; }
.comment b { font-weight: 600; margin-right: 6px; }
.comment-form { display: flex; gap: 8px; margin-top: 6px; }

/* —— 设置 —— */
.settings { display: grid; gap: 16px; }
.settings section { padding: 18px 20px; }
.settings h2 { font-size: 16px; margin: 0 0 4px; }
.settings h2 + p { margin: 0 0 14px; }
.agent-forms { display: grid; gap: 10px; }
.agent-form { border: 1px solid var(--line); border-radius: 8px; }
.agent-form summary { padding: 10px 14px; cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.agent-form .body { padding: 4px 14px 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; white-space: nowrap; }
table.data th { color: var(--ink-3); font-weight: 500; font-size: 12px; }
.add-user { display: grid; grid-template-columns: repeat(5, 1fr) auto; gap: 8px; margin-top: 12px; align-items: end; }

/* —— 弹窗 —— */
.modal-bg { position: fixed; inset: 0; background: rgba(29,29,27,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 560px; padding: 20px 22px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* —— 手机 —— */
@media (max-width: 820px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand span { display: none; }
  .nav button { padding: 6px 8px; font-size: 14px; white-space: nowrap; }
  .me { gap: 6px; }
  .me .name, .me .region { display: none; }
  .me button { padding: 3px 7px; }
  .page { padding: 10px; }
  .workbench { grid-template-columns: 1fr; height: calc(100vh - 56px - 20px); }
  .side { display: none; }
  .agent-select { display: flex; gap: 8px; margin-bottom: 8px; }
  .workbench { grid-template-rows: auto 1fr; }
  .msg.user .bubble { max-width: 92%; }
  .grid2, .add-user { grid-template-columns: 1fr; }
  .board-tools .btn.primary { margin-left: 0; }
}

/* —— v0.2：方案、计算记录、规则库、数据 —— */
.pad { padding: 16px 18px; }
.mono { font-family: var(--mono); font-size: 12px; }
.auto { width: auto !important; }
.ct { font-size: 15px; margin: 0 0 10px; }
h2.ct { font-size: 17px; }
.ct-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.ct-row .ct { margin: 6px 0; }
.chip.tone-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.tone-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip.tone-bad { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip.tone-info { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.chip.tone-muted { color: var(--ink-3); }
.notice { border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: #6d4408; }
.notice.bad { background: var(--accent-soft); color: #7a2817; }
.notice ul { margin: 4px 0 0; padding-left: 20px; }
.lead { font-size: 15px; margin: 8px 0 12px; }
.sub h4 { font-size: 13px; color: var(--ink-2); margin: 12px 0 4px; }
.sub ul { margin: 0; padding-left: 20px; font-size: 14px; }
details.more { margin-top: 10px; font-size: 14px; }
details.more summary { cursor: pointer; color: var(--ink-2); }
details.more pre { max-height: 320px; overflow: auto; background: var(--paper); padding: 10px; border-radius: 6px; font-size: 12px; }
td.wrap, .wrap { white-space: normal !important; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.unpriced td { background: #fdf3f0; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover td { background: var(--paper); }
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 5px 10px 5px 0; width: 44%; border-bottom: 1px solid var(--line); }
table.kv td { padding: 5px 0; border-bottom: 1px solid var(--line); }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.toolrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
label.check { font-size: 13px; color: var(--ink-2); display: block; margin-top: 6px; }
.rr { margin: 2px 0; font-size: 13px; }
.runchip { cursor: pointer; background: var(--blue-soft); border-color: transparent; color: var(--blue); font-size: 11px; }
.dsel { margin-left: auto; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.dsel select { width: auto; max-width: 260px; padding: 4px 8px; }

.dwrap { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.dside { display: flex; flex-direction: column; max-height: calc(100vh - 96px); position: sticky; top: 76px; }
.dlist { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: none; border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.dlist b { display: block; font-weight: 600; }
.dlist small { color: var(--ink-3); font-size: 12px; }
.dlist.on, .dlist:hover { background: var(--paper); border-color: var(--line-2); }
.dmain { min-width: 0; }
.dhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; margin-bottom: 12px; flex-wrap: wrap; }
.dhead h2 { margin: 0; font-size: 18px; }
.dhead-r { display: flex; gap: 8px; align-items: center; }
.dgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 12px; align-items: start; }
.dcol { display: grid; gap: 12px; min-width: 0; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.planfig { margin: 0; }
.planfig figcaption { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
svg.plan { width: 100%; max-height: 360px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.p-mod { fill: #f3f0e8; stroke: var(--ink); stroke-width: 40; }
.p-mod.has-room { fill: #e9eff6; }
.p-label { font-size: 420px; font-weight: 600; text-anchor: middle; fill: var(--ink); font-family: var(--mono); }
.p-sub { font-size: 300px; text-anchor: middle; fill: var(--ink-2); }
.p-open { stroke-width: 160; stroke-linecap: butt; }
.p-open.door { stroke: var(--accent); }
.p-open.window { stroke: var(--blue); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; align-items: center; }
.lg::before { content: ""; display: inline-block; width: 14px; height: 10px; margin-right: 5px; vertical-align: -1px; border-radius: 2px; }
.lg.door::before { background: var(--accent); }
.lg.window::before { background: var(--blue); }
.lg.room::before { background: #e9eff6; border: 1px solid var(--ink); }
.lg.item::before { background: #e4dccb; border: 1px solid #55534d; }
.lg.zone::before { border: 1.5px dashed var(--ok); }
.lg.swing::before { background: #f6e3dd; border: 1px solid var(--accent); }
.layouts { display: grid; gap: 12px; }
.layfig { margin: 0; }
.layfig figcaption { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
svg.layout { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.l-room { fill: #fbfaf6; stroke: var(--ink); stroke-width: 40; }
.l-item { fill: #e4dccb; stroke: #55534d; stroke-width: 15; }
.l-zone { fill: rgba(47,125,85,.07); stroke: var(--ok); stroke-width: 15; stroke-dasharray: 60 40; }
.l-swing { fill: #f6e3dd; stroke: var(--accent); stroke-width: 12; }
.l-door { fill: var(--accent); }
.l-text { font-size: 190px; text-anchor: middle; dominant-baseline: middle; fill: var(--ink); }
.runview h3 { margin: 0 0 4px; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.runhead { margin-bottom: 10px; }
.runhead .notice { margin-top: 8px; }
.totals { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: 6px 0 12px; }
.totals b { font-size: 20px; font-variant-numeric: tabular-nums; }
.plist { display: grid; gap: 8px; }
.prop { border-bottom: 1px dashed var(--line); padding-bottom: 8px; font-size: 14px; }
.errs { margin: 4px 0 0; padding-left: 20px; color: var(--accent); font-size: 13px; }
.qtys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 14px; margin-top: 4px; }
.qtys input.qty { width: 48px; padding: 3px 6px; display: inline-block; }
.rules { display: grid; gap: 6px; }
details.rule { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
details.rule summary { padding: 9px 12px; cursor: pointer; font-size: 14px; line-height: 1.8; }
.rule-body { padding: 0 14px 12px; font-size: 14px; }
.rule-body h4 { font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
.rule-body pre { background: var(--paper); padding: 8px; border-radius: 6px; font-size: 12px; overflow: auto; margin: 0; }
.modal.wide { max-width: 980px; }
.modal-actions.top { margin: 0 0 8px; }
.empty.card { padding: 30px; }
.pad.thinking { padding: 16px 18px; }

@media (max-width: 1000px) {
  .dgrid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .dwrap { grid-template-columns: 1fr; }
  .dside { position: static; max-height: 240px; }
  .grid3, .qtys { grid-template-columns: 1fr; }
  .nav { overflow-x: auto; }
  .dsel { margin-left: 0; }
}
.dwrap > *, .dgrid > *, .dcol > *, .dmain > * { min-width: 0; }
@media (max-width: 820px) {
  .dwrap, .dgrid { grid-template-columns: minmax(0, 1fr); }
  .dhead-r { flex-wrap: wrap; }
  .dhead-r select { max-width: 100%; }
}
table.rt td { vertical-align: top; font-size: 13px; }
table.rt td:nth-child(1) { white-space: nowrap; }
table.rt td:nth-child(2) { min-width: 150px; }
table.rt td:nth-child(3) { min-width: 220px; }
table.rt td:nth-child(4) { min-width: 120px; }
