:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f4f6fb;
    --card: #ffffff;
    --sidebar: #111827;
    --sidebar-hover: #1f2a44;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.6;
}

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

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

.sidebar {
    width: 224px;
    flex: 0 0 224px;
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid #1f2937;
}
.brand-mark {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
    flex: 0 0 32px;
}
.brand-text { color: #f8fafc; font-weight: 600; font-size: 14px; line-height: 1.3; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #cbd5e1;
    font-size: 14px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--brand); color: #fff; }
.nav-ico { width: 18px; height: 18px; display: inline-flex; }
.nav-ico svg { width: 18px; height: 18px; }

.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #64748b; border-top: 1px solid #1f2937; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
}
.crumb { font-weight: 600; font-size: 15px; }
.userbox { display: flex; align-items: center; gap: 14px; }
.user-meta { text-align: right; line-height: 1.25; }
.uname { display: block; font-weight: 600; }
.urole { display: block; font-size: 12px; color: var(--muted); }

.content { padding: 20px 24px 8px; flex: 1; }
.pagefoot { padding: 14px 24px 22px; color: var(--muted); font-size: 12px; }

/* ---------- 页头 ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: #f1f5f9; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.link-danger { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; font-size: 14px; }
.link-danger:hover { text-decoration: underline; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-hint { color: var(--muted); font-size: 12px; }
.card-link { font-size: 13px; }
.card-body { padding: 16px 18px; }
.card-body > .table:first-child { margin-top: -6px; }

.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi-grid-4 { grid-template-columns: repeat(4, 1fr); }
.kpi-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 6px 0 2px; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi-warn { border-color: #fed7aa; background: #fffbf5; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr:hover { background: #f9fbff; }
.table .num { text-align: right; white-space: nowrap; }
.table .strong { font-weight: 600; }
.ops { white-space: nowrap; }
.ops > a { margin-right: 10px; }
.inline-form { display: inline; }

/* ---------- 徽标 ---------- */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; line-height: 1.7; white-space: nowrap;
    background: #eef2f7; color: #475569;
}
.badge-due { background: #fff7ed; color: #c2410c; }
.badge-over { background: #fef2f2; color: #b91c1c; }
.badge-credit-A { background: #ecfdf5; color: #047857; }
.badge-credit-B { background: #eff6ff; color: #1d4ed8; }
.badge-credit-C { background: #fef9c3; color: #a16207; }
.badge-status-draft { background: #f1f5f9; color: #475569; }
.badge-status-submitted { background: #eff6ff; color: #1d4ed8; }
.badge-status-examining { background: #fff7ed; color: #c2410c; }
.badge-status-granted { background: #ecfdf5; color: #047857; }
.badge-status-rejected { background: #fef2f2; color: #b91c1c; }
.badge-status-closed { background: #f3f4f6; color: #6b7280; }
.badge-role-admin { background: #eef2ff; color: #4338ca; }
.badge-role-consultant { background: #eff6ff; color: #1d4ed8; }
.badge-role-flow { background: #f0fdfa; color: #0f766e; }
.badge-role-finance { background: #fdf4ff; color: #a21caf; }

/* ---------- 状态筛选 chip ---------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 999px;
    background: #fff; border: 1px solid var(--line);
    color: #475569; font-size: 13px;
}
.chip:hover { text-decoration: none; border-color: var(--brand); color: var(--brand); }
.chip b { background: #f1f5f9; border-radius: 999px; padding: 0 7px; font-size: 12px; }
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.is-active b { background: rgba(255, 255, 255, .25); color: #fff; }

/* ---------- 筛选栏 ---------- */
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px; margin-bottom: 16px;
}
.filter-bar .input { min-width: 150px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 6px; color: #475569; font-size: 13px; }

/* ---------- 表单 ---------- */
.form-card { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field-label { font-size: 13px; color: #475569; }
.field-label em { color: var(--danger); font-style: normal; }
.field-help { font-size: 12px; color: var(--muted); }
.input {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--line); border-radius: 8px;
    font-size: 14px; font-family: inherit; color: var(--ink); background: #fff;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea.input { resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.stack-form { display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px dashed var(--line); }
.stack-form .form-grid { grid-template-columns: 1fr 1fr; }

/* ---------- 详情信息 ---------- */
.info-list { margin: 0; display: grid; grid-template-columns: 108px 1fr; gap: 8px 12px; }
.info-list dt { color: var(--muted); font-size: 13px; }
.info-list dd { margin: 0; }
.note-box { margin-top: 14px; padding: 12px; background: #f8fafc; border-radius: 10px; }
.note-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.muted { color: var(--muted); }

/* ---------- 待办列表 ---------- */
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-list li { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.todo-list li:last-child { border-bottom: none; }
.todo-title { font-weight: 600; }
.todo-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

/* ---------- 时间线 ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 16px; border-left: 2px solid #e2e8f0; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.tl-time { font-size: 12px; color: var(--muted); }
.tl-body { margin: 4px 0; }
.tl-next { font-size: 12.5px; color: var(--warn); }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart-donut { width: 190px; height: 190px; margin: 0 auto 10px; }
.c-axis { font-size: 11px; fill: #94a3b8; }
.c-donut-num { font-size: 22px; font-weight: 700; fill: #1f2937; }
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 7px; color: #475569; }
.legend b { margin-left: auto; color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: 0 0 10px; }

/* ---------- 排行 ---------- */
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.rank-list li:last-child { border-bottom: none; }
.rank-no { width: 22px; height: 22px; border-radius: 6px; background: #eff6ff; color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { color: var(--muted); font-size: 13px; }

/* ---------- 金额 ---------- */
.money-row { display: flex; gap: 24px; }
.money-col { flex-direction: column; gap: 12px; }
.money-item { display: flex; flex-direction: column; }
.money-item span { color: var(--muted); font-size: 13px; }
.money-item b { font-size: 20px; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.progress { height: 10px; background: #eef2f7; border-radius: 999px; overflow: hidden; margin: 14px 0 6px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #2563eb, #0ea5e9); }

/* ---------- 角色说明 ---------- */
.role-note { background: #f0f7ff; border: 1px solid #dbeafe; color: #334155; padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13px; }
.role-note b { color: #1d4ed8; }

/* ---------- 消息提示 ---------- */
.flash { padding: 11px 16px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px; }
.flash-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.empty { color: var(--muted); text-align: center; padding: 22px 0; }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; gap: 6px; justify-content: flex-end; padding-top: 14px; }
.page-btn { padding: 5px 11px; border: 1px solid var(--line); border-radius: 7px; color: #475569; font-size: 13px; background: #fff; }
.page-btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.page-btn.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-btn.is-disabled { color: #cbd5e1; pointer-events: none; }
.page-info { color: var(--muted); font-size: 12.5px; margin-left: 6px; }

.hidden { display: none; }

/* ---------- 登录页 ---------- */
.login-body { background: linear-gradient(135deg, #eef4ff 0%, #f7f9fc 100%); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: 40px; padding: 24px; flex-wrap: wrap; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 34px 32px; box-shadow: 0 18px 45px rgba(15, 23, 42, .1); }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-brand .brand-mark { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px; font-size: 20px; }
.login-brand h1 { margin: 0; font-size: 18px; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.login-form { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }
.login-tip { color: var(--muted); font-size: 12px; margin: 16px 0 0; text-align: center; }
.login-side { max-width: 320px; }
.login-side h2 { font-size: 20px; margin: 0 0 14px; color: #1e3a8a; }
.login-side ul { list-style: none; margin: 0; padding: 0; }
.login-side li { padding: 7px 0 7px 22px; position: relative; color: #475569; }
.login-side li::before { content: ""; position: absolute; left: 0; top: 14px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
    .kpi-grid, .kpi-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; flex: none; height: auto; position: static; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .cols-2, .cols-3, .form-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .content { padding: 16px; }
    .info-list { grid-template-columns: 92px 1fr; }
}