/* ============================================================
   楚骏工具 ERP —— 全局样式
   纯手写，无外部 CDN 依赖，断网也能正常显示。
   ============================================================ */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #6b7280;
  --line: #e8ebf2;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --violet: #7c3aed;
  --blue: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 28px -20px rgba(16, 24, 40, .35);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.sprite { display: none; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#i-grid, #i-check { stroke-width: 1.6; }
#i-grid path { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------- 布局 */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: linear-gradient(180deg, #0d1424 0%, #121a2e 60%, #0e1626 100%);
  color: #cbd5e1; display: flex; flex-direction: column; z-index: 40;
  border-right: 1px solid rgba(255, 255, 255, .04);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 18px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 17px;
  box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .9);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: .3px; }
.brand-text small { color: #7c8aa5; font-size: 11px; margin-top: 2px; }

.nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #253048; border-radius: 8px; }
.nav-group { font-size: 11px; color: #64748b; padding: 14px 10px 6px; letter-spacing: .08em; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; margin-bottom: 2px;
  border-radius: 10px; color: #b7c1d4; font-size: 13.5px; transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(99, 102, 241, .18); color: #fff; box-shadow: inset 0 0 0 1px rgba(129, 140, 248, .28); }
.nav-item .icon { width: 17px; height: 17px; opacity: .85; }
.nav-badge {
  margin-left: auto; background: #f59e0b; color: #1f2937; font-style: normal;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
}
.sidebar-foot {
  display: flex; align-items: center; gap: 10px; padding: 14px 18px;
  border-top: 1px solid rgba(255, 255, 255, .06); font-size: 12px; color: #94a3b8;
}
.sidebar-foot strong { display: block; color: #e2e8f0; font-size: 12.5px; }
.sidebar-foot small { color: #64748b; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #1e293b; color: #cbd5e1;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; background: rgba(244, 246, 251, .85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.page-heading { flex: 1; min-width: 0; }
.page-heading h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.page-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.searchbox {
  display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 11px; color: var(--muted); min-width: 230px;
}
.searchbox input { border: 0; outline: 0; background: transparent; font-size: 13px; width: 100%; color: var(--ink); }
.menu-btn { display: none !important; }

.content { padding: 22px 28px 40px; flex: 1; }
.page-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 28px 26px; color: #94a3b8; font-size: 12px;
}

/* ---------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: .15s ease; white-space: nowrap; font-family: inherit;
}
.btn:hover { background: #f8fafc; border-color: #d7dbe6; text-decoration: none; color: var(--ink); }
.btn .icon { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 6px 16px -10px rgba(79, 70, 229, .9); }
.btn.primary:hover { background: #4338ca; border-color: #4338ca; }
.btn.ghost { background: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.warn { color: var(--warn); border-color: #fde68a; background: #fff; }
.btn.warn:hover { background: var(--warn-soft); }
.btn.ok { color: var(--ok); border-color: #a7f3d0; background: #fff; }
.btn.ok:hover { background: var(--ok-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { padding: 7px; }
.btn:disabled, .btn.disabled { opacity: .45; pointer-events: none; }
.inline { display: inline; }

/* ---------------------------------------------------------- 卡片 / 网格 */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card.pad { padding: 20px 22px; }
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 15px 20px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px 20px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.card { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.split { grid-template-columns: 1.55fr 1fr; align-items: start; }
.split-rev { grid-template-columns: 1fr 1.55fr; align-items: start; }

/* ---------------------------------------------------------- 统计卡 */
.stat { display: flex; gap: 14px; align-items: flex-start; padding: 18px 20px; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); flex: 0 0 auto;
}
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon .icon { width: 21px; height: 21px; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 23px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.delta { font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }

/* ---------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 600; color: #64748b; font-size: 12px;
  padding: 11px 16px; background: #fafbfe; border-bottom: 1px solid var(--line);
  white-space: nowrap; letter-spacing: .02em;
}
table.data td { padding: 11px 16px; border-bottom: 1px solid #f1f3f9; vertical-align: middle; }
table.data tbody tr:hover { background: #fafbff; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .right { text-align: right; }
table.data .center { text-align: center; }
.strong { font-weight: 600; }
.muted-row td { color: #94a3b8; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* ---------------------------------------------------------- 徽标 */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: #f1f5f9; color: #475569;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; display: inline-block; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: #eff6ff; color: var(--blue); }
.badge.violet { background: #f5f3ff; color: var(--violet); }
.badge.green { background: #ecfdf5; color: #047857; }
.badge.gray { background: #f1f5f9; color: #64748b; }

/* ---------------------------------------------------------- 表单 */
.field { margin-bottom: 14px; }
.field > label, label.fld { display: block; font-size: 12.5px; color: #475569; margin-bottom: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid #dfe3ec; border-radius: 10px;
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: #fff; outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
.input.sm { padding: 6px 9px; font-size: 12.5px; }
.input[readonly] { background: #f8fafc; color: var(--muted); }
textarea.input { resize: vertical; min-height: 64px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.check input { width: 15px; height: 15px; accent-color: var(--brand); }

/* 工具栏 / 过滤条 */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-head > .toolbar { flex: 1 1 100%; }
.toolbar .spacer { flex: 1; }
.toolbar .input, .toolbar select.input { width: auto; min-width: 110px; }
.toolbar input.input { flex: 1 1 180px; min-width: 130px; max-width: 300px; }
.toolbar .btn { padding: 7px 11px; font-size: 12.5px; }
.toolbar .icon.muted { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input, .filters select { width: auto; min-width: 120px; }

/* ---------------------------------------------------------- 单据录入 */
.party-row { display: grid; grid-template-columns: 1.5fr .9fr .8fr 1.2fr; gap: 14px; align-items: end; }
.party-preview {
  background: #f8fafc; border: 1px dashed #dfe3ec; border-radius: 10px;
  padding: 9px 12px; font-size: 12.5px; color: var(--muted); min-height: 40px; display: flex; align-items: center;
}
.items { overflow-x: auto; padding-bottom: 2px; }
.ihead, .irow {
  display: grid;
  grid-template-columns: 26px 1fr 150px 90px 110px 100px 140px 34px;
  gap: 8px; align-items: start; min-width: 830px;
}
.ihead {
  font-size: 12px; color: #64748b; font-weight: 600; padding: 0 0 8px;
  border-bottom: 1px solid var(--line);
}
.ihead .num { text-align: right; }
.irow { padding: 7px 0; border-bottom: 1px solid #f1f3f9; }
.irow:last-child { border-bottom: 0; }
.irow:hover { background: #fafbff; }
.irow .input { padding: 7px 9px; font-size: 13px; border-radius: 8px; }
.irow .row-index { font-size: 12px; text-align: center; line-height: 34px; }
.irow .row-amount { line-height: 34px; font-size: 13px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.item-qty, .item-price { text-align: right; font-variant-numeric: tabular-nums; }
.transfer-items .ihead, .transfer-items .irow { grid-template-columns: 26px 1fr 150px 100px 150px 34px; }
.items-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 14px 4px 4px; flex-wrap: wrap; }
.totals { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.totals .row { display: flex; justify-content: flex-end; gap: 24px; font-size: 13px; color: var(--muted); }
.totals .row b { color: var(--ink); font-size: 15px; }
.totals .grand { font-size: 24px; font-weight: 700; color: var(--danger); letter-spacing: -.02em; }

/* ---------------------------------------------------------- 空状态 / 分页 */
.empty { padding: 42px 20px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty .icon { width: 30px; height: 30px; opacity: .35; }
.empty strong { color: var(--ink-2); font-weight: 600; }

.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); }
.pager-info { color: var(--muted); font-size: 12.5px; }
.pager-links { display: flex; gap: 4px; margin-left: auto; }
.pg {
  min-width: 32px; height: 32px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; color: var(--ink-2); background: #fff;
}
.pg:hover { background: #f8fafc; text-decoration: none; }
.pg.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pg.disabled { opacity: .4; pointer-events: none; }
.pg.dots { border: 0; background: transparent; }
.pager-size .input { width: auto; }

/* ---------------------------------------------------------- 提示条 */
.flash-stack { padding: 0 28px; display: grid; gap: 8px; margin-top: 14px; }
.flash {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 11px;
  font-size: 13px; border: 1px solid; animation: drop .25s ease;
}
.flash .icon { width: 17px; height: 17px; }
.flash.success { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; }
.flash.danger { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash.warning { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }
.flash.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.flash-close { margin-left: auto; border: 0; background: transparent; color: inherit; cursor: pointer; opacity: .6; display: flex; }
.flash-close:hover { opacity: 1; }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------- 图表 */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 148px; padding: 8px 2px 0; overflow-x: auto; }
.chart .bar { flex: 1; min-width: 16px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.chart .bar-fill {
  width: 100%; min-height: 3px; border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, #818cf8, #4f46e5); transition: .2s;
}
.chart .bar:hover .bar-fill { filter: brightness(1.08); }
.chart .bar-fill.zero { background: #e2e8f0; }
.chart .bar-label { font-size: 10.5px; color: #94a3b8; white-space: nowrap; }

/* ---------------------------------------------------------- 明细页 */
.detail-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 20px; }
.kv { min-width: 0; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-size: 13.5px; color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.summary-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.summary-box .line { display: flex; justify-content: space-between; gap: 20px; font-size: 13px; padding: 4px 0; }
.summary-box .line.total { border-top: 1px dashed #dfe3ec; margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 16px; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); padding: 0 20px; }
.tabs a { padding: 11px 4px; margin-right: 16px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------------------------------------------------------- 弹窗 */
dialog.dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 32px));
  box-shadow: 0 30px 60px -20px rgba(15, 23, 42, .45); color: var(--ink);
}
dialog.dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
dialog.dialog[open] { animation: pop .16s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.98) translateY(6px); } to { opacity: 1; transform: none; } }
.dialog-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 15.5px; }
.dialog-head button { margin-left: auto; }
.dialog-body { padding: 18px 20px; max-height: 62vh; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfe; }

/* ---------------------------------------------------------- 打印 */
.print-sheet {
  width: 21cm; min-height: 14cm; margin: 0 auto; background: #fff; color: #000;
  padding: 1cm 1.4cm; box-shadow: 0 6px 30px -12px rgba(15, 23, 42, .35);
  font-family: "SimSun", "宋体", serif;
}
.print-sheet h1 { font-size: 20px; text-align: center; margin: 0 0 2px; letter-spacing: 2px; }
.print-sheet h2 { font-size: 15px; text-align: center; margin: 0 0 12px; font-weight: 600; letter-spacing: 4px; }
.print-meta { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-bottom: 8px; }
.print-meta td { padding: 3px 0; }
.print-meta .k { width: 78px; color: #333; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-table th, .print-table td { border: 1px solid #111; padding: 5px 4px; text-align: center; }
.print-table th { font-weight: 600; }
.print-total { display: flex; justify-content: space-between; gap: 20px; font-size: 12.5px; padding: 8px 2px; }
.print-sign { display: flex; justify-content: space-between; gap: 20px; font-size: 12.5px; padding: 16px 2px 6px; }
.print-note { font-size: 11.5px; text-align: center; padding-top: 10px; }
.print-bar {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 10px; justify-content: center;
  padding: 12px; background: #eef2f7; border-bottom: 1px solid #dbe2ec;
}
body.print-page { background: #eef2f7; }
body.print-page .print-wrap { padding: 22px 12px 40px; }

/* ---------------------------------------------------------- 其他 */
.chip { display: inline-flex; align-items: center; gap: 6px; background: #f8fafc; border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.stack { display: grid; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tag-warn { color: var(--danger); font-weight: 600; }
.list { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-bottom: 1px solid #f1f3f9; font-size: 13px; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 500; }
.list-row .s { color: var(--muted); font-size: 12px; }

@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-head { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .party-row { grid-template-columns: 1fr 1fr; }
  .split, .split-rev { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; width: 240px; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex !important; }
  .mask.on { position: fixed; inset: 0; background: rgba(15, 23, 42, .4); z-index: 35; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .flash-stack { padding: 0 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .split, .split-rev { grid-template-columns: 1fr; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 8px 10px; }
  .detail-head { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .searchbox { display: none; }
  .page-foot { padding: 14px 16px; }
}

@media (max-width: 560px) {
  .chart .bar:nth-child(even) .bar-label { display: none; }
  .chart { height: 120px; }
  .stat-value { font-size: 20px; }
}

@media print {
  .sidebar, .topbar, .flash-stack, .page-foot, .print-bar, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  body, body.print-page { background: #fff; }
  .print-wrap { padding: 0; }
  .print-sheet { box-shadow: none; width: auto; padding: 0; }
  @page { size: A4; margin: 12mm 10mm; }
}
