:root {
  --primary: #1f5fa8;
  --primary-dark: #174982;
  --bg: #f2f5f9;
  --panel: #ffffff;
  --border: #dde5ee;
  --text: #1f2d3d;
  --muted: #6b7a8d;
  --green: #1e9e6a;
  --red: #d64545;
  --shadow: 0 2px 10px rgba(20, 40, 70, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

.login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #163a63, #2a6ea8); }
.login-card { background: #fff; width: 400px; padding: 34px 32px; border-radius: 14px; box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; margin-bottom: 12px; }
.login-card h1 { font-size: 18px; line-height: 1.5; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0 20px; }
.login-card label { display: block; text-align: left; margin: 12px 0 6px; color: var(--muted); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.tip { margin-top: 16px; font-size: 12px; color: var(--muted); }
.error-text { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: #173553; color: #dbe7f3; display: flex; flex-direction: column; }
.brand { padding: 18px 16px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-logo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; }
.brand-name { font-size: 13px; font-weight: 700; line-height: 1.35; }
.brand-sub { font-size: 11px; color: #9fb8cf; margin-top: 2px; }
#navMenu { display: flex; flex-direction: column; padding: 12px 0; }
#navMenu button { background: none; border: none; color: #c9d8e8; text-align: left; padding: 13px 18px; font-size: 14px; }
#navMenu button.active, #navMenu button:hover { background: rgba(255,255,255,.12); color: #fff; border-left: 3px solid #5fa8e8; }
.main { flex: 1; display: flex; flex-direction: column; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); padding: 14px 22px; display: flex; justify-content: space-between; align-items: center; }
.crumb { font-size: 16px; font-weight: 700; }
.user-box { display: flex; align-items: center; gap: 10px; }
.tag { background: #e6eff8; color: var(--primary); border-radius: 10px; padding: 3px 10px; font-size: 12px; }
.content { padding: 22px; }

.btn { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 8px 14px; font-size: 14px; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #f2c2c2; }
.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.kpi .k-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.kpi .k-value { font-size: 22px; font-weight: 700; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel h3 { margin-bottom: 14px; font-size: 15px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #f8fafc; }
td.num, th.num { text-align: right; }
tr:hover td { background: #f7fafd; }
.muted { color: var(--muted); }
.green { color: var(--green); }
.red { color: var(--red); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filter-bar select, .filter-bar input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.modal-mask { position: fixed; inset: 0; background: rgba(15,30,50,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 720px; max-width: 94vw; max-height: 88vh; overflow-y: auto; padding: 24px; }
.modal h3 { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.field input, .field select, .field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-row .bar-name { width: 90px; }
.bar-track { flex: 1; background: #eef3f8; border-radius: 6px; height: 18px; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--primary); }
.bar-fill.alt { background: var(--green); }
.bar-row .bar-val { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }

/* 订单明细子表 */
.item-panel { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #fafcfe; }
.item-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.item-head strong { font-size: 14px; }
.item-head .muted { margin-left: auto; }
.item-row { display: grid; grid-template-columns: 1.3fr 0.9fr 1fr 1.1fr 1.2fr auto; gap: 10px; margin-bottom: 8px; align-items: center; }
.item-row select, .item-row input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.item-conv { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* 只读明细（业务员查看） */
.ro-head { display: grid; grid-template-columns: 1.3fr 0.9fr 1fr 1.1fr 1.2fr; gap: 10px; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.ro-row { grid-template-columns: 1.3fr 0.9fr 1fr 1.1fr 1.2fr; font-size: 13px; align-items: center; }
.ro-row .num { text-align: right; font-variant-numeric: tabular-nums; }

/* 提成规则档位表 */
.rule-card { margin-bottom: 14px; grid-column: 1 / -1; }
.tier-row { grid-template-columns: 52px 1fr 1.2fr 1fr auto; gap: 10px; }
.tier-row input { padding: 8px 8px; min-width: 0; }
.tier-row input[type=number]::-webkit-outer-spin-button,
.tier-row input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tier-row input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.tier-head { display: grid; grid-template-columns: 52px 1fr 1.2fr 1fr auto; gap: 10px; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.tier-head span:nth-child(2), .tier-head span:nth-child(3), .tier-head span:nth-child(4) { text-align: center; }
.tier-index { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.tier-lower { display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.inline-check input { width: auto; }
.rate-input { width: 110px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; }
.tag.locked { background: #f0f2f5; color: var(--muted); }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  #navMenu { flex-direction: row; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
}
