:root {
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --ink: #1A2233;
  --ink-2: #33445C;
  --muted: #7A8499;
  --line: #E4E9F2;
  --primary: #1F4E79;
  --primary-soft: #EAF1F8;
  --accent: #0E7C66;
  --warn: #B4531F;
  --danger: #B42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22,40,62,.06), 0 8px 24px rgba(22,40,62,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 28px;
  height: 62px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #16283E, #1F4E79);
  color: #fff; display: grid; place-items: center; font-size: 15px;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav-item {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.nav-item:hover { background: #F2F5F9; }
.nav-item.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.top-actions { display: flex; gap: 10px; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 16px;
  font-size: 14px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: #173F62; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { border-color: #C8D3E2; background: #FAFBFD; }
.btn.danger { background: #fff; border-color: #F3C9C4; color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

/* ---------------- 布局 ---------------- */
main { max-width: 1320px; margin: 0 auto; padding: 22px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-head .grow { flex: 1; }
.panel-body { padding: 16px 18px; }

/* ---------------- 看板 ---------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: .3px; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi .foot { color: var(--muted); font-size: 12px; margin-top: 6px; }
.kpi.in .value { color: var(--accent); }
.kpi.out .value { color: var(--warn); }

.dash-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }

.cat-row { display: grid; grid-template-columns: 116px 1fr 130px; align-items: center; gap: 12px; padding: 7px 0; }
.cat-name { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar { height: 20px; background: #F2F5F9; border-radius: 5px; overflow: hidden; }
.cat-bar > i {
  display: block; height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, #2E6CA4, #1F4E79);
}
.cat-val { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.cat-val em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 6px; }

.empty { padding: 40px 0; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------------- 表格 ---------------- */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
table.tbl th { background: #F8FAFC; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.tbl tbody tr:hover { background: #FAFCFE; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.ops { white-space: nowrap; text-align: right; }
.link { color: var(--primary); cursor: pointer; }
.link:hover { text-decoration: underline; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.tag.in { background: #E8F4F0; color: var(--accent); }
.tag.out { background: #FBEFE8; color: var(--warn); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
input[type=text], input[type=date], input[type=number], select, input[type=file] {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px;
  background: #fff; color: var(--ink); outline: none; font-family: inherit;
}
input[type=text]:focus, input[type=date]:focus, input[type=number]:focus, select:focus { border-color: #9FB7CF; }
.toolbar .search { width: 240px; }

/* ---------------- 弹窗 ---------------- */
.mask {
  position: fixed; inset: 0; background: rgba(16,26,40,.42);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 20px; z-index: 100; overflow: auto;
}
.mask.hidden, .hidden { display: none !important; }
.dialog {
  background: #fff; border-radius: 12px; width: 560px; max-width: 100%;
  box-shadow: 0 24px 60px rgba(10,20,35,.24); display: flex; flex-direction: column;
}
.dialog.wide { width: 1120px; }
.dialog-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 16px; flex: 1; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.dialog-body { padding: 18px 20px; }
.dialog-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }

.field { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.field > label { width: 88px; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.field > input, .field > select { flex: 1; }
.rows-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rows-2 .field > label { width: 76px; }

/* 明细编辑表 */
table.edit { width: 100%; border-collapse: collapse; }
table.edit th { font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; text-align: left; white-space: nowrap; }
table.edit td { padding: 3px 4px; }
table.edit input {
  width: 100%; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 7px; font-size: 13px; font-family: inherit; color: var(--ink); background: #fff;
}
table.edit input.num { text-align: right; }
table.edit .del { color: var(--danger); cursor: pointer; border: 0; background: transparent; font-size: 16px; }
.line-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }

/* 单据打印视图 */
.printable { background: #fff; }
.printable h2 { text-align: center; font-size: 22px; letter-spacing: 6px; margin: 6px 0 18px; }
.printable .meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; font-size: 13px; margin-bottom: 14px; }
.printable .meta span { color: var(--muted); }
.printable table { width: 100%; border-collapse: collapse; }
.printable th, .printable td { border: 1px solid #D8DEE9; padding: 7px 8px; font-size: 13px; }
.printable th { background: #F2F5F9; font-weight: 600; }
.printable tfoot td { background: #F8FAFC; font-weight: 600; }
.printable .remark { margin-top: 12px; font-size: 13px; }
.printable .sign { display: flex; justify-content: space-between; margin-top: 36px; font-size: 13px; color: var(--ink-2); }

.tip { color: var(--muted); font-size: 12px; margin: 6px 0 0; line-height: 1.9; }
.tip a { color: var(--primary); }
.result { margin-top: 12px; font-size: 13px; }
.result .ok { color: var(--accent); }
.result .err { color: var(--danger); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #16283E; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.err { background: #8E1D14; }

/* 小屏 */
@media (max-width: 1080px) {
  .dash-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .nav { overflow-x: auto; }
  .logo-text { display: none; }
}
