/* 布局：顶栏三个导航；「开票」是左边待发清单 + 复制区、右边录入的两栏工作台，窄屏堆叠成单列。
   只用系统字体：国内连 Google Fonts 不稳定。 */
:root {
    --bg: #edf0f4;
    --surface: #ffffff;
    --surface-2: #f5f7fa;
    --ink: #15202c;
    --muted: #596577;
    --faint: #8893a2;
    --line: #d9dfe7;
    --primary: #1c3a62;
    --on-primary: #ffffff;
    --primary-soft: #e3eaf4;
    --warn: #8f5408;
    --warn-soft: #fbefd9;
    --ok: #21704a;
    --ok-soft: #e0f1e7;
    --bad: #b0261c;
    --bad-soft: #fbe4e1;
    --shadow: 0 1px 2px rgba(21, 32, 44, .05), 0 6px 20px rgba(21, 32, 44, .06);
    --font-display: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
    --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
    --font-data: "SF Mono", "Cascadia Mono", Consolas, Menlo, "Roboto Mono", monospace;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151b; --surface: #191f27; --surface-2: #1f2630; --ink: #e5e9ef; --muted: #9aa5b4; --faint: #6e7988; --line: #2c3541;
        --primary: #9dbbe6; --on-primary: #0f1722; --primary-soft: #22324a;
        --warn: #f1b65c; --warn-soft: #3a2c14; --ok: #6fd09b; --ok-soft: #163223; --bad: #ff8a7f; --bad-soft: #3d1a17;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.55; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.mono { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1 1 auto; min-width: 0; }
h1, h2, h3 { text-wrap: balance; }

.app { max-width: 1200px; margin: 0 auto; padding-inline: 16px; padding-block: 0 64px; }

/* 顶栏 */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); margin-inline: -16px; padding-inline: 16px; }
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { text-decoration: none; }
.brand b { font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: .04em; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { text-decoration: none; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab .count { font-family: var(--font-data); font-size: 12px; color: var(--warn); margin-left: 4px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: var(--muted); letter-spacing: .1em; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { background: var(--surface-2); color: var(--ink); }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: grid; min-width: 128px; z-index: 30; }
.menu-panel a, .menu-panel button { display: block; text-align: left; text-decoration: none; border: 0; background: none; padding: 8px 10px; border-radius: 7px; font-size: 13.5px; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); }
.menu-panel form { margin: 0; }
.menu-panel button { width: 100%; }

/* 汇总带 */
.summary { margin: 16px 0 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; min-height: 74px; }
.sum { padding: 12px 16px; border-left: 1px solid var(--line); display: grid; gap: 2px; }
.sum:first-child { border-left: 0; }
.sum small { color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.sum strong { font-family: var(--font-data); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sum em { font-style: normal; color: var(--faint); font-size: 12px; }
.sum.pending small { color: var(--warn); }

/* 两栏 */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.composer { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 72px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
@media (max-width: 900px) {
    .workspace { grid-template-columns: minmax(0, 1fr); }
    .composer { position: static; order: -1; }
}

/* 发给代账：复制区 */
.sendbox { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.send-main { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; padding: 14px 16px; }
.send-what { display: grid; gap: 2px; margin-right: auto; min-width: 0; }
.send-what small { color: var(--muted); font-size: 12.5px; }
.send-what b { font-size: 17px; }
.send-what b .mono { font-weight: 600; margin-left: 6px; }
.send-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sendbox details { border-top: 1px solid var(--line); }
.sendbox summary { cursor: pointer; padding: 9px 16px; color: var(--muted); font-size: 13px; list-style: none; display: flex; align-items: center; gap: 6px; }
.sendbox summary::-webkit-details-marker { display: none; }
.sendbox summary::before { content: ""; width: 0; height: 0; border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform .15s; }
.sendbox details[open] summary::before { transform: rotate(90deg); }
.preview { margin: 0; padding: 12px 16px 16px; max-height: 340px; overflow: auto; background: var(--surface-2); border-top: 1px solid var(--line); font-family: var(--font-body); font-size: 13px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 16; }
.preview.tsv { font-family: var(--font-data); font-size: 12px; white-space: pre; overflow-wrap: normal; }
.confirm { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 10px 16px; background: var(--ok-soft); border-top: 1px solid var(--line); font-size: 13.5px; }
.confirm span { margin-right: auto; min-width: 0; }

/* 工具条、按钮 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.chips { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.chip { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.chip .n { font-family: var(--font-data); font-size: 12px; margin-left: 3px; opacity: .85; }
.search { flex: 1 1 160px; min-width: 0; display: flex; margin: 0; }
.search input { width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 12px; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.big { padding: 10px 20px; font-size: 15px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* 发票条目 */
.list { display: grid; gap: 10px; }
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.entry.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { box-shadow: 0 0 0 3px var(--primary); } to { box-shadow: 0 0 0 0 transparent; } }
.entry.picked { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.entry.sent { background: var(--surface-2); }
.entry-top { display: flex; gap: 10px; align-items: flex-start; }
.pick { padding: 2px 2px 0 0; cursor: pointer; }
.pick input { width: 19px; height: 19px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.entry-name { flex: 1; min-width: 0; display: grid; gap: 2px; }
.entry-name b { font-size: 15.5px; overflow-wrap: anywhere; }
.entry-name .tax { font-family: var(--font-data); font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.entry-amt { text-align: right; flex: none; }
.entry-amt small { display: block; font-size: 11.5px; color: var(--muted); }
.entry-amt b { font-family: var(--font-data); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.entry-item { font-size: 14px; display: flex; gap: 10px; align-items: baseline; }
.entry-item span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry-item .mono { color: var(--muted); font-size: 13px; }
.entry-note { font-size: 13px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-note b { font-weight: 500; color: var(--ink); }
.pre { color: var(--faint); }
.entry-foot { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.entry-foot .acts { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }

.tag { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; padding: 0 6px; border-radius: 999px; line-height: 18px; font-weight: 500; font-family: var(--font-body); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.info { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* 明细表 */
.rows { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.rows-head, .rows-line { display: grid; grid-template-columns: minmax(0, 1fr) 92px 48px 100px; }
.rows-head span, .rows-line span { padding: 5px 10px; min-width: 0; }
.rows-head span { font-size: 11.5px; color: var(--muted); background: var(--surface-2); }
.rows-head span:nth-child(n+2), .rows-line span:nth-child(n+2) { text-align: right; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.rows-line { border-top: 1px solid var(--line); font-size: 13.5px; }
.rows-line span:first-child { overflow-wrap: anywhere; }

/* 已发：按发送日期分批 */
.batch { display: grid; gap: 8px; }
.batch + .batch { margin-top: 10px; }
.batch-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 4px 2px; }
.batch-head h3 { margin: 0; font-size: 15px; }
.batch-head .mono { color: var(--muted); font-size: 13px; }
.batch-head .acts { margin-left: auto; display: flex; gap: 4px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; color: var(--muted); }

/* 录入区 */
.composer-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.composer-head h2 { margin: 0; font-size: 15px; }
.composer-head .toggle { display: none; margin-left: auto; }
@media (max-width: 900px) { .composer-head .toggle { display: inline-flex; } }
.composer.collapsed .composer-body { display: none; }
.composer-body { padding: 12px 14px 14px; display: grid; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.lbl { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
textarea, input[type="text"], input[type="number"], input[type="search"], input[type="password"] { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 10px; }
input[type="file"] { max-width: 100%; }
textarea { resize: vertical; line-height: 1.6; }
#pasteBox { min-height: 170px; font-size: 13.5px; }
.paste-acts { margin-top: 10px; }
.parsed { display: grid; gap: 8px; }
.pcard { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; display: grid; gap: 4px; background: var(--surface-2); }
.pcard .row { display: flex; gap: 8px; align-items: baseline; }
.pcard .row b { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pcard .amt { font-family: var(--font-data); font-weight: 600; }
.pcard .sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.pcard .msgs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.pcard .fix { border: 0; background: none; color: var(--primary); text-decoration: underline; font-size: 11.5px; padding: 0; }
.prow { display: flex; gap: 8px; font-size: 12.5px; align-items: baseline; }
.prow span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.prow .mono { color: var(--muted); white-space: nowrap; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; min-height: 1em; }
.hint.ok { color: var(--ok); }
.hint.bad { color: var(--bad); }
.hint.warn { color: var(--warn); }
.formgrid { display: grid; gap: 10px; }
.itemchips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.itemchips button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.itemchips button:hover { color: var(--ink); border-color: var(--faint); }
.check { display: flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.formacts { display: flex; gap: 8px; }
.formacts .btn.primary { flex: 1; }
.rows-ed-head, .row-ed { display: grid; grid-template-columns: minmax(0, 1fr) 92px 56px 28px; gap: 6px; align-items: center; }
.rows-ed-head span { font-size: 12px; color: var(--muted); }
#mRows { display: grid; gap: 6px; margin-top: 4px; }
.row-ed input { padding: 7px 8px; }
.rows-ed-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.rows-ed-foot .hint { margin: 0; }
.ri-del { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; height: 32px; color: var(--muted); }
.ri-del:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
.ri-del:disabled { opacity: .35; cursor: not-allowed; }

/* 面板（抬头库、笔记详情、表单） */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-top: 16px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h1, .panel-head h2 { margin: 0; font-size: 17px; }
.panel-head h1 + p, .panel-head .grow p { margin: 2px 0 0; }
.panel-head > p { margin: 0; color: var(--muted); font-size: 12.5px; flex: 1 1 260px; }
.panel-head .search { flex: 0 1 240px; }
.panel-body { padding: 14px 16px 16px; }
.panel.narrow { max-width: 440px; margin-inline: auto; margin-top: 40px; }
.head-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--font-data); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

/* 表单页 */
.stack-form { display: grid; gap: 14px; }
.field { display: grid; gap: 2px; }
.form-acts { display: flex; gap: 8px; }
.message { padding: 10px 12px; border-radius: 9px; background: var(--ok-soft); color: var(--ok); font-size: 13.5px; }
.message.error { background: var(--bad-soft); color: var(--bad); }
.danger-zone .panel-head { border-bottom: 0; }

/* 笔记 */
.page-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.page-hint { margin: 8px 0 12px; }
.notes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.note-head { display: flex; gap: 8px; align-items: baseline; }
.note-head h2 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.note-head h2 a { text-decoration: none; }
.note-head h2 a:hover { text-decoration: underline; }
.note-head small { color: var(--faint); font-size: 12px; white-space: nowrap; }
.note-cover { position: relative; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.note-cover img { width: 100%; max-height: 220px; object-fit: cover; }
.note-cover .badge { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.note-acts { display: flex; flex-wrap: wrap; gap: 4px; }
.more { font-size: 12.5px; color: var(--primary); }
.lines { display: grid; gap: 4px; }
.ln { display: flex; flex-wrap: wrap; gap: 4px; }
.ln button { border: 1px solid transparent; background: var(--surface-2); border-radius: 6px; padding: 3px 8px; text-align: left; font-size: 13.5px; overflow-wrap: anywhere; max-width: 100%; }
.ln button:hover { border-color: var(--primary); }
.ln.seg-line button { font-family: var(--font-data); font-size: 12.5px; }
.ln.gap { height: 6px; }
.copied { background: var(--ok-soft) !important; border-color: var(--ok) !important; }
.media-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.media-card { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); display: grid; }
.media-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.media-card figcaption { padding: 8px 10px; display: grid; gap: 6px; }
.media-name { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.media-acts { display: flex; gap: 4px; flex-wrap: wrap; }
.media-acts form { margin: 0; }

/* 提示条 */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 13.5px; display: flex; gap: 12px; align-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px); }
.toast button { border: 0; background: none; color: var(--bg); text-decoration: underline; font-weight: 600; padding: 0; }

@media (max-width: 560px) {
    .topbar-in { gap: 8px; padding-block: 6px; }
    .tabs { margin-left: 0; order: 3; width: 100%; }
    .tab { flex: 1; text-align: center; }
    .menu { margin-left: auto; }
    .send-actions { width: 100%; }
    .send-actions .btn.big { flex: 1; }
    .rows-head, .rows-line { grid-template-columns: minmax(0, 1fr) 72px 36px 80px; }
    .rows-head span, .rows-line span { padding-inline: 6px; }
    .rows-ed-head, .row-ed { grid-template-columns: minmax(0, 1fr) 78px 48px 28px; }
    .notes { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
