/* base reset (from host page) */
:root{color-scheme:light;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
html{scroll-padding-top:env(safe-area-inset-top,0px)}
body{margin:0;padding:0;font:14px -apple-system,BlinkMacSystemFont,sans-serif;background:#fff;color:#000}
img{max-width:100%}
[hidden]:not([hidden=until-found i]){display:none!important}
/* Layout: one column app; sticky three-way switch (录入 / 分析 / 问答); receipts drawn like thermal paper slips */
:root{
  --bg:#f3f5f4; --surface:#ffffff; --paper:#fbfcfb; --ink:#16201c; --muted:#5b6964; --line:#dbe2df;
  --accent:#1d6b58; --accent-ink:#ffffff; --accent-soft:#e2efeb; --bar2:#6d8f86;
  --good:#1d7a4b; --bad:#b0281f; --warn:#9a5a00; --joy:#b8456d;
  --c1:#1d6b58; --c2:#c26a1b; --c3:#3b6fb6; --c4:#8e4fa8; --c5:#b23b52; --c6:#5f8a1f; --c7:#23909b; --c8:#7a6a55;
  --ic-green:#2f7a64; --ic-teal:#2f8388; --ic-slate:#4d6b8a; --ic-ochre:#a2772a; --ic-clay:#a35d4c; --ic-plum:#7a5c84; --ic-sage:#62804f;
  --f-body:"Noto Sans SC",system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;
  --f-disp:"Noto Serif SC","Songti SC",serif;
  --f-mono:"IBM Plex Mono",ui-monospace,Menlo,Consolas,monospace;
  --r:10px; --s1:4px; --s2:8px; --s3:12px; --s4:16px; --s5:24px; --s6:36px;
}
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){
  --bg:#0f1412; --surface:#171e1b; --paper:#1b2320; --ink:#e4ebe8; --muted:#97a6a0; --line:#2a3430;
  --accent:#5cbf9e; --accent-ink:#0c1512; --accent-soft:#1b2d27; --bar2:#7f9d95;
  --good:#5ccf93; --bad:#ff8a80; --warn:#f0b35a; --joy:#f08aab; --c1:#5cbf9e; --c2:#f0a35a; --c3:#7fa8e8; --c4:#c58fe0; --c5:#f08a9e; --c6:#a9cc6a; --c7:#66cfd9; --c8:#b8a88f; --ic-green:#6cc3a5; --ic-teal:#6fbfc3; --ic-slate:#93acc8; --ic-ochre:#d5ae63; --ic-clay:#d99685; --ic-plum:#b79bc0; --ic-sage:#a5c08f; color-scheme:dark}}
:root[data-theme="dark"]{
  --bg:#0f1412; --surface:#171e1b; --paper:#1b2320; --ink:#e4ebe8; --muted:#97a6a0; --line:#2a3430;
  --accent:#5cbf9e; --accent-ink:#0c1512; --accent-soft:#1b2d27; --bar2:#7f9d95;
  --good:#5ccf93; --bad:#ff8a80; --warn:#f0b35a; --joy:#f08aab; --c1:#5cbf9e; --c2:#f0a35a; --c3:#7fa8e8; --c4:#c58fe0; --c5:#f08a9e; --c6:#a9cc6a; --c7:#66cfd9; --c8:#b8a88f; --ic-green:#6cc3a5; --ic-teal:#6fbfc3; --ic-slate:#93acc8; --ic-ochre:#d5ae63; --ic-clay:#d99685; --ic-plum:#b79bc0; --ic-sage:#a5c08f; color-scheme:dark}
body{background:var(--bg);color:var(--ink);font-family:var(--f-body);font-size:15px;line-height:1.6}
.wrap{max-width:980px;margin-inline:auto;padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));padding-block:var(--s5) var(--s6);display:flex;flex-direction:column;gap:var(--s5)}
h1{font-family:var(--f-disp);font-weight:600;font-size:1.75rem;margin:0;line-height:1.2;text-wrap:balance}
h2{font-size:1.05rem;font-weight:700;margin:0;text-wrap:balance}
h3{font-size:.95rem;font-weight:500;margin:0}
.sub{color:var(--muted);margin:var(--s1) 0 0;font-size:.9rem}
.num,.mono{font-family:var(--f-mono);font-variant-numeric:tabular-nums}
button,input,select,textarea{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.btn{border:1px solid var(--line);background:var(--surface);border-radius:8px;padding:6px 14px;cursor:pointer}
.btn:hover{border-color:var(--accent)}
.btn.primary{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-weight:500}
.btn:disabled{opacity:.5;cursor:default}
.btn.link{border:0;background:none;padding:2px 6px;color:var(--muted)}
.btn.link:hover{color:var(--bad)}
.field{border:1px solid var(--line);background:var(--surface);border-radius:8px;padding:6px 10px;min-width:0;box-sizing:border-box}

/* switch */
.switch{position:sticky;top:env(safe-area-inset-top,0px);z-index:5;background:var(--bg);padding-block:var(--s2);display:flex;gap:var(--s1);border-bottom:1px solid var(--line)}
body::before{content:"";position:fixed;inset:0 0 auto;height:env(safe-area-inset-top,0px);z-index:10;background:var(--bg)}
.switch a{flex:1;text-align:center;text-decoration:none;color:var(--muted);padding:8px 4px;border-radius:8px;font-weight:500;display:flex;flex-direction:column;align-items:center;gap:2px}
.switch a svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.switch a .lb{display:flex;flex-direction:column;align-items:center;line-height:1.3}
.switch a small{display:block;font-weight:400;font-size:.75rem}
.switch a[aria-current="page"]{background:var(--accent-soft);color:var(--accent)}
.view{display:flex;flex-direction:column;gap:var(--s5)}
.banner{border:1px solid var(--line);background:var(--surface);border-radius:var(--r);padding:var(--s3) var(--s4);color:var(--muted);font-size:.9rem}
.banner.bad{color:var(--bad)}

/* input */
.panel{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);padding:var(--s5);display:flex;flex-direction:column;gap:var(--s4);min-width:0}
.drop{border:1.5px dashed var(--line);border-radius:var(--r);padding:var(--s5);text-align:center;color:var(--muted);cursor:pointer;background:var(--paper)}
.drop.over{border-color:var(--accent);color:var(--accent)}
.drop strong{color:var(--ink);font-weight:500}
.thumbs{display:flex;flex-wrap:wrap;gap:var(--s2)}
.thumb{position:relative;width:72px;height:96px;border-radius:6px;overflow:hidden;border:1px solid var(--line)}
.thumb img{width:100%;height:100%;object-fit:cover}
.thumb button{position:absolute;top:2px;right:2px;border:0;border-radius:50%;width:22px;height:22px;background:var(--surface);color:var(--ink);cursor:pointer;line-height:1}
textarea.field{width:100%;min-height:84px;resize:vertical}
.row{display:flex;gap:var(--s3);align-items:center;flex-wrap:wrap}
.status{color:var(--muted);font-size:.9rem}
.status.bad{color:var(--bad)}

/* receipt slip */
.slips{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,26rem),1fr));gap:var(--s4)}
.slip{background:var(--paper);border:1px solid var(--line);border-radius:4px;padding:var(--s4);font-family:var(--f-mono);font-size:.85rem;display:flex;flex-direction:column;gap:var(--s2);min-width:0}
.slip .hd{display:grid;grid-template-columns:1fr 9.5rem;gap:var(--s2)}
.slip .field{font-family:var(--f-mono);font-size:.85rem;padding:4px 6px;width:100%}
.slip .dash{border-top:1px dashed var(--muted);opacity:.6}
.items{overflow-x:auto}
.items table{width:100%;border-collapse:collapse;min-width:600px}
.items th{font-weight:400;color:var(--muted);font-size:.72rem;text-align:left;padding:0 2px 2px}
.items td{padding:2px 2px;vertical-align:top}
.items .raw{color:var(--muted);font-size:.75rem;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:12rem}
.items td.q .field{width:4.2rem;text-align:right}
.items td.u .field{width:4rem}
.items td.a .field{width:5.4rem;text-align:right}
.items td.c .field{width:8.5rem}
.tools{display:flex;flex-wrap:wrap;gap:var(--s2) var(--s4);align-items:center;font-family:var(--f-body);font-size:.8rem;color:var(--muted)}
.tools .grp{display:flex;gap:var(--s1);align-items:center;flex-wrap:wrap}
.tools .field{width:5rem;text-align:right;font-family:var(--f-mono)}
.tools .btn{padding:3px 10px;font-size:.8rem}
.items .rowbtns{white-space:nowrap}
.brow{display:grid;grid-template-columns:6.5rem 1fr auto auto;gap:var(--s3);padding:8px 2px;font-size:.9rem;align-items:center}
.bnote{font-size:.8rem;color:var(--muted);padding:0 2px 8px 6.5rem;margin-top:-4px}
@media (max-width:520px){.brow{grid-template-columns:5.5rem 1fr auto}.brow .cnt{display:none}.bnote{padding-left:0}}
.items .note-in{margin-top:3px;font-size:.75rem;padding:3px 6px;width:100%;color:var(--muted)}
.billx{display:flex;flex-direction:column;gap:var(--s3);border-top:1px dashed var(--line);padding-top:var(--s4)}
.billx textarea.field{min-height:64px}
.bdrafts{display:flex;flex-direction:column;gap:var(--s3)}
.bdraft{border:1px solid var(--line);border-radius:4px;background:var(--paper);padding:var(--s3);display:flex;flex-wrap:wrap;gap:var(--s2);align-items:center;font-size:.85rem}
.bdraft .field{font-size:.85rem;padding:4px 6px}
.bdraft .grow{flex:1 1 10rem}
.bdraft .acts{margin-left:auto;display:flex;gap:var(--s2)}
.tot{display:flex;justify-content:space-between;font-weight:500}
.tot .warn{color:var(--warn);font-weight:400}
.slip .acts{display:flex;gap:var(--s2);justify-content:flex-end;font-family:var(--f-body)}

