/* ============ FB业绩管理系统 样式 ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --cyan: #0891b2;
  --cyan-light: #cffafe;
  --blue-light: #dbeafe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --gray-light: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
.hidden { display: none !important; }

/* ============ 登录页 ============ */
#loginView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 55%, #3b82f6 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.login-card .field { text-align: left; margin-bottom: 16px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 8px; }
.login-tip { color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.7; }

/* ============ 顶栏 ============ */
#appView { min-height: 100vh; display: flex; flex-direction: column; }
header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.header-inner {
  max-width: 1280px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  height: 58px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand .logo-sm {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
}
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav button {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 14px; white-space: nowrap; font-family: inherit;
  transition: all .15s;
}
nav button:hover { background: var(--bg); color: var(--text); }
nav button.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.user-area { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

/* ============ 主内容 ============ */
main { max-width: 1280px; width: 100%; margin: 0 auto; padding: 20px; flex: 1; }
.view { display: none; }
.view.active { display: block; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-head .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card h3 .tag { font-size: 12px; font-weight: 400; color: var(--muted); }

/* 提醒横幅 */
.alert {
  border-radius: 10px; padding: 10px 16px; margin-bottom: 16px;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.alert.warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert.info { background: var(--blue-light); color: #1e40af; border: 1px solid #bfdbfe; }

/* ============ 表单 ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field label .req { color: var(--danger); margin-left: 2px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input:disabled, select:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 16px; }
.form-grid .field { margin-bottom: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; align-items: center; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; font-family: inherit;
  transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 4px 6px; font-family: inherit; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.summary-row td { background: #f0f7ff; font-weight: 700; color: var(--primary-dark); border-top: 2px solid var(--primary-light); }
tr.summary-row:hover td { background: #f0f7ff; }
.empty-tip { text-align: center; color: var(--muted); padding: 32px 0 !important; }

/* 类型徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge.blue { background: var(--blue-light); color: var(--primary-dark); }
.badge.purple { background: var(--purple-light); color: var(--purple); }
.badge.cyan { background: var(--cyan-light); color: var(--cyan); }
.badge.orange { background: var(--orange-light); color: var(--orange); }
.badge.green { background: var(--green-light); color: var(--green); }
.badge.gray { background: var(--gray-light); color: var(--muted); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.active { background: var(--success); }
.status-dot.disabled { background: #cbd5e1; }

/* ============ 统计卡片 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
  background: #fff; border-radius: 12px; padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.highlight .value { color: var(--primary); }
.stat.orange .value { color: var(--orange); }
.stat.green .value { color: var(--success); }
.stat.red .value { color: var(--danger); }

/* ============ 计算说明页 ============ */
.doc-section { margin-bottom: 20px; }
.doc-section h4 { font-size: 15px; margin-bottom: 10px; padding-left: 10px; border-left: 3px solid var(--primary); }
.formula-block {
  background: #f0f7ff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 10px;
  font-size: 14px;
}
.formula-block .f-name { font-weight: 700; color: var(--primary-dark); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.formula-block .f-body { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 15px; color: var(--text); }
.formula-block .f-note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.formula-list .formula-block:last-child { margin-bottom: 0; }
.type-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 8px; }
.legend-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; background: #fff;
}
.example-box {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px;
  padding: 14px 18px; font-size: 13px;
}
.example-box .step { display: flex; gap: 10px; padding: 5px 0; flex-wrap: wrap; }
.example-box .step b { color: #92400e; min-width: 90px; }
.example-box .result { color: #b45309; font-weight: 700; }

/* ============ Toast ============ */
#toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-16px);
  z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center;
  opacity: 0; pointer-events: none; transition: all .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-item {
  background: #1e293b; color: #fff; border-radius: 8px;
  padding: 10px 20px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  max-width: 90vw;
}
.toast-item.success { background: var(--success); }
.toast-item.error { background: var(--danger); }

/* ============ 弹窗 ============ */
#modalMask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 480px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); max-height: 88vh; overflow-y: auto;
}
.modal .modal-head {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: center;
}
.modal .modal-head .close { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal .modal-body { padding: 20px 22px; }
.modal .modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.confirm-text { font-size: 14px; }
.confirm-text .highlight { color: var(--danger); font-weight: 700; }

/* ============ 其他 ============ */
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.muted { color: var(--muted); }
.money-pos { color: var(--success); }
.money-neg { color: var(--danger); }
.rate-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px; font-size: 13px;
}
.rate-bar .rate-item b { font-size: 15px; font-variant-numeric: tabular-nums; }
.rate-bar .custom-flag { background: var(--orange-light); color: var(--orange); border-radius: 999px; padding: 1px 10px; font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.backup-file-label {
  display: block; border: 2px dashed var(--border); border-radius: 10px;
  padding: 18px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px;
}
.backup-file-label:hover { border-color: var(--primary); color: var(--primary); }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 0 26px; }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .header-inner { padding: 0 12px; gap: 8px; }
  .brand span.title { display: none; }
  main { padding: 14px 12px; }
  .card { padding: 14px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .page-head h2 { font-size: 17px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  th, td { padding: 8px 8px; font-size: 12px; }
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* ============ 每日登记：批量录入表 ============ */
.batch-head {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 14px;
}
.batch-head .field { flex: 1; min-width: 200px; max-width: 360px; }
.batch-head .field:last-child { max-width: none; }

/* 录入表：固定布局铺满卡片，列宽严格按比例分配，
   表格永远等于容器宽度（不出滚动条），各行输入框占满所在列、上下严格对齐 */
.batch-table { width: 100%; table-layout: fixed; }
.batch-table td, .batch-table th { padding: 12px 14px; }
.batch-table input[type="number"] {
  width: 100%; padding: 8px 12px; border-radius: 6px; text-align: right;
}
/* 数字列统一比例（fixed 布局下首列自动占剩余宽度）；min-width 兜底防窄窗口过挤 */
.batch-table th:nth-child(2), .batch-table th:nth-child(3),
.batch-table th:nth-child(4) { width: 15%; min-width: 110px; }
.batch-table th:nth-child(5) { width: 17%; min-width: 122px; }
.batch-table .b-count { font-weight: 600; }
.batch-table .b-count:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.batch-table .mode-hint { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.batch-table td.b-preview { font-weight: 600; }

/* ============ 每日登记：视图切换 ============ */
.view-toggle {
  display: inline-flex; margin-left: 12px;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  vertical-align: middle;
}
.view-toggle button {
  border: none; background: #fff; color: var(--muted);
  padding: 4px 12px; font-size: 12px; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button.active { background: var(--primary); color: #fff; font-weight: 500; }
.view-toggle button:not(.active):hover { color: var(--primary); }

/* ============ 每日登记：按员工汇总矩阵 ============ */
.matrix-table .emp-row td { padding: 10px 12px; }
.matrix-table .emp-row { cursor: default; }
.matrix-table .emp-name { font-weight: 600; }
.matrix-table .emp-row.expanded td { background: var(--primary-light); border-bottom-color: var(--primary); }
.matrix-table .cell-has { font-weight: 700; color: var(--primary-dark); }
.matrix-table .fee-cell { color: var(--orange); }
.matrix-table .rec-badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px;
  font-size: 11px; font-weight: 400; color: var(--muted);
  background: #f1f5f9; border-radius: 999px;
}
.matrix-table .expand-cell { text-align: center; min-width: 64px; }

/* 展开的明细行 */
tr.detail-tr td {
  padding: 0 !important; background: #f8fafc;
  border-bottom: 1px solid var(--border) !important;
}
tr.detail-tr .detail-mini { border: none; border-radius: 0; margin: 0; }
tr.detail-tr .detail-mini table { background: transparent; }
tr.detail-tr .detail-mini th { background: #eef2f7; }
tr.detail-tr .detail-mini td { padding: 8px 12px; }
tr.detail-tr .detail-remark { white-space: normal; min-width: 100px; max-width: 220px; }

/* ============ 类型列配色：表头彩色徽章 + 单元格同色浅底 ============ */
.matrix-table th.type-th { padding: 8px 10px; white-space: nowrap; }
.matrix-table th.type-th .badge { font-size: 12px; }
td.type-cell { font-variant-numeric: tabular-nums; }
td.type-cell.blue   { background: rgba(37, 99, 235, 0.07); }
td.type-cell.purple { background: rgba(124, 58, 237, 0.07); }
td.type-cell.cyan   { background: rgba(8, 145, 178, 0.07); }
td.type-cell.orange { background: rgba(234, 88, 12, 0.07); }
td.type-cell.green  { background: rgba(22, 163, 74, 0.07); }
td.type-cell.gray   { background: rgba(100, 116, 139, 0.07); }
tr.summary-row td.type-cell { border-top: 2px solid var(--primary-light); }

/* ============ 最近录入面板 ============ */
.recent-table td { white-space: nowrap; }
.recent-table .emp-chip { font-weight: 600; margin-right: 8px; }
.day-badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #f1f5f9; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.day-badge.today { background: var(--primary-light); color: var(--primary-dark); }
.not-today-flag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; background: var(--orange-light); color: var(--orange); cursor: help;
}
