/*
 * 报单系统 · 手机优先
 * 底子沿用二手书账本那套（输入框一律 16px 防 iOS 放大、点击区 ≥44px、深色自动切换），主色换成蓝。
 */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-soft: #eef2fb;
  --ink: #1a1f2b;
  --muted: #6b7385;
  --line: #dde2ec;
  --accent: #2f54eb;
  --accent-strong: #2441c2;
  --accent-ink: #ffffff;
  --neg: #d23b3b;
  --pos: #1f8a5b;
  --warn: #a35f00;
  --warn-bg: #fff6dc;
  --warn-line: #ecc75a;
  --ok-bg: #e5f4ec;
  --err-bg: #fdeaea;
  --amber: #f08c00;
  --shadow: 0 6px 20px rgba(30, 45, 90, 0.06);
  --radius-sm: 10px;
  --radius-md: 14px;
  --touch: 46px;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #181c25;
    --surface-soft: #1f2636;
    --ink: #e9edf5;
    --muted: #9aa3b5;
    --line: #2d3445;
    --accent: #7b96ff;
    --accent-strong: #9aafff;
    --accent-ink: #0f1430;
    --neg: #ff8a85;
    --pos: #6fd3a2;
    --warn: #f2c25c;
    --warn-bg: #2e2714;
    --warn-line: #6e5a1d;
    --ok-bg: #173126;
    --err-bg: #3a1f1f;
    --amber: #ffb547;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); }