/* insights */
.bar-head{display:flex;justify-content:space-between;align-items:end;gap:var(--s3);flex-wrap:wrap}
.periods{display:flex;gap:2px;background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:2px}
.periods button{border:0;background:none;border-radius:6px;padding:4px 10px;cursor:pointer;color:var(--muted);font-size:.85rem}
.periods button[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent);font-weight:500}
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,10rem),1fr));gap:var(--s3)}
.kpi{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);padding:var(--s4)}
.kpi[data-go]{cursor:pointer;position:relative}
.kpi[data-go]:hover,.kpi[data-go]:focus-visible{border-color:var(--accent)}
.kpi[data-go] .l::after{content:" ›";color:var(--accent)}
.kpi .l{color:var(--muted);font-size:.8rem}
.kpi .v{font-family:var(--f-disp);font-size:1.7rem;line-height:1.3;margin-top:var(--s1);font-variant-numeric:tabular-nums}
.kpi .d{font-size:.8rem;color:var(--muted);font-family:var(--f-mono)}
.up{color:var(--bad)!important}.down{color:var(--good)!important}
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,22rem),1fr));gap:var(--s4)}
.card{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);padding:var(--s5);min-width:0;display:flex;flex-direction:column;gap:var(--s3)}
.note{color:var(--muted);font-size:.8rem;margin:0}
.empty{color:var(--muted);font-size:.85rem;padding:var(--s4) 0;text-align:center}
.cols{display:flex;align-items:flex-end;gap:6px;height:180px;border-bottom:1px solid var(--line);padding-top:20px;overflow-x:auto}
.col{flex:1 0 28px;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;height:100%;position:relative}
.col .b{width:min(28px,70%);background:var(--accent);border-radius:4px 4px 0 0;min-height:2px}
.col .t{position:absolute;font-family:var(--f-mono);font-size:.7rem;color:var(--muted);white-space:nowrap}
.col .stk{width:min(28px,70%);display:flex;flex-direction:column;border-radius:4px 4px 0 0;overflow:hidden;min-height:2px}
.stk .s1{background:var(--accent)}.stk .s2{background:var(--bar2)}
.col:not(.cur) .stk{opacity:.6}
.legend{display:flex;flex-wrap:wrap;gap:var(--s2) var(--s4);font-size:.75rem;color:var(--muted)}
.legend button{border:0;background:none;color:inherit;cursor:pointer;padding:2px 0;font:inherit}
.legend button[aria-pressed="false"]{opacity:.4;text-decoration:line-through}
.trend{position:relative;min-height:240px}
.trend svg text{font-size:11px;fill:var(--muted)}
.tip{position:absolute;pointer-events:none;background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:6px 10px;font-size:.78rem;box-shadow:0 4px 14px rgba(0,0,0,.14);white-space:nowrap;z-index:2;display:flex;flex-direction:column;gap:2px}
.tip .k{color:var(--muted)}
.tip i{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:6px}
.legend i{display:inline-block;width:10px;height:10px;border-radius:2px;margin-right:4px;vertical-align:-1px}
.billform{display:flex;flex-wrap:wrap;gap:var(--s2);align-items:center}
#b-name{flex:2 1 12rem}#b-amt{width:7rem}
.bills{display:flex;flex-direction:column}
.bill{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:var(--s2) var(--s3);padding:var(--s2) 0;border-bottom:1px solid var(--line);align-items:center}
.bill .meta{color:var(--muted);font-size:.8rem}
.bill .acts{display:flex;gap:2px;flex-wrap:wrap;justify-content:flex-end}
.bill.off .nm{color:var(--muted);text-decoration:line-through}
.bill .edit{grid-column:1/-1;display:flex;gap:var(--s2);flex-wrap:wrap;align-items:center}
.btn.link.plain:hover{color:var(--accent)}
.collabels{display:flex;gap:6px;overflow:hidden}
.collabels span{flex:1 0 28px;text-align:center;font-size:.72rem;color:var(--muted)}
.hb{display:flex;flex-direction:column;gap:var(--s2)}
.hr{display:grid;grid-template-columns:minmax(0,6.5rem) 1fr auto;gap:var(--s2);align-items:center;font-size:.85rem}
.hr .lab{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hr .tr{height:10px;background:var(--accent-soft);border-radius:5px;overflow:hidden}
.hr .fi{height:100%;background:var(--accent);border-radius:5px}
.hr.s .fi{background:var(--bar2)}
.hr .v{font-family:var(--f-mono);font-size:.8rem;text-align:right;min-width:6.5rem}
.hr.click{cursor:pointer;border-radius:6px}
.hr.click:hover .lab{color:var(--accent)}
.hr.sub{padding-left:1.2rem;font-size:.8rem}
.hr.sub .fi{opacity:.6}

.tablebox{overflow:auto;max-height:440px}
table.t{width:100%;border-collapse:collapse;font-size:.85rem}
.t th,.t td{padding:6px 8px;border-bottom:1px solid var(--line);text-align:left;white-space:nowrap}
.t th{position:sticky;top:0;background:var(--surface);font-weight:500;cursor:pointer;user-select:none}
.t th[aria-sort="ascending"]::after{content:" ↑"}.t th[aria-sort="descending"]::after{content:" ↓"}
.t td.n,.t th.n{text-align:right;font-family:var(--f-mono)}
.t .best{color:var(--good)}
.addtabs{align-self:flex-start}
.minus{border:1px solid color-mix(in srgb,var(--ic-clay) 45%,transparent);background:color-mix(in srgb,var(--ic-clay) 12%,transparent);color:var(--ic-clay);border-radius:999px;padding:0 9px;font:inherit;font-size:.78rem;font-weight:700;cursor:pointer;margin:0 4px 0 6px;line-height:1.5;font-family:var(--f-mono)}
.minus:hover{background:color-mix(in srgb,var(--ic-clay) 22%,transparent)}
.minus:disabled{opacity:.5}
h2.withic,h3.withic{display:flex;align-items:center;gap:8px}
.hic{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:7px;background:color-mix(in srgb,var(--ic) 14%,transparent);flex:none}
.hic svg{width:16px;height:16px;fill:none;stroke:var(--ic);stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
h3 .hic{width:22px;height:22px;border-radius:6px}
h3 .hic svg{width:14px;height:14px}
.adv{display:flex;flex-direction:column;gap:var(--s1)}
.adv .line{font-size:.85rem;padding:4px 0;border-bottom:1px dashed var(--line)}
.adv .line b{font-weight:500}
.adv .line .note{display:block}
.items td.ins{text-align:center}
.qsearch{display:flex;flex-direction:column;gap:var(--s2)}
.qsearch .field{width:100%;font-size:.95rem;padding:8px 12px}
.qres{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);padding:var(--s2) var(--s4);max-height:420px;overflow:auto}
.qres .buy{grid-template-columns:6rem minmax(0,1fr) auto}
.qres .sum{font-size:.8rem;color:var(--muted);padding:4px 0 6px;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--surface)}
.qres mark{background:var(--accent-soft);color:inherit;border-radius:2px}
.subnav{display:flex;gap:var(--s2);flex-wrap:wrap}
.subnav a{font-size:.85rem;color:var(--muted);text-decoration:none;border:1px solid var(--line);border-radius:999px;padding:2px 12px;background:var(--surface)}
.subnav a:hover{color:var(--accent);border-color:var(--accent)}
.sec{display:flex;flex-direction:column;gap:var(--s3)}
#insights > *{scroll-margin-top:72px}
.split{display:grid;grid-template-columns:minmax(0,2fr) minmax(0,3fr);gap:var(--s4);align-items:start}
@media (max-width:820px){.split{grid-template-columns:minmax(0,1fr)}}
.hr.sel{background:var(--accent-soft)}
.hr.sel .lab{color:var(--accent);font-weight:500}
.pcomment{font-size:.75rem;color:var(--muted);white-space:normal;margin-top:2px}
.cedit{display:flex;flex-direction:column;gap:var(--s2);margin-top:var(--s2)}
.cedit textarea.field{min-height:56px}
.cols.mini{height:120px}
h4{font-size:.85rem;font-weight:500;margin:var(--s2) 0 0}
.t td.pcell{white-space:normal;min-width:8rem}
.dhead{display:flex;flex-direction:column;gap:2px}
.dhead .big{font-family:var(--f-disp);font-size:1.4rem;line-height:1.3}
.pbtn{border:0;background:none;padding:0;font:inherit;color:inherit;cursor:pointer;text-decoration:underline dotted;text-underline-offset:3px}
.pbtn:hover{color:var(--accent)}
.pdet td{background:var(--paper);white-space:normal;padding:4px 8px 8px}
.buy{display:grid;grid-template-columns:6rem minmax(0,1fr) auto auto;gap:var(--s3);padding:4px 0;width:100%;border:0;background:none;font:inherit;font-size:.8rem;color:inherit;text-align:left;cursor:pointer}
.buy:hover{color:var(--accent)}
.buy .mono{font-family:var(--f-mono);text-align:right}
.buy.lo .mono:first-of-type{color:var(--good)}
.rec.flash{background:var(--accent-soft)}
.rec{transition:background .4s}
.pill{display:inline-block;font-size:.72rem;padding:0 8px;border-radius:999px;background:var(--accent-soft);color:var(--accent)}
.pill.solo{background:transparent;color:var(--muted);border:1px solid var(--line)}
.rl{display:flex;flex-direction:column}
.rl details{border-bottom:1px solid var(--line)}
.rl .rec{border-bottom:1px solid var(--line)}
.rl .sumrow{display:grid;grid-template-columns:1rem 6.5rem 1fr auto auto;gap:var(--s3);padding:8px 2px;cursor:pointer;align-items:center;font-size:.9rem;width:100%;border:0;background:none;text-align:left;color:inherit}
.rl .sumrow:hover{color:var(--accent)}
.rl .sumrow .ar{color:var(--muted)}
.rl .it{font-family:var(--f-mono);font-size:.8rem;padding:0 2px 10px 6.5rem;display:flex;flex-direction:column;gap:2px}
.rl .it div{display:flex;justify-content:space-between;gap:var(--s3)}
.rl .it span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
@media (max-width:520px){.rl .sumrow{grid-template-columns:1rem 5.5rem 1fr auto}.rl .sumrow .cnt{display:none}.rl .it{padding-left:0}}

