:root {
  --bg: #f4f5f7;
  --card: #fff;
  --line: #e5e8ec;
  --line-soft: #eef0f3;
  --text: #1a1d21;
  --dim: #6a7280;
  --faint: #9aa1ab;
  --accent: #1f6feb;
  --accent-soft: #eaf1fd;
  --good: #12794a;
  --bad: #c22b2b;
  --warn: #9a6510;
  --warn-bg: #fff8e8;
  --warn-line: #f0dcae;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
        system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* 金额、数量一律等宽数字，否则一列数字对不齐，扫一眼看不出大小 */
.v, .num, .money, td.num, th.num { font-variant-numeric: tabular-nums; }

/* ---- 顶栏 ---- */
header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
nav {
  display: flex;
  gap: 1px;
  padding: 0 20px;
  max-width: 1180px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
/* 「退出」推到最右边，跟页签拉开距离，免得误点 */
nav button.navout { margin-left: auto; color: var(--faint); }
nav button.navout:hover { color: var(--bad); }
nav button {
  border: 0;
  background: none;
  padding: 15px 15px 13px;
  font-size: 15px;
  color: var(--dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-family: inherit;
  transition: color .12s;
}
nav button:hover { color: var(--text); }
nav button.on {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main { max-width: 1180px; margin: 0 auto; padding: 20px 20px 72px; }

/* ---- 卡片 ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
/* 标题与右上角的小标签分列两端，不用 float */
.card > h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
/* 左右两张卡等高 —— 各自贴着内容收边的话，中间会裂开一道参差的缝 */
/* 一张卡里的第二段（比如进货单下面的「顺手更新成本价」）：
   上面拉条线隔开，否则跟主表单糊成一片，看不出是可选的附加项 */
.card > h3.subhead {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--dim);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
/* .grid2 之间原本靠 .card 的 margin 撑开，上面清掉了，这里补回来 */
.grid2 + .grid2, .grid2 + .card { margin-top: 16px; }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid3 > .card { margin-bottom: 0; }
.grid3 + .card, .grid3 + .grid2 { margin-top: 16px; }
@media (max-width: 900px) { .grid3 { grid-template-columns: 1fr; } }

/* ---- 欠账页顶部：一个主数 + 一列次要数，不用三张空卡撑版面 ---- */
.hero {
  display: flex; align-items: stretch; gap: 28px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 24px; margin-bottom: 16px;
}
.hero-main { flex: 0 0 auto; padding-right: 28px; border-right: 1px solid var(--line-soft); }
.hero-k { color: var(--dim); font-size: 13px; }
.hero-v {
  font-size: 40px; font-weight: 650; letter-spacing: -.025em;
  font-variant-numeric: tabular-nums; line-height: 1.1; margin: 2px 0;
}
.hero-s { color: var(--faint); font-size: 12px; }
/* 次要数字：横向排开，每项自己占一小块，不要拉伸成整行 */
.hero-side {
  flex: 1; display: flex; flex-wrap: wrap; gap: 8px 40px;
  align-content: center; align-items: center;
}
.hero-item { display: flex; flex-direction: column; gap: 2px; min-width: 96px; }
.hi-k { color: var(--dim); font-size: 12px; }
.hi-v { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
@media (max-width: 820px) {
  .hero { flex-direction: column; gap: 14px; }
  .hero-main { border-right: 0; border-bottom: 1px solid var(--line-soft); padding: 0 0 12px; }
}

/* 工具条：左边分段切换，右边杂项 */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.segbar { display: inline-flex; background: #eef0f3; border-radius: 8px; padding: 3px; gap: 2px; }
.seg {
  border: 0; background: transparent; color: var(--dim);
  padding: 6px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.seg:hover { color: var(--text); }
.seg.on { background: var(--card); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }

/* 「还欠我」是这页的主角列 */
th.hi { color: var(--text); font-weight: 600; }
td.hi { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.ok-tag { color: var(--good); font-size: 13px; font-weight: 400; }

/* 说明文字退到脚注，不跟数据抢视线 */
.footnote {
  color: var(--faint); font-size: 12px; line-height: 1.6;
  margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line-soft);
}

/* 展开「跑了什么」 */
.goods-box { padding: 2px 0 6px; }
.goods-head { padding: 8px 2px; color: var(--dim); font-size: 13px; }
.goods-head b { color: var(--text); font-size: 14px; }
.goods-tbl { background: var(--card); border-radius: var(--radius-sm); }
.goods-tbl td.strong { font-weight: 600; }
.goods-tbl .unit { color: var(--faint); font-size: 12px; }
.goods-tbl tfoot td {
  border-top: 1px solid var(--line); border-bottom: 0;
  font-weight: 600; color: var(--text);
}
.goods-foot {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 2px 0; font-size: 13px; color: var(--dim);
}
.goods-foot .goods-sum { margin-right: auto; }
.goods-foot b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- 汇总数字 ---- */
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 6px 0;
}
.stat + .stat { border-top: 1px solid var(--line-soft); }
.stat .k { color: var(--dim); font-size: 13.5px; }
.stat .v { font-size: 17px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
/* 关键数字（净利、欠款合计）拉大一档，一眼能找到 */
.stat.big { padding: 9px 0; }
.stat.big .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
/* 结论行（净利、现金净额）：上面画实线，跟「减 xx」那些过程行分开 ——
   不然一列数字长得都一样，看不出哪个是算完的结果 */
.stat.sum { border-top: 1px solid var(--line); margin-top: 2px; }
.stat.sum .k { color: var(--text); font-weight: 600; font-size: 15px; }
/* 一组的开头：跟上一组之间留白，代替「一条线从头拉到尾」 */
.statgroup { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.statgroup .stat:first-child { border-top: 0; }
.stat .hint {
  display: block;
  font-size: 12px;
  color: var(--faint);
  font-weight: 400;
  margin-top: 1px;
}
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---- 表单 ---- */
label {
  display: block;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 5px;
}
input, select, textarea, button { font-family: inherit; font-size: 15px; }
input, select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #d6dae0;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: #b9c0c9; }
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=date] { min-height: 37px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.row:last-child { margin-bottom: 0; }
/* 字段封顶 —— 不封的话「客户」一个名字要占满 800px，右边全是空 */
.row > div { flex: 1 1 190px; min-width: 0; max-width: 260px; }
.row > div.narrow { flex: 0 0 140px; }
/* 按钮按自身宽度走，塞进 .narrow 会被拉成大方块 */
.row > div.act { flex: 0 0 auto; max-width: none; }

/* a.btn 是下载备份那个链接 —— 不去掉下划线就是一条白线横在蓝底上；
   inline-block 才吃得住 padding，否则按钮比旁边的矮一截 */
.btn {
  display: inline-block;
  text-decoration: none;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: #1a5fd0; border-color: #1a5fd0; }
.btn:active { background: #17539b; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--accent); border-color: var(--accent); }

/* 次要按钮：白底描边 */
.btn.ghost {
  background: #fff;
  color: var(--text);
  border-color: #d6dae0;
  font-weight: 400;
}
.btn.ghost:hover { background: #f7f8fa; border-color: #b9c0c9; }

.btn.sm { padding: 4px 10px; font-size: 13px; font-weight: 400; border-radius: 6px; }
/* 表格里的操作按钮：去掉描边，否则一行三个方框、十几行就是一片格子 */
.btn.sm.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  padding: 4px 8px;
}
.btn.sm.ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn.sm.ghost:disabled:hover { background: transparent; }

.btn.danger { border-color: #e4b9b9; background: #fff; color: var(--bad); }
.btn.danger:hover { background: #fdf2f2; border-color: #d69a9a; }
/* 表格里的「删」平时不涂红 —— 每行都有一个红字，最危险的操作反而变成了背景噪音。
   鼠标移上去再变红，点之前那一下才需要警告。 */
.btn.sm.danger {
  border-color: transparent;
  background: transparent;
  color: var(--dim);
  padding: 4px 8px;
}
.btn.sm.danger:hover { background: #fdeeee; border-color: transparent; color: var(--bad); }

/* 一组并排按钮之间留点气口 */
.btnbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 勾选框和它的字：默认 label 是块级、input 是 100% 宽，
   不管的话勾选框会撑成一整行的大方框，字掉到下一行去 */
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  cursor: pointer;
  user-select: none;
}
.check input { width: auto; margin: 0; accent-color: var(--accent); cursor: pointer; }

/* 卡片里的说明文字 */
.lead { color: var(--dim); font-size: 14px; margin: -4px 0 14px; }

/* ---- 表格 ---- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th {
  color: var(--dim);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: .02em;
  border-bottom-color: var(--line);
  padding-bottom: 8px;
}
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td:first-child, th:first-child { padding-left: 2px; }
td:last-child, th:last-child { padding-right: 2px; }
tbody tr:hover { background: #fafbfc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }
.empty {
  color: var(--faint);
  text-align: center;
  padding: 32px 12px;
  font-size: 14px;
}

/* ---- 提示条 ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(80px);
  background: #23272e;
  color: #fff;
  padding: 11px 22px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
  opacity: 0;
  transition: .2s ease;
  z-index: 99;
  max-width: 90vw;
  font-size: 14px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

/*
 * .note 是「黄色警告」，留给真正需要拦住用户的话（会算重、会覆盖、不可逆）。
 * 单纯解释口径的长句子用 .tip —— 那些是读一次就够的背景知识，
 * 天天顶着一片黄色，视觉重量会盖过数据本身。
 */
.note {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn);
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 14px;
}
.note:last-child { margin-bottom: 0; }

.tip {
  color: var(--dim);
  font-size: 12.5px;
  line-height: 1.65;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}
.tip b { color: var(--text); font-weight: 500; }
.tip:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.balance-tip {
  font-size: 14px;
  padding: 10px 13px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 400;
  background: #f0f2f5;
  color: var(--dim);
  white-space: nowrap;
}
/* 渠道快没钱了。用暖色而不是红色：这是「该充值了」，不是「出错了」 */
.tag.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn-line);
  margin-left: 6px;
}
.warntext { color: var(--warn); }
.warnrow { background: var(--warn-bg); }
.warnrow td { border-bottom-color: var(--warn-line); }

/* ---- 改单状态 ---- */
.editing {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn);
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
/* 改一张单时，另一半表单压暗，避免填错地方 */
.card.dim { opacity: .45; transition: opacity .15s; }
.card.dim:hover { opacity: 1; }

/* ---- 日期切换条 ---- */
.daybar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.daybar input[type=date] { width: auto; }

/* ---- 开单页的合计 ---- */
.lineadd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
.lineadd .total { font-size: 15px; color: var(--dim); }
.lineadd .total b {
  font-size: 22px;
  color: var(--text);
  font-weight: 700;
  margin: 0 3px;
  letter-spacing: -.02em;
}

tr.archived td { color: var(--faint); }
tr.archived td:first-child { text-decoration: line-through; }

/* ---- 展开的单据明细 ---- */
tr.detail > td { background: #f7f9fb; padding: 4px 0 8px 26px; box-shadow: inset 2px 0 0 var(--accent); }
tr.detail > td:last-child { padding-right: 12px; }
table.sub { font-size: 13px; }
table.sub th, table.sub td { border-bottom: 1px solid #eceff3; padding: 6px 8px; }
table.sub tbody tr:hover { background: transparent; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.nowrap .btn + .btn { margin-left: 2px; }

/* ---- 客户 x 货类 交叉表 ---- */
/* 客户小计行加重、留白，货类行缩进 —— 一眼能看出层级，不用看缩进以外的线索 */
table.cc tr.ccsum > td {
  font-weight: 600;
  border-bottom: 0;
  padding-top: 14px;
}
table.cc tr.ccsum:first-child > td { padding-top: 4px; }
table.cc tr.ccrow > td {
  color: var(--dim);
  font-weight: 400;
  border-bottom: 1px solid var(--line-soft);
  padding-top: 6px;
  padding-bottom: 6px;
}
table.cc tr.ccrow > td.ind { padding-left: 22px; }
table.cc tr.ccrow:hover { background: #fafbfc; }
/* 数字列在小计行里保持等宽对齐，别被 600 字重挤歪 */
table.cc td.num { font-variant-numeric: tabular-nums; }
table.cc .disc {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--warn);
}
/* 「给了我 / 还差」是另一码事（收钱，不是卖货），拿竖线隔开 */
table.cc th.sep, table.cc td.sep { border-left: 1px solid var(--line); padding-left: 14px; }
table.cc tfoot td {
  border-top: 2px solid var(--line);
  border-bottom: 0;
  font-weight: 600;
  padding-top: 10px;
}
.dimtext { color: var(--faint); }

/* ---- 打印：只留内容，去掉导航和按钮 ---- */
@media print {
  header, #toast, .btn, .note, .daybar { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0 0 18px; margin: 0; break-inside: avoid; }
  .grid2 { display: block; }
  th, td { padding: 5px 6px; }
}