main {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 12px 14px calc(var(--nav-h) + 72px + env(safe-area-inset-bottom));
}
h1 { margin: 0 0 12px; font-size: 1.25rem; line-height: 1.3; }
h2 { margin: 22px 0 10px; font-size: 1.05rem; line-height: 1.35; }
h2.first, h3:first-child { margin-top: 0; }
h3 { margin: 18px 0 8px; font-size: 1rem; }
.mono, .big, .mid { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.pos { color: var(--pos); }
.neg, .danger-text { color: var(--neg); }
.warn-text { color: var(--warn); }
.wrap { overflow-wrap: anywhere; word-break: break-word; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.empty { padding: 32px 0; text-align: center; }
.spaced { margin-top: 14px; }
[hidden] { display: none !important; }

/* 顶栏、底栏 */
.top {
  position: sticky; top: 0; z-index: 10;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top-inner { display: flex; width: min(100%, 720px); margin: 0 auto; align-items: baseline; gap: 10px; }
.site { color: var(--accent); font-size: 0.8rem; font-weight: 800; white-space: nowrap; }
.page-title { min-width: 0; margin: 0; overflow: hidden; font-size: 1.15rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav {
  position: fixed; z-index: 20; right: 0; bottom: 0; left: 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 4px 8px env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.bottom-nav.five { grid-template-columns: repeat(5, minmax(0, 1fr)); padding-right: 4px; padding-left: 4px; }
.bottom-nav a {
  display: flex; min-width: 0; min-height: 56px; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: var(--radius-sm); color: var(--muted); font-size: 0.75rem; font-weight: 700; text-decoration: none;
}
.bottom-nav a.on { color: var(--accent); background: var(--surface-soft); }
.bottom-nav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* 卡片 */
.card {
  margin: 0 0 12px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 28px auto; }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); box-shadow: none; }
.hero .big { margin: 2px 0 12px; font-size: clamp(1.9rem, 9vw, 2.6rem); font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; }
.label { color: var(--muted); font-size: 0.85rem; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 8px; }
.trio > div { min-width: 0; padding: 10px; background: var(--surface-soft); border-radius: var(--radius-sm); }
.mid { font-size: clamp(0.95rem, 4.4vw, 1.15rem); font-weight: 800; white-space: nowrap; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 12px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { min-width: 0; margin: 0; text-align: right; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.stat { display: flex; min-width: 0; flex-direction: column; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; }
.stat.hot { border-color: var(--amber); }
.stat.hot b { color: var(--amber); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.row-actions .button { flex: 1 1 auto; }

/* 控件 */
input, select, button, textarea { color: inherit; font: inherit; }
input, select, textarea {
  width: 100%; min-height: var(--touch); padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px; line-height: 1.4; outline: none;
}
textarea { resize: vertical; }
input:disabled { color: var(--muted); background: var(--surface-soft); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 84, 235, 0.16); }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7385' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input[type="date"] { appearance: none; min-width: 0; }
button, .button {
  display: inline-flex; min-height: var(--touch); align-items: center; justify-content: center; padding: 9px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--ink); cursor: pointer; font-weight: 700; text-decoration: none; white-space: nowrap;
}
button:active, .button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button.primary { width: 100%; min-height: 50px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 800; }
button.primary-btn { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
button.wide { width: 100%; }
.small-btn { min-height: 44px; padding: 6px 14px; font-size: 0.875rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > label, .two > label, .inline-form > label { display: flex; flex-direction: column; gap: 5px; font-size: 0.875rem; font-weight: 700; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.check { display: flex !important; min-height: 40px; flex-direction: row !important; align-items: center; gap: 8px; font-weight: 600 !important; }
.check input, .radios input { width: 20px; min-height: 20px; padding: 0; flex: 0 0 auto; }
.radios { display: flex; gap: 6px 18px; flex-wrap: wrap; margin: 0; padding: 0; border: 0; }
.radios label { display: flex; min-height: 40px; align-items: center; gap: 6px; font-weight: 600; }
.field-err { color: var(--neg); font-size: 0.85rem; font-weight: 700; }
.hint { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.copy-src { font-size: 16px; }

/* 提示 */
.flash { margin: 0 0 12px; padding: 11px 14px; border-radius: var(--radius-sm); }
.flash.ok { background: var(--ok-bg); }
.flash.warn { background: var(--warn-bg); }
.flash.err { background: var(--err-bg); color: var(--neg); }
.result p { margin: 4px 0; }
.ok-line { color: var(--pos); }
.err-line { color: var(--neg); }
.bad-lines { margin: 4px 0; padding-left: 20px; font-size: 0.9rem; }
.acct { display: flex; flex-direction: column; gap: 3px; }
.acct-v { font-weight: 700; }

/* 筛选标签、搜索、翻页、合计条 */
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0 0 10px; }
.tabs.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tabs.two-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tabs a { display: flex; min-width: 0; min-height: 40px; align-items: center; justify-content: center; padding: 6px 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; color: var(--ink); font-size: 0.9rem; font-weight: 700; text-decoration: none; white-space: nowrap; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin: 0 0 12px; }
.filter-box { margin: 0 0 12px; padding: 0 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.filter-box[open] { padding-bottom: 14px; }
.pager { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin: 12px 0; }
.pager > :last-child { justify-self: end; }
.sumbar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; margin: 12px 0 0; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 0.9rem;
}
.sumbar b.mono { color: var(--amber); }

/* 单据卡片 */
.order { margin: 0 0 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow); }
.order.s-void { opacity: 0.55; }
.o-top { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 6px; }
.wb { min-width: 0; flex: 1 1 auto; font-weight: 800; color: var(--ink); text-decoration: none; }
a.wb { color: var(--accent); }
.big-wb { font-size: 1.1rem; }
.chip { flex: 0 0 auto; padding: 1px 8px; background: var(--surface-soft); border-radius: 999px; color: var(--muted); font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.chip.s-pending { color: var(--muted); }
.chip.s-arrived { background: var(--warn-bg); color: var(--warn); }
.chip.s-settled { background: var(--ok-bg); color: var(--pos); }
.chip.s-void { background: var(--err-bg); color: var(--neg); }
.chip.c-admin { background: var(--surface-soft); color: var(--accent); }
.chip.c-warn { background: var(--warn-bg); color: var(--warn); }
.chip.c-new { background: var(--ok-bg); color: var(--pos); }
.fresh-line { display: block; padding: 12px 16px; color: var(--ink); text-decoration: none; font-size: 0.92rem; }
.fresh-line b { color: var(--accent); }
.fresh-line.hot { border-color: var(--amber); }
.review-list { margin: 0; padding: 0; list-style: none; }
.review-list > li { padding: 12px 0; border-top: 1px solid var(--warn-line); }
.review-act { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: end; }
.review-act .inline-form { flex: 1 1 100%; }
.o-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 3px; color: var(--muted); font-size: 0.8rem; }
.items { margin: 8px 0 0; padding: 6px 10px; background: var(--surface-soft); border-radius: var(--radius-sm); list-style: none; }
.items li, .d-row { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; padding: 3px 0; font-size: 0.9rem; }
.items .nm { min-width: 0; }
.items .pq { flex: 0 0 auto; white-space: nowrap; }
.minus .pq, .d-row.minus .mono { color: var(--neg); }
.o-sum { margin-top: 6px; text-align: right; font-size: 0.9rem; }
.o-sum b { color: var(--amber); }
.o-empty { margin-top: 6px; }
.o-cost { margin-top: 2px; text-align: right; }
.o-note { margin-top: 6px; padding: 6px 10px; background: var(--surface-soft); border-radius: 8px; font-size: 0.85rem; overflow-wrap: anywhere; }
.o-act { margin-top: 8px; text-align: right; }

/* 单据详情：商品编辑 */
.edit-items { margin: 0 0 8px; padding: 0; list-style: none; }
.edit-items > li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.item-edit > summary { display: inline-block; min-height: 44px; padding: 10px 12px 10px 0; color: var(--accent); cursor: pointer; font-size: 0.85rem; font-weight: 700; }
.item-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 8px 0; }
.item-form .f-name, .item-form .f-note, .item-form .inline { grid-column: 1 / -1; }
.add-items .item-form + .item-form { border-top: 1px dashed var(--line); }
.item-head { display: none; }
.inline { display: flex; gap: 8px; justify-content: flex-end; }
@media (min-width: 560px) {
  .item-form { grid-template-columns: minmax(0, 1fr) 4.5em 7em minmax(0, 0.6fr); }
  .item-form .f-name { grid-column: auto; }
  .item-form .f-note { grid-column: auto; }
  .add-items .item-head { display: grid; grid-template-columns: minmax(0, 1fr) 4.5em 7em minmax(0, 0.6fr); gap: 6px; }
}
.log summary, details.card > summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.history { margin: 8px 0 0; padding-left: 18px; font-size: 0.875rem; }
.history li { margin: 3px 0; }
.howto > summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.steps { margin: 10px 0 0; padding-left: 20px; font-size: 0.92rem; }
.steps li { margin: 6px 0; }

/* 对账单 */
details.day { padding: 0; }
details.day > summary { color: var(--ink); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; padding: 12px 14px; list-style: none; cursor: pointer; }
details.day > summary::-webkit-details-marker { display: none; }
.d-date { font-weight: 800; }
.d-nums { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.875rem; }
details.day[open] > summary { border-bottom: 1px solid var(--line); }
details.day .d-order, details.day .d-row.pay { margin: 0 14px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
details.day > :last-child { border-bottom: 0; }
.d-row.pay small { display: block; }

/* 报单人列表 */
.people { margin: 0; padding: 0; list-style: none; }
.people li a { display: block; margin: 0 0 8px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); color: var(--ink); text-decoration: none; }
.people li.off a { opacity: 0.55; }
.p-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.p-bal { margin-left: auto; font-weight: 800; }
.p-bal.owe { color: var(--amber); }
.pays { margin: 8px 0 0; padding: 0; list-style: none; }
.pays li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.pays li.void { opacity: 0.5; }
.pays li.void .mono { text-decoration: line-through; }
.plain { margin: 0; padding-left: 18px; }

/* 身份证照片 */
.photo-pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.photo-box { display: flex !important; min-width: 0; flex-direction: column; gap: 6px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }
.photo-label { font-weight: 700; font-size: 0.875rem; }
.photo-box input[type="file"] { min-height: 44px; padding: 8px; font-size: 14px; background: var(--surface); }
.photo-box img { width: 100%; max-height: 160px; object-fit: contain; border-radius: 8px; background: #000; }
.thumbs { display: flex; gap: 8px; margin: 8px 0; }
.thumbs a { display: flex; min-width: 0; flex: 1 1 0; flex-direction: column; gap: 4px; text-decoration: none; }
.thumbs img { width: 100%; height: 90px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.thumbs.big img { height: 150px; object-fit: contain; background: #000; }
@media (max-width: 380px) { .photo-pick { grid-template-columns: minmax(0, 1fr); } }

/* 批量贴表预览 */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.pv { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.pv th, table.pv td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.pv th { color: var(--muted); font-weight: 700; white-space: nowrap; }
table.pv td.mono { white-space: nowrap; }
table.pv tr.bad td { color: var(--neg); }
table.pv tr.dup td { color: var(--warn); }

@media (max-width: 380px) {
  main { padding-right: 10px; padding-left: 10px; }
  .card { padding: 14px 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trio { grid-template-columns: minmax(0, 1fr); }
  .trio > div { display: flex; align-items: baseline; justify-content: space-between; }
  .tabs a { font-size: 0.85rem; }
}
