:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e7e9f0;
  --text: #1f2330;
  --muted: #8a90a2;
  --primary: #4f6ef7;
  --primary-d: #3a56d4;
  --primary-bg: #eef2ff;
  --purple: #7c5cf0;
  --amber: #e0901a;
  --amber-bg: #fdf3e1;
  --green: #18a558;
  --green-bg: #e7f6ee;
  --red: #e0495b;
  --red-bg: #fdebed;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 6px 20px rgba(20, 24, 40, .05);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #f4f6fb 55%, #fdf3e1 100%);
}
.login-card {
  background: var(--panel);
  width: 100%;
  max-width: 400px;
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(40, 50, 90, .14);
  padding: 36px 34px 30px;
}
.login-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: .5px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; outline: none; transition: border .15s, box-shadow .15s;
  background: #fff; font-family: inherit; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .14);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 11px 18px; font-size: 14px; cursor: pointer; transition: background .15s, transform .05s;
  font-family: inherit;
}
.btn:hover { background: var(--primary-d); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f5f6fa; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.xs { padding: 3px 9px; font-size: 11.5px; border-radius: 7px; }
.btn.green { background: var(--green); }
.btn.green:hover { background: #158a49; }
.btn.red { background: var(--red); }
.btn.red:hover { background: #c93f50; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.cred-box {
  margin-top: 20px; background: #f8f9fc; border: 1px dashed var(--border);
  border-radius: 10px; padding: 13px 15px; font-size: 12.5px; color: var(--muted);
}
.cred-box b { color: var(--text); }
.cred-box table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.cred-box td { padding: 3px 0; vertical-align: top; }

/* ---------- 应用框架 ---------- */
.topbar {
  height: 58px; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 22px; gap: 14px; position: sticky; top: 0; z-index: 20;
}
.topbar .logo { font-weight: 800; font-size: 17px; letter-spacing: .5px; }
.topbar .logo .dot { color: var(--primary); margin: 0 1px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: var(--muted); }
.role-tag {
  font-size: 12px; padding: 3px 11px; border-radius: 20px; background: var(--primary); color: #fff; font-weight: 600;
}
.role-tag.manager { background: var(--purple); }
.role-tag.approver { background: var(--amber); }
.role-tag.finance { background: var(--green); }
.role-tag.customer { background: var(--primary); }

.layout { display: flex; height: calc(100vh - 58px); }
.sidebar {
  width: 224px; background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px 12px; flex-shrink: 0; align-self: stretch; overflow-y: auto;
}
.sidebar .nav-item {
  padding: 10px 13px; border-radius: 10px; cursor: pointer; color: var(--text);
  font-size: 13.5px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; transition: background .15s;
}
.sidebar .nav-item:hover { background: #f4f6fb; }
.sidebar .nav-item.active { background: var(--primary-bg); color: var(--primary-d); font-weight: 600; }
.sidebar .nav-item .badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 11px;
  border-radius: 10px; padding: 0 7px; min-width: 18px; text-align: center; font-weight: 600;
}
.main { flex: 1; padding: 22px 26px; overflow: auto; }

.year-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.year-pick select { padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-family: inherit; }

/* 卡片/面板 */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 16px; font-size: 15.5px; display: flex; align-items: center; gap: 9px; position: relative; padding-left: 12px; }
.card h3::before { content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 4px; border-radius: 4px; background: var(--primary); }
.card h3 .ic { font-size: 16px; }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat {
  flex: 1; min-width: 190px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); opacity: .8; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 27px; font-weight: 800; margin-top: 8px; letter-spacing: .3px; }
.stat .value.money { color: var(--primary); }
.stat .value.warn { color: var(--amber); }
.stat .value.danger { color: var(--red); }

