/* ==========================================================================
   设计变量
   ========================================================================== */
:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --surface-2: #f8f9fb;
  --fg: #1f2329;
  --fg-2: #4b5563;
  --muted: #8a919c;
  --line: #e6e8eb;
  --line-strong: #d5d9de;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef3ff;
  --warn: #b45309;
  --warn-bg: #fff8e1;
  --warn-line: #f3dc94;
  --err: #d92d20;
  --err-bg: #fef3f2;
  --err-line: #fecdca;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --ok-line: #abefc6;
  --purple: #6941c6;
  --purple-bg: #f4f3ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-pop: 0 8px 24px rgba(16, 24, 40, 0.12);
  --sidebar-w: 196px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { font-size: 14px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

h1 { font-size: 1.45rem; font-weight: 650; margin: 0 0 1rem; letter-spacing: 0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; }
h1 .muted, h2 .muted { font-weight: 400; }

.muted { color: var(--muted); }
.err { color: var(--err); }
.ok { color: var(--ok); }
.small { font-size: 0.86rem; }
.nowrap { white-space: nowrap; }
.diff { background: var(--warn-bg); }
[hidden] { display: none !important; }

/* ==========================================================================
   整体布局：左侧导航 + 内容区
   ========================================================================== */
.app-body { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid var(--line);
  z-index: 20;
}

.brand { padding: 1rem 1rem 0.6rem; }
.brand a { display: flex; align-items: center; gap: 0.55rem; color: var(--fg); font-weight: 650; font-size: 1.05rem; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
}

.nav { flex: 1 1 auto; overflow-y: auto; padding: 0.25rem 0.6rem 1rem; }
.nav-group + .nav-group { margin-top: 0.6rem; }
.nav-title { padding: 0 0.6rem 0.25rem; font-size: 0.78rem; color: var(--muted); letter-spacing: 0.05em; }
.nav a {
  display: block;
  padding: 0.36rem 0.6rem;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--fg-2);
}
.nav a:hover { background: var(--surface-2); color: var(--fg); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-user { border-top: 1px solid var(--line); padding: 0.75rem 1rem; font-size: 0.9rem; }
.user-name { font-weight: 600; display: flex; align-items: baseline; gap: 0.4rem; }
.user-name .muted { font-weight: 400; font-size: 0.82rem; }
.user-links { display: flex; align-items: center; gap: 0.9rem; margin-top: 0.2rem; }
.user-links a, .user-links .link-button { color: var(--muted); font-size: 0.86rem; }
.user-links a:hover { color: var(--accent); }

.logout-form { margin: 0; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--fg-2);
  font: inherit;
  cursor: pointer;
  height: auto;
  min-height: 0;
}
.link-button:hover { background: none; color: var(--err); }

.container { flex: 1 1 auto; min-width: 0; max-width: 1360px; padding: 1.5rem 2rem 3rem; }

/* ==========================================================================
   页面头部、卡片
   ========================================================================== */
.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }
.page-sub { color: var(--muted); font-size: 0.92rem; margin: -0.6rem 0 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: baseline; justify-content: space-between; margin-bottom: 0.75rem; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .table-wrap > table { border: none; }
.card.flush > .card-foot, .card.flush > .empty { padding: 0.8rem 1.25rem; margin: 0; }

.link-card { display: block; color: inherit; }
.link-card:hover { border-color: var(--accent); color: inherit; }
.link-card p { color: var(--muted); margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }

.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; margin: 0; }

/* ==========================================================================
   表格
   ========================================================================== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.93rem;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: middle;
}

thead th {
  background: var(--surface-2);
  color: var(--fg-2);
  font-weight: 600;
  font-size: 0.86rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
tbody tr:hover td { background: #f7f9fc; }
tbody tr:last-child td { border-bottom-color: var(--line); }
tfoot td { font-weight: 600; background: var(--surface-2); border-bottom: none; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.date, th.date { white-space: nowrap; }
.doc-no { font-family: var(--mono); font-size: 0.9em; white-space: nowrap; }
td .badge { white-space: nowrap; }

tr.clickable { cursor: pointer; }

/* ==========================================================================
   表单
   ========================================================================== */
form .field { margin-bottom: 0.85rem; }
label { display: block; font-weight: 500; color: var(--fg-2); font-size: 0.88rem; margin-bottom: 0.3rem; }

input, select, textarea {
  width: 100%;
  height: 2.35rem;
  padding: 0 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--fg);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; padding: 0.5rem 0.7rem; }
