/* ============ 基础 ============ */
:root {
    --bg: #f3f5f9;
    --card: #ffffff;
    --line: #e6eaf2;
    --line-strong: #d5dbe7;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff4ff;
    --green: #059669;
    --green-soft: #e8f7f0;
    --red: #dc2626;
    --red-soft: #fdecec;
    --amber: #d97706;
    --amber-soft: #fef4e6;
    --sidebar: #0f1a2e;
    --sidebar-2: #16233a;
    --sidebar-text: #c3ccdd;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -14px rgba(16, 24, 40, .18);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.ico { width: 18px; height: 18px; flex: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* ============ 布局 ============ */
.app { min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 238px;
    background: var(--sidebar);
    display: flex; flex-direction: column;
    z-index: 40;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.brand-logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff; font-size: 19px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 14px -6px rgba(37, 99, 235, .8);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #fff; font-size: 15.5px; letter-spacing: .5px; }
.brand-text span { color: #7d8aa5; font-size: 11px; margin-top: 2px; }
.sidebar-close { display: none; }
.nav {
    flex: 1; overflow-y: auto;
    padding: 12px 10px 18px;
    scrollbar-width: thin;
}
.nav::-webkit-scrollbar { width: 5px; }
.nav::-webkit-scrollbar-thumb { background: #2a3852; border-radius: 3px; }
.nav-group {
    padding: 14px 10px 6px;
    color: #61708c;
    font-size: 11px;
    letter-spacing: 1px;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px;
    margin: 1px 0;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    transition: background .15s, color .15s;
}
.nav-link .ico { width: 17px; height: 17px; color: #7d8aa5; }
.nav-link:hover { background: rgba(255, 255, 255, .055); color: #fff; }
.nav-link:hover .ico { color: #a9b6cc; }
.nav-link.active {
    background: linear-gradient(90deg, rgba(37, 99, 235, .95), rgba(37, 99, 235, .78));
    color: #fff;
    box-shadow: 0 6px 16px -8px rgba(37, 99, 235, .9);
}
.nav-link.active .ico { color: #fff; }
.sidebar-foot {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, .07);
}
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: #22314d; color: #9fb3d8;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600; flex: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; background: var(--primary-soft); color: var(--primary); }
.sidebar-user { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar-user strong { color: #e7ecf5; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { color: #77849c; font-size: 11px; }
.main { margin-left: 238px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: 68px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 14px;
    padding: 0 26px;
    position: sticky; top: 0; z-index: 30;
}
.menu-toggle {
    display: none; flex-direction: column; gap: 4px;
    background: none; border: 0; padding: 8px; cursor: pointer;
}
.menu-toggle span { width: 18px; height: 2px; background: var(--text); border-radius: 2px; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 17px; letter-spacing: .3px; }
.crumb { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.top-user { display: flex; align-items: center; gap: 7px; color: var(--text); font-size: 13px; }
.top-user:hover { color: var(--primary); }
.content { padding: 22px 26px; flex: 1; }
.foot { padding: 16px 26px 22px; color: #9aa3b2; font-size: 11.5px; text-align: center; }
.sidebar-mask { display: none; }

/* ============ 卡片 ============ */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
}
.card-title { font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.card-title .ico { color: var(--primary); }
.card-sub { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 4px; }
.card-body { padding: 18px; }
.card-body.p0 { padding: 0; }

/* ============ 统计卡 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 17px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 13px;
    min-width: 0;
}
.stat-ico {
    width: 42px; height: 42px; border-radius: 11px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary);
}
.stat-ico.green { background: var(--green-soft); color: var(--green); }
.stat-ico.red { background: var(--red-soft); color: var(--red); }
.stat-ico.amber { background: var(--amber-soft); color: var(--amber); }
.stat-body { min-width: 0; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value {
    font-size: 21px; font-weight: 650; letter-spacing: .2px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-value small { font-size: 12px; font-weight: 400; color: var(--muted); }
.stat-sub { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

/* ============ 按钮 ============ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 15px;
    border-radius: 8px; border: 1px solid transparent;
    background: var(--primary); color: #fff;
    font-size: 13px; font-family: inherit; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); color: #fff; }
.btn .ico { width: 15px; height: 15px; }
.btn-light { background: #fff; border-color: var(--line-strong); color: #374151; }
.btn-light:hover { background: #f7f9fc; color: var(--primary); border-color: #c5d3ec; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f4f9; color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn-icon {
    width: 30px; height: 30px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 7px; border: 1px solid var(--line-strong);
    background: #fff; color: var(--muted); cursor: pointer;
    font-size: 15px; line-height: 1;
}
.btn-icon:hover { color: var(--primary); border-color: #b9c9e8; background: var(--primary-soft); }
.btn-icon.danger:hover { color: var(--red); border-color: #f0c4c4; background: var(--red-soft); }
.btn-icon .ico { width: 15px; height: 15px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============ 表单 ============ */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; height: 36px; font-size: 12.5px; color: #4b5563; white-space: nowrap; cursor: pointer; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field.span-4 { grid-column: span 4; }
.field label { color: #4b5563; font-size: 12.5px; }
.field label .req { color: var(--red); margin-left: 2px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: #93b4f5;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
input[readonly] { background: #f8fafc; color: #4b5563; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); }
.form-actions {
    display: flex; align-items: center; gap: 10px;
    padding-top: 14px; margin-top: 16px;
    border-top: 1px dashed var(--line);
}
.form-actions .spacer { flex: 1; }
.filter-bar {
    display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: #fbfcfe;
    border-radius: var(--radius) var(--radius) 0 0;
}
.filter-bar .field { width: 150px; flex: none; }
.filter-bar .field.wide { width: 230px; }
.filter-bar .btn { flex: none; }
.hint { color: var(--muted); font-size: 11.5px; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; border-radius: 0 0 var(--radius) var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    background: #f7f9fc;
    color: #566274;
    font-weight: 500;
    font-size: 12px;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td {
    padding: 9px 12px;
    border-bottom: 1px solid #eef1f7;
    vertical-align: middle;
}
.table tbody tr:hover { background: #f8faff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .code { font-family: Consolas, "SF Mono", monospace; font-size: 12px; color: #44516a; }
.table .strong { font-weight: 600; }
.table tfoot td { background: #fafbfe; font-weight: 600; border-top: 1px solid var(--line); }
.table.compact td { padding: 7px 9px; }
.table .muted { font-size: 11.5px; }
.cell-sub { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }

/* 单据明细录入 */
.items-table th { position: static; }
.items-table td { padding: 6px 7px; }
.items-table input, .items-table select { height: 32px; font-size: 12.5px; padding: 0 8px; }
.items-table .product-select { min-width: 210px; }
.items-table .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items-table input[type="number"] { text-align: right; }
.items-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); background: #fbfcfe; flex-wrap: wrap; gap: 12px; }
.items-total { font-size: 14px; color: var(--muted); }
.items-total strong { color: var(--red); font-size: 20px; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* ============ 徽标 ============ */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11.5px; line-height: 1.6; white-space: nowrap;
    background: #f1f4f9; color: #5b6678;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-gray { background: #f1f4f9; color: #6b7280; }

/* ============ 提示 ============ */
.alert {
    padding: 11px 15px; border-radius: 9px; margin-bottom: 16px;
    font-size: 13px; border: 1px solid transparent;
}
.alert-success { background: var(--green-soft); color: #047857; border-color: #c7ecdc; }
.alert-error { background: var(--red-soft); color: #b91c1c; border-color: #f5cfcf; }
.alert-info { background: var(--primary-soft); color: #1e40af; border-color: #d5e3fb; }
.alert-warn { background: var(--amber-soft); color: #b45309; border-color: #f6dfb8; }

/* ============ 分页 ============ */
.pager { display: flex; align-items: center; gap: 5px; padding: 14px 18px; }
.pager-link {
    min-width: 30px; height: 30px; padding: 0 8px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-strong); border-radius: 7px;
    color: #4b5563; font-size: 12.5px; background: #fff;
}
.pager-link:hover { border-color: #b9c9e8; color: var(--primary); }
.pager-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-info { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ============ 空状态 ============ */
.empty { padding: 42px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .ico { width: 34px; height: 34px; color: #c2cad8; display: block; margin: 0 auto 8px; }

/* ============ 登录页 ============ */
.auth-body {
    min-height: 100vh;
    background: radial-gradient(900px 500px at 10% 0%, #1e3a8a 0%, transparent 60%),
                radial-gradient(800px 500px at 95% 100%, #0e7490 0%, transparent 55%),
                #0b1426;
    display: flex; align-items: center; justify-content: center;
    padding: 30px 16px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
    width: 54px; height: 54px; border-radius: 15px; margin: 0 auto 12px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff; font-size: 25px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 14px 30px -12px rgba(37, 99, 235, .9);
}
.auth-brand h1 { color: #fff; font-size: 21px; letter-spacing: 1px; }
.auth-brand p { color: #8291ab; font-size: 12px; margin: 5px 0 0; letter-spacing: .5px; }
.auth-card {
    background: #fff; border-radius: 16px; padding: 28px 26px;
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .6);
}
.auth-card h2 { font-size: 17px; margin-bottom: 2px; }
.auth-card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 20px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card input { height: 42px; }
.auth-card .btn { width: 100%; height: 42px; margin-top: 4px; font-size: 14px; }
.auth-foot { text-align: center; color: #6f7f99; font-size: 11.5px; margin-top: 18px; }
.auth-error { background: var(--red-soft); color: #b91c1c; border: 1px solid #f5cfcf; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px; }

/* ============ 首页 ============ */
.dash-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; }
.chart-bars {
    display: flex; align-items: flex-end; gap: 10px;
    height: 170px; padding: 8px 4px 0;
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.chart-bar {
    width: 100%; max-width: 42px; border-radius: 6px 6px 3px 3px;
    background: linear-gradient(180deg, #60a5fa, #2563eb);
    min-height: 3px; transition: opacity .15s;
}
.chart-col:hover .chart-bar { opacity: .82; }
.chart-bar-val { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.chart-bar-label { font-size: 10.5px; color: #8a94a6; white-space: nowrap; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-link {
    display: flex; align-items: center; gap: 9px;
    padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px;
    color: #374151; font-size: 13px; background: #fbfcfe;
}
.quick-link .ico { color: var(--primary); }
.quick-link:hover { border-color: #bcd0f2; background: var(--primary-soft); color: var(--primary-dark); }
.mini-list { display: flex; flex-direction: column; }
.mini-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; border-bottom: 1px solid #eef1f7;
}
.mini-item:last-child { border-bottom: 0; }
.mini-main { flex: 1; min-width: 0; }
.mini-main strong { display: block; font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-main span { color: var(--muted); font-size: 11.5px; }
.mini-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ============ 打印 ============ */
.print-toolbar {
    display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.print-doc {
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    padding: 30px 34px; max-width: 900px; margin: 0 auto;
    box-shadow: var(--shadow);
}
.print-doc h2 { text-align: center; font-size: 24px; letter-spacing: 8px; margin-bottom: 16px; font-weight: 600; }
.doc-meta { display: flex; justify-content: space-between; gap: 20px; font-size: 13px; margin-bottom: 14px; flex-wrap: wrap; }
.doc-meta span { white-space: nowrap; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.doc-table th, .doc-table td { border: 1px solid #333; padding: 6px 7px; }
.doc-table th { background: #f2f2f2; text-align: center; font-weight: 600; }
.doc-table td.amt, .doc-table td.num { text-align: right; }
.doc-sum { display: flex; justify-content: space-between; font-size: 13px; margin-top: 10px; flex-wrap: wrap; gap: 10px; }
.doc-sign { display: flex; justify-content: space-between; margin-top: 34px; font-size: 13px; flex-wrap: wrap; gap: 16px; }
.doc-note { font-size: 12px; margin-top: 10px; color: #444; }

@media print {
    body { background: #fff; }
    .sidebar, .topbar, .foot, .sidebar-mask, .no-print, .print-toolbar { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    .card, .print-doc { box-shadow: none !important; border: 0 !important; }
    .print-doc { max-width: none; padding: 0; }
    .table-wrap { overflow: visible !important; }
    .table th { background: #f5f5f5 !important; }
}

/* ============ 响应式 ============ */
@media (max-width: 1280px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-mask {
        display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 35;
    }
    .sidebar-close {
        display: block; margin-left: auto; background: none; border: 0; color: #8fa0bd;
        font-size: 24px; line-height: 1; cursor: pointer; padding: 0 2px;
    }
    .main { margin-left: 0; }
    .menu-toggle { display: flex; }
    .topbar { padding: 0 14px; height: 62px; }
    .content { padding: 16px 14px; }
    .form-grid, .form-grid.cols-3, .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .field.span-3, .field.span-4 { grid-column: span 2; }
    .filter-bar .field { width: calc(50% - 5px); }
    .filter-bar .field.wide { width: 100%; }
}
@media (max-width: 620px) {
    .stat-grid { grid-template-columns: 1fr; }
    .form-grid, .form-grid.cols-3, .form-grid.cols-2 { grid-template-columns: 1fr; }
    .field.span-2, .field.span-3, .field.span-4 { grid-column: span 1; }
    .top-user span:last-child { display: none; }
    .quick-grid { grid-template-columns: 1fr; }
    .filter-bar .field { width: 100%; }
    .print-doc { padding: 18px 12px; }
}