/* 表格 */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl th { color: var(--muted); font-weight: 600; background: #f7f8fc; position: sticky; top: 0; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: #fafbff; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 状态标签 */
.st { font-size: 12px; padding: 3px 10px; border-radius: 20px; white-space: nowrap; font-weight: 600; }
.st.pending { background: var(--amber-bg); color: var(--amber); }
.st.manager_approved { background: var(--primary-bg); color: var(--primary-d); }
.st.approved { background: var(--green-bg); color: var(--green); }
.st.rejected { background: var(--red-bg); color: var(--red); }
.st.shipped { background: var(--green-bg); color: var(--green); }

/* 类型徽标（产品/现金）与细分金额 */
.tb { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.tb.product { background: #eaf0ff; color: #3a56d4; }
.tb.cash { background: var(--amber-bg); color: var(--amber); }
.tb.warn { background: #fdeee0; color: #c46a13; }

/* 预支持费用抵减说明块 */
.pre-note { background: #fdeee0; border: 1px solid #f3d6b3; color: #8a5212; border-radius: 8px; padding: 10px 14px; font-size: 13px; line-height: 1.6; }
.pre-note b { color: #c46a13; }
.value .sub, .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.cust-item .sub { margin-top: 3px; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; align-items: end; }
.form-grid .field { margin-bottom: 0; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; outline: none; font-family: inherit; background: #fff; color: var(--text); transition: border .15s, box-shadow .15s;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .14);
}
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); cursor: pointer; }
.check input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 9px 0 0; line-height: 1.5; }
.err { color: var(--red); font-size: 12.5px; margin-top: 9px; }

/* 客户列表（通知等） */
.ov-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 14px; }
.cust-list { display: flex; flex-direction: column; gap: 10px; }
.cust-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; transition: border .15s, background .15s;
}
.cust-item:hover { border-color: var(--primary); }
.cust-item.active { border-color: var(--primary); background: #f7f9ff; }
.cust-item .name { font-weight: 600; }
.cust-item .meta { color: var(--muted); font-size: 12.5px; }
.cust-item .amt { margin-left: auto; text-align: right; }
.cust-item .amt .v { font-weight: 700; font-size: 15px; }
.cust-item .amt .l { color: var(--muted); font-size: 12px; }

.detail-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.detail-head h2 { margin: 0; font-size: 18px; }
.empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }

.split { display: flex; gap: 16px; align-items: flex-start; }
.split .left { width: 300px; flex-shrink: 0; }
.split .right { flex: 1; min-width: 0; }

/* ---------- 客户卡片折叠（概览） ---------- */
.cust-cards { display: flex; flex-direction: column; gap: 14px; }
.cust-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s; }
.cust-card:hover { box-shadow: 0 8px 28px rgba(20, 24, 40, .08); }
.cc-head { display: flex; align-items: center; gap: 14px; padding: 16px 18px; cursor: pointer; transition: background .15s; }
.cc-head:hover { background: #f7f9ff; }
.cc-name { font-weight: 700; font-size: 15.5px; }
.cc-name .meta { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.cc-name .btn.xs { margin-left: 10px; vertical-align: middle; }
.cc-amt { margin-left: auto; display: flex; gap: 18px; align-items: center; }
.cc-amt .cc-sales { color: var(--muted); font-size: 13px; }
.cc-amt .cc-unret { font-weight: 800; font-size: 15px; }
.cc-amt .cc-unret.warn { color: var(--amber); }
.cc-amt .cc-unret.danger { color: var(--red); }
.chev { color: var(--muted); font-size: 14px; transition: transform .15s; }
.cc-body { border-top: 1px solid var(--border); padding: 18px; background: #fcfcfe; }

/* 订单 / 费用明细行 */
.ord-lines { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.fee-line {
  display: grid;
  grid-template-columns: 84px minmax(120px, 1.4fr) 78px 86px 102px 36px;
  gap: 8px; align-items: center;
}
.ord-line {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.ord-line > * { flex: 0 0 auto; }
.ord-line .ln-type { flex: 0 0 84px; }
.ord-line .ln-product { flex: 1 1 160px; min-width: 140px; max-width: 260px; }
.ord-line .ln-qty { flex: 0 0 70px; }
.ord-line .ln-price { flex: 0 0 78px; }
.ord-line .ln-amount { flex: 0 0 96px; }
.ord-line .ln-del { flex: 0 0 34px; }
.ord-line select, .ord-line input, .fee-line select, .fee-line input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text); outline: none; transition: border .15s, box-shadow .15s;
}
.ord-line select:focus, .ord-line input:focus, .fee-line select:focus, .fee-line input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .14);
}
.ord-line .check.sm { font-size: 12.5px; white-space: nowrap; color: var(--text); }
.ord-line .check.sm input { accent-color: var(--green); }
.ord-total { font-size: 13px; color: var(--muted); margin: 8px 0; }
.ord-total b { color: var(--text); font-size: 15px; }
.ol { font-size: 12.5px; color: #4a4f5e; padding: 3px 0; line-height: 1.5; }

/* 关联申请下拉选择（核销） */
.app-select {
  width: 100%; padding: 11px 14px; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; background: #fff;
  cursor: pointer; transition: border .15s, box-shadow .15s; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2387857e' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.app-select:hover { border-color: #c3ccf5; }
.app-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .12); }
.app-done-line {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 10px;
  font-size: 13px; color: var(--text); cursor: pointer; user-select: none;
}
.app-done-line input[type="checkbox"] { accent-color: var(--green); width: 16px; height: 16px; margin: 0; }

/* 表格横向滚动 */
.table-wrap { width: 100%; overflow-x: auto; border-radius: 10px; }

/* ---------- 审批原因弹框 ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 24, 33, .5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 440px; padding: 24px 24px 20px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .25); animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin: 0 0 6px; font-size: 16.5px; color: var(--text); }
.modal textarea {
  width: 100%; margin-top: 10px; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; font-family: inherit; resize: vertical; outline: none; transition: border .15s, box-shadow .15s;
}
.modal textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .14); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 草稿箱 */
.drafts { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.draft { border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; background: #fafbff; }
.draft-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 9px; }
.draft-head .meta { font-size: 12px; color: var(--muted); }
.draft-msg { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 13.5px; font-family: inherit; resize: vertical; outline: none; transition: border .15s, box-shadow .15s; }
.draft-msg:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .14); }
.draft-actions { display: flex; gap: 10px; margin-top: 11px; }

