:root {
  --bg: #f5f6f8; --panel: #fff; --line: #e3e6eb; --text: #1f2328; --muted: #6b7280;
  --primary: #2563eb; --primary-weak: #e8efff; --ok: #16a34a; --warn: #d97706; --fail: #dc2626;
  --radius: 8px; --font: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.45 var(--font); color: var(--text); background: var(--bg); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 10px; }
button:hover { background: #f3f4f6; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.ghost { background: transparent; }
button.danger { color: var(--fail); }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-weak); border-color: var(--primary); }
a { color: var(--primary); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--fail); color: #fff; font-size: 11px; line-height: 18px; text-align: center; vertical-align: middle; }
.badge.zero { background: #cbd5e1; }

/* ---------- 布局 ---------- */
#app { display: grid; grid-template-columns: 3fr 2fr; height: 100vh; gap: 8px; padding: 8px; }
#left, #right { min-width: 0; min-height: 0; }
#left { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#right { display: grid; grid-template-rows: minmax(160px, 38%) 1fr; gap: 8px; }
#review, #chat { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 0; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.bar h1 { font-size: 15px; margin: 0; }
.bar h2 { font-size: 14px; margin: 0; }
footer.bar { border-bottom: 0; border-top: 1px solid var(--line); }

/* ---------- 视图条 ---------- */
.viewbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.viewbar select { max-width: 130px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; background: var(--primary-weak); color: #1e40af; font-size: 12px; }
.chip b { font-weight: 600; }
.chip .x { cursor: pointer; opacity: .6; padding: 0 2px; }
.chip .x:hover { opacity: 1; }
.chip.placeholder { background: transparent; color: var(--muted); }

/* ---------- KPI / 图 ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px 12px; }
.kpi { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.kpi .v { font-size: 18px; font-weight: 600; }
.kpi .l { color: var(--muted); font-size: 12px; }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 12px 8px; }
.chart { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; height: 150px; position: relative; }
.chart h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.chart canvas { max-height: 115px; }

/* ---------- 表格 ---------- */
.tablewrap { flex: 1; overflow: auto; min-height: 0; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
thead th { position: sticky; top: 0; background: #fafbfc; text-align: left; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
tbody td { padding: 6px 8px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: #f8fafc; }
tbody tr.row.selected { background: var(--primary-weak); }
tr.group td { background: #f1f5f9; font-weight: 600; padding: 5px 8px; }
tr.sub td { background: #fbfbfc; padding: 4px 8px 8px 32px; }
td.num, th.num { text-align: right; white-space: nowrap; }
.w-exp { width: 22px; }
.exp { display: inline-block; width: 16px; text-align: center; color: var(--muted); user-select: none; }
.rooms { color: #374151; font-size: 12px; }
.prog { white-space: nowrap; }
.prog .ok { color: var(--ok); }
.prog .warn { color: var(--warn); }
.pay { display: grid; grid-template-columns: 40px 110px 1fr 110px auto; gap: 6px 10px; align-items: center; font-size: 12px; }
.pay .h { color: var(--muted); }
.pay input[type=date] { padding: 2px 4px; }
.pay .paid { color: var(--ok); }
.pay .unpaid { color: var(--warn); }

/* ---------- 详情条 ---------- */
.detail { border-top: 1px solid var(--line); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; background: #fafbfc; }
.detail .kv { font-size: 12px; }
.detail .kv b { color: var(--muted); font-weight: 500; margin-right: 4px; }
.detail .acts { display: flex; gap: 6px; margin-left: auto; }

/* ---------- 待审核 ---------- */
.cards { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.card { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.card .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--muted); font-size: 12px; }
.st { font-size: 11px; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.st.extracting { background: #fef3c7; color: #92400e; }
.st.needs_review { background: #dbeafe; color: #1e40af; }
.st.failed { background: #fee2e2; color: #991b1b; }
.st.uploaded { background: #e5e7eb; color: #374151; }
.st.confirmed { background: #dcfce7; color: #166534; }
.card .err { color: var(--fail); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.reconfirm { border-color: #f59e0b; }

/* ---------- 聊天 ---------- */
.stage { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.dropzone { border: 1.5px dashed #cbd5e1; border-radius: 6px; padding: 10px; text-align: center; color: var(--muted); }
.dropzone.over { border-color: var(--primary); background: var(--primary-weak); }
.stagedlist { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.staged { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; }
.staged .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.staged.dup { border-color: var(--fail); color: var(--fail); }
.staged .x { cursor: pointer; color: var(--muted); }
.stageactions { margin-top: 6px; display: flex; justify-content: flex-end; }
.messages { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; padding: 6px 10px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.msg.assistant { align-self: flex-start; background: #f1f5f9; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 0; }
.msg .atts { font-size: 11px; opacity: .8; margin-top: 4px; }
.msg code { background: rgba(0,0,0,.06); padding: 0 3px; border-radius: 3px; }
.msg.assistant .think { color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; white-space: normal; }
.msg .atts { white-space: normal; }
.action-link { display: inline-block; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; font-size: 12px; }
.proposal { border: 1px solid #f59e0b; background: #fffbeb; border-radius: 6px; padding: 8px 10px; font-size: 12px; }
.proposal .t { font-weight: 600; margin-bottom: 4px; }
.proposal .row { display: flex; gap: 6px; }
.proposal .row b { color: var(--muted); font-weight: 500; min-width: 56px; }
.proposal .btns { margin-top: 6px; display: flex; gap: 6px; }
.proposal.applied { border-color: var(--ok); background: #f0fdf4; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.composer textarea { flex: 1; min-width: 120px; resize: none; max-height: 120px; }
.attachchips { display: flex; gap: 4px; flex-wrap: wrap; }
.attachchips .chip { background: #fef3c7; color: #92400e; }

/* ---------- 抽屉 ---------- */
#drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(1100px, 86vw); background: #fff; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
.drawer-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.1fr 1fr; }

/* 留痕弹窗 */
#auditModal { position: fixed; inset: 0; z-index: 60; }
.modal-panel { position: absolute; inset: 6vh 8vw; background: #fff; border-radius: 8px; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.2); overflow: hidden; }
.modal-body { flex: 1; min-height: 0; overflow: auto; }
table.audit { width: 100%; border-collapse: collapse; font-size: 13px; }
table.audit td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit td.when { color: var(--muted); white-space: nowrap; width: 1%; font-variant-numeric: tabular-nums; }
table.audit td.tool { white-space: nowrap; width: 1%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
table.audit td.ms { color: var(--muted); text-align: right; white-space: nowrap; width: 1%; font-variant-numeric: tabular-nums; }
table.audit tr.bad td.tool { color: #b91c1c; }
table.audit .args { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }
.evidence { overflow: auto; padding: 10px; border-right: 1px solid var(--line); background: #fafbfc; }
.evi { margin-bottom: 12px; }
.evi h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; display: flex; gap: 8px; align-items: center; }
.evi img { width: 100%; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: zoom-in; }
.evi .q { font-size: 12px; color: #374151; margin-top: 3px; }
.pdfpane { border-right: 1px solid var(--line); }
.pdfpane iframe { width: 100%; height: 100%; border: 0; }
.reviewform { overflow: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.field input, .field textarea { width: 100%; }
.field .prev { font-size: 11px; color: var(--muted); }
.field .prev.diff { color: var(--warn); }
.lvl { font-size: 11px; padding: 0 5px; border-radius: 3px; }
.lvl.warn { background: #fef3c7; color: #92400e; }
.lvl.fail { background: #fee2e2; color: #991b1b; }
.lvl.ok { background: #dcfce7; color: #166534; }
.field.fail input { border-color: var(--fail); }
.field.warn input { border-color: var(--warn); }
.subtable { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.subtable h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.subtable .r { display: grid; gap: 4px; margin-bottom: 4px; align-items: center; }
.subtable .r.rooms { grid-template-columns: 1.3fr 1.5fr 88px 1fr 24px; }
.brandcell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brandcell select, .brandcell input { width: 100%; }
.brandhint { font-size: 11px; color: var(--muted); line-height: 1.3; }
.brandhint.match { color: #166534; }
.brandhint.create { color: #92400e; }
#brandModal { position: fixed; inset: 0; z-index: 60; }
#brandNewName { width: 180px; }
.subtable .r.plan { grid-template-columns: 34px 100px 1fr 120px 24px; }
.subtable .r input, .subtable .r select { padding: 3px 6px; font-size: 12px; }
.subtable .h { color: var(--muted); font-size: 11px; }
.subtable .del { cursor: pointer; color: var(--muted); text-align: center; }
.tabs { display: flex; gap: 2px; }
.tab { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; color: var(--muted); }
.tab.active { background: var(--primary-weak); color: #1e40af; }

/* ---------- 登录 ---------- */
.login-body { display: grid; place-items: center; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 24px 28px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.login-card input { padding: 8px; }
.login-card button { background: var(--primary); color: #fff; border-color: var(--primary); padding: 8px; }
.err { color: var(--fail); min-height: 1em; margin: 0; font-size: 12px; }

/* ---------- 小屏 ---------- */
@media (max-width: 1280px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .charts { display: none; }
}