input[type="checkbox"], input[type="radio"] { width: auto; height: auto; }
input::placeholder { color: #b0b6bf; }
input:hover, select:hover { border-color: #b9c0c9; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
input:disabled { background: var(--surface-2); color: var(--muted); }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 2.35rem;
  padding: 0 1rem;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover, .button:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary, .button.secondary {
  background: #fff;
  color: var(--fg);
  border-color: var(--line-strong);
}
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); color: var(--fg); border-color: #b9c0c9; }

button.ghost, .button.ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
button.ghost:hover, .button.ghost:hover { background: var(--surface-2); color: var(--fg); border-color: transparent; }

button.danger, .button.danger { background: #fff; color: var(--err); border-color: var(--err-line); }
button.danger:hover, .button.danger:hover { background: var(--err-bg); color: var(--err); border-color: var(--err); }

button.sm, .button.sm { height: 1.95rem; padding: 0 0.7rem; font-size: 0.88rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.actions .spacer { flex: 1 1 auto; }

.alert {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }
.alert.err { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.alert.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }

.inline-form { display: flex; gap: 0.5rem; align-items: center; margin: 0; }
.inline-form input, .inline-form select { width: auto; min-width: 10rem; }
.inline-form label { margin: 0; }

.filter-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.filter-form .field { margin-bottom: 0; }
.filter-form input, .filter-form select { width: auto; min-width: 11rem; }
.filter-form .filter-actions { display: flex; gap: 0.5rem; }

.user-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.user-form .field { margin-bottom: 0; }

.checkbox { width: auto; }
.checkbox-label { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 400; color: var(--fg); margin: 0; cursor: pointer; }
.field-hint { color: var(--muted); font-size: 0.82rem; margin: 0.3rem 0 0; }

/* 折叠的行内操作 */
details.row-menu > summary { list-style: none; cursor: pointer; color: var(--accent); white-space: nowrap; }
details.row-menu > summary::-webkit-details-marker { display: none; }
details.row-menu[open] > summary { margin-bottom: 0.5rem; }
details.row-menu .inline-form + .inline-form { margin-top: 0.4rem; }

/* ==========================================================================
   徽标 / 标签
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  height: 1.45rem;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--fg-2);
  white-space: nowrap;
  font-weight: 500;
}
.badge.locked { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge.err, .badge-err { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.badge-draft { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge-confirmed { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.badge-voided { background: var(--surface-2); border-color: var(--line); color: var(--muted); }
.badge-qr { background: var(--accent-soft); border-color: #c7d7fe; color: var(--accent-dark); }
.badge-manual { background: var(--surface-2); border-color: var(--line); color: var(--fg-2); }
.badge-match { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.badge-qty { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge-customer { background: var(--accent-soft); border-color: #c7d7fe; color: var(--accent-dark); }
.badge-ledger-only { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.badge-yonbip-only { background: var(--purple-bg); border-color: #d9d6fe; color: var(--purple); }
.badge-running { background: #f0f9ff; border-color: #b9e6fe; color: #026aa2; }

.code-chip {
  display: inline-block;
  margin: 0.1rem 0.3rem 0.1rem 0;
  padding: 0 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.84rem;
}

/* ==========================================================================
   期间切换器
   ========================================================================== */
.period-picker { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.period-switch {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}
.period-switch a {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  color: var(--fg-2);
  font-size: 1.1rem;
}
.period-switch a:hover { background: var(--surface-2); color: var(--accent); }
.period-switch form { margin: 0; display: flex; }
.period-switch input[type="month"] {
  width: 10.5rem;
  min-width: 0;
  padding: 0 0.5rem;
  border: none;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: 0;
  text-align: center;
  font-weight: 600;
}
.period-switch input[type="month"]:focus { box-shadow: none; background: var(--accent-soft); }

/* 分段选择（品类等） */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: #eceef1; flex-wrap: wrap; }
.segmented a {
  padding: 0.25rem 0.8rem;
  border-radius: 6px;
  color: var(--fg-2);
  font-size: 0.9rem;
  white-space: nowrap;
}
.segmented a:hover { color: var(--fg); }
.segmented a.active { background: #fff; color: var(--fg); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1); }
.segmented .tab-count { margin-left: 0.25rem; color: var(--muted); font-weight: 400; font-size: 0.82rem; }

/* ==========================================================================
   首页
   ========================================================================== */
.home-stats { margin-bottom: 1rem; }
.stat-card { display: flex; flex-direction: column; gap: 0.15rem; color: inherit; margin: 0; }
.stat-card:hover { border-color: var(--accent); color: inherit; }
.stat-label { color: var(--fg-2); font-size: 0.9rem; order: -1; }
.stat-value { font-size: 1.9rem; font-weight: 650; line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: 0.84rem; }
.stat-alert { border-color: var(--err-line); }
.stat-alert .stat-value { color: var(--err); }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.quick-action {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.15rem;
  margin: 0;
  color: inherit;
}
.quick-action:hover { border-color: var(--accent); color: inherit; }
.quick-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 700;
}
.quick-action strong { display: block; font-size: 1rem; }
.quick-action span.muted { font-size: 0.86rem; }
.section-title { font-size: 0.9rem; color: var(--muted); font-weight: 500; margin: 1.5rem 0 0.6rem; }

/* ==========================================================================
   登录
   ========================================================================== */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef3ff 0%, var(--bg) 55%);
}
.login-wrap { width: 100%; max-width: 380px; padding: 1rem; }
.login-card { padding: 2rem 1.75rem 1.5rem; box-shadow: var(--shadow-pop); border: none; }
.login-card .brand-mark { width: 2.6rem; height: 2.6rem; font-size: 1.2rem; border-radius: 10px; margin: 0 auto 0.75rem; display: grid; }
.login-card h1 { font-size: 1.2rem; margin: 0 0 0.25rem; text-align: center; }
.login-card .login-sub { text-align: center; color: var(--muted); margin: 0 0 1.5rem; font-size: 0.9rem; }
.login-card button { width: 100%; height: 2.6rem; margin-top: 0.4rem; }

/* ==========================================================================
   基础资料
   ========================================================================== */
.subnav { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; margin: 0 0 1rem; border-bottom: 1px solid var(--line); }
.subnav a { padding: 0.5rem 0; margin-bottom: -1px; color: var(--fg-2); border-bottom: 2px solid transparent; }
.subnav a:hover { color: var(--fg); }
.subnav a.active { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }

.form-narrow { max-width: 560px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }

/* ==========================================================================
   台账
   ========================================================================== */
.ledger-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1rem; align-items: start; }
.ledger-sidebar { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; padding: 0.75rem 0.5rem; }
.ledger-main { min-width: 0; }

.mobile-picker { display: none; }
.sidebar-search { padding: 0 0.35rem 0.6rem; }
.sidebar-search input { height: 2.1rem; }
.sidebar-group { margin-bottom: 0.75rem; }
.sidebar-group h2 { font-size: 0.8rem; margin: 0 0 0.2rem; padding: 0 0.5rem; color: var(--muted); font-weight: 500; letter-spacing: 0.05em; }
.sidebar-all { display: block; padding: 0.4rem 0.5rem; margin-bottom: 0.5rem; border-radius: var(--radius-sm); color: var(--fg); font-weight: 500; }
.sidebar-all:hover { background: var(--surface-2); color: var(--fg); }
.sidebar-all.active { background: var(--accent-soft); color: var(--accent); }
.product-list { list-style: none; margin: 0; padding: 0; }
.product-list li a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name qty" "spec qty";
  column-gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  color: var(--fg);
  border-radius: var(--radius-sm);
}
.product-list li a:hover { background: var(--surface-2); color: var(--fg); }
.product-list li.active a { background: var(--accent-soft); }
.product-list li.active .product-name { color: var(--accent); font-weight: 600; }
.product-list .product-name { grid-area: name; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-list .product-spec { grid-area: spec; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-list .product-spec:empty { display: none; }
.product-list .num { grid-area: qty; align-self: center; font-weight: 600; color: var(--fg-2); }
.product-list .num.err { color: var(--err); }

.ledger-head { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: baseline; margin-bottom: 0.75rem; }
.ledger-head h2 { margin: 0; }
.hint { font-size: 0.86rem; color: var(--muted); margin: 0 0 0.75rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.kpi { padding: 0.65rem 0.85rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.kpi .kpi-label { font-size: 0.8rem; color: var(--muted); }
.kpi .kpi-value { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .kpi-unit { font-size: 0.8rem; color: var(--muted); font-weight: 400; margin-left: 0.15rem; }
.kpi.negative .kpi-value { color: var(--err); }

.ledger-table tbody tr.ledger-row { cursor: pointer; }
.ledger-table tbody tr.pick-row td { color: var(--muted); }
.ledger-table tbody tr.err td { color: var(--err); background: var(--err-bg); }
.ledger-table tbody tr.opening-row td { font-weight: 600; background: var(--surface-2); }
.ledger-table tbody tr.opening-row.err td { color: var(--err); background: var(--err-bg); }
.ledger-table .source { text-align: center; white-space: nowrap; }
.ledger-table td.dim { color: #c4c9d0; }
.tons-summary { margin-top: 0.75rem; padding: 0.55rem 0.8rem; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.9rem; }

.summary-table tbody tr.err td { color: var(--err); background: var(--err-bg); }
.summary-table td:first-child, .summary-table td:nth-child(2) { white-space: nowrap; }

.promo-matrix th[scope="row"] { background: transparent; font-weight: 500; white-space: nowrap; }
.promo-matrix tr.opening-row th[scope="row"] { font-weight: 600; }

/* ==========================================================================
   单据
   ========================================================================== */
.doc-filter .field-q input { min-width: 14rem; }
.doc-table tbody tr.doc-row { cursor: pointer; }
.doc-table .qty-cell { color: var(--fg-2); font-size: 0.88rem; max-width: 22rem; white-space: normal; }
.doc-head { display: flex; flex-wrap: wrap; gap: 0.4rem 0.7rem; align-items: center; margin-bottom: 1rem; }
.doc-kind { font-weight: 650; font-size: 1.15rem; }
.doc-head .doc-no { font-size: 1.05rem; color: var(--fg-2); }
.voided-text { text-decoration: line-through; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.85rem 1.5rem; margin: 0; }
.detail-grid > div { min-width: 0; }
.detail-grid .wide { grid-column: 1 / -1; }
.detail-grid dt { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.1rem; }
.detail-grid dd { margin: 0; word-break: break-word; }
.doc-lines tbody tr.src-row td { color: var(--muted); font-size: 0.86rem; background: var(--surface-2); }
.doc-lines td.diff { background: var(--warn-bg); }
.void-box > summary { cursor: pointer; color: var(--err); list-style: none; display: inline-block; }
.void-box > summary::-webkit-details-marker { display: none; }
.void-form { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; margin-top: 0.75rem; }
.void-form .field { margin-bottom: 0; flex: 1 1 18rem; max-width: 28rem; }
.pagination { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; justify-content: flex-end; }
.history { list-style: none; padding: 0; margin: 0; }
.history > li { position: relative; padding: 0 0 0.9rem 1.1rem; border-left: 2px solid var(--line); margin-left: 0.3rem; }
.history > li:last-child { padding-bottom: 0; }
.history > li::before { content: ""; position: absolute; left: -6px; top: 0.4rem; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--line-strong); }
.history-head { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center; }
.history-diff { margin: 0.3rem 0 0; padding-left: 1.2rem; color: var(--fg-2); font-size: 0.9rem; }
.raw-json { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem; overflow-x: auto; font-size: 0.82rem; max-height: 26rem; }
.totals-summary { margin-top: 0.75rem; font-size: 0.92rem; color: var(--fg-2); }
.totals-summary strong { color: var(--fg); }

/* 页面底部操作条 */
.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 1rem -2rem -3rem;
  padding: 0.75rem 2rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.06);
  backdrop-filter: blur(6px);
}
.action-bar .spacer { flex: 1 1 auto; }
.action-bar .bar-note { color: var(--muted); font-size: 0.86rem; }

/* ==========================================================================
   扫码
   ========================================================================== */
.scan-card { max-width: 720px; }
.scan-reader { width: 100%; max-width: 420px; margin: 0 auto 1rem; }
.scan-reader video { width: 100%; border-radius: 8px; }
.scan-hint { font-size: 0.85rem; margin: 0.6rem 0 0; color: var(--muted); }
.scan-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: stretch; }
.scan-form .field { flex: 1 1 16rem; margin-bottom: 0; }
.scan-form input { height: 2.9rem; font-size: 1.1rem; font-family: var(--mono); }
.scan-form button { height: 2.9rem; padding: 0 1.5rem; }
.scan-form .scan-bill { flex: 0 1 9rem; }
.scan-form select { height: 2.9rem; font-size: 1rem; }
.scan-camera { margin-top: 0.85rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.draft-list { list-style: none; margin: 0; padding: 0; }
.draft-list li + li { border-top: 1px solid var(--line); }
.draft-link { display: flex; flex-wrap: wrap; gap: 0.15rem 0.8rem; align-items: baseline; padding: 0.6rem 0.4rem; color: var(--fg); border-radius: var(--radius-sm); }
.draft-link:hover { background: var(--surface-2); color: var(--fg); }
.draft-link::after { content: "›"; margin-left: auto; color: var(--muted); }
.draft-no { font-weight: 600; font-family: var(--mono); }
.draft-meta { color: var(--muted); font-size: 0.86rem; }
.candidate-form { display: flex; gap: 0.8rem; align-items: center; justify-content: space-between; padding: 0.6rem 0.4rem; }
.candidate-form .draft-meta { margin-top: 0.15rem; }

.review-header { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.review-header .field { margin-bottom: 0.75rem; }
.readonly-value { min-height: 2.35rem; display: flex; align-items: center; word-break: break-all; }
.src-note { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

.review-table .line-input { width: 6.5rem; height: 2rem; text-align: right; }
.review-table .batch-input { width: 9rem; text-align: left; font-family: var(--mono); font-size: 0.85rem; }
.review-table td.diff,
.review-table tbody tr:hover td.diff { background: var(--warn-bg); }
.review-table td.err { color: var(--err); font-weight: 600; }

/* ==========================================================================
   手工录入
   ========================================================================== */
.kind-tabs { margin: 0 0 1rem; }
.kind-tabs.static a, .kind-tabs.static span { cursor: default; }
.kind-tab { padding: 0.25rem 0.8rem; border-radius: 6px; color: var(--fg-2); font-size: 0.9rem; white-space: nowrap; }
.kind-tab.active { background: #fff; color: var(--fg); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1); }
.editor-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.85rem 1rem; }
.editor-fields .field { margin-bottom: 0; }
.editor-fields .field.wide { grid-column: span 2; }
.lines-table td { vertical-align: middle; padding: 0.45rem 0.5rem; }
.lines-table th { padding: 0.5rem; }
.lines-table input { height: 2.15rem; }
.lines-table .col-product { min-width: 15rem; }
.lines-table td.col-qty, .lines-table td.col-amount { text-align: right; }
.lines-table .col-qty input, .lines-table .col-amount input { width: 7rem; text-align: right; }
.lines-table .qty-unit { display: inline-block; min-width: 1.5em; margin-left: 0.35rem; color: var(--muted); text-align: left; }
.lines-table .balance-preview { white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines-table .balance-preview.negative { color: var(--err); font-weight: 600; }
.lines-table .remove-row { width: 2rem; height: 2rem; padding: 0; font-size: 1.1rem; line-height: 1; color: var(--muted); }
.lines-table .remove-row:hover { color: var(--err); background: var(--err-bg); }
.lines-foot { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; padding-top: 0.75rem; }
.docno-warning { color: var(--warn); margin: 0.3rem 0 0; font-size: 0.85rem; }

/* ==========================================================================
   自检
   ========================================================================== */
.check-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.chip { display: inline-flex; align-items: center; height: 1.6rem; padding: 0 0.7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg-2); font-size: 0.86rem; white-space: nowrap; }
.chip-error { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.chip-warning { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.chip-info { background: var(--accent-soft); border-color: #c7d7fe; color: var(--accent-dark); }
.chip-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.check-rule { padding: 0; }
.check-rule summary { cursor: pointer; list-style: none; padding: 0.85rem 1.25rem; }
.check-rule summary::-webkit-details-marker { display: none; }
.check-rule summary::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 1.2rem; transition: transform 0.15s; }
.check-rule[open] summary::after { transform: rotate(90deg); }
.check-rule > :not(summary) { margin-left: 1.25rem; margin-right: 1.25rem; }
.check-rule > :last-child { margin-bottom: 1rem; }
.check-rule.passed summary { color: var(--fg-2); }
.check-summary { display: flex; flex-wrap: wrap; gap: 0.4rem 0.7rem; align-items: center; }
.check-title { font-weight: 600; font-size: 1rem; }
.check-pass { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.check-sev.error { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.check-sev.warning { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.check-sev.info { background: var(--accent-soft); border-color: #c7d7fe; color: var(--accent-dark); }
.check-desc { font-size: 0.88rem; margin-top: 0; margin-bottom: 0.75rem; }
.check-pass-text { margin: 0 0 1rem; }
.checks-table td:last-child { white-space: nowrap; }
.check-links a + a { margin-left: 0.75rem; }

/* ==========================================================================
   对账
   ========================================================================== */
.reconcile-form input[type="month"] { min-width: 10rem; }
.reconcile-tabs { margin: 0 0 1rem; }
.reconcile-table .reconcile-note { color: var(--fg-2); font-size: 0.86rem; }
.reconcile-table .reconcile-actions { min-width: 12rem; }
.reconcile-table .reconcile-actions .inline-form input { min-width: 8rem; height: 2rem; }
.reconcile-table .reconcile-actions > * + * { margin-top: 0.4rem; }
.reconcile-resolved { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: center; }
.reconcile-progress { margin-top: 0.75rem; }
.progress-bar { height: 0.5rem; border-radius: 999px; background: #eceef1; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.4s ease; }
.reconcile-progress p { margin: 0.4rem 0 0; font-size: 0.88rem; }

/* ==========================================================================
   日志
   ========================================================================== */
.audit-table pre { white-space: pre-wrap; word-break: break-all; font-size: 0.8rem; background: var(--surface-2); padding: 0.5rem; border-radius: var(--radius-sm); }

/* ==========================================================================
   窄屏：侧栏变为顶部横向导航
   ========================================================================== */
@media (max-width: 1100px) {
  .container { padding: 1.25rem 1.25rem 3rem; }
  .action-bar { margin: 1rem -1.25rem -3rem; padding-left: 1.25rem; padding-right: 1.25rem; }
}

@media (max-width: 900px) {
  .app-body { flex-direction: column; }
  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0.55rem 0.75rem; }
  .brand-text { display: none; }
  .nav {
    display: flex;
    padding: 0.4rem 0.25rem;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-group { display: flex; }
  .nav-group + .nav-group { margin: 0 0 0 0.6rem; padding-left: 0.6rem; border-left: 1px solid var(--line); }
  .nav-title { display: none; }
  .nav a { white-space: nowrap; padding: 0.4rem 0.6rem; margin: 0; }
  .sidebar-user { flex: 0 0 auto; border-top: none; border-left: 1px solid var(--line); padding: 0 0.75rem; }
  .sidebar-user .user-name, .sidebar-user .user-links a { display: none; }
  .sidebar-user .user-links { margin: 0; }
  .container { padding: 1rem 0.9rem 3rem; }
  .ledger-layout { grid-template-columns: 1fr; }
  .ledger-sidebar { position: static; max-height: none; padding: 0.75rem; }
  .ledger-sidebar .mobile-picker { display: block; }
  .ledger-sidebar .product-groups, .ledger-sidebar .sidebar-search { display: none; }
  .action-bar { margin: 1rem -0.9rem -3rem; padding-left: 0.9rem; padding-right: 0.9rem; }
}

@media (max-width: 640px) {
  h1 { font-size: 1.25rem; }
  .card { padding: 0.9rem; }
  table { font-size: 0.86rem; }
  th, td { padding: 0.45rem 0.5rem; }
  .filter-form input, .filter-form select { min-width: 0; width: 100%; }
  .filter-form .field { flex: 1 1 45%; }
  .scan-form button { width: 100%; }
  .review-table .line-input { width: 5rem; }
  .review-table .batch-input { width: 7rem; }
  .action-bar button, .action-bar .button { flex: 1 1 40%; height: 2.75rem; }
  .action-bar .ghost { flex: 0 1 auto; height: 2.2rem; font-size: 0.9rem; }
  .action-bar .spacer, .action-bar .bar-note { display: none; }
  .editor-fields .field.wide { grid-column: span 1; }
  .inline-form { flex-wrap: wrap; }

  /* 手工录入的明细行改成卡片，每个字段一行 */
  .lines-table thead { display: none; }
  .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }
  .lines-table tr.line-row {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.6rem;
    background: #fff;
  }
  .lines-table td { border: none; padding: 0.2rem 0; display: flex; align-items: center; gap: 0.5rem; }
  .lines-table td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 4.5rem;
    color: var(--muted);
    font-size: 0.8rem;
  }
  .lines-table td input { flex: 1 1 auto; min-width: 0; width: auto; }
  .lines-table .col-product { min-width: 0; padding-right: 2.4rem; }
  .lines-table .col-qty input, .lines-table .col-amount input { width: auto; }
  .lines-table td.col-remove { position: absolute; top: 0.45rem; right: 0.5rem; width: auto; padding: 0; }
  .lines-table td.col-remove::before { content: none; }
  .lines-table tbody tr:hover td { background: transparent; }
}