/* chat */
.chat{display:flex;flex-direction:column;gap:var(--s3);min-height:200px}
.msg{max-width:min(46rem,92%);padding:var(--s3) var(--s4);border-radius:var(--r);white-space:pre-wrap;word-break:break-word}
.msg.u{align-self:flex-end;background:var(--accent);color:var(--accent-ink)}
.msg.a{align-self:flex-start;background:var(--surface);border:1px solid var(--line)}
.msg.a.thinking{color:var(--muted)}
.chips{display:flex;flex-wrap:wrap;gap:var(--s2)}
.chip{border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:4px 12px;cursor:pointer;font-size:.85rem}
.chip:hover{border-color:var(--accent);color:var(--accent)}
.ask{display:flex;gap:var(--s2);align-items:flex-end}
.ask textarea{flex:1;min-height:44px;max-height:160px;resize:vertical}
@media (prefers-reduced-motion:no-preference){.msg{animation:in .2s ease-out}@keyframes in{from{opacity:.4;transform:translateY(4px)}}}

/* header + settings */
.top{display:flex;justify-content:space-between;align-items:flex-start;gap:var(--s3)}
.gear{flex:none;display:inline-flex;align-items:center;gap:6px}
.gear svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
dialog#settings{border:1px solid var(--line);border-radius:var(--r);background:var(--surface);color:var(--ink);padding:var(--s5);width:min(34rem,calc(100vw - 32px));max-height:calc(100vh - 32px);overflow:auto}
dialog#settings::backdrop{background:rgba(0,0,0,.45)}
dialog#settings form{display:flex;flex-direction:column;gap:var(--s3)}
dialog#settings label{display:flex;flex-direction:column;gap:var(--s1);font-size:.85rem;color:var(--muted)}
dialog#settings .field{width:100%}
.presets{display:flex;flex-wrap:wrap;gap:var(--s2)}
.presets button[aria-pressed="true"]{border-color:var(--accent);color:var(--accent);background:var(--accent-soft)}
