:root {
  --bar: #3f6e52;
  --green: #4a7d5e;
  --green-soft: #eaf2ec;
  --ink: #1f2423;
  --muted: #8a8f8c;
  --line: #e3e5e2;
  --bg: #f6f6f4;
  --bubble: #f0f0ee;
  --warn: #9a3b2f;
  --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.6;
  line-break: strict; overflow-wrap: anywhere;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; }
.login-tag { color: var(--muted); font-size: 13px; letter-spacing: .14em; margin: 0; }
.login h1 { font-size: 28px; margin: 6px 0 20px; }
.login label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.login input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.login input:focus { outline: none; border-color: var(--green); }
.btn-primary { width: 100%; padding: 12px; border: 0; border-radius: var(--r); background: var(--green); color: #fff; font-weight: 600; margin-top: 4px; }
.login-error { color: var(--warn); font-size: 14px; min-height: 22px; margin: 10px 0 0; }
.login-hint { color: var(--muted); font-size: 13px; }

.shell { display: flex; height: 100%; height: 100dvh; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: #fff; }

.tabs { background: var(--bar); display: flex; align-items: center; gap: 4px; padding: 8px 8px; padding-top: max(8px, env(safe-area-inset-top)); }
.tab-list { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab { flex: none; display: flex; align-items: center; border-radius: 10px; }
.tab-title { border: 0; background: transparent; color: #e3ece6; padding: 7px 12px; font-size: 15px; white-space: nowrap; max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: rgba(255,255,255,.18); }
.tab.on .tab-title { color: #fff; font-weight: 600; padding-right: 2px; }
.tab-x { border: 0; background: transparent; color: #cfdcd3; padding: 4px 8px 4px 4px; font-size: 16px; line-height: 1; }
.tab-new { flex: none; border: 0; background: rgba(255,255,255,.18); color: #fff; border-radius: 10px; padding: 4px 12px; font-size: 20px; line-height: 1.4; }
.tab-more { flex: none; border: 0; background: transparent; color: #e3ece6; padding: 7px 8px; font-size: 15px; }

.chat { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; max-width: 280px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--r); white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--green); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--bubble); }
.msg.typing { color: var(--muted); }
.quiet { align-self: flex-start; font-size: 13px; color: var(--muted); padding-left: 2px; }
.quiet.ok::before { content: "✓ "; color: var(--green); }
.quiet.err { color: var(--warn); }
.quiet.ask { color: #8a5a14; }
.quiet.ask::before { content: "? "; }
.upload-row { align-self: flex-end; font-size: 13px; color: var(--muted); background: var(--bubble); border-radius: 10px; padding: 6px 10px; }

.drop-overlay { position: absolute; inset: 0; background: rgba(74,125,94,.12); border: 2px dashed var(--green); display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--green); z-index: 5; pointer-events: none; }

.ctxbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; }
.pill { border: 0; background: #f1f2ef; border-radius: 18px; padding: 5px 12px; font-size: 14px; }
.pill-ctx { font-weight: 600; }
.pill .gt { color: var(--muted); font-weight: 400; margin-left: 4px; }
.quota { margin-left: auto; font-size: 13px; color: var(--green); }

.inputbar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); margin-top: 8px; }
.ib-icon { flex: none; width: 34px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 20px; }
.ib-icon:disabled { opacity: .35; cursor: default; }
.inputbar textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; border: 1px solid #d8dbd8; border-radius: 10px; padding: 9px 12px; background: #fff; }
.inputbar textarea:focus { outline: none; border-color: var(--green); }
.ib-btn { flex: none; border: 0; border-radius: 10px; padding: 9px 14px; background: var(--green); color: #fff; }
.ib-ghost { background: var(--green-soft); color: var(--green); }
.ib-btn.recording { background: var(--warn); color: #fff; }

.rail { display: none; width: 104px; flex: none; border-left: 1px solid var(--line); background: #fafaf8; padding-top: 16px; flex-direction: column; align-items: stretch; }
.rail-item { border: 0; background: transparent; color: var(--muted); font-size: 15px; padding: 10px 0; border-left: 3px solid transparent; }
.rail-item:hover, .rail-item.on { color: var(--green); font-weight: 600; border-left-color: var(--green); }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-box { background: #fff; width: 100%; max-width: 560px; max-height: 80vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-close { margin-left: auto; border: 0; background: transparent; color: var(--muted); }
.sheet-body { overflow-y: auto; padding: 8px 16px 20px; }
.sheet-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.sheet-row span { color: var(--muted); font-size: 13px; flex: none; text-align: right; }
.sheet-sub { display: block; color: var(--green); font-size: 13px; margin-top: 2px; }
.link-btn { display: block; margin-left: auto; border: 0; background: transparent; color: var(--green); font-size: 13px; padding: 4px 0; }
.sheet-menu { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.sheet-note { color: var(--muted); font-size: 14px; }

@media (min-width: 900px) {
  .rail { display: flex; }
  .tab-more { display: none; }
  .chat { padding: 22px 28px; }
  .sheet { align-items: center; right: 104px; }
  .sheet-box { border-radius: 16px; }
}

.sheet.wide .sheet-box { max-width: 980px; max-height: 92vh; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.form-grid input, .form-grid select, .inline-form input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-width: 0; }
.inline-form { display: flex; gap: 8px; margin: 10px 0; }
.btn-small { flex: none; border: 0; border-radius: 10px; padding: 8px 14px; background: var(--green); color: #fff; }
.btn-small.ghost { background: var(--green-soft); color: var(--green); }
.btn-small:disabled { opacity: .5; }
.back-btn { border: 0; background: transparent; color: var(--green); padding: 4px 0 8px; }
.fact { padding: 8px 0; border-bottom: 1px solid var(--line); }
.fact small { display: block; color: var(--muted); font-size: 12px; }
.kv { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.tbl-wrap { overflow-x: auto; margin: 8px 0; }
.val-table { border-collapse: collapse; width: 100%; min-width: 760px; font-size: 14px; }
.val-table th, .val-table td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; white-space: nowrap; }
.val-table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.val-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.val-table tr.off td { color: #b5b9b6; }
.val-table input.adj { width: 70px; text-align: right; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; }
.val-table input.why { width: 150px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; }
.result-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 6px; }
.result-cards div { background: var(--green-soft); border-radius: 12px; padding: 10px 6px; text-align: center; }
.result-cards b { display: block; font-size: 24px; color: var(--green); font-variant-numeric: tabular-nums; }
.result-cards span { font-size: 12.5px; color: var(--muted); }
.note-line { font-size: 13.5px; color: var(--muted); margin: 6px 0; }
.note-line.warn { color: #8a5a14; }
.section-title { font-weight: 600; margin: 16px 0 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid var(--green); background: #fff; color: var(--green); border-radius: 16px; padding: 4px 12px; font-size: 13px; }
.chip.ghost { border-color: var(--line); color: var(--muted); }
.chip:disabled { opacity: .5; }
.chip-done { color: var(--green); font-size: 13px; }
.pick-filter { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; margin: 4px 0 6px; }
.fact-actions { display: flex; gap: 8px; margin: 4px 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field select, .val-table select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-width: 0; }
.save-state { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.check-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 8px 0; }
.check-group { background: #fafaf8; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.check-group b { display: block; font-size: 14px; margin-bottom: 4px; }
.check-row { display: grid; grid-template-columns: 20px 1fr; gap: 2px 6px; font-size: 14px; padding: 4px 0; align-items: start; }
.check-row input { margin-top: 5px; }
.check-row small { grid-column: 2; color: var(--green); font-size: 12px; }
.basis { display: inline-block; font-size: 11.5px; line-height: 1.5; padding: 0 6px; border-radius: 6px; margin-right: 6px; vertical-align: 1px; }
.b-calc { background: var(--green-soft); color: var(--green); }
.b-guess { background: #f6ecd9; color: #8a5a14; }
.b-fact { background: #eef0ee; color: #5f6662; }
.report-warn { background: #fbefe9; color: var(--warn); border-radius: 10px; padding: 8px 12px; margin: 6px 0; font-size: 14px; }
.report-sec { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 4px; }
.report-sec h3 { font-size: 17px; margin: 10px 0 6px; }
.report-sub { font-weight: 600; font-size: 14px; margin: 10px 0 2px; }
.report-items { list-style: none; padding: 0; margin: 4px 0; }
.report-items li { padding: 4px 0; font-size: 14.5px; }
.report-table { min-width: 520px; }
.report-table td { white-space: normal; }
.report-table tr.hl td { background: var(--green-soft); font-weight: 600; }
.plan-box { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; margin: 8px 0; }
.plan-box.rec { border-color: var(--green); }
.wechat-preview { white-space: pre-wrap; font: inherit; font-size: 13.5px; background: #fafaf8; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; max-height: 260px; overflow-y: auto; user-select: text; -webkit-user-select: text; }
.long-images img { display: block; width: 100%; max-width: 480px; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0 2px; }
.long-images .link-btn { margin-left: 0; display: inline-block; }
.sheet-close { flex: none; white-space: nowrap; }
.sheet-head > :first-child { min-width: 0; }
.draft-box { background: #fbf4e6; border: 1px solid #ecd9b0; border-radius: 12px; padding: 10px 14px; margin: 6px 0 10px; }
.draft-box b { color: #8a5a14; }
.draft-box p { margin: 4px 0 8px; font-size: 14px; color: #5f6662; }
.quadrant { display: block; width: 100%; max-width: 640px; margin: 8px 0; font-family: inherit; }
.b-edit { background: #e6eef8; color: #2f5d8a; }
.edit-line { width: calc(100% - 52px); vertical-align: top; font: inherit; font-size: 14.5px; padding: 4px 8px; border: 1px solid #c9d6e6; border-radius: 8px; resize: vertical; background: #fbfdff; }
.pill-go { background: var(--green); color: #fff; font-weight: 600; }
.pill-go:disabled { opacity: .6; }
.empty-action { display: block; margin: 14px auto 0; }
.warn-num { color: var(--warn); font-weight: 600; }
.val-table tr.dim-gap td { color: var(--warn); }
details summary { cursor: pointer; color: var(--green); font-size: 14px; margin: 6px 0; }
.pending-btn { display: block; width: 100%; text-align: left; border: 1px solid #ecd9b0; background: #fbf4e6; color: #8a5a14; border-radius: 12px; padding: 10px 14px; margin: 6px 0 10px; font-weight: 600; }
.confirm-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.confirm-head { display: flex; align-items: baseline; gap: 8px; }
.confirm-head small { color: var(--muted); font-size: 12.5px; }
.confirm-fact { margin: 4px 0; font-size: 14px; color: #5f6662; }
.chip.on { background: var(--green); color: #fff; }
.src-link { color: var(--green); }
