/* ============ 通用 ERP 管理系统 ============ */
:root {
    --blue: #2563eb;
    --blue-d: #1d4ed8;
    --blue-l: #eff6ff;
    --ink: #0f172a;
    --text: #334155;
    --muted: #7d899b;
    --line: #e5e9f0;
    --line-d: #d6dde8;
    --bg: #f6f8fb;
    --white: #fff;
    --green: #059669;
    --green-l: #ecfdf5;
    --red: #dc2626;
    --red-l: #fef2f2;
    --amber: #d97706;
    --amber-l: #fffbeb;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-d); }
h1, h2, h3, h4 { margin: 0; color: var(--ink); font-weight: 600; }
p { margin: 0; }
table { border-collapse: collapse; width: 100%; }
.ic { flex: 0 0 auto; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* ---------- 顶栏 ---------- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 30;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; background: var(--white);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}
.top-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn {
    display: none; padding: 6px; border: 1px solid var(--line-d); background: #fff;
    border-radius: 6px; color: var(--text); cursor: pointer; align-items: center;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 8px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .5px;
    display: flex; align-items: center; justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: 15px; color: var(--ink); }
.brand-text i { font-style: normal; font-size: 11.5px; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 16px; }
.top-date { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.top-user { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.top-user em { font-style: normal; font-size: 11px; color: var(--blue); background: var(--blue-l); padding: 2px 6px; border-radius: 4px; }
.top-out { display: flex; color: var(--muted); padding: 6px; border-radius: 6px; }
.top-out:hover { background: #f1f5f9; color: var(--red); }

/* ---------- 侧栏 ---------- */
.sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 228px; z-index: 20;
    background: var(--white); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar nav { padding: 10px 8px; flex: 1; }
.nav-item, .nav-head {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px;
    border-radius: 7px; color: var(--text); font-size: 13.5px; cursor: pointer;
    user-select: none;
}
.nav-item:hover, .nav-head:hover { background: #f4f7fb; color: var(--ink); }
.nav-item.on { background: var(--blue-l); color: var(--blue-d); font-weight: 600; }
.nav-group .nav-head .arrow { margin-left: auto; color: #b0bac9; transition: transform .18s; }
.nav-group.open .nav-head .arrow { transform: rotate(180deg); }
.nav-sub { display: none; padding: 2px 0 4px 0; }
.nav-group.open .nav-sub { display: block; }
.nav-sub a {
    display: block; padding: 7px 12px 7px 40px; font-size: 13px;
    color: var(--muted); border-radius: 6px; position: relative;
}
.nav-sub a:hover { background: #f4f7fb; color: var(--ink); }
.nav-sub a.on { color: var(--blue-d); background: var(--blue-l); font-weight: 600; }
.nav-sub a.on::before {
    content: ''; position: absolute; left: 26px; top: 50%; transform: translateY(-50%);
    width: 4px; height: 4px; border-radius: 50%; background: var(--blue);
}
.side-foot { padding: 12px 20px; font-size: 11.5px; color: #b0bac9; border-top: 1px solid var(--line); }

/* ---------- 主区 ---------- */
.main { margin-left: 228px; padding: 76px 24px 40px; min-height: 100vh; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; letter-spacing: -.3px; }
.page-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.page-tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 14px; border-radius: 6px; font-size: 13px;
    border: 1px solid var(--line-d); background: var(--white); color: var(--text);
    cursor: pointer; white-space: nowrap; transition: .15s; font-family: inherit;
}
.btn:hover { border-color: #bcc7d6; color: var(--ink); background: #fbfcfe; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); border-color: var(--blue-d); color: #fff; }
.btn-danger { color: var(--red); border-color: #f3c9c9; background: #fff; }
.btn-danger:hover { background: var(--red-l); border-color: #e9a8a8; color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 卡片 ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: 14.5px; }
.card-head .actions { display: flex; gap: 8px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { font-size: 13px; }
.table th {
    text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--muted);
    font-weight: 500; font-size: 12.5px; border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #f1f4f9; color: var(--text); vertical-align: middle; white-space: nowrap; }
.table td.wrap { white-space: normal; min-width: 160px; }
.table tbody tr:hover td { background: #fafcff; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { background: #f8fafc; font-weight: 600; color: var(--ink); border-top: 1px solid var(--line); }
.table.compact td, .table.compact th { padding: 7px 10px; }
.table input, .table select { height: 30px; padding: 0 8px; font-size: 12.5px; }
.table .btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.link-strong { color: var(--ink); font-weight: 500; }
.link-strong:hover { color: var(--blue); }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 18px; }
.form-grid.c2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.c3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.c4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span2 { grid-column: span 2; }
.field.span3 { grid-column: span 3; }
.field.span4 { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; color: var(--muted); }
.field > label .req { color: var(--red); margin-left: 2px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=email], input[type=search], select, textarea {
    width: 100%; height: 34px; padding: 0 10px; font-size: 13px; font-family: inherit;
    color: var(--ink); background: #fff; border: 1px solid var(--line-d); border-radius: 6px;
    outline: none; transition: .15s;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
input[readonly] { background: #f8fafc; color: var(--muted); }
.form-foot { display: flex; gap: 10px; justify-content: flex-end; padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--line); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- 徽标 ---------- */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px;
    line-height: 1.6; font-weight: 500; white-space: nowrap;
}
.badge.gray { background: #f1f5f9; color: #64748b; }
.badge.green { background: var(--green-l); color: var(--green); }
.badge.blue { background: var(--blue-l); color: var(--blue-d); }
.badge.red { background: var(--red-l); color: var(--red); }
.badge.amber { background: var(--amber-l); color: var(--amber); }

/* ---------- 提示 ---------- */
.msg {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 7px;
    font-size: 13px; margin-bottom: 14px; border: 1px solid transparent;
}
.msg-ok { background: var(--green-l); color: #047857; border-color: #b7e8d5; }
.msg-error { background: var(--red-l); color: #b91c1c; border-color: #f5c6c6; }
.msg-warn { background: var(--amber-l); color: #b45309; border-color: #f5e0b7; }

/* ---------- 统计卡 ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--white); border: 1px solid var(--line); border-radius: 10px;
    padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .k { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.stat .v { font-size: 23px; font-weight: 600; color: var(--ink); letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat .d b.up { color: var(--red); }
.stat .d b.down { color: var(--green); }
.stat.accent { border-left: 3px solid var(--blue); }
.stat.accent-green { border-left: 3px solid var(--green); }
.stat.accent-amber { border-left: 3px solid var(--amber); }
.stat.accent-red { border-left: 3px solid var(--red); }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; font-size: 12.5px; gap: 12px; flex-wrap: wrap; }
.pager-btns { display: flex; gap: 4px; }
.pager-btns a {
    min-width: 30px; height: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-d); border-radius: 6px; color: var(--text); background: #fff;
}
.pager-btns a:hover { border-color: #bcc7d6; }
.pager-btns a.on { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- 筛选栏 ---------- */
.filter {
    display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
    padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fcfdfe;
}
.filter .fi { display: flex; flex-direction: column; gap: 5px; }
.filter .fi label { font-size: 12px; color: var(--muted); }
.filter input, .filter select { height: 32px; font-size: 12.5px; min-width: 140px; }
.filter .grow { flex: 1; }

/* ---------- 空状态 ---------- */
.empty { padding: 56px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-ic { color: #cbd5e1; margin-bottom: 12px; }
.empty p { margin-bottom: 14px; }

/* ---------- 弹层 ---------- */
.mask {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
    display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.mask.show { display: flex; }
.dialog {
    background: #fff; border-radius: 12px; width: 100%; max-width: 620px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .2); animation: pop .16s ease-out;
}
.dialog.wide { max-width: 920px; }
.dialog.narrow { max-width: 420px; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { font-size: 15px; }
.dialog-body { padding: 20px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fcfdfe; border-radius: 0 0 12px 12px; }
.dialog-close { cursor: pointer; color: var(--muted); background: none; border: none; padding: 4px; border-radius: 5px; display: flex; }
.dialog-close:hover { background: #f1f5f9; color: var(--ink); }

/* ---------- 明细表格（单据行） ---------- */
.lines th { font-size: 12px; }
.lines td { padding: 6px 8px; }
.lines input { height: 30px; font-size: 12.5px; }
.lines .del-row { color: var(--muted); cursor: pointer; background: none; border: none; padding: 4px; }
.lines .del-row:hover { color: var(--red); }
.line-total { font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-bar {
    display: flex; justify-content: flex-end; gap: 28px; padding: 14px 18px;
    background: #f8fafc; border-top: 1px solid var(--line); font-size: 13px;
}
.sum-bar .item { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.sum-bar .item span { color: var(--muted); font-size: 12px; }
.sum-bar .item b { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-bar .item b.hi { color: var(--blue-d); font-size: 17px; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a {
    padding: 9px 16px; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--blue-d); border-bottom-color: var(--blue); font-weight: 600; }

/* ---------- 仪表盘 ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.chart { position: relative; }
.chart::before {
    content: ''; position: absolute; left: 0; right: 0; top: 0; bottom: 22px; pointer-events: none;
    background: repeating-linear-gradient(to top, #eef2f8 0 1px, transparent 1px 25%);
    border-bottom: 1px solid #e2e9f3;
}
.bars { position: relative; z-index: 1; display: flex; align-items: flex-end; gap: 10px; height: 160px; padding: 10px 4px 0; }
.bars .bar { flex: 1; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; }
.bars .bar.zero { background: #e2e8f2; }
.bars .bar span { position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.list-simple { display: flex; flex-direction: column; }
.list-simple .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f1f4f9; font-size: 13px; }
.list-simple .row:last-child { border-bottom: none; }
.list-simple .row .t { color: var(--text); }
.list-simple .row .m { color: var(--muted); font-size: 12px; }

/* ---------- 登录 ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #f0f5fc 0%, #e8effa 40%, #f6f8fb 100%);
    padding: 20px;
}
.login-box { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 36px 32px; box-shadow: 0 12px 40px rgba(15, 23, 42, .1); border: 1px solid #e8eef6; }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.login-logo .brand-mark { width: 40px; height: 40px; font-size: 12px; }
.login-logo b { font-size: 17px; color: var(--ink); display: block; }
.login-logo i { font-style: normal; font-size: 12px; color: var(--muted); }
.login-box .field { margin-bottom: 16px; }
.login-box input { height: 40px; }
.login-box .btn { height: 42px; font-size: 14px; margin-top: 6px; }
.login-tip { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.7; }

/* ---------- 报表 ---------- */
.rpt-title { text-align: center; padding: 18px 0 6px; }
.rpt-title h2 { font-size: 18px; letter-spacing: 1px; }
.rpt-title p { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.rpt-table th, .rpt-table td { border: 1px solid #e8edf4; }
.rpt-table th { background: #f4f7fb; }
.rpt-table .lv1 td { font-weight: 600; color: var(--ink); background: #fafcfe; }
.rpt-table .lv2 td:first-child { padding-left: 34px; }

/* ---------- 打印 ---------- */
@media print {
    .topbar, .sidebar, .page-tools, .filter, .pager, .btn, .no-print { display: none !important; }
    .main { margin: 0; padding: 0; }
    .card { border: none; box-shadow: none; }
    body { background: #fff; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
    .form-grid.c3, .form-grid.c4 { grid-template-columns: repeat(2, 1fr); }
    .form-grid.c3 .span3, .form-grid.c4 .span3 { grid-column: 1 / -1; }
    .grid2, .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .menu-btn { display: inline-flex; }
    .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.15); z-index: 25; }
    .sidebar.open { transform: none; }
    .main { margin-left: 0; padding: 68px 14px 30px; }
    .topbar { padding: 0 12px; }
    .brand-text b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .brand-mark { width: 30px; height: 30px; font-size: 10px; }
    .top-user em { display: none; }
    .top-user { font-size: 0; }
    .top-right { gap: 10px; }
    .form-grid, .form-grid.c2, .form-grid.c3, .form-grid.c4 { grid-template-columns: 1fr; }
    .field.span2, .field.span3 { grid-column: span 1; }
    .brand-text i { display: none; }
    .top-date { display: none; }
    .page-head { flex-direction: column; }
    .table { min-width: 680px; }
    .table td, .table th { white-space: nowrap; }
    .filter { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 14px; }
    .filter .fi { flex: none; }
    .filter input, .filter select { min-width: 0 !important; width: 100%; }
    .filter .grow { display: none; }
    .filter .btn { width: 100%; }
    .sum-bar { flex-wrap: wrap; gap: 14px; justify-content: space-between; }
    .stat-row { grid-template-columns: 1fr 1fr; }
    .stat .v { font-size: 19px; }
}

/* 负数用红色标记（会计惯例） */
.num.neg { color: #dc2626; }