/* 审批原因展示 */
.reason { font-size: 12px; color: #b0511a; margin-top: 5px; line-height: 1.5; }

/* 客户建议（向公司提建议 / 公司审批查看） */
.sug-list { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.sug-item { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: #fafbff; }
.sug-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sug-head .meta { color: var(--muted); font-size: 12px; margin-left: auto; }
.sug-status { font-size: 12px; padding: 2px 10px; border-radius: 999px; font-weight: 700; }
.sug-status.pending { background: var(--amber-bg); color: var(--amber); }
.sug-status.done { background: var(--green-bg); color: var(--green); }
.sug-content { font-size: 13.5px; line-height: 1.6; margin-top: 9px; white-space: pre-wrap; }
.sug-reply { margin-top: 10px; padding: 11px 13px; background: #eef6f1; border-radius: 10px; font-size: 13px; line-height: 1.6; color: #1f4d36; }
.sug-reply-form { margin-top: 11px; display: flex; flex-direction: column; gap: 9px; align-items: flex-start; }
.sug-reply-form .sug-reply-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; font-family: inherit; resize: vertical; outline: none; background: #fff; color: var(--text);
  transition: border .15s, box-shadow .15s;
}
.sug-reply-form .sug-reply-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, .14); }

/* 通知项 */
.cust-item .name, .cust-item span:first-child { font-weight: 600; }

/* 未发回项：三态状态徽标 + 区块小标题 */
.sub-h { font-size: 13px; color: #8a8f99; margin: 16px 0 8px; font-weight: 600; }
.ust { font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.ust-none { background: var(--amber-bg); color: var(--amber); }
.ust-part { background: var(--primary-bg); color: var(--primary-d); }
.ust-done { background: var(--green-bg); color: var(--green); }
.ord-line .ln-fulfills { flex: 1 1 100%; }
.ord-line .ln-fulfills option { font-size: 13px; }

/* 订单列表：折叠（默认只显示日期+金额，点击展开明细） */
.ord-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.ord-item { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.ord-sum { display: flex; align-items: center; gap: 14px; padding: 12px 14px; cursor: pointer; transition: background .15s; }
.ord-sum:hover { background: #f7f9ff; }
.ord-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ord-sum .chev { color: var(--muted); font-size: 13px; transition: transform .15s; }
.ord-type { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ord-status { display: flex; }
.ord-amt { margin-left: auto; font-weight: 800; font-size: 15px; white-space: nowrap; }
.ord-detail { border-top: 1px solid var(--border); padding: 12px 14px; background: #fcfcfe; }
.ord-act { margin-top: 8px; }

/* ---------- 移动端 ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; height: auto; }
  .sidebar {
    width: 100%; border-right: none; border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: nowrap; gap: 6px; padding: 8px 10px; overflow-x: auto;
    position: sticky; top: 58px; z-index: 30;
  }
  .sidebar .nav-item { margin-bottom: 0; white-space: nowrap; }
  .main { padding: 14px; }
  .stat-row { flex-direction: column; gap: 12px; }
  .stat { min-width: 0; }
  .cust-card .cc-head { flex-wrap: wrap; }
  .cc-amt { margin-left: 0; width: 100%; justify-content: space-between; }
  .ord-line, .fee-line { display: flex; flex-wrap: wrap; }
  .ord-line select, .ord-line input, .ord-line .check.sm, .ord-line .ln-del,
  .fee-line select, .fee-line input, .fee-line .ln-del { flex: 1 1 45%; min-width: 120px; }
  .ord-line .ln-fulfills { flex: 1 1 100%; grid-column: auto; }
  .app-done-line { margin-left: auto; }
}
