:root {
  --bg: #f3f6f5;
  --card: #fff;
  --text: #172321;
  --muted: #6b7c78;
  --line: #dfe8e5;
  --brand: #0f766e;
  --brand2: #14b8a6;
  --danger: #dc4c4c;
  --shadow: 0 10px 35px rgba(25, 55, 48, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: .01em;
}

button, input, select { font: inherit; }
[hidden] { display: none !important; }

/* 布局 */
.app {
  display: grid;
  grid-template-columns: 218px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  background: #102d29;
  color: #e7f6f3;
  padding: 22px 16px;
  position: fixed;
  inset: 0 auto 0 0;
  width: 218px;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 16px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
  margin: 0 8px 22px;
  padding: 4px 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #a9c5c0;
  padding: 11px 12px;
  border-radius: 8px;
  text-align: left;
  margin: 2px 0;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, color .15s, transform .15s;
}

.nav button.active,
.nav button:hover {
  background: #1b4942;
  color: #fff;
}

.nav button:hover { transform: translateX(2px); }
.nav small { display: block; margin: 20px 12px 7px; color: #658d86; }

.side-logout {
  margin-top: auto;
  width: 100%;
  border: 1px solid #31514b;
  background: transparent;
  color: #b9cfcb;
  text-align: left;
}

.side-logout:hover { background: #1b4942; color: #fff; }

.main {
  grid-column: 2;
  padding: 22px 26px;
  min-width: 0;
  background: linear-gradient(180deg, #f5f8f7 0, #f3f6f5 240px);
}

.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; min-height: 54px; }
.top h1 { font-size: 23px; margin: 0 0 4px; font-weight: 700; letter-spacing: .02em; }
.sub { color: var(--muted); font-size: 13px; }

/* 卡片与面板 */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px 17px;
  box-shadow: var(--shadow);
}

.metric { text-align: center; display: flex; min-height: 112px; flex-direction: column; align-items: center; justify-content: center; }
.metric .label { color: var(--muted); font-size: 13px; }
.metric strong { font-size: 26px; display: block; margin: 7px 0 3px; font-weight: 700; font-variant-numeric: tabular-nums; }
.trend { font-size: 12px; color: var(--brand); line-height: 1.35; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
  flex-wrap: wrap;
}

.toolbar h2 { font-size: 16px; margin: 0 auto 0 0; font-weight: 700; }
.toolbar > .input { min-width: 140px; }

/* 控件 */
.input {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fbfdfc;
  outline: none;
  min-height: 36px;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus { border-color: var(--brand2); box-shadow: 0 0 0 3px rgba(20, 184, 166, .1); }

.btn {
  border: 0;
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 650;
  transition: transform .12s, box-shadow .12s, background .12s;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 9px rgba(16, 72, 63, .12); }
.btn:active { transform: none; }
.primary { background: var(--brand); color: #fff; }
.ghost { background: #edf4f2; color: #31514b; }
.danger { color: var(--danger); background: #fff0f0; }

/* 表格 */
.table-wrap { overflow: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; min-width: 800px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 13px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { font-size: 12px; color: var(--muted); background: #fbfcfc; font-weight: 600; text-align: center; position: sticky; top: 0; z-index: 2; }
td { vertical-align: middle; }
tbody tr:nth-child(even) { background: #fcfdfd; }
tbody tr:hover { background: #f1f8f6; }
th:first-child, td:first-child { text-align: left; }

.employee-table { min-width: 1400px; }
.employee-table th, .employee-table td { text-align: left; white-space: nowrap; }
.employee-table th:nth-child(1), .employee-table td:nth-child(1) { width: 140px; }
.employee-table th:nth-child(2), .employee-table td:nth-child(2) { width: 90px; }
.employee-table th:nth-child(3), .employee-table td:nth-child(3) { width: 70px; }
.employee-table th:nth-child(4), .employee-table td:nth-child(4) { width: 120px; }
.employee-table th:nth-child(5), .employee-table td:nth-child(5) { width: 110px; }
.employee-table th:nth-child(6), .employee-table td:nth-child(6) { width: 130px; }
.employee-table th:nth-child(7), .employee-table td:nth-child(7) { width: 190px; }
.employee-table th:nth-child(8), .employee-table td:nth-child(8) { width: 210px; }

.station {
  font-size: 11px;
  white-space: nowrap;
  color: #08766b;
  background: #e8f7f3;
  border-radius: 5px;
  padding: 3px 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 15px;
  padding: 4px 8px;
  background: #e8f7f3;
  color: #08766b;
  font-size: 12px;
}

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

/* 页面切换 */
.page { display: none; min-width: 0; }
.page.active { display: block; animation: pageIn .16s ease-out; }
@keyframes pageIn { from { opacity: .55; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.placeholder { min-height: 320px; display: grid; place-items: center; text-align: center; }
.placeholder b { display: block; font-size: 20px; margin-bottom: 6px; }

/* 项目树 */
.project-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.project-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.project-head { padding: 14px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.project-head > div:first-child { flex: 1; }
.project-head h3 { margin: 1px 0 4px; font-size: 16px; font-weight: 700; }
.units { padding: 8px 14px 12px; }
.tree-node { position: relative; margin: 4px 0 4px 12px; }
.tree-line { display: flex; align-items: center; gap: 7px; min-height: 32px; padding: 4px 7px; border-radius: 7px; background: #f7faf9; border: 1px solid transparent; }
.tree-line:hover { background: #edf7f4; border-color: #dcebe7; }
.tree-line .node-name { flex: 1; }
.tree-children { margin-left: 10px; padding-left: 8px; border-left: 1px solid #d8e9e5; }
.level { font-size: 10px; color: #6b7c78; background: #e7efed; padding: 2px 5px; border-radius: 8px; }
.tiny { padding: 4px 7px; font-size: 11px; }
.count { font-size: 11px; color: var(--muted); background: #f0f5f4; padding: 3px 7px; border-radius: 10px; }
.empty-project { grid-column: 1/-1; padding: 40px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: 12px; }

/* 登录 */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 10%, #d5f5ee, transparent 35%), linear-gradient(135deg, #eff7f5, #f7faf9);
}
.login-card {
  width: min(410px, 100%);
  padding: 34px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 25px 70px rgba(15, 70, 61, .14);
}
.login-brand { text-align: center; justify-content: center; margin-bottom: 26px; }
.login-card h1 { font-size: 21px; margin: 0; font-weight: 700; }
.login-card p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 15px; }
.login-form .btn { padding: 12px; width: 100%; }
.login-error { min-height: 20px; color: var(--danger); font-size: 13px; }

/* 弹窗 */
.modal { display: none; position: fixed; inset: 0; background: #081b1899; z-index: 20; place-items: center; padding: 20px; }
.modal.open { display: grid; }
.dialog { background: #fff; width: min(560px, 100%); border-radius: 14px; padding: 20px; box-shadow: 0 30px 80px #0005; }
.dialog-head { display: flex; justify-content: center; align-items: center; margin-bottom: 16px; position: relative; }
.dialog h2 { margin: 0; text-align: center; font-size: 20px; }
.close { border: 0; background: none; font-size: 24px; cursor: pointer; position: absolute; right: 0; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: #51635f; font-weight: 600; }
.field.full { grid-column: 1/-1; }
.actions { grid-column: 1/-1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; padding-top: 5px; border-top: 1px solid #edf2f0; }

.pay-type-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pay-type-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fbfa;
  cursor: pointer;
  font-weight: 700;
}
.pay-type-option:has(input:checked) { border-color: var(--brand); background: #e8f7f3; color: var(--brand); }
.pay-type-option input { width: 18px; height: 18px; accent-color: var(--brand); }

/* 工资表 */
.payroll-tools { display: flex; gap: 10px; align-items: center; padding: 11px 15px; background: #f7fbfa; border-bottom: 1px solid var(--line); flex-wrap: wrap; justify-content: flex-start; }
.payroll-tools strong { font-size: 14px; margin-right: 4px; }
.payroll-tools .selected-count { color: var(--brand); font-size: 13px; }
.payroll-table { min-width: 2050px; }
.payroll-table th, .payroll-table td { padding: 10px 8px; white-space: nowrap; text-align: center; }
.payroll-table th:nth-child(2), .payroll-table td:nth-child(2), .payroll-table th:nth-child(3), .payroll-table td:nth-child(3) { text-align: left; }
.payroll-table th:nth-child(3), .payroll-table td:nth-child(3) { text-align: center; width: 64px; }
.payroll-table th:nth-child(4), .payroll-table td:nth-child(4) { text-align: left; min-width: 90px; }
.payroll-table .pay { width: 94px; padding: 8px; text-align: right; font-variant-numeric: tabular-nums; }
.payroll-table .money-cell { font-weight: 700; font-variant-numeric: tabular-nums; }
.payroll-table .deduct-col { background: #fff9f5; }
.row-check, .check-all { width: 17px; height: 17px; accent-color: var(--brand); }
.pay-field-head { cursor: grab; user-select: none; transition: background .15s, box-shadow .15s; }
.pay-field-head:active { cursor: grabbing; }
.pay-field-head.dragging { opacity: .45; }
.pay-field-head.drop-before { box-shadow: inset 3px 0 0 var(--brand); }
.pay-field-head.drop-after { box-shadow: inset -3px 0 0 var(--brand); }
.drag-hint { color: var(--muted); font-size: 12px; white-space: nowrap; }
.payroll-total-row td { font-weight: 800; background: #eaf5f2 !important; border-top: 2px solid #b9d9d2; color: #173f38; }
.payroll-total-row td:first-child { text-align: center; }
.payroll-total-row .money-cell { color: #0d6256; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #123e37;
  color: #fff;
  padding: 11px 15px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* 响应式 */
@media (max-width: 900px) {
  .app { display: block; }
  .side { position: static; width: auto; padding: 14px 16px; }
  .brand { margin: 0 0 12px; }
  .nav { display: flex; overflow: auto; }
  .nav small { display: none; }
  .nav button { white-space: nowrap; width: auto; }
  .main { padding: 22px 16px; }
  .cards, .project-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-wrap: wrap; }
  .toolbar h2 { width: 100%; }
  .input { flex: 1; }
  .form { grid-template-columns: 1fr; }
  .field.full, .actions { grid-column: 1; }
}

@media (max-width: 520px) {
  .cards, .project-grid { grid-template-columns: 1fr; }
  .top { align-items: flex-start; }
  .toolbar .btn { width: 100%; }
  .payroll-tools > * { width: 100%; }
  .dialog { padding: 17px; }
}
